Ignore:
Timestamp:
Nov 8, 2017, 5:43:33 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
954908d
Parents:
78315272 (diff), e35f30a (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 branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r78315272 r3f7e12cb  
    5656#include "FixFunction.h"               // for FixFunction
    5757#include "Indexer.h"                   // for Indexer
     58#include "InitTweak/GenInit.h"         // for fixReturnStatements
    5859#include "InitTweak/InitTweak.h"       // for isCtorDtorAssign
    5960#include "Parser/LinkageSpec.h"        // for C
     
    150151        /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.
    151152        struct ForallPointerDecay final {
    152                 void previsit( ObjectDecl *object );
    153                 void previsit( FunctionDecl *func );
     153                void previsit( ObjectDecl * object );
     154                void previsit( FunctionDecl * func );
     155                void previsit( StructDecl * aggrDecl );
     156                void previsit( UnionDecl * aggrDecl );
    154157        };
    155158
     
    265268                HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
    266269                ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
     270                acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes because it is an indexer and needs correct types for mangling
    267271                acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
    268272                acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes
    269                 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist
    270273                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
     274                ReturnChecker::checkFunctionReturns( translationUnit );
     275                InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
    271276                Concurrency::applyKeywords( translationUnit );
     277                acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
    272278                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
    273279                Concurrency::implementMutexFuncs( translationUnit );
    274280                Concurrency::implementThreadStarter( translationUnit );
    275                 ReturnChecker::checkFunctionReturns( translationUnit );
    276281                mutateAll( translationUnit, compoundliteral );
    277                 acceptAll( translationUnit, fpd );
    278282                ArrayLength::computeLength( translationUnit );
    279                 acceptAll( translationUnit, finder );
     283                acceptAll( translationUnit, finder ); // xxx - remove this pass soon
    280284                mutateAll( translationUnit, labelAddrFixer );
    281285        }
     
    368372                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
    369373                        if ( begin == end ) return;
    370                         FixFunction fixer;
     374                        PassVisitor<FixFunction> fixer;
    371375                        DWTIterator i = begin;
    372376                        *i = (*i)->acceptMutator( fixer );
    373                         if ( fixer.get_isVoid() ) {
     377                        if ( fixer.pass.isVoid ) {
    374378                                DWTIterator j = i;
    375379                                ++i;
     
    382386                                ++i;
    383387                                for ( ; i != end; ++i ) {
    384                                         FixFunction fixer;
     388                                        PassVisitor<FixFunction> fixer;
    385389                                        *i = (*i)->acceptMutator( fixer );
    386                                         if ( fixer.get_isVoid() ) {
     390                                        if ( fixer.pass.isVoid ) {
    387391                                                throw SemanticError( "invalid type void in function type ", func );
    388392                                        } // if
     
    579583
    580584        /// Fix up assertions - flattens assertion lists, removing all trait instances
    581         void forallFixer( Type * func ) {
    582                 for ( TypeDecl * type : func->get_forall() ) {
     585        void forallFixer( std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) {
     586                for ( TypeDecl * type : forall ) {
    583587                        std::list< DeclarationWithType * > asserts;
    584588                        asserts.splice( asserts.end(), type->assertions );
     
    596600                        // apply FixFunction to every assertion to check for invalid void type
    597601                        for ( DeclarationWithType *& assertion : type->assertions ) {
    598                                 FixFunction fixer;
     602                                PassVisitor<FixFunction> fixer;
    599603                                assertion = assertion->acceptMutator( fixer );
    600                                 if ( fixer.get_isVoid() ) {
    601                                         throw SemanticError( "invalid type void in assertion of function ", func );
     604                                if ( fixer.pass.isVoid ) {
     605                                        throw SemanticError( "invalid type void in assertion of function ", node );
    602606                                } // if
    603607                        } // for
     
    607611
    608612        void ForallPointerDecay::previsit( ObjectDecl *object ) {
    609                 forallFixer( object->get_type() );
    610                 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
    611                         forallFixer( pointer->get_base() );
     613                forallFixer( object->type->forall, object );
     614                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->type ) ) {
     615                        forallFixer( pointer->base->forall, object );
    612616                } // if
    613617                object->fixUniqueId();
     
    615619
    616620        void ForallPointerDecay::previsit( FunctionDecl *func ) {
    617                 forallFixer( func->get_type() );
     621                forallFixer( func->type->forall, func );
    618622                func->fixUniqueId();
     623        }
     624
     625        void ForallPointerDecay::previsit( StructDecl * aggrDecl ) {
     626                forallFixer( aggrDecl->parameters, aggrDecl );
     627        }
     628
     629        void ForallPointerDecay::previsit( UnionDecl * aggrDecl ) {
     630                forallFixer( aggrDecl->parameters, aggrDecl );
    619631        }
    620632
     
    656668                }
    657669                filter( translationUnit, isTypedef, true );
    658 
    659670        }
    660671
     
    664675                TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() );
    665676                if ( def != typedefNames.end() ) {
    666                         Type *ret = def->second.first->get_base()->clone();
     677                        Type *ret = def->second.first->base->clone();
    667678                        ret->get_qualifiers() |= typeInst->get_qualifiers();
    668679                        // place instance parameters on the typedef'd type
    669                         if ( ! typeInst->get_parameters().empty() ) {
     680                        if ( ! typeInst->parameters.empty() ) {
    670681                                ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
    671682                                if ( ! rtt ) {
    672                                         throw SemanticError("cannot apply type parameters to base type of " + typeInst->get_name());
     683                                        throw SemanticError("Cannot apply type parameters to base type of " + typeInst->name);
    673684                                }
    674685                                rtt->get_parameters().clear();
    675                                 cloneAll( typeInst->get_parameters(), rtt->get_parameters() );
    676                                 mutateAll( rtt->get_parameters(), *visitor );  // recursively fix typedefs on parameters
     686                                cloneAll( typeInst->parameters, rtt->parameters );
     687                                mutateAll( rtt->parameters, *visitor );  // recursively fix typedefs on parameters
    677688                        } // if
    678689                        delete typeInst;
     
    680691                } else {
    681692                        TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() );
    682                         assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst->get_name().c_str() );
     693                        assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst->name.c_str() );
    683694                        typeInst->set_baseType( base->second );
    684695                } // if
    685696                return typeInst;
     697        }
     698
     699        struct VarLenChecker : WithShortCircuiting {
     700                void previsit( FunctionType * ) { visit_children = false; }
     701                void previsit( ArrayType * at ) {
     702                        isVarLen |= at->isVarLen;
     703                }
     704                bool isVarLen = false;
     705        };
     706
     707        bool isVariableLength( Type * t ) {
     708                PassVisitor<VarLenChecker> varLenChecker;
     709                maybeAccept( t, varLenChecker );
     710                return varLenChecker.pass.isVarLen;
    686711        }
    687712
     
    694719                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
    695720                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
    696                                 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
     721                                throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
     722                        }
     723                        // cannot redefine VLA typedefs
     724                        if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) {
     725                                throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
    697726                        }
    698727                } else {
Note: See TracChangeset for help on using the changeset viewer.