Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r954c954 r4ef08f7  
    177177        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    178178                if ( inCache( node ) ) return nullptr;
    179 
    180                 // function decl contains real variables that the type must use.
    181                 // the structural change means function type in and out of decl
    182                 // must be handled **differently** on convert back to old.
    183                 auto ftype = new FunctionType(
    184                         cv(node->type),
    185                         (bool)node->type->isVarArgs
    186                 );
    187                 ftype->returnVals = get<DeclarationWithType>().acceptL(node->returns);
    188                 ftype->parameters = get<DeclarationWithType>().acceptL(node->params);
    189 
    190                 ftype->forall = get<TypeDecl>().acceptL( node->type->forall );
    191 
    192                 visitType(node->type, ftype);
    193 
    194179                auto decl = new FunctionDecl(
    195180                        node->name,
    196181                        Type::StorageClasses( node->storage.val ),
    197182                        LinkageSpec::Spec( node->linkage.val ),
    198                         ftype,
    199                         //get<FunctionType>().accept1( node->type ),
     183                        get<FunctionType>().accept1( node->type ),
    200184                        {},
    201185                        get<Attribute>().acceptL( node->attributes ),
     
    11681152
    11691153        const ast::Type * visit( const ast::FunctionType * node ) override final {
    1170                 static std::string dummy_paramvar_prefix = "__param_";
    1171                 static std::string dummy_returnvar_prefix = "__retval_";
    1172 
    11731154                auto ty = new FunctionType {
    11741155                        cv( node ),
    11751156                        (bool)node->isVarArgs
    11761157                };
    1177                 auto returns = get<Type>().acceptL(node->returns);
    1178                 auto params = get<Type>().acceptL(node->params);
    1179 
    1180                 int ret_index = 0;
    1181                 for (auto t: returns) {
    1182                         // xxx - LinkageSpec shouldn't matter but needs to be something
    1183                         ObjectDecl * dummy = new ObjectDecl(dummy_returnvar_prefix + std::to_string(ret_index++), {}, LinkageSpec::C, nullptr, t, nullptr);
    1184                         ty->returnVals.push_back(dummy);
    1185                 }
    1186                 int param_index = 0;
    1187                 for (auto t: params) {
    1188                         ObjectDecl * dummy = new ObjectDecl(dummy_paramvar_prefix + std::to_string(param_index++), {}, LinkageSpec::C, nullptr, t, nullptr);
    1189                         ty->parameters.push_back(dummy);
    1190                 }
    1191 
    1192                 // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
    1193                 // ty->parameters = get<DeclarationWithType>().acceptL( node->params );
     1158                ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
     1159                ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    11941160                ty->forall = get<TypeDecl>().acceptL( node->forall );
    11951161                return visitType( node, ty );
    11961162        }
    11971163
    1198         const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
     1164        const ast::Type * postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) {
    11991165                ty->forall = get<TypeDecl>().acceptL( old->forall );
    12001166                ty->parameters = get<Expression>().acceptL( old->params );
     
    14081374        ast::Node * node = nullptr;
    14091375        /// cache of nodes that might be referenced by readonly<> for de-duplication
    1410         /// in case that some nodes are dropped by conversion (due to possible structural change)
    1411         /// use smart pointers in cache value to prevent accidental invalidation.
    1412         /// at conversion stage, all created nodes are guaranteed to be unique, therefore
    1413         /// const_casting out of smart pointers is permitted.
    1414         std::unordered_map< const BaseSyntaxNode *, ast::ptr<ast::Node> > cache = {};
     1376        std::unordered_map< const BaseSyntaxNode *, ast::Node * > cache = {};
    14151377
    14161378        // Local Utilities:
     
    14851447                auto it = cache.find( old );
    14861448                if ( it == cache.end() ) return false;
    1487                 node = const_cast<ast::Node *>(it->second.get());
     1449                node = it->second;
    14881450                return true;
    14891451        }
     
    15241486        virtual void visit( const FunctionDecl * old ) override final {
    15251487                if ( inCache( old ) ) return;
    1526                 auto paramVars = GET_ACCEPT_V(type->parameters, DeclWithType);
    1527                 auto returnVars = GET_ACCEPT_V(type->returnVals, DeclWithType);
    1528                 auto forall = GET_ACCEPT_V(type->forall, TypeDecl);
    1529 
    1530                 // function type is now derived from parameter decls instead of storing them
    1531                 auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type));
    1532                 ftype->params.reserve(paramVars.size());
    1533                 ftype->returns.reserve(returnVars.size());
    1534 
    1535                 for (auto & v: paramVars) {
    1536                         ftype->params.emplace_back(v->get_type());
    1537                 }
    1538                 for (auto & v: returnVars) {
    1539                         ftype->returns.emplace_back(v->get_type());
    1540                 }
    1541                 ftype->forall = std::move(forall);
    1542                 visitType(old->type, ftype);
    1543 
    15441488                auto decl = new ast::FunctionDecl{
    15451489                        old->location,
    15461490                        old->name,
    1547                         // GET_ACCEPT_1(type, FunctionType),
    1548                         std::move(paramVars),
    1549                         std::move(returnVars),
     1491                        GET_ACCEPT_1(type, FunctionType),
    15501492                        {},
    15511493                        { old->storageClasses.val },
     
    15541496                        { old->get_funcSpec().val }
    15551497                };
    1556 
    1557                 decl->type = ftype;
    15581498                cache.emplace( old, decl );
    1559 
    15601499                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    15611500                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
     
    25762515                        cv( old )
    25772516                };
    2578                 auto returnVars = GET_ACCEPT_V(returnVals, DeclWithType);
    2579                 auto paramVars = GET_ACCEPT_V(parameters, DeclWithType);
    2580                 // ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
    2581                 // ty->params = GET_ACCEPT_V( parameters, DeclWithType );
    2582                 for (auto & v: returnVars) {
    2583                         ty->returns.emplace_back(v->get_type());
    2584                 }
    2585                 for (auto & v: paramVars) {
    2586                         ty->params.emplace_back(v->get_type());
    2587                 }
     2517                ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
     2518                ty->params = GET_ACCEPT_V( parameters, DeclWithType );
    25882519                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    25892520                visitType( old, ty );
    25902521        }
    25912522
    2592         void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
     2523        void postvisit( const ReferenceToType * old, ast::ReferenceToType * ty ) {
    25932524                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    25942525                ty->params = GET_ACCEPT_V( parameters, Expr );
Note: See TracChangeset for help on using the changeset viewer.