typechecker.h

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
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 {
00041     class CompileTimeComputableValues : public SystemVisitor
00042     {
00043     private:
00044         std::set<symbol_t> variables;
00045     public:
00046         virtual void visitVariable(variable_t &);
00047         virtual void visitInstance(instance_t &);
00048         bool contains(symbol_t) const;
00049     };
00050 
00057     class TypeChecker : public SystemVisitor, public AbstractStatementVisitor
00058     {
00059     private:
00060         TimedAutomataSystem *system;
00061         CompileTimeComputableValues compileTimeComputableValues;
00062         function_t *function; 
00064         template<class T>
00065         void handleError(T, std::string);
00066         template<class T>
00067         void handleWarning(T, std::string);
00068     
00069         expression_t checkInitialiser(type_t type, expression_t init);
00070         bool areAssignmentCompatible(type_t lvalue, type_t rvalue) const;
00071         bool areInlineIfCompatible(type_t thenArg, type_t elseArg) const;
00072         bool areEqCompatible(type_t t1, type_t t2) const;
00073         bool areEquivalent(type_t, type_t) const;
00074         bool isLValue(expression_t) const;
00075         bool isModifiableLValue(expression_t) const;
00076         bool isUniqueReference(expression_t expr) const;
00077         bool isParameterCompatible(type_t param, expression_t arg);
00078         bool checkParameterCompatible(type_t param, expression_t arg);
00079         void checkIgnoredValue(expression_t expr);
00080         bool checkAssignmentExpression(expression_t);
00081         bool checkConditionalExpressionInFunction(expression_t);
00082 
00083         bool isCompileTimeComputable(expression_t expr) const;
00084         void checkType(type_t, bool initialisable = false);
00085 
00086     public:
00087         TypeChecker(TimedAutomataSystem *system);
00088         virtual ~TypeChecker() {}
00089         virtual void visitSystemAfter(TimedAutomataSystem *);
00090         virtual void visitVariable(variable_t &);
00091         virtual void visitState(state_t &);
00092         virtual void visitEdge(edge_t &);
00093         virtual void visitInstance(instance_t &);
00094         virtual void visitProperty(expression_t);
00095         virtual void visitFunction(function_t &);
00096         virtual void visitProgressMeasure(progress_t &);
00097         virtual void visitProcess(instance_t &);
00098 
00099         virtual int32_t visitEmptyStatement(EmptyStatement *stat);
00100         virtual int32_t visitExprStatement(ExprStatement *stat);
00101         virtual int32_t visitAssertStatement(AssertStatement *stat);
00102         virtual int32_t visitForStatement(ForStatement *stat);
00103         virtual int32_t visitIterationStatement(IterationStatement *stat);
00104         virtual int32_t visitWhileStatement(WhileStatement *stat);
00105         virtual int32_t visitDoWhileStatement(DoWhileStatement *stat);
00106         virtual int32_t visitBlockStatement(BlockStatement *stat);
00107         virtual int32_t visitIfStatement(IfStatement *stat);
00108         virtual int32_t visitReturnStatement(ReturnStatement *stat);
00109 
00111         bool checkExpression(expression_t);
00112     };
00113 }
00114 
00115 #endif

Generated on Thu Feb 22 14:46:52 2007 for libutap by  doxygen 1.4.7