| 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 | //
|
|---|
| 7 | // Expression.h --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Richard C. Bilson
|
|---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Wed Dec 11 16:50:19 2019
|
|---|
| 13 | // Update Count : 60
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 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
|
|---|
| 23 | #include <vector> // for vector
|
|---|
| 24 |
|
|---|
| 25 | #include "BaseSyntaxNode.h" // for BaseSyntaxNode
|
|---|
| 26 | #include "Constant.h" // for Constant
|
|---|
| 27 | #include "Initializer.h" // for Designation (ptr only), Initializer
|
|---|
| 28 | #include "Label.h" // for Label
|
|---|
| 29 | #include "Mutator.h" // for Mutator
|
|---|
| 30 | #include "Declaration.h" // for Aggregate
|
|---|
| 31 | #include "SynTree.h" // for UniqueId
|
|---|
| 32 | #include "Visitor.h" // for Visitor
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 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 {
|
|---|
| 42 | ParamEntry(): decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {}
|
|---|
| 43 | ParamEntry( UniqueId decl, Declaration * declptr, Type * actualType, Type * formalType, Expression* expr );
|
|---|
| 44 | ParamEntry( const ParamEntry & other );
|
|---|
| 45 | ParamEntry( ParamEntry && other );
|
|---|
| 46 | ~ParamEntry();
|
|---|
| 47 | ParamEntry & operator=( ParamEntry && other );
|
|---|
| 48 |
|
|---|
| 49 | UniqueId const decl;
|
|---|
| 50 | Declaration * const declptr;
|
|---|
| 51 | Type * const actualType;
|
|---|
| 52 | Type * const formalType;
|
|---|
| 53 | Expression * expr;
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | /// Expression is the root type for all expressions
|
|---|
| 57 | class Expression : public BaseSyntaxNode {
|
|---|
| 58 | public:
|
|---|
| 59 | Type * result;
|
|---|
| 60 | TypeSubstitution * env;
|
|---|
| 61 | bool extension = false;
|
|---|
| 62 | InferredParams inferParams; ///< Post-resolution inferred parameter slots
|
|---|
| 63 | std::vector<UniqueId> resnSlots; ///< Pre-resolution inferred parameter slots
|
|---|
| 64 |
|
|---|
| 65 | // xxx - should turn inferParams+resnSlots into a union to save some memory
|
|---|
| 66 |
|
|---|
| 67 | Expression();
|
|---|
| 68 | Expression( const Expression & other );
|
|---|
| 69 | virtual ~Expression();
|
|---|
| 70 |
|
|---|
| 71 | Type *& get_result() { return result; }
|
|---|
| 72 | const Type * get_result() const { return result; }
|
|---|
| 73 | void set_result( Type * newValue ) { result = newValue; }
|
|---|
| 74 | virtual bool get_lvalue() const;
|
|---|
| 75 |
|
|---|
| 76 | TypeSubstitution * get_env() const { return env; }
|
|---|
| 77 | void set_env( TypeSubstitution * newValue ) { env = newValue; }
|
|---|
| 78 | bool get_extension() const { return extension; }
|
|---|
| 79 | Expression * set_extension( bool exten ) { extension = exten; return this; }
|
|---|
| 80 |
|
|---|
| 81 | // move other's inferParams to this
|
|---|
| 82 | void spliceInferParams( Expression * other );
|
|---|
| 83 |
|
|---|
| 84 | virtual Expression * clone() const override = 0;
|
|---|
| 85 | virtual void accept( Visitor & v ) override = 0;
|
|---|
| 86 | virtual void accept( Visitor & v ) const override = 0;
|
|---|
| 87 | virtual Expression * acceptMutator( Mutator & m ) override = 0;
|
|---|
| 88 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
|---|
| 89 | };
|
|---|
| 90 |
|
|---|
| 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.
|
|---|
| 93 | class ApplicationExpr : public Expression {
|
|---|
| 94 | public:
|
|---|
| 95 | Expression * function;
|
|---|
| 96 | std::list<Expression *> args;
|
|---|
| 97 |
|
|---|
| 98 | ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
|
|---|
| 99 | ApplicationExpr( const ApplicationExpr & other );
|
|---|
| 100 | virtual ~ApplicationExpr();
|
|---|
| 101 |
|
|---|
| 102 | bool get_lvalue() const final;
|
|---|
| 103 |
|
|---|
| 104 | Expression * get_function() const { return function; }
|
|---|
| 105 | void set_function( Expression * newValue ) { function = newValue; }
|
|---|
| 106 | std::list<Expression *>& get_args() { return args; }
|
|---|
| 107 |
|
|---|
| 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;
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 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.
|
|---|
| 118 | class UntypedExpr : public Expression {
|
|---|
| 119 | public:
|
|---|
| 120 | Expression * function;
|
|---|
| 121 | std::list<Expression*> args;
|
|---|
| 122 |
|
|---|
| 123 | UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
|
|---|
| 124 | UntypedExpr( const UntypedExpr & other );
|
|---|
| 125 | virtual ~UntypedExpr();
|
|---|
| 126 |
|
|---|
| 127 | bool get_lvalue() const final;
|
|---|
| 128 |
|
|---|
| 129 | Expression * get_function() const { return function; }
|
|---|
| 130 | void set_function( Expression * newValue ) { function = newValue; }
|
|---|
| 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 |
|
|---|
| 136 | static UntypedExpr * createDeref( Expression * arg );
|
|---|
| 137 | static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
|
|---|
| 138 |
|
|---|
| 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;
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 | /// NameExpr contains a name whose meaning is still not determined
|
|---|
| 147 | class NameExpr : public Expression {
|
|---|
| 148 | public:
|
|---|
| 149 | std::string name;
|
|---|
| 150 |
|
|---|
| 151 | NameExpr( std::string name );
|
|---|
| 152 | NameExpr( const NameExpr & other );
|
|---|
| 153 | virtual ~NameExpr();
|
|---|
| 154 |
|
|---|
| 155 | const std::string & get_name() const { return name; }
|
|---|
| 156 | void set_name( std::string newValue ) { name = newValue; }
|
|---|
| 157 |
|
|---|
| 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;
|
|---|
| 163 | };
|
|---|
| 164 |
|
|---|
| 165 | // [Qualifier].name; Qualifier is the type_name from the parser
|
|---|
| 166 | class QualifiedNameExpr : public Expression {
|
|---|
| 167 | public:
|
|---|
| 168 | Declaration * type_decl;
|
|---|
| 169 | std::string name;
|
|---|
| 170 |
|
|---|
| 171 | QualifiedNameExpr( Declaration * decl, std::string name): Expression(), type_decl(decl), name(name) {}
|
|---|
| 172 | QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name) {}
|
|---|
| 173 |
|
|---|
| 174 | virtual ~QualifiedNameExpr() {
|
|---|
| 175 | delete type_decl;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | virtual QualifiedNameExpr * clone() const override {
|
|---|
| 179 | return new QualifiedNameExpr( * this );
|
|---|
| 180 | }
|
|---|
| 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 |
|
|---|
| 187 | virtual void print( std::ostream & os, Indenter indent = {} ) const override {
|
|---|
| 188 | type_decl->print( os, indent );
|
|---|
| 189 | os << name << std::endl;
|
|---|
| 190 | }
|
|---|
| 191 | };
|
|---|
| 192 |
|
|---|
| 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 |
|
|---|
| 218 | // The following classes are used to represent expression types that cannot be converted into
|
|---|
| 219 | // function-call format.
|
|---|
| 220 |
|
|---|
| 221 | /// AddressExpr represents a address-of expression, e.g. & e
|
|---|
| 222 | class AddressExpr : public Expression {
|
|---|
| 223 | public:
|
|---|
| 224 | Expression * arg;
|
|---|
| 225 |
|
|---|
| 226 | AddressExpr( Expression * arg );
|
|---|
| 227 | AddressExpr( const AddressExpr & other );
|
|---|
| 228 | virtual ~AddressExpr();
|
|---|
| 229 |
|
|---|
| 230 | Expression * get_arg() const { return arg; }
|
|---|
| 231 | void set_arg(Expression * newValue ) { arg = newValue; }
|
|---|
| 232 |
|
|---|
| 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;
|
|---|
| 238 | };
|
|---|
| 239 |
|
|---|
| 240 | // GCC &&label
|
|---|
| 241 | // https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html
|
|---|
| 242 | class LabelAddressExpr : public Expression {
|
|---|
| 243 | public:
|
|---|
| 244 | Label arg;
|
|---|
| 245 |
|
|---|
| 246 | LabelAddressExpr( const Label &arg );
|
|---|
| 247 | LabelAddressExpr( const LabelAddressExpr & other );
|
|---|
| 248 | virtual ~LabelAddressExpr();
|
|---|
| 249 |
|
|---|
| 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;
|
|---|
| 255 | };
|
|---|
| 256 |
|
|---|
| 257 | /// CastExpr represents a type cast expression, e.g. (int)e
|
|---|
| 258 | class CastExpr : public Expression {
|
|---|
| 259 | public:
|
|---|
| 260 | Expression * arg;
|
|---|
| 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;
|
|---|
| 272 |
|
|---|
| 273 | CastExpr( Expression * arg, bool isGenerated = true );
|
|---|
| 274 | CastExpr( Expression * arg, Type * toType, bool isGenerated = true );
|
|---|
| 275 | CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor
|
|---|
| 276 | CastExpr( const CastExpr & other );
|
|---|
| 277 | virtual ~CastExpr();
|
|---|
| 278 |
|
|---|
| 279 | bool get_lvalue() const final;
|
|---|
| 280 |
|
|---|
| 281 | Expression * get_arg() const { return arg; }
|
|---|
| 282 | void set_arg( Expression * newValue ) { arg = newValue; }
|
|---|
| 283 |
|
|---|
| 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;
|
|---|
| 289 | };
|
|---|
| 290 |
|
|---|
| 291 | /// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t
|
|---|
| 292 | class KeywordCastExpr : public Expression {
|
|---|
| 293 | public:
|
|---|
| 294 | Expression * arg;
|
|---|
| 295 | struct Concrete {
|
|---|
| 296 | std::string field;
|
|---|
| 297 | std::string getter;
|
|---|
| 298 | };
|
|---|
| 299 | AggregateDecl::Aggregate target;
|
|---|
| 300 | Concrete concrete_target;
|
|---|
| 301 |
|
|---|
| 302 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target );
|
|---|
| 303 | KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target, const Concrete & concrete_target );
|
|---|
| 304 | KeywordCastExpr( const KeywordCastExpr & other );
|
|---|
| 305 | virtual ~KeywordCastExpr();
|
|---|
| 306 |
|
|---|
| 307 | const char * targetString() const;
|
|---|
| 308 |
|
|---|
| 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;
|
|---|
| 314 | };
|
|---|
| 315 |
|
|---|
| 316 | /// VirtualCastExpr repersents a virtual dynamic cast, e.g. (virtual exception)e
|
|---|
| 317 | class VirtualCastExpr : public Expression {
|
|---|
| 318 | public:
|
|---|
| 319 | Expression * arg;
|
|---|
| 320 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 333 | };
|
|---|
| 334 |
|
|---|
| 335 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
|
|---|
| 336 | class UntypedMemberExpr : public Expression {
|
|---|
| 337 | public:
|
|---|
| 338 | Expression * member;
|
|---|
| 339 | Expression * aggregate;
|
|---|
| 340 |
|
|---|
| 341 | UntypedMemberExpr( Expression * member, Expression * aggregate );
|
|---|
| 342 | UntypedMemberExpr( const UntypedMemberExpr & other );
|
|---|
| 343 | virtual ~UntypedMemberExpr();
|
|---|
| 344 |
|
|---|
| 345 | bool get_lvalue() const final;
|
|---|
| 346 |
|
|---|
| 347 | Expression * get_member() const { return member; }
|
|---|
| 348 | void set_member( Expression * newValue ) { member = newValue; }
|
|---|
| 349 | Expression * get_aggregate() const { return aggregate; }
|
|---|
| 350 | void set_aggregate( Expression * newValue ) { aggregate = newValue; }
|
|---|
| 351 |
|
|---|
| 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;
|
|---|
| 357 | };
|
|---|
| 358 |
|
|---|
| 359 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
|
|---|
| 360 | /// Does not take ownership of member.
|
|---|
| 361 | class MemberExpr : public Expression {
|
|---|
| 362 | public:
|
|---|
| 363 | DeclarationWithType * member;
|
|---|
| 364 | Expression * aggregate;
|
|---|
| 365 |
|
|---|
| 366 | MemberExpr( DeclarationWithType * member, Expression * aggregate );
|
|---|
| 367 | MemberExpr( const MemberExpr & other );
|
|---|
| 368 | virtual ~MemberExpr();
|
|---|
| 369 |
|
|---|
| 370 | bool get_lvalue() const final;
|
|---|
| 371 |
|
|---|
| 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; }
|
|---|
| 376 |
|
|---|
| 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;
|
|---|
| 382 | };
|
|---|
| 383 |
|
|---|
| 384 | /// ConstantExpr represents an expression that simply refers to the value of a constant
|
|---|
| 385 | class ConstantExpr : public Expression {
|
|---|
| 386 | public:
|
|---|
| 387 | Constant constant;
|
|---|
| 388 |
|
|---|
| 389 | ConstantExpr( Constant constant );
|
|---|
| 390 | ConstantExpr( const ConstantExpr & other );
|
|---|
| 391 | virtual ~ConstantExpr();
|
|---|
| 392 |
|
|---|
| 393 | Constant * get_constant() { return & constant; }
|
|---|
| 394 | const Constant * get_constant() const { return & constant; }
|
|---|
| 395 | void set_constant( const Constant & newValue ) { constant = newValue; }
|
|---|
| 396 |
|
|---|
| 397 | long long int intValue() const;
|
|---|
| 398 |
|
|---|
| 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;
|
|---|
| 404 | };
|
|---|
| 405 |
|
|---|
| 406 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
|
|---|
| 407 | class SizeofExpr : public Expression {
|
|---|
| 408 | public:
|
|---|
| 409 | Expression * expr;
|
|---|
| 410 | Type * type;
|
|---|
| 411 | bool isType;
|
|---|
| 412 |
|
|---|
| 413 | SizeofExpr( Expression * expr );
|
|---|
| 414 | SizeofExpr( const SizeofExpr & other );
|
|---|
| 415 | SizeofExpr( Type * type );
|
|---|
| 416 | virtual ~SizeofExpr();
|
|---|
| 417 |
|
|---|
| 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; }
|
|---|
| 422 | bool get_isType() const { return isType; }
|
|---|
| 423 | void set_isType( bool newValue ) { isType = newValue; }
|
|---|
| 424 |
|
|---|
| 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;
|
|---|
| 430 | };
|
|---|
| 431 |
|
|---|
| 432 | /// AlignofExpr represents an alignof expression
|
|---|
| 433 | class AlignofExpr : public Expression {
|
|---|
| 434 | public:
|
|---|
| 435 | Expression * expr;
|
|---|
| 436 | Type * type;
|
|---|
| 437 | bool isType;
|
|---|
| 438 |
|
|---|
| 439 | AlignofExpr( Expression * expr );
|
|---|
| 440 | AlignofExpr( const AlignofExpr & other );
|
|---|
| 441 | AlignofExpr( Type * type );
|
|---|
| 442 | virtual ~AlignofExpr();
|
|---|
| 443 |
|
|---|
| 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; }
|
|---|
| 448 | bool get_isType() const { return isType; }
|
|---|
| 449 | void set_isType( bool newValue ) { isType = newValue; }
|
|---|
| 450 |
|
|---|
| 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;
|
|---|
| 456 | };
|
|---|
| 457 |
|
|---|
| 458 | /// UntypedOffsetofExpr represents an offsetof expression before resolution
|
|---|
| 459 | class UntypedOffsetofExpr : public Expression {
|
|---|
| 460 | public:
|
|---|
| 461 | Type * type;
|
|---|
| 462 | std::string member;
|
|---|
| 463 |
|
|---|
| 464 | UntypedOffsetofExpr( Type * type, const std::string & member );
|
|---|
| 465 | UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
|
|---|
| 466 | virtual ~UntypedOffsetofExpr();
|
|---|
| 467 |
|
|---|
| 468 | std::string get_member() const { return member; }
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 478 | };
|
|---|
| 479 |
|
|---|
| 480 | /// OffsetofExpr represents an offsetof expression
|
|---|
| 481 | class OffsetofExpr : public Expression {
|
|---|
| 482 | public:
|
|---|
| 483 | Type * type;
|
|---|
| 484 | DeclarationWithType * member;
|
|---|
| 485 |
|
|---|
| 486 | OffsetofExpr( Type * type, DeclarationWithType * member );
|
|---|
| 487 | OffsetofExpr( const OffsetofExpr & other );
|
|---|
| 488 | virtual ~OffsetofExpr();
|
|---|
| 489 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 500 | };
|
|---|
| 501 |
|
|---|
| 502 | /// Expression representing a pack of field-offsets for a generic type
|
|---|
| 503 | class OffsetPackExpr : public Expression {
|
|---|
| 504 | public:
|
|---|
| 505 | StructInstType * type;
|
|---|
| 506 |
|
|---|
| 507 | OffsetPackExpr( StructInstType * type );
|
|---|
| 508 | OffsetPackExpr( const OffsetPackExpr & other );
|
|---|
| 509 | virtual ~OffsetPackExpr();
|
|---|
| 510 |
|
|---|
| 511 | StructInstType * get_type() const { return type; }
|
|---|
| 512 | void set_type( StructInstType * newValue ) { type = newValue; }
|
|---|
| 513 |
|
|---|
| 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;
|
|---|
| 519 | };
|
|---|
| 520 |
|
|---|
| 521 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
|
|---|
| 522 | class LogicalExpr : public Expression {
|
|---|
| 523 | public:
|
|---|
| 524 | Expression * arg1;
|
|---|
| 525 | Expression * arg2;
|
|---|
| 526 |
|
|---|
| 527 | LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true );
|
|---|
| 528 | LogicalExpr( const LogicalExpr & other );
|
|---|
| 529 | virtual ~LogicalExpr();
|
|---|
| 530 |
|
|---|
| 531 | bool get_isAnd() const { return isAnd; }
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 542 |
|
|---|
| 543 | private:
|
|---|
| 544 | bool isAnd;
|
|---|
| 545 | };
|
|---|
| 546 |
|
|---|
| 547 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
|
|---|
| 548 | class ConditionalExpr : public Expression {
|
|---|
| 549 | public:
|
|---|
| 550 | Expression * arg1;
|
|---|
| 551 | Expression * arg2;
|
|---|
| 552 | Expression * arg3;
|
|---|
| 553 |
|
|---|
| 554 | ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 );
|
|---|
| 555 | ConditionalExpr( const ConditionalExpr & other );
|
|---|
| 556 | virtual ~ConditionalExpr();
|
|---|
| 557 |
|
|---|
| 558 | bool get_lvalue() const final;
|
|---|
| 559 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 572 | };
|
|---|
| 573 |
|
|---|
| 574 | /// CommaExpr represents the sequence operator ( a, b )
|
|---|
| 575 | class CommaExpr : public Expression {
|
|---|
| 576 | public:
|
|---|
| 577 | Expression * arg1;
|
|---|
| 578 | Expression * arg2;
|
|---|
| 579 |
|
|---|
| 580 | CommaExpr( Expression * arg1, Expression * arg2 );
|
|---|
| 581 | CommaExpr( const CommaExpr & other );
|
|---|
| 582 | virtual ~CommaExpr();
|
|---|
| 583 |
|
|---|
| 584 | bool get_lvalue() const final;
|
|---|
| 585 |
|
|---|
| 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; }
|
|---|
| 590 |
|
|---|
| 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;
|
|---|
| 596 | };
|
|---|
| 597 |
|
|---|
| 598 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
|
|---|
| 599 | class TypeExpr : public Expression {
|
|---|
| 600 | public:
|
|---|
| 601 | Type * type;
|
|---|
| 602 |
|
|---|
| 603 | TypeExpr( Type * type );
|
|---|
| 604 | TypeExpr( const TypeExpr & other );
|
|---|
| 605 | virtual ~TypeExpr();
|
|---|
| 606 |
|
|---|
| 607 | Type * get_type() const { return type; }
|
|---|
| 608 | void set_type( Type * newValue ) { type = newValue; }
|
|---|
| 609 |
|
|---|
| 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 ); }
|
|---|
| 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 ); }
|
|---|
| 633 | virtual void print( std::ostream & os, Indenter indent = {} ) const override;
|
|---|
| 634 | };
|
|---|
| 635 |
|
|---|
| 636 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
|
|---|
| 637 | class AsmExpr : public Expression {
|
|---|
| 638 | public:
|
|---|
| 639 | std::string inout;
|
|---|
| 640 | Expression * constraint;
|
|---|
| 641 | Expression * operand;
|
|---|
| 642 |
|
|---|
| 643 | AsmExpr( const std::string * _inout, Expression * constraint, Expression * operand ) : inout( _inout ? *_inout : "" ), constraint( constraint ), operand( operand ) { delete _inout; }
|
|---|
| 644 | AsmExpr( const AsmExpr & other );
|
|---|
| 645 | virtual ~AsmExpr() { delete constraint; delete operand; };
|
|---|
| 646 |
|
|---|
| 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;
|
|---|
| 652 |
|
|---|
| 653 | // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
|
|---|
| 654 | };
|
|---|
| 655 |
|
|---|
| 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:
|
|---|
| 660 | ApplicationExpr * callExpr = nullptr;
|
|---|
| 661 |
|
|---|
| 662 | ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
|
|---|
| 663 | ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
|
|---|
| 664 | virtual ~ImplicitCopyCtorExpr();
|
|---|
| 665 |
|
|---|
| 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;
|
|---|
| 671 | };
|
|---|
| 672 |
|
|---|
| 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:
|
|---|
| 676 | Expression * callExpr;
|
|---|
| 677 |
|
|---|
| 678 | ConstructorExpr( Expression * callExpr );
|
|---|
| 679 | ConstructorExpr( const ConstructorExpr & other );
|
|---|
| 680 | ~ConstructorExpr();
|
|---|
| 681 |
|
|---|
| 682 | bool get_lvalue() const final;
|
|---|
| 683 |
|
|---|
| 684 | Expression * get_callExpr() const { return callExpr; }
|
|---|
| 685 | void set_callExpr( Expression * newValue ) { callExpr = newValue; }
|
|---|
| 686 |
|
|---|
| 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;
|
|---|
| 692 | };
|
|---|
| 693 |
|
|---|
| 694 | /// CompoundLiteralExpr represents a C99 'compound literal'
|
|---|
| 695 | class CompoundLiteralExpr : public Expression {
|
|---|
| 696 | public:
|
|---|
| 697 | Initializer * initializer;
|
|---|
| 698 |
|
|---|
| 699 | CompoundLiteralExpr( Type * type, Initializer * initializer );
|
|---|
| 700 | CompoundLiteralExpr( const CompoundLiteralExpr & other );
|
|---|
| 701 | virtual ~CompoundLiteralExpr();
|
|---|
| 702 |
|
|---|
| 703 | bool get_lvalue() const final;
|
|---|
| 704 |
|
|---|
| 705 | Initializer * get_initializer() const { return initializer; }
|
|---|
| 706 | void set_initializer( Initializer * i ) { initializer = i; }
|
|---|
| 707 |
|
|---|
| 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;
|
|---|
| 713 | };
|
|---|
| 714 |
|
|---|
| 715 | /// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
|
|---|
| 716 | class RangeExpr : public Expression {
|
|---|
| 717 | public:
|
|---|
| 718 | Expression * low, * high;
|
|---|
| 719 |
|
|---|
| 720 | RangeExpr( Expression * low, Expression * high );
|
|---|
| 721 | RangeExpr( const RangeExpr & other );
|
|---|
| 722 |
|
|---|
| 723 | Expression * get_low() const { return low; }
|
|---|
| 724 | Expression * get_high() const { return high; }
|
|---|
| 725 | RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
|
|---|
| 726 | RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
|
|---|
| 727 |
|
|---|
| 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;
|
|---|
| 733 | };
|
|---|
| 734 |
|
|---|
| 735 | /// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
|
|---|
| 736 | class UntypedTupleExpr : public Expression {
|
|---|
| 737 | public:
|
|---|
| 738 | std::list<Expression*> exprs;
|
|---|
| 739 |
|
|---|
| 740 | UntypedTupleExpr( const std::list< Expression * > & exprs );
|
|---|
| 741 | UntypedTupleExpr( const UntypedTupleExpr & other );
|
|---|
| 742 | virtual ~UntypedTupleExpr();
|
|---|
| 743 |
|
|---|
| 744 | std::list<Expression*>& get_exprs() { return exprs; }
|
|---|
| 745 |
|
|---|
| 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;
|
|---|
| 751 | };
|
|---|
| 752 |
|
|---|
| 753 | /// TupleExpr represents a tuple expression ( [a, b, c] )
|
|---|
| 754 | class TupleExpr : public Expression {
|
|---|
| 755 | public:
|
|---|
| 756 | std::list<Expression*> exprs;
|
|---|
| 757 |
|
|---|
| 758 | TupleExpr( const std::list< Expression * > & exprs );
|
|---|
| 759 | TupleExpr( const TupleExpr & other );
|
|---|
| 760 | virtual ~TupleExpr();
|
|---|
| 761 |
|
|---|
| 762 | bool get_lvalue() const final;
|
|---|
| 763 |
|
|---|
| 764 | std::list<Expression*>& get_exprs() { return exprs; }
|
|---|
| 765 |
|
|---|
| 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;
|
|---|
| 771 | };
|
|---|
| 772 |
|
|---|
| 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:
|
|---|
| 776 | Expression * tuple;
|
|---|
| 777 | unsigned int index;
|
|---|
| 778 |
|
|---|
| 779 | TupleIndexExpr( Expression * tuple, unsigned int index );
|
|---|
| 780 | TupleIndexExpr( const TupleIndexExpr & other );
|
|---|
| 781 | virtual ~TupleIndexExpr();
|
|---|
| 782 |
|
|---|
| 783 | bool get_lvalue() const final;
|
|---|
| 784 |
|
|---|
| 785 | Expression * get_tuple() const { return tuple; }
|
|---|
| 786 | int get_index() const { return index; }
|
|---|
| 787 | TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
|
|---|
| 788 | TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
|
|---|
| 789 |
|
|---|
| 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;
|
|---|
| 795 | };
|
|---|
| 796 |
|
|---|
| 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
|
|---|
| 798 | class TupleAssignExpr : public Expression {
|
|---|
| 799 | public:
|
|---|
| 800 | StmtExpr * stmtExpr = nullptr;
|
|---|
| 801 |
|
|---|
| 802 | TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls );
|
|---|
| 803 | TupleAssignExpr( const TupleAssignExpr & other );
|
|---|
| 804 | virtual ~TupleAssignExpr();
|
|---|
| 805 |
|
|---|
| 806 | TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
|
|---|
| 807 | StmtExpr * get_stmtExpr() const { return stmtExpr; }
|
|---|
| 808 |
|
|---|
| 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;
|
|---|
| 814 |
|
|---|
| 815 | friend class ConverterNewToOld;
|
|---|
| 816 | private:
|
|---|
| 817 | TupleAssignExpr( StmtExpr * stmts );
|
|---|
| 818 | };
|
|---|
| 819 |
|
|---|
| 820 | /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
|
|---|
| 821 | class StmtExpr : public Expression {
|
|---|
| 822 | public:
|
|---|
| 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 |
|
|---|
| 827 | // readonly
|
|---|
| 828 | ExprStmt * resultExpr = nullptr;
|
|---|
| 829 |
|
|---|
| 830 | StmtExpr( CompoundStmt * statements );
|
|---|
| 831 | StmtExpr( const StmtExpr & other );
|
|---|
| 832 | virtual ~StmtExpr();
|
|---|
| 833 |
|
|---|
| 834 | bool get_lvalue() const final;
|
|---|
| 835 |
|
|---|
| 836 | CompoundStmt * get_statements() const { return statements; }
|
|---|
| 837 | StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
|
|---|
| 838 |
|
|---|
| 839 | // call to set the result type of this StmtExpr based on its body
|
|---|
| 840 | void computeResult();
|
|---|
| 841 |
|
|---|
| 842 | std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
|
|---|
| 843 | std::list< Expression * > & get_dtors() { return dtors; }
|
|---|
| 844 |
|
|---|
| 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;
|
|---|
| 850 | };
|
|---|
| 851 |
|
|---|
| 852 | class UniqueExpr : public Expression {
|
|---|
| 853 | public:
|
|---|
| 854 | Expression * expr;
|
|---|
| 855 | ObjectDecl * object;
|
|---|
| 856 | VariableExpr * var;
|
|---|
| 857 |
|
|---|
| 858 | UniqueExpr( Expression * expr, long long idVal = -1 );
|
|---|
| 859 | UniqueExpr( const UniqueExpr & other );
|
|---|
| 860 | ~UniqueExpr();
|
|---|
| 861 |
|
|---|
| 862 | Expression * get_expr() const { return expr; }
|
|---|
| 863 | UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
|
|---|
| 864 |
|
|---|
| 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; }
|
|---|
| 870 |
|
|---|
| 871 | int get_id() const { return id; }
|
|---|
| 872 |
|
|---|
| 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;
|
|---|
| 878 |
|
|---|
| 879 | private:
|
|---|
| 880 | int id;
|
|---|
| 881 | static long long count;
|
|---|
| 882 | };
|
|---|
| 883 |
|
|---|
| 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:
|
|---|
| 896 | Expression * expr;
|
|---|
| 897 | std::list<InitAlternative> initAlts;
|
|---|
| 898 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 913 | };
|
|---|
| 914 |
|
|---|
| 915 | class InitExpr : public Expression {
|
|---|
| 916 | public:
|
|---|
| 917 | Expression * expr;
|
|---|
| 918 | Designation * designation;
|
|---|
| 919 |
|
|---|
| 920 | InitExpr( Expression * expr, Designation * designation );
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 935 | };
|
|---|
| 936 |
|
|---|
| 937 | /// expression that contains a deleted identifier - should never make it past the resolver.
|
|---|
| 938 | class DeletedExpr : public Expression {
|
|---|
| 939 | public:
|
|---|
| 940 | Expression * expr;
|
|---|
| 941 | Declaration * deleteStmt;
|
|---|
| 942 |
|
|---|
| 943 | DeletedExpr( Expression * expr, Declaration * deleteStmt );
|
|---|
| 944 | DeletedExpr( const DeletedExpr & other );
|
|---|
| 945 | ~DeletedExpr();
|
|---|
| 946 |
|
|---|
| 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;
|
|---|
| 952 | };
|
|---|
| 953 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 968 | };
|
|---|
| 969 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 997 | };
|
|---|
| 998 |
|
|---|
| 999 | // Local Variables: //
|
|---|
| 1000 | // tab-width: 4 //
|
|---|
| 1001 | // mode: c++ //
|
|---|
| 1002 | // compile-command: "make install" //
|
|---|
| 1003 | // End: //
|
|---|