source: src/SynTree/Initializer.cc @ bb8ea30

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since bb8ea30 was bb8ea30, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

fix printing for ArrayType?, Expression, Initializer, etc.

  • Property mode set to 100644
File size: 2.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// Initializer.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Fri May 13 13:19:30 2016
13// Update Count     : 28
14//
15
16#include "Initializer.h"
17#include "Expression.h"
18#include "Common/utility.h"
19
20Initializer::Initializer() {}
21
22Initializer::~Initializer() {}
23
24std::string Initializer::designator_name( Expression *des ) {
25        if ( NameExpr *n = dynamic_cast<NameExpr *>(des) )
26                return n->get_name();
27        else
28                throw 0;
29}
30
31void Initializer::print( std::ostream &os, int indent ) {}
32
33SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) {
34}
35
36SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) {
37        cloneAll(other.designators, designators );
38}
39
40SingleInit::~SingleInit() {}
41
42SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
43
44void SingleInit::print( std::ostream &os, int indent ) {
45        os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: " << std::endl;
46        os << std::string(indent+4, ' ' );
47        value->print( os, indent+4 );
48
49        if ( ! designators.empty() ) {
50                os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " << std::endl;
51                for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) {
52                        os << std::string(indent + 4, ' ' );
53                        ( *i )->print(os, indent + 4 );
54                }
55        } // if
56}
57
58ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators )
59        : initializers( _initializers ), designators( _designators ) {
60}
61
62ListInit::~ListInit() {}
63
64ListInit *ListInit::clone() const {
65        return new ListInit( *this );
66}
67
68void ListInit::print( std::ostream &os, int indent ) {
69        os << std::endl << std::string(indent, ' ') << "Compound initializer:  ";
70        if ( ! designators.empty() ) {
71                os << std::string(indent + 2, ' ' ) << "designated by: [";
72                for ( std::list < Expression * >::iterator i = designators.begin();
73                          i != designators.end(); i++ ) {
74                        ( *i )->print(os, indent + 4 );
75                } // for
76
77                os << std::string(indent + 2, ' ' ) << "]";
78        } // if
79
80        for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ )
81                (*i)->print( os, indent + 2 );
82}
83// Local Variables: //
84// tab-width: 4 //
85// mode: c++ //
86// compile-command: "make install" //
87// End: //
Note: See TracBrowser for help on using the repository browser.