Changeset e874605 for src/Validate


Ignore:
Timestamp:
Oct 28, 2022, 3:11:57 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master
Children:
93d2219
Parents:
77de429
Message:

Add class InlineValueDecl, which is a Declaration class that works as a placeholder for aggregration value inherited from other aggregration. Disable inline value overwrite.

Location:
src/Validate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/EnumAndPointerDecay.cpp

    r77de429 re874605  
    2121#include "AST/Type.hpp"
    2222#include "SymTab/FixFunction.h"
     23#include "Validate/NoIdSymbolTable.hpp"
    2324
    2425namespace Validate {
     
    2627namespace {
    2728
    28 struct EnumAndPointerDecayCore final : public ast::WithCodeLocation {
     29struct EnumAndPointerDecayCore final : public WithNoIdSymbolTable, public ast::WithCodeLocation {
    2930        ast::EnumDecl const * previsit( ast::EnumDecl const * decl );
    3031        ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl );
     
    3940        // Set the type of each member of the enumeration to be EnumContant.
    4041        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 it = decl->members.begin(); it != decl->members.end(); ++it ) {
     44                if ( ast::ObjectDecl const * object = (*it).as<ast::ObjectDecl>() ) {
     45                        buffer.push_back( ast::mutate_field( object, &ast::ObjectDecl::type, new ast::EnumInstType( decl, ast::CV::Const ) ) );
     46                } else if ( ast::InlineValueDecl const * value = (*it).as<ast::InlineValueDecl>() ) {
     47                        if ( auto targetEnum = symtab.lookupEnum( value->name ) ) {
     48                                for ( auto singleMember : targetEnum->members ) {
     49                                        auto copyingMember = singleMember.as<ast::ObjectDecl>();
     50                                        buffer.push_back( new ast::ObjectDecl(
     51                                                value->location, // use the "inline" location
     52                                                copyingMember->name,
     53                                                new ast::EnumInstType( decl, ast::CV::Const ),
     54                                                // Construct a new EnumInstType as the type
     55                                                copyingMember->init,
     56                                                copyingMember->storage,
     57                                                copyingMember->linkage,
     58                                                copyingMember->bitfieldWidth,
     59                                                {},
     60                                                copyingMember->funcSpec
     61                                        ) );
     62                                }
     63                        }
     64                }
    4565        }
     66        mut->members = buffer;
    4667        return mut;
    4768}
  • src/Validate/LinkReferenceToTypes.cpp

    r77de429 re874605  
    185185                                decl = mut;
    186186                        }
     187                        // visit the base
    187188                } else if ( auto ptr = decl->base.as<ast::PointerType>() ) {
    188189                        if ( auto base = ptr->base.as<ast::TypeInstType>() ) {
     
    203204
    204205        // 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;
    244206
    245207        ForwardEnumsType::iterator fwds = forwardEnums.find( decl->name );
Note: See TracChangeset for help on using the changeset viewer.