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-2003 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 
00042     class PersistentVariables : public SystemVisitor
00043     {
00044     private:
00045         std::set<symbol_t> variables;
00046     public:
00047         virtual void visitVariable(variable_t &);
00048         virtual void visitTemplateAfter(template_t &);
00049         const std::set<symbol_t> &get() const;
00050     };
00051 
00058     class TypeChecker : public ContextVisitor, public StatementVisitor
00059     {
00060     private:
00061         ErrorHandler *errorHandler;
00062         TimedAutomataSystem *system;
00063         PersistentVariables persistentVariables;
00064     
00065         bool annotate(expression_t expr);
00066         void checkInitialiser(variable_t &var);
00067         expression_t checkInitialiser(type_t type, expression_t init);
00068         bool areAssignmentCompatible(type_t lvalue, type_t rvalue);
00069         bool areInlineIfCompatible(type_t thenArg, type_t elseArg);
00070         bool isSideEffectFree(expression_t) const;
00071         bool isLHSValue(expression_t) const;
00072         bool isUniqueReference(expression_t expr) const;
00073         void checkRange(expression_t expr);
00074         void checkParameterCompatible(const Interpreter &,
00075                                       type_t param, expression_t expr);
00076 
00078         void checkAssignmentExpressionInFunction(expression_t);
00079 
00081         void checkConditionalExpressionInFunction(expression_t);
00082 
00084         void checkFunctionCallArguments(expression_t);
00085 
00086         void annotateAndExpectConstantInteger(expression_t);
00087         void checkType(type_t, bool inRecord = false);
00088 
00090         void checkVariableDeclaration(variable_t &variable);
00091 
00092         expression_t makeConstant(int);
00093         type_t typeOfBinaryNonInt(expression_t, uint32_t binaryop, expression_t);
00094     
00095     public:
00096         TypeChecker(TimedAutomataSystem *system, ErrorHandler *handler);
00097         virtual ~TypeChecker() {}
00098         virtual void visitVariable(variable_t &);
00099         virtual void visitState(state_t &);
00100         virtual void visitEdge(edge_t &);
00101         virtual void visitInstance(instance_t &);
00102         virtual void visitProperty(expression_t);
00103         virtual void visitFunction(function_t &);
00104 
00105         virtual int32_t visitEmptyStatement(EmptyStatement *stat);
00106         virtual int32_t visitExprStatement(ExprStatement *stat);
00107         virtual int32_t visitForStatement(ForStatement *stat);
00108         virtual int32_t visitWhileStatement(WhileStatement *stat);
00109         virtual int32_t visitDoWhileStatement(DoWhileStatement *stat);
00110         virtual int32_t visitBlockStatement(BlockStatement *stat);
00111         virtual int32_t visitSwitchStatement(SwitchStatement *stat);
00112         virtual int32_t visitCaseStatement(CaseStatement *stat);
00113         virtual int32_t visitDefaultStatement(DefaultStatement *stat);
00114         virtual int32_t visitIfStatement(IfStatement *stat);
00115         virtual int32_t visitBreakStatement(BreakStatement *stat);
00116         virtual int32_t visitContinueStatement(ContinueStatement *stat);
00117         virtual int32_t visitReturnStatement(ReturnStatement *stat);
00118 
00119         static bool isVoid(expression_t);
00120         static bool isInteger(expression_t);
00121         static bool isClock(expression_t);
00122         static bool isRecord(expression_t);
00123         static bool isDiff(expression_t);
00124         static bool isInvariant(expression_t);
00125         static bool isGuard(expression_t);
00126         static bool isConstraint(expression_t);
00127 
00129         void checkExpression(expression_t);
00130     };
00131 }
00132 
00133 #endif

Generated on Thu Feb 17 15:20:58 2005 for libutap by  doxygen 1.4.1