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