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 | // Expression.h -- |
---|
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 : Wed Dec 11 16:50:19 2019 |
---|
13 | // Update Count : 60 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <iosfwd> // for ostream |
---|
19 | #include <list> // for list, list<>::iterator |
---|
20 | #include <map> // for map, map<>::value_compare |
---|
21 | #include <memory> // for allocator, unique_ptr |
---|
22 | #include <string> // for string |
---|
23 | #include <vector> // for vector |
---|
24 | |
---|
25 | #include "BaseSyntaxNode.h" // for BaseSyntaxNode |
---|
26 | #include "Constant.h" // for Constant |
---|
27 | #include "Initializer.h" // for Designation (ptr only), Initializer |
---|
28 | #include "Label.h" // for Label |
---|
29 | #include "Mutator.h" // for Mutator |
---|
30 | #include "Declaration.h" // for Aggregate |
---|
31 | #include "SynTree.h" // for UniqueId |
---|
32 | #include "Visitor.h" // for Visitor |
---|
33 | |
---|
34 | |
---|
35 | struct ParamEntry; |
---|
36 | |
---|
37 | typedef std::map< UniqueId, ParamEntry > InferredParams; |
---|
38 | |
---|
39 | /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, |
---|
40 | /// but subject to decay-to-pointer and type parameter renaming |
---|
41 | struct ParamEntry { |
---|
42 | ParamEntry(): decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {} |
---|
43 | ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr ); |
---|
44 | ParamEntry( const ParamEntry & other ); |
---|
45 | ParamEntry( ParamEntry && other ); |
---|
46 | ~ParamEntry(); |
---|
47 | ParamEntry & operator=( ParamEntry && other ); |
---|
48 | |
---|
49 | UniqueId const decl; |
---|
50 | Declaration * const declptr; |
---|
51 | Type * const actualType; |
---|
52 | Type * const formalType; |
---|
53 | Expression * expr; |
---|
54 | }; |
---|
55 | |
---|
56 | /// Expression is the root type for all expressions |
---|
57 | class Expression : public BaseSyntaxNode { |
---|
58 | public: |
---|
59 | Type * result; |
---|
60 | TypeSubstitution * env; |
---|
61 | bool extension = false; |
---|
62 | InferredParams inferParams; ///< Post-resolution inferred parameter slots |
---|
63 | std::vector<UniqueId> resnSlots; ///< Pre-resolution inferred parameter slots |
---|
64 | |
---|
65 | // xxx - should turn inferParams+resnSlots into a union to save some memory |
---|
66 | |
---|
67 | Expression(); |
---|
68 | Expression( const Expression & other ); |
---|
69 | virtual ~Expression(); |
---|
70 | |
---|
71 | Type *& get_result() { return result; } |
---|
72 | const Type * get_result() const { return result; } |
---|
73 | void set_result( Type * newValue ) { result = newValue; } |
---|
74 | virtual bool get_lvalue() const; |
---|
75 | |
---|
76 | TypeSubstitution * get_env() const { return env; } |
---|
77 | void set_env( TypeSubstitution * newValue ) { env = newValue; } |
---|
78 | bool get_extension() const { return extension; } |
---|
79 | Expression * set_extension( bool exten ) { extension = exten; return this; } |
---|
80 | |
---|
81 | // move other's inferParams to this |
---|
82 | void spliceInferParams( Expression * other ); |
---|
83 | |
---|
84 | virtual Expression * clone() const override = 0; |
---|
85 | virtual void accept( Visitor & v ) override = 0; |
---|
86 | virtual void accept( Visitor & v ) const override = 0; |
---|
87 | virtual Expression * acceptMutator( Mutator & m ) override = 0; |
---|
88 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
89 | }; |
---|
90 | |
---|
91 | /// ApplicationExpr represents the application of a function to a set of parameters. This is the result of running an |
---|
92 | /// UntypedExpr through the expression analyzer. |
---|
93 | class ApplicationExpr : public Expression { |
---|
94 | public: |
---|
95 | Expression * function; |
---|
96 | std::list<Expression *> args; |
---|
97 | |
---|
98 | ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); |
---|
99 | ApplicationExpr( const ApplicationExpr & other ); |
---|
100 | virtual ~ApplicationExpr(); |
---|
101 | |
---|
102 | bool get_lvalue() const final; |
---|
103 | |
---|
104 | Expression * get_function() const { return function; } |
---|
105 | void set_function( Expression * newValue ) { function = newValue; } |
---|
106 | std::list<Expression *>& get_args() { return args; } |
---|
107 | |
---|
108 | virtual ApplicationExpr * clone() const override { return new ApplicationExpr( * this ); } |
---|
109 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
110 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
111 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
112 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
113 | }; |
---|
114 | |
---|
115 | /// UntypedExpr represents the application of a function to a set of parameters, but where the particular overload for |
---|
116 | /// the function name has not yet been determined. Most operators are converted into functional form automatically, to |
---|
117 | /// permit operator overloading. |
---|
118 | class UntypedExpr : public Expression { |
---|
119 | public: |
---|
120 | Expression * function; |
---|
121 | std::list<Expression*> args; |
---|
122 | |
---|
123 | UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); |
---|
124 | UntypedExpr( const UntypedExpr & other ); |
---|
125 | virtual ~UntypedExpr(); |
---|
126 | |
---|
127 | bool get_lvalue() const final; |
---|
128 | |
---|
129 | Expression * get_function() const { return function; } |
---|
130 | void set_function( Expression * newValue ) { function = newValue; } |
---|
131 | |
---|
132 | std::list<Expression*>::iterator begin_args() { return args.begin(); } |
---|
133 | std::list<Expression*>::iterator end_args() { return args.end(); } |
---|
134 | std::list<Expression*>& get_args() { return args; } |
---|
135 | |
---|
136 | static UntypedExpr * createDeref( Expression * arg ); |
---|
137 | static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 ); |
---|
138 | |
---|
139 | virtual UntypedExpr * clone() const override { return new UntypedExpr( * this ); } |
---|
140 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
141 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
142 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
143 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
144 | }; |
---|
145 | |
---|
146 | /// NameExpr contains a name whose meaning is still not determined |
---|
147 | class NameExpr : public Expression { |
---|
148 | public: |
---|
149 | std::string name; |
---|
150 | |
---|
151 | NameExpr( std::string name ); |
---|
152 | NameExpr( const NameExpr & other ); |
---|
153 | virtual ~NameExpr(); |
---|
154 | |
---|
155 | const std::string & get_name() const { return name; } |
---|
156 | void set_name( std::string newValue ) { name = newValue; } |
---|
157 | |
---|
158 | virtual NameExpr * clone() const override { return new NameExpr( * this ); } |
---|
159 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
160 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
161 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
162 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
163 | }; |
---|
164 | |
---|
165 | // [Qualifier].name; Qualifier is the type_name from the parser |
---|
166 | class QualifiedNameExpr : public Expression { |
---|
167 | public: |
---|
168 | Declaration * type_decl; |
---|
169 | std::string name; |
---|
170 | DeclarationWithType * var; |
---|
171 | |
---|
172 | QualifiedNameExpr( Declaration * decl, std::string name): Expression(), type_decl(decl), name(name) {} |
---|
173 | QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name), var(other.var) {} |
---|
174 | DeclarationWithType * get_var() const { return var; } |
---|
175 | void set_var( DeclarationWithType * newValue ) { var = newValue; } |
---|
176 | |
---|
177 | virtual ~QualifiedNameExpr() { |
---|
178 | delete var; |
---|
179 | delete type_decl; |
---|
180 | } |
---|
181 | |
---|
182 | virtual QualifiedNameExpr * clone() const override { |
---|
183 | return new QualifiedNameExpr( * this ); |
---|
184 | } |
---|
185 | virtual void accept( Visitor & v ) override { v.visit(this); } |
---|
186 | virtual void accept( Visitor & v ) const override { v.visit(this); } |
---|
187 | virtual Expression * acceptMutator( Mutator & m ) override { |
---|
188 | return m.mutate( this ); |
---|
189 | } |
---|
190 | |
---|
191 | virtual void print( std::ostream & os, Indenter indent = {} ) const override { |
---|
192 | type_decl->print( os, indent ); |
---|
193 | os << name << std::endl; |
---|
194 | } |
---|
195 | }; |
---|
196 | |
---|
197 | /// VariableExpr represents an expression that simply refers to the value of a named variable. |
---|
198 | /// Does not take ownership of var. |
---|
199 | class VariableExpr : public Expression { |
---|
200 | public: |
---|
201 | DeclarationWithType * var; |
---|
202 | |
---|
203 | VariableExpr(); |
---|
204 | VariableExpr( DeclarationWithType * var ); |
---|
205 | VariableExpr( const VariableExpr & other ); |
---|
206 | virtual ~VariableExpr(); |
---|
207 | |
---|
208 | bool get_lvalue() const final; |
---|
209 | |
---|
210 | DeclarationWithType * get_var() const { return var; } |
---|
211 | void set_var( DeclarationWithType * newValue ) { var = newValue; } |
---|
212 | |
---|
213 | static VariableExpr * functionPointer( FunctionDecl * decl ); |
---|
214 | |
---|
215 | virtual VariableExpr * clone() const override { return new VariableExpr( * this ); } |
---|
216 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
217 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
218 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
219 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
220 | }; |
---|
221 | |
---|
222 | // The following classes are used to represent expression types that cannot be converted into |
---|
223 | // function-call format. |
---|
224 | |
---|
225 | /// AddressExpr represents a address-of expression, e.g. & e |
---|
226 | class AddressExpr : public Expression { |
---|
227 | public: |
---|
228 | Expression * arg; |
---|
229 | |
---|
230 | AddressExpr( Expression * arg ); |
---|
231 | AddressExpr( const AddressExpr & other ); |
---|
232 | virtual ~AddressExpr(); |
---|
233 | |
---|
234 | Expression * get_arg() const { return arg; } |
---|
235 | void set_arg(Expression * newValue ) { arg = newValue; } |
---|
236 | |
---|
237 | virtual AddressExpr * clone() const override { return new AddressExpr( * this ); } |
---|
238 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
239 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
240 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
241 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
242 | }; |
---|
243 | |
---|
244 | // GCC &&label |
---|
245 | // https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html |
---|
246 | class LabelAddressExpr : public Expression { |
---|
247 | public: |
---|
248 | Label arg; |
---|
249 | |
---|
250 | LabelAddressExpr( const Label &arg ); |
---|
251 | LabelAddressExpr( const LabelAddressExpr & other ); |
---|
252 | virtual ~LabelAddressExpr(); |
---|
253 | |
---|
254 | virtual LabelAddressExpr * clone() const override { return new LabelAddressExpr( * this ); } |
---|
255 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
256 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
257 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
258 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
259 | }; |
---|
260 | |
---|
261 | /// CastExpr represents a type cast expression, e.g. (int)e |
---|
262 | class CastExpr : public Expression { |
---|
263 | public: |
---|
264 | Expression * arg; |
---|
265 | |
---|
266 | // Inidicates cast is introduced by the CFA type system. |
---|
267 | // true for casts that the resolver introduces to force a return type |
---|
268 | // false for casts from user code |
---|
269 | // false for casts from desugaring advanced CFA features into simpler CFA |
---|
270 | // example |
---|
271 | // int * p; // declaration |
---|
272 | // (float *) p; // use, with subject cast |
---|
273 | // subject cast isGenerated means we are considering an interpretation with a type mismatch |
---|
274 | // subject cast not isGenerated means someone in charge wants it that way |
---|
275 | bool isGenerated = true; |
---|
276 | |
---|
277 | CastExpr( Expression * arg, bool isGenerated = true ); |
---|
278 | CastExpr( Expression * arg, Type * toType, bool isGenerated = true ); |
---|
279 | CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor |
---|
280 | CastExpr( const CastExpr & other ); |
---|
281 | virtual ~CastExpr(); |
---|
282 | |
---|
283 | bool get_lvalue() const final; |
---|
284 | |
---|
285 | Expression * get_arg() const { return arg; } |
---|
286 | void set_arg( Expression * newValue ) { arg = newValue; } |
---|
287 | |
---|
288 | virtual CastExpr * clone() const override { return new CastExpr( * this ); } |
---|
289 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
290 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
291 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
292 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
293 | }; |
---|
294 | |
---|
295 | /// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t |
---|
296 | class KeywordCastExpr : public Expression { |
---|
297 | public: |
---|
298 | Expression * arg; |
---|
299 | struct Concrete { |
---|
300 | std::string field; |
---|
301 | std::string getter; |
---|
302 | }; |
---|
303 | AggregateDecl::Aggregate target; |
---|
304 | Concrete concrete_target; |
---|
305 | |
---|
306 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ); |
---|
307 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target, const Concrete & concrete_target ); |
---|
308 | KeywordCastExpr( const KeywordCastExpr & other ); |
---|
309 | virtual ~KeywordCastExpr(); |
---|
310 | |
---|
311 | const char * targetString() const; |
---|
312 | |
---|
313 | virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); } |
---|
314 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
315 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
316 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
317 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
318 | }; |
---|
319 | |
---|
320 | /// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e |
---|
321 | class VirtualCastExpr : public Expression { |
---|
322 | public: |
---|
323 | Expression * arg; |
---|
324 | |
---|
325 | VirtualCastExpr( Expression * arg, Type * toType ); |
---|
326 | VirtualCastExpr( const VirtualCastExpr & other ); |
---|
327 | virtual ~VirtualCastExpr(); |
---|
328 | |
---|
329 | Expression * get_arg() const { return arg; } |
---|
330 | void set_arg( Expression * newValue ) { arg = newValue; } |
---|
331 | |
---|
332 | virtual VirtualCastExpr * clone() const override { return new VirtualCastExpr( * this ); } |
---|
333 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
334 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
335 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
336 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
337 | }; |
---|
338 | |
---|
339 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer |
---|
340 | class UntypedMemberExpr : public Expression { |
---|
341 | public: |
---|
342 | Expression * member; |
---|
343 | Expression * aggregate; |
---|
344 | |
---|
345 | UntypedMemberExpr( Expression * member, Expression * aggregate ); |
---|
346 | UntypedMemberExpr( const UntypedMemberExpr & other ); |
---|
347 | virtual ~UntypedMemberExpr(); |
---|
348 | |
---|
349 | bool get_lvalue() const final; |
---|
350 | |
---|
351 | Expression * get_member() const { return member; } |
---|
352 | void set_member( Expression * newValue ) { member = newValue; } |
---|
353 | Expression * get_aggregate() const { return aggregate; } |
---|
354 | void set_aggregate( Expression * newValue ) { aggregate = newValue; } |
---|
355 | |
---|
356 | virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); } |
---|
357 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
358 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
359 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
360 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
361 | }; |
---|
362 | |
---|
363 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer. |
---|
364 | /// Does not take ownership of member. |
---|
365 | class MemberExpr : public Expression { |
---|
366 | public: |
---|
367 | DeclarationWithType * member; |
---|
368 | Expression * aggregate; |
---|
369 | |
---|
370 | MemberExpr( DeclarationWithType * member, Expression * aggregate ); |
---|
371 | MemberExpr( const MemberExpr & other ); |
---|
372 | virtual ~MemberExpr(); |
---|
373 | |
---|
374 | bool get_lvalue() const final; |
---|
375 | |
---|
376 | DeclarationWithType * get_member() const { return member; } |
---|
377 | void set_member( DeclarationWithType * newValue ) { member = newValue; } |
---|
378 | Expression * get_aggregate() const { return aggregate; } |
---|
379 | void set_aggregate( Expression * newValue ) { aggregate = newValue; } |
---|
380 | |
---|
381 | virtual MemberExpr * clone() const override { return new MemberExpr( * this ); } |
---|
382 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
383 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
384 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
385 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
386 | }; |
---|
387 | |
---|
388 | /// ConstantExpr represents an expression that simply refers to the value of a constant |
---|
389 | class ConstantExpr : public Expression { |
---|
390 | public: |
---|
391 | Constant constant; |
---|
392 | |
---|
393 | ConstantExpr( Constant constant ); |
---|
394 | ConstantExpr( const ConstantExpr & other ); |
---|
395 | virtual ~ConstantExpr(); |
---|
396 | |
---|
397 | Constant * get_constant() { return & constant; } |
---|
398 | const Constant * get_constant() const { return & constant; } |
---|
399 | void set_constant( const Constant & newValue ) { constant = newValue; } |
---|
400 | |
---|
401 | long long int intValue() const; |
---|
402 | |
---|
403 | virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); } |
---|
404 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
405 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
406 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
407 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
408 | }; |
---|
409 | |
---|
410 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) |
---|
411 | class SizeofExpr : public Expression { |
---|
412 | public: |
---|
413 | Expression * expr; |
---|
414 | Type * type; |
---|
415 | bool isType; |
---|
416 | |
---|
417 | SizeofExpr( Expression * expr ); |
---|
418 | SizeofExpr( const SizeofExpr & other ); |
---|
419 | SizeofExpr( Type * type ); |
---|
420 | virtual ~SizeofExpr(); |
---|
421 | |
---|
422 | Expression * get_expr() const { return expr; } |
---|
423 | void set_expr( Expression * newValue ) { expr = newValue; } |
---|
424 | Type * get_type() const { return type; } |
---|
425 | void set_type( Type * newValue ) { type = newValue; } |
---|
426 | bool get_isType() const { return isType; } |
---|
427 | void set_isType( bool newValue ) { isType = newValue; } |
---|
428 | |
---|
429 | virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); } |
---|
430 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
431 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
432 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
433 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
434 | }; |
---|
435 | |
---|
436 | /// AlignofExpr represents an alignof expression |
---|
437 | class AlignofExpr : public Expression { |
---|
438 | public: |
---|
439 | Expression * expr; |
---|
440 | Type * type; |
---|
441 | bool isType; |
---|
442 | |
---|
443 | AlignofExpr( Expression * expr ); |
---|
444 | AlignofExpr( const AlignofExpr & other ); |
---|
445 | AlignofExpr( Type * type ); |
---|
446 | virtual ~AlignofExpr(); |
---|
447 | |
---|
448 | Expression * get_expr() const { return expr; } |
---|
449 | void set_expr( Expression * newValue ) { expr = newValue; } |
---|
450 | Type * get_type() const { return type; } |
---|
451 | void set_type( Type * newValue ) { type = newValue; } |
---|
452 | bool get_isType() const { return isType; } |
---|
453 | void set_isType( bool newValue ) { isType = newValue; } |
---|
454 | |
---|
455 | virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); } |
---|
456 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
457 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
458 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
459 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
460 | }; |
---|
461 | |
---|
462 | /// UntypedOffsetofExpr represents an offsetof expression before resolution |
---|
463 | class UntypedOffsetofExpr : public Expression { |
---|
464 | public: |
---|
465 | Type * type; |
---|
466 | std::string member; |
---|
467 | |
---|
468 | UntypedOffsetofExpr( Type * type, const std::string & member ); |
---|
469 | UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); |
---|
470 | virtual ~UntypedOffsetofExpr(); |
---|
471 | |
---|
472 | std::string get_member() const { return member; } |
---|
473 | void set_member( const std::string & newValue ) { member = newValue; } |
---|
474 | Type * get_type() const { return type; } |
---|
475 | void set_type( Type * newValue ) { type = newValue; } |
---|
476 | |
---|
477 | virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); } |
---|
478 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
479 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
480 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
481 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
482 | }; |
---|
483 | |
---|
484 | /// OffsetofExpr represents an offsetof expression |
---|
485 | class OffsetofExpr : public Expression { |
---|
486 | public: |
---|
487 | Type * type; |
---|
488 | DeclarationWithType * member; |
---|
489 | |
---|
490 | OffsetofExpr( Type * type, DeclarationWithType * member ); |
---|
491 | OffsetofExpr( const OffsetofExpr & other ); |
---|
492 | virtual ~OffsetofExpr(); |
---|
493 | |
---|
494 | Type * get_type() const { return type; } |
---|
495 | void set_type( Type * newValue ) { type = newValue; } |
---|
496 | DeclarationWithType * get_member() const { return member; } |
---|
497 | void set_member( DeclarationWithType * newValue ) { member = newValue; } |
---|
498 | |
---|
499 | virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); } |
---|
500 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
501 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
502 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
503 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
504 | }; |
---|
505 | |
---|
506 | /// Expression representing a pack of field-offsets for a generic type |
---|
507 | class OffsetPackExpr : public Expression { |
---|
508 | public: |
---|
509 | StructInstType * type; |
---|
510 | |
---|
511 | OffsetPackExpr( StructInstType * type ); |
---|
512 | OffsetPackExpr( const OffsetPackExpr & other ); |
---|
513 | virtual ~OffsetPackExpr(); |
---|
514 | |
---|
515 | StructInstType * get_type() const { return type; } |
---|
516 | void set_type( StructInstType * newValue ) { type = newValue; } |
---|
517 | |
---|
518 | virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); } |
---|
519 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
520 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
521 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
522 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
523 | }; |
---|
524 | |
---|
525 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||) |
---|
526 | class LogicalExpr : public Expression { |
---|
527 | public: |
---|
528 | Expression * arg1; |
---|
529 | Expression * arg2; |
---|
530 | |
---|
531 | LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true ); |
---|
532 | LogicalExpr( const LogicalExpr & other ); |
---|
533 | virtual ~LogicalExpr(); |
---|
534 | |
---|
535 | bool get_isAnd() const { return isAnd; } |
---|
536 | Expression * get_arg1() { return arg1; } |
---|
537 | void set_arg1( Expression * newValue ) { arg1 = newValue; } |
---|
538 | Expression * get_arg2() const { return arg2; } |
---|
539 | void set_arg2( Expression * newValue ) { arg2 = newValue; } |
---|
540 | |
---|
541 | virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); } |
---|
542 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
543 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
544 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
545 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
546 | |
---|
547 | private: |
---|
548 | bool isAnd; |
---|
549 | }; |
---|
550 | |
---|
551 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) |
---|
552 | class ConditionalExpr : public Expression { |
---|
553 | public: |
---|
554 | Expression * arg1; |
---|
555 | Expression * arg2; |
---|
556 | Expression * arg3; |
---|
557 | |
---|
558 | ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ); |
---|
559 | ConditionalExpr( const ConditionalExpr & other ); |
---|
560 | virtual ~ConditionalExpr(); |
---|
561 | |
---|
562 | bool get_lvalue() const final; |
---|
563 | |
---|
564 | Expression * get_arg1() const { return arg1; } |
---|
565 | void set_arg1( Expression * newValue ) { arg1 = newValue; } |
---|
566 | Expression * get_arg2() const { return arg2; } |
---|
567 | void set_arg2( Expression * newValue ) { arg2 = newValue; } |
---|
568 | Expression * get_arg3() const { return arg3; } |
---|
569 | void set_arg3( Expression * newValue ) { arg3 = newValue; } |
---|
570 | |
---|
571 | virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * this ); } |
---|
572 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
573 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
574 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
575 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
576 | }; |
---|
577 | |
---|
578 | /// CommaExpr represents the sequence operator ( a, b ) |
---|
579 | class CommaExpr : public Expression { |
---|
580 | public: |
---|
581 | Expression * arg1; |
---|
582 | Expression * arg2; |
---|
583 | |
---|
584 | CommaExpr( Expression * arg1, Expression * arg2 ); |
---|
585 | CommaExpr( const CommaExpr & other ); |
---|
586 | virtual ~CommaExpr(); |
---|
587 | |
---|
588 | bool get_lvalue() const final; |
---|
589 | |
---|
590 | Expression * get_arg1() const { return arg1; } |
---|
591 | void set_arg1( Expression * newValue ) { arg1 = newValue; } |
---|
592 | Expression * get_arg2() const { return arg2; } |
---|
593 | void set_arg2( Expression * newValue ) { arg2 = newValue; } |
---|
594 | |
---|
595 | virtual CommaExpr * clone() const override { return new CommaExpr( * this ); } |
---|
596 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
597 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
598 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
599 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
600 | }; |
---|
601 | |
---|
602 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter) |
---|
603 | class TypeExpr : public Expression { |
---|
604 | public: |
---|
605 | Type * type; |
---|
606 | |
---|
607 | TypeExpr( Type * type ); |
---|
608 | TypeExpr( const TypeExpr & other ); |
---|
609 | virtual ~TypeExpr(); |
---|
610 | |
---|
611 | Type * get_type() const { return type; } |
---|
612 | void set_type( Type * newValue ) { type = newValue; } |
---|
613 | |
---|
614 | virtual TypeExpr * clone() const override { return new TypeExpr( * this ); } |
---|
615 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
616 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
617 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
618 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
619 | }; |
---|
620 | |
---|
621 | /// DimensionExpr represents a type-system provided value used in an expression ( forrall([N]) ... N + 1 ) |
---|
622 | class DimensionExpr : public Expression { |
---|
623 | public: |
---|
624 | std::string name; |
---|
625 | |
---|
626 | DimensionExpr( std::string name ); |
---|
627 | DimensionExpr( const DimensionExpr & other ); |
---|
628 | virtual ~DimensionExpr(); |
---|
629 | |
---|
630 | const std::string & get_name() const { return name; } |
---|
631 | void set_name( std::string newValue ) { name = newValue; } |
---|
632 | |
---|
633 | virtual DimensionExpr * clone() const override { return new DimensionExpr( * this ); } |
---|
634 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
635 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
636 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
637 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
638 | }; |
---|
639 | |
---|
640 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) |
---|
641 | class AsmExpr : public Expression { |
---|
642 | public: |
---|
643 | std::string inout; |
---|
644 | Expression * constraint; |
---|
645 | Expression * operand; |
---|
646 | |
---|
647 | AsmExpr( const std::string * _inout, Expression * constraint, Expression * operand ) : inout( _inout ? *_inout : "" ), constraint( constraint ), operand( operand ) { delete _inout; } |
---|
648 | AsmExpr( const AsmExpr & other ); |
---|
649 | virtual ~AsmExpr() { delete constraint; delete operand; }; |
---|
650 | |
---|
651 | virtual AsmExpr * clone() const override { return new AsmExpr( * this ); } |
---|
652 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
653 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
654 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
655 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
656 | |
---|
657 | // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints |
---|
658 | }; |
---|
659 | |
---|
660 | /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters, |
---|
661 | /// along with a set of copy constructor calls, one for each argument. |
---|
662 | class ImplicitCopyCtorExpr : public Expression { |
---|
663 | public: |
---|
664 | ApplicationExpr * callExpr = nullptr; |
---|
665 | |
---|
666 | ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); |
---|
667 | ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); |
---|
668 | virtual ~ImplicitCopyCtorExpr(); |
---|
669 | |
---|
670 | virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); } |
---|
671 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
672 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
673 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
674 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
675 | }; |
---|
676 | |
---|
677 | /// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 }; |
---|
678 | class ConstructorExpr : public Expression { |
---|
679 | public: |
---|
680 | Expression * callExpr; |
---|
681 | |
---|
682 | ConstructorExpr( Expression * callExpr ); |
---|
683 | ConstructorExpr( const ConstructorExpr & other ); |
---|
684 | ~ConstructorExpr(); |
---|
685 | |
---|
686 | bool get_lvalue() const final; |
---|
687 | |
---|
688 | Expression * get_callExpr() const { return callExpr; } |
---|
689 | void set_callExpr( Expression * newValue ) { callExpr = newValue; } |
---|
690 | |
---|
691 | virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); } |
---|
692 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
693 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
694 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
695 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
696 | }; |
---|
697 | |
---|
698 | /// CompoundLiteralExpr represents a C99 'compound literal' |
---|
699 | class CompoundLiteralExpr : public Expression { |
---|
700 | public: |
---|
701 | Initializer * initializer; |
---|
702 | |
---|
703 | CompoundLiteralExpr( Type * type, Initializer * initializer ); |
---|
704 | CompoundLiteralExpr( const CompoundLiteralExpr & other ); |
---|
705 | virtual ~CompoundLiteralExpr(); |
---|
706 | |
---|
707 | bool get_lvalue() const final; |
---|
708 | |
---|
709 | Initializer * get_initializer() const { return initializer; } |
---|
710 | void set_initializer( Initializer * i ) { initializer = i; } |
---|
711 | |
---|
712 | virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); } |
---|
713 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
714 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
715 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
716 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
717 | }; |
---|
718 | |
---|
719 | /// RangeExpr represents a range e.g. '3 ... 5' or '1~10' |
---|
720 | class RangeExpr : public Expression { |
---|
721 | public: |
---|
722 | Expression * low, * high; |
---|
723 | |
---|
724 | RangeExpr( Expression * low, Expression * high ); |
---|
725 | RangeExpr( const RangeExpr & other ); |
---|
726 | |
---|
727 | Expression * get_low() const { return low; } |
---|
728 | Expression * get_high() const { return high; } |
---|
729 | RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; } |
---|
730 | RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; } |
---|
731 | |
---|
732 | virtual RangeExpr * clone() const override { return new RangeExpr( * this ); } |
---|
733 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
734 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
735 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
736 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
737 | }; |
---|
738 | |
---|
739 | /// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution |
---|
740 | class UntypedTupleExpr : public Expression { |
---|
741 | public: |
---|
742 | std::list<Expression*> exprs; |
---|
743 | |
---|
744 | UntypedTupleExpr( const std::list< Expression * > & exprs ); |
---|
745 | UntypedTupleExpr( const UntypedTupleExpr & other ); |
---|
746 | virtual ~UntypedTupleExpr(); |
---|
747 | |
---|
748 | std::list<Expression*>& get_exprs() { return exprs; } |
---|
749 | |
---|
750 | virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); } |
---|
751 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
752 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
753 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
754 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
755 | }; |
---|
756 | |
---|
757 | /// TupleExpr represents a tuple expression ( [a, b, c] ) |
---|
758 | class TupleExpr : public Expression { |
---|
759 | public: |
---|
760 | std::list<Expression*> exprs; |
---|
761 | |
---|
762 | TupleExpr( const std::list< Expression * > & exprs ); |
---|
763 | TupleExpr( const TupleExpr & other ); |
---|
764 | virtual ~TupleExpr(); |
---|
765 | |
---|
766 | bool get_lvalue() const final; |
---|
767 | |
---|
768 | std::list<Expression*>& get_exprs() { return exprs; } |
---|
769 | |
---|
770 | virtual TupleExpr * clone() const override { return new TupleExpr( * this ); } |
---|
771 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
772 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
773 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
774 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
775 | }; |
---|
776 | |
---|
777 | /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer |
---|
778 | class TupleIndexExpr : public Expression { |
---|
779 | public: |
---|
780 | Expression * tuple; |
---|
781 | unsigned int index; |
---|
782 | |
---|
783 | TupleIndexExpr( Expression * tuple, unsigned int index ); |
---|
784 | TupleIndexExpr( const TupleIndexExpr & other ); |
---|
785 | virtual ~TupleIndexExpr(); |
---|
786 | |
---|
787 | bool get_lvalue() const final; |
---|
788 | |
---|
789 | Expression * get_tuple() const { return tuple; } |
---|
790 | int get_index() const { return index; } |
---|
791 | TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; } |
---|
792 | TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; } |
---|
793 | |
---|
794 | virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); } |
---|
795 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
796 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
797 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
798 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
799 | }; |
---|
800 | |
---|
801 | /// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, a mass assignment operation, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0;, or a tuple ctor/dtor expression |
---|
802 | class TupleAssignExpr : public Expression { |
---|
803 | public: |
---|
804 | StmtExpr * stmtExpr = nullptr; |
---|
805 | |
---|
806 | TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ); |
---|
807 | TupleAssignExpr( const TupleAssignExpr & other ); |
---|
808 | virtual ~TupleAssignExpr(); |
---|
809 | |
---|
810 | TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; } |
---|
811 | StmtExpr * get_stmtExpr() const { return stmtExpr; } |
---|
812 | |
---|
813 | virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); } |
---|
814 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
815 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
816 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
817 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
818 | |
---|
819 | friend class ConverterNewToOld; |
---|
820 | private: |
---|
821 | TupleAssignExpr( StmtExpr * stmts ); |
---|
822 | }; |
---|
823 | |
---|
824 | /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; }) |
---|
825 | class StmtExpr : public Expression { |
---|
826 | public: |
---|
827 | CompoundStmt * statements; |
---|
828 | std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression |
---|
829 | std::list< Expression * > dtors; // destructor(s) for return variable(s) |
---|
830 | |
---|
831 | // readonly |
---|
832 | ExprStmt * resultExpr = nullptr; |
---|
833 | |
---|
834 | StmtExpr( CompoundStmt * statements ); |
---|
835 | StmtExpr( const StmtExpr & other ); |
---|
836 | virtual ~StmtExpr(); |
---|
837 | |
---|
838 | bool get_lvalue() const final; |
---|
839 | |
---|
840 | CompoundStmt * get_statements() const { return statements; } |
---|
841 | StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; } |
---|
842 | |
---|
843 | // call to set the result type of this StmtExpr based on its body |
---|
844 | void computeResult(); |
---|
845 | |
---|
846 | std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } |
---|
847 | std::list< Expression * > & get_dtors() { return dtors; } |
---|
848 | |
---|
849 | virtual StmtExpr * clone() const override { return new StmtExpr( * this ); } |
---|
850 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
851 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
852 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
853 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
854 | }; |
---|
855 | |
---|
856 | class UniqueExpr : public Expression { |
---|
857 | public: |
---|
858 | Expression * expr; |
---|
859 | ObjectDecl * object; |
---|
860 | VariableExpr * var; |
---|
861 | |
---|
862 | UniqueExpr( Expression * expr, long long idVal = -1 ); |
---|
863 | UniqueExpr( const UniqueExpr & other ); |
---|
864 | ~UniqueExpr(); |
---|
865 | |
---|
866 | Expression * get_expr() const { return expr; } |
---|
867 | UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; } |
---|
868 | |
---|
869 | ObjectDecl * get_object() const { return object; } |
---|
870 | UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; } |
---|
871 | |
---|
872 | VariableExpr * get_var() const { return var; } |
---|
873 | UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; } |
---|
874 | |
---|
875 | int get_id() const { return id; } |
---|
876 | |
---|
877 | virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); } |
---|
878 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
879 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
880 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
881 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
882 | |
---|
883 | private: |
---|
884 | int id; |
---|
885 | static long long count; |
---|
886 | }; |
---|
887 | |
---|
888 | struct InitAlternative { |
---|
889 | public: |
---|
890 | Type * type = nullptr; |
---|
891 | Designation * designation = nullptr; |
---|
892 | InitAlternative( Type * type, Designation * designation ); |
---|
893 | InitAlternative( const InitAlternative & other ); |
---|
894 | InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it |
---|
895 | ~InitAlternative(); |
---|
896 | }; |
---|
897 | |
---|
898 | class UntypedInitExpr : public Expression { |
---|
899 | public: |
---|
900 | Expression * expr; |
---|
901 | std::list<InitAlternative> initAlts; |
---|
902 | |
---|
903 | UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ); |
---|
904 | UntypedInitExpr( const UntypedInitExpr & other ); |
---|
905 | ~UntypedInitExpr(); |
---|
906 | |
---|
907 | Expression * get_expr() const { return expr; } |
---|
908 | UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; } |
---|
909 | |
---|
910 | std::list<InitAlternative> & get_initAlts() { return initAlts; } |
---|
911 | |
---|
912 | virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); } |
---|
913 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
914 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
915 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
916 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
917 | }; |
---|
918 | |
---|
919 | class InitExpr : public Expression { |
---|
920 | public: |
---|
921 | Expression * expr; |
---|
922 | Designation * designation; |
---|
923 | |
---|
924 | InitExpr( Expression * expr, Designation * designation ); |
---|
925 | InitExpr( const InitExpr & other ); |
---|
926 | ~InitExpr(); |
---|
927 | |
---|
928 | Expression * get_expr() const { return expr; } |
---|
929 | InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; } |
---|
930 | |
---|
931 | Designation * get_designation() const { return designation; } |
---|
932 | InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; } |
---|
933 | |
---|
934 | virtual InitExpr * clone() const override { return new InitExpr( * this ); } |
---|
935 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
936 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
937 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
938 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
939 | }; |
---|
940 | |
---|
941 | /// expression that contains a deleted identifier - should never make it past the resolver. |
---|
942 | class DeletedExpr : public Expression { |
---|
943 | public: |
---|
944 | Expression * expr; |
---|
945 | Declaration * deleteStmt; |
---|
946 | |
---|
947 | DeletedExpr( Expression * expr, Declaration * deleteStmt ); |
---|
948 | DeletedExpr( const DeletedExpr & other ); |
---|
949 | ~DeletedExpr(); |
---|
950 | |
---|
951 | virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); } |
---|
952 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
953 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
954 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
955 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
956 | }; |
---|
957 | |
---|
958 | /// expression wrapping the use of a default argument - should never make it past the resolver. |
---|
959 | class DefaultArgExpr : public Expression { |
---|
960 | public: |
---|
961 | Expression * expr; |
---|
962 | |
---|
963 | DefaultArgExpr( Expression * expr ); |
---|
964 | DefaultArgExpr( const DefaultArgExpr & other ); |
---|
965 | ~DefaultArgExpr(); |
---|
966 | |
---|
967 | virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); } |
---|
968 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
969 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
970 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
971 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
972 | }; |
---|
973 | |
---|
974 | /// C11 _Generic expression |
---|
975 | class GenericExpr : public Expression { |
---|
976 | public: |
---|
977 | struct Association { |
---|
978 | Type * type = nullptr; |
---|
979 | Expression * expr = nullptr; |
---|
980 | bool isDefault = false; |
---|
981 | |
---|
982 | Association( Type * type, Expression * expr ); |
---|
983 | Association( Expression * expr ); |
---|
984 | Association( const Association & other ); |
---|
985 | Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it |
---|
986 | ~Association(); |
---|
987 | }; |
---|
988 | |
---|
989 | Expression * control; |
---|
990 | std::list<Association> associations; |
---|
991 | |
---|
992 | GenericExpr( Expression * control, const std::list<Association> & assoc ); |
---|
993 | GenericExpr( const GenericExpr & other ); |
---|
994 | virtual ~GenericExpr(); |
---|
995 | |
---|
996 | virtual GenericExpr * clone() const override { return new GenericExpr( * this ); } |
---|
997 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
998 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
999 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
1000 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
1001 | }; |
---|
1002 | |
---|
1003 | // Local Variables: // |
---|
1004 | // tab-width: 4 // |
---|
1005 | // mode: c++ // |
---|
1006 | // compile-command: "make install" // |
---|
1007 | // End: // |
---|