[0dd3a2f] | 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 | //
|
---|
[3be261a] | 7 | // Expression.h --
|
---|
[0dd3a2f] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
---|
[e612146c] | 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Sun Sep 3 19:23:46 2017
|
---|
| 13 | // Update Count : 48
|
---|
[0dd3a2f] | 14 | //
|
---|
[e612146c] | 15 |
|
---|
[6b0b624] | 16 | #pragma once
|
---|
[51b73452] | 17 |
|
---|
[ea6332d] | 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 |
|
---|
| 24 | #include "BaseSyntaxNode.h" // for BaseSyntaxNode
|
---|
| 25 | #include "Constant.h" // for Constant
|
---|
| 26 | #include "Initializer.h" // for Designation (ptr only), Initializer
|
---|
[5809461] | 27 | #include "Label.h" // for Label
|
---|
[ea6332d] | 28 | #include "Mutator.h" // for Mutator
|
---|
| 29 | #include "SynTree.h" // for UniqueId
|
---|
| 30 | #include "Visitor.h" // for Visitor
|
---|
[294647b] | 31 |
|
---|
[51b73452] | 32 |
|
---|
[df626eb] | 33 | struct ParamEntry;
|
---|
| 34 |
|
---|
| 35 | typedef std::map< UniqueId, ParamEntry > InferredParams;
|
---|
| 36 |
|
---|
| 37 | /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
|
---|
| 38 | /// but subject to decay-to-pointer and type parameter renaming
|
---|
| 39 | struct ParamEntry {
|
---|
| 40 | ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ), inferParams( new InferredParams ) {}
|
---|
| 41 | ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}
|
---|
| 42 | ParamEntry( const ParamEntry & other );
|
---|
| 43 | ~ParamEntry();
|
---|
| 44 | ParamEntry & operator=( const ParamEntry & other );
|
---|
| 45 |
|
---|
| 46 | UniqueId decl;
|
---|
| 47 | Type * actualType;
|
---|
| 48 | Type * formalType;
|
---|
| 49 | Expression * expr;
|
---|
| 50 | std::unique_ptr< InferredParams > inferParams;
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[47534159] | 53 | /// Expression is the root type for all expressions
|
---|
[df626eb] | 54 | class Expression : public BaseSyntaxNode {
|
---|
[0dd3a2f] | 55 | public:
|
---|
[65cdc1e] | 56 | Type * result;
|
---|
| 57 | TypeSubstitution * env;
|
---|
| 58 | bool extension = false;
|
---|
[df626eb] | 59 | InferredParams inferParams;
|
---|
[65cdc1e] | 60 |
|
---|
[bf4b4cf] | 61 | Expression();
|
---|
[5ded739] | 62 | Expression( const Expression & other );
|
---|
[0dd3a2f] | 63 | virtual ~Expression();
|
---|
| 64 |
|
---|
[906e24d] | 65 | Type *& get_result() { return result; }
|
---|
[fbcde64] | 66 | const Type * get_result() const { return result; }
|
---|
[5ded739] | 67 | void set_result( Type * newValue ) { result = newValue; }
|
---|
[0dd3a2f] | 68 |
|
---|
[5ded739] | 69 | TypeSubstitution * get_env() const { return env; }
|
---|
| 70 | void set_env( TypeSubstitution * newValue ) { env = newValue; }
|
---|
[e04ef3a] | 71 | bool get_extension() const { return extension; }
|
---|
[8e9cbb2] | 72 | Expression * set_extension( bool exten ) { extension = exten; return this; }
|
---|
[0dd3a2f] | 73 |
|
---|
[df626eb] | 74 | InferredParams & get_inferParams() { return inferParams; }
|
---|
| 75 |
|
---|
[fa16264] | 76 | virtual Expression * clone() const override = 0;
|
---|
| 77 | virtual void accept( Visitor & v ) override = 0;
|
---|
| 78 | virtual Expression * acceptMutator( Mutator & m ) override = 0;
|
---|
[50377a4] | 79 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 80 | };
|
---|
| 81 |
|
---|
[9706554] | 82 | /// ApplicationExpr represents the application of a function to a set of parameters. This is the result of running an
|
---|
| 83 | /// UntypedExpr through the expression analyzer.
|
---|
[0dd3a2f] | 84 | class ApplicationExpr : public Expression {
|
---|
| 85 | public:
|
---|
[65cdc1e] | 86 | Expression * function;
|
---|
[871cdb4] | 87 | std::list<Expression *> args;
|
---|
[65cdc1e] | 88 |
|
---|
[a5f0529] | 89 | ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
|
---|
[5ded739] | 90 | ApplicationExpr( const ApplicationExpr & other );
|
---|
[0dd3a2f] | 91 | virtual ~ApplicationExpr();
|
---|
| 92 |
|
---|
[5ded739] | 93 | Expression * get_function() const { return function; }
|
---|
| 94 | void set_function( Expression * newValue ) { function = newValue; }
|
---|
[0dd3a2f] | 95 | std::list<Expression *>& get_args() { return args; }
|
---|
| 96 |
|
---|
[5ded739] | 97 | virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); }
|
---|
| 98 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 99 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 100 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 101 | };
|
---|
| 102 |
|
---|
[9706554] | 103 | /// UntypedExpr represents the application of a function to a set of parameters, but where the particular overload for
|
---|
| 104 | /// the function name has not yet been determined. Most operators are converted into functional form automatically, to
|
---|
| 105 | /// permit operator overloading.
|
---|
[0dd3a2f] | 106 | class UntypedExpr : public Expression {
|
---|
| 107 | public:
|
---|
[65cdc1e] | 108 | Expression * function;
|
---|
| 109 | std::list<Expression*> args;
|
---|
| 110 |
|
---|
[bf4b4cf] | 111 | UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
|
---|
[5ded739] | 112 | UntypedExpr( const UntypedExpr & other );
|
---|
[0dd3a2f] | 113 | virtual ~UntypedExpr();
|
---|
| 114 |
|
---|
[5ded739] | 115 | Expression * get_function() const { return function; }
|
---|
| 116 | void set_function( Expression * newValue ) { function = newValue; }
|
---|
[0dd3a2f] | 117 |
|
---|
| 118 | std::list<Expression*>::iterator begin_args() { return args.begin(); }
|
---|
| 119 | std::list<Expression*>::iterator end_args() { return args.end(); }
|
---|
| 120 | std::list<Expression*>& get_args() { return args; }
|
---|
| 121 |
|
---|
[b3b2077] | 122 | static UntypedExpr * createDeref( Expression * arg );
|
---|
| 123 | static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
|
---|
| 124 |
|
---|
[5ded739] | 125 | virtual UntypedExpr * clone() const { return new UntypedExpr( * this ); }
|
---|
| 126 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 127 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 128 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 129 | };
|
---|
| 130 |
|
---|
[47534159] | 131 | /// NameExpr contains a name whose meaning is still not determined
|
---|
[0dd3a2f] | 132 | class NameExpr : public Expression {
|
---|
| 133 | public:
|
---|
[65cdc1e] | 134 | std::string name;
|
---|
| 135 |
|
---|
[bf4b4cf] | 136 | NameExpr( std::string name );
|
---|
[5ded739] | 137 | NameExpr( const NameExpr & other );
|
---|
[0dd3a2f] | 138 | virtual ~NameExpr();
|
---|
| 139 |
|
---|
[5ded739] | 140 | const std::string & get_name() const { return name; }
|
---|
[0dd3a2f] | 141 | void set_name( std::string newValue ) { name = newValue; }
|
---|
| 142 |
|
---|
[5ded739] | 143 | virtual NameExpr * clone() const { return new NameExpr( * this ); }
|
---|
| 144 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 145 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 146 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 147 | };
|
---|
| 148 |
|
---|
| 149 | // The following classes are used to represent expression types that cannot be converted into
|
---|
| 150 | // function-call format.
|
---|
| 151 |
|
---|
[5ded739] | 152 | /// AddressExpr represents a address-of expression, e.g. & e
|
---|
[0dd3a2f] | 153 | class AddressExpr : public Expression {
|
---|
| 154 | public:
|
---|
[65cdc1e] | 155 | Expression * arg;
|
---|
| 156 |
|
---|
[bf4b4cf] | 157 | AddressExpr( Expression * arg );
|
---|
[5ded739] | 158 | AddressExpr( const AddressExpr & other );
|
---|
[0dd3a2f] | 159 | virtual ~AddressExpr();
|
---|
| 160 |
|
---|
[5ded739] | 161 | Expression * get_arg() const { return arg; }
|
---|
| 162 | void set_arg(Expression * newValue ) { arg = newValue; }
|
---|
[0dd3a2f] | 163 |
|
---|
[5ded739] | 164 | virtual AddressExpr * clone() const { return new AddressExpr( * this ); }
|
---|
| 165 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 166 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 167 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 168 | };
|
---|
| 169 |
|
---|
[5809461] | 170 | // GCC &&label
|
---|
| 171 | // https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html
|
---|
[0dd3a2f] | 172 | class LabelAddressExpr : public Expression {
|
---|
| 173 | public:
|
---|
[5809461] | 174 | Label arg;
|
---|
[65cdc1e] | 175 |
|
---|
[5809461] | 176 | LabelAddressExpr( const Label &arg );
|
---|
[5ded739] | 177 | LabelAddressExpr( const LabelAddressExpr & other );
|
---|
[0dd3a2f] | 178 | virtual ~LabelAddressExpr();
|
---|
| 179 |
|
---|
[5ded739] | 180 | virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); }
|
---|
| 181 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 182 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 183 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 184 | };
|
---|
| 185 |
|
---|
[47534159] | 186 | /// CastExpr represents a type cast expression, e.g. (int)e
|
---|
[0dd3a2f] | 187 | class CastExpr : public Expression {
|
---|
| 188 | public:
|
---|
[65cdc1e] | 189 | Expression * arg;
|
---|
[c0bf94e] | 190 | bool isGenerated = true; // whether this cast appeared in the source program
|
---|
[65cdc1e] | 191 |
|
---|
[c0bf94e] | 192 | CastExpr( Expression * arg, bool isGenerated = true );
|
---|
| 193 | CastExpr( Expression * arg, Type * toType, bool isGenerated = true );
|
---|
[9a705dc8] | 194 | CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor
|
---|
[5ded739] | 195 | CastExpr( const CastExpr & other );
|
---|
[0dd3a2f] | 196 | virtual ~CastExpr();
|
---|
| 197 |
|
---|
[5ded739] | 198 | Expression * get_arg() const { return arg; }
|
---|
[a5f0529] | 199 | void set_arg( Expression * newValue ) { arg = newValue; }
|
---|
[0dd3a2f] | 200 |
|
---|
[5ded739] | 201 | virtual CastExpr * clone() const { return new CastExpr( * this ); }
|
---|
| 202 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 203 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 204 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 205 | };
|
---|
| 206 |
|
---|
[9a705dc8] | 207 | /// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t
|
---|
| 208 | class KeywordCastExpr : public Expression {
|
---|
| 209 | public:
|
---|
| 210 | Expression * arg;
|
---|
| 211 | enum Target {
|
---|
| 212 | Coroutine, Thread, Monitor, NUMBER_OF_TARGETS
|
---|
| 213 | } target;
|
---|
| 214 |
|
---|
| 215 | KeywordCastExpr( Expression * arg, Target target );
|
---|
| 216 | KeywordCastExpr( const KeywordCastExpr & other );
|
---|
| 217 | virtual ~KeywordCastExpr();
|
---|
| 218 |
|
---|
| 219 | const std::string & targetString() const;
|
---|
| 220 |
|
---|
| 221 | virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); }
|
---|
| 222 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 223 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
| 224 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
| 225 | };
|
---|
| 226 |
|
---|
[a5f0529] | 227 | /// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e
|
---|
| 228 | class VirtualCastExpr : public Expression {
|
---|
| 229 | public:
|
---|
[5ded739] | 230 | Expression * arg;
|
---|
[65cdc1e] | 231 |
|
---|
[a5f0529] | 232 | VirtualCastExpr( Expression * arg, Type * toType );
|
---|
| 233 | VirtualCastExpr( const VirtualCastExpr & other );
|
---|
| 234 | virtual ~VirtualCastExpr();
|
---|
| 235 |
|
---|
| 236 | Expression * get_arg() const { return arg; }
|
---|
| 237 | void set_arg( Expression * newValue ) { arg = newValue; }
|
---|
| 238 |
|
---|
| 239 | virtual VirtualCastExpr * clone() const { return new VirtualCastExpr( * this ); }
|
---|
| 240 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 241 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 242 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 243 | };
|
---|
| 244 |
|
---|
[47534159] | 245 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
|
---|
[0dd3a2f] | 246 | class UntypedMemberExpr : public Expression {
|
---|
| 247 | public:
|
---|
[65cdc1e] | 248 | Expression * member;
|
---|
| 249 | Expression * aggregate;
|
---|
| 250 |
|
---|
[bf4b4cf] | 251 | UntypedMemberExpr( Expression * member, Expression * aggregate );
|
---|
[5ded739] | 252 | UntypedMemberExpr( const UntypedMemberExpr & other );
|
---|
[0dd3a2f] | 253 | virtual ~UntypedMemberExpr();
|
---|
| 254 |
|
---|
[3b58d91] | 255 | Expression * get_member() const { return member; }
|
---|
| 256 | void set_member( Expression * newValue ) { member = newValue; }
|
---|
[5ded739] | 257 | Expression * get_aggregate() const { return aggregate; }
|
---|
| 258 | void set_aggregate( Expression * newValue ) { aggregate = newValue; }
|
---|
[0dd3a2f] | 259 |
|
---|
[5ded739] | 260 | virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
|
---|
| 261 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 262 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 263 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 264 | };
|
---|
| 265 |
|
---|
[4551a6e] | 266 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
|
---|
| 267 | /// Does not take ownership of member.
|
---|
[0dd3a2f] | 268 | class MemberExpr : public Expression {
|
---|
| 269 | public:
|
---|
[65cdc1e] | 270 | DeclarationWithType * member;
|
---|
| 271 | Expression * aggregate;
|
---|
| 272 |
|
---|
[bf4b4cf] | 273 | MemberExpr( DeclarationWithType * member, Expression * aggregate );
|
---|
[5ded739] | 274 | MemberExpr( const MemberExpr & other );
|
---|
[0dd3a2f] | 275 | virtual ~MemberExpr();
|
---|
| 276 |
|
---|
[5ded739] | 277 | DeclarationWithType * get_member() const { return member; }
|
---|
| 278 | void set_member( DeclarationWithType * newValue ) { member = newValue; }
|
---|
| 279 | Expression * get_aggregate() const { return aggregate; }
|
---|
| 280 | void set_aggregate( Expression * newValue ) { aggregate = newValue; }
|
---|
[0dd3a2f] | 281 |
|
---|
[5ded739] | 282 | virtual MemberExpr * clone() const { return new MemberExpr( * this ); }
|
---|
| 283 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 284 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 285 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 286 | };
|
---|
| 287 |
|
---|
[4551a6e] | 288 | /// VariableExpr represents an expression that simply refers to the value of a named variable.
|
---|
| 289 | /// Does not take ownership of var.
|
---|
[0dd3a2f] | 290 | class VariableExpr : public Expression {
|
---|
| 291 | public:
|
---|
[65cdc1e] | 292 | DeclarationWithType * var;
|
---|
| 293 |
|
---|
[bf4b4cf] | 294 | VariableExpr( DeclarationWithType * var );
|
---|
[5ded739] | 295 | VariableExpr( const VariableExpr & other );
|
---|
[0dd3a2f] | 296 | virtual ~VariableExpr();
|
---|
| 297 |
|
---|
[5ded739] | 298 | DeclarationWithType * get_var() const { return var; }
|
---|
| 299 | void set_var( DeclarationWithType * newValue ) { var = newValue; }
|
---|
[0dd3a2f] | 300 |
|
---|
[8a6cf7e] | 301 | static VariableExpr * functionPointer( FunctionDecl * decl );
|
---|
| 302 |
|
---|
[5ded739] | 303 | virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
|
---|
| 304 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 305 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 306 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 307 | };
|
---|
| 308 |
|
---|
[3be261a] | 309 | /// ConstantExpr represents an expression that simply refers to the value of a constant
|
---|
[0dd3a2f] | 310 | class ConstantExpr : public Expression {
|
---|
| 311 | public:
|
---|
[65cdc1e] | 312 | Constant constant;
|
---|
| 313 |
|
---|
[bf4b4cf] | 314 | ConstantExpr( Constant constant );
|
---|
[5ded739] | 315 | ConstantExpr( const ConstantExpr & other );
|
---|
[0dd3a2f] | 316 | virtual ~ConstantExpr();
|
---|
| 317 |
|
---|
[5ded739] | 318 | Constant * get_constant() { return & constant; }
|
---|
[ddb80bd] | 319 | const Constant * get_constant() const { return & constant; }
|
---|
[5ded739] | 320 | void set_constant( const Constant & newValue ) { constant = newValue; }
|
---|
[0dd3a2f] | 321 |
|
---|
[ddb80bd] | 322 | long long int intValue() const;
|
---|
| 323 |
|
---|
[5ded739] | 324 | virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
|
---|
| 325 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 326 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 327 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 328 | };
|
---|
| 329 |
|
---|
[47534159] | 330 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
|
---|
[0dd3a2f] | 331 | class SizeofExpr : public Expression {
|
---|
| 332 | public:
|
---|
[65cdc1e] | 333 | Expression * expr;
|
---|
| 334 | Type * type;
|
---|
| 335 | bool isType;
|
---|
| 336 |
|
---|
[bf4b4cf] | 337 | SizeofExpr( Expression * expr );
|
---|
[5ded739] | 338 | SizeofExpr( const SizeofExpr & other );
|
---|
[bf4b4cf] | 339 | SizeofExpr( Type * type );
|
---|
[0dd3a2f] | 340 | virtual ~SizeofExpr();
|
---|
| 341 |
|
---|
[5ded739] | 342 | Expression * get_expr() const { return expr; }
|
---|
| 343 | void set_expr( Expression * newValue ) { expr = newValue; }
|
---|
| 344 | Type * get_type() const { return type; }
|
---|
| 345 | void set_type( Type * newValue ) { type = newValue; }
|
---|
[0dd3a2f] | 346 | bool get_isType() const { return isType; }
|
---|
| 347 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
| 348 |
|
---|
[5ded739] | 349 | virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
|
---|
| 350 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 351 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 352 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 353 | };
|
---|
| 354 |
|
---|
[47534159] | 355 | /// AlignofExpr represents an alignof expression
|
---|
| 356 | class AlignofExpr : public Expression {
|
---|
| 357 | public:
|
---|
[65cdc1e] | 358 | Expression * expr;
|
---|
| 359 | Type * type;
|
---|
| 360 | bool isType;
|
---|
| 361 |
|
---|
[bf4b4cf] | 362 | AlignofExpr( Expression * expr );
|
---|
[5ded739] | 363 | AlignofExpr( const AlignofExpr & other );
|
---|
[bf4b4cf] | 364 | AlignofExpr( Type * type );
|
---|
[47534159] | 365 | virtual ~AlignofExpr();
|
---|
| 366 |
|
---|
[5ded739] | 367 | Expression * get_expr() const { return expr; }
|
---|
| 368 | void set_expr( Expression * newValue ) { expr = newValue; }
|
---|
| 369 | Type * get_type() const { return type; }
|
---|
| 370 | void set_type( Type * newValue ) { type = newValue; }
|
---|
[47534159] | 371 | bool get_isType() const { return isType; }
|
---|
| 372 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
| 373 |
|
---|
[5ded739] | 374 | virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
|
---|
| 375 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 376 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 377 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[47534159] | 378 | };
|
---|
| 379 |
|
---|
[2a4b088] | 380 | /// UntypedOffsetofExpr represents an offsetof expression before resolution
|
---|
| 381 | class UntypedOffsetofExpr : public Expression {
|
---|
| 382 | public:
|
---|
[65cdc1e] | 383 | Type * type;
|
---|
| 384 | std::string member;
|
---|
| 385 |
|
---|
[bf4b4cf] | 386 | UntypedOffsetofExpr( Type * type, const std::string & member );
|
---|
[5ded739] | 387 | UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
|
---|
[2a4b088] | 388 | virtual ~UntypedOffsetofExpr();
|
---|
| 389 |
|
---|
| 390 | std::string get_member() const { return member; }
|
---|
[5ded739] | 391 | void set_member( const std::string & newValue ) { member = newValue; }
|
---|
| 392 | Type * get_type() const { return type; }
|
---|
| 393 | void set_type( Type * newValue ) { type = newValue; }
|
---|
| 394 |
|
---|
| 395 | virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
|
---|
| 396 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 397 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 398 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[2a4b088] | 399 | };
|
---|
| 400 |
|
---|
[25a054f] | 401 | /// OffsetofExpr represents an offsetof expression
|
---|
| 402 | class OffsetofExpr : public Expression {
|
---|
| 403 | public:
|
---|
[65cdc1e] | 404 | Type * type;
|
---|
| 405 | DeclarationWithType * member;
|
---|
| 406 |
|
---|
[bf4b4cf] | 407 | OffsetofExpr( Type * type, DeclarationWithType * member );
|
---|
[5ded739] | 408 | OffsetofExpr( const OffsetofExpr & other );
|
---|
[25a054f] | 409 | virtual ~OffsetofExpr();
|
---|
| 410 |
|
---|
[5ded739] | 411 | Type * get_type() const { return type; }
|
---|
| 412 | void set_type( Type * newValue ) { type = newValue; }
|
---|
| 413 | DeclarationWithType * get_member() const { return member; }
|
---|
| 414 | void set_member( DeclarationWithType * newValue ) { member = newValue; }
|
---|
| 415 |
|
---|
| 416 | virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
|
---|
| 417 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 418 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 419 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[25a054f] | 420 | };
|
---|
| 421 |
|
---|
[afc1045] | 422 | /// Expression representing a pack of field-offsets for a generic type
|
---|
| 423 | class OffsetPackExpr : public Expression {
|
---|
| 424 | public:
|
---|
[65cdc1e] | 425 | StructInstType * type;
|
---|
| 426 |
|
---|
[bf4b4cf] | 427 | OffsetPackExpr( StructInstType * type );
|
---|
[5ded739] | 428 | OffsetPackExpr( const OffsetPackExpr & other );
|
---|
[afc1045] | 429 | virtual ~OffsetPackExpr();
|
---|
| 430 |
|
---|
[5ded739] | 431 | StructInstType * get_type() const { return type; }
|
---|
| 432 | void set_type( StructInstType * newValue ) { type = newValue; }
|
---|
[afc1045] | 433 |
|
---|
[5ded739] | 434 | virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
|
---|
| 435 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 436 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 437 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[afc1045] | 438 | };
|
---|
| 439 |
|
---|
[47534159] | 440 | /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
|
---|
[0dd3a2f] | 441 | class AttrExpr : public Expression {
|
---|
| 442 | public:
|
---|
[65cdc1e] | 443 | Expression * attr;
|
---|
| 444 | Expression * expr;
|
---|
| 445 | Type * type;
|
---|
| 446 | bool isType;
|
---|
| 447 |
|
---|
[bf4b4cf] | 448 | AttrExpr(Expression * attr, Expression * expr );
|
---|
[5ded739] | 449 | AttrExpr( const AttrExpr & other );
|
---|
[bf4b4cf] | 450 | AttrExpr( Expression * attr, Type * type );
|
---|
[0dd3a2f] | 451 | virtual ~AttrExpr();
|
---|
| 452 |
|
---|
[5ded739] | 453 | Expression * get_attr() const { return attr; }
|
---|
| 454 | void set_attr( Expression * newValue ) { attr = newValue; }
|
---|
| 455 | Expression * get_expr() const { return expr; }
|
---|
| 456 | void set_expr( Expression * newValue ) { expr = newValue; }
|
---|
| 457 | Type * get_type() const { return type; }
|
---|
| 458 | void set_type( Type * newValue ) { type = newValue; }
|
---|
[0dd3a2f] | 459 | bool get_isType() const { return isType; }
|
---|
| 460 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
| 461 |
|
---|
[5ded739] | 462 | virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
|
---|
| 463 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 464 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 465 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 466 | };
|
---|
| 467 |
|
---|
[47534159] | 468 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
|
---|
[0dd3a2f] | 469 | class LogicalExpr : public Expression {
|
---|
| 470 | public:
|
---|
[65cdc1e] | 471 | Expression * arg1;
|
---|
| 472 | Expression * arg2;
|
---|
| 473 |
|
---|
[bf4b4cf] | 474 | LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
|
---|
[5ded739] | 475 | LogicalExpr( const LogicalExpr & other );
|
---|
[0dd3a2f] | 476 | virtual ~LogicalExpr();
|
---|
| 477 |
|
---|
| 478 | bool get_isAnd() const { return isAnd; }
|
---|
[5ded739] | 479 | Expression * get_arg1() { return arg1; }
|
---|
| 480 | void set_arg1( Expression * newValue ) { arg1 = newValue; }
|
---|
| 481 | Expression * get_arg2() const { return arg2; }
|
---|
| 482 | void set_arg2( Expression * newValue ) { arg2 = newValue; }
|
---|
| 483 |
|
---|
| 484 | virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); }
|
---|
| 485 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 486 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 487 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[65cdc1e] | 488 |
|
---|
[0dd3a2f] | 489 | private:
|
---|
| 490 | bool isAnd;
|
---|
[51b73452] | 491 | };
|
---|
| 492 |
|
---|
[47534159] | 493 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
|
---|
[0dd3a2f] | 494 | class ConditionalExpr : public Expression {
|
---|
| 495 | public:
|
---|
[65cdc1e] | 496 | Expression * arg1;
|
---|
| 497 | Expression * arg2;
|
---|
| 498 | Expression * arg3;
|
---|
| 499 |
|
---|
[bf4b4cf] | 500 | ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
|
---|
[5ded739] | 501 | ConditionalExpr( const ConditionalExpr & other );
|
---|
[0dd3a2f] | 502 | virtual ~ConditionalExpr();
|
---|
| 503 |
|
---|
[5ded739] | 504 | Expression * get_arg1() const { return arg1; }
|
---|
| 505 | void set_arg1( Expression * newValue ) { arg1 = newValue; }
|
---|
| 506 | Expression * get_arg2() const { return arg2; }
|
---|
| 507 | void set_arg2( Expression * newValue ) { arg2 = newValue; }
|
---|
| 508 | Expression * get_arg3() const { return arg3; }
|
---|
| 509 | void set_arg3( Expression * newValue ) { arg3 = newValue; }
|
---|
| 510 |
|
---|
| 511 | virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
|
---|
| 512 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 513 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 514 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 515 | };
|
---|
| 516 |
|
---|
[47534159] | 517 | /// CommaExpr represents the sequence operator ( a, b )
|
---|
[0dd3a2f] | 518 | class CommaExpr : public Expression {
|
---|
| 519 | public:
|
---|
[65cdc1e] | 520 | Expression * arg1;
|
---|
| 521 | Expression * arg2;
|
---|
| 522 |
|
---|
[bf4b4cf] | 523 | CommaExpr( Expression * arg1, Expression * arg2 );
|
---|
[5ded739] | 524 | CommaExpr( const CommaExpr & other );
|
---|
[0dd3a2f] | 525 | virtual ~CommaExpr();
|
---|
| 526 |
|
---|
[5ded739] | 527 | Expression * get_arg1() const { return arg1; }
|
---|
| 528 | void set_arg1( Expression * newValue ) { arg1 = newValue; }
|
---|
| 529 | Expression * get_arg2() const { return arg2; }
|
---|
| 530 | void set_arg2( Expression * newValue ) { arg2 = newValue; }
|
---|
[0dd3a2f] | 531 |
|
---|
[5ded739] | 532 | virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
|
---|
| 533 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 534 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 535 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 536 | };
|
---|
| 537 |
|
---|
[47534159] | 538 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
|
---|
[0dd3a2f] | 539 | class TypeExpr : public Expression {
|
---|
| 540 | public:
|
---|
[65cdc1e] | 541 | Type * type;
|
---|
| 542 |
|
---|
[5ded739] | 543 | TypeExpr( Type * type );
|
---|
| 544 | TypeExpr( const TypeExpr & other );
|
---|
[0dd3a2f] | 545 | virtual ~TypeExpr();
|
---|
| 546 |
|
---|
[5ded739] | 547 | Type * get_type() const { return type; }
|
---|
| 548 | void set_type( Type * newValue ) { type = newValue; }
|
---|
[0dd3a2f] | 549 |
|
---|
[5ded739] | 550 | virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
|
---|
| 551 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 552 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 553 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 554 | };
|
---|
| 555 |
|
---|
[47534159] | 556 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
|
---|
[7f5566b] | 557 | class AsmExpr : public Expression {
|
---|
| 558 | public:
|
---|
[65cdc1e] | 559 | Expression * inout;
|
---|
[e612146c] | 560 | Expression * constraint;
|
---|
[65cdc1e] | 561 | Expression * operand;
|
---|
| 562 |
|
---|
[e612146c] | 563 | AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
|
---|
[3be261a] | 564 | AsmExpr( const AsmExpr & other );
|
---|
[7f5566b] | 565 | virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
|
---|
| 566 |
|
---|
[5ded739] | 567 | Expression * get_inout() const { return inout; }
|
---|
| 568 | void set_inout( Expression * newValue ) { inout = newValue; }
|
---|
[7f5566b] | 569 |
|
---|
[e612146c] | 570 | Expression * get_constraint() const { return constraint; }
|
---|
| 571 | void set_constraint( Expression * newValue ) { constraint = newValue; }
|
---|
[7f5566b] | 572 |
|
---|
[5ded739] | 573 | Expression * get_operand() const { return operand; }
|
---|
| 574 | void set_operand( Expression * newValue ) { operand = newValue; }
|
---|
[7f5566b] | 575 |
|
---|
[5ded739] | 576 | virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
|
---|
| 577 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 578 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 579 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[65cdc1e] | 580 |
|
---|
[7f5566b] | 581 | // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
|
---|
| 582 | };
|
---|
| 583 |
|
---|
[db4ecc5] | 584 | /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
|
---|
| 585 | /// along with a set of copy constructor calls, one for each argument.
|
---|
| 586 | class ImplicitCopyCtorExpr : public Expression {
|
---|
| 587 | public:
|
---|
[65cdc1e] | 588 | ApplicationExpr * callExpr;
|
---|
| 589 | std::list< ObjectDecl * > tempDecls;
|
---|
| 590 | std::list< ObjectDecl * > returnDecls;
|
---|
| 591 | std::list< Expression * > dtors;
|
---|
| 592 |
|
---|
[db4ecc5] | 593 | ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
|
---|
| 594 | ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
|
---|
| 595 | virtual ~ImplicitCopyCtorExpr();
|
---|
| 596 |
|
---|
[5ded739] | 597 | ApplicationExpr * get_callExpr() const { return callExpr; }
|
---|
| 598 | void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
|
---|
[db4ecc5] | 599 |
|
---|
| 600 | std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
|
---|
| 601 | std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
|
---|
| 602 | std::list< Expression * > & get_dtors() { return dtors; }
|
---|
| 603 |
|
---|
[5ded739] | 604 | virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
|
---|
| 605 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 606 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 607 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[db4ecc5] | 608 | };
|
---|
| 609 |
|
---|
[b6fe7e6] | 610 | /// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
|
---|
| 611 | class ConstructorExpr : public Expression {
|
---|
| 612 | public:
|
---|
[65cdc1e] | 613 | Expression * callExpr;
|
---|
| 614 |
|
---|
[b6fe7e6] | 615 | ConstructorExpr( Expression * callExpr );
|
---|
| 616 | ConstructorExpr( const ConstructorExpr & other );
|
---|
| 617 | ~ConstructorExpr();
|
---|
[0dd3a2f] | 618 |
|
---|
[5ded739] | 619 | Expression * get_callExpr() const { return callExpr; }
|
---|
| 620 | void set_callExpr( Expression * newValue ) { callExpr = newValue; }
|
---|
[0dd3a2f] | 621 |
|
---|
[5ded739] | 622 | virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
|
---|
| 623 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 624 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 625 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[51b73452] | 626 | };
|
---|
| 627 |
|
---|
[630a82a] | 628 | /// CompoundLiteralExpr represents a C99 'compound literal'
|
---|
| 629 | class CompoundLiteralExpr : public Expression {
|
---|
| 630 | public:
|
---|
[65cdc1e] | 631 | Initializer * initializer;
|
---|
| 632 |
|
---|
[630a82a] | 633 | CompoundLiteralExpr( Type * type, Initializer * initializer );
|
---|
[5ded739] | 634 | CompoundLiteralExpr( const CompoundLiteralExpr & other );
|
---|
[3b58d91] | 635 | virtual ~CompoundLiteralExpr();
|
---|
[630a82a] | 636 |
|
---|
| 637 | Initializer * get_initializer() const { return initializer; }
|
---|
| 638 | void set_initializer( Initializer * i ) { initializer = i; }
|
---|
| 639 |
|
---|
[5ded739] | 640 | virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
|
---|
| 641 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 642 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 643 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[630a82a] | 644 | };
|
---|
| 645 |
|
---|
[b6fe7e6] | 646 | /// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
|
---|
[8688ce1] | 647 | class RangeExpr : public Expression {
|
---|
| 648 | public:
|
---|
[65cdc1e] | 649 | Expression * low, * high;
|
---|
| 650 |
|
---|
[5ded739] | 651 | RangeExpr( Expression * low, Expression * high );
|
---|
| 652 | RangeExpr( const RangeExpr & other );
|
---|
[8688ce1] | 653 |
|
---|
[d9e2280] | 654 | Expression * get_low() const { return low; }
|
---|
| 655 | Expression * get_high() const { return high; }
|
---|
[5ded739] | 656 | RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
|
---|
| 657 | RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
|
---|
[8688ce1] | 658 |
|
---|
[5ded739] | 659 | virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
|
---|
| 660 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 661 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 662 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[8688ce1] | 663 | };
|
---|
| 664 |
|
---|
[907eccb] | 665 | /// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
|
---|
| 666 | class UntypedTupleExpr : public Expression {
|
---|
| 667 | public:
|
---|
[65cdc1e] | 668 | std::list<Expression*> exprs;
|
---|
| 669 |
|
---|
[bf4b4cf] | 670 | UntypedTupleExpr( const std::list< Expression * > & exprs );
|
---|
[5ded739] | 671 | UntypedTupleExpr( const UntypedTupleExpr & other );
|
---|
[907eccb] | 672 | virtual ~UntypedTupleExpr();
|
---|
| 673 |
|
---|
| 674 | std::list<Expression*>& get_exprs() { return exprs; }
|
---|
| 675 |
|
---|
[5ded739] | 676 | virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); }
|
---|
| 677 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 678 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 679 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[907eccb] | 680 | };
|
---|
| 681 |
|
---|
[6eb8948] | 682 | /// TupleExpr represents a tuple expression ( [a, b, c] )
|
---|
| 683 | class TupleExpr : public Expression {
|
---|
| 684 | public:
|
---|
[65cdc1e] | 685 | std::list<Expression*> exprs;
|
---|
| 686 |
|
---|
[bf4b4cf] | 687 | TupleExpr( const std::list< Expression * > & exprs );
|
---|
[5ded739] | 688 | TupleExpr( const TupleExpr & other );
|
---|
[6eb8948] | 689 | virtual ~TupleExpr();
|
---|
| 690 |
|
---|
| 691 | std::list<Expression*>& get_exprs() { return exprs; }
|
---|
| 692 |
|
---|
[5ded739] | 693 | virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
|
---|
| 694 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 695 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 696 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[6eb8948] | 697 | };
|
---|
| 698 |
|
---|
[3b58d91] | 699 | /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
|
---|
| 700 | class TupleIndexExpr : public Expression {
|
---|
| 701 | public:
|
---|
[65cdc1e] | 702 | Expression * tuple;
|
---|
| 703 | unsigned int index;
|
---|
| 704 |
|
---|
[3b58d91] | 705 | TupleIndexExpr( Expression * tuple, unsigned int index );
|
---|
[5ded739] | 706 | TupleIndexExpr( const TupleIndexExpr & other );
|
---|
[3b58d91] | 707 | virtual ~TupleIndexExpr();
|
---|
| 708 |
|
---|
| 709 | Expression * get_tuple() const { return tuple; }
|
---|
| 710 | int get_index() const { return index; }
|
---|
[5ded739] | 711 | TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
|
---|
[3b58d91] | 712 | TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
|
---|
| 713 |
|
---|
[5ded739] | 714 | virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
|
---|
| 715 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 716 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 717 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[3b58d91] | 718 | };
|
---|
| 719 |
|
---|
[65660bd] | 720 | /// 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
|
---|
[6eb8948] | 721 | class TupleAssignExpr : public Expression {
|
---|
[3b58d91] | 722 | public:
|
---|
[65cdc1e] | 723 | StmtExpr * stmtExpr = nullptr;
|
---|
| 724 |
|
---|
[bf4b4cf] | 725 | TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
|
---|
[5ded739] | 726 | TupleAssignExpr( const TupleAssignExpr & other );
|
---|
[6eb8948] | 727 | virtual ~TupleAssignExpr();
|
---|
[3b58d91] | 728 |
|
---|
[d5556a3] | 729 | TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
|
---|
| 730 | StmtExpr * get_stmtExpr() const { return stmtExpr; }
|
---|
[3b58d91] | 731 |
|
---|
[5ded739] | 732 | virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
|
---|
| 733 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 734 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 735 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[3b58d91] | 736 | };
|
---|
| 737 |
|
---|
[6eb8948] | 738 | /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
|
---|
| 739 | class StmtExpr : public Expression {
|
---|
| 740 | public:
|
---|
[65cdc1e] | 741 | CompoundStmt * statements;
|
---|
| 742 | std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
|
---|
| 743 | std::list< Expression * > dtors; // destructor(s) for return variable(s)
|
---|
| 744 |
|
---|
[5ded739] | 745 | StmtExpr( CompoundStmt * statements );
|
---|
[6eb8948] | 746 | StmtExpr( const StmtExpr & other );
|
---|
| 747 | virtual ~StmtExpr();
|
---|
[3b58d91] | 748 |
|
---|
[6eb8948] | 749 | CompoundStmt * get_statements() const { return statements; }
|
---|
| 750 | StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
|
---|
[3b58d91] | 751 |
|
---|
[5e2c348] | 752 | // call to set the result type of this StmtExpr based on its body
|
---|
| 753 | void computeResult();
|
---|
| 754 |
|
---|
[d5556a3] | 755 | std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
|
---|
| 756 | std::list< Expression * > & get_dtors() { return dtors; }
|
---|
| 757 |
|
---|
[5ded739] | 758 | virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
|
---|
| 759 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 760 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 761 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[3b58d91] | 762 | };
|
---|
| 763 |
|
---|
[3c13c03] | 764 | class UniqueExpr : public Expression {
|
---|
| 765 | public:
|
---|
[65cdc1e] | 766 | Expression * expr;
|
---|
| 767 | ObjectDecl * object;
|
---|
| 768 | VariableExpr * var;
|
---|
| 769 |
|
---|
[bf32bb8] | 770 | UniqueExpr( Expression * expr, long long idVal = -1 );
|
---|
[3c13c03] | 771 | UniqueExpr( const UniqueExpr & other );
|
---|
| 772 | ~UniqueExpr();
|
---|
| 773 |
|
---|
[141b786] | 774 | Expression * get_expr() const { return expr; }
|
---|
| 775 | UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
|
---|
[3c13c03] | 776 |
|
---|
[141b786] | 777 | ObjectDecl * get_object() const { return object; }
|
---|
| 778 | UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
|
---|
| 779 |
|
---|
| 780 | VariableExpr * get_var() const { return var; }
|
---|
| 781 | UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
|
---|
[77971f6] | 782 |
|
---|
[bf32bb8] | 783 | int get_id() const { return id; }
|
---|
| 784 |
|
---|
[5ded739] | 785 | virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
|
---|
| 786 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 787 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 788 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[65cdc1e] | 789 |
|
---|
[3c13c03] | 790 | private:
|
---|
[bf32bb8] | 791 | int id;
|
---|
| 792 | static long long count;
|
---|
[3c13c03] | 793 | };
|
---|
| 794 |
|
---|
[e4d829b] | 795 | struct InitAlternative {
|
---|
| 796 | public:
|
---|
| 797 | Type * type = nullptr;
|
---|
| 798 | Designation * designation = nullptr;
|
---|
| 799 | InitAlternative( Type * type, Designation * designation );
|
---|
| 800 | InitAlternative( const InitAlternative & other );
|
---|
| 801 | InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
|
---|
| 802 | ~InitAlternative();
|
---|
| 803 | };
|
---|
| 804 |
|
---|
| 805 | class UntypedInitExpr : public Expression {
|
---|
| 806 | public:
|
---|
[65cdc1e] | 807 | Expression * expr;
|
---|
| 808 | std::list<InitAlternative> initAlts;
|
---|
| 809 |
|
---|
[e4d829b] | 810 | UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
|
---|
| 811 | UntypedInitExpr( const UntypedInitExpr & other );
|
---|
| 812 | ~UntypedInitExpr();
|
---|
| 813 |
|
---|
| 814 | Expression * get_expr() const { return expr; }
|
---|
| 815 | UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
|
---|
| 816 |
|
---|
| 817 | std::list<InitAlternative> & get_initAlts() { return initAlts; }
|
---|
| 818 |
|
---|
| 819 | virtual UntypedInitExpr * clone() const { return new UntypedInitExpr( * this ); }
|
---|
| 820 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 821 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 822 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[e4d829b] | 823 | };
|
---|
| 824 |
|
---|
| 825 | class InitExpr : public Expression {
|
---|
| 826 | public:
|
---|
[65cdc1e] | 827 | Expression * expr;
|
---|
| 828 | Designation * designation;
|
---|
| 829 |
|
---|
[62423350] | 830 | InitExpr( Expression * expr, Designation * designation );
|
---|
[e4d829b] | 831 | InitExpr( const InitExpr & other );
|
---|
| 832 | ~InitExpr();
|
---|
| 833 |
|
---|
| 834 | Expression * get_expr() const { return expr; }
|
---|
| 835 | InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
|
---|
| 836 |
|
---|
| 837 | Designation * get_designation() const { return designation; }
|
---|
| 838 | InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
|
---|
| 839 |
|
---|
| 840 | virtual InitExpr * clone() const { return new InitExpr( * this ); }
|
---|
| 841 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 842 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
[50377a4] | 843 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
[e4d829b] | 844 | };
|
---|
| 845 |
|
---|
[44b4114] | 846 | /// expression that contains a deleted identifier - should never make it past the resolver.
|
---|
| 847 | class DeletedExpr : public Expression {
|
---|
| 848 | public:
|
---|
| 849 | Expression * expr;
|
---|
| 850 | BaseSyntaxNode * deleteStmt;
|
---|
| 851 |
|
---|
| 852 | DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt );
|
---|
| 853 | DeletedExpr( const DeletedExpr & other );
|
---|
| 854 | ~DeletedExpr();
|
---|
| 855 |
|
---|
| 856 | virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); }
|
---|
| 857 | virtual void accept( Visitor & v ) { v.visit( this ); }
|
---|
| 858 | virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
|
---|
| 859 | virtual void print( std::ostream & os, Indenter indent = {} ) const;
|
---|
| 860 | };
|
---|
| 861 |
|
---|
[0dd3a2f] | 862 | // Local Variables: //
|
---|
| 863 | // tab-width: 4 //
|
---|
| 864 | // mode: c++ //
|
---|
| 865 | // compile-command: "make install" //
|
---|
| 866 | // End: //
|
---|