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