Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r7e08acf r2bfc6b2  
    7575#include "SynTree/Visitor.h"           // for Visitor
    7676#include "Validate/HandleAttributes.h" // for handleAttributes
     77#include "Validate/FindSpecialDecls.h" // for FindSpecialDecls
    7778
    7879class CompoundStmt;
     
    287288        };
    288289
    289         FunctionDecl * dereferenceOperator = nullptr;
    290         struct FindSpecialDeclarations final {
    291                 void previsit( FunctionDecl * funcDecl );
    292         };
    293 
    294290        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
    295291                PassVisitor<EnumAndPointerDecay> epc;
     
    298294                PassVisitor<CompoundLiteral> compoundliteral;
    299295                PassVisitor<ValidateGenericParameters> genericParams;
    300                 PassVisitor<FindSpecialDeclarations> finder;
    301296                PassVisitor<LabelAddressFixer> labelAddrFixer;
    302297                PassVisitor<HoistTypeDecls> hoistDecls;
     
    325320                FixObjectType::fix( translationUnit );
    326321                ArrayLength::computeLength( translationUnit );
    327                 acceptAll( translationUnit, finder ); // xxx - remove this pass soon
     322                Validate::findSpecialDecls( translationUnit );
    328323                mutateAll( translationUnit, labelAddrFixer );
    329324                Validate::handleAttributes( translationUnit );
     
    403398                        assert( aggr ); // TODO: need to handle forward declarations
    404399                        for ( Declaration * member : aggr->members ) {
    405                                 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
     400                                if ( StructInstType * inst = dynamic_cast< StructInstType * >( child ) ) {
     401                                        if ( StructDecl * aggr = dynamic_cast< StructDecl * >( member ) ) {
     402                                                if ( aggr->name == inst->name ) {
     403                                                        // TODO: is this case, and other non-TypeInstType cases, necessary?
     404                                                        return new StructInstType( qualType->get_qualifiers(), aggr );
     405                                                }
     406                                        }
     407                                } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( child ) ) {
     408                                        if ( UnionDecl * aggr = dynamic_cast< UnionDecl * > ( member ) ) {
     409                                                if ( aggr->name == inst->name ) {
     410                                                        return new UnionInstType( qualType->get_qualifiers(), aggr );
     411                                                }
     412                                        }
     413                                } else if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( child ) ) {
     414                                        if ( EnumDecl * aggr = dynamic_cast< EnumDecl * > ( member ) ) {
     415                                                if ( aggr->name == inst->name ) {
     416                                                        return new EnumInstType( qualType->get_qualifiers(), aggr );
     417                                                }
     418                                        }
     419                                } else if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
    406420                                        // name on the right is a typedef
    407421                                        if ( NamedTypeDecl * aggr = dynamic_cast< NamedTypeDecl * > ( member ) ) {
     
    410424                                                        Type * ret = aggr->base->clone();
    411425                                                        ret->get_qualifiers() = qualType->get_qualifiers();
    412                                                         TypeSubstitution sub = parent->genericSubstitution();
    413                                                         sub.apply(ret);
    414426                                                        return ret;
    415427                                                }
     
    884896                if ( eliminator.pass.typedefNames.count( "size_t" ) ) {
    885897                        // grab and remember declaration of size_t
    886                         SizeType = eliminator.pass.typedefNames["size_t"].first->base->clone();
     898                        Validate::SizeType = eliminator.pass.typedefNames["size_t"].first->base->clone();
    887899                } else {
    888900                        // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
    889901                        // eventually should have a warning for this case.
    890                         SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     902                        Validate::SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    891903                }
    892904        }
     
    12761288                        // need to resolve array dimensions early so that constructor code can correctly determine
    12771289                        // if a type is a VLA (and hence whether its elements need to be constructed)
    1278                         ResolvExpr::findSingleExpression( type->dimension, SymTab::SizeType->clone(), indexer );
     1290                        ResolvExpr::findSingleExpression( type->dimension, Validate::SizeType->clone(), indexer );
    12791291
    12801292                        // must re-evaluate whether a type is a VLA, now that more information is available
     
    13131325                return addrExpr;
    13141326        }
    1315 
    1316         void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) {
    1317                 if ( ! dereferenceOperator ) {
    1318                         if ( funcDecl->get_name() == "*?" && funcDecl->get_linkage() == LinkageSpec::Intrinsic ) {
    1319                                 FunctionType * ftype = funcDecl->get_functionType();
    1320                                 if ( ftype->get_parameters().size() == 1 && ftype->get_parameters().front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {
    1321                                         dereferenceOperator = funcDecl;
    1322                                 }
    1323                         }
    1324                 }
    1325         }
    13261327} // namespace SymTab
    13271328
Note: See TracChangeset for help on using the changeset viewer.