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