32 #include <boost/tuple/tuple.hpp> 35 using namespace Constants;
54 for (
auto b:
blocks)
delete b;
60 std::set<symbol_t> symbols;
62 while (!symbols.empty())
66 if (dependencies.find(s) == dependencies.end())
68 dependencies.insert(s);
79 std::set<symbol_t> &dependencies,
type_t type)
84 boost::tie(lower, upper) = type.
getRange();
91 for (
size_t i = 0; i < type.
size(); i++)
134 handleError(
"$Array_must_be_defined_over_an_integer_range_or_a_scalar_set");
167 handleError(
"$Constant_fields_not_allowed_in_struct");
192 bool duplicate =
frames.top().getIndexOf(name) != -1;
197 throw TypeException(boost::format(
"$Duplicate_definition_of %1%") % name);
200 frames.top().addSymbol(name, type);
209 for (
size_t i = 0; i < type.
size(); i++)
211 if (!
initRec(type[i], thisTypeOnly))
226 return thisTypeOnly == 0
251 for (
size_t i = 0; i < type.
size(); i++)
293 handleError(
"$Constants_must_have_an_initialiser");
342 vector<expression_t>
fields(num);
343 for (uint32_t i = 0; i < num; i++)
350 vector<type_t>
types;
352 for (uint32_t i = 0; i < num; i++)
354 type_t type = fields[i].getType();
355 types.push_back(type[0]);
357 fields[i].setType(type[0]);
389 vector<type_t>
types;
393 types.push_back(
params[i].getType());
394 labels.push_back(
params[i].getName());
399 boost::format err = boost::format(
"$Duplicate_definition_of %1%") % name;
467 blocks.back()->push_stat(block);
487 blocks.back()->push_stat(forstat);
543 blocks.back()->push_stat(whilestat);
565 blocks.back()->push_stat(ifstat);
580 handleError(
"$Cannot_return_outside_of_function_declaration");
588 if (return_type.
isVoid() && args)
590 handleError(
"$return_with_a_value_in_function_returning_void");
592 else if (!return_type.
isVoid() && !args)
594 handleError(
"$return_with_no_value_in_function_returning_non-void");
607 blocks.back()->push_stat(stat);
symbol_t uid
The symbol of the variables.
void typeArrayOfSize(size_t) override
Called to create an array type.
bool isClock() const
Shortcut for is(CLOCK).
static bool initRec(type_t type, int thisTypeOnly)
void declFuncEnd() override
std::set< symbol_t > restricted
Restricted variables.
bool isVoid() const
Shortcut for is(VOID_TYPE).
bool isIntegral() const
Returns true if this is a boolean or integer.
uint32_t getSize() const
Returns the number of symbols in this frame.
void declInitialiserList(uint32_t num) override
void popFrame()
Pop the topmost frame.
bool isInteger() const
Shortcut for is(INT).
std::vector< std::string > labels
The labels of a struct.
static expression_t createNary(Constants::kind_t, const std::vector< expression_t > &, position_t=position_t(), type_t=type_t())
Create an n-ary expression.
type_t createPrefix(Constants::kind_t kind, position_t=position_t()) const
Creates a new type by adding a prefix to it.
std::vector< type_t > fields
The types of a struct.
void typeBoundedInt(PREFIX) override
Called whenever an integer type with a range is parsed.
Statement class for the iterator loop-construction.
void declTypeDef(const char *name) override
A type definition.
static bool mustInitialise(type_t type)
void iterationBegin(const char *name) override
void declParameter(const char *name, bool) override
void pushFrame(frame_t)
Push a new frame.
void iterationEnd(const char *name) override
std::pair< expression_t, expression_t > getRange() const
Returns the range of a RANGE type.
void typeArrayOfType(size_t) override
Called to create an array type.
void exprCallBegin() override
void push(expression_t e)
Partial implementation of the builder interface: The ExpressionBuilder implements all expression rela...
const std::string & getLabel(uint32_t) const
Returns the i'th label.
StatementBuilder(TimedAutomataSystem *)
type_t strip() const
Removes any leading prefixes, RANGE, REF and LABEL types and returns the result.
static frame_t createFrame()
Creates and returns a new root-frame.
void returnStatement(bool) override
static type_t createFunction(type_t, const std::vector< type_t > &, const std::vector< std::string > &, position_t=position_t())
Creates a new function type.
template_t * currentTemplate
The template currently being parsed.
Base type for variables, clocks, etc.
type_t stripArray() const
Removes any leading prefixes, RANGE, REF, LABEL and ARRAY types and returns the result.
function_t * currentFun
The function currently being parsed.
type_t getSub() const
Returns the element type of an array.
ExpressionFragments fragments
Expression stack.
void blockBegin() override
std::stack< frame_t > frames
Frame stack.
void whileBegin() override
void handleError(const std::string &) override
Exception indicating a type error.
static type_t createTypeDef(const std::string &, type_t, position_t=position_t())
Creates a new type definition.
void emptyStatement() override
static void collectDependencies(std::set< symbol_t > &, expression_t)
void exprStatement() override
expression_t expr
The initialiser.
type_t getType() const
Returns the type of this symbol.
void structField(const char *name) override
Used to declare the fields of a structure.
frame_t params
The params frame is used temporarily during parameter parsing.
size_t size() const
Returns the number of children.
symbol_t uid
The symbol of the function.
void declFieldInit(const char *name) override
virtual bool addFunction(type_t type, const char *name)=0
static type_t createRecord(const std::vector< type_t > &, const std::vector< std::string > &, position_t=position_t())
Creates a new record type.
BlockStatement * body
Pointer to the block.
void ifEnd(bool) override
void exprNat(int32_t) override
A reference to an expression.
static bool initialisable(type_t type)
type_t getArraySize() const
Returns the size of an array (this is itself a type).
void * getData()
Returns the user data of this symbol.
void typeStruct(PREFIX, uint32_t fields) override
Used to construct a new struct type, which is then pushed onto the type stack.
void moveTo(frame_t)
Move all symbols from this to a given one (leaving this empty).
void declFuncBegin(const char *name) override
void assertStatement() override
bool is(Constants::kind_t kind) const
Returns true if the type has kind kind or if type is a prefix, RANGE or REF type and the getChild()...
symbol_t addSymbol(const std::string &name, type_t, void *user=NULL)
Adds a symbol of the given name and type to the frame.
void exprBinary(Constants::kind_t binaryop) override
std::vector< BlockStatement * > blocks
Stack of nested statement blocks.
void doWhileBegin() override
type_t applyPrefix(PREFIX, type_t type)
Given a prefix and a type, this method creates a new type by applying the prefix. ...
bool isScalar() const
Shortcut for is(SCALAR).
void collectPossibleReads(std::set< symbol_t > &, bool collectRandom=false) const
void exprCallBegin() override
virtual variable_t * addVariable(type_t type, const char *name, expression_t init)=0
TypeFragments typeFragments
Type stack.
static type_t createArray(type_t sub, type_t size, position_t=position_t())
Creates an array type.
bool isDouble() const
Shortcut for is(DOUBLE).
bool isRecord() const
Shortcut for is(RECORD).
Constants::kind_t getKind() const
Returns the kind of type object.
void doWhileEnd() override
void declVar(const char *name, bool init) override
Declare a new variable of the given name.