Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r20737104 r8913de4  
    2525
    2626#include "AST/Attribute.hpp"
     27#include "AST/Copy.hpp"
    2728#include "AST/Create.hpp"
    2829#include "AST/Decl.hpp"
     
    3940#include "InitTweak/GenInit.h"     // for fixReturnStatements
    4041#include "InitTweak/InitTweak.h"   // for isAssignment, isCopyConstructor
     42#include "SymTab/GenImplicitCall.hpp"  // for genImplicitCall
    4143#include "SymTab/Mangler.h"        // for Mangler
    4244#include "CompilationState.h"
    43 
    44 // TODO: The other new ast function should be moved over to this file.
    45 #include "SymTab/Autogen.h"
    4645
    4746namespace Validate {
     
    9493
    9594        const CodeLocation& getLocation() const { return getDecl()->location; }
    96         ast::FunctionDecl * genProto( const std::string& name,
     95        ast::FunctionDecl * genProto( std::string&& name,
    9796                std::vector<ast::ptr<ast::DeclWithType>>&& params,
    9897                std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const;
     
    335334}
    336335
     336void replaceAll( std::vector<ast::ptr<ast::DeclWithType>> & dwts,
     337                const ast::DeclReplacer::TypeMap & map ) {
     338        for ( auto & dwt : dwts ) {
     339                dwt = strict_dynamic_cast<const ast::DeclWithType *>(
     340                                ast::DeclReplacer::replace( dwt, map ) );
     341        }
     342}
     343
    337344/// Generates a basic prototype function declaration.
    338 ast::FunctionDecl * FuncGenerator::genProto( const std::string& name,
     345ast::FunctionDecl * FuncGenerator::genProto( std::string&& name,
    339346                std::vector<ast::ptr<ast::DeclWithType>>&& params,
    340347                std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const {
     
    342349        // Handle generic prameters and assertions, if any.
    343350        auto const & old_type_params = getGenericParams( type );
     351        ast::DeclReplacer::TypeMap oldToNew;
    344352        std::vector<ast::ptr<ast::TypeDecl>> type_params;
    345353        std::vector<ast::ptr<ast::DeclWithType>> assertions;
    346354        for ( auto & old_param : old_type_params ) {
    347355                ast::TypeDecl * decl = ast::deepCopy( old_param );
    348                 for ( auto assertion : decl->assertions ) {
    349                         assertions.push_back( assertion );
    350                 }
    351                 decl->assertions.clear();
     356                decl->init = nullptr;
     357                splice( assertions, decl->assertions );
     358                oldToNew.emplace( std::make_pair( old_param, decl ) );
    352359                type_params.push_back( decl );
    353360        }
    354         // TODO: The values in params and returns still may point at the old
    355         // generic params, that does not appear to be an issue but perhaps it
    356         // should be addressed.
     361        replaceAll( params, oldToNew );
     362        replaceAll( returns, oldToNew );
     363        replaceAll( assertions, oldToNew );
    357364
    358365        ast::FunctionDecl * decl = new ast::FunctionDecl(
    359366                // Auto-generated routines use the type declaration's location.
    360367                getLocation(),
    361                 name,
     368                std::move( name ),
    362369                std::move( type_params ),
    363370                std::move( assertions ),
     
    423430        for ( unsigned int index = 0 ; index < fields ; ++index ) {
    424431                auto member = aggr->members[index].strict_as<ast::DeclWithType>();
    425                 if ( SymTab::isUnnamedBitfield(
     432                if ( ast::isUnnamedBitfield(
    426433                                dynamic_cast<const ast::ObjectDecl *>( member ) ) ) {
    427434                        if ( index == fields - 1 ) {
     
    599606                // Not sure why it could be null.
    600607                // Don't make a function for a parameter that is an unnamed bitfield.
    601                 if ( nullptr == field || SymTab::isUnnamedBitfield( field ) ) {
     608                if ( nullptr == field || ast::isUnnamedBitfield( field ) ) {
    602609                        continue;
    603610                // Matching Parameter: Initialize the field by copy.
Note: See TracChangeset for help on using the changeset viewer.