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