Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    rb8524ca ra16764a6  
    1515#include "GenInit.h"
    1616
    17 #include <stddef.h>                    // for NULL
    18 #include <algorithm>                   // for any_of
    19 #include <cassert>                     // for assert, strict_dynamic_cast, assertf
    20 #include <deque>
    21 #include <iterator>                    // for back_inserter, inserter, back_inse...
    22 #include <list>                        // for _List_iterator, list
    23 
    24 #include "AST/Decl.hpp"
    25 #include "AST/Init.hpp"
    26 #include "AST/Node.hpp"
    27 #include "AST/Stmt.hpp"
     17#include <stddef.h>                // for NULL
     18#include <algorithm>               // for any_of
     19#include <cassert>                 // for assert, strict_dynamic_cast, assertf
     20#include <iterator>                // for back_inserter, inserter, back_inse...
     21#include <list>                    // for _List_iterator, list
     22
    2823#include "CodeGen/OperatorTable.h"
    29 #include "Common/PassVisitor.h"        // for PassVisitor, WithGuards, WithShort...
    30 #include "Common/SemanticError.h"      // for SemanticError
    31 #include "Common/UniqueName.h"         // for UniqueName
    32 #include "Common/utility.h"            // for ValueGuard, maybeClone
    33 #include "GenPoly/GenPoly.h"           // for getFunctionType, isPolyType
    34 #include "GenPoly/ScopedSet.h"         // for ScopedSet, ScopedSet<>::const_iter...
    35 #include "InitTweak.h"                 // for isConstExpr, InitExpander, checkIn...
    36 #include "Parser/LinkageSpec.h"        // for isOverridable, C
     24#include "Common/PassVisitor.h"    // for PassVisitor, WithGuards, WithShort...
     25#include "Common/SemanticError.h"  // for SemanticError
     26#include "Common/UniqueName.h"     // for UniqueName
     27#include "Common/utility.h"        // for ValueGuard, maybeClone
     28#include "GenPoly/GenPoly.h"       // for getFunctionType, isPolyType
     29#include "GenPoly/ScopedSet.h"     // for ScopedSet, ScopedSet<>::const_iter...
     30#include "InitTweak.h"             // for isConstExpr, InitExpander, checkIn...
     31#include "Parser/LinkageSpec.h"    // for isOverridable, C
    3732#include "ResolvExpr/Resolver.h"
    38 #include "SymTab/Autogen.h"            // for genImplicitCall
    39 #include "SymTab/Mangler.h"            // for Mangler
    40 #include "SynTree/Declaration.h"       // for ObjectDecl, DeclarationWithType
    41 #include "SynTree/Expression.h"        // for VariableExpr, UntypedExpr, Address...
    42 #include "SynTree/Initializer.h"       // for ConstructorInit, SingleInit, Initi...
    43 #include "SynTree/Label.h"             // for Label
    44 #include "SynTree/Mutator.h"           // for mutateAll
    45 #include "SynTree/Statement.h"         // for CompoundStmt, ImplicitCtorDtorStmt
    46 #include "SynTree/Type.h"              // for Type, ArrayType, Type::Qualifiers
    47 #include "SynTree/Visitor.h"           // for acceptAll, maybeAccept
    48 #include "Tuples/Tuples.h"             // for maybeImpure
    49 #include "Validate/FindSpecialDecls.h" // for SizeType
     33#include "SymTab/Autogen.h"        // for genImplicitCall, SizeType
     34#include "SymTab/Mangler.h"        // for Mangler
     35#include "SynTree/Declaration.h"   // for ObjectDecl, DeclarationWithType
     36#include "SynTree/Expression.h"    // for VariableExpr, UntypedExpr, Address...
     37#include "SynTree/Initializer.h"   // for ConstructorInit, SingleInit, Initi...
     38#include "SynTree/Label.h"         // for Label
     39#include "SynTree/Mutator.h"       // for mutateAll
     40#include "SynTree/Statement.h"     // for CompoundStmt, ImplicitCtorDtorStmt
     41#include "SynTree/Type.h"          // for Type, ArrayType, Type::Qualifiers
     42#include "SynTree/Visitor.h"       // for acceptAll, maybeAccept
     43#include "Tuples/Tuples.h"         // for maybeImpure
    5044
    5145namespace InitTweak {
     
    192186
    193187                        // need to resolve array dimensions in order to accurately determine if constexpr
    194                         ResolvExpr::findSingleExpression( arrayType->dimension, Validate::SizeType->clone(), indexer );
     188                        ResolvExpr::findSingleExpression( arrayType->dimension, SymTab::SizeType->clone(), indexer );
    195189                        // array is variable-length when the dimension is not constexpr
    196190                        arrayType->isVarLen = ! isConstExpr( arrayType->dimension );
     
    198192                        if ( ! Tuples::maybeImpure( arrayType->dimension ) ) return;
    199193
    200                         ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, Validate::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
     194                        ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
    201195                        arrayDimension->get_type()->set_const( true );
    202196
     
    279273                assertf( objDecl, "genCtorDtor passed null objDecl" );
    280274                std::list< Statement * > stmts;
    281                 InitExpander_old srcParam( maybeClone( arg ) );
     275                InitExpander srcParam( maybeClone( arg ) );
    282276                SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), fname, back_inserter( stmts ), objDecl );
    283277                assert( stmts.size() <= 1 );
     
    291285                std::list< Statement * > dtor;
    292286
    293                 InitExpander_old srcParam( objDecl->get_init() );
    294                 InitExpander_old nullParam( (Initializer *)NULL );
     287                InitExpander srcParam( objDecl->get_init() );
     288                InitExpander nullParam( (Initializer *)NULL );
    295289                SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), "?{}", back_inserter( ctor ), objDecl );
    296290                SymTab::genImplicitCall( nullParam, new VariableExpr( objDecl ), "^?{}", front_inserter( dtor ), objDecl, false );
     
    358352                GuardScope( managedTypes );
    359353        }
    360 
    361 ast::ConstructorInit * genCtorInit( const CodeLocation & loc, const ast::ObjectDecl * objDecl ) {
    362         // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor for each
    363         // constructable object
    364         InitExpander_new srcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr };
    365        
    366         ast::ptr< ast::Stmt > ctor = SymTab::genImplicitCall(
    367                 srcParam, new ast::VariableExpr{ loc, objDecl }, loc, "?{}", objDecl );
    368         ast::ptr< ast::Stmt > dtor = SymTab::genImplicitCall(
    369                 nullParam, new ast::VariableExpr{ loc, objDecl }, loc, "^?{}", objDecl,
    370                 SymTab::LoopBackward );
    371        
    372         // check that either both ctor and dtor are present, or neither
    373         assert( (bool)ctor == (bool)dtor );
    374 
    375         if ( ctor ) {
    376                 // need to remember init expression, in case no ctors exist. If ctor does exist, want to
    377                 // use ctor expression instead of init.
    378                 ctor.strict_as< ast::ImplicitCtorDtorStmt >();
    379                 dtor.strict_as< ast::ImplicitCtorDtorStmt >();
    380 
    381                 return new ast::ConstructorInit{ loc, ctor, dtor, objDecl->init };
    382         }
    383 
    384         return nullptr;
    385 }
    386 
    387354} // namespace InitTweak
    388355
Note: See TracChangeset for help on using the changeset viewer.