source: src/Parser/InitializerNode.cc @ b7d6a36

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since b7d6a36 was 3ed994e, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Push deleted decls through the system

  • Property mode set to 100644
File size: 3.8 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 ), isDelete( false ) {
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 ), isDelete( false ) {
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( bool isDelete ) : expr( nullptr ), aggregate( false ), designator( nullptr ), kids( nullptr ), maybeConstructed( false ), isDelete( isDelete ) {}
50
51InitializerNode::~InitializerNode() {
52        delete expr;
53        delete designator;
54        delete kids;
55} // InitializerNode::~InitializerNode
56
57void InitializerNode::print( std::ostream &os, int indent ) const {
58        os << std::string( indent, ' ' ) << "Initializer expression" << std::endl;
59} // InitializerNode::print
60
61void InitializerNode::printOneLine( std::ostream &os ) const {
62        if ( ! aggregate ) {
63                if ( designator ) {
64                        os << "designated by: (";
65                        ExpressionNode *curdes = designator;
66                        while ( curdes != nullptr) {
67                                curdes->printOneLine(os);
68                                curdes = (ExpressionNode *)(curdes->get_next());
69                                if ( curdes ) os << ", ";
70                        } // while
71                        os << ")";
72                } // if
73                if ( expr ) expr->printOneLine( os );
74        } else {  // It's an aggregate
75                os << "[--";
76                if ( next_init() != nullptr )
77                        next_init()->printOneLine( os );
78                if (aggregate) os << "--]";
79        } // if
80
81        InitializerNode *moreInit;
82        if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) {
83                moreInit->printOneLine( os );
84        } // if
85} // InitializerNode::printOneLine
86
87Initializer * InitializerNode::build() const {
88        assertf( ! isDelete, "Should not build delete stmt InitializerNode" );
89        if ( aggregate ) {
90                // steal designators from children
91                std::list< Designation * > designlist;
92                InitializerNode * child = next_init();
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 ) );
97                } // for
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                        return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed );
104                } // if
105        } // if
106        return nullptr;
107} // InitializerNode::build
108
109// Local Variables: //
110// tab-width: 4 //
111// mode: c++ //
112// compile-command: "make install" //
113// End: //
Note: See TracBrowser for help on using the repository browser.