Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r73737e5 r51b986f  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jul 13 14:38:19 2015
    13 // Update Count     : 184
     12// Last Modified On : Wed Jul 22 13:16:00 2015
     13// Update Count     : 194
    1414//
    1515
     
    162162        class EliminateTypedef : public Mutator {
    163163          public:
    164           EliminateTypedef() : scopeLevel( 0 ) {}
    165             /// Replaces typedefs by forward declarations
     164                EliminateTypedef() : scopeLevel( 0 ) {}
    166165                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
    167166          private:
     
    169168                virtual TypeDecl *mutate( TypeDecl *typeDecl );
    170169                virtual DeclarationWithType *mutate( FunctionDecl *funcDecl );
    171                 virtual ObjectDecl *mutate( ObjectDecl *objDecl );
     170                virtual DeclarationWithType *mutate( ObjectDecl *objDecl );
    172171                virtual CompoundStmt *mutate( CompoundStmt *compoundStmt );
    173172                virtual Type *mutate( TypeInstType *aggregateUseType );
     
    203202        void validateType( Type *type, const Indexer *indexer ) {
    204203                Pass1 pass1;
     204                Pass2 pass2( false, indexer );
    205205                Pass3 pass3( indexer );
    206206                type->accept( pass1 );
     207                type->accept( pass2 );
    207208                type->accept( pass3 );
    208209        }
     
    403404                        } // for
    404405                } // for
     406
     407                if ( ctx->get_parameters().size() != contextInst->get_parameters().size() ) {
     408                        throw SemanticError( "incorrect number of context parameters: ", contextInst );
     409                } // if
     410
    405411                applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
    406412        }
     
    534540                init->get_args().push_back( new NameExpr( "0" ) );
    535541                Statement *initStmt = new ExprStmt( noLabels, init );
    536  
     542                std::list<Statement *> initList;
     543                initList.push_back( initStmt );
     544
    537545                UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
    538546                cond->get_args().push_back( new VariableExpr( index ) );
     
    559567                assignExpr->get_args().push_back( srcIndex );
    560568 
    561                 *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
     569                *out++ = new ForStmt( noLabels, initList, cond, inc, new ExprStmt( noLabels, assignExpr ) );
    562570        }
    563571
     
    609617
    610618                // need to remove the prototypes, since this may be nested in a routine
    611                 for (int start = 0, end = assigns.size()/2; start < end; start++) {
     619                for ( int start = 0, end = assigns.size() / 2; start < end; start++ ) {
    612620                        delete assigns.front();
    613621                        assigns.pop_front();
    614                 }
     622                } // for
    615623
    616624                declsToAdd.insert( declsToAdd.begin(), assigns.begin(), assigns.end() );
     
    827835                                rtt->get_parameters().clear();
    828836                                cloneAll(typeInst->get_parameters(), rtt->get_parameters());
    829                         }
     837                        } // if
    830838                        delete typeInst;
    831839                        return ret;
     
    881889        }
    882890
    883         ObjectDecl *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
     891        DeclarationWithType *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
    884892                TypedefMap oldNames = typedefNames;
    885                 ObjectDecl *ret = Mutator::mutate( objDecl );
     893                DeclarationWithType *ret = Mutator::mutate( objDecl );
     894                if ( FunctionType *funtype = dynamic_cast<FunctionType *>( ret->get_type() ) ) {
     895                        return new FunctionDecl( ret->get_name(), ret->get_storageClass(), ret->get_linkage(), funtype, 0, ret->get_isInline(), ret->get_isNoreturn() );
     896                } else if ( objDecl->get_isInline() || objDecl->get_isNoreturn() ) {
     897                        throw SemanticError( "invalid inline or _Noreturn specification in declaration of ", objDecl );
     898                } // if
    886899                typedefNames = oldNames;
    887900                return ret;
     
    947960        }
    948961
    949                 Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
     962        Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
    950963                Mutator::mutate( contextDecl );
    951964                return handleAggregate( contextDecl );
Note: See TracChangeset for help on using the changeset viewer.