Changeset 8913de4


Ignore:
Timestamp:
May 30, 2023, 11:13:58 AM (18 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ast-experimental, master
Children:
2cb8bf71, 6f774be, 70a4ed5
Parents:
efe89894
Message:

Update in autogen that should help with some resolver issues and invariant checks. Some related headers were cleaned up to reduce new code files including old ones.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    refe89894 r8913de4  
    2020#include <string>                 // for string
    2121
    22 #include "AST/Decl.hpp"
    23 #include "AST/Expr.hpp"
    24 #include "AST/Init.hpp"
    25 #include "AST/Node.hpp"
    26 #include "AST/Stmt.hpp"
    27 #include "AST/Type.hpp"
    2822#include "CodeGen/OperatorTable.h"
    2923#include "Common/UniqueName.h"    // for UniqueName
     
    5751        /// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
    5852        FunctionType * genCopyType( Type * paramType, bool maybePolymorphic = true );
    59 
    60         /// Enum for loop direction
    61         enum LoopDirection { LoopBackward, LoopForward };
    6253
    6354        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
  • src/SymTab/GenImplicitCall.cpp

    refe89894 r8913de4  
    1616#include "GenImplicitCall.hpp"
    1717
     18#include "AST/Decl.hpp"                  // for ObjectDecl
     19#include "AST/Expr.hpp"                  // for ConstantExpr, UntypedExpr,...
     20#include "AST/Init.hpp"                  // for SingleInit
    1821#include "AST/Inspect.hpp"               // for isUnnamedBitfield
     22#include "AST/Stmt.hpp"                  // for ExprStmt
     23#include "AST/Type.hpp"                  // for ArrayType, BasicType, ...
    1924#include "CodeGen/OperatorTable.h"       // for isCtorDtor
    2025#include "Common/UniqueName.h"           // for UniqueName
    2126
    2227namespace SymTab {
     28
     29namespace {
    2330
    2431template< typename OutIter >
     
    173180}
    174181
     182} // namespace
     183
    175184ast::ptr< ast::Stmt > genImplicitCall(
    176185        InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
  • src/SymTab/GenImplicitCall.hpp

    refe89894 r8913de4  
    1717
    1818#include "InitTweak/InitTweak.h"  // for InitExpander
    19 #include "SymTab/Autogen.h"       // for LoopDirection
    2019
    2120namespace SymTab {
    2221
     22/// Enum for loop direction
     23enum LoopDirection { LoopBackward, LoopForward };
     24
     25/// Returns a generated call expression to function fname with srcParam and
     26/// dstParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
    2327ast::ptr<ast::Stmt> genImplicitCall(
    2428        InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     
    3438// compile-command: "make install" //
    3539// End: //
    36 
  • src/Validate/Autogen.cpp

    refe89894 r8913de4  
    4444#include "CompilationState.h"
    4545
    46 // TODO: The other new ast function should be moved over to this file.
    47 #include "SymTab/Autogen.h"
    48 
    4946namespace Validate {
    5047
     
    9693
    9794        const CodeLocation& getLocation() const { return getDecl()->location; }
    98         ast::FunctionDecl * genProto( const std::string& name,
     95        ast::FunctionDecl * genProto( std::string&& name,
    9996                std::vector<ast::ptr<ast::DeclWithType>>&& params,
    10097                std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const;
     
    337334}
    338335
     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
    339344/// Generates a basic prototype function declaration.
    340 ast::FunctionDecl * FuncGenerator::genProto( const std::string& name,
     345ast::FunctionDecl * FuncGenerator::genProto( std::string&& name,
    341346                std::vector<ast::ptr<ast::DeclWithType>>&& params,
    342347                std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const {
     
    344349        // Handle generic prameters and assertions, if any.
    345350        auto const & old_type_params = getGenericParams( type );
     351        ast::DeclReplacer::TypeMap oldToNew;
    346352        std::vector<ast::ptr<ast::TypeDecl>> type_params;
    347353        std::vector<ast::ptr<ast::DeclWithType>> assertions;
    348354        for ( auto & old_param : old_type_params ) {
    349355                ast::TypeDecl * decl = ast::deepCopy( old_param );
    350                 for ( auto assertion : decl->assertions ) {
    351                         assertions.push_back( assertion );
    352                 }
    353                 decl->assertions.clear();
     356                decl->init = nullptr;
     357                splice( assertions, decl->assertions );
     358                oldToNew.emplace( std::make_pair( old_param, decl ) );
    354359                type_params.push_back( decl );
    355360        }
    356         // TODO: The values in params and returns still may point at the old
    357         // generic params, that does not appear to be an issue but perhaps it
    358         // should be addressed.
     361        replaceAll( params, oldToNew );
     362        replaceAll( returns, oldToNew );
     363        replaceAll( assertions, oldToNew );
    359364
    360365        ast::FunctionDecl * decl = new ast::FunctionDecl(
    361366                // Auto-generated routines use the type declaration's location.
    362367                getLocation(),
    363                 name,
     368                std::move( name ),
    364369                std::move( type_params ),
    365370                std::move( assertions ),
Note: See TracChangeset for help on using the changeset viewer.