source: src/Parser/InitializerNode.cc @ a43dd54

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since a43dd54 was d180746, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 2

  • Property mode set to 100644
File size: 3.5 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// InitializerNode.cc --
8//
9// Author           : Rodolfo G. Esteves
10// Created On       : Sat May 16 13:20:24 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Jul 28 23:27:20 2017
13// Update Count     : 26
14//
15
16#include <iostream>                // for operator<<, ostream, basic_ostream
17#include <list>                    // for list
18#include <string>                  // for operator<<, string
19
20using namespace std;
21
22#include "Common/SemanticError.h"  // for SemanticError
23#include "Common/utility.h"        // for maybeBuild
24#include "ParseNode.h"             // for InitializerNode, ExpressionNode
25#include "SynTree/Expression.h"    // for Expression
26#include "SynTree/Initializer.h"   // for Initializer, ListInit, SingleInit
27
28InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des )
29                : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
30        if ( aggrp )
31                kids = dynamic_cast< InitializerNode * >( get_next() );
32
33        if ( kids )
34                set_last( nullptr );
35} // InitializerNode::InitializerNode
36
37InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des )
38                : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
39        if ( init )
40                set_last( init );
41
42        if ( aggrp )
43                kids = dynamic_cast< InitializerNode * >( get_next() );
44
45        if ( kids )
46                set_next( nullptr );
47} // InitializerNode::InitializerNode
48
49InitializerNode::~InitializerNode() {
50        delete expr;
51        delete designator;
52        delete kids;
53} // InitializerNode::~InitializerNode
54
55void InitializerNode::print( std::ostream &os, int indent ) const {
56        os << std::string( indent, ' ' ) << "Initializer expression" << std::endl;
57} // InitializerNode::print
58
59void InitializerNode::printOneLine( std::ostream &os ) const {
60        if ( ! aggregate ) {
61                if ( designator ) {
62                        os << "designated by: (";
63                        ExpressionNode *curdes = designator;
64                        while ( curdes != nullptr) {
65                                curdes->printOneLine(os);
66                                curdes = (ExpressionNode *)(curdes->get_next());
67                                if ( curdes ) os << ", ";
68                        } // while
69                        os << ")";
70                } // if
71                if ( expr ) expr->printOneLine( os );
72        } else {  // It's an aggregate
73                os << "[--";
74                if ( next_init() != nullptr )
75                        next_init()->printOneLine( os );
76                if (aggregate) os << "--]";
77        } // if
78
79        InitializerNode *moreInit;
80        if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) {
81                moreInit->printOneLine( os );
82        } // if
83} // InitializerNode::printOneLine
84
85Initializer * InitializerNode::build() const {
86        if ( aggregate ) {
87                // steal designators from children
88                std::list< Designation * > designlist;
89                InitializerNode * child = next_init();
90                for ( ; child != nullptr; child = dynamic_cast< InitializerNode * >( child->get_next() ) ) {
91                        std::list< Expression * > desList;
92                        buildList< Expression, ExpressionNode >( child->designator, desList );
93                        designlist.push_back( new Designation( desList ) );
94                } // for
95                std::list< Initializer * > initlist;
96                buildList< Initializer, InitializerNode >( next_init(), initlist );
97                return new ListInit( initlist, designlist, maybeConstructed );
98        } else {
99                if ( get_expression() ) {
100                        return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed );
101                } // if
102        } // if
103        return nullptr;
104} // InitializerNode::build
105
106// Local Variables: //
107// tab-width: 4 //
108// mode: c++ //
109// compile-command: "make install" //
110// End: //
Note: See TracBrowser for help on using the repository browser.