Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r2bfc6b2 r7e08acf  
    7575#include "SynTree/Visitor.h"           // for Visitor
    7676#include "Validate/HandleAttributes.h" // for handleAttributes
    77 #include "Validate/FindSpecialDecls.h" // for FindSpecialDecls
    7877
    7978class CompoundStmt;
     
    288287        };
    289288
     289        FunctionDecl * dereferenceOperator = nullptr;
     290        struct FindSpecialDeclarations final {
     291                void previsit( FunctionDecl * funcDecl );
     292        };
     293
    290294        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
    291295                PassVisitor<EnumAndPointerDecay> epc;
     
    294298                PassVisitor<CompoundLiteral> compoundliteral;
    295299                PassVisitor<ValidateGenericParameters> genericParams;
     300                PassVisitor<FindSpecialDeclarations> finder;
    296301                PassVisitor<LabelAddressFixer> labelAddrFixer;
    297302                PassVisitor<HoistTypeDecls> hoistDecls;
     
    320325                FixObjectType::fix( translationUnit );
    321326                ArrayLength::computeLength( translationUnit );
    322                 Validate::findSpecialDecls( translationUnit );
     327                acceptAll( translationUnit, finder ); // xxx - remove this pass soon
    323328                mutateAll( translationUnit, labelAddrFixer );
    324329                Validate::handleAttributes( translationUnit );
     
    398403                        assert( aggr ); // TODO: need to handle forward declarations
    399404                        for ( Declaration * member : aggr->members ) {
    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 ) ) {
     405                                if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( child ) ) {
    420406                                        // name on the right is a typedef
    421407                                        if ( NamedTypeDecl * aggr = dynamic_cast< NamedTypeDecl * > ( member ) ) {
     
    424410                                                        Type * ret = aggr->base->clone();
    425411                                                        ret->get_qualifiers() = qualType->get_qualifiers();
     412                                                        TypeSubstitution sub = parent->genericSubstitution();
     413                                                        sub.apply(ret);
    426414                                                        return ret;
    427415                                                }
     
    896884                if ( eliminator.pass.typedefNames.count( "size_t" ) ) {
    897885                        // grab and remember declaration of size_t
    898                         Validate::SizeType = eliminator.pass.typedefNames["size_t"].first->base->clone();
     886                        SizeType = eliminator.pass.typedefNames["size_t"].first->base->clone();
    899887                } else {
    900888                        // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
    901889                        // eventually should have a warning for this case.
    902                         Validate::SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     890                        SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    903891                }
    904892        }
     
    12881276                        // need to resolve array dimensions early so that constructor code can correctly determine
    12891277                        // if a type is a VLA (and hence whether its elements need to be constructed)
    1290                         ResolvExpr::findSingleExpression( type->dimension, Validate::SizeType->clone(), indexer );
     1278                        ResolvExpr::findSingleExpression( type->dimension, SymTab::SizeType->clone(), indexer );
    12911279
    12921280                        // must re-evaluate whether a type is a VLA, now that more information is available
     
    13251313                return addrExpr;
    13261314        }
     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        }
    13271326} // namespace SymTab
    13281327
Note: See TracChangeset for help on using the changeset viewer.