Changeset 63be3387 for src/Validate
- Timestamp:
- Nov 14, 2022, 11:52:44 AM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 7d9598d8
- Parents:
- b77f0e1 (diff), 19a8c40 (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. - Location:
- src/Validate
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/EnumAndPointerDecay.cpp
rb77f0e1 r63be3387 21 21 #include "AST/Type.hpp" 22 22 #include "SymTab/FixFunction.h" 23 #include "Validate/NoIdSymbolTable.hpp" 23 24 24 25 namespace Validate { … … 26 27 namespace { 27 28 28 struct EnumAndPointerDecayCore final : public ast::WithCodeLocation {29 struct EnumAndPointerDecayCore final : public WithNoIdSymbolTable, public ast::WithCodeLocation { 29 30 ast::EnumDecl const * previsit( ast::EnumDecl const * decl ); 30 31 ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl ); … … 39 40 // Set the type of each member of the enumeration to be EnumContant. 40 41 auto mut = ast::mutate( decl ); 41 for ( ast::ptr<ast::Decl> & member : mut->members ) { 42 ast::ObjectDecl const * object = member.strict_as<ast::ObjectDecl>(); 43 member = ast::mutate_field( object, &ast::ObjectDecl::type, 44 new ast::EnumInstType( decl, ast::CV::Const ) ); 42 std::vector<ast::ptr<ast::Decl>> buffer; 43 for ( auto member : decl->members ) { 44 if ( ast::ObjectDecl const * object = member.as<ast::ObjectDecl>() ) { 45 buffer.push_back( ast::mutate_field( object, 46 &ast::ObjectDecl::type, 47 new ast::EnumInstType( decl, ast::CV::Const ) ) ); 48 } else if ( auto value = member.as<ast::InlineMemberDecl>() ) { 49 if ( auto targetEnum = symtab.lookupEnum( value->name ) ) { 50 for ( auto enumMember : targetEnum->members ) { 51 auto enumObject = enumMember.strict_as<ast::ObjectDecl>(); 52 buffer.push_back( new ast::ObjectDecl( 53 // Get the location from the "inline" declaration. 54 value->location, 55 enumObject->name, 56 // Construct a new EnumInstType as the type. 57 new ast::EnumInstType( decl, ast::CV::Const ), 58 enumObject->init, 59 enumObject->storage, 60 enumObject->linkage, 61 enumObject->bitfieldWidth, 62 {}, 63 enumObject->funcSpec 64 ) ); 65 } 66 } 67 } 45 68 } 69 mut->members = buffer; 46 70 return mut; 47 71 } -
src/Validate/LinkReferenceToTypes.cpp
rb77f0e1 r63be3387 185 185 decl = mut; 186 186 } 187 // visit the base 187 188 } else if ( auto ptr = decl->base.as<ast::PointerType>() ) { 188 189 if ( auto base = ptr->base.as<ast::TypeInstType>() ) { … … 203 204 204 205 // 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" location216 tm->name,217 new ast::EnumInstType( decl, ast::CV::Const ),218 // Construct a new EnumInstType as the type219 tm->init,220 tm->storage,221 tm->linkage,222 tm->bitfieldWidth,223 {}, // enum member doesn't have attribute224 tm->funcSpec225 );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 name237 // override the imported value238 }239 buffer.push_back( *it );240 }241 }242 mut->members = buffer;243 decl = mut;244 206 245 207 ForwardEnumsType::iterator fwds = forwardEnums.find( decl->name );
Note:
See TracChangeset
for help on using the changeset viewer.