source: src/Parser/InitializerNode.cc @ 1a5ad8c

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 1a5ad8c 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
RevLine 
[b87a5ed]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//
[974906e2]7// InitializerNode.cc --
8//
[b87a5ed]9// Author           : Rodolfo G. Esteves
10// Created On       : Sat May 16 13:20:24 2015
[8e9cbb2]11// Last Modified By : Peter A. Buhr
[1131392]12// Last Modified On : Fri Jul 28 23:27:20 2017
13// Update Count     : 26
[974906e2]14//
[b87a5ed]15
[d180746]16#include <iostream>                // for operator<<, ostream, basic_ostream
17#include <list>                    // for list
18#include <string>                  // for operator<<, string
19
[d9a0e76]20using namespace std;
[51b7345]21
[d180746]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
[bdd516a]27
[1131392]28InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des )
29                : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
[b87a5ed]30        if ( aggrp )
[7880579]31                kids = dynamic_cast< InitializerNode * >( get_next() );
[51b7345]32
[1131392]33        if ( kids )
34                set_last( nullptr );
35} // InitializerNode::InitializerNode
[51b7345]36
[1131392]37InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des )
38                : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
39        if ( init )
[1d4580a]40                set_last( init );
[51b7345]41
[b87a5ed]42        if ( aggrp )
[7880579]43                kids = dynamic_cast< InitializerNode * >( get_next() );
[51b7345]44
[1131392]45        if ( kids )
46                set_next( nullptr );
47} // InitializerNode::InitializerNode
[51b7345]48
49InitializerNode::~InitializerNode() {
[b87a5ed]50        delete expr;
[4f147cc]51        delete designator;
52        delete kids;
[1131392]53} // InitializerNode::~InitializerNode
[51b7345]54
55void InitializerNode::print( std::ostream &os, int indent ) const {
[59db689]56        os << std::string( indent, ' ' ) << "Initializer expression" << std::endl;
[1131392]57} // InitializerNode::print
[51b7345]58
59void InitializerNode::printOneLine( std::ostream &os ) const {
[b87a5ed]60        if ( ! aggregate ) {
[1131392]61                if ( designator ) {
[b87a5ed]62                        os << "designated by: (";
63                        ExpressionNode *curdes = designator;
[1131392]64                        while ( curdes != nullptr) {
[b87a5ed]65                                curdes->printOneLine(os);
[1d4580a]66                                curdes = (ExpressionNode *)(curdes->get_next());
[b87a5ed]67                                if ( curdes ) os << ", ";
68                        } // while
69                        os << ")";
70                } // if
[1131392]71                if ( expr ) expr->printOneLine( os );
[b87a5ed]72        } else {  // It's an aggregate
73                os << "[--";
[1131392]74                if ( next_init() != nullptr )
75                        next_init()->printOneLine( os );
[b87a5ed]76                if (aggregate) os << "--]";
[17cd4eb]77        } // if
[b87a5ed]78
79        InitializerNode *moreInit;
[e4d829b]80        if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) {
[b87a5ed]81                moreInit->printOneLine( os );
[1131392]82        } // if
83} // InitializerNode::printOneLine
[51b7345]84
[1131392]85Initializer * InitializerNode::build() const {
[b87a5ed]86        if ( aggregate ) {
[e4d829b]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
[7880579]95                std::list< Initializer * > initlist;
96                buildList< Initializer, InitializerNode >( next_init(), initlist );
[974906e2]97                return new ListInit( initlist, designlist, maybeConstructed );
[b87a5ed]98        } else {
[1131392]99                if ( get_expression() ) {
[e4d829b]100                        return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed );
[1131392]101                } // if
[b87a5ed]102        } // if
[1131392]103        return nullptr;
104} // InitializerNode::build
[b87a5ed]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.