Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    r7951100 rb067d9b  
    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 <iterator>                // for back_inserter, inserter, back_inse...
    21 #include <list>                    // for _List_iterator, list
    22 
     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"
    2328#include "CodeGen/OperatorTable.h"
    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
     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
    3237#include "ResolvExpr/Resolver.h"
    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
     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
    4450
    4551namespace InitTweak {
     
    186192
    187193                        // need to resolve array dimensions in order to accurately determine if constexpr
    188                         ResolvExpr::findSingleExpression( arrayType->dimension, SymTab::SizeType->clone(), indexer );
     194                        ResolvExpr::findSingleExpression( arrayType->dimension, Validate::SizeType->clone(), indexer );
    189195                        // array is variable-length when the dimension is not constexpr
    190196                        arrayType->isVarLen = ! isConstExpr( arrayType->dimension );
     
    192198                        if ( ! Tuples::maybeImpure( arrayType->dimension ) ) return;
    193199
    194                         ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
     200                        ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, Validate::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
    195201                        arrayDimension->get_type()->set_const( true );
    196202
     
    273279                assertf( objDecl, "genCtorDtor passed null objDecl" );
    274280                std::list< Statement * > stmts;
    275                 InitExpander srcParam( maybeClone( arg ) );
     281                InitExpander_old srcParam( maybeClone( arg ) );
    276282                SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), fname, back_inserter( stmts ), objDecl );
    277283                assert( stmts.size() <= 1 );
     
    285291                std::list< Statement * > dtor;
    286292
    287                 InitExpander srcParam( objDecl->get_init() );
    288                 InitExpander nullParam( (Initializer *)NULL );
     293                InitExpander_old srcParam( objDecl->get_init() );
     294                InitExpander_old nullParam( (Initializer *)NULL );
    289295                SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), "?{}", back_inserter( ctor ), objDecl );
    290296                SymTab::genImplicitCall( nullParam, new VariableExpr( objDecl ), "^?{}", front_inserter( dtor ), objDecl, false );
     
    352358                GuardScope( managedTypes );
    353359        }
     360
     361ast::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
    354387} // namespace InitTweak
    355388
Note: See TracChangeset for help on using the changeset viewer.