source: translator/Parser/InitializerNode.cc@ d4778a6

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since d4778a6 was bdd516a, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

fixed sizeof type variable, find lowest cost alternative for sizeof expression, removed unused classes, added compiler flag, remove temporary file for -CFA, formatting

  • Property mode set to 100644
File size: 2.3 KB
Line 
1#include <cassert>
2#include <iostream>
3using namespace std;
4
5#include "ParseNode.h"
6#include "SynTree/Expression.h"
7#include "SynTree/Initializer.h"
8
9InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des )
10 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ) {
11 if ( aggrp )
12 kids = dynamic_cast< InitializerNode *>( get_link() );
13
14 if ( kids != 0 )
15 set_link( 0 );
16}
17
18InitializerNode::InitializerNode( InitializerNode *init, bool aggrp, ExpressionNode *des )
19 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ) {
20 if ( init != 0 )
21 set_link(init);
22
23 if ( aggrp )
24 kids = dynamic_cast< InitializerNode *>( get_link() );
25
26 if ( kids != 0 )
27 set_next( 0 );
28}
29
30InitializerNode::~InitializerNode() {
31 delete expr;
32}
33
34void InitializerNode::print( std::ostream &os, int indent ) const {
35 os << std::string(indent, ' ') << "Initializer expression" << std::endl;
36}
37
38void InitializerNode::printOneLine( std::ostream &os ) const {
39 if ( ! aggregate ) {
40 if ( designator != 0 ) {
41 os << "designated by: (";
42 ExpressionNode *curdes = designator;
43 while( curdes != 0) {
44 curdes->printOneLine(os);
45 curdes = (ExpressionNode *)(curdes->get_link());
46 if ( curdes ) os << ", ";
47 } // while
48 os << ")";
49 } // if
50 if ( expr ) expr->printOneLine(os);
51 } else { // It's an aggregate
52 os << "[--";
53 if ( next_init() != 0 )
54 next_init()->printOneLine(os);
55 if (aggregate) os << "--]";
56 } // if
57
58 InitializerNode *moreInit;
59 if ( get_link() != 0 && ((moreInit = dynamic_cast< InitializerNode * >( get_link() ) ) != 0) )
60 moreInit->printOneLine( os );
61}
62
63Initializer *InitializerNode::build() const {
64 // if ( get_expression() == 0 ) return 0; // XXX (?)
65
66 if ( aggregate ) {
67 assert( next_init() != 0 );
68
69 std::list< Initializer *> initlist;
70 buildList<Initializer, InitializerNode>( next_init(), initlist );
71
72 std::list< Expression *> designlist;
73
74 if ( designator != 0 ) {
75 buildList<Expression, ExpressionNode>( designator, designlist );
76 } // if
77
78 return new ListInit( initlist, designlist );
79 } else {
80 std::list< Expression *> designators;
81
82 if ( designator != 0 )
83 buildList<Expression, ExpressionNode>( designator, designators );
84
85 if ( get_expression() != 0)
86 return new SingleInit( get_expression()->build(), designators );
87 } // if
88
89 return 0;
90}
Note: See TracBrowser for help on using the repository browser.