Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r8913de4 r20737104  
    2525
    2626#include "AST/Attribute.hpp"
    27 #include "AST/Copy.hpp"
    2827#include "AST/Create.hpp"
    2928#include "AST/Decl.hpp"
     
    4039#include "InitTweak/GenInit.h"     // for fixReturnStatements
    4140#include "InitTweak/InitTweak.h"   // for isAssignment, isCopyConstructor
    42 #include "SymTab/GenImplicitCall.hpp"  // for genImplicitCall
    4341#include "SymTab/Mangler.h"        // for Mangler
    4442#include "CompilationState.h"
     43
     44// TODO: The other new ast function should be moved over to this file.
     45#include "SymTab/Autogen.h"
    4546
    4647namespace Validate {
     
    9394
    9495        const CodeLocation& getLocation() const { return getDecl()->location; }
    95         ast::FunctionDecl * genProto( std::string&& name,
     96        ast::FunctionDecl * genProto( const std::string& name,
    9697                std::vector<ast::ptr<ast::DeclWithType>>&& params,
    9798                std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const;
     
    334335}
    335336
    336 void 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 
    344337/// Generates a basic prototype function declaration.
    345 ast::FunctionDecl * FuncGenerator::genProto( std::string&& name,
     338ast::FunctionDecl * FuncGenerator::genProto( const std::string& name,
    346339                std::vector<ast::ptr<ast::DeclWithType>>&& params,
    347340                std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const {
     
    349342        // Handle generic prameters and assertions, if any.
    350343        auto const & old_type_params = getGenericParams( type );
    351         ast::DeclReplacer::TypeMap oldToNew;
    352344        std::vector<ast::ptr<ast::TypeDecl>> type_params;
    353345        std::vector<ast::ptr<ast::DeclWithType>> assertions;
    354346        for ( auto & old_param : old_type_params ) {
    355347                ast::TypeDecl * decl = ast::deepCopy( old_param );
    356                 decl->init = nullptr;
    357                 splice( assertions, decl->assertions );
    358                 oldToNew.emplace( std::make_pair( old_param, decl ) );
     348                for ( auto assertion : decl->assertions ) {
     349                        assertions.push_back( assertion );
     350                }
     351                decl->assertions.clear();
    359352                type_params.push_back( decl );
    360353        }
    361         replaceAll( params, oldToNew );
    362         replaceAll( returns, oldToNew );
    363         replaceAll( assertions, oldToNew );
     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.
    364357
    365358        ast::FunctionDecl * decl = new ast::FunctionDecl(
    366359                // Auto-generated routines use the type declaration's location.
    367360                getLocation(),
    368                 std::move( name ),
     361                name,
    369362                std::move( type_params ),
    370363                std::move( assertions ),
     
    430423        for ( unsigned int index = 0 ; index < fields ; ++index ) {
    431424                auto member = aggr->members[index].strict_as<ast::DeclWithType>();
    432                 if ( ast::isUnnamedBitfield(
     425                if ( SymTab::isUnnamedBitfield(
    433426                                dynamic_cast<const ast::ObjectDecl *>( member ) ) ) {
    434427                        if ( index == fields - 1 ) {
     
    606599                // Not sure why it could be null.
    607600                // Don't make a function for a parameter that is an unnamed bitfield.
    608                 if ( nullptr == field || ast::isUnnamedBitfield( field ) ) {
     601                if ( nullptr == field || SymTab::isUnnamedBitfield( field ) ) {
    609602                        continue;
    610603                // Matching Parameter: Initialize the field by copy.
Note: See TracChangeset for help on using the changeset viewer.