Ignore:
Timestamp:
Aug 30, 2018, 1:00:41 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
bcc0946
Parents:
a715b5c
Message:

Refactor FindSpecialDeclarations? and associated special declarations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    ra715b5c r2bfc6b2  
    5656#include "SynTree/DeclReplacer.h"      // for DeclReplacer
    5757#include "SynTree/Visitor.h"           // for acceptAll, maybeAccept
     58#include "Validate/FindSpecialDecls.h" // for dtorStmt, dtorStructDestroy
    5859
    5960bool ctordtorp = false; // print all debug
     
    204205                        static void generate( std::list< Declaration * > & translationUnit );
    205206
    206                         void premutate( StructDecl * structDecl );
    207 
    208207                        void premutate( FunctionDecl * funcDecl );
    209208                        DeclarationWithType * postmutate( FunctionDecl * funcDecl );
     
    227226                        bool isCtor = false; // true if current function is a constructor
    228227                        StructDecl * structDecl = nullptr;
    229 
    230                         // special built-in functions necessary for this to work
    231                         StructDecl * dtorStruct = nullptr;
    232                         FunctionDecl * dtorStructDestroy = nullptr;
    233228                };
    234229
     
    10191014                }
    10201015
    1021                 void GenStructMemberCalls::premutate( StructDecl * structDecl ) {
    1022                         if ( ! dtorStruct && structDecl->name == "__Destructor" ) {
    1023                                 dtorStruct = structDecl;
    1024                         }
    1025                 }
    1026 
    10271016                void GenStructMemberCalls::premutate( FunctionDecl * funcDecl ) {
    10281017                        GuardValue( function );
     
    10371026                        unhandled.clear();
    10381027                        usedUninit.clear();
    1039 
    1040                         if ( ! dtorStructDestroy && funcDecl->name == "__destroy_Destructor" ) {
    1041                                 dtorStructDestroy = funcDecl;
    1042                                 return;
    1043                         }
    10441028
    10451029                        function = funcDecl;
     
    10531037                                if ( structType ) {
    10541038                                        structDecl = structType->get_baseStruct();
    1055                                         if ( structDecl == dtorStruct ) return;
    10561039                                        for ( Declaration * member : structDecl->get_members() ) {
    10571040                                                if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) {
     
    11271110                                                                // function->get_statements()->push_back( callStmt );
    11281111
     1112                                                                // Optimization: do not need to call intrinsic destructors on members
     1113                                                                if ( isIntrinsicSingleArgCallStmt( callStmt ) ) continue;;
     1114
    11291115                                                                // __Destructor _dtor0 = { (void *)&b.a1, (void (*)(void *)_destroy_A };
    11301116                                                                std::list< Statement * > stmtsToAdd;
    11311117
    11321118                                                                static UniqueName memberDtorNamer = { "__memberDtor" };
    1133                                                                 assertf( dtorStruct, "builtin __Destructor not found." );
    1134                                                                 assertf( dtorStructDestroy, "builtin __destroy_Destructor not found." );
     1119                                                                assertf( Validate::dtorStruct, "builtin __Destructor not found." );
     1120                                                                assertf( Validate::dtorStructDestroy, "builtin __destroy_Destructor not found." );
    11351121
    11361122                                                                Expression * thisExpr = new CastExpr( new AddressExpr( new VariableExpr( thisParam ) ), new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ) );
     
    11421128                                                                Type * dtorType = new PointerType( Type::Qualifiers(), dtorFtype );
    11431129
    1144                                                                 ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( new CastExpr( dtorExpr, dtorType ) ) } ) );
     1130                                                                ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), Validate::dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( new CastExpr( dtorExpr, dtorType ) ) } ) );
    11451131                                                                function->statements->push_front( new DeclStmt( destructor ) );
    1146                                                                 destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorStructDestroy ) } ) );
     1132                                                                destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( Validate::dtorStructDestroy ) } ) );
    11471133
    11481134                                                                function->statements->kids.splice( function->statements->kids.begin(), stmtsToAdd );
Note: See TracChangeset for help on using the changeset viewer.