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