libutap
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 
26 #include <exception>
27 #include <set>
28 #include "utap/system.h"
29 #include "utap/common.h"
30 #include "utap/expression.h"
31 #include "utap/statement.h"
32 
33 namespace UTAP
34 {
42  {
43  private:
44  std::set<symbol_t> variables;
45  public:
46  virtual void visitVariable(variable_t &);
47  virtual void visitInstance(instance_t &);
48  bool contains(symbol_t) const;
49  };
50 
58  {
59  private:
60  TimedAutomataSystem *system;
61  CompileTimeComputableValues compileTimeComputableValues;
62  function_t *function;
63  bool refinementWarnings;
64 
65  template<class T>
66  void handleError(T, std::string);
67  template<class T>
68  void handleWarning(T, 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  virtual ~TypeChecker() {}
91  virtual void visitTemplateAfter (template_t& );
92  virtual bool visitTemplateBefore(template_t& );
93  virtual void visitSystemAfter(TimedAutomataSystem *);
94  virtual void visitVariable(variable_t &);
95  virtual void visitState(state_t &);
96  virtual void visitEdge(edge_t &);
97  virtual void visitInstance(instance_t &);
98  virtual void visitProperty(expression_t);
99  virtual void visitFunction(function_t &);
100  virtual void visitProgressMeasure(progress_t &);
101  virtual void visitHybridClock(expression_t);
102  virtual void visitIODecl(iodecl_t &);
103  virtual void visitGanttChart(gantt_t&);
104  virtual void visitProcess(instance_t &);
105  virtual void visitInstanceLine(instanceLine_t &);
106  virtual void visitMessage(message_t &);
107  virtual void visitCondition(condition_t &);
108  virtual void visitUpdate(update_t &);
109  virtual int32_t visitEmptyStatement(EmptyStatement *stat);
110  virtual int32_t visitExprStatement(ExprStatement *stat);
111  virtual int32_t visitAssertStatement(AssertStatement *stat);
112  virtual int32_t visitForStatement(ForStatement *stat);
113  virtual int32_t visitIterationStatement(IterationStatement *stat);
114  virtual int32_t visitWhileStatement(WhileStatement *stat);
115  virtual int32_t visitDoWhileStatement(DoWhileStatement *stat);
116  virtual int32_t visitBlockStatement(BlockStatement *stat);
117  virtual int32_t visitIfStatement(IfStatement *stat);
118  virtual int32_t visitReturnStatement(ReturnStatement *stat);
119 
120  bool checkDynamicExpressions (Statement* stat);
125  private:
126  int syncUsed; // Keep track of sync declarations, 0->nothing, 1->IO, 2->CSP, -1->error.
127  template_t* temp;
128  };
129 }
130 
131 #endif
Definition: statement.h:180
bool checkExpression(expression_t)
Type check an expression.
Definition: typechecker.cpp:2120
Definition: statement.h:75
virtual void visitProperty(expression_t)
Definition: typechecker.cpp:1368
bool contains(symbol_t) const
Definition: typechecker.cpp:292
virtual void visitVariable(variable_t &)
Definition: typechecker.cpp:271
A reference to a symbol.
Definition: symbols.h:107
Definition: statement.h:243
virtual int32_t visitIfStatement(IfStatement *stat)
Definition: typechecker.cpp:1738
Definition: system.h:356
Information about a condition.
Definition: system.h:200
virtual void visitVariable(variable_t &)
Definition: typechecker.cpp:870
virtual void visitEdge(edge_t &)
Definition: typechecker.cpp:953
Statement class for the iterator loop-construction.
Definition: statement.h:91
virtual void visitProcess(instance_t &)
Definition: typechecker.cpp:845
Definition: statement.h:55
virtual int32_t visitIterationStatement(IterationStatement *stat)
Definition: typechecker.cpp:1658
virtual bool visitTemplateBefore(template_t &)
Definition: typechecker.cpp:3424
Partial instance of a template.
Definition: system.h:331
virtual void visitIODecl(iodecl_t &)
Definition: typechecker.cpp:720
virtual void visitFunction(function_t &)
Definition: typechecker.cpp:1574
virtual void visitInstance(instance_t &)
Definition: typechecker.cpp:1267
Information about a message.
Definition: system.h:187
Definition: statement.h:211
virtual void visitSystemAfter(TimedAutomataSystem *)
Definition: typechecker.cpp:629
virtual void visitUpdate(update_t &)
Definition: typechecker.cpp:1208
Definition: lexer.cc:585
Definition: statement.h:105
virtual int32_t visitBlockStatement(BlockStatement *stat)
Definition: typechecker.cpp:1695
virtual void visitMessage(message_t &)
Definition: typechecker.cpp:1168
virtual int32_t visitWhileStatement(WhileStatement *stat)
Definition: typechecker.cpp:1677
Definition: system.h:127
Definition: statement.h:127
Definition: system.h:121
Definition: statement.h:35
Definition: statement.h:65
Information about a function.
Definition: system.h:109
virtual int32_t visitExprStatement(ExprStatement *stat)
Definition: typechecker.cpp:1629
virtual void visitTemplateAfter(template_t &)
Definition: typechecker.cpp:3418
virtual void visitCondition(condition_t &)
Definition: typechecker.cpp:1188
Information about a location.
Definition: system.h:55
bool checkSpawnParameterCompatible(type_t param, expression_t arg)
Definition: typechecker.cpp:3432
A reference to an expression.
Definition: expression.h:68
TypeChecker(TimedAutomataSystem *system, bool refinement=false)
Definition: typechecker.cpp:394
virtual void visitState(state_t &)
Definition: typechecker.cpp:896
virtual void visitInstance(instance_t &)
Definition: typechecker.cpp:279
virtual int32_t visitDoWhileStatement(DoWhileStatement *stat)
Definition: typechecker.cpp:1686
Information about an edge.
Definition: system.h:84
virtual void visitInstanceLine(instanceLine_t &)
Definition: typechecker.cpp:1164
Base type for variables, clocks, etc.
Definition: system.h:42
virtual int32_t visitReturnStatement(ReturnStatement *stat)
Definition: typechecker.cpp:1752
virtual int32_t visitForStatement(ForStatement *stat)
Definition: typechecker.cpp:1644
A visitor which type checks the system it visits.
Definition: typechecker.h:57
Definition: statement.h:46
virtual void visitGanttChart(gantt_t &)
Definition: typechecker.cpp:1234
Information about an instance line.
Definition: system.h:348
virtual ~TypeChecker()
Definition: typechecker.h:90
virtual void visitProgressMeasure(progress_t &)
Definition: typechecker.cpp:1216
Definition: statement.h:116
A reference to a type.
Definition: type.h:92
Visitor which collects all compile time computable symbols.
Definition: typechecker.h:41
virtual void visitHybridClock(expression_t)
Definition: typechecker.cpp:703
virtual int32_t visitEmptyStatement(EmptyStatement *stat)
Definition: typechecker.cpp:1624
static bool initialisable(type_t type)
Definition: statementbuilder.cpp:229
Definition: system.h:448
bool checkSpawnAndExit(expression_t)
virtual int32_t visitAssertStatement(AssertStatement *stat)
Definition: typechecker.cpp:1635
bool checkDynamicExpressions(Statement *stat)
Definition: typechecker.cpp:3437
Gantt chart entry.
Definition: system.h:147
Definition: system.h:472
Information about an update.
Definition: system.h:214