| 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 : Sat Jan 14 14:37:54 2017
 | 
|---|
| 13 | // Update Count     : 37
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #ifndef EXPRESSION_H
 | 
|---|
| 17 | #define EXPRESSION_H
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include <map>
 | 
|---|
| 20 | #include <memory>
 | 
|---|
| 21 | #include "SynTree.h"
 | 
|---|
| 22 | #include "Visitor.h"
 | 
|---|
| 23 | #include "Mutator.h"
 | 
|---|
| 24 | #include "Constant.h"
 | 
|---|
| 25 | #include "Common/UniqueName.h"
 | 
|---|
| 26 | 
 | 
|---|
| 27 | /// Expression is the root type for all expressions
 | 
|---|
| 28 | class Expression {
 | 
|---|
| 29 |   public:
 | 
|---|
| 30 |         Expression( Expression * _aname = nullptr );
 | 
|---|
| 31 |         Expression( const Expression & other );
 | 
|---|
| 32 |         virtual ~Expression();
 | 
|---|
| 33 | 
 | 
|---|
| 34 |         Type *& get_result() { return result; }
 | 
|---|
| 35 |         void set_result( Type * newValue ) { result = newValue; }
 | 
|---|
| 36 |         bool has_result() const { return result != nullptr; }
 | 
|---|
| 37 | 
 | 
|---|
| 38 |         TypeSubstitution * get_env() const { return env; }
 | 
|---|
| 39 |         void set_env( TypeSubstitution * newValue ) { env = newValue; }
 | 
|---|
| 40 |         Expression * get_argName() const { return argName; }
 | 
|---|
| 41 |         void set_argName( Expression * name ) { argName = name; }
 | 
|---|
| 42 |         bool get_extension() const { return extension; }
 | 
|---|
| 43 |         Expression * set_extension( bool exten ) { extension = exten; return this; }
 | 
|---|
| 44 | 
 | 
|---|
| 45 |         virtual Expression * clone() const = 0;
 | 
|---|
| 46 |         virtual void accept( Visitor & v ) = 0;
 | 
|---|
| 47 |         virtual Expression * acceptMutator( Mutator & m ) = 0;
 | 
|---|
| 48 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 49 |   protected:
 | 
|---|
| 50 |         Type * result;
 | 
|---|
| 51 |         TypeSubstitution * env;
 | 
|---|
| 52 |         Expression * argName; // if expression is used as an argument, it can be "designated" by this name
 | 
|---|
| 53 |         bool extension = false;
 | 
|---|
| 54 | };
 | 
|---|
| 55 | 
 | 
|---|
| 56 | struct ParamEntry;
 | 
|---|
| 57 | typedef std::map< UniqueId, ParamEntry > InferredParams;
 | 
|---|
| 58 | 
 | 
|---|
| 59 | /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
 | 
|---|
| 60 | /// but subject to decay-to-pointer and type parameter renaming
 | 
|---|
| 61 | struct ParamEntry {
 | 
|---|
| 62 |         ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ), inferParams( new InferredParams ) {}
 | 
|---|
| 63 |         ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}
 | 
|---|
| 64 |         ParamEntry( const ParamEntry & other );
 | 
|---|
| 65 |         ~ParamEntry();
 | 
|---|
| 66 |         ParamEntry & operator=( const ParamEntry & other );
 | 
|---|
| 67 | 
 | 
|---|
| 68 |         UniqueId decl;
 | 
|---|
| 69 |         Type * actualType;
 | 
|---|
| 70 |         Type * formalType;
 | 
|---|
| 71 |         Expression* expr;
 | 
|---|
| 72 |         std::unique_ptr< InferredParams > inferParams;
 | 
|---|
| 73 | };
 | 
|---|
| 74 | 
 | 
|---|
| 75 | /// ApplicationExpr represents the application of a function to a set of parameters.  This is the result of running an
 | 
|---|
| 76 | /// UntypedExpr through the expression analyzer.
 | 
|---|
| 77 | class ApplicationExpr : public Expression {
 | 
|---|
| 78 |   public:
 | 
|---|
| 79 |         ApplicationExpr( Expression * function );
 | 
|---|
| 80 |         ApplicationExpr( const ApplicationExpr & other );
 | 
|---|
| 81 |         virtual ~ApplicationExpr();
 | 
|---|
| 82 | 
 | 
|---|
| 83 |         Expression * get_function() const { return function; }
 | 
|---|
| 84 |         void set_function( Expression * newValue ) { function = newValue; }
 | 
|---|
| 85 |         std::list<Expression *>& get_args() { return args; }
 | 
|---|
| 86 |         InferredParams & get_inferParams() { return inferParams; }
 | 
|---|
| 87 | 
 | 
|---|
| 88 |         virtual ApplicationExpr * clone() const { return new ApplicationExpr( * this ); }
 | 
|---|
| 89 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 90 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 91 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 92 |   private:
 | 
|---|
| 93 |         Expression * function;
 | 
|---|
| 94 |         std::list<Expression *> args;
 | 
|---|
| 95 |         InferredParams inferParams;
 | 
|---|
| 96 | };
 | 
|---|
| 97 | 
 | 
|---|
| 98 | /// UntypedExpr represents the application of a function to a set of parameters, but where the particular overload for
 | 
|---|
| 99 | /// the function name has not yet been determined.  Most operators are converted into functional form automatically, to
 | 
|---|
| 100 | /// permit operator overloading.
 | 
|---|
| 101 | class UntypedExpr : public Expression {
 | 
|---|
| 102 |   public:
 | 
|---|
| 103 |         UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr );
 | 
|---|
| 104 |         UntypedExpr( const UntypedExpr & other );
 | 
|---|
| 105 |         virtual ~UntypedExpr();
 | 
|---|
| 106 | 
 | 
|---|
| 107 |         Expression * get_function() const { return function; }
 | 
|---|
| 108 |         void set_function( Expression * newValue ) { function = newValue; }
 | 
|---|
| 109 | 
 | 
|---|
| 110 |         void set_args( std::list<Expression *> & listArgs ) { args = listArgs; }
 | 
|---|
| 111 |         std::list<Expression*>::iterator begin_args() { return args.begin(); }
 | 
|---|
| 112 |         std::list<Expression*>::iterator end_args() { return args.end(); }
 | 
|---|
| 113 |         std::list<Expression*>& get_args() { return args; }
 | 
|---|
| 114 | 
 | 
|---|
| 115 |         static UntypedExpr * createDeref( Expression * arg );
 | 
|---|
| 116 |         static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
 | 
|---|
| 117 | 
 | 
|---|
| 118 |         virtual UntypedExpr * clone() const { return new UntypedExpr( * this ); }
 | 
|---|
| 119 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 120 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 121 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 122 |         virtual void printArgs(std::ostream & os, int indent = 0) const;
 | 
|---|
| 123 |   private:
 | 
|---|
| 124 |         Expression * function;
 | 
|---|
| 125 |         std::list<Expression*> args;
 | 
|---|
| 126 | };
 | 
|---|
| 127 | 
 | 
|---|
| 128 | /// NameExpr contains a name whose meaning is still not determined
 | 
|---|
| 129 | class NameExpr : public Expression {
 | 
|---|
| 130 |   public:
 | 
|---|
| 131 |         NameExpr( std::string name, Expression *_aname = nullptr );
 | 
|---|
| 132 |         NameExpr( const NameExpr & other );
 | 
|---|
| 133 |         virtual ~NameExpr();
 | 
|---|
| 134 | 
 | 
|---|
| 135 |         const std::string & get_name() const { return name; }
 | 
|---|
| 136 |         void set_name( std::string newValue ) { name = newValue; }
 | 
|---|
| 137 | 
 | 
|---|
| 138 |         virtual NameExpr * clone() const { return new NameExpr( * this ); }
 | 
|---|
| 139 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 140 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 141 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 142 |   private:
 | 
|---|
| 143 |         std::string name;
 | 
|---|
| 144 | };
 | 
|---|
| 145 | 
 | 
|---|
| 146 | // The following classes are used to represent expression types that cannot be converted into
 | 
|---|
| 147 | // function-call format.
 | 
|---|
| 148 | 
 | 
|---|
| 149 | /// AddressExpr represents a address-of expression, e.g. & e
 | 
|---|
| 150 | class AddressExpr : public Expression {
 | 
|---|
| 151 |   public:
 | 
|---|
| 152 |         AddressExpr( Expression * arg, Expression *_aname = nullptr );
 | 
|---|
| 153 |         AddressExpr( const AddressExpr & other );
 | 
|---|
| 154 |         virtual ~AddressExpr();
 | 
|---|
| 155 | 
 | 
|---|
| 156 |         Expression * get_arg() const { return arg; }
 | 
|---|
| 157 |         void set_arg(Expression * newValue ) { arg = newValue; }
 | 
|---|
| 158 | 
 | 
|---|
| 159 |         virtual AddressExpr * clone() const { return new AddressExpr( * this ); }
 | 
|---|
| 160 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 161 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 162 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 163 |   private:
 | 
|---|
| 164 |         Expression * arg;
 | 
|---|
| 165 | };
 | 
|---|
| 166 | 
 | 
|---|
| 167 | // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
 | 
|---|
| 168 | class LabelAddressExpr : public Expression {
 | 
|---|
| 169 |   public:
 | 
|---|
| 170 |         LabelAddressExpr( Expression * arg );
 | 
|---|
| 171 |         LabelAddressExpr( const LabelAddressExpr & other );
 | 
|---|
| 172 |         virtual ~LabelAddressExpr();
 | 
|---|
| 173 | 
 | 
|---|
| 174 |         Expression * get_arg() const { return arg; }
 | 
|---|
| 175 |         void set_arg(Expression * newValue ) { arg = newValue; }
 | 
|---|
| 176 | 
 | 
|---|
| 177 |         virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); }
 | 
|---|
| 178 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 179 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 180 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 181 |   private:
 | 
|---|
| 182 |         Expression * arg;
 | 
|---|
| 183 | };
 | 
|---|
| 184 | 
 | 
|---|
| 185 | /// CastExpr represents a type cast expression, e.g. (int)e
 | 
|---|
| 186 | class CastExpr : public Expression {
 | 
|---|
| 187 |   public:
 | 
|---|
| 188 |         CastExpr( Expression * arg, Expression *_aname = nullptr );
 | 
|---|
| 189 |         CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr );
 | 
|---|
| 190 |         CastExpr( const CastExpr & other );
 | 
|---|
| 191 |         virtual ~CastExpr();
 | 
|---|
| 192 | 
 | 
|---|
| 193 |         Expression * get_arg() const { return arg; }
 | 
|---|
| 194 |         void set_arg(Expression * newValue ) { arg = newValue; }
 | 
|---|
| 195 | 
 | 
|---|
| 196 |         virtual CastExpr * clone() const { return new CastExpr( * this ); }
 | 
|---|
| 197 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 198 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 199 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 200 |   private:
 | 
|---|
| 201 |         Expression * arg;
 | 
|---|
| 202 | };
 | 
|---|
| 203 | 
 | 
|---|
| 204 | /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
 | 
|---|
| 205 | class UntypedMemberExpr : public Expression {
 | 
|---|
| 206 |   public:
 | 
|---|
| 207 |         UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr );
 | 
|---|
| 208 |         UntypedMemberExpr( const UntypedMemberExpr & other );
 | 
|---|
| 209 |         virtual ~UntypedMemberExpr();
 | 
|---|
| 210 | 
 | 
|---|
| 211 |         Expression * get_member() const { return member; }
 | 
|---|
| 212 |         void set_member( Expression * newValue ) { member = newValue; }
 | 
|---|
| 213 |         Expression * get_aggregate() const { return aggregate; }
 | 
|---|
| 214 |         void set_aggregate( Expression * newValue ) { aggregate = newValue; }
 | 
|---|
| 215 | 
 | 
|---|
| 216 |         virtual UntypedMemberExpr * clone() const { return new UntypedMemberExpr( * this ); }
 | 
|---|
| 217 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 218 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 219 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 220 |   private:
 | 
|---|
| 221 |         Expression * member;
 | 
|---|
| 222 |         Expression * aggregate;
 | 
|---|
| 223 | };
 | 
|---|
| 224 | 
 | 
|---|
| 225 | /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
 | 
|---|
| 226 | class MemberExpr : public Expression {
 | 
|---|
| 227 |   public:
 | 
|---|
| 228 |         MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr );
 | 
|---|
| 229 |         MemberExpr( const MemberExpr & other );
 | 
|---|
| 230 |         virtual ~MemberExpr();
 | 
|---|
| 231 | 
 | 
|---|
| 232 |         DeclarationWithType * get_member() const { return member; }
 | 
|---|
| 233 |         void set_member( DeclarationWithType * newValue ) { member = newValue; }
 | 
|---|
| 234 |         Expression * get_aggregate() const { return aggregate; }
 | 
|---|
| 235 |         void set_aggregate( Expression * newValue ) { aggregate = newValue; }
 | 
|---|
| 236 | 
 | 
|---|
| 237 |         virtual MemberExpr * clone() const { return new MemberExpr( * this ); }
 | 
|---|
| 238 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 239 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 240 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 241 |   private:
 | 
|---|
| 242 |         DeclarationWithType * member;
 | 
|---|
| 243 |         Expression * aggregate;
 | 
|---|
| 244 | };
 | 
|---|
| 245 | 
 | 
|---|
| 246 | /// VariableExpr represents an expression that simply refers to the value of a named variable
 | 
|---|
| 247 | class VariableExpr : public Expression {
 | 
|---|
| 248 |   public:
 | 
|---|
| 249 |         VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr );
 | 
|---|
| 250 |         VariableExpr( const VariableExpr & other );
 | 
|---|
| 251 |         virtual ~VariableExpr();
 | 
|---|
| 252 | 
 | 
|---|
| 253 |         DeclarationWithType * get_var() const { return var; }
 | 
|---|
| 254 |         void set_var( DeclarationWithType * newValue ) { var = newValue; }
 | 
|---|
| 255 | 
 | 
|---|
| 256 |         virtual VariableExpr * clone() const { return new VariableExpr( * this ); }
 | 
|---|
| 257 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 258 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 259 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 260 |   private:
 | 
|---|
| 261 |         DeclarationWithType * var;
 | 
|---|
| 262 | };
 | 
|---|
| 263 | 
 | 
|---|
| 264 | /// ConstantExpr represents an expression that simply refers to the value of a constant
 | 
|---|
| 265 | class ConstantExpr : public Expression {
 | 
|---|
| 266 |   public:
 | 
|---|
| 267 |         ConstantExpr( Constant constant, Expression *_aname = nullptr );
 | 
|---|
| 268 |         ConstantExpr( const ConstantExpr & other );
 | 
|---|
| 269 |         virtual ~ConstantExpr();
 | 
|---|
| 270 | 
 | 
|---|
| 271 |         Constant * get_constant() { return & constant; }
 | 
|---|
| 272 |         void set_constant( const Constant & newValue ) { constant = newValue; }
 | 
|---|
| 273 | 
 | 
|---|
| 274 |         virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
 | 
|---|
| 275 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 276 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 277 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 278 |   private:
 | 
|---|
| 279 |         Constant constant;
 | 
|---|
| 280 | };
 | 
|---|
| 281 | 
 | 
|---|
| 282 | /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
 | 
|---|
| 283 | class SizeofExpr : public Expression {
 | 
|---|
| 284 |   public:
 | 
|---|
| 285 |         SizeofExpr( Expression * expr, Expression *_aname = nullptr );
 | 
|---|
| 286 |         SizeofExpr( const SizeofExpr & other );
 | 
|---|
| 287 |         SizeofExpr( Type * type, Expression *_aname = nullptr );
 | 
|---|
| 288 |         virtual ~SizeofExpr();
 | 
|---|
| 289 | 
 | 
|---|
| 290 |         Expression * get_expr() const { return expr; }
 | 
|---|
| 291 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
| 292 |         Type * get_type() const { return type; }
 | 
|---|
| 293 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| 294 |         bool get_isType() const { return isType; }
 | 
|---|
| 295 |         void set_isType( bool newValue ) { isType = newValue; }
 | 
|---|
| 296 | 
 | 
|---|
| 297 |         virtual SizeofExpr * clone() const { return new SizeofExpr( * this ); }
 | 
|---|
| 298 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 299 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 300 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 301 |   private:
 | 
|---|
| 302 |         Expression * expr;
 | 
|---|
| 303 |         Type * type;
 | 
|---|
| 304 |         bool isType;
 | 
|---|
| 305 | };
 | 
|---|
| 306 | 
 | 
|---|
| 307 | /// AlignofExpr represents an alignof expression
 | 
|---|
| 308 | class AlignofExpr : public Expression {
 | 
|---|
| 309 |   public:
 | 
|---|
| 310 |         AlignofExpr( Expression * expr, Expression *_aname = nullptr );
 | 
|---|
| 311 |         AlignofExpr( const AlignofExpr & other );
 | 
|---|
| 312 |         AlignofExpr( Type * type, Expression *_aname = nullptr );
 | 
|---|
| 313 |         virtual ~AlignofExpr();
 | 
|---|
| 314 | 
 | 
|---|
| 315 |         Expression * get_expr() const { return expr; }
 | 
|---|
| 316 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
| 317 |         Type * get_type() const { return type; }
 | 
|---|
| 318 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| 319 |         bool get_isType() const { return isType; }
 | 
|---|
| 320 |         void set_isType( bool newValue ) { isType = newValue; }
 | 
|---|
| 321 | 
 | 
|---|
| 322 |         virtual AlignofExpr * clone() const { return new AlignofExpr( * this ); }
 | 
|---|
| 323 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 324 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 325 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 326 |   private:
 | 
|---|
| 327 |         Expression * expr;
 | 
|---|
| 328 |         Type * type;
 | 
|---|
| 329 |         bool isType;
 | 
|---|
| 330 | };
 | 
|---|
| 331 | 
 | 
|---|
| 332 | /// UntypedOffsetofExpr represents an offsetof expression before resolution
 | 
|---|
| 333 | class UntypedOffsetofExpr : public Expression {
 | 
|---|
| 334 |   public:
 | 
|---|
| 335 |         UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
 | 
|---|
| 336 |         UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
 | 
|---|
| 337 |         virtual ~UntypedOffsetofExpr();
 | 
|---|
| 338 | 
 | 
|---|
| 339 |         std::string get_member() const { return member; }
 | 
|---|
| 340 |         void set_member( const std::string & newValue ) { member = newValue; }
 | 
|---|
| 341 |         Type * get_type() const { return type; }
 | 
|---|
| 342 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| 343 | 
 | 
|---|
| 344 |         virtual UntypedOffsetofExpr * clone() const { return new UntypedOffsetofExpr( * this ); }
 | 
|---|
| 345 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 346 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 347 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 348 |   private:
 | 
|---|
| 349 |         Type * type;
 | 
|---|
| 350 |         std::string member;
 | 
|---|
| 351 | };
 | 
|---|
| 352 | 
 | 
|---|
| 353 | /// OffsetofExpr represents an offsetof expression
 | 
|---|
| 354 | class OffsetofExpr : public Expression {
 | 
|---|
| 355 |   public:
 | 
|---|
| 356 |         OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
 | 
|---|
| 357 |         OffsetofExpr( const OffsetofExpr & other );
 | 
|---|
| 358 |         virtual ~OffsetofExpr();
 | 
|---|
| 359 | 
 | 
|---|
| 360 |         Type * get_type() const { return type; }
 | 
|---|
| 361 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| 362 |         DeclarationWithType * get_member() const { return member; }
 | 
|---|
| 363 |         void set_member( DeclarationWithType * newValue ) { member = newValue; }
 | 
|---|
| 364 | 
 | 
|---|
| 365 |         virtual OffsetofExpr * clone() const { return new OffsetofExpr( * this ); }
 | 
|---|
| 366 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 367 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 368 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 369 |   private:
 | 
|---|
| 370 |         Type * type;
 | 
|---|
| 371 |         DeclarationWithType * member;
 | 
|---|
| 372 | };
 | 
|---|
| 373 | 
 | 
|---|
| 374 | /// Expression representing a pack of field-offsets for a generic type
 | 
|---|
| 375 | class OffsetPackExpr : public Expression {
 | 
|---|
| 376 | public:
 | 
|---|
| 377 |         OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
 | 
|---|
| 378 |         OffsetPackExpr( const OffsetPackExpr & other );
 | 
|---|
| 379 |         virtual ~OffsetPackExpr();
 | 
|---|
| 380 | 
 | 
|---|
| 381 |         StructInstType * get_type() const { return type; }
 | 
|---|
| 382 |         void set_type( StructInstType * newValue ) { type = newValue; }
 | 
|---|
| 383 | 
 | 
|---|
| 384 |         virtual OffsetPackExpr * clone() const { return new OffsetPackExpr( * this ); }
 | 
|---|
| 385 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 386 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 387 | 
 | 
|---|
| 388 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 389 | 
 | 
|---|
| 390 | private:
 | 
|---|
| 391 |         StructInstType * type;
 | 
|---|
| 392 | };
 | 
|---|
| 393 | 
 | 
|---|
| 394 | /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
 | 
|---|
| 395 | class AttrExpr : public Expression {
 | 
|---|
| 396 |   public:
 | 
|---|
| 397 |         AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
 | 
|---|
| 398 |         AttrExpr( const AttrExpr & other );
 | 
|---|
| 399 |         AttrExpr( Expression * attr, Type * type, Expression *_aname = nullptr );
 | 
|---|
| 400 |         virtual ~AttrExpr();
 | 
|---|
| 401 | 
 | 
|---|
| 402 |         Expression * get_attr() const { return attr; }
 | 
|---|
| 403 |         void set_attr( Expression * newValue ) { attr = newValue; }
 | 
|---|
| 404 |         Expression * get_expr() const { return expr; }
 | 
|---|
| 405 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
| 406 |         Type * get_type() const { return type; }
 | 
|---|
| 407 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| 408 |         bool get_isType() const { return isType; }
 | 
|---|
| 409 |         void set_isType( bool newValue ) { isType = newValue; }
 | 
|---|
| 410 | 
 | 
|---|
| 411 |         virtual AttrExpr * clone() const { return new AttrExpr( * this ); }
 | 
|---|
| 412 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 413 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 414 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 415 |   private:
 | 
|---|
| 416 |         Expression * attr;
 | 
|---|
| 417 |         Expression * expr;
 | 
|---|
| 418 |         Type * type;
 | 
|---|
| 419 |         bool isType;
 | 
|---|
| 420 | };
 | 
|---|
| 421 | 
 | 
|---|
| 422 | /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
 | 
|---|
| 423 | class LogicalExpr : public Expression {
 | 
|---|
| 424 |   public:
 | 
|---|
| 425 |         LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
 | 
|---|
| 426 |         LogicalExpr( const LogicalExpr & other );
 | 
|---|
| 427 |         virtual ~LogicalExpr();
 | 
|---|
| 428 | 
 | 
|---|
| 429 |         bool get_isAnd() const { return isAnd; }
 | 
|---|
| 430 |         Expression * get_arg1() { return arg1; }
 | 
|---|
| 431 |         void set_arg1( Expression * newValue ) { arg1 = newValue; }
 | 
|---|
| 432 |         Expression * get_arg2() const { return arg2; }
 | 
|---|
| 433 |         void set_arg2( Expression * newValue ) { arg2 = newValue; }
 | 
|---|
| 434 | 
 | 
|---|
| 435 |         virtual LogicalExpr * clone() const { return new LogicalExpr( * this ); }
 | 
|---|
| 436 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 437 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 438 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 439 |   private:
 | 
|---|
| 440 |         Expression * arg1;
 | 
|---|
| 441 |         Expression * arg2;
 | 
|---|
| 442 |         bool isAnd;
 | 
|---|
| 443 | };
 | 
|---|
| 444 | 
 | 
|---|
| 445 | /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
 | 
|---|
| 446 | class ConditionalExpr : public Expression {
 | 
|---|
| 447 |   public:
 | 
|---|
| 448 |         ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
 | 
|---|
| 449 |         ConditionalExpr( const ConditionalExpr & other );
 | 
|---|
| 450 |         virtual ~ConditionalExpr();
 | 
|---|
| 451 | 
 | 
|---|
| 452 |         Expression * get_arg1() const { return arg1; }
 | 
|---|
| 453 |         void set_arg1( Expression * newValue ) { arg1 = newValue; }
 | 
|---|
| 454 |         Expression * get_arg2() const { return arg2; }
 | 
|---|
| 455 |         void set_arg2( Expression * newValue ) { arg2 = newValue; }
 | 
|---|
| 456 |         Expression * get_arg3() const { return arg3; }
 | 
|---|
| 457 |         void set_arg3( Expression * newValue ) { arg3 = newValue; }
 | 
|---|
| 458 | 
 | 
|---|
| 459 |         virtual ConditionalExpr * clone() const { return new ConditionalExpr( * this ); }
 | 
|---|
| 460 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 461 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 462 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 463 |   private:
 | 
|---|
| 464 |         Expression * arg1;
 | 
|---|
| 465 |         Expression * arg2;
 | 
|---|
| 466 |         Expression * arg3;
 | 
|---|
| 467 | };
 | 
|---|
| 468 | 
 | 
|---|
| 469 | /// CommaExpr represents the sequence operator ( a, b )
 | 
|---|
| 470 | class CommaExpr : public Expression {
 | 
|---|
| 471 |   public:
 | 
|---|
| 472 |         CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
 | 
|---|
| 473 |         CommaExpr( const CommaExpr & other );
 | 
|---|
| 474 |         virtual ~CommaExpr();
 | 
|---|
| 475 | 
 | 
|---|
| 476 |         Expression * get_arg1() const { return arg1; }
 | 
|---|
| 477 |         void set_arg1( Expression * newValue ) { arg1 = newValue; }
 | 
|---|
| 478 |         Expression * get_arg2() const { return arg2; }
 | 
|---|
| 479 |         void set_arg2( Expression * newValue ) { arg2 = newValue; }
 | 
|---|
| 480 | 
 | 
|---|
| 481 |         virtual CommaExpr * clone() const { return new CommaExpr( * this ); }
 | 
|---|
| 482 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 483 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 484 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 485 |   private:
 | 
|---|
| 486 |         Expression * arg1;
 | 
|---|
| 487 |         Expression * arg2;
 | 
|---|
| 488 | };
 | 
|---|
| 489 | 
 | 
|---|
| 490 | /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
 | 
|---|
| 491 | class TypeExpr : public Expression {
 | 
|---|
| 492 |   public:
 | 
|---|
| 493 |         TypeExpr( Type * type );
 | 
|---|
| 494 |         TypeExpr( const TypeExpr & other );
 | 
|---|
| 495 |         virtual ~TypeExpr();
 | 
|---|
| 496 | 
 | 
|---|
| 497 |         Type * get_type() const { return type; }
 | 
|---|
| 498 |         void set_type( Type * newValue ) { type = newValue; }
 | 
|---|
| 499 | 
 | 
|---|
| 500 |         virtual TypeExpr * clone() const { return new TypeExpr( * this ); }
 | 
|---|
| 501 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 502 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 503 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 504 |   private:
 | 
|---|
| 505 |         Type * type;
 | 
|---|
| 506 | };
 | 
|---|
| 507 | 
 | 
|---|
| 508 | /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
 | 
|---|
| 509 | class AsmExpr : public Expression {
 | 
|---|
| 510 |   public:
 | 
|---|
| 511 |         AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
 | 
|---|
| 512 |         AsmExpr( const AsmExpr & other );
 | 
|---|
| 513 |         virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
 | 
|---|
| 514 | 
 | 
|---|
| 515 |         Expression * get_inout() const { return inout; }
 | 
|---|
| 516 |         void set_inout( Expression * newValue ) { inout = newValue; }
 | 
|---|
| 517 | 
 | 
|---|
| 518 |         ConstantExpr * get_constraint() const { return constraint; }
 | 
|---|
| 519 |         void set_constraint( ConstantExpr * newValue ) { constraint = newValue; }
 | 
|---|
| 520 | 
 | 
|---|
| 521 |         Expression * get_operand() const { return operand; }
 | 
|---|
| 522 |         void set_operand( Expression * newValue ) { operand = newValue; }
 | 
|---|
| 523 | 
 | 
|---|
| 524 |         virtual AsmExpr * clone() const { return new AsmExpr( * this ); }
 | 
|---|
| 525 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 526 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 527 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 528 |   private:
 | 
|---|
| 529 |         // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
 | 
|---|
| 530 |         Expression * inout;
 | 
|---|
| 531 |         ConstantExpr * constraint;
 | 
|---|
| 532 |         Expression * operand;
 | 
|---|
| 533 | };
 | 
|---|
| 534 | 
 | 
|---|
| 535 | /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,
 | 
|---|
| 536 | /// along with a set of copy constructor calls, one for each argument.
 | 
|---|
| 537 | class ImplicitCopyCtorExpr : public Expression {
 | 
|---|
| 538 | public:
 | 
|---|
| 539 |         ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
 | 
|---|
| 540 |         ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
 | 
|---|
| 541 |         virtual ~ImplicitCopyCtorExpr();
 | 
|---|
| 542 | 
 | 
|---|
| 543 |         ApplicationExpr * get_callExpr() const { return callExpr; }
 | 
|---|
| 544 |         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
 | 
|---|
| 545 | 
 | 
|---|
| 546 |         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
 | 
|---|
| 547 |         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
 | 
|---|
| 548 |         std::list< Expression * > & get_dtors() { return dtors; }
 | 
|---|
| 549 | 
 | 
|---|
| 550 |         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
 | 
|---|
| 551 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 552 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 553 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 554 |   private:
 | 
|---|
| 555 |         ApplicationExpr * callExpr;
 | 
|---|
| 556 |         std::list< ObjectDecl * > tempDecls;
 | 
|---|
| 557 |         std::list< ObjectDecl * > returnDecls;
 | 
|---|
| 558 |         std::list< Expression * > dtors;
 | 
|---|
| 559 | };
 | 
|---|
| 560 | 
 | 
|---|
| 561 | /// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
 | 
|---|
| 562 | class ConstructorExpr : public Expression {
 | 
|---|
| 563 | public:
 | 
|---|
| 564 |         ConstructorExpr( Expression * callExpr );
 | 
|---|
| 565 |         ConstructorExpr( const ConstructorExpr & other );
 | 
|---|
| 566 |         ~ConstructorExpr();
 | 
|---|
| 567 | 
 | 
|---|
| 568 |         Expression * get_callExpr() const { return callExpr; }
 | 
|---|
| 569 |         void set_callExpr( Expression * newValue ) { callExpr = newValue; }
 | 
|---|
| 570 | 
 | 
|---|
| 571 |         virtual ConstructorExpr * clone() const { return new ConstructorExpr( * this ); }
 | 
|---|
| 572 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 573 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 574 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 575 | private:
 | 
|---|
| 576 |         Expression * callExpr;
 | 
|---|
| 577 | };
 | 
|---|
| 578 | 
 | 
|---|
| 579 | /// CompoundLiteralExpr represents a C99 'compound literal'
 | 
|---|
| 580 | class CompoundLiteralExpr : public Expression {
 | 
|---|
| 581 |   public:
 | 
|---|
| 582 |         CompoundLiteralExpr( Type * type, Initializer * initializer );
 | 
|---|
| 583 |         CompoundLiteralExpr( const CompoundLiteralExpr & other );
 | 
|---|
| 584 |         virtual ~CompoundLiteralExpr();
 | 
|---|
| 585 | 
 | 
|---|
| 586 |         Type * get_type() const { return type; }
 | 
|---|
| 587 |         void set_type( Type * t ) { type = t; }
 | 
|---|
| 588 | 
 | 
|---|
| 589 |         Initializer * get_initializer() const { return initializer; }
 | 
|---|
| 590 |         void set_initializer( Initializer * i ) { initializer = i; }
 | 
|---|
| 591 | 
 | 
|---|
| 592 |         virtual CompoundLiteralExpr * clone() const { return new CompoundLiteralExpr( * this ); }
 | 
|---|
| 593 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 594 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 595 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 596 |   private:
 | 
|---|
| 597 |         Type * type;
 | 
|---|
| 598 |         Initializer * initializer;
 | 
|---|
| 599 | };
 | 
|---|
| 600 | 
 | 
|---|
| 601 | /// ValofExpr represents a GCC 'lambda expression'
 | 
|---|
| 602 | class UntypedValofExpr : public Expression {
 | 
|---|
| 603 |   public:
 | 
|---|
| 604 |         UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}
 | 
|---|
| 605 |         UntypedValofExpr( const UntypedValofExpr & other );
 | 
|---|
| 606 |         virtual ~UntypedValofExpr();
 | 
|---|
| 607 | 
 | 
|---|
| 608 |         Expression * get_value();
 | 
|---|
| 609 |         Statement * get_body() const { return body; }
 | 
|---|
| 610 | 
 | 
|---|
| 611 |         virtual UntypedValofExpr * clone() const { return new UntypedValofExpr( * this ); }
 | 
|---|
| 612 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 613 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 614 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 615 |   private:
 | 
|---|
| 616 |         Statement * body;
 | 
|---|
| 617 | };
 | 
|---|
| 618 | 
 | 
|---|
| 619 | /// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
 | 
|---|
| 620 | class RangeExpr : public Expression {
 | 
|---|
| 621 |   public:
 | 
|---|
| 622 |         RangeExpr( Expression * low, Expression * high );
 | 
|---|
| 623 |         RangeExpr( const RangeExpr & other );
 | 
|---|
| 624 | 
 | 
|---|
| 625 |         Expression * get_low() const { return low; }
 | 
|---|
| 626 |         Expression * get_high() const { return high; }
 | 
|---|
| 627 |         RangeExpr * set_low( Expression * low ) { RangeExpr::low = low; return this; }
 | 
|---|
| 628 |         RangeExpr * set_high( Expression * high ) { RangeExpr::high = high; return this; }
 | 
|---|
| 629 | 
 | 
|---|
| 630 |         virtual RangeExpr * clone() const { return new RangeExpr( * this ); }
 | 
|---|
| 631 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 632 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 633 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 634 |   private:
 | 
|---|
| 635 |         Expression * low, * high;
 | 
|---|
| 636 | };
 | 
|---|
| 637 | 
 | 
|---|
| 638 | /// UntypedTupleExpr represents a tuple expression ( [a, b, c] ) before resolution
 | 
|---|
| 639 | class UntypedTupleExpr : public Expression {
 | 
|---|
| 640 |   public:
 | 
|---|
| 641 |         UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
 | 
|---|
| 642 |         UntypedTupleExpr( const UntypedTupleExpr & other );
 | 
|---|
| 643 |         virtual ~UntypedTupleExpr();
 | 
|---|
| 644 | 
 | 
|---|
| 645 |         std::list<Expression*>& get_exprs() { return exprs; }
 | 
|---|
| 646 | 
 | 
|---|
| 647 |         virtual UntypedTupleExpr * clone() const { return new UntypedTupleExpr( * this ); }
 | 
|---|
| 648 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 649 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 650 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 651 |   private:
 | 
|---|
| 652 |         std::list<Expression*> exprs;
 | 
|---|
| 653 | };
 | 
|---|
| 654 | 
 | 
|---|
| 655 | /// TupleExpr represents a tuple expression ( [a, b, c] )
 | 
|---|
| 656 | class TupleExpr : public Expression {
 | 
|---|
| 657 |   public:
 | 
|---|
| 658 |         TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
 | 
|---|
| 659 |         TupleExpr( const TupleExpr & other );
 | 
|---|
| 660 |         virtual ~TupleExpr();
 | 
|---|
| 661 | 
 | 
|---|
| 662 |         std::list<Expression*>& get_exprs() { return exprs; }
 | 
|---|
| 663 | 
 | 
|---|
| 664 |         virtual TupleExpr * clone() const { return new TupleExpr( * this ); }
 | 
|---|
| 665 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 666 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 667 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 668 |   private:
 | 
|---|
| 669 |         std::list<Expression*> exprs;
 | 
|---|
| 670 | };
 | 
|---|
| 671 | 
 | 
|---|
| 672 | /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer
 | 
|---|
| 673 | class TupleIndexExpr : public Expression {
 | 
|---|
| 674 |   public:
 | 
|---|
| 675 |         TupleIndexExpr( Expression * tuple, unsigned int index );
 | 
|---|
| 676 |         TupleIndexExpr( const TupleIndexExpr & other );
 | 
|---|
| 677 |         virtual ~TupleIndexExpr();
 | 
|---|
| 678 | 
 | 
|---|
| 679 |         Expression * get_tuple() const { return tuple; }
 | 
|---|
| 680 |         int get_index() const { return index; }
 | 
|---|
| 681 |         TupleIndexExpr * set_tuple( Expression * newValue ) { tuple = newValue; return this; }
 | 
|---|
| 682 |         TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; }
 | 
|---|
| 683 | 
 | 
|---|
| 684 |         virtual TupleIndexExpr * clone() const { return new TupleIndexExpr( * this ); }
 | 
|---|
| 685 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 686 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 687 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 688 |   private:
 | 
|---|
| 689 |         Expression * tuple;
 | 
|---|
| 690 |         unsigned int index;
 | 
|---|
| 691 | };
 | 
|---|
| 692 | 
 | 
|---|
| 693 | /// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer
 | 
|---|
| 694 | class MemberTupleExpr : public Expression {
 | 
|---|
| 695 |   public:
 | 
|---|
| 696 |         MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );
 | 
|---|
| 697 |         MemberTupleExpr( const MemberTupleExpr & other );
 | 
|---|
| 698 |         virtual ~MemberTupleExpr();
 | 
|---|
| 699 | 
 | 
|---|
| 700 |         Expression * get_member() const { return member; }
 | 
|---|
| 701 |         Expression * get_aggregate() const { return aggregate; }
 | 
|---|
| 702 |         MemberTupleExpr * set_member( Expression * newValue ) { member = newValue; return this; }
 | 
|---|
| 703 |         MemberTupleExpr * set_aggregate( Expression * newValue ) { aggregate = newValue; return this; }
 | 
|---|
| 704 | 
 | 
|---|
| 705 |         virtual MemberTupleExpr * clone() const { return new MemberTupleExpr( * this ); }
 | 
|---|
| 706 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 707 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 708 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 709 |   private:
 | 
|---|
| 710 |         Expression * member;
 | 
|---|
| 711 |         Expression * aggregate;
 | 
|---|
| 712 | };
 | 
|---|
| 713 | 
 | 
|---|
| 714 | /// 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
 | 
|---|
| 715 | class TupleAssignExpr : public Expression {
 | 
|---|
| 716 |   public:
 | 
|---|
| 717 |         TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
 | 
|---|
| 718 |         TupleAssignExpr( const TupleAssignExpr & other );
 | 
|---|
| 719 |         virtual ~TupleAssignExpr();
 | 
|---|
| 720 | 
 | 
|---|
| 721 |         TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; }
 | 
|---|
| 722 |         StmtExpr * get_stmtExpr() const { return stmtExpr; }
 | 
|---|
| 723 | 
 | 
|---|
| 724 |         virtual TupleAssignExpr * clone() const { return new TupleAssignExpr( * this ); }
 | 
|---|
| 725 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 726 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 727 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 728 |   private:
 | 
|---|
| 729 |         StmtExpr * stmtExpr = nullptr;
 | 
|---|
| 730 | };
 | 
|---|
| 731 | 
 | 
|---|
| 732 | /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; })
 | 
|---|
| 733 | class StmtExpr : public Expression {
 | 
|---|
| 734 | public:
 | 
|---|
| 735 |         StmtExpr( CompoundStmt * statements );
 | 
|---|
| 736 |         StmtExpr( const StmtExpr & other );
 | 
|---|
| 737 |         virtual ~StmtExpr();
 | 
|---|
| 738 | 
 | 
|---|
| 739 |         CompoundStmt * get_statements() const { return statements; }
 | 
|---|
| 740 |         StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
 | 
|---|
| 741 | 
 | 
|---|
| 742 |         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
 | 
|---|
| 743 |         std::list< Expression * > & get_dtors() { return dtors; }
 | 
|---|
| 744 | 
 | 
|---|
| 745 |         virtual StmtExpr * clone() const { return new StmtExpr( * this ); }
 | 
|---|
| 746 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 747 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 748 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 749 | private:
 | 
|---|
| 750 |         CompoundStmt * statements;
 | 
|---|
| 751 |         std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
 | 
|---|
| 752 |         std::list< Expression * > dtors; // destructor(s) for return variable(s)
 | 
|---|
| 753 | };
 | 
|---|
| 754 | 
 | 
|---|
| 755 | class UniqueExpr : public Expression {
 | 
|---|
| 756 | public:
 | 
|---|
| 757 |         UniqueExpr( Expression * expr, long long idVal = -1 );
 | 
|---|
| 758 |         UniqueExpr( const UniqueExpr & other );
 | 
|---|
| 759 |         ~UniqueExpr();
 | 
|---|
| 760 | 
 | 
|---|
| 761 |         Expression * get_expr() const { return expr; }
 | 
|---|
| 762 |         UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; }
 | 
|---|
| 763 | 
 | 
|---|
| 764 |         ObjectDecl * get_object() const { return object; }
 | 
|---|
| 765 |         UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; }
 | 
|---|
| 766 | 
 | 
|---|
| 767 |         VariableExpr * get_var() const { return var; }
 | 
|---|
| 768 |         UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; }
 | 
|---|
| 769 | 
 | 
|---|
| 770 |         int get_id() const { return id; }
 | 
|---|
| 771 | 
 | 
|---|
| 772 |         virtual UniqueExpr * clone() const { return new UniqueExpr( * this ); }
 | 
|---|
| 773 |         virtual void accept( Visitor & v ) { v.visit( this ); }
 | 
|---|
| 774 |         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 | 
|---|
| 775 |         virtual void print( std::ostream & os, int indent = 0 ) const;
 | 
|---|
| 776 | private:
 | 
|---|
| 777 |         Expression * expr;
 | 
|---|
| 778 |         ObjectDecl * object;
 | 
|---|
| 779 |         VariableExpr * var;
 | 
|---|
| 780 |         int id;
 | 
|---|
| 781 |         static long long count;
 | 
|---|
| 782 | };
 | 
|---|
| 783 | 
 | 
|---|
| 784 | std::ostream & operator<<( std::ostream & out, const Expression * expr );
 | 
|---|
| 785 | 
 | 
|---|
| 786 | #endif // EXPRESSION_H
 | 
|---|
| 787 | 
 | 
|---|
| 788 | // Local Variables: //
 | 
|---|
| 789 | // tab-width: 4 //
 | 
|---|
| 790 | // mode: c++ //
 | 
|---|
| 791 | // compile-command: "make install" //
 | 
|---|
| 792 | // End: //
 | 
|---|