Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInitNew.cpp

    rfb4dc28 r9feb34b  
    1414#include <utility>                     // for pair
    1515
    16 #include "AST/DeclReplacer.hpp"
    17 #include "AST/Expr.hpp"
    1816#include "AST/Inspect.hpp"             // for getFunction, getPointerBase, g...
    19 #include "AST/Node.hpp"
    20 #include "AST/Pass.hpp"
    21 #include "AST/Print.hpp"
    22 #include "AST/SymbolTable.hpp"
    23 #include "AST/Type.hpp"
    2417#include "CodeGen/GenType.h"           // for genPrettyType
    2518#include "CodeGen/OperatorTable.h"
     19#include "Common/CodeLocationTools.hpp"
    2620#include "Common/PassVisitor.h"        // for PassVisitor, WithStmtsToAdd
    2721#include "Common/SemanticError.h"      // for SemanticError
     
    3428#include "ResolvExpr/Unify.h"          // for typesCompatible
    3529#include "SymTab/Autogen.h"            // for genImplicitCall
    36 #include "SymTab/GenImplicitCall.hpp"  // for genImplicitCall
    3730#include "SymTab/Indexer.h"            // for Indexer
    3831#include "SymTab/Mangler.h"            // for Mangler
     
    5245#include "Validate/FindSpecialDecls.h" // for dtorStmt, dtorStructDestroy
    5346
     47#include "AST/Expr.hpp"
     48#include "AST/Node.hpp"
     49#include "AST/Pass.hpp"
     50#include "AST/Print.hpp"
     51#include "AST/SymbolTable.hpp"
     52#include "AST/Type.hpp"
     53#include "AST/DeclReplacer.hpp"
     54
    5455extern bool ctordtorp; // print all debug
    5556extern bool ctorp; // print ctor debug
     
    6263namespace InitTweak {
    6364namespace {
    64 
    65         // Shallow copy the pointer list for return.
    66         std::vector<ast::ptr<ast::TypeDecl>> getGenericParams( const ast::Type * t ) {
    67                 if ( auto inst = dynamic_cast<const ast::StructInstType *>( t ) ) {
    68                         return inst->base->params;
    69                 }
    70                 if ( auto inst = dynamic_cast<const ast::UnionInstType *>( t ) ) {
    71                         return inst->base->params;
    72                 }
    73                 return {};
    74         }
    75 
    76         /// Given type T, generate type of default ctor/dtor, i.e. function type void (*) (T &).
    77         ast::FunctionDecl * genDefaultFunc(
    78                         const CodeLocation loc,
    79                         const std::string fname,
    80                         const ast::Type * paramType,
    81                         bool maybePolymorphic = true) {
    82                 std::vector<ast::ptr<ast::TypeDecl>> typeParams;
    83                 if ( maybePolymorphic ) typeParams = getGenericParams( paramType );
    84                 auto dstParam = new ast::ObjectDecl( loc,
    85                         "_dst",
    86                         new ast::ReferenceType( paramType ),
    87                         nullptr,
    88                         {},
    89                         ast::Linkage::Cforall
    90                 );
    91                 return new ast::FunctionDecl( loc,
    92                         fname,
    93                         std::move(typeParams),
    94                         {dstParam},
    95                         {},
    96                         new ast::CompoundStmt(loc),
    97                         {},
    98                         ast::Linkage::Cforall
    99                 );
    100         }
    101 
    10265        struct SelfAssignChecker {
    10366                void previsit( const ast::ApplicationExpr * appExpr );
     
    158121                void previsit( const ast::FunctionDecl * ) { visit_children = false; }
    159122
    160         protected:
     123          protected:
    161124                ObjectSet curVars;
    162125        };
     
    239202
    240203                SemanticErrorException errors;
    241         private:
     204          private:
    242205                template< typename... Params >
    243206                void emit( CodeLocation, const Params &... params );
     
    325288                static UniqueName dtorNamer( "__cleanup_dtor" );
    326289                std::string name = dtorNamer.newName();
    327                 ast::FunctionDecl * dtorFunc = genDefaultFunc( loc, name, objDecl->type->stripReferences(), false );
     290                ast::FunctionDecl * dtorFunc = SymTab::genDefaultFunc( loc, name, objDecl->type->stripReferences(), false );
    328291                stmtsToAdd.push_back( new ast::DeclStmt(loc, dtorFunc ) );
    329292
     
    11171080        void InsertDtors::previsit( const ast::BranchStmt * stmt ) {
    11181081                switch( stmt->kind ) {
    1119                 case ast::BranchStmt::Continue:
    1120                 case ast::BranchStmt::Break:
     1082                  case ast::BranchStmt::Continue:
     1083                  case ast::BranchStmt::Break:
    11211084                        // could optimize the break/continue case, because the S_L-S_G check is unnecessary (this set should
    11221085                        // always be empty), but it serves as a small sanity check.
    1123                 case ast::BranchStmt::Goto:
     1086                  case ast::BranchStmt::Goto:
    11241087                        handleGoto( stmt );
    11251088                        break;
    1126                 default:
     1089                  default:
    11271090                        assert( false );
    11281091                } // switch
     
    13491312                // xxx - functions returning ast::ptr seems wrong...
    13501313                auto res = ResolvExpr::findVoidExpression( untypedExpr, { symtab, transUnit().global } );
    1351                 return res.release();
     1314                // Fix CodeLocation (at least until resolver is fixed).
     1315                auto fix = localFillCodeLocations( untypedExpr->location, res.release() );
     1316                return strict_dynamic_cast<const ast::Expr *>( fix );
    13521317        }
    13531318
Note: See TracChangeset for help on using the changeset viewer.