Changeset 522363e for src/SymTab


Ignore:
Timestamp:
Sep 14, 2017, 1:46:06 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
3e3d923, bff09c8, f92c696
Parents:
c57ded70
Message:

Fix PassVisitor? Indexer calls, aggregate top-level errors in PassVisitor?, convert ForallPointerDecay? and LinkReferenceToTypes? to PassVisitor?

Location:
src/SymTab
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    rc57ded70 r522363e  
    3737#include "SynTree/Type.h"          // for Type, StructInstType, UnionInstType
    3838
    39 #define debugPrint(x) if ( doDebug ) { std::cout << x; }
     39#define debugPrint(x) if ( doDebug ) { std::cerr << x; }
    4040
    4141namespace SymTab {
  • src/SymTab/Indexer.h

    rc57ded70 r522363e  
    104104
    105105                void print( std::ostream &os, int indent = 0 ) const;
    106           private:
     106
    107107                /// looks up a specific mangled ID at the given scope
    108108                DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
     
    127127                void addTrait( TraitDecl *decl );
    128128
     129          private:
    129130                struct Impl;
    130131
  • src/SymTab/Validate.cc

    rc57ded70 r522363e  
    123123
    124124        /// Associates forward declarations of aggregates with their definitions
    125         class LinkReferenceToTypes final : public Indexer {
    126                 typedef Indexer Parent;
    127           public:
    128                 LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
    129                 using Parent::visit;
    130                 void visit( TypeInstType *typeInst ) final;
    131 
    132                 void visit( EnumInstType *enumInst ) final;
    133                 void visit( StructInstType *structInst ) final;
    134                 void visit( UnionInstType *unionInst ) final;
    135                 void visit( TraitInstType *traitInst ) final;
    136 
    137                 void visit( EnumDecl *enumDecl ) final;
    138                 void visit( StructDecl *structDecl ) final;
    139                 void visit( UnionDecl *unionDecl ) final;
    140                 void visit( TraitDecl * traitDecl ) final;
     125        struct LinkReferenceToTypes final : public WithIndexer {
     126                LinkReferenceToTypes( const Indexer *indexer );
     127                void postvisit( TypeInstType *typeInst );
     128
     129                void postvisit( EnumInstType *enumInst );
     130                void postvisit( StructInstType *structInst );
     131                void postvisit( UnionInstType *unionInst );
     132                void postvisit( TraitInstType *traitInst );
     133
     134                void postvisit( EnumDecl *enumDecl );
     135                void postvisit( StructDecl *structDecl );
     136                void postvisit( UnionDecl *unionDecl );
     137                void postvisit( TraitDecl * traitDecl );
    141138
    142139          private:
    143                 const Indexer *indexer;
     140                const Indexer *local_indexer;
    144141
    145142                typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
     
    152149
    153150        /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.
    154         class ForallPointerDecay final : public Indexer {
    155                 typedef Indexer Parent;
    156           public:
    157                 using Parent::visit;
    158                 ForallPointerDecay( const Indexer *indexer );
    159 
    160                 virtual void visit( ObjectDecl *object ) override;
    161                 virtual void visit( FunctionDecl *func ) override;
    162 
    163                 const Indexer *indexer;
     151        struct ForallPointerDecay final {
     152                void previsit( ObjectDecl *object );
     153                void previsit( FunctionDecl *func );
    164154        };
    165155
     
    263253        };
    264254
    265         void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
     255        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
    266256                PassVisitor<EnumAndPointerDecay> epc;
    267                 LinkReferenceToTypes lrt( doDebug, 0 );
    268                 ForallPointerDecay fpd( 0 );
     257                PassVisitor<LinkReferenceToTypes> lrt( nullptr );
     258                PassVisitor<ForallPointerDecay> fpd;
    269259                PassVisitor<CompoundLiteral> compoundliteral;
    270260                PassVisitor<ValidateGenericParameters> genericParams;
     
    293283        void validateType( Type *type, const Indexer *indexer ) {
    294284                PassVisitor<EnumAndPointerDecay> epc;
    295                 LinkReferenceToTypes lrt( false, indexer );
    296                 ForallPointerDecay fpd( indexer );
     285                PassVisitor<LinkReferenceToTypes> lrt( indexer );
     286                PassVisitor<ForallPointerDecay> fpd;
    297287                type->accept( epc );
    298288                type->accept( lrt );
     
    408398        }
    409399
    410         LinkReferenceToTypes::LinkReferenceToTypes( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) {
     400        LinkReferenceToTypes::LinkReferenceToTypes( const Indexer *other_indexer ) {
    411401                if ( other_indexer ) {
    412                         indexer = other_indexer;
     402                        local_indexer = other_indexer;
    413403                } else {
    414                         indexer = this;
    415                 } // if
    416         }
    417 
    418         void LinkReferenceToTypes::visit( EnumInstType *enumInst ) {
    419                 Parent::visit( enumInst );
    420                 EnumDecl *st = indexer->lookupEnum( enumInst->get_name() );
     404                        local_indexer = &indexer;
     405                } // if
     406        }
     407
     408        void LinkReferenceToTypes::postvisit( EnumInstType *enumInst ) {
     409                EnumDecl *st = local_indexer->lookupEnum( enumInst->get_name() );
    421410                // it's not a semantic error if the enum is not found, just an implicit forward declaration
    422411                if ( st ) {
     
    430419        }
    431420
    432         void LinkReferenceToTypes::visit( StructInstType *structInst ) {
    433                 Parent::visit( structInst );
    434                 StructDecl *st = indexer->lookupStruct( structInst->get_name() );
     421        void LinkReferenceToTypes::postvisit( StructInstType *structInst ) {
     422                StructDecl *st = local_indexer->lookupStruct( structInst->get_name() );
    435423                // it's not a semantic error if the struct is not found, just an implicit forward declaration
    436424                if ( st ) {
     
    444432        }
    445433
    446         void LinkReferenceToTypes::visit( UnionInstType *unionInst ) {
    447                 Parent::visit( unionInst );
    448                 UnionDecl *un = indexer->lookupUnion( unionInst->get_name() );
     434        void LinkReferenceToTypes::postvisit( UnionInstType *unionInst ) {
     435                UnionDecl *un = local_indexer->lookupUnion( unionInst->get_name() );
    449436                // it's not a semantic error if the union is not found, just an implicit forward declaration
    450437                if ( un ) {
     
    499486        }
    500487
    501         void LinkReferenceToTypes::visit( TraitDecl * traitDecl ) {
    502                 Parent::visit( traitDecl );
    503 
     488        void LinkReferenceToTypes::postvisit( TraitDecl * traitDecl ) {
    504489                if ( traitDecl->name == "sized" ) {
    505490                        // "sized" is a special trait - flick the sized status on for the type variable
     
    523508        }
    524509
    525         void LinkReferenceToTypes::visit( TraitInstType * traitInst ) {
    526                 Parent::visit( traitInst );
     510        void LinkReferenceToTypes::postvisit( TraitInstType * traitInst ) {
    527511                // handle other traits
    528                 TraitDecl *traitDecl = indexer->lookupTrait( traitInst->name );
     512                TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name );
    529513                if ( ! traitDecl ) {
    530514                        throw SemanticError( "use of undeclared trait " + traitInst->name );
     
    547531        }
    548532
    549         void LinkReferenceToTypes::visit( EnumDecl *enumDecl ) {
     533        void LinkReferenceToTypes::postvisit( EnumDecl *enumDecl ) {
    550534                // visit enum members first so that the types of self-referencing members are updated properly
    551                 Parent::visit( enumDecl );
    552535                if ( ! enumDecl->get_members().empty() ) {
    553536                        ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->get_name() );
     
    561544        }
    562545
    563         void LinkReferenceToTypes::visit( StructDecl *structDecl ) {
     546        void LinkReferenceToTypes::postvisit( StructDecl *structDecl ) {
    564547                // visit struct members first so that the types of self-referencing members are updated properly
    565                 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and and their defaults)
    566                 Parent::visit( structDecl );
     548                // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)
    567549                if ( ! structDecl->get_members().empty() ) {
    568550                        ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
     
    576558        }
    577559
    578         void LinkReferenceToTypes::visit( UnionDecl *unionDecl ) {
    579                 Parent::visit( unionDecl );
     560        void LinkReferenceToTypes::postvisit( UnionDecl *unionDecl ) {
    580561                if ( ! unionDecl->get_members().empty() ) {
    581562                        ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
     
    589570        }
    590571
    591         void LinkReferenceToTypes::visit( TypeInstType *typeInst ) {
    592                 if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {
     572        void LinkReferenceToTypes::postvisit( TypeInstType *typeInst ) {
     573                if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->get_name() ) ) {
    593574                        if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
    594575                                typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
    595576                        } // if
    596                 } // if
    597         }
    598 
    599         ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) :  Indexer( false ) {
    600                 if ( other_indexer ) {
    601                         indexer = other_indexer;
    602                 } else {
    603                         indexer = this;
    604577                } // if
    605578        }
     
    633606        }
    634607
    635         void ForallPointerDecay::visit( ObjectDecl *object ) {
     608        void ForallPointerDecay::previsit( ObjectDecl *object ) {
    636609                forallFixer( object->get_type() );
    637610                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
    638611                        forallFixer( pointer->get_base() );
    639612                } // if
    640                 Parent::visit( object );
    641613                object->fixUniqueId();
    642614        }
    643615
    644         void ForallPointerDecay::visit( FunctionDecl *func ) {
     616        void ForallPointerDecay::previsit( FunctionDecl *func ) {
    645617                forallFixer( func->get_type() );
    646                 Parent::visit( func );
    647618                func->fixUniqueId();
    648619        }
Note: See TracChangeset for help on using the changeset viewer.