[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 |
|
---|
[bbf17d5] | 165 | // [Qualifier].name; Qualifier is the type_name from the parser
|
---|
| 166 | class QualifiedNameExpr : public Expression {
|
---|
| 167 | public:
|
---|
[b0d9ff7] | 168 | Declaration * type_decl;
|
---|
| 169 | std::string name;
|
---|
[bbf17d5] | 170 |
|
---|
[b0d9ff7] | 171 | QualifiedNameExpr( Declaration * decl, std::string name): Expression(), type_decl(decl), name(name) {}
|
---|
[5408b59] | 172 | QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name) {}
|
---|
[bbf17d5] | 173 |
|
---|
| 174 | virtual ~QualifiedNameExpr() {
|
---|
[b0d9ff7] | 175 | delete type_decl;
|
---|
[bbf17d5] | 176 | }
|
---|
| 177 |
|
---|
| 178 | virtual QualifiedNameExpr * clone() const override {
|
---|
| 179 | return new QualifiedNameExpr( * this );
|
---|
| 180 | }
|
---|
[b0d9ff7] | 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 {
|
---|
| 184 | return m.mutate( this );
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[bbf17d5] | 187 | virtual void print( std::ostream & os, Indenter indent = {} ) const override {
|
---|
[b0d9ff7] | 188 | type_decl->print( os, indent );
|
---|
| 189 | os << name << std::endl;
|
---|
[bbf17d5] | 190 | }
|
---|
| 191 | };
|
---|
| 192 |
|
---|
[d5631b3] | 193 | /// VariableExpr represents an expression that simply refers to the value of a named variable.
|
---|
| 194 | /// Does not take ownership of var.
|
---|
| 195 | class VariableExpr : public Expression {
|
---|
| 196 | public:
|
---|
| 197 | DeclarationWithType * var;
|
---|
| 198 |
|
---|
| 199 | VariableExpr();
|
---|
| 200 | VariableExpr( DeclarationWithType * var );
|
---|
| 201 | VariableExpr( const VariableExpr & other );
|
---|
| 202 | virtual ~VariableExpr();
|
---|
| 203 |
|
---|
| 204 | bool get_lvalue() const final;
|
---|
| 205 |
|
---|
| 206 | DeclarationWithType * get_var() const { return var; }
|
---|
| 207 | void set_var( DeclarationWithType * newValue ) { var = newValue; }
|
---|
| 208 |
|
---|
| 209 | static VariableExpr * functionPointer( FunctionDecl * decl );
|
---|
| 210 |
|
---|
| 211 | virtual VariableExpr * clone() const override { return new VariableExpr( * this ); }
|
---|
| 212 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 213 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 214 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 215 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
| 216 | };
|
---|
| 217 |
|
---|
[51b73452] | 218 | // The following classes are used to represent expression types that cannot be converted into
|
---|
| 219 | // function-call format.
|
---|
| 220 |
|
---|
[5ded739] | 221 | /// AddressExpr represents a address-of expression, e.g. & e
|
---|
[0dd3a2f] | 222 | class AddressExpr : public Expression {
|
---|
| 223 | public:
|
---|
[65cdc1e] | 224 | Expression * arg;
|
---|
| 225 |
|
---|
[bf4b4cf] | 226 | AddressExpr( Expression * arg );
|
---|
[5ded739] | 227 | AddressExpr( const AddressExpr & other );
|
---|
[0dd3a2f] | 228 | virtual ~AddressExpr();
|
---|
| 229 |
|
---|
[5ded739] | 230 | Expression * get_arg() const { return arg; }
|
---|
| 231 | void set_arg(Expression * newValue ) { arg = newValue; }
|
---|
[0dd3a2f] | 232 |
|
---|
[7870799] | 233 | virtual AddressExpr * clone() const override { return new AddressExpr( * this ); }
|
---|
| 234 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 235 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 236 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 237 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 238 | };
|
---|
| 239 |
|
---|
[5809461] | 240 | // GCC &&label
|
---|
| 241 | // https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html
|
---|
[0dd3a2f] | 242 | class LabelAddressExpr : public Expression {
|
---|
| 243 | public:
|
---|
[5809461] | 244 | Label arg;
|
---|
[65cdc1e] | 245 |
|
---|
[5809461] | 246 | LabelAddressExpr( const Label &arg );
|
---|
[5ded739] | 247 | LabelAddressExpr( const LabelAddressExpr & other );
|
---|
[0dd3a2f] | 248 | virtual ~LabelAddressExpr();
|
---|
| 249 |
|
---|
[7870799] | 250 | virtual LabelAddressExpr * clone() const override { return new LabelAddressExpr( * this ); }
|
---|
| 251 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 252 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 253 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 254 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 255 | };
|
---|
| 256 |
|
---|
[47534159] | 257 | /// CastExpr represents a type cast expression, e.g. (int)e
|
---|
[0dd3a2f] | 258 | class CastExpr : public Expression {
|
---|
| 259 | public:
|
---|
[65cdc1e] | 260 | Expression * arg;
|
---|
[b81fd95] | 261 |
|
---|
| 262 | // Inidicates cast is introduced by the CFA type system.
|
---|
| 263 | // true for casts that the resolver introduces to force a return type
|
---|
| 264 | // false for casts from user code
|
---|
| 265 | // false for casts from desugaring advanced CFA features into simpler CFA
|
---|
| 266 | // example
|
---|
| 267 | // int * p; // declaration
|
---|
| 268 | // (float *) p; // use, with subject cast
|
---|
| 269 | // subject cast isGenerated means we are considering an interpretation with a type mismatch
|
---|
| 270 | // subject cast not isGenerated means someone in charge wants it that way
|
---|
| 271 | bool isGenerated = true;
|
---|
[65cdc1e] | 272 |
|
---|
[c0bf94e] | 273 | CastExpr( Expression * arg, bool isGenerated = true );
|
---|
| 274 | CastExpr( Expression * arg, Type * toType, bool isGenerated = true );
|
---|
[9a705dc8] | 275 | CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor
|
---|
[5ded739] | 276 | CastExpr( const CastExpr & other );
|
---|
[0dd3a2f] | 277 | virtual ~CastExpr();
|
---|
| 278 |
|
---|
[14388c1] | 279 | bool get_lvalue() const final;
|
---|
| 280 |
|
---|
[5ded739] | 281 | Expression * get_arg() const { return arg; }
|
---|
[a5f0529] | 282 | void set_arg( Expression * newValue ) { arg = newValue; }
|
---|
[0dd3a2f] | 283 |
|
---|
[7870799] | 284 | virtual CastExpr * clone() const override { return new CastExpr( * this ); }
|
---|
| 285 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 286 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 287 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 288 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 289 | };
|
---|
| 290 |
|
---|
[9a705dc8] | 291 | /// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t
|
---|
| 292 | class KeywordCastExpr : public Expression {
|
---|
| 293 | public:
|
---|
| 294 | Expression * arg;
|
---|
[3b0c8cb] | 295 | struct Concrete {
|
---|
| 296 | std::string field;
|
---|
| 297 | std::string getter;
|
---|
| 298 | };
|
---|
[312029a] | 299 | AggregateDecl::Aggregate target;
|
---|
[3b0c8cb] | 300 | Concrete concrete_target;
|
---|
[9a705dc8] | 301 |
|
---|
[312029a] | 302 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target );
|
---|
[4ef08f7] | 303 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target, const Concrete & concrete_target );
|
---|
[9a705dc8] | 304 | KeywordCastExpr( const KeywordCastExpr & other );
|
---|
| 305 | virtual ~KeywordCastExpr();
|
---|
| 306 |
|
---|
[312029a] | 307 | const char * targetString() const;
|
---|
[9a705dc8] | 308 |
|
---|
[7870799] | 309 | virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); }
|
---|
| 310 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 311 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 312 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 313 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[9a705dc8] | 314 | };
|
---|
| 315 |
|
---|
[a5f0529] | 316 | /// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e
|
---|
| 317 | class VirtualCastExpr : public Expression {
|
---|
| 318 | public:
|
---|
[5ded739] | 319 | Expression * arg;
|
---|
[65cdc1e] | 320 |
|
---|
[a5f0529] | 321 | VirtualCastExpr( Expression * arg, Type * toType );
|
---|
| 322 | VirtualCastExpr( const VirtualCastExpr & other );
|
---|
| 323 | virtual ~VirtualCastExpr();
|
---|
| 324 |
|
---|
| 325 | Expression * get_arg() const { return arg; }
|
---|
| 326 | void set_arg( Expression * newValue ) { arg = newValue; }
|
---|
| 327 |
|
---|
[7870799] | 328 | virtual VirtualCastExpr * clone() const override { return new VirtualCastExpr( * this ); }
|
---|
| 329 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 330 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 331 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 332 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 333 | };
|
---|
| 334 |
|
---|
[47534159] | 335 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
|
---|
[0dd3a2f] | 336 | class UntypedMemberExpr : public Expression {
|
---|
| 337 | public:
|
---|
[65cdc1e] | 338 | Expression * member;
|
---|
| 339 | Expression * aggregate;
|
---|
| 340 |
|
---|
[bf4b4cf] | 341 | UntypedMemberExpr( Expression * member, Expression * aggregate );
|
---|
[5ded739] | 342 | UntypedMemberExpr( const UntypedMemberExpr & other );
|
---|
[0dd3a2f] | 343 | virtual ~UntypedMemberExpr();
|
---|
| 344 |
|
---|
[849720f] | 345 | bool get_lvalue() const final;
|
---|
| 346 |
|
---|
[3b58d91] | 347 | Expression * get_member() const { return member; }
|
---|
| 348 | void set_member( Expression * newValue ) { member = newValue; }
|
---|
[5ded739] | 349 | Expression * get_aggregate() const { return aggregate; }
|
---|
| 350 | void set_aggregate( Expression * newValue ) { aggregate = newValue; }
|
---|
[0dd3a2f] | 351 |
|
---|
[7870799] | 352 | virtual UntypedMemberExpr * clone() const override { return new UntypedMemberExpr( * this ); }
|
---|
| 353 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 354 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 355 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 356 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 357 | };
|
---|
| 358 |
|
---|
[4551a6e] | 359 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
|
---|
| 360 | /// Does not take ownership of member.
|
---|
[0dd3a2f] | 361 | class MemberExpr : public Expression {
|
---|
| 362 | public:
|
---|
[65cdc1e] | 363 | DeclarationWithType * member;
|
---|
| 364 | Expression * aggregate;
|
---|
| 365 |
|
---|
[bf4b4cf] | 366 | MemberExpr( DeclarationWithType * member, Expression * aggregate );
|
---|
[5ded739] | 367 | MemberExpr( const MemberExpr & other );
|
---|
[0dd3a2f] | 368 | virtual ~MemberExpr();
|
---|
| 369 |
|
---|
[14388c1] | 370 | bool get_lvalue() const final;
|
---|
| 371 |
|
---|
[5ded739] | 372 | DeclarationWithType * get_member() const { return member; }
|
---|
| 373 | void set_member( DeclarationWithType * newValue ) { member = newValue; }
|
---|
| 374 | Expression * get_aggregate() const { return aggregate; }
|
---|
| 375 | void set_aggregate( Expression * newValue ) { aggregate = newValue; }
|
---|
[0dd3a2f] | 376 |
|
---|
[7870799] | 377 | virtual MemberExpr * clone() const override { return new MemberExpr( * this ); }
|
---|
| 378 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 379 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 380 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 381 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 382 | };
|
---|
| 383 |
|
---|
[3be261a] | 384 | /// ConstantExpr represents an expression that simply refers to the value of a constant
|
---|
[0dd3a2f] | 385 | class ConstantExpr : public Expression {
|
---|
| 386 | public:
|
---|
[65cdc1e] | 387 | Constant constant;
|
---|
| 388 |
|
---|
[bf4b4cf] | 389 | ConstantExpr( Constant constant );
|
---|
[5ded739] | 390 | ConstantExpr( const ConstantExpr & other );
|
---|
[0dd3a2f] | 391 | virtual ~ConstantExpr();
|
---|
| 392 |
|
---|
[5ded739] | 393 | Constant * get_constant() { return & constant; }
|
---|
[ddb80bd] | 394 | const Constant * get_constant() const { return & constant; }
|
---|
[5ded739] | 395 | void set_constant( const Constant & newValue ) { constant = newValue; }
|
---|
[0dd3a2f] | 396 |
|
---|
[ddb80bd] | 397 | long long int intValue() const;
|
---|
| 398 |
|
---|
[7870799] | 399 | virtual ConstantExpr * clone() const override { return new ConstantExpr( * this ); }
|
---|
| 400 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 401 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 402 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 403 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 404 | };
|
---|
| 405 |
|
---|
[47534159] | 406 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
|
---|
[0dd3a2f] | 407 | class SizeofExpr : public Expression {
|
---|
| 408 | public:
|
---|
[65cdc1e] | 409 | Expression * expr;
|
---|
| 410 | Type * type;
|
---|
| 411 | bool isType;
|
---|
| 412 |
|
---|
[bf4b4cf] | 413 | SizeofExpr( Expression * expr );
|
---|
[5ded739] | 414 | SizeofExpr( const SizeofExpr & other );
|
---|
[bf4b4cf] | 415 | SizeofExpr( Type * type );
|
---|
[0dd3a2f] | 416 | virtual ~SizeofExpr();
|
---|
| 417 |
|
---|
[5ded739] | 418 | Expression * get_expr() const { return expr; }
|
---|
| 419 | void set_expr( Expression * newValue ) { expr = newValue; }
|
---|
| 420 | Type * get_type() const { return type; }
|
---|
| 421 | void set_type( Type * newValue ) { type = newValue; }
|
---|
[0dd3a2f] | 422 | bool get_isType() const { return isType; }
|
---|
| 423 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
| 424 |
|
---|
[7870799] | 425 | virtual SizeofExpr * clone() const override { return new SizeofExpr( * this ); }
|
---|
| 426 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 427 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 428 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 429 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 430 | };
|
---|
| 431 |
|
---|
[47534159] | 432 | /// AlignofExpr represents an alignof expression
|
---|
| 433 | class AlignofExpr : public Expression {
|
---|
| 434 | public:
|
---|
[65cdc1e] | 435 | Expression * expr;
|
---|
| 436 | Type * type;
|
---|
| 437 | bool isType;
|
---|
| 438 |
|
---|
[bf4b4cf] | 439 | AlignofExpr( Expression * expr );
|
---|
[5ded739] | 440 | AlignofExpr( const AlignofExpr & other );
|
---|
[bf4b4cf] | 441 | AlignofExpr( Type * type );
|
---|
[47534159] | 442 | virtual ~AlignofExpr();
|
---|
| 443 |
|
---|
[5ded739] | 444 | Expression * get_expr() const { return expr; }
|
---|
| 445 | void set_expr( Expression * newValue ) { expr = newValue; }
|
---|
| 446 | Type * get_type() const { return type; }
|
---|
| 447 | void set_type( Type * newValue ) { type = newValue; }
|
---|
[47534159] | 448 | bool get_isType() const { return isType; }
|
---|
| 449 | void set_isType( bool newValue ) { isType = newValue; }
|
---|
| 450 |
|
---|
[7870799] | 451 | virtual AlignofExpr * clone() const override { return new AlignofExpr( * this ); }
|
---|
| 452 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 453 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 454 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 455 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[47534159] | 456 | };
|
---|
| 457 |
|
---|
[2a4b088] | 458 | /// UntypedOffsetofExpr represents an offsetof expression before resolution
|
---|
| 459 | class UntypedOffsetofExpr : public Expression {
|
---|
| 460 | public:
|
---|
[65cdc1e] | 461 | Type * type;
|
---|
| 462 | std::string member;
|
---|
| 463 |
|
---|
[bf4b4cf] | 464 | UntypedOffsetofExpr( Type * type, const std::string & member );
|
---|
[5ded739] | 465 | UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
|
---|
[2a4b088] | 466 | virtual ~UntypedOffsetofExpr();
|
---|
| 467 |
|
---|
| 468 | std::string get_member() const { return member; }
|
---|
[5ded739] | 469 | void set_member( const std::string & newValue ) { member = newValue; }
|
---|
| 470 | Type * get_type() const { return type; }
|
---|
| 471 | void set_type( Type * newValue ) { type = newValue; }
|
---|
| 472 |
|
---|
[7870799] | 473 | virtual UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr( * this ); }
|
---|
| 474 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 475 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 476 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 477 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[2a4b088] | 478 | };
|
---|
| 479 |
|
---|
[25a054f] | 480 | /// OffsetofExpr represents an offsetof expression
|
---|
| 481 | class OffsetofExpr : public Expression {
|
---|
| 482 | public:
|
---|
[65cdc1e] | 483 | Type * type;
|
---|
| 484 | DeclarationWithType * member;
|
---|
| 485 |
|
---|
[bf4b4cf] | 486 | OffsetofExpr( Type * type, DeclarationWithType * member );
|
---|
[5ded739] | 487 | OffsetofExpr( const OffsetofExpr & other );
|
---|
[25a054f] | 488 | virtual ~OffsetofExpr();
|
---|
| 489 |
|
---|
[5ded739] | 490 | Type * get_type() const { return type; }
|
---|
| 491 | void set_type( Type * newValue ) { type = newValue; }
|
---|
| 492 | DeclarationWithType * get_member() const { return member; }
|
---|
| 493 | void set_member( DeclarationWithType * newValue ) { member = newValue; }
|
---|
| 494 |
|
---|
[7870799] | 495 | virtual OffsetofExpr * clone() const override { return new OffsetofExpr( * this ); }
|
---|
| 496 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 497 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 498 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 499 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[25a054f] | 500 | };
|
---|
| 501 |
|
---|
[afc1045] | 502 | /// Expression representing a pack of field-offsets for a generic type
|
---|
| 503 | class OffsetPackExpr : public Expression {
|
---|
| 504 | public:
|
---|
[65cdc1e] | 505 | StructInstType * type;
|
---|
| 506 |
|
---|
[bf4b4cf] | 507 | OffsetPackExpr( StructInstType * type );
|
---|
[5ded739] | 508 | OffsetPackExpr( const OffsetPackExpr & other );
|
---|
[afc1045] | 509 | virtual ~OffsetPackExpr();
|
---|
| 510 |
|
---|
[5ded739] | 511 | StructInstType * get_type() const { return type; }
|
---|
| 512 | void set_type( StructInstType * newValue ) { type = newValue; }
|
---|
[afc1045] | 513 |
|
---|
[7870799] | 514 | virtual OffsetPackExpr * clone() const override { return new OffsetPackExpr( * this ); }
|
---|
| 515 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 516 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 517 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 518 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[afc1045] | 519 | };
|
---|
| 520 |
|
---|
[47534159] | 521 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
|
---|
[0dd3a2f] | 522 | class LogicalExpr : public Expression {
|
---|
| 523 | public:
|
---|
[65cdc1e] | 524 | Expression * arg1;
|
---|
| 525 | Expression * arg2;
|
---|
| 526 |
|
---|
[bf4b4cf] | 527 | LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
|
---|
[5ded739] | 528 | LogicalExpr( const LogicalExpr & other );
|
---|
[0dd3a2f] | 529 | virtual ~LogicalExpr();
|
---|
| 530 |
|
---|
| 531 | bool get_isAnd() const { return isAnd; }
|
---|
[5ded739] | 532 | Expression * get_arg1() { return arg1; }
|
---|
| 533 | void set_arg1( Expression * newValue ) { arg1 = newValue; }
|
---|
| 534 | Expression * get_arg2() const { return arg2; }
|
---|
| 535 | void set_arg2( Expression * newValue ) { arg2 = newValue; }
|
---|
| 536 |
|
---|
[7870799] | 537 | virtual LogicalExpr * clone() const override { return new LogicalExpr( * this ); }
|
---|
| 538 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 539 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 540 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 541 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[65cdc1e] | 542 |
|
---|
[0dd3a2f] | 543 | private:
|
---|
| 544 | bool isAnd;
|
---|
[51b73452] | 545 | };
|
---|
| 546 |
|
---|
[47534159] | 547 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
|
---|
[0dd3a2f] | 548 | class ConditionalExpr : public Expression {
|
---|
| 549 | public:
|
---|
[65cdc1e] | 550 | Expression * arg1;
|
---|
| 551 | Expression * arg2;
|
---|
| 552 | Expression * arg3;
|
---|
| 553 |
|
---|
[bf4b4cf] | 554 | ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
|
---|
[5ded739] | 555 | ConditionalExpr( const ConditionalExpr & other );
|
---|
[0dd3a2f] | 556 | virtual ~ConditionalExpr();
|
---|
| 557 |
|
---|
[14388c1] | 558 | bool get_lvalue() const final;
|
---|
| 559 |
|
---|
[5ded739] | 560 | Expression * get_arg1() const { return arg1; }
|
---|
| 561 | void set_arg1( Expression * newValue ) { arg1 = newValue; }
|
---|
| 562 | Expression * get_arg2() const { return arg2; }
|
---|
| 563 | void set_arg2( Expression * newValue ) { arg2 = newValue; }
|
---|
| 564 | Expression * get_arg3() const { return arg3; }
|
---|
| 565 | void set_arg3( Expression * newValue ) { arg3 = newValue; }
|
---|
| 566 |
|
---|
[7870799] | 567 | virtual ConditionalExpr * clone() const override { return new ConditionalExpr( * this ); }
|
---|
| 568 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 569 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 570 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 571 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 572 | };
|
---|
| 573 |
|
---|
[47534159] | 574 | /// CommaExpr represents the sequence operator ( a, b )
|
---|
[0dd3a2f] | 575 | class CommaExpr : public Expression {
|
---|
| 576 | public:
|
---|
[65cdc1e] | 577 | Expression * arg1;
|
---|
| 578 | Expression * arg2;
|
---|
| 579 |
|
---|
[bf4b4cf] | 580 | CommaExpr( Expression * arg1, Expression * arg2 );
|
---|
[5ded739] | 581 | CommaExpr( const CommaExpr & other );
|
---|
[0dd3a2f] | 582 | virtual ~CommaExpr();
|
---|
| 583 |
|
---|
[14388c1] | 584 | bool get_lvalue() const final;
|
---|
| 585 |
|
---|
[5ded739] | 586 | Expression * get_arg1() const { return arg1; }
|
---|
| 587 | void set_arg1( Expression * newValue ) { arg1 = newValue; }
|
---|
| 588 | Expression * get_arg2() const { return arg2; }
|
---|
| 589 | void set_arg2( Expression * newValue ) { arg2 = newValue; }
|
---|
[0dd3a2f] | 590 |
|
---|
[7870799] | 591 | virtual CommaExpr * clone() const override { return new CommaExpr( * this ); }
|
---|
| 592 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 593 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 594 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 595 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 596 | };
|
---|
| 597 |
|
---|
[47534159] | 598 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
|
---|
[0dd3a2f] | 599 | class TypeExpr : public Expression {
|
---|
| 600 | public:
|
---|
[65cdc1e] | 601 | Type * type;
|
---|
| 602 |
|
---|
[5ded739] | 603 | TypeExpr( Type * type );
|
---|
| 604 | TypeExpr( const TypeExpr & other );
|
---|
[0dd3a2f] | 605 | virtual ~TypeExpr();
|
---|
| 606 |
|
---|
[5ded739] | 607 | Type * get_type() const { return type; }
|
---|
| 608 | void set_type( Type * newValue ) { type = newValue; }
|
---|
[0dd3a2f] | 609 |
|
---|
[7870799] | 610 | virtual TypeExpr * clone() const override { return new TypeExpr( * this ); }
|
---|
| 611 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 612 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 613 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
[6e50a6b] | 614 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
| 615 | };
|
---|
| 616 |
|
---|
| 617 | /// DimensionExpr represents a type-system provided value used in an expression ( forrall([N]) ... N + 1 )
|
---|
| 618 | class DimensionExpr : public Expression {
|
---|
| 619 | public:
|
---|
| 620 | std::string name;
|
---|
| 621 |
|
---|
| 622 | DimensionExpr( std::string name );
|
---|
| 623 | DimensionExpr( const DimensionExpr & other );
|
---|
| 624 | virtual ~DimensionExpr();
|
---|
| 625 |
|
---|
| 626 | const std::string & get_name() const { return name; }
|
---|
| 627 | void set_name( std::string newValue ) { name = newValue; }
|
---|
| 628 |
|
---|
| 629 | virtual DimensionExpr * clone() const override { return new DimensionExpr( * this ); }
|
---|
| 630 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 631 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 632 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
[7870799] | 633 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 634 | };
|
---|
| 635 |
|
---|
[47534159] | 636 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
|
---|
[7f5566b] | 637 | class AsmExpr : public Expression {
|
---|
| 638 | public:
|
---|
[665f432] | 639 | std::string inout;
|
---|
[e612146c] | 640 | Expression * constraint;
|
---|
[65cdc1e] | 641 | Expression * operand;
|
---|
| 642 |
|
---|
[665f432] | 643 | AsmExpr( const std::string * _inout, Expression * constraint, Expression * operand ) : inout( _inout ? *_inout : "" ), constraint( constraint ), operand( operand ) { delete _inout; }
|
---|
[3be261a] | 644 | AsmExpr( const AsmExpr & other );
|
---|
[665f432] | 645 | virtual ~AsmExpr() { delete constraint; delete operand; };
|
---|
[7f5566b] | 646 |
|
---|
[7870799] | 647 | virtual AsmExpr * clone() const override { return new AsmExpr( * this ); }
|
---|
| 648 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 649 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 650 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 651 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[65cdc1e] | 652 |
|
---|
[7f5566b] | 653 | // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
|
---|
| 654 | };
|
---|
| 655 |
|
---|
[db4ecc5] | 656 | /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
|
---|
| 657 | /// along with a set of copy constructor calls, one for each argument.
|
---|
| 658 | class ImplicitCopyCtorExpr : public Expression {
|
---|
| 659 | public:
|
---|
[2f86ddf] | 660 | ApplicationExpr * callExpr = nullptr;
|
---|
[65cdc1e] | 661 |
|
---|
[db4ecc5] | 662 | ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
|
---|
| 663 | ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
|
---|
| 664 | virtual ~ImplicitCopyCtorExpr();
|
---|
| 665 |
|
---|
[7870799] | 666 | virtual ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr( * this ); }
|
---|
| 667 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 668 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 669 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 670 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[db4ecc5] | 671 | };
|
---|
| 672 |
|
---|
[b6fe7e6] | 673 | /// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
|
---|
| 674 | class ConstructorExpr : public Expression {
|
---|
| 675 | public:
|
---|
[65cdc1e] | 676 | Expression * callExpr;
|
---|
| 677 |
|
---|
[b6fe7e6] | 678 | ConstructorExpr( Expression * callExpr );
|
---|
| 679 | ConstructorExpr( const ConstructorExpr & other );
|
---|
| 680 | ~ConstructorExpr();
|
---|
[0dd3a2f] | 681 |
|
---|
[14388c1] | 682 | bool get_lvalue() const final;
|
---|
| 683 |
|
---|
[5ded739] | 684 | Expression * get_callExpr() const { return callExpr; }
|
---|
| 685 | void set_callExpr( Expression * newValue ) { callExpr = newValue; }
|
---|
[0dd3a2f] | 686 |
|
---|
[7870799] | 687 | virtual ConstructorExpr * clone() const override { return new ConstructorExpr( * this ); }
|
---|
| 688 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 689 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 690 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 691 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[51b73452] | 692 | };
|
---|
| 693 |
|
---|
[630a82a] | 694 | /// CompoundLiteralExpr represents a C99 'compound literal'
|
---|
| 695 | class CompoundLiteralExpr : public Expression {
|
---|
| 696 | public:
|
---|
[65cdc1e] | 697 | Initializer * initializer;
|
---|
| 698 |
|
---|
[630a82a] | 699 | CompoundLiteralExpr( Type * type, Initializer * initializer );
|
---|
[5ded739] | 700 | CompoundLiteralExpr( const CompoundLiteralExpr & other );
|
---|
[3b58d91] | 701 | virtual ~CompoundLiteralExpr();
|
---|
[630a82a] | 702 |
|
---|
[14388c1] | 703 | bool get_lvalue() const final;
|
---|
| 704 |
|
---|
[630a82a] | 705 | Initializer * get_initializer() const { return initializer; }
|
---|
| 706 | void set_initializer( Initializer * i ) { initializer = i; }
|
---|
| 707 |
|
---|
[7870799] | 708 | virtual CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr( * this ); }
|
---|
| 709 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 710 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 711 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 712 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[630a82a] | 713 | };
|
---|
| 714 |
|
---|
[b6fe7e6] | 715 | /// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
|
---|
[8688ce1] | 716 | class RangeExpr : public Expression {
|
---|
| 717 | public:
|
---|
[65cdc1e] | 718 | Expression * low, * high;
|
---|
| 719 |
|
---|
[5ded739] | 720 | RangeExpr( Expression * low, Expression * high );
|
---|
| 721 | RangeExpr( const RangeExpr & other );
|
---|
[8688ce1] | 722 |
|
---|
[d9e2280] | 723 | Expression * get_low() const { return low; }
|
---|
| 724 | Expression * get_high() const { return high; }
|
---|
[5ded739] | 725 | RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
|
---|
| 726 | RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
|
---|
[8688ce1] | 727 |
|
---|
[7870799] | 728 | virtual RangeExpr * clone() const override { return new RangeExpr( * this ); }
|
---|
| 729 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 730 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 731 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 732 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[8688ce1] | 733 | };
|
---|
| 734 |
|
---|
[907eccb] | 735 | /// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
|
---|
| 736 | class UntypedTupleExpr : public Expression {
|
---|
| 737 | public:
|
---|
[65cdc1e] | 738 | std::list<Expression*> exprs;
|
---|
| 739 |
|
---|
[bf4b4cf] | 740 | UntypedTupleExpr( const std::list< Expression * > & exprs );
|
---|
[5ded739] | 741 | UntypedTupleExpr( const UntypedTupleExpr & other );
|
---|
[907eccb] | 742 | virtual ~UntypedTupleExpr();
|
---|
| 743 |
|
---|
| 744 | std::list<Expression*>& get_exprs() { return exprs; }
|
---|
| 745 |
|
---|
[7870799] | 746 | virtual UntypedTupleExpr * clone() const override { return new UntypedTupleExpr( * this ); }
|
---|
| 747 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 748 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 749 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 750 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[907eccb] | 751 | };
|
---|
| 752 |
|
---|
[6eb8948] | 753 | /// TupleExpr represents a tuple expression ( [a, b, c] )
|
---|
| 754 | class TupleExpr : public Expression {
|
---|
| 755 | public:
|
---|
[65cdc1e] | 756 | std::list<Expression*> exprs;
|
---|
| 757 |
|
---|
[bf4b4cf] | 758 | TupleExpr( const std::list< Expression * > & exprs );
|
---|
[5ded739] | 759 | TupleExpr( const TupleExpr & other );
|
---|
[6eb8948] | 760 | virtual ~TupleExpr();
|
---|
| 761 |
|
---|
[3c7f01b] | 762 | bool get_lvalue() const final;
|
---|
| 763 |
|
---|
[6eb8948] | 764 | std::list<Expression*>& get_exprs() { return exprs; }
|
---|
| 765 |
|
---|
[7870799] | 766 | virtual TupleExpr * clone() const override { return new TupleExpr( * this ); }
|
---|
| 767 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 768 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 769 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 770 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[6eb8948] | 771 | };
|
---|
| 772 |
|
---|
[3b58d91] | 773 | /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
|
---|
| 774 | class TupleIndexExpr : public Expression {
|
---|
| 775 | public:
|
---|
[65cdc1e] | 776 | Expression * tuple;
|
---|
| 777 | unsigned int index;
|
---|
| 778 |
|
---|
[3b58d91] | 779 | TupleIndexExpr( Expression * tuple, unsigned int index );
|
---|
[5ded739] | 780 | TupleIndexExpr( const TupleIndexExpr & other );
|
---|
[3b58d91] | 781 | virtual ~TupleIndexExpr();
|
---|
| 782 |
|
---|
[14388c1] | 783 | bool get_lvalue() const final;
|
---|
| 784 |
|
---|
[3b58d91] | 785 | Expression * get_tuple() const { return tuple; }
|
---|
| 786 | int get_index() const { return index; }
|
---|
[5ded739] | 787 | TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
|
---|
[3b58d91] | 788 | TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
|
---|
| 789 |
|
---|
[7870799] | 790 | virtual TupleIndexExpr * clone() const override { return new TupleIndexExpr( * this ); }
|
---|
| 791 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 792 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 793 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 794 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[3b58d91] | 795 | };
|
---|
| 796 |
|
---|
[65660bd] | 797 | /// 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] | 798 | class TupleAssignExpr : public Expression {
|
---|
[3b58d91] | 799 | public:
|
---|
[65cdc1e] | 800 | StmtExpr * stmtExpr = nullptr;
|
---|
| 801 |
|
---|
[bf4b4cf] | 802 | TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
|
---|
[5ded739] | 803 | TupleAssignExpr( const TupleAssignExpr & other );
|
---|
[6eb8948] | 804 | virtual ~TupleAssignExpr();
|
---|
[3b58d91] | 805 |
|
---|
[d5556a3] | 806 | TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
|
---|
| 807 | StmtExpr * get_stmtExpr() const { return stmtExpr; }
|
---|
[3b58d91] | 808 |
|
---|
[7870799] | 809 | virtual TupleAssignExpr * clone() const override { return new TupleAssignExpr( * this ); }
|
---|
| 810 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 811 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 812 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 813 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[20de6fb] | 814 |
|
---|
| 815 | friend class ConverterNewToOld;
|
---|
| 816 | private:
|
---|
| 817 | TupleAssignExpr( StmtExpr * stmts );
|
---|
[3b58d91] | 818 | };
|
---|
| 819 |
|
---|
[6eb8948] | 820 | /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
|
---|
| 821 | class StmtExpr : public Expression {
|
---|
| 822 | public:
|
---|
[65cdc1e] | 823 | CompoundStmt * statements;
|
---|
| 824 | std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
|
---|
| 825 | std::list< Expression * > dtors; // destructor(s) for return variable(s)
|
---|
| 826 |
|
---|
[0e315a5] | 827 | // readonly
|
---|
| 828 | ExprStmt * resultExpr = nullptr;
|
---|
| 829 |
|
---|
[5ded739] | 830 | StmtExpr( CompoundStmt * statements );
|
---|
[6eb8948] | 831 | StmtExpr( const StmtExpr & other );
|
---|
| 832 | virtual ~StmtExpr();
|
---|
[3b58d91] | 833 |
|
---|
[5d00425] | 834 | bool get_lvalue() const final;
|
---|
| 835 |
|
---|
[6eb8948] | 836 | CompoundStmt * get_statements() const { return statements; }
|
---|
| 837 | StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
|
---|
[3b58d91] | 838 |
|
---|
[5e2c348] | 839 | // call to set the result type of this StmtExpr based on its body
|
---|
| 840 | void computeResult();
|
---|
| 841 |
|
---|
[d5556a3] | 842 | std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
|
---|
| 843 | std::list< Expression * > & get_dtors() { return dtors; }
|
---|
| 844 |
|
---|
[7870799] | 845 | virtual StmtExpr * clone() const override { return new StmtExpr( * this ); }
|
---|
| 846 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 847 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 848 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 849 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[3b58d91] | 850 | };
|
---|
| 851 |
|
---|
[3c13c03] | 852 | class UniqueExpr : public Expression {
|
---|
| 853 | public:
|
---|
[65cdc1e] | 854 | Expression * expr;
|
---|
| 855 | ObjectDecl * object;
|
---|
| 856 | VariableExpr * var;
|
---|
| 857 |
|
---|
[bf32bb8] | 858 | UniqueExpr( Expression * expr, long long idVal = -1 );
|
---|
[3c13c03] | 859 | UniqueExpr( const UniqueExpr & other );
|
---|
| 860 | ~UniqueExpr();
|
---|
| 861 |
|
---|
[141b786] | 862 | Expression * get_expr() const { return expr; }
|
---|
| 863 | UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
|
---|
[3c13c03] | 864 |
|
---|
[141b786] | 865 | ObjectDecl * get_object() const { return object; }
|
---|
| 866 | UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
|
---|
| 867 |
|
---|
| 868 | VariableExpr * get_var() const { return var; }
|
---|
| 869 | UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
|
---|
[77971f6] | 870 |
|
---|
[bf32bb8] | 871 | int get_id() const { return id; }
|
---|
| 872 |
|
---|
[7870799] | 873 | virtual UniqueExpr * clone() const override { return new UniqueExpr( * this ); }
|
---|
| 874 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 875 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 876 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 877 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[65cdc1e] | 878 |
|
---|
[3c13c03] | 879 | private:
|
---|
[bf32bb8] | 880 | int id;
|
---|
| 881 | static long long count;
|
---|
[3c13c03] | 882 | };
|
---|
| 883 |
|
---|
[e4d829b] | 884 | struct InitAlternative {
|
---|
| 885 | public:
|
---|
| 886 | Type * type = nullptr;
|
---|
| 887 | Designation * designation = nullptr;
|
---|
| 888 | InitAlternative( Type * type, Designation * designation );
|
---|
| 889 | InitAlternative( const InitAlternative & other );
|
---|
| 890 | InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it
|
---|
| 891 | ~InitAlternative();
|
---|
| 892 | };
|
---|
| 893 |
|
---|
| 894 | class UntypedInitExpr : public Expression {
|
---|
| 895 | public:
|
---|
[65cdc1e] | 896 | Expression * expr;
|
---|
| 897 | std::list<InitAlternative> initAlts;
|
---|
| 898 |
|
---|
[e4d829b] | 899 | UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
|
---|
| 900 | UntypedInitExpr( const UntypedInitExpr & other );
|
---|
| 901 | ~UntypedInitExpr();
|
---|
| 902 |
|
---|
| 903 | Expression * get_expr() const { return expr; }
|
---|
| 904 | UntypedInitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
|
---|
| 905 |
|
---|
| 906 | std::list<InitAlternative> & get_initAlts() { return initAlts; }
|
---|
| 907 |
|
---|
[7870799] | 908 | virtual UntypedInitExpr * clone() const override { return new UntypedInitExpr( * this ); }
|
---|
| 909 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 910 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 911 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 912 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[e4d829b] | 913 | };
|
---|
| 914 |
|
---|
| 915 | class InitExpr : public Expression {
|
---|
| 916 | public:
|
---|
[65cdc1e] | 917 | Expression * expr;
|
---|
| 918 | Designation * designation;
|
---|
| 919 |
|
---|
[62423350] | 920 | InitExpr( Expression * expr, Designation * designation );
|
---|
[e4d829b] | 921 | InitExpr( const InitExpr & other );
|
---|
| 922 | ~InitExpr();
|
---|
| 923 |
|
---|
| 924 | Expression * get_expr() const { return expr; }
|
---|
| 925 | InitExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
|
---|
| 926 |
|
---|
| 927 | Designation * get_designation() const { return designation; }
|
---|
| 928 | InitExpr * set_designation( Designation * newValue ) { designation = newValue; return this; }
|
---|
| 929 |
|
---|
[7870799] | 930 | virtual InitExpr * clone() const override { return new InitExpr( * this ); }
|
---|
| 931 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 932 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 933 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 934 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[e4d829b] | 935 | };
|
---|
| 936 |
|
---|
[44b4114] | 937 | /// expression that contains a deleted identifier - should never make it past the resolver.
|
---|
| 938 | class DeletedExpr : public Expression {
|
---|
| 939 | public:
|
---|
| 940 | Expression * expr;
|
---|
[e67991f] | 941 | Declaration * deleteStmt;
|
---|
[44b4114] | 942 |
|
---|
[e67991f] | 943 | DeletedExpr( Expression * expr, Declaration * deleteStmt );
|
---|
[44b4114] | 944 | DeletedExpr( const DeletedExpr & other );
|
---|
| 945 | ~DeletedExpr();
|
---|
| 946 |
|
---|
[7870799] | 947 | virtual DeletedExpr * clone() const override { return new DeletedExpr( * this ); }
|
---|
| 948 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 949 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 950 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 951 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[44b4114] | 952 | };
|
---|
| 953 |
|
---|
[0f79853] | 954 | /// expression wrapping the use of a default argument - should never make it past the resolver.
|
---|
| 955 | class DefaultArgExpr : public Expression {
|
---|
| 956 | public:
|
---|
| 957 | Expression * expr;
|
---|
| 958 |
|
---|
| 959 | DefaultArgExpr( Expression * expr );
|
---|
| 960 | DefaultArgExpr( const DefaultArgExpr & other );
|
---|
| 961 | ~DefaultArgExpr();
|
---|
| 962 |
|
---|
[7870799] | 963 | virtual DefaultArgExpr * clone() const override { return new DefaultArgExpr( * this ); }
|
---|
| 964 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 965 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 966 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 967 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[0f79853] | 968 | };
|
---|
| 969 |
|
---|
[d807ca28] | 970 | /// C11 _Generic expression
|
---|
| 971 | class GenericExpr : public Expression {
|
---|
| 972 | public:
|
---|
| 973 | struct Association {
|
---|
| 974 | Type * type = nullptr;
|
---|
| 975 | Expression * expr = nullptr;
|
---|
| 976 | bool isDefault = false;
|
---|
| 977 |
|
---|
| 978 | Association( Type * type, Expression * expr );
|
---|
| 979 | Association( Expression * expr );
|
---|
| 980 | Association( const Association & other );
|
---|
| 981 | Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it
|
---|
| 982 | ~Association();
|
---|
| 983 | };
|
---|
| 984 |
|
---|
| 985 | Expression * control;
|
---|
| 986 | std::list<Association> associations;
|
---|
| 987 |
|
---|
| 988 | GenericExpr( Expression * control, const std::list<Association> & assoc );
|
---|
| 989 | GenericExpr( const GenericExpr & other );
|
---|
| 990 | virtual ~GenericExpr();
|
---|
| 991 |
|
---|
[7870799] | 992 | virtual GenericExpr * clone() const override { return new GenericExpr( * this ); }
|
---|
| 993 | virtual void accept( Visitor & v ) override { v.visit( this ); }
|
---|
| 994 | virtual void accept( Visitor & v ) const override { v.visit( this ); }
|
---|
| 995 | virtual Expression * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
|
---|
| 996 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
---|
[d807ca28] | 997 | };
|
---|
| 998 |
|
---|
[0dd3a2f] | 999 | // Local Variables: //
|
---|
| 1000 | // tab-width: 4 //
|
---|
| 1001 | // mode: c++ //
|
---|
| 1002 | // compile-command: "make install" //
|
---|
| 1003 | // End: //
|
---|