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