Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    r16ba4a6f r490fb92e  
    2626#include "AST/Node.hpp"
    2727#include "AST/Stmt.hpp"
    28 #include "CompilationState.h"
    2928#include "CodeGen/OperatorTable.h"
    3029#include "Common/PassVisitor.h"        // for PassVisitor, WithGuards, WithShort...
     
    123122
    124123        void genInit( std::list< Declaration * > & translationUnit ) {
     124                fixReturnStatements( translationUnit );
    125125                HoistArrayDimension::hoistArrayDimension( translationUnit );
    126                 fixReturnStatements( translationUnit );
    127 
    128                 if (!useNewAST) {
    129                         CtorDtor::generateCtorDtor( translationUnit );
    130                 }
     126                CtorDtor::generateCtorDtor( translationUnit );
    131127        }
    132128
     
    196192
    197193                        // need to resolve array dimensions in order to accurately determine if constexpr
    198                         if (!useNewAST) {
    199                                 ResolvExpr::findSingleExpression( arrayType->dimension, Validate::SizeType->clone(), indexer );
    200                                 // array is variable-length when the dimension is not constexpr
    201                                 arrayType->isVarLen = ! isConstExpr( arrayType->dimension );
    202                         }
     194                        ResolvExpr::findSingleExpression( arrayType->dimension, Validate::SizeType->clone(), indexer );
     195                        // array is variable-length when the dimension is not constexpr
     196                        arrayType->isVarLen = ! isConstExpr( arrayType->dimension );
    203197                        // don't need to hoist dimension if it's definitely pure - only need to if there's potential for side effects.
    204                         // xxx - hoisting has no side effects anyways, so don't skip since we delay resolve     
    205                         // only skip in the most trivial case, which does not require resolve
    206                         if (dynamic_cast<ConstantExpr *>(arrayType->dimension)) return;
    207                         // if ( ! Tuples::maybeImpure( arrayType->dimension ) ) return;
     198                        if ( ! Tuples::maybeImpure( arrayType->dimension ) ) return;
    208199
    209200                        ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, Validate::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
     
    254245        }
    255246
    256         // why is this not just on FunctionDecl?
    257247        void ManagedTypes::handleDWT( DeclarationWithType * dwt ) {
    258248                // if this function is a user-defined constructor or destructor, mark down the type as "managed"
     
    284274        void ManagedTypes::beginScope() { managedTypes.beginScope(); }
    285275        void ManagedTypes::endScope() { managedTypes.endScope(); }
    286 
    287         bool ManagedTypes_new::isManaged( const ast::Type * type ) const {
    288                 // references are never constructed
    289                 if ( dynamic_cast< const ast::ReferenceType * >( type ) ) return false;
    290                 if ( auto tupleType = dynamic_cast< const ast::TupleType * > ( type ) ) {
    291                         // tuple is also managed if any of its components are managed
    292                         for (auto & component : tupleType->types) {
    293                                 if (isManaged(component)) return true;
    294                         }
    295                 }
    296                 // need to clear and reset qualifiers when determining if a type is managed
    297                 // ValueGuard< Type::Qualifiers > qualifiers( type->get_qualifiers() );
    298                 auto tmp = shallowCopy(type);
    299                 tmp->qualifiers = {};
    300                 // delete tmp at return
    301                 ast::ptr<ast::Type> guard = tmp;
    302                 // a type is managed if it appears in the map of known managed types, or if it contains any polymorphism (is a type variable or generic type containing a type variable)
    303                 return managedTypes.find( Mangle::mangle( tmp, {Mangle::NoOverrideable | Mangle::NoGenericParams | Mangle::Type} ) ) != managedTypes.end() || GenPoly::isPolyType( tmp );
    304         }
    305 
    306         bool ManagedTypes_new::isManaged( const ast::ObjectDecl * objDecl ) const {
    307                 const ast::Type * type = objDecl->type;
    308                 while ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
    309                         // must always construct VLAs with an initializer, since this is an error in C
    310                         if ( at->isVarLen && objDecl->init ) return true;
    311                         type = at->base;
    312                 }
    313                 return isManaged( type );
    314         }
    315 
    316         void ManagedTypes_new::handleDWT( const ast::DeclWithType * dwt ) {
    317                 // if this function is a user-defined constructor or destructor, mark down the type as "managed"
    318                 if ( ! dwt->linkage.is_overrideable && CodeGen::isCtorDtor( dwt->name ) ) {
    319                         auto & params = GenPoly::getFunctionType( dwt->get_type())->params;
    320                         assert( ! params.empty() );
    321                         // Type * type = InitTweak::getPointerBase( params.front() );
    322                         // assert( type );
    323                         managedTypes.insert( Mangle::mangle( params.front(), {Mangle::NoOverrideable | Mangle::NoGenericParams | Mangle::Type} ) );
    324                 }
    325         }
    326 
    327         void ManagedTypes_new::handleStruct( const ast::StructDecl * aggregateDecl ) {
    328                 // don't construct members, but need to take note if there is a managed member,
    329                 // because that means that this type is also managed
    330                 for ( auto & member : aggregateDecl->members ) {
    331                         if ( auto field = member.as<ast::ObjectDecl>() ) {
    332                                 if ( isManaged( field ) ) {
    333                                         // generic parameters should not play a role in determining whether a generic type is constructed - construct all generic types, so that
    334                                         // polymorphic constructors make generic types managed types
    335                                         ast::StructInstType inst( aggregateDecl );
    336                                         managedTypes.insert( Mangle::mangle( &inst, {Mangle::NoOverrideable | Mangle::NoGenericParams | Mangle::Type} ) );
    337                                         break;
    338                                 }
    339                         }
    340                 }
    341         }
    342 
    343         void ManagedTypes_new::beginScope() { managedTypes.beginScope(); }
    344         void ManagedTypes_new::endScope() { managedTypes.endScope(); }
    345276
    346277        ImplicitCtorDtorStmt * genCtorDtor( const std::string & fname, ObjectDecl * objDecl, Expression * arg ) {
     
    439370        // constructable object
    440371        InitExpander_new srcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr };
    441         ast::ptr< ast::Expr > dstParam = new ast::VariableExpr(loc, objDecl);
    442372       
    443373        ast::ptr< ast::Stmt > ctor = SymTab::genImplicitCall(
    444                 srcParam, dstParam, loc, "?{}", objDecl );
     374                srcParam, new ast::VariableExpr{ loc, objDecl }, loc, "?{}", objDecl );
    445375        ast::ptr< ast::Stmt > dtor = SymTab::genImplicitCall(
    446                 nullParam, dstParam, loc, "^?{}", objDecl,
     376                nullParam, new ast::VariableExpr{ loc, objDecl }, loc, "^?{}", objDecl,
    447377                SymTab::LoopBackward );
    448378       
Note: See TracChangeset for help on using the changeset viewer.