Ignore:
Timestamp:
Jun 12, 2023, 2:45:32 PM (13 months ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ast-experimental, master
Children:
62d62db
Parents:
34b4268 (diff), 251ce80 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ast-experimental

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r34b4268 r24d6572  
    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;
     
    322321void FuncGenerator::produceDecl( const ast::FunctionDecl * decl ) {
    323322        assert( nullptr != decl->stmts );
     323        const auto & oldParams = getGenericParams(type);
     324        assert( decl->type_params.size() == oldParams.size());
     325
     326        /*
     327        ast::DeclReplacer::TypeMap typeMap;
     328        for (auto it = oldParams.begin(), jt = decl->type_params.begin(); it != oldParams.end(); ++it, ++jt) {
     329                typeMap.emplace(*it, *jt);
     330        }
     331
     332        const ast::FunctionDecl * mut = strict_dynamic_cast<const ast::FunctionDecl *>(ast::DeclReplacer::replace(decl, typeMap));
     333        assert (mut == decl);
     334        */
    324335
    325336        definitions.push_back( decl );
     
    335346}
    336347
     348void replaceAll( std::vector<ast::ptr<ast::DeclWithType>> & dwts,
     349                const ast::DeclReplacer::TypeMap & map ) {
     350        for ( auto & dwt : dwts ) {
     351                dwt = strict_dynamic_cast<const ast::DeclWithType *>(
     352                                ast::DeclReplacer::replace( dwt, map ) );
     353        }
     354}
     355
    337356/// Generates a basic prototype function declaration.
    338 ast::FunctionDecl * FuncGenerator::genProto( const std::string& name,
     357ast::FunctionDecl * FuncGenerator::genProto( std::string&& name,
    339358                std::vector<ast::ptr<ast::DeclWithType>>&& params,
    340359                std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const {
     
    342361        // Handle generic prameters and assertions, if any.
    343362        auto const & old_type_params = getGenericParams( type );
     363        ast::DeclReplacer::TypeMap oldToNew;
    344364        std::vector<ast::ptr<ast::TypeDecl>> type_params;
    345365        std::vector<ast::ptr<ast::DeclWithType>> assertions;
     366
     367        ast::DeclReplacer::TypeMap typeMap;
    346368        for ( auto & old_param : old_type_params ) {
    347369                ast::TypeDecl * decl = ast::deepCopy( old_param );
    348                 for ( auto assertion : decl->assertions ) {
    349                         assertions.push_back( assertion );
    350                 }
    351                 decl->assertions.clear();
     370                decl->init = nullptr;
     371                splice( assertions, decl->assertions );
     372                oldToNew.emplace( std::make_pair( old_param, decl ) );
    352373                type_params.push_back( decl );
    353         }
    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.
     374                typeMap.emplace(old_param, decl);
     375        }
     376
     377        for (auto & param : params) {
     378                param = ast::DeclReplacer::replace(param, typeMap);
     379        }
     380        for (auto & param : returns) {
     381                param = ast::DeclReplacer::replace(param, typeMap);
     382        }
     383        replaceAll( params, oldToNew );
     384        replaceAll( returns, oldToNew );
     385        replaceAll( assertions, oldToNew );
    357386
    358387        ast::FunctionDecl * decl = new ast::FunctionDecl(
    359388                // Auto-generated routines use the type declaration's location.
    360389                getLocation(),
    361                 name,
     390                std::move( name ),
    362391                std::move( type_params ),
    363392                std::move( assertions ),
     
    423452        for ( unsigned int index = 0 ; index < fields ; ++index ) {
    424453                auto member = aggr->members[index].strict_as<ast::DeclWithType>();
    425                 if ( SymTab::isUnnamedBitfield(
     454                if ( ast::isUnnamedBitfield(
    426455                                dynamic_cast<const ast::ObjectDecl *>( member ) ) ) {
    427456                        if ( index == fields - 1 ) {
     
    515544        InitTweak::InitExpander_new srcParam( src );
    516545        // Assign to destination.
    517         ast::Expr * dstSelect = new ast::MemberExpr(
     546        ast::MemberExpr * dstSelect = new ast::MemberExpr(
    518547                location,
    519548                field,
     
    567596                }
    568597
    569                 ast::Expr * srcSelect = (srcParam) ? new ast::MemberExpr(
     598                ast::MemberExpr * srcSelect = (srcParam) ? new ast::MemberExpr(
    570599                        location, field, new ast::VariableExpr( location, srcParam )
    571600                ) : nullptr;
     
    599628                // Not sure why it could be null.
    600629                // Don't make a function for a parameter that is an unnamed bitfield.
    601                 if ( nullptr == field || SymTab::isUnnamedBitfield( field ) ) {
     630                if ( nullptr == field || ast::isUnnamedBitfield( field ) ) {
    602631                        continue;
    603632                // Matching Parameter: Initialize the field by copy.
Note: See TracChangeset for help on using the changeset viewer.