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

common.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 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_COMMON_HH
00023 #define UTAP_COMMON_HH
00024 
00025 #ifdef __MINGW32__
00026 #include <stdint.h>
00027 #else
00028 #include <inttypes.h>
00029 #endif
00030 #include <string>
00031 #include <iostream>
00032 #include <vector>
00033 
00034 namespace UTAP
00035 {
00036     class XPath
00037     {
00038     public:
00039         virtual ~XPath() {};
00040         virtual std::string get() const = 0;
00041     };
00042     
00043     struct position_t 
00044     {
00045         int32_t first_line, first_column, last_line, last_column;
00046         position_t() {}
00047         position_t(int fl, int fc, int ll, int lc)
00048             : first_line(fl), first_column(fc), last_line(ll), last_column(lc)
00049             {}
00050     };
00051 
00052     class ErrorHandler
00053     {
00054     public:
00055         struct error_t
00056         {
00057             int32_t fline, fcolumn, lline, lcolumn;
00058 
00059             std::string xpath;
00060             std::string msg;
00061 
00062             error_t(int32_t fl, int32_t fc, int32_t ll, int32_t lc)
00063                 : fline(fl), fcolumn(fc), lline(ll), lcolumn(lc)
00064                   {}
00065 
00066             error_t(const error_t &err)
00067                 : fline(err.fline), fcolumn(err.fcolumn),
00068                   lline(err.lline), lcolumn(err.lcolumn),
00069                   xpath(err.xpath), msg(err.msg) {}
00070 
00071             void setPath(std::string path) { xpath = path; }
00072             void setMessage(std::string value) { msg = value; }
00073         };
00074     private:
00075         std::vector<error_t> errors;
00076         std::vector<error_t> warnings;
00077         const XPath *currentPath;
00078         int first_line, first_column, last_line, last_column;
00079     public:
00080         ErrorHandler();
00081 
00082         // Sets the call back object for the current patch.
00083         // Clears the current position.
00084         void setCurrentPath(const XPath *path);
00085 
00086         // Sets the current position of the parser. Any errors or
00087         // warnings will be assumed to be at this position.
00088         void setCurrentPosition(int first_line, int first_column, int last_line, int last_column);
00089 
00090         // Sets the current position of the parser. Any errors or
00091         // warnings will be assumed to be at this position.
00092         void setCurrentPosition(const position_t &);
00093 
00094         // Called when an error is detected
00095         void handleError(const char *, ...);
00096 
00097         // Called when a warning is issued
00098         void handleWarning(const char *, ...);
00099 
00100         // Returns the errors
00101         const std::vector<error_t> &getErrors() const;
00102 
00103         // Returns the warnings
00104         const std::vector<error_t> &getWarnings() const;
00105 
00106         // True if there are one or more errors
00107         bool hasErrors() const;
00108 
00109         // True if there are one or more warnings
00110         bool hasWarnings() const;
00111 
00112         // Clears the list of errors and warnings
00113         void clear();
00114     };
00115 
00116     namespace Constants
00117     {
00118         enum kind_t 
00119         {
00120             PLUS = 0,
00121             MINUS = 1,
00122             MULT = 2,
00123             DIV = 3,
00124             MOD = 4,
00125             BIT_AND = 5,
00126             BIT_OR = 6,
00127             BIT_XOR = 7,
00128             BIT_LSHIFT = 8,
00129             BIT_RSHIFT = 9,
00130             AND = 10,
00131             OR = 11,
00132             MIN = 12,
00133             MAX = 13,
00134             RATE = 14,
00135 
00136             /********************************************************
00137              * Relational operators
00138              */
00139             LT = 20,
00140             LE = 21,
00141             EQ = 22,
00142             NEQ = 23,
00143             GE = 24,
00144             GT = 25,
00145 
00146             /********************************************************
00147              * Unary operators
00148              */
00149             NOT = 30,
00150 
00151             /********************************************************
00152              * Assignment operators
00153              */
00154             ASSIGN = 40,
00155             ASSPLUS = 41,
00156             ASSMINUS = 42,
00157             ASSDIV = 43,
00158             ASSMOD = 44,
00159             ASSMULT = 45,
00160             ASSAND = 46,
00161             ASSOR = 47,
00162             ASSXOR = 48,
00163             ASSLSHIFT = 49,
00164             ASSRSHIFT = 50,
00165 
00166             /*******************************************************
00167              * CTL Quantifiers
00168              */
00169             EF = 60,
00170             EG = 61,
00171             AF = 62,
00172             AG = 63,
00173             LEADSTO = 64,
00174 
00175             /*******************************************************
00176              * Additional constants used by ExpressionProgram's and
00177              * the TypeCheckBuilder (but not by the parser, although
00178              * some of then ought to be used, FIXME).
00179              */
00180             IDENTIFIER = 512,
00181             CONSTANT = 513,
00182             ARRAY = 514,
00183             POSTINCREMENT = 515,
00184             PREINCREMENT = 516,
00185             POSTDECREMENT = 517,
00186             PREDECREMENT = 518,
00187             UNARY_MINUS = 519,
00188             LIST = 520,
00189             DOT = 521,
00190             INLINEIF = 522,
00191             COMMA = 523,
00192             SYNC = 525,
00193             DEADLOCK = 526,
00194             FUNCALL = 527
00195         };
00196 
00197         /**********************************************************
00198          * Synchronisations:
00199          */
00200         enum synchronisation_t 
00201         {
00202             SYNC_QUE = 0,
00203             SYNC_BANG = 1
00204         };
00205     }
00206 
00208     typedef enum 
00209     { 
00210         S_XTA, // entire system 
00211         S_DECLARATION, S_LOCAL_DECL, S_INST, S_SYSTEM, S_PARAMETERS, 
00212         S_INVARIANT, S_GUARD, S_SYNC, S_ASSIGN, S_EXPRESSION, S_PROPERTY
00213     } xta_part_t;
00214 
00215 }
00216 
00217 std::ostream &operator <<(std::ostream &out, const UTAP::ErrorHandler::error_t &e);
00218 
00219 #endif

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