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