Changeset 5b7a60c8 for src/Parser


Ignore:
Timestamp:
Aug 18, 2016, 5:00:32 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, 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:
12756de
Parents:
99cad3aa (diff), 7ecbb7e (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 plg2:software/cfa/cfa-cc

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r99cad3aa r5b7a60c8  
    167167
    168168NameExpr * build_varref( const string *name, bool labelp ) {
    169         return new NameExpr( *name, nullptr );
     169        NameExpr *expr = new NameExpr( *name, nullptr );
     170        delete name;
     171        return expr;
    170172}
    171173
     
    184186        if ( dynamic_cast< VoidType * >( targetType ) ) {
    185187                delete targetType;
    186                 return new CastExpr( maybeBuild< Expression >(expr_node) );
     188                return new CastExpr( maybeMoveBuild< Expression >(expr_node) );
    187189        } else {
    188                 return new CastExpr( maybeBuild< Expression >(expr_node), targetType );
     190                return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
    189191        } // if
    190192}
    191193
    192194Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) {
    193         UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild< Expression >(expr_node) );
     195        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeMoveBuild< Expression >(expr_node) );
    194196        delete member;
    195197        return ret;
     
    198200Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) {
    199201        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    200         deref->get_args().push_back( maybeBuild< Expression >(expr_node) );
     202        deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
    201203        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
    202204        delete member;
     
    205207
    206208Expression *build_addressOf( ExpressionNode *expr_node ) {
    207                 return new AddressExpr( maybeBuild< Expression >(expr_node) );
     209                return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
    208210}
    209211Expression *build_sizeOfexpr( ExpressionNode *expr_node ) {
    210         return new SizeofExpr( maybeBuild< Expression >(expr_node) );
     212        return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
    211213}
    212214Expression *build_sizeOftype( DeclarationNode *decl_node ) {
     
    214216}
    215217Expression *build_alignOfexpr( ExpressionNode *expr_node ) {
    216         return new AlignofExpr( maybeBuild< Expression >(expr_node) );
     218        return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
    217219}
    218220Expression *build_alignOftype( DeclarationNode *decl_node ) {
     
    224226
    225227Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) {
    226         return new LogicalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), notZeroExpr( maybeBuild< Expression >(expr_node2) ), kind );
     228        return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
    227229}
    228230
    229231Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) {
    230232        std::list< Expression * > args;
    231         args.push_back( maybeBuild< Expression >(expr_node) );
     233        args.push_back( maybeMoveBuild< Expression >(expr_node) );
    232234        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    233235}
    234236Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) {
    235237        std::list< Expression * > args;
    236         args.push_back( new AddressExpr( maybeBuild< Expression >(expr_node) ) );
     238        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) );
    237239        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    238240}
    239241Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    240242        std::list< Expression * > args;
    241         args.push_back( maybeBuild< Expression >(expr_node1) );
    242         args.push_back( maybeBuild< Expression >(expr_node2) );
     243        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
     244        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    243245        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    244246}
    245247Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    246248        std::list< Expression * > args;
    247         args.push_back( new AddressExpr( maybeBuild< Expression >(expr_node1) ) );
    248         args.push_back( maybeBuild< Expression >(expr_node2) );
     249        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node1) ) );
     250        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    249251        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    250252}
    251253
    252254Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) {
    253         return new ConditionalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), maybeBuild< Expression >(expr_node2), maybeBuild< Expression >(expr_node3) );
     255        return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
    254256}
    255257
    256258Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
    257         return new CommaExpr( maybeBuild< Expression >(expr_node1), maybeBuild< Expression >(expr_node2) );
     259        return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );
    258260}
    259261
    260262Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) {
    261         return new AttrExpr( var, maybeBuild< Expression >(expr_node) );
     263        return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
    262264}
    263265Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) {
     
    267269Expression *build_tuple( ExpressionNode * expr_node ) {
    268270        TupleExpr *ret = new TupleExpr();
    269         buildList( expr_node, ret->get_exprs() );
     271        buildMoveList( expr_node, ret->get_exprs() );
    270272        return ret;
    271273}
     
    273275Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
    274276        std::list< Expression * > args;
    275 
    276         buildList( expr_node, args );
    277         return new UntypedExpr( maybeBuild< Expression >(function), args, nullptr );
     277        buildMoveList( expr_node, args );
     278        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
    278279}
    279280
    280281Expression *build_range( ExpressionNode * low, ExpressionNode *high ) {
    281         Expression *low_cexpr = maybeBuild< Expression >( low );
    282         Expression *high_cexpr = maybeBuild< Expression >( high );
    283         return new RangeExpr( low_cexpr, high_cexpr );
     282        return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
    284283}
    285284
    286285Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {
    287         return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild< Expression >(operand) );
     286        return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
    288287}
    289288
    290289Expression *build_valexpr( StatementNode *s ) {
    291         return new UntypedValofExpr( maybeBuild< Statement >(s), nullptr );
     290        return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr );
    292291}
    293292Expression *build_typevalue( DeclarationNode *decl ) {
     
    298297        Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
    299298        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
    300                 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild< Initializer >(kids) );
     299                return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild< Initializer >(kids) );
    301300        // these types do not have associated type information
    302301        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
    303                 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild< Initializer >(kids) );
     302                return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
    304303        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
    305                 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild< Initializer >(kids) );
     304                return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
    306305        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
    307                 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild< Initializer >(kids) );
     306                return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
    308307        } else {
    309308                assert( false );
  • src/Parser/ParseNode.h

    r99cad3aa r5b7a60c8  
    387387void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
    388388
     389template< typename SynTreeType, typename NodeType >
     390void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {
     391        buildList(firstNode, outputList);
     392        delete firstNode;
     393}
     394
     395
    389396#endif // PARSENODE_H
    390397
  • src/Parser/StatementNode.cc

    r99cad3aa r5b7a60c8  
    6262        StatementNode *node = dynamic_cast< StatementNode * >(prev);
    6363        std::list< Statement * > stmts;
    64         buildList( stmt, stmts );
     64        buildMoveList( stmt, stmts );
    6565        // splice any new Statements to end of current Statements
    6666        CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt);
     
    7070
    7171Statement *build_expr( ExpressionNode *ctl ) {
    72         Expression *e = maybeBuild< Expression >( ctl );
     72        Expression *e = maybeMoveBuild< Expression >( ctl );
    7373
    7474        if ( e )
     
    8181        Statement *thenb, *elseb = 0;
    8282        std::list< Statement * > branches;
    83         buildList< Statement, StatementNode >( then_stmt, branches );
     83        buildMoveList< Statement, StatementNode >( then_stmt, branches );
    8484        assert( branches.size() == 1 );
    8585        thenb = branches.front();
     
    8787        if ( else_stmt ) {
    8888                std::list< Statement * > branches;
    89                 buildList< Statement, StatementNode >( else_stmt, branches );
     89                buildMoveList< Statement, StatementNode >( else_stmt, branches );
    9090                assert( branches.size() == 1 );
    9191                elseb = branches.front();
    9292        } // if
    93         return new IfStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), thenb, elseb );
     93        return new IfStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), thenb, elseb );
    9494}
    9595
    9696Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {
    9797        std::list< Statement * > branches;
    98         buildList< Statement, StatementNode >( stmt, branches );
     98        buildMoveList< Statement, StatementNode >( stmt, branches );
    9999        assert( branches.size() >= 0 );                                         // size == 0 for switch (...) {}, i.e., no declaration or statements
    100         return new SwitchStmt( noLabels, maybeBuild< Expression >(ctl), branches );
     100        return new SwitchStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches );
    101101}
    102102Statement *build_case( ExpressionNode *ctl ) {
    103103        std::list< Statement * > branches;
    104         return new CaseStmt( noLabels, maybeBuild< Expression >(ctl), branches );
     104        return new CaseStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches );
    105105}
    106106Statement *build_default() {
     
    111111Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {
    112112        std::list< Statement * > branches;
    113         buildList< Statement, StatementNode >( stmt, branches );
     113        buildMoveList< Statement, StatementNode >( stmt, branches );
    114114        assert( branches.size() == 1 );
    115         return new WhileStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), branches.front(), kind );
     115        return new WhileStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind );
    116116}
    117117
    118118Statement *build_for( ForCtl *forctl, StatementNode *stmt ) {
    119119        std::list< Statement * > branches;
    120         buildList< Statement, StatementNode >( stmt, branches );
     120        buildMoveList< Statement, StatementNode >( stmt, branches );
    121121        assert( branches.size() == 1 );
    122122
    123123        std::list< Statement * > init;
    124124        if ( forctl->init != 0 ) {
    125                 buildList( forctl->init, init );
     125                buildMoveList( forctl->init, init );
    126126        } // if
    127127
    128128        Expression *cond = 0;
    129129        if ( forctl->condition != 0 )
    130                 cond = notZeroExpr( maybeBuild< Expression >(forctl->condition) );
     130                cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) );
    131131
    132132        Expression *incr = 0;
    133133        if ( forctl->change != 0 )
    134                 incr = maybeBuild< Expression >(forctl->change);
     134                incr = maybeMoveBuild< Expression >(forctl->change);
    135135
    136136        delete forctl;
     
    142142}
    143143Statement *build_computedgoto( ExpressionNode *ctl ) {
    144         return new BranchStmt( noLabels, maybeBuild< Expression >(ctl), BranchStmt::Goto );
     144        return new BranchStmt( noLabels, maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    145145}
    146146
    147147Statement *build_return( ExpressionNode *ctl ) {
    148148        std::list< Expression * > exps;
    149         buildList( ctl, exps );
     149        buildMoveList( ctl, exps );
    150150        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr );
    151151}
    152152Statement *build_throw( ExpressionNode *ctl ) {
    153153        std::list< Expression * > exps;
    154         buildList( ctl, exps );
     154        buildMoveList( ctl, exps );
    155155        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr, true );
    156156}
     
    158158Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {
    159159        std::list< Statement * > branches;
    160         buildList< Statement, StatementNode >( catch_stmt, branches );
    161         CompoundStmt *tryBlock = dynamic_cast< CompoundStmt * >(maybeBuild< Statement >(try_stmt));
     160        buildMoveList< Statement, StatementNode >( catch_stmt, branches );
     161        CompoundStmt *tryBlock = dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
    162162        assert( tryBlock );
    163         FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeBuild< Statement >(finally_stmt) );
     163        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    164164        return new TryStmt( noLabels, tryBlock, branches, finallyBlock );
    165165}
    166166Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) {
    167167        std::list< Statement * > branches;
    168         buildList< Statement, StatementNode >( stmt, branches );
     168        buildMoveList< Statement, StatementNode >( stmt, branches );
    169169        assert( branches.size() == 1 );
    170         return new CatchStmt( noLabels, maybeBuild< Declaration >(decl), branches.front(), catchAny );
     170        return new CatchStmt( noLabels, maybeMoveBuild< Declaration >(decl), branches.front(), catchAny );
    171171}
    172172Statement *build_finally( StatementNode *stmt ) {
    173173        std::list< Statement * > branches;
    174         buildList< Statement, StatementNode >( stmt, branches );
     174        buildMoveList< Statement, StatementNode >( stmt, branches );
    175175        assert( branches.size() == 1 );
    176176        return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt * >( branches.front() ) );
     
    179179Statement *build_compound( StatementNode *first ) {
    180180        CompoundStmt *cs = new CompoundStmt( noLabels );
    181         buildList( first, cs->get_kids() );
     181        buildMoveList( first, cs->get_kids() );
    182182        return cs;
    183183}
     
    187187        std::list< ConstantExpr * > clob;
    188188
    189         buildList( output, out );
    190         buildList( input, in );
    191         buildList( clobber, clob );
     189        buildMoveList( output, out );
     190        buildMoveList( input, in );
     191        buildMoveList( clobber, clob );
    192192        return new AsmStmt( noLabels, voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    193193}
Note: See TracChangeset for help on using the changeset viewer.