Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/InitializerNode.cc

    rc468150 r374cb117  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:20:24 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr  4 11:18:00 2023
    13 // Update Count     : 27
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jul 28 23:27:20 2017
     13// Update Count     : 26
    1414//
    15 
    16 #include "InitializerNode.h"
    1715
    1816#include <iostream>                // for operator<<, ostream, basic_ostream
     
    2018#include <string>                  // for operator<<, string
    2119
    22 #include "AST/Expr.hpp"            // for Expr
    23 #include "AST/Init.hpp"            // for Designator, Init, ListInit, Sing...
     20using namespace std;
     21
    2422#include "Common/SemanticError.h"  // for SemanticError
    2523#include "Common/utility.h"        // for maybeBuild
    26 #include "ExpressionNode.h"        // for ExpressionNode
    27 #include "DeclarationNode.h"       // for buildList
    28 
    29 using namespace std;
    30 
    31 static ast::ConstructFlag toConstructFlag( bool maybeConstructed ) {
    32         return maybeConstructed ? ast::MaybeConstruct : ast::NoConstruct;
    33 }
     24#include "ParseNode.h"             // for InitializerNode, ExpressionNode
     25#include "SynTree/Expression.h"    // for Expression
     26#include "SynTree/Initializer.h"   // for Initializer, ListInit, SingleInit
    3427
    3528InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des )
     
    4033        if ( kids )
    4134                set_last( nullptr );
    42 } // InitializerNode::InitializerNode
     35} // InitializerNode::InitializerNode
    4336
    4437InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des )
     
    9285} // InitializerNode::printOneLine
    9386
    94 ast::Init * InitializerNode::build() const {
     87Initializer * InitializerNode::build() const {
    9588        assertf( ! isDelete, "Should not build delete stmt InitializerNode" );
    9689        if ( aggregate ) {
    9790                // steal designators from children
    98                 std::vector<ast::ptr<ast::Designation>> designlist;
     91                std::list< Designation * > designlist;
    9992                InitializerNode * child = next_init();
    100                 for ( ; child != nullptr ; child = dynamic_cast< InitializerNode * >( child->get_next() ) ) {
    101                         std::deque<ast::ptr<ast::Expr>> desList;
    102                         buildList( child->designator, desList );
    103                         designlist.push_back(
    104                                 new ast::Designation( location, std::move( desList ) ) );
     93                for ( ; child != nullptr; child = dynamic_cast< InitializerNode * >( child->get_next() ) ) {
     94                        std::list< Expression * > desList;
     95                        buildList< Expression, ExpressionNode >( child->designator, desList );
     96                        designlist.push_back( new Designation( desList ) );
    10597                } // for
    106                 std::vector<ast::ptr<ast::Init>> initlist;
    107                 buildList( next_init(), initlist );
    108                 return new ast::ListInit( location,
    109                         std::move( initlist ),
    110                         std::move( designlist ),
    111                         toConstructFlag( maybeConstructed )
    112                 );
    113         } else if ( get_expression() ) {
    114                 assertf( get_expression()->expr, "The expression of initializer must have value" );
    115                 return new ast::SingleInit( location,
    116                         maybeBuild( get_expression() ),
    117                         toConstructFlag( maybeConstructed )
    118                 );
     98                std::list< Initializer * > initlist;
     99                buildList< Initializer, InitializerNode >( next_init(), initlist );
     100                return new ListInit( initlist, designlist, maybeConstructed );
     101        } else {
     102                if ( get_expression() ) {
     103                        assertf( get_expression()->expr, "The expression of initializer must have value" );
     104                        return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed );
     105                } // if
    119106        } // if
    120107        return nullptr;
Note: See TracChangeset for help on using the changeset viewer.