Changeset dbf5e18 for src/Validate/LinkReferenceToTypes.cpp
- Timestamp:
- Jul 17, 2023, 9:24:46 AM (2 years ago)
- Branches:
- master
- Children:
- 7ed01be
- Parents:
- 847ab8f (diff), 0d7fc00 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/LinkReferenceToTypes.cpp
r847ab8f rdbf5e18 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 declsToAddAfter once traversal is 74 /// outside of any namespaces. 75 void addDeclAfterOutside( ast::Decl const * ); 65 76 }; 77 78 void LinkTypesCore::enterNamespace() { 79 if ( inNamespace ) return; 80 inNamespace = true; 81 GuardAction( [this](){ 82 inNamespace = false; 83 declsToAddAfter.splice( declsToAddAfter.begin(), declsToAddOutside ); 84 } ); 85 } 86 87 void LinkTypesCore::addDeclAfterOutside( ast::Decl const * decl ) { 88 if ( inNamespace ) { 89 declsToAddOutside.emplace_back( decl ); 90 } else { 91 declsToAddAfter.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 ast::EnumDecl * mut = new ast::EnumDecl( *location, type->name ); 116 mut->linkage = ast::Linkage::Compiler; 117 decl = mut; 118 symtab.addEnum( decl ); 119 addDeclAfterOutside( decl ); 120 } 121 82 122 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 ) { 123 124 // Just linking in the node. 125 mut->base = decl; 126 127 if ( !decl->body ) { 89 128 forwardEnums[ mut->name ].push_back( mut ); 90 129 } … … 94 133 ast::StructInstType const * LinkTypesCore::postvisit( ast::StructInstType const * type ) { 95 134 ast::StructDecl const * decl = symtab.lookupStruct( type->name ); 135 // It's not a semantic error if the struct is not found, just an implicit forward declaration. 136 // The unset code location is used to detect imaginary declarations. 137 if ( !decl || decl->location.isUnset() ) { 138 assert( location ); 139 ast::StructDecl * mut = new ast::StructDecl( *location, type->name ); 140 mut->linkage = ast::Linkage::Compiler; 141 decl = mut; 142 symtab.addStruct( decl ); 143 addDeclAfterOutside( decl ); 144 } 145 96 146 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 ) { 147 148 // Just linking in the node. 149 mut->base = decl; 150 151 if ( !decl->body ) { 103 152 forwardStructs[ mut->name ].push_back( mut ); 104 153 } … … 108 157 ast::UnionInstType const * LinkTypesCore::postvisit( ast::UnionInstType const * type ) { 109 158 ast::UnionDecl const * decl = symtab.lookupUnion( type->name ); 159 // It's not a semantic error if the union is not found, just an implicit forward declaration. 160 // The unset code location is used to detect imaginary declarations. 161 if ( !decl || decl->location.isUnset() ) { 162 assert( location ); 163 ast::UnionDecl * mut = new ast::UnionDecl( *location, type->name ); 164 mut->linkage = ast::Linkage::Compiler; 165 decl = mut; 166 symtab.addUnion( decl ); 167 addDeclAfterOutside( decl ); 168 } 169 110 170 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 ) { 171 172 // Just linking in the node. 173 mut->base = decl; 174 175 if ( !decl->body ) { 117 176 forwardUnions[ mut->name ].push_back( mut ); 118 177 } … … 219 278 220 279 ast::StructDecl const * LinkTypesCore::previsit( ast::StructDecl const * decl ) { 280 enterNamespace(); 221 281 return renameGenericParams( decl ); 222 282 } … … 237 297 238 298 ast::UnionDecl const * LinkTypesCore::previsit( ast::UnionDecl const * decl ) { 299 enterNamespace(); 239 300 return renameGenericParams( decl ); 240 301 }
Note:
See TracChangeset
for help on using the changeset viewer.