Changeset b7c53a9d for src/Validate/LinkReferenceToTypes.cpp
- Timestamp:
- Jul 14, 2023, 9:32:31 AM (15 months ago)
- Branches:
- master
- Children:
- 402a1e7
- Parents:
- 4acf56d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/LinkReferenceToTypes.cpp
r4acf56d rb7c53a9d 10 10 // Created On : Thr Apr 21 11:41:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Sep 20 16:17:00 202213 // Update Count : 212 // Last Modified On : Fri Jul 14 9:19:00 2023 13 // Update Count : 3 14 14 // 15 15 … … 27 27 struct LinkTypesCore : public WithNoIdSymbolTable, 28 28 public ast::WithCodeLocation, 29 public ast::WithDeclsToAdd<>, 29 30 public ast::WithGuards, 30 31 public ast::WithShortCircuiting, … … 63 64 template<typename AggrDecl> 64 65 AggrDecl const * renameGenericParams( AggrDecl const * decl ); 66 67 // This cluster is used to add declarations (before) but outside of 68 // any "namespaces" which would qualify the names. 69 bool inNamespace = false; 70 std::list<ast::ptr<ast::Decl>> declsToAddOutside; 71 /// The "leaveNamespace" is handled by guard. 72 void enterNamespace(); 73 /// Puts the decl on the back of declsToAddBefore once traversal is 74 /// outside of any namespaces. 75 void addDeclBeforeOutside( ast::Decl const * ); 65 76 }; 77 78 void LinkTypesCore::enterNamespace() { 79 if ( inNamespace ) return; 80 inNamespace = true; 81 GuardAction( [this](){ 82 inNamespace = false; 83 declsToAddBefore.splice( declsToAddBefore.begin(), declsToAddOutside ); 84 } ); 85 } 86 87 void LinkTypesCore::addDeclBeforeOutside( ast::Decl const * decl ) { 88 if ( inNamespace ) { 89 declsToAddOutside.emplace_back( decl ); 90 } else { 91 declsToAddBefore.emplace_back( decl ); 92 } 93 } 66 94 67 95 ast::TypeInstType const * LinkTypesCore::postvisit( ast::TypeInstType const * type ) { … … 80 108 ast::EnumInstType const * LinkTypesCore::postvisit( ast::EnumInstType const * type ) { 81 109 ast::EnumDecl const * decl = symtab.lookupEnum( type->name ); 110 // It's not a semantic error if the enum is not found, just an implicit forward declaration. 111 // The unset code location is used to detect imaginary declarations. 112 // (They may never be used for enumerations.) 113 if ( !decl || decl->location.isUnset() ) { 114 assert( location ); 115 decl = new ast::EnumDecl( *location, type->name ); 116 symtab.addEnum( decl ); 117 addDeclBeforeOutside( decl ); 118 } 119 82 120 ast::EnumInstType * mut = ast::mutate( type ); 83 // It's not a semantic error if the enum is not found, just an implicit forward declaration. 84 if ( decl ) { 85 // Just linking in the node. 86 mut->base = decl; 87 } 88 if ( !decl || !decl->body ) { 121 122 // Just linking in the node. 123 mut->base = decl; 124 125 if ( !decl->body ) { 89 126 forwardEnums[ mut->name ].push_back( mut ); 90 127 } … … 94 131 ast::StructInstType const * LinkTypesCore::postvisit( ast::StructInstType const * type ) { 95 132 ast::StructDecl const * decl = symtab.lookupStruct( type->name ); 133 // It's not a semantic error if the struct is not found, just an implicit forward declaration. 134 // The unset code location is used to detect imaginary declarations. 135 if ( !decl || decl->location.isUnset() ) { 136 assert( location ); 137 decl = new ast::StructDecl( *location, type->name ); 138 symtab.addStruct( decl ); 139 addDeclBeforeOutside( decl ); 140 } 141 96 142 ast::StructInstType * mut = ast::mutate( type ); 97 // It's not a semantic error if the struct is not found, just an implicit forward declaration. 98 if ( decl ) { 99 // Just linking in the node. 100 mut->base = decl; 101 } 102 if ( !decl || !decl->body ) { 143 144 // Just linking in the node. 145 mut->base = decl; 146 147 if ( !decl->body ) { 103 148 forwardStructs[ mut->name ].push_back( mut ); 104 149 } … … 108 153 ast::UnionInstType const * LinkTypesCore::postvisit( ast::UnionInstType const * type ) { 109 154 ast::UnionDecl const * decl = symtab.lookupUnion( type->name ); 155 // It's not a semantic error if the union is not found, just an implicit forward declaration. 156 // The unset code location is used to detect imaginary declarations. 157 if ( !decl || decl->location.isUnset() ) { 158 assert( location ); 159 decl = new ast::UnionDecl( *location, type->name ); 160 symtab.addUnion( decl ); 161 addDeclBeforeOutside( decl ); 162 } 163 110 164 ast::UnionInstType * mut = ast::mutate( type ); 111 // It's not a semantic error if the union is not found, just an implicit forward declaration. 112 if ( decl ) { 113 // Just linking in the node. 114 mut->base = decl; 115 } 116 if ( !decl || !decl->body ) { 165 166 // Just linking in the node. 167 mut->base = decl; 168 169 if ( !decl->body ) { 117 170 forwardUnions[ mut->name ].push_back( mut ); 118 171 } … … 219 272 220 273 ast::StructDecl const * LinkTypesCore::previsit( ast::StructDecl const * decl ) { 274 enterNamespace(); 221 275 return renameGenericParams( decl ); 222 276 } … … 237 291 238 292 ast::UnionDecl const * LinkTypesCore::previsit( ast::UnionDecl const * decl ) { 293 enterNamespace(); 239 294 return renameGenericParams( decl ); 240 295 }
Note: See TracChangeset
for help on using the changeset viewer.