source: src/SynTree/Initializer.h@ 5f5083e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 5f5083e was f0121d7, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

refactor genCtorInit, generate ConstructorInit for UniqueExpr

  • Property mode set to 100644
File size: 5.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.h --
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 : Tue Apr 12 13:49:13 2016
13// Update Count : 19
14//
15
16#ifndef INITIALIZER_H
17#define INITIALIZER_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22#include "Type.h"
23
24#include <cassert>
25
26const std::list<Expression*> noDesignators;
27
28// Initializer: base class for object initializers (provide default values)
29class Initializer {
30 public:
31 // Initializer( std::string _name = std::string(""), int _pos = 0 );
32 Initializer( bool maybeConstructed );
33 Initializer( const Initializer & other );
34 virtual ~Initializer();
35
36 static std::string designator_name( Expression *designator );
37
38 // void set_name( std::string newValue ) { name = newValue; }
39 // std::string get_name() const { return name; }
40
41 // void set_pos( int newValue ) { pos = newValue; }
42 // int get_pos() const { return pos; }
43 virtual void set_designators( std::list<Expression *> & ) { assert(false); }
44 virtual std::list<Expression *> &get_designators() {
45 assert(false);
46 std::list<Expression *> *ret = 0; return *ret; // never reached
47 }
48
49 bool get_maybeConstructed() { return maybeConstructed; }
50
51 virtual Initializer *clone() const = 0;
52 virtual void accept( Visitor &v ) = 0;
53 virtual Initializer *acceptMutator( Mutator &m ) = 0;
54 virtual void print( std::ostream &os, int indent = 0 );
55 private:
56 // std::string name;
57 // int pos;
58 bool maybeConstructed;
59};
60
61// SingleInit represents an initializer for a common object (e.g., int x = 4)
62class SingleInit : public Initializer {
63 public:
64 SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
65 SingleInit( const SingleInit &other );
66 virtual ~SingleInit();
67
68 Expression *get_value() { return value; }
69 void set_value( Expression *newValue ) { value = newValue; }
70
71 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
72 std::list<Expression *> &get_designators() { return designators; }
73
74 virtual SingleInit *clone() const { return new SingleInit( *this); }
75 virtual void accept( Visitor &v ) { v.visit( this ); }
76 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
77 virtual void print( std::ostream &os, int indent = 0 );
78 private:
79 //Constant *value;
80 Expression *value; // has to be a compile-time constant
81 std::list< Expression * > designators;
82};
83
84// ListInit represents an initializer that is composed recursively of a list of initializers; this is used to initialize
85// an array or aggregate
86class ListInit : public Initializer {
87 public:
88 ListInit( const std::list<Initializer*> &initializers,
89 const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false );
90 virtual ~ListInit();
91
92 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; }
93 std::list<Expression *> &get_designators() { return designators; }
94 void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; }
95 std::list<Initializer*> &get_initializers() { return initializers; }
96
97 typedef std::list<Initializer*>::iterator iterator;
98 iterator begin() { return initializers.begin(); }
99 iterator end() { return initializers.end(); }
100
101 virtual ListInit *clone() const { return new ListInit( *this ); }
102 virtual void accept( Visitor &v ) { v.visit( this ); }
103 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
104 virtual void print( std::ostream &os, int indent = 0 );
105 private:
106 std::list<Initializer*> initializers; // order *is* important
107 std::list<Expression *> designators;
108};
109
110// ConstructorInit represents an initializer that is either a constructor expression or
111// a C-style initializer.
112class ConstructorInit : public Initializer {
113 public:
114 ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
115 ConstructorInit( const ConstructorInit &other );
116 virtual ~ConstructorInit();
117
118 void set_ctor( Statement * newValue ) { ctor = newValue; }
119 Statement * get_ctor() const { return ctor; }
120 void set_dtor( Statement * newValue ) { dtor = newValue; }
121 Statement * get_dtor() const { return dtor; }
122 void set_init( Initializer * newValue ) { init = newValue; }
123 Initializer * get_init() const { return init; }
124
125 ConstructorInit *clone() const { return new ConstructorInit( *this ); }
126 virtual void accept( Visitor &v ) { v.visit( this ); }
127 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
128 virtual void print( std::ostream &os, int indent = 0 );
129
130 private:
131 Statement * ctor;
132 Statement * dtor;
133 // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback
134 // if an appropriate constructor definition is not found by the resolver
135 Initializer * init;
136};
137
138std::ostream & operator<<( std::ostream & out, Initializer * init );
139
140#endif // INITIALIZER_H
141
142// Local Variables: //
143// tab-width: 4 //
144// mode: c++ //
145// compile-command: "make install" //
146// End: //
Note: See TracBrowser for help on using the repository browser.