Browse Source
Pgcl: Refactorign and introduced blocks
Pgcl: Refactorign and introduced blocks
Former-commit-id:main9c493a8d6c
[formerly5ac9dc524e
] Former-commit-id:1931feb6ab
16 changed files with 252 additions and 272 deletions
-
84src/storage/pgcl/Block.cpp
-
119src/storage/pgcl/Block.h
-
4src/storage/pgcl/BranchStatement.cpp
-
8src/storage/pgcl/BranchStatement.h
-
8src/storage/pgcl/IfStatement.cpp
-
12src/storage/pgcl/IfStatement.h
-
4src/storage/pgcl/LoopStatement.cpp
-
6src/storage/pgcl/LoopStatement.h
-
2src/storage/pgcl/NondeterministicBranch.cpp
-
2src/storage/pgcl/NondeterministicBranch.h
-
97src/storage/pgcl/PgclProgram.cpp
-
119src/storage/pgcl/PgclProgram.h
-
2src/storage/pgcl/ProbabilisticBranch.cpp
-
2src/storage/pgcl/ProbabilisticBranch.h
-
23src/storage/pgcl/Statement.cpp
-
32src/storage/pgcl/Statement.h
@ -0,0 +1,84 @@ |
|||
#include "Block.h"
|
|||
#include "StatementPrinterVisitor.h"
|
|||
#include <typeinfo>
|
|||
|
|||
namespace storm { |
|||
namespace pgcl { |
|||
|
|||
|
|||
PgclBlock::PgclBlock(vector const &statements, std::shared_ptr<storm::expressions::ExpressionManager> expressions, bool hasLoop, bool hasNondet, bool hasObserve) |
|||
: sequenceOfStatements(statements), |
|||
expressions(expressions), |
|||
loop(hasLoop), |
|||
nondet(hasNondet), |
|||
observe(hasObserve) |
|||
{ |
|||
|
|||
} |
|||
|
|||
iterator PgclBlock::begin() { |
|||
return this->sequenceOfStatements.begin(); |
|||
} |
|||
|
|||
iterator PgclBlock::end() { |
|||
return this->sequenceOfStatements.end(); |
|||
} |
|||
|
|||
bool PgclBlock::empty() { |
|||
return this->sequenceOfStatements.empty(); |
|||
} |
|||
|
|||
element PgclBlock::front() { |
|||
return this->sequenceOfStatements.front(); |
|||
} |
|||
|
|||
element PgclBlock::back() { |
|||
return this->sequenceOfStatements.back(); |
|||
} |
|||
|
|||
unsigned long PgclBlock::size() { |
|||
return this->sequenceOfStatements.size(); |
|||
} |
|||
|
|||
element PgclBlock::at(size_type n) { |
|||
return this->sequenceOfStatements.at(n); |
|||
} |
|||
|
|||
iterator PgclBlock::insert(iterator position, const element& statement) { |
|||
return this->sequenceOfStatements.insert(position, statement); |
|||
} |
|||
|
|||
void PgclBlock::clear() { |
|||
this->sequenceOfStatements.clear(); |
|||
} |
|||
|
|||
std::shared_ptr<storm::expressions::ExpressionManager> PgclBlock::getExpressionManager() { |
|||
return this->expressions; |
|||
} |
|||
|
|||
std::vector<storm::expressions::Variable> PgclBlock::getParameters() { |
|||
return this->parameters; |
|||
} |
|||
|
|||
bool PgclBlock::hasParameters() const { |
|||
return !(this->parameters.empty()); |
|||
} |
|||
|
|||
bool PgclBlock::hasObserve() const { |
|||
return this->observe; |
|||
} |
|||
|
|||
bool PgclBlock::hasNondet() const { |
|||
return this->nondet; |
|||
} |
|||
|
|||
bool PgclBlock::hasLoop() const { |
|||
return this->loop; |
|||
} |
|||
|
|||
iterator PgclBlock::find(element &statement) { |
|||
return std::find(this->sequenceOfStatements.begin(), this->sequenceOfStatements.end(), statement); |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,119 @@ |
|||
#pragma once |
|||
|
|||
#include <vector> |
|||
#include "src/storage/pgcl/Statement.h" |
|||
#include "src/storage/pgcl/StatementPrinterVisitor.h" |
|||
#include "src/storage/expressions/ExpressionManager.h" |
|||
|
|||
namespace storm { |
|||
namespace pgcl { |
|||
|
|||
typedef std::shared_ptr<storm::pgcl::Statement> element; |
|||
typedef std::vector<element> vector; |
|||
typedef std::vector<element>::iterator iterator; |
|||
typedef std::vector<element>::const_iterator const_iterator; |
|||
typedef std::vector<element>::size_type size_type; |
|||
|
|||
/** |
|||
* This class represents a complete and functional PGCL program. It |
|||
* contains an expression manager which keeps track of the current |
|||
* identifiers and variable valuations. Other than that, it basically |
|||
* wraps a std::vector of program statements and is intended to be used |
|||
* as such. |
|||
*/ |
|||
class PgclBlock { |
|||
public: |
|||
PgclBlock() = default; |
|||
/** |
|||
* Does the same as the beforementioned constructor, but sets the |
|||
* location to statement vector to the empty vector. This |
|||
* constructor should be used for sub-programs, for which the |
|||
* location to statement relation doesn't make much sense. |
|||
* @param statements The sequence of statements representing the |
|||
* program. |
|||
* @param expressions The manager responsible for the expressions |
|||
* and variables of the program. |
|||
* @param hasLoop Whether the program contains a loop |
|||
* @param hasNondet Whether the program contains a nondeterministic |
|||
* statement. |
|||
* @param hasParam Whether the program is parameterized. |
|||
*/ |
|||
PgclBlock(vector const& statements, std::shared_ptr<storm::expressions::ExpressionManager> expressions, bool hasLoop, bool hasNondet, bool hasObserve); |
|||
PgclBlock(const PgclBlock & orig) = default; |
|||
PgclBlock & operator=(PgclBlock const& other) = default; |
|||
iterator begin(); |
|||
iterator end(); |
|||
element front(); |
|||
element back(); |
|||
unsigned long size(); |
|||
element at(size_type n); |
|||
iterator insert(iterator position, const element& statement); |
|||
iterator find(element& statement); |
|||
void clear(); |
|||
bool empty(); |
|||
|
|||
/** |
|||
* Returns the list of parameters of the PGCL program. |
|||
*/ |
|||
std::vector<storm::expressions::Variable> getParameters(); |
|||
/** |
|||
* Returns the expression manager of the PGCL program, which is |
|||
* responsible for managing all expressions and variables of the |
|||
* the program and all its subprograms. |
|||
* @return The expression manager of the program. |
|||
*/ |
|||
std::shared_ptr<storm::expressions::ExpressionManager> getExpressionManager(); |
|||
/** |
|||
* Returns true if the program contains a loop statement. |
|||
* @return True if the program has a loop. |
|||
*/ |
|||
bool hasLoop() const; |
|||
/** |
|||
* Returns true if the program contains a nondeterministic |
|||
* statement. |
|||
* @return True if the program has a nondeterministic statement. |
|||
*/ |
|||
bool hasNondet() const; |
|||
/** |
|||
* Returns true if the program contains an observe statement. |
|||
* @return True if the program has an observe statement. |
|||
*/ |
|||
bool hasObserve() const; |
|||
/** |
|||
* Returns true if the program is parameterized. |
|||
* @return True if the program has at least one parameter. |
|||
*/ |
|||
bool hasParameters() const; |
|||
|
|||
protected: |
|||
/** |
|||
* We are basically wrapping a std::vector which represents the |
|||
* ordered single statements of the program. |
|||
*/ |
|||
vector sequenceOfStatements; |
|||
/** |
|||
* Stores the parameters a.k.a. free variables of the PGCL program. |
|||
*/ |
|||
std::vector<storm::expressions::Variable> parameters; |
|||
/** |
|||
* Handles the expressions and variables for the whole program. |
|||
* The expressions of every subprogram are also handled by this |
|||
* manager. We are using a shared pointer since all subprograms |
|||
* are referring to that expression manager, too. |
|||
*/ |
|||
std::shared_ptr<storm::expressions::ExpressionManager> expressions; |
|||
/** |
|||
* Boolean variables to save some properties of the PGCL program. |
|||
* They are later on used by the model builder to possibly |
|||
* construct simpler models (e.g. if no loops, params and nondets |
|||
* are used, a DTMC suffices). |
|||
* The values are set to true if the PGCL parser hits a loop resp. |
|||
* nondet resp. observe resp. parameter statement. |
|||
*/ |
|||
bool loop = false; |
|||
bool nondet = false; |
|||
bool observe = false; |
|||
bool top = false; |
|||
}; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue