Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

c_breeze.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 //  C-Breeze
00004 //  C Compiler Framework
00005 // 
00006 //  Copyright (c) 2000 University of Texas at Austin
00007 // 
00008 //  Samuel Z. Guyer
00009 //  Daniel A. Jimenez
00010 //  Calvin Lin
00011 // 
00012 //  Permission is hereby granted, free of charge, to any person
00013 //  obtaining a copy of this software and associated documentation
00014 //  files (the "Software"), to deal in the Software without
00015 //  restriction, including without limitation the rights to use, copy,
00016 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00017 //  of the Software, and to permit persons to whom the Software is
00018 //  furnished to do so, subject to the following conditions:
00019 //  
00020 //  The above copyright notice and this permission notice shall be
00021 //  included in all copies or substantial portions of the Software.
00022 //  
00023 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00024 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00025 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00026 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00027 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00028 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00029 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00030 //  THE SOFTWARE.
00031 //
00032 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00033 //  Computer Science for inspiring parts of the C-Breeze design.
00034 //
00035 // ----------------------------------------------------------------------
00036 
00037 #ifndef CBZ_C_BREEZE_H
00038 #define CBZ_C_BREEZE_H
00039 
00040 
00041 // EDB
00042 #ifdef _WIN32
00043 // Disable warnings about long (> 255 chars) identifiers.
00044 #pragma warning(disable:4786)
00045 #pragma warning(disable:4503)
00046 // Disable warnings about int being forced to bool.
00047 #pragma warning(disable:4800)
00048 #endif // 
00049 
00050 // -- Include the necessary standard library stuff
00051 
00052 // #include <ios>
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 // -- Declare all the classes ahead of time...
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 // EDB
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 // --- Map for node numberings
00188 
00189   typedef map<Node *,
00190           unsigned int,
00191           less< Node * > > numbering_map;
00192 
00193 // --- The CBZ class holds many of the global configuration values as
00194 // static data members.
00195 
00196 class CBZ {
00197 
00198 public:
00199 
00200   // -- The parsed program
00201   static unit_list Program;
00202 
00203   // -- Global list of all files
00204   static str_vec Files;
00205           
00206   // -- expected suffixes for input and output files 
00207   static string input_suffix ;
00208   static string output_suffix ;
00209 
00210   // -- preprocessor command lines 
00211   static string preproc;
00212   static string default_preproc ;
00213   static string gcc_preproc ;
00214   static string ansi_preproc  ;
00215 
00216   // -- Basic Global Variables 
00217 
00218   static float VersionNumber ;
00219   static string VersionDate ;
00220   static string Executable;
00221 
00222   // -- default warning level 
00223   static int WarningLevel ;
00224 
00225   // -- CPP flags
00226   static str_list * cpp_flags;
00227 
00228   // -- Parsing state
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   // -- Current phase in processing
00244 
00245   static string PhaseName;
00246 
00247   // -- Command Line Flags
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   // --- Flag old-style fdcls
00262 
00263   static bool OldStyleFunctionDefinition;
00264 
00265   // --- Errors, warnings, failures...
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 //   Node types
00277 // --------------------------------------------------------------------
00278 
00279 typedef enum {
00280   // expression nodes
00281   Const, Id, Binary, Unary, Cast, Comma, Ternary, Call, Initializer,
00282 
00283   // statement nodes 
00284   Label, Switch, Case, If, While, Do, For, Goto, Continue, 
00285   Break, Return, Block, 
00286 
00287   // type nodes 
00288   Prim, Tdef, Ptr, Array, Func, Struct, Union, Enum, sueSpec,
00289 
00290 
00291   // declaration node 
00292   Decl, 
00293 
00294   // GCC __attribute__ extension 
00295   Attrib, 
00296 
00297   // procedure def node
00298   Proc,
00299 
00300   // random text and preprocessor command node
00301   Text,
00302 
00303   // A statement that just consists of an expression
00304   Expr,
00305 
00306   // Special undeclared node
00307   Undeclared,
00308 
00309   // Translation unit
00310 
00311   Unit,
00312 
00313   // Indicates that the node is a meta-variable
00314 
00315   Meta
00316 
00317 } NodeType;
00318 
00319 // A declarator has several context-dependent scoping options:
00320 
00321 typedef enum {
00322   Redecl,    // may redeclare a typdef name
00323   NoRedecl,  // may not redeclare a typedef name
00324   SU,        // is a structure or union field
00325   Formal     // is a formal parameter, goes into scope of the following body
00326              //  (storage class NOT extern, static, typedef, auto)
00327 } ScopeState;
00328 
00329 // -- Assoc is used in the output phase to control associativity
00330 // for operators and context for types.
00331 
00332 typedef enum { Right, Left } Assoc;
00333 
00334 // -- Inlcude other headers, including the AST
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 // -- Struct to hold parsing information about type qualifiers...
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

Generated on Thu Jan 10 12:06:18 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001