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

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

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