29 #include <boost/format.hpp> 34 using namespace Constants;
71 uint32_t
position, uint32_t offset, uint32_t line,
const string& path)
99 return frames.top().resolve(name, uid);
214 std::set<symbol_t> symbols;
216 while (!symbols.empty())
220 if (dependencies.find(s) == dependencies.end())
222 dependencies.insert(s);
246 string count = (boost::format(
"%1%") %
scalar_count++).str();
278 throw TypeException(
"$Identifier_is_undeclared_or_not_a_type_name");
320 throw TypeException(boost::format(
"$Unknown_identifier: %1%") % name);
355 vector<expression_t> expr;
356 for (
int i = n; i >= 0; i--)
365 switch (
id.getType().getKind())
368 if (expr.size() !=
id.getType().size())
376 if (expr.size() - 1!=
id.getType().size())
380 instance =
static_cast<instance_t*
>(
id.getSymbol().getData());
387 for (
size_t i = 0; i < instance->
unbound; i++)
397 for (
size_t i = 1; i < expr.size(); i++)
541 vector<expression_t> fields(num);
542 for (uint32_t i = 0; i < num; i++)
555 bool check [[maybe_unused]] =
resolve(name, uid);
587 ternaryop, first, second, third,
position));
647 map<symbol_t, expression_t>::const_iterator arg;
648 for (arg = process->
mapping.begin(); arg != process->
mapping.end(); arg++)
650 type = type.
subst(arg->first, arg->second);
667 throw TypeException(boost::format(
"$Unknown_identifier: %1%") %
id);
672 vector<expression_t> exprs;
673 exprs.push_back (identifier);
674 exprs.push_back (expr);
705 handleError(
"$Quantifier_must_range_over_integer_or_scalar_set");
774 auto invert = (comp ==
LE);
775 auto& boundTypeOrBoundedExpr =
fragments[3];
780 auto args = std::vector<expression_t>{
781 runs, boundTypeOrBoundedExpr, bound,
796 auto& boundTypeOrBoundedExpr =
fragments[4];
802 auto args = std::vector<expression_t>{
803 runs, boundTypeOrBoundedExpr, bound, predicate, untilCond
815 auto& boundTypeOrBoundedExpr1 =
fragments[7];
820 auto& boundTypeOrBoundedExpr2 =
fragments[3];
825 if (runs1.getValue()!=-1 || runs2.getValue()!=-1)
826 throw TypeException(
"The number of runs is not supported in probability comparison");
828 auto args = std::vector<expression_t>{
839 auto& boundTypeOrBoundedExpr =
fragments[3];
844 if (runs.getKind()==
CONSTANT && runs.getType().isInteger() &&
849 if (strcmp(
"min", aggregatingOp) == 0)
851 else if (strcmp(
"max", aggregatingOp) == 0)
856 auto args = std::vector<expression_t>{
857 runs, boundTypeOrBoundedExpr, bound,
866 int numberOfAcceptingRuns)
873 auto offset = nbExpr + (hasReach ? 1 : 0);
874 auto& boundTypeOrBoundedExpr =
fragments[2+offset];
878 auto args = std::vector<expression_t>{};
879 args.reserve(offset+4);
881 if (runs.getKind()==
CONSTANT && runs.getType().isInteger() &&
885 args.push_back(runs);
886 args.push_back(boundTypeOrBoundedExpr);
887 args.push_back(bound);
888 for(
int i=0; i<nbExpr; ++i)
893 args.push_back(predicate);
920 std::vector<expression_t> args;
934 args.push_back(left);
935 args.push_back(lowd);
936 args.push_back(highd);
937 args.push_back(right);
945 std::vector<expression_t> args;
959 args.push_back(left);
960 args.push_back(lowd);
961 args.push_back(highd);
962 args.push_back(right);
969 std::vector<expression_t> args;
979 args.push_back(left);
980 args.push_back(lowd);
981 args.push_back(highd);
982 args.push_back(right);
992 std::vector<expression_t> args;
1002 args.push_back(left);
1003 args.push_back(lowd);
1004 args.push_back(highd);
1005 args.push_back(right);
1055 vector<expression_t> expr;
1057 for (
int i = n; i >= 0; i--)
1084 throw TypeException(boost::format(
"Unknown dynamic template "+
string(temp)+
" used in for all"));
1099 bool mitl =
isMITL(expr);
1110 vector<expression_t> exprs;
1111 exprs.push_back(identifier);
1112 exprs.push_back(process);
1113 exprs.push_back(expr);
1126 throw TypeException(boost::format(
"Unknown dynamic template "+
string(temp)+
" used in exists"));
1139 vector<expression_t> exprs;
1140 bool mitl =
isMITL(expr);
1151 exprs.push_back(identifier);
1152 exprs.push_back(process);
1153 exprs.push_back(expr);
1166 throw TypeException(boost::format(
"Unknown dynamic template "+
string(temp)+
" used in sum"));
1179 vector<expression_t> exprs;
1180 exprs.push_back(identifier);
1181 exprs.push_back(process);
1182 exprs.push_back(expr);
1194 throw TypeException(boost::format(
"Unknown dynamic template "+
string(temp)+
" used in foreach"));
1207 vector<expression_t> exprs;
1208 exprs.push_back(identifier);
1209 exprs.push_back(process);
1210 exprs.push_back(expr);
void exprArray() override
static expression_t createDouble(double, position_t=position_t())
void exprSumBegin(const char *name) override
Constants::kind_t getKind() const
Returns the kind of the expression.
Partial instance of a template.
void exprPostDecrement() override
struct template_t * templ
static expression_t createExit(position_t=position_t())
void exprMitlBox(int, int) override
void exprMitlFormula() override
void exprMitlDisj() override
TimedAutomataSystem * system
Pointer to the system under construction.
void addPosition(uint32_t position, uint32_t offset, uint32_t line, const std::string &path)
void exprBuiltinFunction2(Constants::kind_t) override
std::set< symbol_t > restricted
Restricted variables.
void exprTernary(Constants::kind_t ternaryop, bool firstMissing) override
expression_t clone() const
Make a shallow clone of the expression.
void typeChannel(PREFIX) override
Called whenever a channel type is parsed.
expression_t exprScenario()
void exprSumDynamicEnd(const char *name) override
void exprForAllEnd(const char *name) override
void exprSumEnd(const char *name) override
void popFrame()
Pop the topmost frame.
void exprNumOf() override
void exprExistsDynamicBegin(const char *, const char *) override
bool isInteger() const
Shortcut for is(INT).
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.
static type_t createRange(type_t, expression_t, expression_t, position_t=position_t())
void exprId(const char *varName) override
std::string getName() const
Returns the name (identifier) of this symbol.
void exprMitlConj() override
symbol_t getSymbol()
Returns the symbol of a variable reference.
void exprNary(Constants::kind_t op, uint32_t num) override
type_t createPrefix(Constants::kind_t kind, position_t=position_t()) const
Creates a new type by adding a prefix to it.
void addError(position_t, const std::string &msg, const std::string &ctx="")
void exprDeadlock() override
void addWarning(position_t, const std::string &msg, const std::string &ctx="")
void exprMitlRelease(int, int) override
void typeBoundedInt(PREFIX) override
Called whenever an integer type with a range is parsed.
void exprSMCControl() override
void typeInt(PREFIX) override
Called whenever an integer type is parsed.
void exprBuiltinFunction1(Constants::kind_t) override
std::map< std::string, frame_t > dynamicFrames
frame_t parameters
The parameters.
void exprUnary(Constants::kind_t unaryop) override
void exprProbaExpected(const char *aggregatingOp) override
void exprFalse() override
void typeScalar(PREFIX) override
Called whenever a scalar type is parsed.
static type_t createPrimitive(Constants::kind_t, position_t=position_t())
Create a primitive type.
void handleWarning(const std::string &) override
bool resolve(const std::string &, symbol_t &)
void exprAssignment(Constants::kind_t op) override
void exprPreIncrement() override
void typeName(PREFIX, const char *name) override
Called when a type name has been parsed.
void exprCallEnd(uint32_t n) override
bool isArray() const
Shortcut for is(ARRAY).
void process(const char *) override
ExpressionFragments & getExpressions()
void pushFrame(frame_t)
Push a new frame.
type_t rename(const std::string &from, const std::string &to) const
Replaces any LABEL labeled from occuring in the type with a LABEL to.
void exprCallBegin() override
void exprProbaQuantitative(Constants::kind_t) override
void push(expression_t e)
static expression_t createDot(expression_t, int32_t=-1, position_t=position_t(), type_t=type_t())
Create a DOT expression.
void typeVoid() override
Called whenever a void type is parsed.
expression_t & get(uint32_t)
Returns the ith subexpression.
expression_t toMITLAtom(expression_t e)
static expression_t createUnary(Constants::kind_t, expression_t, position_t=position_t(), type_t=type_t())
Create a unary expression.
static frame_t createFrame()
Creates and returns a new root-frame.
template_t * getDynamicTemplate(const std::string &name)
void exprForAllDynamicBegin(const char *, const char *) override
void exprExistsDynamicEnd(const char *) override
void exprForAllDynamicEnd(const char *name) override
template_t * currentTemplate
The template currently being parsed.
void exprSumDynamicBegin(const char *, const char *) override
Base type for variables, clocks, etc.
type_t getSub() const
Returns the element type of an array.
ExpressionFragments fragments
Expression stack.
static string symbol(const char *str)
Extracts the alpha-numerical symbol used for variable/type identifiers.
void exprComma() override
std::string toString(bool old=false) const
Returns a string representation of the expression.
void typePop() override
Pop type at the topof the type stack.
std::stack< frame_t > frames
Frame stack.
static expression_t createTernary(Constants::kind_t, expression_t, expression_t, expression_t, position_t=position_t(), type_t=type_t())
Create a ternary expression.
void handleError(const std::string &) override
void typeBool(PREFIX) override
Called whenever a boolean type is parsed.
virtual void handleError(const std::string &)=0
void exprMitlUntil(int, int) override
void exprMitlAtom() override
Exception indicating a type error.
type_t subst(symbol_t symbol, expression_t expr) const
Substitutes any occurence of symbol in any expression in the type (expressions that occur as ranges e...
void exprSpawn(int params) override
bool isMITL(expression_t e)
expression_t expr
The initialiser.
void exprForAllBegin(const char *name) override
std::map< symbol_t, expression_t > mapping
The arguments.
type_t getType() const
Returns the type of this symbol.
static expression_t createDeadlock(position_t=position_t())
Create a DEADLOCK expression.
void exprProbaQualitative(Constants::kind_t, Constants::kind_t, double) override
void exprSimulate(int, bool=false, int=0) override
int32_t findIndexOf(const std::string &) const
Returns the index of the record or process field with the given label.
static void collectDependencies(std::set< symbol_t > &dependencies, expression_t expr)
void exprPostIncrement() override
type_t createLabel(const std::string &, position_t=position_t()) const
Creates a LABEL.
ExpressionBuilder(TimedAutomataSystem *)
bool isType(const char *) override
Must return true if and only if name is registered in the symbol table as a named type...
void exprBuiltinFunction3(Constants::kind_t) override
void exprNat(int32_t) override
A reference to an expression.
void exprExistsBegin(const char *name) override
type_t getType() const
Returns the type of the expression.
void * getData()
Returns the user data of this symbol.
void exprDouble(double) override
void exprForeachDynamicEnd(const char *name) override
void exprProbaCompare(Constants::kind_t, Constants::kind_t) override
void pushDynamicFrameOf(template_t *t, const std::string &name)
void exprExistsEnd(const char *name) 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()...
void exprMitlNext() override
void exprBinary(Constants::kind_t binaryop) override
void exprDot(const char *) override
bool isLocation() const
Shortcut for is(LOCATION).
static expression_t createConstant(int32_t, position_t=position_t())
Create a CONSTANT expression.
void typeDuplicate() override
Duplicate type at the top of the type stack.
void setType(type_t)
Sets the type of the expression.
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 popDynamicFrameOf(const std::string &name)
static expression_t createBinary(Constants::kind_t, expression_t, expression_t, position_t=position_t(), type_t=type_t())
Create a binary expression.
void collectPossibleReads(std::set< symbol_t > &, bool collectRandom=false) const
void typeDouble(PREFIX) override
Called whenever a double type is parsed.
void typeClock(PREFIX) override
Called whenever a clock type is parsed.
declarations_t & getGlobals()
Returns the global declarations of the system.
TypeFragments typeFragments
Type stack.
static type_t createArray(type_t sub, type_t size, position_t=position_t())
Creates an array type.
void exprMitlDiamond(int, int) override
static type_t createProcess(frame_t, position_t=position_t())
Creates a new process type.
bool isRecord() const
Shortcut for is(RECORD).
static expression_t createIdentifier(symbol_t, position_t=position_t())
Create an IDENTIFIER expression.
Constants::kind_t getKind() const
Returns the kind of type object.
void exprInlineIf() override
void exprForeachDynamicBegin(const char *, const char *) override
void exprPreDecrement() override
expression_t makeConstant(int value)
bool isProcess() const
Shortcut for is(PROCESS).
void addPosition(uint32_t position, uint32_t offset, uint32_t line, const std::string &path) override
Add mapping from an absolute position to a relative XML element.
int32_t scalar_count
Counter for creating unique scalarset names.