Changeset df6cc9d for src/Validate/LinkReferenceToTypes.cpp
- Timestamp:
- Oct 19, 2022, 4:43:26 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 1a45263
- Parents:
- 9cd5bd2 (diff), 135143ba (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
r9cd5bd2 rdf6cc9d 44 44 void postvisit( ast::UnionDecl const * decl ); 45 45 ast::TraitDecl const * postvisit( ast::TraitDecl const * decl ); 46 ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl);47 46 48 47 private: … … 203 202 } 204 203 204 // The following section 205 auto mut = ast::mutate( decl ); 206 std::vector<ast::ptr<ast::Decl>> buffer; 207 for ( auto it = decl->members.begin(); it != decl->members.end(); ++it) { 208 auto member = (*it).as<ast::ObjectDecl>(); 209 if ( member->enumInLine ) { 210 auto targetEnum = symtab.lookupEnum( member->name ); 211 if ( targetEnum ) { 212 for ( auto singleMamber : targetEnum->members ) { 213 auto tm = singleMamber.as<ast::ObjectDecl>(); 214 auto t = new ast::ObjectDecl( 215 member->location, // use the "inline" location 216 tm->name, 217 new ast::EnumInstType( decl, ast::CV::Const ), 218 // Construct a new EnumInstType as the type 219 tm->init, 220 tm->storage, 221 tm->linkage, 222 tm->bitfieldWidth, 223 {}, // enum member doesn't have attribute 224 tm->funcSpec 225 ); 226 t->importValue = true; 227 buffer.push_back(t); 228 } 229 } 230 } else { 231 auto search_it = std::find_if( buffer.begin(), buffer.end(), [member](ast::ptr<ast::Decl> cur) { 232 auto curAsObjDecl = cur.as<ast::ObjectDecl>(); 233 return (curAsObjDecl->importValue) && (curAsObjDecl->name == member->name); 234 }); 235 if ( search_it != buffer.end() ) { 236 buffer.erase( search_it ); // Found an import enum value that has the same name 237 // override the imported value 238 } 239 buffer.push_back( *it ); 240 } 241 } 242 mut->members = buffer; 243 decl = mut; 244 205 245 ForwardEnumsType::iterator fwds = forwardEnums.find( decl->name ); 206 246 if ( fwds != forwardEnums.end() ) { … … 284 324 } 285 325 286 ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) {287 // Try to lookup type288 if ( auto objDecl = decl->type_decl.as<ast::ObjectDecl>() ) {289 if ( auto inst = objDecl->type.as<ast::TypeInstType>()) {290 if ( auto enumDecl = symtab.lookupEnum ( inst->name ) ) {291 auto mut = ast::mutate( decl );292 mut->type_decl = enumDecl;293 auto enumInst = new ast::EnumInstType( enumDecl );294 enumInst->name = decl->name;295 // Adding result; addCandidate() use result296 mut->result = enumInst;297 decl = mut;298 }299 }300 } else if ( auto enumDecl = decl->type_decl.as<ast::EnumDecl>() ) {301 auto mut = ast::mutate( decl );302 auto enumInst = new ast::EnumInstType( enumDecl );303 enumInst->name = decl->name;304 // Adding result; addCandidate() use result305 mut->result = enumInst;306 decl = mut;307 }308 // ast::EnumDecl const * decl = symtab.lookupEnum( type->name );309 // // It's not a semantic error if the enum is not found, just an implicit forward declaration.310 // if ( decl ) {311 // // Just linking in the node.312 // auto mut = ast::mutate( type );313 // mut->base = const_cast<ast::EnumDecl *>( decl );314 // type = mut;315 // }316 return decl;317 }318 319 326 } // namespace 320 327
Note:
See TracChangeset
for help on using the changeset viewer.