source: src/Parser/InitializerNode.cc @ 3f3b731d

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 3f3b731d was 974906e2, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

propagate maybeConstructed flag through system, begin create constructor/destructor statements for further processing by Resolver

  • Property mode set to 100644
File size: 2.9 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
[974906e2]11// Last Modified By : Rob Schluntz
12// Last Modified On : Thu Jan 07 13:32:57 2016
13// Update Count     : 13
14//
[b87a5ed]15
[51b7345]16#include <cassert>
[d9a0e76]17#include <iostream>
18using namespace std;
[51b7345]19
[bdd516a]20#include "ParseNode.h"
21#include "SynTree/Expression.h"
22#include "SynTree/Initializer.h"
23
[51b7345]24InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des )
[974906e2]25        : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
[b87a5ed]26        if ( aggrp )
27                kids = dynamic_cast< InitializerNode *>( get_link() );
[51b7345]28
[b87a5ed]29        if ( kids != 0 )
30                set_link( 0 );
[51b7345]31}
32
33InitializerNode::InitializerNode( InitializerNode *init, bool aggrp, ExpressionNode *des )
[974906e2]34        : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
[b87a5ed]35        if ( init != 0 )
36                set_link(init);
[51b7345]37
[b87a5ed]38        if ( aggrp )
39                kids = dynamic_cast< InitializerNode *>( get_link() );
[51b7345]40
[b87a5ed]41        if ( kids != 0 )
42                set_next( 0 );
[51b7345]43}
44
45InitializerNode::~InitializerNode() {
[b87a5ed]46        delete expr;
[51b7345]47}
48
49void InitializerNode::print( std::ostream &os, int indent ) const {
[59db689]50        os << std::string( indent, ' ' ) << "Initializer expression" << std::endl;
[51b7345]51}
52
53void InitializerNode::printOneLine( std::ostream &os ) const {
[b87a5ed]54        if ( ! aggregate ) {
55                if ( designator != 0 ) {
56                        os << "designated by: (";
57                        ExpressionNode *curdes = designator;
[a32b204]58                        while ( curdes != 0) {
[b87a5ed]59                                curdes->printOneLine(os);
60                                curdes = (ExpressionNode *)(curdes->get_link());
61                                if ( curdes ) os << ", ";
62                        } // while
63                        os << ")";
64                } // if
65                if ( expr ) expr->printOneLine(os);
66        } else {  // It's an aggregate
67                os << "[--";
68                if ( next_init() != 0 )
69                        next_init()->printOneLine(os);
70                if (aggregate) os << "--]";
[17cd4eb]71        } // if
[b87a5ed]72
73        InitializerNode *moreInit;
74        if  ( get_link() != 0 && ((moreInit = dynamic_cast< InitializerNode * >( get_link() ) ) != 0) )
75                moreInit->printOneLine( os );
[51b7345]76}
77
78Initializer *InitializerNode::build() const {
[b87a5ed]79        // if ( get_expression() == 0 ) return 0;  // XXX (?)
[51b7345]80
[b87a5ed]81        if ( aggregate ) {
[097e2b0]82                //assert( next_init() != 0 );
[51b7345]83
[b87a5ed]84                std::list< Initializer *> initlist;
85                buildList<Initializer, InitializerNode>( next_init(), initlist );
[51b7345]86
[b87a5ed]87                std::list< Expression *> designlist;
[d9a0e76]88
[b87a5ed]89                if ( designator != 0 ) {
90                        buildList<Expression, ExpressionNode>( designator, designlist );
91                } // if
[51b7345]92
[974906e2]93                return new ListInit( initlist, designlist, maybeConstructed );
[b87a5ed]94        } else {
95                std::list< Expression *> designators;
[51b7345]96
[b87a5ed]97                if ( designator != 0 )
98                        buildList<Expression, ExpressionNode>( designator, designators );
[51b7345]99
[b87a5ed]100                if ( get_expression() != 0)
[974906e2]101                        return new SingleInit( get_expression()->build(), designators, maybeConstructed );
[b87a5ed]102        } // if
[51b7345]103
[b87a5ed]104        return 0;
[51b7345]105}
[b87a5ed]106
107// Local Variables: //
108// tab-width: 4 //
109// mode: c++ //
110// compile-command: "make install" //
111// End: //
Note: See TracBrowser for help on using the repository browser.