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

systembuilder.hh

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_SYSTEMBUILDER_HH 00023 #define UTAP_SYSTEMBUILDER_HH 00024 00025 #include <cassert> 00026 #include <vector> 00027 #include <inttypes.h> 00028 00029 #include "utap/builder.hh" 00030 #include "utap/utap.hh" 00031 00032 namespace UTAP 00033 { 00034 00073 class SystemBuilder : public ParserBuilder 00074 { 00075 protected: 00076 // Error message for unsupported features 00077 static const char *const unsupported; 00078 static const char *const invalid_type; 00079 00080 /* Flag used to determine how strict we check for inclusion 00081 between ranges of integers. TODO: Replace this with a 00082 system, which reports a warning if there is a potential 00083 overflow. */ 00084 bool strict_range; 00085 00086 /* Pointer to the intermediate system under construction */ 00087 TimedAutomataSystem *system; 00088 00089 /* A pointer to the error handler */ 00090 ErrorHandler *errorHandler; 00091 00092 position_t position; 00093 00094 private: 00095 // 00096 // The stack of expression fragments. 00097 // 00098 class ExpressionFragments 00099 { 00100 private: 00101 std::vector<expression_t> data; 00102 public: 00103 expression_t &operator[] (int idx) 00104 { return data[data.size() - idx - 1]; } 00105 void push(expression_t e) 00106 { data.push_back(e); } 00107 void pop() 00108 { data.pop_back(); } 00109 void pop(int n); 00110 uint32_t size() { return data.size(); } 00111 } fragments; 00112 00113 // 00114 // The stack of type fragments. A type fragment is a pair 00115 // consiting of a type and an optional name (the name is 00116 // used for fields of a structure). 00117 // 00118 class TypeFragments 00119 { 00120 private: 00121 std::vector<std::pair<type_t, char *> > data; 00122 public: 00123 ~TypeFragments() 00124 { while (!data.empty()) pop(); } 00125 std::pair<type_t, char *> &operator[] (int idx) 00126 { return data[data.size() - idx - 1]; } 00127 void push(type_t value) 00128 { data.push_back(std::make_pair(value, (char*)NULL)); } 00129 void pop() 00130 { assert(!data.empty()); free(data.back().second); data.pop_back(); } 00131 } typeFragments; 00132 00133 // 00134 // Support for handling template and function parameters 00135 // 00136 00137 /* The params vector is used temporarily during parameter parsing */ 00138 frame_t params; 00139 00140 /* Current frame */ 00141 frame_t frame; 00142 00143 /* current parsing function structure */ 00144 function_t *currentFun; 00145 00146 template_t *currentTemplate; 00147 00148 /* stack of function body statement blocks */ 00149 std::vector<BlockStatement*> blocks; 00150 00151 // 00152 // Fields for handling transition labels 00153 // 00154 int32_t guard; 00155 int32_t sync; 00156 int32_t update; 00157 00158 // 00159 // Fields for function call and template instantiation handling 00160 // 00161 00162 /* list of expected arguments */ 00163 std::list<uint32_t> expectedArguments; 00164 00165 /* stack of function or template symbols */ 00166 std::vector<symbol_t> identifierStack; 00167 00168 // 00169 // Method for handling types 00170 // 00171 00172 type_t buildArrayType(type_t type, uint32_t dim); 00173 type_t getElementTypeOfArray(type_t type); 00174 type_t applyPrefix(int32_t prefix, type_t type); 00175 00176 // 00177 // Methods for handling expressions 00178 // 00179 00180 expression_t makeConstant(int value); 00181 00182 protected: 00183 00185 // allowProcessReferences() 00187 // If this method returns true, it is allowed to access the 00188 // private identifiers of a process by prefixing the identifier 00189 // with the process name. 00190 // 00191 // This is only interesting when parsing properties. In this case 00192 // the method should be overridden by a sub class. 00193 virtual bool allowProcessReferences() { return false; } 00194 00196 // property() 00198 // This method is called once for each property, which has 00199 // been parsed. The default implementation does nothing, so 00200 // you need to override this in a subclass. 00201 virtual void property(Constants::kind_t, int line, expression_t) {}; 00202 00203 public: 00204 00205 SystemBuilder(TimedAutomataSystem *); 00206 00207 virtual void setErrorHandler(ErrorHandler *); 00208 virtual void setPosition(const position_t &); 00209 00210 /************************************************************ 00211 * Query functions 00212 */ 00213 virtual bool isType(const char*); 00214 virtual bool isLocation(const char*); 00215 00216 /************************************************************ 00217 * Types 00218 */ 00219 virtual void typeName(int32_t prefix, const char* name, bool range); 00220 // 2 expr if range==true 00221 virtual void typeStruct(int32_t prefix, uint32_t fields); 00222 00223 virtual void structField(const char* name, uint32_t dim); 00224 // 1 type and dim array sizes 00225 virtual void structFieldEnd(); 00226 00227 virtual void declTypeDef(const char* name, uint32_t dim); 00228 // 1 type and dim array sizes 00229 virtual void declTypeDefEnd(); 00230 00231 /************************************************************ 00232 * Variable declarations 00233 */ 00234 virtual void declVar(const char* name, uint32_t dim, bool init); 00235 // 1 type, dims, initializer if init==true 00236 virtual void declVarEnd(); 00237 virtual void declInitialiserList(uint32_t num); // n initialisers 00238 virtual void declFieldInit(const char* name); // 1 initialiser 00239 00240 /************************************************************ 00241 * Function declarations 00242 */ 00243 virtual void declParameter(const char* name, bool reference, uint32_t dim); 00244 // 1 type, dim array sizes 00245 virtual void declParameterEnd(); // pop parameter type 00246 00247 virtual void declFuncBegin(const char* name, uint32_t n); // n paramaters 00248 virtual void declFuncEnd(); // 1 block 00249 00250 /************************************************************ 00251 * Process declarations 00252 */ 00253 virtual void procBegin(const char* name, uint32_t n); // n parameters 00254 virtual void procEnd(); // 1 ProcBody 00255 virtual void procState(const char* name, bool hasInvariant); // 1 expr 00256 virtual void procStateCommit(const char* name); // mark previously decl. state 00257 virtual void procStateUrgent(const char* name); // mark previously decl. state 00258 virtual void procStateInit(const char* name); // mark previously decl. state 00259 virtual void procTransition(const char* from, const char* to); 00260 // 1 epxr,1sync,1expr 00261 virtual void procGuard(); 00262 virtual void procSync(Constants::synchronisation_t type); // 1 expr 00263 virtual void procUpdate(); 00264 00265 /************************************************************ 00266 * Statements 00267 */ 00268 virtual void blockBegin(); 00269 virtual void blockEnd(); 00270 virtual void emptyStatement(); 00271 virtual void forBegin(); 00272 virtual void forEnd(); // 3 expr, 1 stat 00273 virtual void whileBegin(); 00274 virtual void whileEnd(); // 1 expr, 1 stat 00275 virtual void doWhileBegin(); 00276 virtual void doWhileEnd(); // 1 stat, 1 expr 00277 virtual void ifBegin(); 00278 virtual void ifElse(); 00279 virtual void ifEnd(bool); // 1 expr, 1 or 2 statements 00280 virtual void breakStatement(); 00281 virtual void continueStatement(); 00282 virtual void switchBegin(); 00283 virtual void switchEnd(); // 1 expr, 1+ case/default 00284 virtual void caseBegin(); 00285 virtual void caseEnd(); // 1 expr, 0+ stat 00286 virtual void defaultBegin(); 00287 virtual void defaultEnd(); // 0+ statements 00288 virtual void exprStatement(); // 1 expr 00289 virtual void returnStatement(bool); // 1 expr if argument is true 00290 00291 /************************************************************ 00292 * Expressions 00293 */ 00294 virtual void exprTrue(); 00295 virtual void exprFalse(); 00296 virtual void exprId(const char * varName); 00297 virtual void exprNat(int32_t); // natural number 00298 virtual void exprCallBegin(const char * functionName); 00299 virtual void exprCallEnd(uint32_t n); // n exprs as arguments 00300 virtual void exprArg(uint32_t n); // 1 exprs as n-th argument for fn-call 00301 virtual void exprArray(); // 2 expr 00302 virtual void exprPostIncrement(); // 1 expr 00303 virtual void exprPreIncrement(); // 1 expr 00304 virtual void exprPostDecrement(); // 1 expr 00305 virtual void exprPreDecrement(); // 1 expr 00306 virtual void exprAssignment(Constants::kind_t op); // 2 expr 00307 virtual void exprUnary(Constants::kind_t unaryop); // 1 expr 00308 virtual void exprBinary(Constants::kind_t binaryop); // 2 expr 00309 virtual void exprInlineIf(); // 3 expr 00310 virtual void exprComma(); // 2 expr 00311 virtual void exprDot(const char *); // 1 expr 00312 virtual void exprDeadlock(); 00313 00314 /************************************************************ 00315 * System declaration 00316 */ 00317 virtual void instantiationBegin(const char*, const char*); 00318 virtual void instantiationEnd(const char *, const char *, uint32_t n); // n arguments 00319 virtual void process(const char*); 00320 00321 virtual void done(); 00322 00323 virtual void property(Constants::kind_t, int line); 00324 00325 /******************************************************************** 00326 * Guiding 00327 */ 00328 00329 virtual void beforeUpdate(); 00330 virtual void afterUpdate(); 00331 }; 00332 } 00333 #endif

Generated on Sat May 15 12:33:41 2004 for libutap by doxygen 1.3.7