expressionbuilder.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-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_EXPRESSIONBUILDER_HH
00023 #define UTAP_EXPRESSIONBUILDER_HH
00024 
00025 #include <stack>
00026 #include <vector>
00027 #include <cassert>
00028 
00029 #include "abstractbuilder.h"
00030 #include "utap.h"
00031 
00032 namespace UTAP
00033 {
00047     class ExpressionBuilder : public AbstractBuilder 
00048     {
00049     public:
00050         class ExpressionFragments 
00051         {
00052         private:
00053             std::vector<expression_t> data;
00054         public:
00055             expression_t &operator[] (int idx)
00056                 { return data[data.size() - idx - 1]; }
00057             void push(expression_t e)
00058                 { data.push_back(e); }
00059             void pop()
00060                 { data.pop_back(); }
00061             void pop(uint32_t n);
00062             uint32_t size() { return data.size(); }
00063         };
00064 
00065         class TypeFragments 
00066         {
00067         private:
00068             std::vector<type_t> data;
00069         public:
00070             type_t &operator[](int idx)
00071                 { return data[data.size() - idx - 1]; }
00072             void push(type_t value)
00073                 { data.push_back(value); }
00074             void pop()
00075                 { assert(!data.empty()); data.pop_back(); }
00076             void duplicate()
00077                 { assert(!data.empty()); data.push_back(data.back()); }
00078         };
00079 
00080     protected:
00082         ExpressionFragments fragments;
00083 
00085         TypeFragments typeFragments;
00086 
00088         std::stack<frame_t> frames;
00089 
00091         TimedAutomataSystem *system;
00092 
00094         template_t *currentTemplate;
00095 
00097         int32_t scalar_count;
00098 
00100         void pushFrame(frame_t);
00101         
00103         void popFrame();
00104 
00105         bool resolve(std::string, symbol_t &);
00106 
00107         expression_t makeConstant(int value);
00108 
00114         type_t applyPrefix(PREFIX, type_t type);
00115 
00124         virtual bool allowProcessReferences() { return false; }
00125 
00126     public:
00127         ExpressionBuilder(TimedAutomataSystem *);
00128         ExpressionFragments &getExpressions();
00129 
00130         virtual void addPosition(
00131             uint32_t position, uint32_t offset, uint32_t line, std::string path);
00132 
00133         virtual void handleError(std::string);
00134         virtual void handleWarning(std::string);
00135         virtual void typeDuplicate();
00136         virtual void typePop();
00137         virtual void typeBool(PREFIX);
00138         virtual void typeInt(PREFIX);
00139         virtual void typeBoundedInt(PREFIX);
00140         virtual void typeChannel(PREFIX);
00141         virtual void typeClock();
00142         virtual void typeVoid();
00143         virtual void typeScalar(PREFIX);
00144         virtual void typeName(PREFIX, const char* name);
00145         virtual bool isType(const char*);
00146         virtual void exprTrue();
00147         virtual void exprFalse();
00148         virtual void exprId(const char * varName);
00149         virtual void exprNat(int32_t);
00150         virtual void exprCallBegin();
00151         virtual void exprCallEnd(uint32_t n);
00152         virtual void exprArray();
00153         virtual void exprPostIncrement();
00154         virtual void exprPreIncrement(); 
00155         virtual void exprPostDecrement();
00156         virtual void exprPreDecrement(); 
00157         virtual void exprAssignment(Constants::kind_t op);
00158         virtual void exprUnary(Constants::kind_t unaryop); 
00159         virtual void exprBinary(Constants::kind_t binaryop); 
00160         virtual void exprTernary(Constants::kind_t ternaryop, bool firstMissing);
00161         virtual void exprInlineIf(); 
00162         virtual void exprComma(); 
00163         virtual void exprDot(const char *);
00164         virtual void exprDeadlock();
00165         virtual void exprForAllBegin(const char *name);
00166         virtual void exprForAllEnd(const char *name);
00167         virtual void exprExistsBegin(const char *name);
00168         virtual void exprExistsEnd(const char *name);
00169     };
00170 }
00171 
00172 #endif

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