libutap  0.93
Uppaal Timed Automata Parser
typechecker.h
Go to the documentation of this file.
1 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 
3 /* libutap - Uppaal Timed Automata Parser.
4  Copyright (C) 2002-2006 Uppsala University and Aalborg University.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public License
8  as published by the Free Software Foundation; either version 2.1 of
9  the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  USA
20 */
21 
22 #ifndef UTAP_TYPECHECKER_HH
23 #define UTAP_TYPECHECKER_HH
24 
25 #include "utap/system.h"
26 #include "utap/common.h"
27 #include "utap/expression.h"
28 #include "utap/statement.h"
29 
30 #include <exception>
31 #include <set>
32 
33 namespace UTAP
34 {
42  {
43  private:
44  std::set<symbol_t> variables;
45  public:
46  void visitVariable(variable_t &) override;
47  void visitInstance(instance_t &) override;
48  bool contains(symbol_t) const;
49  };
50 
58  {
59  private:
60  TimedAutomataSystem *system;
61  CompileTimeComputableValues compileTimeComputableValues;
62  function_t *function{nullptr};
63  bool refinementWarnings;
64 
65  template<class T>
66  void handleError(const T&, const std::string&);
67  template<class T>
68  void handleWarning(const T&, const std::string&);
69 
70  expression_t checkInitialiser(type_t type, expression_t init);
71  bool areAssignmentCompatible(type_t lvalue, type_t rvalue, bool init = false) const;
72  bool areInlineIfCompatible(type_t thenArg, type_t elseArg) const;
73  bool areEqCompatible(type_t t1, type_t t2) const;
74  bool areEquivalent(type_t, type_t) const;
75  bool isLValue(expression_t) const;
76  bool isModifiableLValue(expression_t) const;
77  bool isUniqueReference(expression_t expr) const;
78  bool isParameterCompatible(type_t param, expression_t arg);
79  bool checkParameterCompatible(type_t param, expression_t arg);
80  void checkIgnoredValue(expression_t expr);
81  bool checkAssignmentExpression(expression_t);
82  bool checkConditionalExpressionInFunction(expression_t);
83  void checkObservationConstraints(expression_t);
84 
85  bool isCompileTimeComputable(expression_t expr) const;
86  void checkType(type_t, bool initialisable = false, bool inStruct = false);
87 
88  public:
89  TypeChecker(TimedAutomataSystem *system, bool refinement = false);
90  ~TypeChecker() override {}
91  void visitTemplateAfter (template_t& ) override;
92  bool visitTemplateBefore(template_t& ) override;
93  void visitSystemAfter(TimedAutomataSystem *) override;
94  void visitVariable(variable_t &) override;
95  void visitState(state_t &) override;
96  void visitEdge(edge_t &) override;
97  void visitInstance(instance_t &) override;
98  virtual void visitProperty(expression_t); // FIXME: does not override?!
99  void visitFunction(function_t &) override;
100  void visitProgressMeasure(progress_t &) override;
101  virtual void visitHybridClock(expression_t); // FIXME: does not override?!
102  void visitIODecl(iodecl_t &) override;
103  void visitGanttChart(gantt_t&) override;
104  void visitProcess(instance_t &) override;
105  void visitInstanceLine(instanceLine_t &) override;
106  void visitMessage(message_t &) override;
107  void visitCondition(condition_t &) override;
108  void visitUpdate(update_t &) override;
109  int32_t visitEmptyStatement(EmptyStatement *stat) override;
110  int32_t visitExprStatement(ExprStatement *stat) override;
111  int32_t visitAssertStatement(AssertStatement *stat) override;
112  int32_t visitForStatement(ForStatement *stat) override;
113  int32_t visitIterationStatement(IterationStatement *stat) override;
114  int32_t visitWhileStatement(WhileStatement *stat) override;
115  int32_t visitDoWhileStatement(DoWhileStatement *stat) override;
116  int32_t visitBlockStatement(BlockStatement *stat) override;
117  int32_t visitIfStatement(IfStatement *stat) override;
118  int32_t visitReturnStatement(ReturnStatement *stat) override;
119 
120  bool checkDynamicExpressions (Statement* stat);
122  bool checkExpression(expression_t);
123  bool checkSpawnParameterCompatible (type_t param, expression_t arg);
124  bool checkSpawnAndExit (expression_t);
125 
126  private:
127  sync_use_t syncUsed{sync_use_t::unused}; // tracks sync declarations
128  bool syncError{false}; // true when sync usage is inconsistent (mix of io and csp)
129  template_t* temp{nullptr};
130 
135  bool checkNrOfRuns(const expression_t& expr);
136  bool checkBoundTypeOrBoundedExpr(const expression_t& expr);
137  bool checkBound(const expression_t& expr);
138  bool checkPredicate(const expression_t& expr);
139  bool checkProbBound(const expression_t& expr);
140  bool checkUntilCond(Constants::kind_t kind, const expression_t& expr);
141  bool checkMonitoredExpr(const expression_t& expr);
142  bool checkPathQuant(const expression_t& expr);
143  bool checkAggregationOp(const expression_t& expr);
144  };
145 }
146 
147 #endif
Partial instance of a template.
Definition: system.h:329
virtual void visitProgressMeasure(progress_t &)
Definition: system.h:463
virtual void visitInstanceLine(instanceLine_t &)
Definition: system.h:465
virtual void visitSystemAfter(TimedAutomataSystem *)
Definition: system.h:452
void visitInstance(instance_t &) override
Information about a location.
Definition: system.h:56
A visitor which type checks the system it visits.
Definition: typechecker.h:57
sync_use_t
Synchronization usage options: I/O (with ? or !) or CSP (plain)
Definition: common.h:270
A reference to a symbol.
Definition: symbols.h:107
virtual void visitUpdate(update_t &)
Definition: system.h:468
Information about an edge.
Definition: system.h:85
Statement class for the iterator loop-construction.
Definition: statement.h:91
Information about an update.
Definition: system.h:213
virtual void visitFunction(function_t &)
Definition: system.h:460
virtual bool visitTemplateBefore(template_t &)
Definition: system.h:454
Gantt chart entry.
Definition: system.h:148
void visitVariable(variable_t &) override
Information about an instance line.
Definition: system.h:346
virtual void visitMessage(message_t &)
Definition: system.h:466
Base type for variables, clocks, etc.
Definition: system.h:43
Visitor which collects all compile time computable symbols.
Definition: typechecker.h:41
virtual void visitGanttChart(gantt_t &)
Definition: system.h:464
virtual void visitEdge(edge_t &)
Definition: system.h:457
virtual void visitProcess(instance_t &)
Definition: system.h:459
A reference to a type.
Definition: type.h:93
virtual void visitTemplateAfter(template_t &)
Definition: system.h:455
Information about a message.
Definition: system.h:188
A reference to an expression.
Definition: expression.h:70
static bool initialisable(type_t type)
Information about a function.
Definition: system.h:110
virtual void visitIODecl(iodecl_t &)
Definition: system.h:462
~TypeChecker() override
Definition: typechecker.h:90
Definition: lexer.cc:817
virtual void visitState(state_t &)
Definition: system.h:456
Information about a condition.
Definition: system.h:200
virtual void visitCondition(condition_t &)
Definition: system.h:467