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