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