Changeset 4520b77e for src/Validate


Ignore:
Timestamp:
Sep 20, 2022, 8:37:05 PM (19 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
a065f1f
Parents:
d489da8 (diff), 12df6fe (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.
Message:

Merge to Master Sept 19

Location:
src/Validate
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    rd489da8 r4520b77e  
    235235        // Must visit children (enum constants) to add them to the symbol table.
    236236        if ( !enumDecl->body ) return;
     237
     238        // if ( auto enumBaseType = enumDecl->base ) {
     239        //      if ( auto enumBaseTypeAsStructInst = dynamic_cast<const ast::StructInstType *>(enumBaseType.get()) ) {
     240        //              const ast::StructDecl * structDecl = enumBaseTypeAsStructInst->base.get();
     241        //              this->previsit( structDecl );
     242        //      }
     243        // }
    237244
    238245        ast::EnumInstType enumInst( enumDecl->name );
  • src/Validate/FixQualifiedTypes.cpp

    rd489da8 r4520b77e  
    1919#include "AST/TranslationUnit.hpp"
    2020#include "Validate/NoIdSymbolTable.hpp"
     21#include "SymTab/Mangler.h"            // for Mangler
     22#include "AST/LinkageSpec.hpp"                     // for Linkage
    2123
    2224namespace Validate {
     
    8991                }
    9092        }
     93
     94        ast::Expr const * postvisit( ast::QualifiedNameExpr const * t) {
     95                assert( location );
     96                if ( t->type_decl ) {
     97                auto enumName = t->type_decl->name;
     98                const ast::EnumDecl * enumDecl = symtab.lookupEnum( enumName );
     99                        for ( ast::ptr<ast::Decl> const & member : enumDecl->members ) {
     100                                if ( auto memberAsObj = member.as<ast::ObjectDecl>() ) {
     101                                        if ( memberAsObj->name == t->name ) {
     102                                                return new ast::VariableExpr( t->location, memberAsObj );
     103                                        }
     104                                } else {
     105                                        assertf( false, "unhandled qualified child type");
     106                                }
     107                        }
     108
     109
     110                auto var = new ast::ObjectDecl( t->var->location, t->name,
     111                         new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall );
     112                        var->scopeLevel = 1; // 1 for now; should copy the scopeLevel of the enumValue
     113                        var->mangleName = Mangle::mangle( var );
     114                        return new ast::VariableExpr( t->location, var );
     115                // return ret;
     116        }
     117
     118                return t;
     119        }
     120
    91121};
    92122
  • src/Validate/LinkReferenceToTypes.cpp

    rd489da8 r4520b77e  
    4646        void postvisit( ast::UnionDecl const * decl );
    4747        ast::TraitDecl const * postvisit( ast::TraitDecl const * decl );
     48        ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl);
    4849
    4950private:
     
    292293}
    293294
     295ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) {
     296        // Try to lookup type
     297        if ( auto objDecl = decl->type_decl.as<ast::ObjectDecl>() ) {
     298                if ( auto inst = objDecl->type.as<ast::TypeInstType>()) {
     299                        if ( auto enumDecl = symtab.lookupEnum ( inst->name ) ) {
     300                                auto mut = ast::mutate( decl );
     301                                mut->type_decl = enumDecl;
     302                                auto enumInst = new ast::EnumInstType( enumDecl );
     303                                enumInst->name = decl->name;
     304                                // Adding result; addCandidate() use result
     305                                mut->result = enumInst;
     306                                decl = mut;
     307                        }
     308                }
     309        } else if ( auto enumDecl = decl->type_decl.as<ast::EnumDecl>() ) {
     310                auto mut = ast::mutate( decl );
     311                auto enumInst = new ast::EnumInstType( enumDecl );
     312                enumInst->name = decl->name;
     313                // Adding result; addCandidate() use result
     314                mut->result = enumInst;
     315                decl = mut;
     316        }
     317        // ast::EnumDecl const * decl = symtab.lookupEnum( type->name );
     318        // // It's not a semantic error if the enum is not found, just an implicit forward declaration.
     319        // if ( decl ) {
     320        //      // Just linking in the node.
     321        //      auto mut = ast::mutate( type );
     322        //      mut->base = const_cast<ast::EnumDecl *>( decl );
     323        //      type = mut;
     324        // }
     325        return decl;
     326}
     327
    294328} // namespace
    295329
  • src/Validate/ReplaceTypedef.cpp

    rd489da8 r4520b77e  
    183183        } else if ( auto enumType = dynamic_cast<ast::EnumInstType const *>( designatorType ) ) {
    184184                declsToAddBefore.push_back( new ast::EnumDecl(
    185                         decl->location, enumType->name, {}, decl->linkage,
     185                        decl->location, enumType->name, false, {}, decl->linkage,
    186186                        ( (enumType->base) ? enumType->base->base : nullptr )
    187187                        ) );
Note: See TracChangeset for help on using the changeset viewer.