Ignore:
Timestamp:
Jun 7, 2016, 4:51:26 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8abfdb4
Parents:
a436947
Message:

generate ctor/dtors for enum types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    ra436947 rd0f8b19  
    102102                FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    103103
     104                ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType ), 0 );
     105                assignType->get_parameters().push_back( dstParam );
     106
     107                // void ?{}(E *); void ^?{}(E *);
     108                FunctionType * ctorType = assignType->clone();
     109                FunctionType * dtorType = assignType->clone();
     110
     111                ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
     112                assignType->get_parameters().push_back( srcParam );
     113                // void ?{}(E *, E);
     114                FunctionType *copyCtorType = assignType->clone();
     115
     116                // T ?=?(E *, E);
    104117                ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
    105118                assignType->get_returnVals().push_back( returnVal );
    106119
    107                 // need two assignment operators with different types
    108                 FunctionType * assignType2 = assignType->clone();
    109 
    110                 // E ?=?(E volatile *, E)
    111                 Type *etype = refType->clone();
    112                 // etype->get_qualifiers() += Type::Qualifiers(false, true, false, false, false, false);
    113 
    114                 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), etype ), 0 );
    115                 assignType->get_parameters().push_back( dstParam );
    116 
    117                 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, etype->clone(), 0 );
    118                 assignType->get_parameters().push_back( srcParam );
    119 
    120                 // E ?=?(E volatile *, int)
    121                 assignType2->get_parameters().push_back( dstParam->clone() );
    122                 BasicType * paramType = new BasicType(Type::Qualifiers(), BasicType::SignedInt);
    123                 ObjectDecl *srcParam2 = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, paramType, 0 );
    124                 assignType2->get_parameters().push_back( srcParam2 );
     120                // xxx - should we also generate void ?{}(E *, int) and E ?{}(E *, E)?
     121                // right now these cases work, but that might change.
    125122
    126123                // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
    127124                // because each unit generates copies of the default routines for each aggregate.
    128 
    129                 // since there is no definition, these should not be inline
    130                 // make these intrinsic so that the code generator does not make use of them
    131                 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType, 0, true, false );
     125                // xxx - Temporary: make these functions intrinsic so they codegen as C assignment.
     126                // Really they're something of a cross between instrinsic and autogen, so should
     127                // probably make a new linkage type
     128                FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType, new CompoundStmt( noLabels ), true, false );
     129                FunctionDecl *ctorDecl = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, ctorType, new CompoundStmt( noLabels ), true, false );
     130                FunctionDecl *copyCtorDecl = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, copyCtorType, new CompoundStmt( noLabels ), true, false );
     131                FunctionDecl *dtorDecl = new FunctionDecl( "^?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, dtorType, new CompoundStmt( noLabels ), true, false );
    132132                assignDecl->fixUniqueId();
    133                 FunctionDecl *assignDecl2 = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType2, 0, true, false );
    134                 assignDecl2->fixUniqueId();
    135 
    136                 // these should be built in the same way that the prelude
    137                 // functions are, so build a list containing the prototypes
    138                 // and allow MakeLibCfa to autogenerate the bodies.
    139                 std::list< Declaration * > assigns;
    140                 assigns.push_back( assignDecl );
    141                 assigns.push_back( assignDecl2 );
    142 
    143                 LibCfa::makeLibCfa( assigns );
    144 
    145                 // need to remove the prototypes, since this may be nested in a routine
    146                 for (int start = 0, end = assigns.size()/2; start < end; start++) {
    147                         delete assigns.front();
    148                         assigns.pop_front();
    149                 } // for
    150 
    151                 declsToAdd.insert( declsToAdd.begin(), assigns.begin(), assigns.end() );
     133                ctorDecl->fixUniqueId();
     134                copyCtorDecl->fixUniqueId();
     135                dtorDecl->fixUniqueId();
     136
     137                // enum copy construct and assignment is just C-style assignment.
     138                // this looks like a bad recursive call, but code gen will turn it into
     139                // a C-style assignment.
     140                // This happens before function pointer type conversion, so need to do it manually here
     141                VariableExpr * assignVarExpr = new VariableExpr( assignDecl );
     142                Type *& assignVarExprType = assignVarExpr->get_results().front();
     143                assignVarExprType = new PointerType( Type::Qualifiers(), assignVarExprType );
     144                ApplicationExpr * assignExpr = new ApplicationExpr( assignVarExpr );
     145                assignExpr->get_args().push_back( new VariableExpr( dstParam ) );
     146                assignExpr->get_args().push_back( new VariableExpr( srcParam ) );
     147
     148                // body is either return stmt or expr stmt
     149                assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, assignExpr ) );
     150                copyCtorDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, assignExpr->clone() ) );
     151
     152                declsToAdd.push_back( assignDecl );
     153                declsToAdd.push_back( ctorDecl );
     154                declsToAdd.push_back( copyCtorDecl );
     155                declsToAdd.push_back( dtorDecl );
    152156        }
    153157
Note: See TracChangeset for help on using the changeset viewer.