Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

typechecker.h

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; -*-
00002 
00003 /* libutap - Uppaal Timed Automata Parser.
00004    Copyright (C) 2002-2006 Uppsala University and Aalborg University.
00005    
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public License
00008    as published by the Free Software Foundation; either version 2.1 of
00009    the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful, but
00012    WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with this library; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00019    USA
00020 */
00021 
00022 #ifndef UTAP_TYPECHECKER_HH
00023 #define UTAP_TYPECHECKER_HH
00024 
00025 
00026 #include <exception>
00027 #include <set>
00028 #include "utap/system.h"
00029 #include "utap/common.h"
00030 #include "utap/expression.h"
00031 #include "utap/statement.h"
00032 
00033 namespace UTAP
00034 {
00035 
00044     class PersistentVariables : public SystemVisitor
00045     {
00046     private:
00047         std::set<symbol_t> variables;
00048     public:
00049         virtual void visitVariable(variable_t &);
00050         virtual void visitInstance(instance_t &);
00051         const std::set<symbol_t> &get() const;
00052     };
00053 
00060     class CompileTimeComputableValues : public SystemVisitor
00061     {
00062     private:
00063         std::set<symbol_t> variables;
00064     public:
00065         virtual void visitVariable(variable_t &);
00066         virtual void visitInstance(instance_t &);
00067         bool contains(symbol_t) const;
00068     };
00069 
00076     class TypeChecker : public SystemVisitor, public AbstractStatementVisitor
00077     {
00078     private:
00079         TimedAutomataSystem *system;
00080         PersistentVariables persistentVariables;
00081         CompileTimeComputableValues compileTimeComputableValues;
00082         function_t *function; 
00084         template<class T>
00085         void handleError(T, std::string);
00086         template<class T>
00087         void handleWarning(T, std::string);
00088     
00089         expression_t checkInitialiser(type_t type, expression_t init);
00090         bool areAssignmentCompatible(type_t lvalue, type_t rvalue) const;
00091         bool areInlineIfLHSCompatible(type_t t1, type_t t2) const;
00092         bool areInlineIfCompatible(type_t thenArg, type_t elseArg) const;
00093         bool areEqCompatible(type_t t1, type_t t2) const;
00094         bool isSideEffectFree(expression_t) const;
00095         bool isLHSValue(expression_t) const;
00096         bool isUniqueReference(expression_t expr) const;
00097         bool checkParameterCompatible(type_t param, expression_t expr);
00098 
00100         void checkAssignmentExpressionInFunction(expression_t);
00101 
00103         void checkConditionalExpressionInFunction(expression_t);
00104 
00105         bool isCompileTimeComputable(expression_t expr) const;
00106         void checkType(type_t, bool initialisable = false);
00107 
00108     public:
00109         TypeChecker(TimedAutomataSystem *system);
00110         virtual ~TypeChecker() {}
00111         virtual void visitSystemAfter(TimedAutomataSystem *);
00112         virtual void visitVariable(variable_t &);
00113         virtual void visitState(state_t &);
00114         virtual void visitEdge(edge_t &);
00115         virtual void visitInstance(instance_t &);
00116         virtual void visitProperty(expression_t);
00117         virtual void visitFunction(function_t &);
00118         virtual void visitProgressMeasure(progress_t &);
00119         virtual void visitProcess(instance_t &);
00120 
00121         virtual int32_t visitEmptyStatement(EmptyStatement *stat);
00122         virtual int32_t visitExprStatement(ExprStatement *stat);
00123         virtual int32_t visitForStatement(ForStatement *stat);
00124         virtual int32_t visitIterationStatement(IterationStatement *stat);
00125         virtual int32_t visitWhileStatement(WhileStatement *stat);
00126         virtual int32_t visitDoWhileStatement(DoWhileStatement *stat);
00127         virtual int32_t visitBlockStatement(BlockStatement *stat);
00128         virtual int32_t visitIfStatement(IfStatement *stat);
00129         virtual int32_t visitReturnStatement(ReturnStatement *stat);
00130 
00132         bool checkExpression(expression_t);
00133     };
00134 }
00135 
00136 #endif

Generated on Sat Apr 29 21:02:14 2006 for libutap by  doxygen 1.4.2