Changeset 2f42718 for src/SymTab


Ignore:
Timestamp:
Feb 22, 2019, 10:43:29 AM (7 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
no_list
Parents:
43e0949
Message:

Parameters and return value of functions are now vectors (and some related clean-up)

Location:
src/SymTab
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    r43e0949 r2f42718  
    410410                                }
    411411
    412                                 assert( ! func->get_functionType()->get_parameters().empty() );
    413                                 ObjectDecl * dstParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->get_parameters().front() );
     412                                assert( ! func->get_functionType()->parameters.empty() );
     413                                ObjectDecl * dstParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->parameters.front() );
    414414                                ObjectDecl * srcParam = nullptr;
    415                                 if ( func->get_functionType()->get_parameters().size() == 2 ) {
    416                                         srcParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->get_parameters().back() );
     415                                if ( func->get_functionType()->parameters.size() == 2 ) {
     416                                        srcParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->parameters.back() );
    417417                                }
    418418
     
    429429        void StructFuncGenerator::makeFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func ) {
    430430                FunctionType * ftype = func->type;
    431                 std::list<DeclarationWithType*> & params = ftype->parameters;
     431                auto & params = ftype->parameters;
    432432                assert( params.size() >= 2 );  // should not call this function for default ctor, etc.
    433433
     
    435435                ObjectDecl * dstParam = dynamic_cast<ObjectDecl*>( params.front() );
    436436                assert( dstParam );
    437                 std::list<DeclarationWithType*>::iterator parameter = params.begin()+1;
     437                auto parameter = params.begin()+1;
    438438                for ( ; member != end; ++member ) {
    439439                        if ( DeclarationWithType * field = dynamic_cast<DeclarationWithType*>( *member ) ) {
     
    656656        void makeTupleFunctionBody( FunctionDecl * function ) {
    657657                FunctionType * ftype = function->get_functionType();
    658                 assertf( ftype->get_parameters().size() == 1 || ftype->get_parameters().size() == 2, "too many parameters in generated tuple function" );
     658                assertf( ftype->parameters.size() == 1 || ftype->parameters.size() == 2, "too many parameters in generated tuple function" );
    659659
    660660                UntypedExpr * untyped = new UntypedExpr( new NameExpr( function->get_name() ) );
    661661
    662662                /// xxx - &* is used to make this easier for later passes to handle
    663                 untyped->get_args().push_back( new AddressExpr( UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) );
    664                 if ( ftype->get_parameters().size() == 2 ) {
    665                         untyped->get_args().push_back( new VariableExpr( ftype->get_parameters().back() ) );
    666                 }
    667                 function->get_statements()->get_kids().push_back( new ExprStmt( untyped ) );
    668                 function->get_statements()->get_kids().push_back( new ReturnStmt( UntypedExpr::createDeref( new VariableExpr( ftype->get_parameters().front() ) ) ) );
     663                untyped->get_args().push_back( new AddressExpr( UntypedExpr::createDeref( new VariableExpr( ftype->parameters.front() ) ) ) );
     664                if ( ftype->parameters.size() == 2 ) {
     665                        untyped->get_args().push_back( new VariableExpr( ftype->parameters.back() ) );
     666                }
     667                function->statements->get_kids().push_back( new ExprStmt( untyped ) );
     668                function->statements->get_kids().push_back( new ReturnStmt( UntypedExpr::createDeref( new VariableExpr( ftype->parameters.front() ) ) ) );
    669669        }
    670670
     
    691691                                        TypeDecl * newDecl = new TypeDecl( ty->get_baseType()->get_name(), Type::StorageClasses(), nullptr, TypeDecl::Dtype, true );
    692692                                        TypeInstType * inst = new TypeInstType( Type::Qualifiers(), newDecl->get_name(), newDecl );
    693                                         newDecl->get_assertions().push_back( new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, genAssignType( inst ), nullptr,
     693                                        newDecl->assertions.push_back( new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, genAssignType( inst ), nullptr,
    694694                                                                                                                                                   std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) );
    695                                         newDecl->get_assertions().push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr,
     695                                        newDecl->assertions.push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr,
    696696                                                                                                                                                   std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) );
    697                                         newDecl->get_assertions().push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genCopyType( inst ), nullptr,
     697                                        newDecl->assertions.push_back( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, genCopyType( inst ), nullptr,
    698698                                                                                                                                                   std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) );
    699                                         newDecl->get_assertions().push_back( new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr,
     699                                        newDecl->assertions.push_back( new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, genDefaultType( inst ), nullptr,
    700700                                                                                                                                                   std::vector< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ) );
    701701                                        typeParams.push_back( newDecl );
  • src/SymTab/Demangle.cc

    r43e0949 r2f42718  
    173173
    174174                /************* parameters ***************/
    175                 const std::list<DeclarationWithType *> &pars = funcType->parameters;
     175                const std::vector<DeclarationWithType *> &pars = funcType->parameters;
    176176
    177177                if ( pars.empty() ) {
     
    476476                        Type * StringView::parseTuple(Type::Qualifiers tq) {
    477477                                PRINT( std::cerr << "tuple..." << std::endl; )
    478                                 std::list< Type * > types;
     478                                std::vector< Type * > types;
    479479                                size_t ncomponents;
    480480                                if (! extractNumber(ncomponents)) return nullptr;
  • src/SymTab/Indexer.cc

    r43e0949 r2f42718  
    142142                for ( auto decl : copy ) {
    143143                        if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl.id ) ) {
    144                                 std::list< DeclarationWithType * > & params = function->type->parameters;
     144                                auto & params = function->type->parameters;
    145145                                assert( ! params.empty() );
    146146                                // use base type of pointer, so that qualifiers on the pointer type aren't considered.
     
    668668        }
    669669
    670         void Indexer::addIds( const std::list< DeclarationWithType * > & decls ) {
     670        void Indexer::addIds( const std::vector< DeclarationWithType * > & decls ) {
    671671                for ( auto d : decls ) {
    672672                        addId( d );
  • src/SymTab/Indexer.h

    r43e0949 r2f42718  
    117117
    118118                /// convenience function for adding a list of Ids to the indexer
    119                 void addIds( const std::list< DeclarationWithType * > & decls );
     119                void addIds( const std::vector< DeclarationWithType * > & decls );
    120120
    121121                /// convenience function for adding a list of forall parameters to the indexer
  • src/SymTab/Mangler.cc

    r43e0949 r2f42718  
    7979
    8080                          public:
    81                                 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 
    82                                         int nextVarNum, const ResolvExpr::TypeEnvironment* env, 
     81                                Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
     82                                        int nextVarNum, const ResolvExpr::TypeEnvironment* env,
    8383                                        const VarMapType& varNums );
    8484
     
    109109                }
    110110
    111                 std::string mangleAssnKey( DeclarationWithType* decl, 
     111                std::string mangleAssnKey( DeclarationWithType* decl,
    112112                                const ResolvExpr::TypeEnvironment& env ) {
    113113                        PassVisitor<Mangler> mangler( env );
     
    118118                namespace {
    119119                        Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams )
    120                                 : nextVarNum( 0 ), env(nullptr), isTopLevel( true ), 
    121                                 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 
     120                                : nextVarNum( 0 ), env(nullptr), isTopLevel( true ),
     121                                mangleOverridable( mangleOverridable ), typeMode( typeMode ),
    122122                                mangleGenericParams( mangleGenericParams ) {}
    123                        
     123
    124124                        Mangler::Mangler( const ResolvExpr::TypeEnvironment& env )
    125125                                : nextVarNum( 0 ), env( &env ), isTopLevel( true ), mangleOverridable( false ),
    126126                                typeMode( false ), mangleGenericParams( true ) {}
    127                        
    128                         Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 
    129                                 int nextVarNum, const ResolvExpr::TypeEnvironment* env, 
     127
     128                        Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams,
     129                                int nextVarNum, const ResolvExpr::TypeEnvironment* env,
    130130                                const VarMapType& varNums )
    131                                 : varNums( varNums ), nextVarNum( nextVarNum ), env( env ), isTopLevel( false ), 
    132                                 mangleOverridable( mangleOverridable ), typeMode( typeMode ), 
     131                                : varNums( varNums ), nextVarNum( nextVarNum ), env( env ), isTopLevel( false ),
     132                                mangleOverridable( mangleOverridable ), typeMode( typeMode ),
    133133                                mangleGenericParams( mangleGenericParams ) {}
    134134
     
    207207
    208208                        namespace {
    209                                 inline std::list< Type* > getTypes( const std::list< DeclarationWithType* > decls ) {
    210                                         std::list< Type* > ret;
     209                                inline std::vector< Type* > getTypes( const std::vector< DeclarationWithType* > decls ) {
     210                                        std::vector< Type* > ret;
    211211                                        std::transform( decls.begin(), decls.end(), std::back_inserter( ret ),
    212212                                                                        std::mem_fun( &DeclarationWithType::get_type ) );
     
    223223                                GuardValue( inFunctionType );
    224224                                inFunctionType = true;
    225                                 std::list< Type* > returnTypes = getTypes( functionType->returnVals );
     225                                std::vector< Type* > returnTypes = getTypes( functionType->returnVals );
    226226                                if (returnTypes.empty()) mangleName << Encoding::void_t;
    227227                                else acceptAll( returnTypes, *visitor );
    228228                                mangleName << "_";
    229                                 std::list< Type* > paramTypes = getTypes( functionType->parameters );
     229                                std::vector< Type* > paramTypes = getTypes( functionType->parameters );
    230230                                acceptAll( paramTypes, *visitor );
    231231                                mangleName << "_";
     
    238238
    239239                                if ( mangleGenericParams ) {
    240                                         std::list< Expression* >& params = refType->parameters;
     240                                        std::list< Expression* > & params = refType->parameters;
    241241                                        if ( ! params.empty() ) {
    242242                                                mangleName << "_";
    243                                                 for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param ) {
    244                                                         TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
    245                                                         assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(*param));
     243                                                for ( auto param : params ) {
     244                                                        TypeExpr *paramType = dynamic_cast< TypeExpr* >( param );
     245                                                        assertf(paramType, "Aggregate parameters should be type expressions: %s", toCString(param));
    246246                                                        maybeAccept( paramType->type, *visitor );
    247247                                                }
     
    364364                                                        if ( varClass && varClass->type ) {
    365365                                                                PassVisitor<Mangler> sub_mangler(
    366                                                                         mangleOverridable, typeMode, mangleGenericParams, nextVarNum, 
     366                                                                        mangleOverridable, typeMode, mangleGenericParams, nextVarNum,
    367367                                                                        env, varNums );
    368368                                                                varClass->type->accept( sub_mangler );
     
    375375                                                }
    376376                                                varNums[ (*i)->name ] = std::make_pair( varName, (int)(*i)->get_kind() );
    377                                                 for ( std::list< DeclarationWithType* >::iterator assert = (*i)->assertions.begin(); assert != (*i)->assertions.end(); ++assert ) {
    378                                                         PassVisitor<Mangler> sub_mangler( 
    379                                                                 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, env, 
     377                                                for ( auto assert : (*i)->assertions ) {
     378                                                        PassVisitor<Mangler> sub_mangler(
     379                                                                mangleOverridable, typeMode, mangleGenericParams, nextVarNum, env,
    380380                                                                varNums );
    381                                                         (*assert)->accept( sub_mangler );
     381                                                        assert->accept( sub_mangler );
    382382                                                        assertionNames.push_back( sub_mangler.pass.get_mangleName() );
    383383                                                        acount++;
  • src/SymTab/Validate.cc

    r43e0949 r2f42718  
    179179                void previsit( ReturnStmt * returnStmt );
    180180
    181                 typedef std::list< DeclarationWithType * > ReturnVals;
    182                 ReturnVals returnVals;
     181                std::vector< DeclarationWithType * > returnVals;
    183182        };
    184183
     
    866865        void ReturnChecker::previsit( FunctionDecl * functionDecl ) {
    867866                GuardValue( returnVals );
    868                 returnVals = functionDecl->get_functionType()->get_returnVals();
     867                returnVals = functionDecl->get_functionType()->returnVals;
    869868        }
    870869
     
    11211120        void VerifyCtorDtorAssign::previsit( FunctionDecl * funcDecl ) {
    11221121                FunctionType * funcType = funcDecl->get_functionType();
    1123                 std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();
    1124                 std::list< DeclarationWithType * > &params = funcType->get_parameters();
     1122                auto & returnVals = funcType->returnVals;
     1123                auto & params = funcType->parameters;
    11251124
    11261125                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
     
    12051204        void ReturnTypeFixer::postvisit( FunctionDecl * functionDecl ) {
    12061205                FunctionType * ftype = functionDecl->get_functionType();
    1207                 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
     1206                auto & retVals = ftype->returnVals;
    12081207                assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %zu", functionDecl->get_name().c_str(), retVals.size() );
    12091208                if ( retVals.size() == 1 ) {
     
    12231222                // Note that this pass needs to happen early so that other passes which look for tuple types
    12241223                // find them in all of the right places, including function return types.
    1225                 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
     1224                auto & retVals = ftype->returnVals;
    12261225                if ( retVals.size() > 1 ) {
    12271226                        // generate a single return parameter which is the tuple of all of the return values
     
    13201319                        if ( funcDecl->get_name() == "*?" && funcDecl->get_linkage() == LinkageSpec::Intrinsic ) {
    13211320                                FunctionType * ftype = funcDecl->get_functionType();
    1322                                 if ( ftype->get_parameters().size() == 1 && ftype->get_parameters().front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {
     1321                                if ( ftype->parameters.size() == 1 && ftype->parameters.front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {
    13231322                                        dereferenceOperator = funcDecl;
    13241323                                }
Note: See TracChangeset for help on using the changeset viewer.