Changeset 24d6572 for src/Validate


Ignore:
Timestamp:
Jun 12, 2023, 2:45:32 PM (2 years 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

Location:
src/Validate
Files:
8 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.
  • src/Validate/FixQualifiedTypes.cpp

    r34b4268 r24d6572  
    1616#include "Validate/FixQualifiedTypes.hpp"
    1717
     18#include "AST/Copy.hpp"
     19#include "AST/LinkageSpec.hpp"             // for Linkage
    1820#include "AST/Pass.hpp"
    1921#include "AST/TranslationUnit.hpp"
     22#include "Common/ToString.hpp"             // for toString
     23#include "SymTab/Mangler.h"                // for Mangler
    2024#include "Validate/NoIdSymbolTable.hpp"
    21 #include "SymTab/Mangler.h"            // for Mangler
    22 #include "AST/LinkageSpec.hpp"                     // for Linkage
    2325
    2426namespace Validate {
  • src/Validate/FixReturnTypes.cpp

    r34b4268 r24d6572  
    2020#include "AST/Type.hpp"
    2121#include "CodeGen/CodeGenerator.h"
    22 #include "ResolvExpr/typeops.h"
     22#include "ResolvExpr/Unify.h"
    2323
    2424namespace ast {
  • src/Validate/ForallPointerDecay.cpp

    r34b4268 r24d6572  
    2222#include "CodeGen/OperatorTable.h"
    2323#include "Common/CodeLocation.h"
     24#include "Common/ToString.hpp"
    2425#include "SymTab/FixFunction.h"
    2526
  • src/Validate/GenericParameter.cpp

    r34b4268 r24d6572  
    1616#include "GenericParameter.hpp"
    1717
     18#include "AST/Copy.hpp"
    1819#include "AST/Decl.hpp"
    1920#include "AST/Expr.hpp"
  • src/Validate/HandleAttributes.cc

    r34b4268 r24d6572  
    1717
    1818#include "CompilationState.h"
     19#include "Common/Eval.h"
    1920#include "Common/PassVisitor.h"
     21#include "Common/ToString.hpp"
    2022#include "Common/SemanticError.h"
    2123#include "ResolvExpr/Resolver.h"
  • src/Validate/HoistStruct.cpp

    r34b4268 r24d6572  
    1616#include "Validate/HoistStruct.hpp"
    1717
     18#include <sstream>
     19
    1820#include "AST/Pass.hpp"
    1921#include "AST/TranslationUnit.hpp"
    20 #include "Common/utility.h"
    2122
    2223namespace Validate {
  • src/Validate/ReplaceTypedef.cpp

    r34b4268 r24d6572  
    1616#include "ReplaceTypedef.hpp"
    1717
     18#include "AST/Copy.hpp"
    1819#include "AST/Pass.hpp"
    1920#include "Common/ScopedMap.h"
    2021#include "Common/UniqueName.h"
    2122#include "Common/utility.h"
    22 #include "ResolvExpr/typeops.h"
     23#include "ResolvExpr/Unify.h"
    2324
    2425namespace Validate {
     
    149150                // constant/enumerator. The effort required to fix this corner case
    150151                // likely outweighs the utility of allowing it.
    151                 if ( !ResolvExpr::typesCompatible( t0, t1, ast::SymbolTable() )
     152                if ( !ResolvExpr::typesCompatible( t0, t1 )
    152153                                || ast::Pass<VarLenChecker>::read( t0 )
    153154                                || ast::Pass<VarLenChecker>::read( t1 ) ) {
     
    186187
    187188void ReplaceTypedefCore::previsit( ast::TypeDecl const * decl ) {
    188         TypedefMap::iterator iter = typedefNames.find( decl->name );
    189         if ( iter != typedefNames.end() ) {
    190                 typedefNames.erase( iter );
    191         }
     189        typedefNames.erase( decl->name );
    192190        typedeclNames.insert( decl->name, decl );
    193191}
Note: See TracChangeset for help on using the changeset viewer.