|
||
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
nodeinfo.hGo to the documentation of this file.00001 // $Id: nodeinfo.h,v 1.4 2003/08/11 19:05:01 toktb Exp $ 00002 00003 // ---------------------------------------------------------------------- 00004 // 00005 // J-Breeze 00006 // Java Compiler Framework 00007 // 00008 // Copyright (c) 2001 University of Texas at Austin 00009 // 00010 // Teck B. Tok 00011 // Samuel Z. Guyer 00012 // Daniel A. Jimenez 00013 // Calvin Lin 00014 // 00015 // Permission is hereby granted, free of charge, to any person 00016 // obtaining a copy of this software and associated documentation 00017 // files (the "Software"), to deal in the Software without 00018 // restriction, including without limitation the rights to use, copy, 00019 // modify, merge, publish, distribute, and/or sublicense copies 00020 // of the Software, and to permit persons to whom the Software is 00021 // furnished to do so, subject to the following conditions: 00022 // 00023 // The above copyright notice and this permission notice shall be 00024 // included in all copies or substantial portions of the Software. 00025 // 00026 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00027 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00028 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00029 // NONINFRINGEMENT. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT 00030 // AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 00031 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 00032 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00033 // THE SOFTWARE. 00034 // 00035 // J-Breeze extends from C-Breeze (copyright University of Texas at 00036 // Austin), part of whose design is inspired by the C-to-C Translator 00037 // from MIT Laboratory for Computer Science. 00038 // 00039 // ---------------------------------------------------------------------- 00040 00041 #ifndef NODEINFO_H 00042 #define NODEINFO_H 00043 00044 #ifdef J_BREEZE 00045 #include "j_breeze.h" 00046 #include "arrayclass.h" 00047 #else 00048 #include "c_breeze.h" 00049 #endif 00050 00051 /* Note: additional flags needed if this file is compiled for different 00052 * purpose. If it is part of J-Breeze compilation, add in additional flag: 00053 * -DJ_BREEZE 00054 */ 00055 00082 class NodeInfo { 00083 private: 00084 FILE *_file; 00085 bool _read_mode; 00086 bool _verbose; 00087 00088 //str_list strings; 00089 map<int,string> strings; 00090 map<int,Node*> index2node; 00091 map<Node*,int> node2index; 00092 int _line; 00093 00094 #ifndef J_BREEZE 00095 // canonicalize arrays. for J-Breeze, already handled by ArrayClass. 00096 // for primitive base type 00097 static list<arrayNode*> _canonical1; 00098 // for reference base type, map from an array's component type to its 00099 // canonical array. 00100 static map<typeNode*,arrayNode*> _canonical2; 00101 #endif 00102 00103 public: 00105 // @{ 00117 NodeInfo(string filename, bool readmode, bool verbose); 00118 00120 ~NodeInfo(); 00121 // @} 00122 00124 // @{ 00126 inline bool read_mode(void) { return _read_mode; } 00127 00130 inline string index(int i) { return strings[i]; } 00131 00135 inline Node *indexNode(int i) { return index2node[i]; } 00136 00141 inline int nodeIndex(Node *node) { 00142 if(!node) return 0; 00143 if(node->typ()==Array) 00144 #ifdef J_BREEZE 00145 return node2index[ ArrayClass::canonical((arrayNode*)node) ]; 00146 #else 00147 return node2index[ canonical((arrayNode*)node) ]; 00148 #endif 00149 return node2index[node]; 00150 } 00151 00153 inline int nStrings() { return strings.size(); } 00154 // @} 00155 00165 // @{ 00171 inline int current_line(void) { return _line; } 00172 00174 void writeType(typeNode *t); 00175 #ifdef J_BREEZE 00176 00177 void writeClassOrInterface(referenceNode *t); 00179 void writeMethod(methodNode *m); 00181 void writeConstructor(constructorNode *c); 00183 void writeFieldvar(fieldvarNode *fv, declNode *d=0); 00185 void writeFieldinit(fieldinitNode *fi); 00186 #else 00187 00188 void writeProc(procNode *proc); 00189 #endif 00190 00191 /* for the following, container = line_number refering to the node containing 00192 * the expression/statement */ 00193 00197 void writeStmt(stmtNode *s, int container=-1); 00198 00199 #ifdef J_BREEZE 00200 00203 void writeCall(mcallNode *c, int container=-1); 00204 00208 void writeNew(newNode *n, int container=-1); 00209 00210 #else 00211 00214 void writeCall(callNode *c, int container=-1); 00215 #endif 00216 00223 void writeExpr(exprNode *expr, int container=-1); 00224 00228 void writeDecl(declNode *d, int container=-1); 00229 00234 void writeString(string s); 00235 00236 #ifdef J_BREEZE 00237 00241 static string type_string(typeNode *ty); 00242 #endif 00243 // @} 00244 00245 #ifndef J_BREEZE 00246 00251 static arrayNode *canonical(arrayNode *array); 00252 #endif 00253 00254 private: 00255 class NodeLocator; 00258 friend class NodeLocator; 00259 00263 // @{ 00264 // extract the coord from inside the string ("...@coord") 00265 // also obtain the corresponding unitNode 00266 Coord getCoord(string s, unitNode **unit); 00267 00268 // search for a class/interface in an unit. s is the fully qualified name. 00269 typeNode *getType(unitNode *unit, string s); 00270 00271 #ifdef J_BREEZE 00272 // search for a class/interface using standardPackage::findType 00273 typeNode *getLibType(string s); 00274 #endif 00275 00276 #ifndef J_BREEZE 00277 static string type_name(typeNode *t); 00278 static typeNode *def_type(typeNode *ty); 00279 #endif 00280 // @} 00281 00285 // @{ 00286 Node *getNode(string s); 00287 00288 typeNode *readType(string s); 00289 #ifdef J_BREEZE 00290 typeNode *readClassOrInterface(string s); 00291 methodNode *readMethod(string s); 00292 constructorNode *readConstructor(string s); 00293 fieldvarNode *readFieldvar(string s); 00294 fieldinitNode *readFieldinit(string s); 00295 mcallNode *readCall(string s); 00296 newNode *readNew(string s); 00297 #else 00298 procNode *readProc(string s); 00299 typeNode *readsuef(string s); 00300 callNode *readCall(string s); 00301 #endif 00302 Node *readExprOrStmt(string s, NodeType typ); 00303 declNode *readDecl(string s); 00304 00305 bool match_args(string args, decl_list formals); 00306 // @} 00307 }; 00308 00309 #endif |
Generated on February 1, 2006
Back to the C-Breeze home page