Changeset 17cd4eb for translator/SymTab
- Timestamp:
- Jan 7, 2015, 6:04:42 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, with_gc
- Children:
- 0b8cd722
- Parents:
- d9a0e76
- Location:
- translator/SymTab
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/Indexer.cc
rd9a0e76 r17cd4eb 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Indexer.cc,v 1.12 2005/08/29 20:14:17 rcbilson Exp $5 *6 */7 8 1 #include "SynTree/Declaration.h" 9 2 #include "SynTree/Type.h" … … 15 8 #include "utility.h" 16 9 17 #define debugPrint(x) if ( doDebug ) { std::cout << x; }10 #define debugPrint(x) if ( doDebug ) { std::cout << x; } 18 11 19 12 namespace SymTab { 20 21 Indexer::Indexer( bool useDebug ) 22 : doDebug( useDebug ) 23 { 24 } 25 26 Indexer::~Indexer() 27 { 28 } 29 30 void 31 Indexer::visit( ObjectDecl *objectDecl ) 32 { 33 maybeAccept( objectDecl->get_type(), *this ); 34 maybeAccept( objectDecl->get_init(), *this ); 35 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); 36 if( objectDecl->get_name() != "" ) { 37 debugPrint( "Adding object " << objectDecl->get_name() << std::endl ); 38 idTable.addDecl( objectDecl ); 39 } 40 } 41 42 void 43 Indexer::visit( FunctionDecl *functionDecl ) 44 { 45 if( functionDecl->get_name() == "" ) return; 46 debugPrint( "Adding function " << functionDecl->get_name() << std::endl ); 47 idTable.addDecl( functionDecl ); 48 enterScope(); 49 maybeAccept( functionDecl->get_functionType(), *this ); 50 acceptAll( functionDecl->get_oldDecls(), *this ); 51 maybeAccept( functionDecl->get_statements(), *this ); 52 leaveScope(); 53 } 13 Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {} 14 15 Indexer::~Indexer() {} 16 17 void Indexer::visit( ObjectDecl *objectDecl ) { 18 maybeAccept( objectDecl->get_type(), *this ); 19 maybeAccept( objectDecl->get_init(), *this ); 20 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); 21 if ( objectDecl->get_name() != "" ) { 22 debugPrint( "Adding object " << objectDecl->get_name() << std::endl ); 23 idTable.addDecl( objectDecl ); 24 } 25 } 26 27 void Indexer::visit( FunctionDecl *functionDecl ) { 28 if ( functionDecl->get_name() == "" ) return; 29 debugPrint( "Adding function " << functionDecl->get_name() << std::endl ); 30 idTable.addDecl( functionDecl ); 31 enterScope(); 32 maybeAccept( functionDecl->get_functionType(), *this ); 33 acceptAll( functionDecl->get_oldDecls(), *this ); 34 maybeAccept( functionDecl->get_statements(), *this ); 35 leaveScope(); 36 } 54 37 55 38 /******** … … 72 55 */ 73 56 74 void 75 Indexer::visit( TypeDecl *typeDecl ) 76 { 77 // see A NOTE ON THE ORDER OF TRAVERSAL, above 78 // note that assertions come after the type is added to the symtab, since they aren't part 79 // of the type proper and may depend on the type itself 80 enterScope(); 81 acceptAll( typeDecl->get_parameters(), *this ); 82 maybeAccept( typeDecl->get_base(), *this ); 83 leaveScope(); 84 debugPrint( "Adding type " << typeDecl->get_name() << std::endl ); 85 typeTable.add( typeDecl ); 86 acceptAll( typeDecl->get_assertions(), *this ); 87 } 88 89 void 90 Indexer::visit( TypedefDecl *typeDecl ) 91 { 92 enterScope(); 93 acceptAll( typeDecl->get_parameters(), *this ); 94 maybeAccept( typeDecl->get_base(), *this ); 95 leaveScope(); 96 debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl ); 97 typeTable.add( typeDecl ); 98 } 99 100 void 101 Indexer::visit( StructDecl *aggregateDecl ) 102 { 103 // make up a forward declaration and add it before processing the members 104 StructDecl fwdDecl( aggregateDecl->get_name() ); 105 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 106 debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl ); 107 structTable.add( &fwdDecl ); 108 109 enterScope(); 110 acceptAll( aggregateDecl->get_parameters(), *this ); 111 acceptAll( aggregateDecl->get_members(), *this ); 112 leaveScope(); 113 114 debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl ); 115 // this addition replaces the forward declaration 116 structTable.add( aggregateDecl ); 117 } 118 119 void 120 Indexer::visit( UnionDecl *aggregateDecl ) 121 { 122 // make up a forward declaration and add it before processing the members 123 UnionDecl fwdDecl( aggregateDecl->get_name() ); 124 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 125 debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl ); 126 unionTable.add( &fwdDecl ); 127 128 enterScope(); 129 acceptAll( aggregateDecl->get_parameters(), *this ); 130 acceptAll( aggregateDecl->get_members(), *this ); 131 leaveScope(); 132 133 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 134 unionTable.add( aggregateDecl ); 135 } 136 137 void 138 Indexer::visit( EnumDecl *aggregateDecl ) 139 { 140 debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl ); 141 enumTable.add( aggregateDecl ); 142 // unlike structs, contexts, and unions, enums inject their members into the 143 // global scope 144 acceptAll( aggregateDecl->get_members(), *this ); 145 } 146 147 void 148 Indexer::visit( ContextDecl *aggregateDecl ) 149 { 150 enterScope(); 151 acceptAll( aggregateDecl->get_parameters(), *this ); 152 acceptAll( aggregateDecl->get_members(), *this ); 153 leaveScope(); 154 155 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 156 contextTable.add( aggregateDecl ); 157 } 158 159 void 160 Indexer::visit( CompoundStmt *compoundStmt ) 161 { 162 enterScope(); 163 acceptAll( compoundStmt->get_kids(), *this ); 164 leaveScope(); 165 } 166 167 void 168 Indexer::visit( ContextInstType *contextInst ) 169 { 170 acceptAll( contextInst->get_parameters(), *this ); 171 acceptAll( contextInst->get_members(), *this ); 172 } 173 174 void 175 Indexer::visit( StructInstType *structInst ) 176 { 177 if( !structTable.lookup( structInst->get_name() ) ) { 178 debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl ); 179 structTable.add( structInst->get_name() ); 180 } 181 enterScope(); 182 acceptAll( structInst->get_parameters(), *this ); 183 leaveScope(); 184 } 185 186 void 187 Indexer::visit( UnionInstType *unionInst ) 188 { 189 if( !unionTable.lookup( unionInst->get_name() ) ) { 190 debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl ); 191 unionTable.add( unionInst->get_name() ); 192 } 193 enterScope(); 194 acceptAll( unionInst->get_parameters(), *this ); 195 leaveScope(); 196 } 197 198 void 199 Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const 200 { 201 idTable.lookupId( id, list ); 202 } 203 204 NamedTypeDecl * 205 Indexer::lookupType( const std::string &id ) const 206 { 207 return typeTable.lookup( id ); 208 } 209 210 StructDecl * 211 Indexer::lookupStruct( const std::string &id ) const 212 { 213 return structTable.lookup( id ); 214 } 215 216 EnumDecl * 217 Indexer::lookupEnum( const std::string &id ) const 218 { 219 return enumTable.lookup( id ); 220 } 221 222 UnionDecl * 223 Indexer::lookupUnion( const std::string &id ) const 224 { 225 return unionTable.lookup( id ); 226 } 227 228 ContextDecl * 229 Indexer::lookupContext( const std::string &id ) const 230 { 231 return contextTable.lookup( id ); 232 } 233 234 void 235 Indexer::enterScope() 236 { 237 if( doDebug ) { 238 std::cout << "--- Entering scope" << std::endl; 239 } 240 idTable.enterScope(); 241 typeTable.enterScope(); 242 structTable.enterScope(); 243 enumTable.enterScope(); 244 unionTable.enterScope(); 245 contextTable.enterScope(); 246 } 247 248 void 249 Indexer::leaveScope() 250 { 251 using std::cout; 252 using std::endl; 253 254 if( doDebug ) { 255 cout << "--- Leaving scope containing" << endl; 256 idTable.dump( cout ); 257 typeTable.dump( cout ); 258 structTable.dump( cout ); 259 enumTable.dump( cout ); 260 unionTable.dump( cout ); 261 contextTable.dump( cout ); 262 } 263 idTable.leaveScope(); 264 typeTable.leaveScope(); 265 structTable.leaveScope(); 266 enumTable.leaveScope(); 267 unionTable.leaveScope(); 268 contextTable.leaveScope(); 269 } 270 271 void 272 Indexer::print( std::ostream &os, int indent ) const 273 { 274 idTable.dump( os ); 275 typeTable.dump( os ); 276 structTable.dump( os ); 277 enumTable.dump( os ); 278 unionTable.dump( os ); 279 contextTable.dump( os ); 280 } 281 57 void Indexer::visit( TypeDecl *typeDecl ) { 58 // see A NOTE ON THE ORDER OF TRAVERSAL, above 59 // note that assertions come after the type is added to the symtab, since they aren't part 60 // of the type proper and may depend on the type itself 61 enterScope(); 62 acceptAll( typeDecl->get_parameters(), *this ); 63 maybeAccept( typeDecl->get_base(), *this ); 64 leaveScope(); 65 debugPrint( "Adding type " << typeDecl->get_name() << std::endl ); 66 typeTable.add( typeDecl ); 67 acceptAll( typeDecl->get_assertions(), *this ); 68 } 69 70 void Indexer::visit( TypedefDecl *typeDecl ) { 71 enterScope(); 72 acceptAll( typeDecl->get_parameters(), *this ); 73 maybeAccept( typeDecl->get_base(), *this ); 74 leaveScope(); 75 debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl ); 76 typeTable.add( typeDecl ); 77 } 78 79 void Indexer::visit( StructDecl *aggregateDecl ) { 80 // make up a forward declaration and add it before processing the members 81 StructDecl fwdDecl( aggregateDecl->get_name() ); 82 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 83 debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl ); 84 structTable.add( &fwdDecl ); 85 86 enterScope(); 87 acceptAll( aggregateDecl->get_parameters(), *this ); 88 acceptAll( aggregateDecl->get_members(), *this ); 89 leaveScope(); 90 91 debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl ); 92 // this addition replaces the forward declaration 93 structTable.add( aggregateDecl ); 94 } 95 96 void Indexer::visit( UnionDecl *aggregateDecl ) { 97 // make up a forward declaration and add it before processing the members 98 UnionDecl fwdDecl( aggregateDecl->get_name() ); 99 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 100 debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl ); 101 unionTable.add( &fwdDecl ); 102 103 enterScope(); 104 acceptAll( aggregateDecl->get_parameters(), *this ); 105 acceptAll( aggregateDecl->get_members(), *this ); 106 leaveScope(); 107 108 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 109 unionTable.add( aggregateDecl ); 110 } 111 112 void Indexer::visit( EnumDecl *aggregateDecl ) { 113 debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl ); 114 enumTable.add( aggregateDecl ); 115 // unlike structs, contexts, and unions, enums inject their members into the global scope 116 acceptAll( aggregateDecl->get_members(), *this ); 117 } 118 119 void Indexer::visit( ContextDecl *aggregateDecl ) { 120 enterScope(); 121 acceptAll( aggregateDecl->get_parameters(), *this ); 122 acceptAll( aggregateDecl->get_members(), *this ); 123 leaveScope(); 124 125 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 126 contextTable.add( aggregateDecl ); 127 } 128 129 void Indexer::visit( CompoundStmt *compoundStmt ) { 130 enterScope(); 131 acceptAll( compoundStmt->get_kids(), *this ); 132 leaveScope(); 133 } 134 135 void Indexer::visit( ContextInstType *contextInst ) { 136 acceptAll( contextInst->get_parameters(), *this ); 137 acceptAll( contextInst->get_members(), *this ); 138 } 139 140 void Indexer::visit( StructInstType *structInst ) { 141 if ( ! structTable.lookup( structInst->get_name() ) ) { 142 debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl ); 143 structTable.add( structInst->get_name() ); 144 } 145 enterScope(); 146 acceptAll( structInst->get_parameters(), *this ); 147 leaveScope(); 148 } 149 150 void Indexer::visit( UnionInstType *unionInst ) { 151 if ( ! unionTable.lookup( unionInst->get_name() ) ) { 152 debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl ); 153 unionTable.add( unionInst->get_name() ); 154 } 155 enterScope(); 156 acceptAll( unionInst->get_parameters(), *this ); 157 leaveScope(); 158 } 159 160 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const { 161 idTable.lookupId( id, list ); 162 } 163 164 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const { 165 return typeTable.lookup( id ); 166 } 167 168 StructDecl *Indexer::lookupStruct( const std::string &id ) const { 169 return structTable.lookup( id ); 170 } 171 172 EnumDecl *Indexer::lookupEnum( const std::string &id ) const { 173 return enumTable.lookup( id ); 174 } 175 176 UnionDecl *Indexer::lookupUnion( const std::string &id ) const { 177 return unionTable.lookup( id ); 178 } 179 180 ContextDecl * Indexer::lookupContext( const std::string &id ) const { 181 return contextTable.lookup( id ); 182 } 183 184 void Indexer::enterScope() { 185 if ( doDebug ) { 186 std::cout << "--- Entering scope" << std::endl; 187 } 188 idTable.enterScope(); 189 typeTable.enterScope(); 190 structTable.enterScope(); 191 enumTable.enterScope(); 192 unionTable.enterScope(); 193 contextTable.enterScope(); 194 } 195 196 void Indexer::leaveScope() { 197 using std::cout; 198 using std::endl; 199 200 if ( doDebug ) { 201 cout << "--- Leaving scope containing" << endl; 202 idTable.dump( cout ); 203 typeTable.dump( cout ); 204 structTable.dump( cout ); 205 enumTable.dump( cout ); 206 unionTable.dump( cout ); 207 contextTable.dump( cout ); 208 } 209 idTable.leaveScope(); 210 typeTable.leaveScope(); 211 structTable.leaveScope(); 212 enumTable.leaveScope(); 213 unionTable.leaveScope(); 214 contextTable.leaveScope(); 215 } 216 217 void Indexer::print( std::ostream &os, int indent ) const { 218 idTable.dump( os ); 219 typeTable.dump( os ); 220 structTable.dump( os ); 221 enumTable.dump( os ); 222 unionTable.dump( os ); 223 contextTable.dump( os ); 224 } 282 225 } // namespace SymTab -
translator/SymTab/Indexer.h
rd9a0e76 r17cd4eb 1 /*2 * This file is part of the Cforall project3 *4 * A class that indexes the syntax tree. It is intended to be subclassed by a visitor class5 * that wants to use the index.6 *7 * $Id: Indexer.h,v 1.9 2005/08/29 20:14:18 rcbilson Exp $8 *9 */10 11 1 #ifndef SYMTAB_INDEXER_H 12 2 #define SYMTAB_INDEXER_H … … 22 12 23 13 namespace SymTab { 14 class Indexer : public Visitor { 15 public: 16 Indexer( bool useDebug = false ); 17 virtual ~Indexer(); 24 18 25 class Indexer : public Visitor 26 { 27 public: 28 Indexer( bool useDebug = false ); 29 virtual ~Indexer(); 19 //using Visitor::visit; 20 virtual void visit( ObjectDecl *objectDecl ); 21 virtual void visit( FunctionDecl *functionDecl ); 22 virtual void visit( TypeDecl *typeDecl ); 23 virtual void visit( TypedefDecl *typeDecl ); 24 virtual void visit( StructDecl *aggregateDecl ); 25 virtual void visit( UnionDecl *aggregateDecl ); 26 virtual void visit( EnumDecl *aggregateDecl ); 27 virtual void visit( ContextDecl *aggregateDecl ); 30 28 31 /// using Visitor::visit; 32 virtual void visit( ObjectDecl *objectDecl ); 33 virtual void visit( FunctionDecl *functionDecl ); 34 virtual void visit( TypeDecl *typeDecl ); 35 virtual void visit( TypedefDecl *typeDecl ); 36 virtual void visit( StructDecl *aggregateDecl ); 37 virtual void visit( UnionDecl *aggregateDecl ); 38 virtual void visit( EnumDecl *aggregateDecl ); 39 virtual void visit( ContextDecl *aggregateDecl ); 29 virtual void visit( CompoundStmt *compoundStmt ); 40 30 41 virtual void visit( CompoundStmt *compoundStmt ); 31 virtual void visit( ContextInstType *contextInst ); 32 virtual void visit( StructInstType *contextInst ); 33 virtual void visit( UnionInstType *contextInst ); 34 35 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to tell the indexer 36 // explicitly when scopes begin and end 37 void enterScope(); 38 void leaveScope(); 42 39 43 virtual void visit( ContextInstType *contextInst ); 44 virtual void visit( StructInstType *contextInst ); 45 virtual void visit( UnionInstType *contextInst ); 40 void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const; 41 NamedTypeDecl *lookupType( const std::string &id ) const; 42 StructDecl *lookupStruct( const std::string &id ) const; 43 EnumDecl *lookupEnum( const std::string &id ) const; 44 UnionDecl *lookupUnion( const std::string &id ) const; 45 ContextDecl *lookupContext( const std::string &id ) const; 46 46 47 // when using an indexer manually (e.g., within a mutator traversal), it is 48 // necessary to tell the indexer explicitly when scopes begin and end 49 void enterScope(); 50 void leaveScope(); 51 52 void lookupId( const std::string &id, std::list< DeclarationWithType* >& ) const; 53 NamedTypeDecl *lookupType( const std::string &id ) const; 54 StructDecl *lookupStruct( const std::string &id ) const; 55 EnumDecl *lookupEnum( const std::string &id ) const; 56 UnionDecl *lookupUnion( const std::string &id ) const; 57 ContextDecl *lookupContext( const std::string &id ) const; 47 void print( std::ostream &os, int indent = 0 ) const; 48 private: 49 IdTable idTable; 50 TypeTable typeTable; 51 StructTable structTable; 52 EnumTable enumTable; 53 UnionTable unionTable; 54 ContextTable contextTable; 58 55 59 void print( std::ostream &os, int indent = 0 ) const; 60 61 private: 62 IdTable idTable; 63 TypeTable typeTable; 64 StructTable structTable; 65 EnumTable enumTable; 66 UnionTable unionTable; 67 ContextTable contextTable; 68 69 bool doDebug; // display debugging trace 70 }; 71 56 bool doDebug; // display debugging trace 57 }; 72 58 } // namespace SymTab 73 59 -
translator/SymTab/Validate.cc
rd9a0e76 r17cd4eb 185 185 if ( ! visitor.get_declsToAdd().empty() ) { 186 186 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() ); 187 } 187 } // if 188 188 i = next; 189 } 189 } // while 190 190 } 191 191 … … 206 206 if ( doDelete ) { 207 207 delete *i; 208 } 208 } // if 209 209 declList.erase( i ); 210 } 210 } // if 211 211 i = next; 212 } 212 } // while 213 213 } 214 214 … … 227 227 Visitor::visit( aggregateDecl ); 228 228 inStruct = false; 229 } 229 } // if 230 230 // Always remove the hoisted aggregate from the inner structure. 231 231 filter( aggregateDecl->get_members(), isStructOrUnion, false ); … … 275 275 // Set the type of each member of the enumeration to be EnumConstant 276 276 277 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {277 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { 278 278 ObjectDecl *obj = dynamic_cast< ObjectDecl * >( *i ); 279 279 assert( obj ); 280 280 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false ), enumDecl->get_name() ) ); 281 } 281 } // for 282 282 Parent::visit( enumDecl ); 283 283 } … … 285 285 namespace { 286 286 template< typename DWTIterator > 287 void 288 fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) { 287 void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) { 289 288 // the only case in which "void" is valid is where it is the only one in the list; then 290 289 // it should be removed entirely … … 300 299 if ( i != end ) { 301 300 throw SemanticError( "invalid type void in function type ", func ); 302 } 301 } // if 303 302 } else { 304 303 ++i; 305 for ( ; i != end; ++i ) {304 for ( ; i != end; ++i ) { 306 305 FixFunction fixer; 307 306 *i = (*i )->acceptMutator( fixer ); 308 307 if ( fixer.get_isVoid() ) { 309 308 throw SemanticError( "invalid type void in function type ", func ); 310 } 311 } 312 } 309 } // if 310 } // for 311 } // if 313 312 } 314 313 } … … 326 325 } else { 327 326 indexer = this; 328 } 327 } // if 329 328 } 330 329 … … 336 335 assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() ); 337 336 structInst->set_baseStruct( st ); 338 } 337 } // if 339 338 if ( ! st || st->get_members().empty() ) { 340 339 // use of forward declaration 341 340 forwardStructs[ structInst->get_name() ].push_back( structInst ); 342 } 341 } // if 343 342 } 344 343 … … 349 348 if ( un ) { 350 349 unionInst->set_baseUnion( un ); 351 } 350 } // if 352 351 if ( ! un || un->get_members().empty() ) { 353 352 // use of forward declaration 354 353 forwardUnions[ unionInst->get_name() ].push_back( unionInst ); 355 } 354 } // if 356 355 } 357 356 … … 361 360 if ( ! ctx ) { 362 361 throw SemanticError( "use of undeclared context " + contextInst->get_name() ); 363 } 364 for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {365 for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {362 } // if 363 for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) { 364 for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 366 365 if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) { 367 366 cloneAll( otherCtx->get_members(), contextInst->get_members() ); 368 367 } else { 369 368 contextInst->get_members().push_back( (*assert )->clone() ); 370 } 371 } 372 } 369 } // if 370 } // for 371 } // for 373 372 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) ); 374 373 } … … 378 377 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() ); 379 378 if ( fwds != forwardStructs.end() ) { 380 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {379 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) { 381 380 (*inst )->set_baseStruct( structDecl ); 382 } 381 } // for 383 382 forwardStructs.erase( fwds ); 384 } 385 } 383 } // if 384 } // if 386 385 Indexer::visit( structDecl ); 387 386 } … … 391 390 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() ); 392 391 if ( fwds != forwardUnions.end() ) { 393 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {392 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) { 394 393 (*inst )->set_baseUnion( unionDecl ); 395 } 394 } // for 396 395 forwardUnions.erase( fwds ); 397 } 398 } 396 } // if 397 } // if 399 398 Indexer::visit( unionDecl ); 400 399 } … … 404 403 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) { 405 404 typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype ); 406 } 407 } 405 } // if 406 } // if 408 407 } 409 408 … … 413 412 } else { 414 413 indexer = this; 415 } 414 } // if 416 415 } 417 416 418 417 void forallFixer( Type *func ) { 419 418 // Fix up assertions 420 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {419 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) { 421 420 std::list< DeclarationWithType * > toBeDone, nextRound; 422 421 toBeDone.splice( toBeDone.end(), (*type )->get_assertions() ); 423 422 while ( ! toBeDone.empty() ) { 424 for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {423 for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) { 425 424 if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) { 426 for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {425 for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) { 427 426 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i ); 428 427 assert( dwt ); … … 449 448 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { 450 449 forallFixer( pointer->get_base() ); 451 } 450 } // if 452 451 Parent::visit( object ); 453 452 object->fixUniqueId(); … … 546 545 assignDecl->fixUniqueId(); 547 546 548 for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {547 for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) { 549 548 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) { 550 549 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { … … 552 551 } else { 553 552 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 554 } 555 } 556 } 553 } // if 554 } // if 555 } // for 557 556 assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 558 557 … … 594 593 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) ); 595 594 structsDone.insert( structDecl->get_name() ); 596 } 595 } // if 597 596 } 598 597 … … 602 601 unionInst->set_baseUnion( unionDecl ); 603 602 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) ); 604 } 603 } // if 605 604 } 606 605 … … 617 616 assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) ); 618 617 stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) ); 619 } 618 } // if 620 619 FunctionType *type = new FunctionType( Type::Qualifiers(), false ); 621 620 type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) ); … … 628 627 void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) { 629 628 if ( ! declsToAdd.empty() ) { 630 for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {629 for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) { 631 630 statements.insert( i, new DeclStmt( noLabels, *decl ) ); 632 } 631 } // for 633 632 declsToAdd.clear(); 634 } 633 } // if 635 634 } 636 635 637 636 void AddStructAssignment::visit( FunctionType *) { 638 // ensure that we don't add assignment ops for types defined 639 // as part of the function 637 // ensure that we don't add assignment ops for types defined as part of the function 640 638 } 641 639 642 640 void AddStructAssignment::visit( PointerType *) { 643 // ensure that we don't add assignment ops for types defined 644 // as part of the pointer 641 // ensure that we don't add assignment ops for types defined as part of the pointer 645 642 } 646 643 647 644 void AddStructAssignment::visit( ContextDecl *) { 648 // ensure that we don't add assignment ops for types defined 649 // as part of the context 645 // ensure that we don't add assignment ops for types defined as part of the context 650 646 } 651 647 … … 714 710 delete typeInst; 715 711 return ret; 716 } 712 } // if 717 713 return typeInst; 718 714 } … … 721 717 Declaration *ret = Mutator::mutate( tyDecl ); 722 718 typedefNames[ tyDecl->get_name() ] = tyDecl; 723 if ( AggregateDecl *aggDecl = dynamic_cast< AggregateDecl * >( tyDecl->get_base() ) ) { 724 tyDecl->set_base( 0 ); 725 delete tyDecl; 726 return aggDecl; 719 // When a typedef is a forward declaration: 720 // typedef struct screen SCREEN; 721 // the declaration portion must be retained: 722 // struct screen; 723 // because the expansion of the typedef is: 724 // void rtn( SCREEN *p ) => void rtn( struct screen *p ) 725 // hence the type-name "screen" must be defined. 726 // Note, qualifiers on the typedef are superfluous for the forward declaration. 727 if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( tyDecl->get_base() ) ) { 728 return new StructDecl( aggDecl->get_name() ); 729 } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( tyDecl->get_base() ) ) { 730 return new UnionDecl( aggDecl->get_name() ); 727 731 } else { 728 732 return ret; 729 } 733 } // if 730 734 } 731 735 … … 734 738 if ( i != typedefNames.end() ) { 735 739 typedefNames.erase( i ) ; 736 } 740 } // if 737 741 return typeDecl; 738 742 } … … 770 774 delete *i; 771 775 compoundStmt->get_kids().erase( i ); 772 } 773 } 776 } // if 777 } // if 774 778 i = next; 775 } 779 } // while 776 780 typedefNames = oldNames; 777 781 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.