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             FORALL = 31,
00151 
00152             /********************************************************
00153              * Assignment operators
00154              */
00155             ASSIGN = 40,
00156             ASSPLUS = 41,
00157             ASSMINUS = 42,
00158             ASSDIV = 43,
00159             ASSMOD = 44,
00160             ASSMULT = 45,
00161             ASSAND = 46,
00162             ASSOR = 47,
00163             ASSXOR = 48,
00164             ASSLSHIFT = 49,
00165             ASSRSHIFT = 50,
00166 
00167             /*******************************************************
00168              * CTL Quantifiers
00169              */
00170             EF = 60,
00171             EG = 61,
00172             AF = 62,
00173             AG = 63,
00174             LEADSTO = 64,
00175 
00176             /*******************************************************
00177              * Additional constants used by ExpressionProgram's and
00178              * the TypeCheckBuilder (but not by the parser, although
00179              * some of then ought to be used, FIXME).
00180              */
00181             IDENTIFIER = 512,
00182             CONSTANT = 513,
00183             ARRAY = 514,
00184             POSTINCREMENT = 515,
00185             PREINCREMENT = 516,
00186             POSTDECREMENT = 517,
00187             PREDECREMENT = 518,
00188             UNARY_MINUS = 519,
00189             LIST = 520,
00190             DOT = 521,
00191             INLINEIF = 522,
00192             COMMA = 523,
00193             SYNC = 525,
00194             DEADLOCK = 526,
00195             FUNCALL = 527
00196         };
00197 
00198         /**********************************************************
00199          * Synchronisations:
00200          */
00201         enum synchronisation_t 
00202         {
00203             SYNC_QUE = 0,
00204             SYNC_BANG = 1
00205         };
00206     }
00207 
00209     typedef enum 
00210     { 
00211         S_XTA, // entire system 
00212         S_DECLARATION, S_LOCAL_DECL, S_INST, S_SYSTEM, S_PARAMETERS, 
00213         S_INVARIANT, S_SELECT, S_GUARD, S_SYNC, S_ASSIGN, 
00214         S_EXPRESSION, S_PROPERTY
00215     } xta_part_t;
00216 
00217 }
00218 
00219 std::ostream &operator <<(std::ostream &out, const UTAP::ErrorHandler::error_t &e);
00220 
00221 #endif

Generated on Thu Nov 10 13:16:12 2005 for libutap by  doxygen 1.4.2