Changeset a08ba92 for translator/SymTab/Indexer.cc
- Timestamp:
- May 19, 2015, 4:58:14 PM (11 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, stuck-waitfor-destruct, with_gc
- Children:
- 843054c2
- Parents:
- 01aeade
- File:
-
- 1 edited
-
translator/SymTab/Indexer.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/Indexer.cc
r01aeade ra08ba92 10 10 // Created On : Sun May 17 21:37:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:38:44201513 // Update Count : 212 // Last Modified On : Tue May 19 16:49:55 2015 13 // Update Count : 3 14 14 // 15 15 … … 26 26 27 27 namespace SymTab { 28 Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {}29 30 Indexer::~Indexer() {}31 32 void Indexer::visit( ObjectDecl *objectDecl ) {28 Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {} 29 30 Indexer::~Indexer() {} 31 32 void Indexer::visit( ObjectDecl *objectDecl ) { 33 33 maybeAccept( objectDecl->get_type(), *this ); 34 34 maybeAccept( objectDecl->get_init(), *this ); … … 38 38 idTable.addDecl( objectDecl ); 39 39 } // if 40 }41 42 void Indexer::visit( FunctionDecl *functionDecl ) {40 } 41 42 void Indexer::visit( FunctionDecl *functionDecl ) { 43 43 if ( functionDecl->get_name() == "" ) return; 44 44 debugPrint( "Adding function " << functionDecl->get_name() << std::endl ); … … 49 49 maybeAccept( functionDecl->get_statements(), *this ); 50 50 leaveScope(); 51 }51 } 52 52 53 53 /******** … … 70 70 */ 71 71 72 void Indexer::visit( TypeDecl *typeDecl ) {72 void Indexer::visit( TypeDecl *typeDecl ) { 73 73 // see A NOTE ON THE ORDER OF TRAVERSAL, above 74 74 // note that assertions come after the type is added to the symtab, since they aren't part … … 81 81 typeTable.add( typeDecl ); 82 82 acceptAll( typeDecl->get_assertions(), *this ); 83 }84 85 void Indexer::visit( TypedefDecl *typeDecl ) {83 } 84 85 void Indexer::visit( TypedefDecl *typeDecl ) { 86 86 enterScope(); 87 87 acceptAll( typeDecl->get_parameters(), *this ); … … 90 90 debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl ); 91 91 typeTable.add( typeDecl ); 92 }93 94 void Indexer::visit( StructDecl *aggregateDecl ) {92 } 93 94 void Indexer::visit( StructDecl *aggregateDecl ) { 95 95 // make up a forward declaration and add it before processing the members 96 96 StructDecl fwdDecl( aggregateDecl->get_name() ); … … 107 107 // this addition replaces the forward declaration 108 108 structTable.add( aggregateDecl ); 109 }110 111 void Indexer::visit( UnionDecl *aggregateDecl ) {109 } 110 111 void Indexer::visit( UnionDecl *aggregateDecl ) { 112 112 // make up a forward declaration and add it before processing the members 113 113 UnionDecl fwdDecl( aggregateDecl->get_name() ); … … 123 123 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 124 124 unionTable.add( aggregateDecl ); 125 }126 127 void Indexer::visit( EnumDecl *aggregateDecl ) {125 } 126 127 void Indexer::visit( EnumDecl *aggregateDecl ) { 128 128 debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl ); 129 129 enumTable.add( aggregateDecl ); 130 130 // unlike structs, contexts, and unions, enums inject their members into the global scope 131 131 acceptAll( aggregateDecl->get_members(), *this ); 132 }133 134 void Indexer::visit( ContextDecl *aggregateDecl ) {132 } 133 134 void Indexer::visit( ContextDecl *aggregateDecl ) { 135 135 enterScope(); 136 136 acceptAll( aggregateDecl->get_parameters(), *this ); … … 140 140 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 141 141 contextTable.add( aggregateDecl ); 142 }143 144 void Indexer::visit( CompoundStmt *compoundStmt ) {142 } 143 144 void Indexer::visit( CompoundStmt *compoundStmt ) { 145 145 enterScope(); 146 146 acceptAll( compoundStmt->get_kids(), *this ); 147 147 leaveScope(); 148 }149 150 void Indexer::visit( ContextInstType *contextInst ) {148 } 149 150 void Indexer::visit( ContextInstType *contextInst ) { 151 151 acceptAll( contextInst->get_parameters(), *this ); 152 152 acceptAll( contextInst->get_members(), *this ); 153 }154 155 void Indexer::visit( StructInstType *structInst ) {153 } 154 155 void Indexer::visit( StructInstType *structInst ) { 156 156 if ( ! structTable.lookup( structInst->get_name() ) ) { 157 157 debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl ); … … 161 161 acceptAll( structInst->get_parameters(), *this ); 162 162 leaveScope(); 163 }164 165 void Indexer::visit( UnionInstType *unionInst ) {163 } 164 165 void Indexer::visit( UnionInstType *unionInst ) { 166 166 if ( ! unionTable.lookup( unionInst->get_name() ) ) { 167 167 debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl ); … … 171 171 acceptAll( unionInst->get_parameters(), *this ); 172 172 leaveScope(); 173 }174 175 void Indexer::visit( ForStmt *forStmt ) {176 // for statements introduce a level of scope177 enterScope();178 Visitor::visit( forStmt );179 leaveScope();180 }181 182 183 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const {173 } 174 175 void Indexer::visit( ForStmt *forStmt ) { 176 // for statements introduce a level of scope 177 enterScope(); 178 Visitor::visit( forStmt ); 179 leaveScope(); 180 } 181 182 183 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const { 184 184 idTable.lookupId( id, list ); 185 }186 187 DeclarationWithType* Indexer::lookupId( const std::string &id) const {185 } 186 187 DeclarationWithType* Indexer::lookupId( const std::string &id) const { 188 188 return idTable.lookupId(id); 189 }190 191 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {189 } 190 191 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const { 192 192 return typeTable.lookup( id ); 193 }194 195 StructDecl *Indexer::lookupStruct( const std::string &id ) const {193 } 194 195 StructDecl *Indexer::lookupStruct( const std::string &id ) const { 196 196 return structTable.lookup( id ); 197 }198 199 EnumDecl *Indexer::lookupEnum( const std::string &id ) const {197 } 198 199 EnumDecl *Indexer::lookupEnum( const std::string &id ) const { 200 200 return enumTable.lookup( id ); 201 }202 203 UnionDecl *Indexer::lookupUnion( const std::string &id ) const {201 } 202 203 UnionDecl *Indexer::lookupUnion( const std::string &id ) const { 204 204 return unionTable.lookup( id ); 205 }206 207 ContextDecl * Indexer::lookupContext( const std::string &id ) const {205 } 206 207 ContextDecl * Indexer::lookupContext( const std::string &id ) const { 208 208 return contextTable.lookup( id ); 209 }210 211 void Indexer::enterScope() {209 } 210 211 void Indexer::enterScope() { 212 212 if ( doDebug ) { 213 213 std::cout << "--- Entering scope" << std::endl; … … 219 219 unionTable.enterScope(); 220 220 contextTable.enterScope(); 221 }222 223 void Indexer::leaveScope() {221 } 222 223 void Indexer::leaveScope() { 224 224 using std::cout; 225 225 using std::endl; … … 240 240 unionTable.leaveScope(); 241 241 contextTable.leaveScope(); 242 }243 244 void Indexer::print( std::ostream &os, int indent ) const {245 using std::cerr;246 using std::endl;247 248 cerr << "===idTable===" << endl;249 idTable.dump( os );250 cerr << "===typeTable===" << endl;251 typeTable.dump( os );252 cerr << "===structTable===" << endl;253 structTable.dump( os );254 cerr << "===enumTable===" << endl;255 enumTable.dump( os );256 cerr << "===unionTable===" << endl;257 unionTable.dump( os );258 cerr << "===contextTable===" << endl;259 contextTable.dump( os );242 } 243 244 void Indexer::print( std::ostream &os, int indent ) const { 245 using std::cerr; 246 using std::endl; 247 248 cerr << "===idTable===" << endl; 249 idTable.dump( os ); 250 cerr << "===typeTable===" << endl; 251 typeTable.dump( os ); 252 cerr << "===structTable===" << endl; 253 structTable.dump( os ); 254 cerr << "===enumTable===" << endl; 255 enumTable.dump( os ); 256 cerr << "===unionTable===" << endl; 257 unionTable.dump( os ); 258 cerr << "===contextTable===" << endl; 259 contextTable.dump( os ); 260 260 #if 0 261 261 idTable.dump( os ); … … 266 266 contextTable.dump( os ); 267 267 #endif 268 }268 } 269 269 } // namespace SymTab 270 270
Note:
See TracChangeset
for help on using the changeset viewer.