00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef CBZ_C_BREEZE_H
00038 #define CBZ_C_BREEZE_H
00039
00040
00041
00042 #ifdef _WIN32
00043
00044 #pragma warning(disable:4786)
00045 #pragma warning(disable:4503)
00046
00047 #pragma warning(disable:4800)
00048 #endif //
00049
00050
00051
00052
00053 #include <iostream>
00054 #include <fstream>
00055 #include <backward/strstream>
00056 #include <string>
00057 #include <list>
00058 #include <vector>
00059 #include <map>
00060 #include <algorithm>
00061 #include <functional>
00062
00063 #ifndef _WIN32
00064 typedef std::ostrstream ostringstream;
00065 #endif //
00066
00067 #include <assert.h>
00068 #include <stdio.h>
00069
00070
00071
00072 class Node;
00073 class unitNode;
00074 class defNode;
00075 class declNode;
00076 class typeNode;
00077 class primNode;
00078 class tdefNode;
00079 class ptrNode;
00080 class arrayNode;
00081 class funcNode;
00082 class sueNode;
00083 class structNode;
00084 class unionNode;
00085 class enumNode;
00086 class suespecNode;
00087 class exprNode;
00088 class constNode;
00089 class idNode;
00090 class binaryNode;
00091 class unaryNode;
00092 class castNode;
00093 class commaNode;
00094 class ternaryNode;
00095 class callNode;
00096 class initializerNode;
00097 class stmtNode;
00098 class blockNode;
00099 class basicblockNode;
00100 class exprstmtNode;
00101 class targetNode;
00102 class labelNode;
00103 class caseNode;
00104 class selectionNode;
00105 class ifNode;
00106 class switchNode;
00107 class loopNode;
00108 class whileNode;
00109 class doNode;
00110 class forNode;
00111 class jumpNode;
00112 class gotoNode;
00113 class continueNode;
00114 class breakNode;
00115 class returnNode;
00116 class attribNode;
00117 class procNode;
00118 class textNode;
00119 class CBZ;
00120 class Containers;
00121 class Coord;
00122 class Datatype;
00123
00124 class Symbols;
00125 class Identifiers_table;
00126 class Tags_table;
00127 class Externals_table;
00128
00129 class FlowVal;
00130 class FlowProblem;
00131 class Annote;
00132
00133
00134 using namespace std;
00135
00136 typedef list< Node * > node_list;
00137 typedef node_list::iterator node_list_p;
00138
00139 typedef list< exprNode * > expr_list;
00140 typedef expr_list::iterator expr_list_p;
00141
00142 typedef list< declNode * > decl_list;
00143 typedef decl_list::iterator decl_list_p;
00144
00145 typedef list< targetNode * > target_list;
00146 typedef target_list::iterator target_list_p;
00147
00148 typedef list< attribNode * > attrib_list;
00149 typedef attrib_list::iterator attrib_list_p;
00150
00151 typedef list< stmtNode * > stmt_list;
00152 typedef stmt_list::iterator stmt_list_p;
00153
00154 typedef list< gotoNode * > goto_list;
00155 typedef goto_list::iterator goto_list_p;
00156
00157 typedef list< defNode * > def_list;
00158 typedef def_list::iterator def_list_p;
00159
00160 typedef list< Annote * > annote_list;
00161 typedef annote_list::iterator annote_list_p;
00162
00163 typedef list< unitNode * > unit_list;
00164 typedef unit_list::iterator unit_list_p;
00165
00166 typedef vector< string > str_vec;
00167 typedef str_vec::iterator str_vec_p;
00168
00169 typedef list< string > str_list;
00170 typedef str_list::iterator str_list_p;
00171
00172 typedef list< textNode * > text_list;
00173 typedef text_list::iterator text_list_p;
00174
00175 typedef list< suespecNode * > suespec_list;
00176 typedef suespec_list::iterator suespec_list_p;
00177
00178 typedef list< basicblockNode * > basicblock_list;
00179 typedef basicblock_list::iterator basicblock_list_p;
00180
00181 class Visitor;
00182 class Walker;
00183 class Changer;
00184
00185 class output_context;
00186
00187
00188
00189 typedef map<Node *,
00190 unsigned int,
00191 less< Node * > > numbering_map;
00192
00193
00194
00195
00196 class CBZ {
00197
00198 public:
00199
00200
00201 static unit_list Program;
00202
00203
00204 static str_vec Files;
00205
00206
00207 static string input_suffix ;
00208 static string output_suffix ;
00209
00210
00211 static string preproc;
00212 static string default_preproc ;
00213 static string gcc_preproc ;
00214 static string ansi_preproc ;
00215
00216
00217
00218 static float VersionNumber ;
00219 static string VersionDate ;
00220 static string Executable;
00221
00222
00223 static int WarningLevel ;
00224
00225
00226 static str_list * cpp_flags;
00227
00228
00229
00230 static unitNode * current_unit;
00231 static int current_file;
00232 static int current_line;
00233 static int current_offset;
00234
00235 static text_list pragmas;
00236
00237 static void set_file(const char *name, int line, bool is_new_file);
00238
00239 static bool is_file_included();
00240
00241 static void char_to_text(char * array, unsigned char value);
00242
00243
00244
00245 static string PhaseName;
00246
00247
00248
00249 static bool QuietlyIgnore;
00250 static bool DebugLex;
00251 static bool PrintSymTables;
00252 static bool TrackInsertSymbol;
00253 static bool PrintLineOffset;
00254 static bool IgnoreLineDirectives;
00255 static bool ANSIOnly;
00256 static bool FormatReadably;
00257 static bool Preprocess;
00258 static bool ShowPreprocess;
00259 static bool GCCisms;
00260
00261
00262
00263 static bool OldStyleFunctionDefinition;
00264
00265
00266
00267 static void Fail(const string file, int line, const string msg);
00268 static void SyntaxError(string s);
00269 static void Warning(int level, string s);
00270 static void SyntaxError(Coord c, string s);
00271 static void Warning(int level, Coord c, string s);
00272 static void WarnAboutPrecedence(unsigned int op_id, exprNode * the_expr);
00273 };
00274
00275
00276
00277
00278
00279 typedef enum {
00280
00281 Const, Id, Binary, Unary, Cast, Comma, Ternary, Call, Initializer,
00282
00283
00284 Label, Switch, Case, If, While, Do, For, Goto, Continue,
00285 Break, Return, Block,
00286
00287
00288 Prim, Tdef, Ptr, Array, Func, Struct, Union, Enum, sueSpec,
00289
00290
00291
00292 Decl,
00293
00294
00295 Attrib,
00296
00297
00298 Proc,
00299
00300
00301 Text,
00302
00303
00304 Expr,
00305
00306
00307 Undeclared,
00308
00309
00310
00311 Unit,
00312
00313
00314
00315 Meta
00316
00317 } NodeType;
00318
00319
00320
00321 typedef enum {
00322 Redecl,
00323 NoRedecl,
00324 SU,
00325 Formal
00326
00327 } ScopeState;
00328
00329
00330
00331
00332 typedef enum { Right, Left } Assoc;
00333
00334
00335
00336 #include "coord.h"
00337 #include "operators.h"
00338 #include "basic_type.h"
00339 #include "constant.h"
00340 #include "annote.h"
00341 #include "ast.h"
00342 #include "visitor.h"
00343 #include "walker.h"
00344 #include "changer.h"
00345 #include "dataflow.h"
00346 #include "symbol.h"
00347 #include "phase.h"
00348 #include "output_context.h"
00349
00350
00351
00352 struct _TQ {
00353 typeNode::Type_qualifiers tq;
00354 declNode::Storage_class sc;
00355 simpleCoord coord;
00356 };
00357
00358 struct _TYPE {
00359 typeNode * ty;
00360 declNode::Storage_class sc;
00361 };
00362
00363
00364 #endif // CBZ_C_BREEZE_H