source: src/SynTree/Initializer.cc@ 982f95d

new-env
Last change on this file since 982f95d was 68f9c43, checked in by Aaron Moss <a3moss@…>, 8 years ago

First pass at delete removal

  • Property mode set to 100644
File size: 4.2 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 : Peter A. Buhr
12// Last Modified On : Mon Aug 21 09:53:15 2017
13// Update Count : 30
14//
15
16#include "Initializer.h"
17
18#include <cassert> // for assertf
19#include <ostream> // for ostream, operator<<, basic_ostream
20#include <string> // for operator<<, string, char_traits
21
22#include "Common/utility.h" // for maybeClone, cloneAll, deleteAll
23#include "Expression.h" // for Expression
24#include "Statement.h" // for Statement
25#include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode
26
27Designation::Designation( const std::list< Expression * > & designators ) : designators( designators ) {}
28Designation::Designation( const Designation & other ) : BaseSyntaxNode( other ) {
29 // std::cerr << "cloning designation" << std::endl;
30 cloneAll( other.designators, designators );
31 // std::cerr << "finished cloning designation" << std::endl;
32}
33
34void Designation::print( std::ostream &os, Indenter indent ) const {
35 if ( ! designators.empty() ) {
36 os << "... designated by: " << std::endl;
37 for ( const Expression * d : designators ) {
38 os << indent+1;
39 d->print(os, indent+1 );
40 os << std::endl;
41 }
42 } // if
43}
44
45Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
46Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) {
47}
48
49SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) {
50}
51
52SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) {
53}
54
55void SingleInit::print( std::ostream &os, Indenter indent ) const {
56 os << "Simple Initializer: ";
57 value->print( os, indent );
58}
59
60
61ListInit::ListInit( const std::list<Initializer*> &inits, const std::list<Designation *> &des, bool maybeConstructed )
62 : Initializer( maybeConstructed ), initializers( inits ), designations( des ) {
63 // handle the common case where a ListInit is created without designations by making a list of empty designations with the same length as the initializer
64 if ( designations.empty() ) {
65 for ( auto & i : initializers ) {
66 (void)i;
67 designations.push_back( new Designation( {} ) );
68 }
69 }
70 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%zd) and designations (%zd)", initializers.size(), designations.size() );
71}
72
73ListInit::ListInit( const ListInit & other ) : Initializer( other ) {
74 cloneAll( other.initializers, initializers );
75 cloneAll( other.designations, designations );
76}
77
78void ListInit::print( std::ostream &os, Indenter indent ) const {
79 os << "Compound initializer: " << std::endl;
80 for ( auto p : group_iterate( designations, initializers ) ) {
81 const Designation * d = std::get<0>(p);
82 const Initializer * init = std::get<1>(p);
83 os << indent+1;
84 init->print( os, indent+1 );
85 os << std::endl;
86 if ( ! d->designators.empty() ) {
87 os << indent+1;
88 d->print( os, indent+1 );
89 }
90 }
91}
92
93
94ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
95ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) {
96}
97
98void ConstructorInit::print( std::ostream &os, Indenter indent ) const {
99 os << "Constructor initializer: " << std::endl;
100 if ( ctor ) {
101 os << indent << "... initially constructed with ";
102 ctor->print( os, indent+1 );
103 } // if
104
105 if ( dtor ) {
106 os << indent << "... destructed with ";
107 dtor->print( os, indent+1 );
108 }
109
110 if ( init ) {
111 os << indent << "... with fallback C-style initializer: ";
112 init->print( os, indent+1 );
113 }
114}
115
116// Local Variables: //
117// tab-width: 4 //
118// mode: c++ //
119// compile-command: "make install" //
120// End: //
Note: See TracBrowser for help on using the repository browser.