00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; -*- 00002 00003 /* libutap - Uppaal Timed Automata Parser. 00004 Copyright (C) 2002 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.hh" 00029 #include "utap/common.hh" 00030 #include "utap/expression.hh" 00031 00032 namespace UTAP 00033 { 00034 00041 class PersistentVariables : public SystemVisitor 00042 { 00043 private: 00044 std::set<symbol_t> variables; 00045 public: 00046 virtual void visitVariable(variable_t &); 00047 virtual void visitTemplateAfter(template_t &); 00048 const std::set<symbol_t> &get() const; 00049 }; 00050 00052 class TypeChecker : public ContextVisitor 00053 { 00054 private: 00055 ErrorHandler *errorHandler; 00056 TimedAutomataSystem *system; 00057 PersistentVariables persistentVariables; 00058 static std::map<symbol_t, expression_t> empty; 00059 00060 void annotate(expression_t expr); 00061 void checkInitialiser(variable_t &var); 00062 void checkInitialiser(type_t type, expression_t init); 00063 bool areAssignmentCompatible(type_t lvalue, type_t rvalue); 00064 bool areInlineIfCompatible(type_t thenArg, type_t elseArg); 00065 bool isInteger(expression_t) const; 00066 bool isClock(expression_t) const; 00067 bool isRecord(expression_t) const; 00068 bool isDiff(expression_t) const; 00069 bool isInvariant(expression_t) const; 00070 bool isGuard(expression_t) const; 00071 bool isConstraint(expression_t) const; 00072 bool isSideEffectFree(expression_t) const; 00073 bool isLHSValue(expression_t) const; 00074 bool isUniqueReference(expression_t expr) const; 00075 void checkRange(expression_t expr); 00076 void checkParameterCompatible(const Interpreter &, 00077 type_t param, expression_t expr); 00078 00080 void checkIntegerType(type_t type); 00081 00082 expression_t makeConstant(int); 00083 type_t typeOfBinaryNonInt(expression_t, uint32_t binaryop, expression_t); 00084 00085 public: 00086 TypeChecker(ErrorHandler *errorHandler); 00087 virtual ~TypeChecker() {} 00088 virtual void visitSystemBefore(TimedAutomataSystem *); 00089 virtual void visitVariable(variable_t &); 00090 virtual void visitConstant(variable_t &); 00091 virtual void visitState(state_t &); 00092 virtual void visitTransition(transition_t &); 00093 virtual void visitInstance(instance_t &); 00094 virtual void visitProperty(expression_t); 00095 }; 00096 } 00097 00098 #endif