Changeset fa2c005 for src/Validate


Ignore:
Timestamp:
Jun 8, 2023, 3:19:43 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT
Parents:
044ae62
Message:

Finish Adt POC

Location:
src/Validate
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/EliminateTypedef.cpp

    r044ae62 rfa2c005  
    3131        ast::StructDecl const * previsit( ast::StructDecl const * decl );
    3232        ast::UnionDecl const * previsit( ast::UnionDecl const * decl );
     33        ast::AdtDecl const * previsit( ast::AdtDecl const * decl );
    3334        // Remove typedefs from statement lists.
    3435        ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt );
     
    6566}
    6667
     68ast::AdtDecl const * EliminateTypedefCore::previsit( ast::AdtDecl const * decl ) {
     69        return field_erase_if( decl, &ast::AdtDecl::members, isTypedef );
     70}
     71
    6772ast::CompoundStmt const * EliminateTypedefCore::previsit( ast::CompoundStmt const * stmt ) {
    6873        return field_erase_if( stmt, &ast::CompoundStmt::kids, isTypedefStmt );
  • src/Validate/FixQualifiedTypes.cpp

    r044ae62 rfa2c005  
    5959                                instp = inst;
    6060                        } else if ( auto inst = parent.as<ast::UnionInstType>() ) {
     61                                aggr = inst->base;
     62                                instp = inst;
     63                        } else if ( auto inst = parent.as<ast::AdtInstType>() ) {
    6164                                aggr = inst->base;
    6265                                instp = inst;
  • src/Validate/HoistStruct.cpp

    r044ae62 rfa2c005  
    2828        return dynamic_cast< ast::StructDecl const * >( decl )
    2929                || dynamic_cast< ast::UnionDecl const * >( decl )
    30                 || dynamic_cast< ast::StaticAssertDecl const * >( decl );
     30                || dynamic_cast< ast::StaticAssertDecl const * >( decl )
     31                || dynamic_cast< ast::AdtDecl const * >( decl );
    3132}
    3233
     
    4546        ast::UnionInstType const * previsit( ast::UnionInstType const * type );
    4647        ast::EnumInstType const * previsit( ast::EnumInstType const * type );
     48        ast::AdtDecl const * previsit( ast::AdtDecl const * decl );
     49        ast::AdtDecl const * postvisit( ast::AdtDecl const * decl );
    4750
    4851private:
     
    100103}
    101104
     105ast::AdtDecl const * HoistStructCore::previsit( ast::AdtDecl const * decl ) {
     106        return preAggregate( decl );
     107}
     108
     109ast::AdtDecl const * HoistStructCore::postvisit( ast::AdtDecl const * decl ) {
     110        return postAggregate( decl );
     111}
     112
    102113ast::StructDecl const * HoistStructCore::postvisit( ast::StructDecl const * decl ) {
    103114        return postAggregate( decl );
     
    138149}
    139150
    140 void hoistAdt( [[maybe_unused]] ast::TranslationUnit & trnaslationUnit ) {
    141        
    142 }
    143 
    144151} // namespace Validate
    145152
  • src/Validate/HoistStruct.hpp

    r044ae62 rfa2c005  
    2424/// Flattens nested type declarations. (Run right after Fix Qualified Types.)
    2525void hoistStruct( ast::TranslationUnit & translationUnit );
    26 void hoistAdt( ast::TranslationUnit & trnaslationUnit );
    2726
    2827}
  • src/Validate/LinkReferenceToTypes.cpp

    r044ae62 rfa2c005  
    2020#include "Validate/ForallPointerDecay.hpp"
    2121#include "Validate/NoIdSymbolTable.hpp"
     22#include <assert.h>
    2223
    2324namespace Validate {
     
    3536        ast::UnionInstType const * postvisit( ast::UnionInstType const * type );
    3637        ast::TraitInstType const * postvisit( ast::TraitInstType const * type );
     38        ast::AdtInstType const * postvisit( ast::AdtInstType const * type );
    3739        void previsit( ast::QualifiedType const * type );
    3840        void postvisit( ast::QualifiedType const * type );
     
    107109                auto mut = ast::mutate( type );
    108110                forwardStructs[ mut->name ].push_back( mut );
     111                type = mut;
     112        }
     113        return type;
     114}
     115
     116ast::AdtInstType const * LinkTypesCore::postvisit( ast::AdtInstType const * type ) {
     117        ast::AdtDecl const * decl = symtab.lookupAdt( type->name );
     118        assert( decl != nullptr );
     119        if ( decl ) {
     120                auto mut = ast::mutate( type );
     121                mut->base = const_cast<ast::AdtDecl *>( decl );
    109122                type = mut;
    110123        }
  • src/Validate/NoIdSymbolTable.hpp

    r044ae62 rfa2c005  
    4141        FORWARD_1( lookupUnion , const std::string & )
    4242        FORWARD_1( lookupTrait , const std::string & )
     43        FORWARD_1( lookupAdt   , const std::string & )
    4344        FORWARD_1( addType  , const ast::NamedTypeDecl * )
    4445        FORWARD_1( addStruct, const ast::StructDecl *    )
     
    4950        FORWARD_1( addStruct, const std::string &        )
    5051        FORWARD_1( addUnion , const std::string &        )
     52        FORWARD_1( addAdt   , const std::string &                )
    5153        FORWARD_2( addWith  , const std::vector< ast::ptr<ast::Expr> > &, const ast::Decl * )
    5254
  • src/Validate/ReplaceTypedef.cpp

    r044ae62 rfa2c005  
    6060        ast::StructDecl const * previsit( ast::StructDecl const * );
    6161        ast::UnionDecl const * previsit( ast::UnionDecl const * );
     62        ast::AdtDecl const * previsit( ast::AdtDecl const * );
    6263        void previsit( ast::EnumDecl const * );
    6364        void previsit( ast::TraitDecl const * );
     
    9091}
    9192
     93// Here, 5/30
    9294ast::Type const * ReplaceTypedefCore::postvisit(
    9395                ast::TypeInstType const * type ) {
    9496        // Instances of typedef types will come here. If it is an instance
    9597        // of a typedef type, link the instance to its actual type.
    96         TypedefMap::const_iterator def = typedefNames.find( type->name );
     98        TypedefMap::const_iterator def = typedefNames.find( type->name ); // because of this
    9799        if ( def != typedefNames.end() ) {
    98100                ast::Type * ret = ast::deepCopy( def->second.first->base );
     
    260262}
    261263
     264ast::AdtDecl const * ReplaceTypedefCore::previsit( ast::AdtDecl const * decl ) {
     265        visit_children = false;
     266        addImplicitTypedef( decl );
     267        return handleAggregate( decl );
     268}
     269
    262270ast::UnionDecl const * ReplaceTypedefCore::previsit( ast::UnionDecl const * decl ) {
    263271        visit_children = false;
     
    287295        } else if ( auto enumDecl = dynamic_cast<const ast::EnumDecl *>( aggrDecl ) ) {
    288296                type = new ast::EnumInstType( enumDecl->name );
     297        } else if ( auto adtDecl = dynamic_cast<const ast::AdtDecl *>( aggrDecl )) {
     298                type = new ast::AdtInstType( adtDecl->name );
    289299        }
    290300        assert( type );
Note: See TracChangeset for help on using the changeset viewer.