[79f7875] | 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 | // Expr.hpp -- |
---|
| 8 | // |
---|
| 9 | // Author : Aaron B. Moss |
---|
| 10 | // Created On : Fri May 10 10:30:00 2019 |
---|
[312029a] | 11 | // Last Modified By : Peter A. Buhr |
---|
[79f7875] | 12 | // Created On : Fri May 10 10:30:00 2019 |
---|
[312029a] | 13 | // Update Count : 7 |
---|
[79f7875] | 14 | // |
---|
| 15 | |
---|
| 16 | #pragma once |
---|
| 17 | |
---|
| 18 | #include <cassert> |
---|
[60aaa51d] | 19 | #include <deque> |
---|
[79f7875] | 20 | #include <map> |
---|
[54e41b3] | 21 | #include <string> |
---|
[79f7875] | 22 | #include <utility> // for move |
---|
| 23 | #include <vector> |
---|
[c36298d] | 24 | #include <optional> |
---|
[79f7875] | 25 | |
---|
| 26 | #include "Fwd.hpp" // for UniqueId |
---|
[54e41b3] | 27 | #include "Label.hpp" |
---|
[312029a] | 28 | #include "Decl.hpp" |
---|
[79f7875] | 29 | #include "ParseNode.hpp" |
---|
[264e691] | 30 | #include "Visitor.hpp" |
---|
[79f7875] | 31 | |
---|
[f3cc5b6] | 32 | // Must be included in *all* AST classes; should be #undef'd at the end of the file |
---|
[99da267] | 33 | #define MUTATE_FRIEND \ |
---|
| 34 | template<typename node_t> friend node_t * mutate(const node_t * node); \ |
---|
| 35 | template<typename node_t> friend node_t * shallowCopy(const node_t * node); |
---|
| 36 | |
---|
[f3cc5b6] | 37 | |
---|
[20de6fb] | 38 | class ConverterOldToNew; |
---|
[c36298d] | 39 | class ConverterNewToOld; |
---|
[20de6fb] | 40 | |
---|
[79f7875] | 41 | namespace ast { |
---|
| 42 | |
---|
[6d51bd7] | 43 | /// Contains the ID of a declaration and a type that is derived from that declaration, |
---|
[79f7875] | 44 | /// but subject to decay-to-pointer and type parameter renaming |
---|
| 45 | struct ParamEntry { |
---|
| 46 | UniqueId decl; |
---|
[07d867b] | 47 | readonly<Decl> declptr; |
---|
[79f7875] | 48 | ptr<Type> actualType; |
---|
| 49 | ptr<Type> formalType; |
---|
| 50 | ptr<Expr> expr; |
---|
| 51 | |
---|
[aaeacf4] | 52 | ParamEntry() : decl( 0 ), declptr( nullptr ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {} |
---|
[7870799] | 53 | ParamEntry( |
---|
| 54 | UniqueId id, const Decl * declptr, const Type * actual, const Type * formal, |
---|
[b69233ac] | 55 | const Expr * e ) |
---|
[aaeacf4] | 56 | : decl( id ), declptr( declptr ), actualType( actual ), formalType( formal ), expr( e ) {} |
---|
[79f7875] | 57 | }; |
---|
| 58 | |
---|
| 59 | /// Pre-resolution list of parameters to infer |
---|
| 60 | using ResnSlots = std::vector<UniqueId>; |
---|
| 61 | /// Post-resolution map of inferred parameters |
---|
| 62 | using InferredParams = std::map< UniqueId, ParamEntry >; |
---|
| 63 | |
---|
| 64 | /// Base node for expressions |
---|
| 65 | class Expr : public ParseNode { |
---|
| 66 | public: |
---|
[07d867b] | 67 | /* |
---|
| 68 | * NOTE: the union approach is incorrect until the case of |
---|
| 69 | * partial resolution in InferMatcher is eliminated. |
---|
| 70 | * it is reverted to allow unresolved and resolved parameters |
---|
| 71 | * to coexist in an expression node. |
---|
| 72 | */ |
---|
[79f7875] | 73 | struct InferUnion { |
---|
[07d867b] | 74 | // mode is now unused |
---|
[79f7875] | 75 | enum { Empty, Slots, Params } mode; |
---|
[07d867b] | 76 | struct data_t { |
---|
| 77 | // char def; |
---|
| 78 | ResnSlots * resnSlots; |
---|
| 79 | InferredParams * inferParams; |
---|
| 80 | |
---|
| 81 | data_t(): resnSlots(nullptr), inferParams(nullptr) {} |
---|
| 82 | data_t(const data_t &other) = delete; |
---|
| 83 | ~data_t() { |
---|
| 84 | delete resnSlots; |
---|
| 85 | delete inferParams; |
---|
| 86 | } |
---|
[79f7875] | 87 | } data; |
---|
| 88 | |
---|
| 89 | /// initializes from other InferUnion |
---|
| 90 | void init_from( const InferUnion& o ) { |
---|
[07d867b] | 91 | if (o.data.resnSlots) { |
---|
| 92 | data.resnSlots = new ResnSlots(*o.data.resnSlots); |
---|
| 93 | } |
---|
| 94 | if (o.data.inferParams) { |
---|
| 95 | data.inferParams = new InferredParams(*o.data.inferParams); |
---|
[79f7875] | 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /// initializes from other InferUnion (move semantics) |
---|
| 100 | void init_from( InferUnion&& o ) { |
---|
[07d867b] | 101 | data.resnSlots = o.data.resnSlots; |
---|
| 102 | data.inferParams = o.data.inferParams; |
---|
| 103 | o.data.resnSlots = nullptr; |
---|
| 104 | o.data.inferParams = nullptr; |
---|
[79f7875] | 105 | } |
---|
| 106 | |
---|
| 107 | InferUnion() : mode(Empty), data() {} |
---|
| 108 | InferUnion( const InferUnion& o ) : mode( o.mode ), data() { init_from( o ); } |
---|
| 109 | InferUnion( InferUnion&& o ) : mode( o.mode ), data() { init_from( std::move(o) ); } |
---|
| 110 | InferUnion& operator= ( const InferUnion& ) = delete; |
---|
| 111 | InferUnion& operator= ( InferUnion&& ) = delete; |
---|
[07d867b] | 112 | |
---|
| 113 | bool hasSlots() const { return data.resnSlots; } |
---|
[79f7875] | 114 | |
---|
| 115 | ResnSlots& resnSlots() { |
---|
[07d867b] | 116 | if (!data.resnSlots) { |
---|
| 117 | data.resnSlots = new ResnSlots(); |
---|
[79f7875] | 118 | } |
---|
[07d867b] | 119 | return *data.resnSlots; |
---|
[19e567dd] | 120 | } |
---|
| 121 | |
---|
[60aaa51d] | 122 | const ResnSlots& resnSlots() const { |
---|
[07d867b] | 123 | if (data.resnSlots) { |
---|
| 124 | return *data.resnSlots; |
---|
[19e567dd] | 125 | } |
---|
[7870799] | 126 | assertf(false, "Mode was not already resnSlots"); |
---|
| 127 | abort(); |
---|
[79f7875] | 128 | } |
---|
| 129 | |
---|
| 130 | InferredParams& inferParams() { |
---|
[07d867b] | 131 | if (!data.inferParams) { |
---|
| 132 | data.inferParams = new InferredParams(); |
---|
[79f7875] | 133 | } |
---|
[07d867b] | 134 | return *data.inferParams; |
---|
[19e567dd] | 135 | } |
---|
| 136 | |
---|
[60aaa51d] | 137 | const InferredParams& inferParams() const { |
---|
[07d867b] | 138 | if (data.inferParams) { |
---|
| 139 | return *data.inferParams; |
---|
[19e567dd] | 140 | } |
---|
[7870799] | 141 | assertf(false, "Mode was not already Params"); |
---|
| 142 | abort(); |
---|
[79f7875] | 143 | } |
---|
[60aaa51d] | 144 | |
---|
[07d867b] | 145 | void set_inferParams( InferredParams * ps ) { |
---|
| 146 | delete data.resnSlots; |
---|
| 147 | data.resnSlots = nullptr; |
---|
| 148 | delete data.inferParams; |
---|
| 149 | data.inferParams = ps; |
---|
[b69233ac] | 150 | } |
---|
| 151 | |
---|
[aaeacf4] | 152 | /// splices other InferUnion into this one. Will fail if one union is in `Slots` mode |
---|
[60aaa51d] | 153 | /// and the other is in `Params`. |
---|
| 154 | void splice( InferUnion && o ) { |
---|
[07d867b] | 155 | if (o.data.resnSlots) { |
---|
| 156 | if (data.resnSlots) { |
---|
| 157 | data.resnSlots->insert( |
---|
| 158 | data.resnSlots->end(), o.data.resnSlots->begin(), o.data.resnSlots->end() ); |
---|
| 159 | delete o.data.resnSlots; |
---|
| 160 | } |
---|
| 161 | else { |
---|
| 162 | data.resnSlots = o.data.resnSlots; |
---|
[60aaa51d] | 163 | } |
---|
[07d867b] | 164 | o.data.resnSlots = nullptr; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | if (o.data.inferParams) { |
---|
| 168 | if (data.inferParams) { |
---|
| 169 | for ( const auto & p : *o.data.inferParams ) { |
---|
| 170 | (*data.inferParams)[p.first] = std::move(p.second); |
---|
| 171 | } |
---|
| 172 | delete o.data.inferParams; |
---|
| 173 | } |
---|
| 174 | else { |
---|
| 175 | data.inferParams = o.data.inferParams; |
---|
| 176 | } |
---|
| 177 | o.data.inferParams = nullptr; |
---|
| 178 | } |
---|
[60aaa51d] | 179 | } |
---|
[79f7875] | 180 | }; |
---|
| 181 | |
---|
| 182 | ptr<Type> result; |
---|
| 183 | ptr<TypeSubstitution> env; |
---|
| 184 | InferUnion inferred; |
---|
| 185 | bool extension = false; |
---|
| 186 | |
---|
[54e41b3] | 187 | Expr( const CodeLocation & loc, const Type * res = nullptr ) |
---|
| 188 | : ParseNode( loc ), result( res ), env(), inferred() {} |
---|
[79f7875] | 189 | |
---|
[9e1d485] | 190 | Expr * set_extension( bool ex ) { extension = ex; return this; } |
---|
[cf32116] | 191 | virtual bool get_lvalue() const; |
---|
[79f7875] | 192 | |
---|
[69bafd2] | 193 | virtual const Expr * accept( Visitor & v ) const override = 0; |
---|
[79f7875] | 194 | private: |
---|
[23f99e1] | 195 | Expr * clone() const override = 0; |
---|
[f3cc5b6] | 196 | MUTATE_FRIEND |
---|
[264e691] | 197 | }; |
---|
| 198 | |
---|
[87701b6] | 199 | /// The application of a function to a set of parameters. |
---|
[54e41b3] | 200 | /// Post-resolver form of `UntypedExpr` |
---|
| 201 | class ApplicationExpr final : public Expr { |
---|
| 202 | public: |
---|
| 203 | ptr<Expr> func; |
---|
| 204 | std::vector<ptr<Expr>> args; |
---|
| 205 | |
---|
| 206 | ApplicationExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} ); |
---|
| 207 | |
---|
[cf32116] | 208 | bool get_lvalue() const final; |
---|
| 209 | |
---|
[54e41b3] | 210 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 211 | private: |
---|
| 212 | ApplicationExpr * clone() const override { return new ApplicationExpr{ *this }; } |
---|
[f3cc5b6] | 213 | MUTATE_FRIEND |
---|
[54e41b3] | 214 | }; |
---|
| 215 | |
---|
| 216 | /// The application of a function to a set of parameters, pre-overload resolution. |
---|
| 217 | class UntypedExpr final : public Expr { |
---|
| 218 | public: |
---|
| 219 | ptr<Expr> func; |
---|
| 220 | std::vector<ptr<Expr>> args; |
---|
| 221 | |
---|
| 222 | UntypedExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} ) |
---|
| 223 | : Expr( loc ), func( f ), args( std::move(as) ) {} |
---|
| 224 | |
---|
[cf32116] | 225 | bool get_lvalue() const final; |
---|
| 226 | |
---|
[54e41b3] | 227 | /// Creates a new dereference expression |
---|
| 228 | static UntypedExpr * createDeref( const CodeLocation & loc, Expr * arg ); |
---|
| 229 | /// Creates a new assignment expression |
---|
| 230 | static UntypedExpr * createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs ); |
---|
| 231 | |
---|
| 232 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 233 | private: |
---|
| 234 | UntypedExpr * clone() const override { return new UntypedExpr{ *this }; } |
---|
[f3cc5b6] | 235 | MUTATE_FRIEND |
---|
[54e41b3] | 236 | }; |
---|
| 237 | |
---|
| 238 | /// A name whose name is as-yet undetermined. |
---|
| 239 | /// May also be used to avoid name mangling in codegen phase. |
---|
| 240 | class NameExpr final : public Expr { |
---|
| 241 | public: |
---|
| 242 | std::string name; |
---|
| 243 | |
---|
| 244 | NameExpr( const CodeLocation & loc, const std::string & n ) : Expr( loc ), name( n ) {} |
---|
| 245 | |
---|
| 246 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 247 | private: |
---|
| 248 | NameExpr * clone() const override { return new NameExpr{ *this }; } |
---|
[f3cc5b6] | 249 | MUTATE_FRIEND |
---|
[54e41b3] | 250 | }; |
---|
| 251 | |
---|
| 252 | /// Address-of expression `&e` |
---|
| 253 | class AddressExpr final : public Expr { |
---|
| 254 | public: |
---|
| 255 | ptr<Expr> arg; |
---|
| 256 | |
---|
| 257 | AddressExpr( const CodeLocation & loc, const Expr * a ); |
---|
| 258 | |
---|
[b8524ca] | 259 | /// Generate AddressExpr wrapping given expression at same location |
---|
| 260 | AddressExpr( const Expr * a ) : AddressExpr( a->location, a ) {} |
---|
| 261 | |
---|
[54e41b3] | 262 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 263 | private: |
---|
| 264 | AddressExpr * clone() const override { return new AddressExpr{ *this }; } |
---|
[f3cc5b6] | 265 | MUTATE_FRIEND |
---|
[54e41b3] | 266 | }; |
---|
| 267 | |
---|
| 268 | /// GCC &&label |
---|
| 269 | /// https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html |
---|
| 270 | class LabelAddressExpr final : public Expr { |
---|
| 271 | public: |
---|
| 272 | Label arg; |
---|
| 273 | |
---|
| 274 | LabelAddressExpr( const CodeLocation & loc, Label && a ); |
---|
| 275 | |
---|
| 276 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 277 | private: |
---|
| 278 | LabelAddressExpr * clone() const override { return new LabelAddressExpr{ *this }; } |
---|
[f3cc5b6] | 279 | MUTATE_FRIEND |
---|
[54e41b3] | 280 | }; |
---|
| 281 | |
---|
| 282 | /// Whether a cast existed in the program source or not |
---|
| 283 | enum GeneratedFlag { ExplicitCast, GeneratedCast }; |
---|
| 284 | |
---|
| 285 | /// A type cast, e.g. `(int)e` |
---|
| 286 | class CastExpr final : public Expr { |
---|
| 287 | public: |
---|
| 288 | ptr<Expr> arg; |
---|
| 289 | GeneratedFlag isGenerated; |
---|
| 290 | |
---|
[87701b6] | 291 | CastExpr( const CodeLocation & loc, const Expr * a, const Type * to, |
---|
[54e41b3] | 292 | GeneratedFlag g = GeneratedCast ) : Expr( loc, to ), arg( a ), isGenerated( g ) {} |
---|
| 293 | /// Cast-to-void |
---|
| 294 | CastExpr( const CodeLocation & loc, const Expr * a, GeneratedFlag g = GeneratedCast ); |
---|
| 295 | |
---|
[b8524ca] | 296 | /// Wrap a cast expression around an existing expression (always generated) |
---|
| 297 | CastExpr( const Expr * a, const Type * to ) : CastExpr( a->location, a, to, GeneratedCast ) {} |
---|
| 298 | |
---|
| 299 | /// Wrap a cast-to-void expression around an existing expression (always generated) |
---|
| 300 | CastExpr( const Expr * a ) : CastExpr( a->location, a, GeneratedCast ) {} |
---|
| 301 | |
---|
[cf32116] | 302 | bool get_lvalue() const final; |
---|
| 303 | |
---|
[54e41b3] | 304 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 305 | private: |
---|
| 306 | CastExpr * clone() const override { return new CastExpr{ *this }; } |
---|
[f3cc5b6] | 307 | MUTATE_FRIEND |
---|
[54e41b3] | 308 | }; |
---|
| 309 | |
---|
| 310 | /// A cast to "keyword types", e.g. `(thread &)t` |
---|
| 311 | class KeywordCastExpr final : public Expr { |
---|
| 312 | public: |
---|
| 313 | ptr<Expr> arg; |
---|
[312029a] | 314 | ast::AggregateDecl::Aggregate target; |
---|
[54e41b3] | 315 | |
---|
[312029a] | 316 | KeywordCastExpr( const CodeLocation & loc, const Expr * a, ast::AggregateDecl::Aggregate t ) |
---|
[54e41b3] | 317 | : Expr( loc ), arg( a ), target( t ) {} |
---|
| 318 | |
---|
| 319 | /// Get a name for the target type |
---|
[312029a] | 320 | const char * targetString() const; |
---|
[54e41b3] | 321 | |
---|
| 322 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 323 | private: |
---|
| 324 | KeywordCastExpr * clone() const override { return new KeywordCastExpr{ *this }; } |
---|
[f3cc5b6] | 325 | MUTATE_FRIEND |
---|
[54e41b3] | 326 | }; |
---|
| 327 | |
---|
| 328 | /// A virtual dynamic cast, e.g. `(virtual exception)e` |
---|
| 329 | class VirtualCastExpr final : public Expr { |
---|
| 330 | public: |
---|
| 331 | ptr<Expr> arg; |
---|
| 332 | |
---|
| 333 | VirtualCastExpr( const CodeLocation & loc, const Expr * a, const Type * to ) |
---|
| 334 | : Expr( loc, to ), arg( a ) {} |
---|
| 335 | |
---|
| 336 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 337 | private: |
---|
| 338 | VirtualCastExpr * clone() const override { return new VirtualCastExpr{ *this }; } |
---|
[f3cc5b6] | 339 | MUTATE_FRIEND |
---|
[54e41b3] | 340 | }; |
---|
| 341 | |
---|
| 342 | /// A member selection operation before expression resolution, e.g. `q.p` |
---|
| 343 | class UntypedMemberExpr final : public Expr { |
---|
| 344 | public: |
---|
| 345 | ptr<Expr> member; |
---|
| 346 | ptr<Expr> aggregate; |
---|
| 347 | |
---|
| 348 | UntypedMemberExpr( const CodeLocation & loc, const Expr * mem, const Expr * agg ) |
---|
| 349 | : Expr( loc ), member( mem ), aggregate( agg ) { assert( aggregate ); } |
---|
| 350 | |
---|
[cf32116] | 351 | bool get_lvalue() const final; |
---|
| 352 | |
---|
[54e41b3] | 353 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 354 | private: |
---|
| 355 | UntypedMemberExpr * clone() const override { return new UntypedMemberExpr{ *this }; } |
---|
[f3cc5b6] | 356 | MUTATE_FRIEND |
---|
[54e41b3] | 357 | }; |
---|
| 358 | |
---|
| 359 | /// A member selection operation after expression resolution, e.g. `q.p` |
---|
| 360 | class MemberExpr final : public Expr { |
---|
| 361 | public: |
---|
| 362 | readonly<DeclWithType> member; |
---|
| 363 | ptr<Expr> aggregate; |
---|
| 364 | |
---|
| 365 | MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg ); |
---|
| 366 | |
---|
[cf32116] | 367 | bool get_lvalue() const final; |
---|
| 368 | |
---|
[54e41b3] | 369 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 370 | private: |
---|
| 371 | MemberExpr * clone() const override { return new MemberExpr{ *this }; } |
---|
[f3cc5b6] | 372 | MUTATE_FRIEND |
---|
[ae265b55] | 373 | |
---|
| 374 | // Custructor overload meant only for AST conversion |
---|
| 375 | enum NoOpConstruction { NoOpConstructionChosen }; |
---|
| 376 | MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg, |
---|
| 377 | NoOpConstruction overloadSelector ); |
---|
| 378 | friend class ::ConverterOldToNew; |
---|
| 379 | friend class ::ConverterNewToOld; |
---|
[54e41b3] | 380 | }; |
---|
| 381 | |
---|
| 382 | /// A reference to a named variable. |
---|
| 383 | class VariableExpr final : public Expr { |
---|
| 384 | public: |
---|
| 385 | readonly<DeclWithType> var; |
---|
| 386 | |
---|
[546e712] | 387 | VariableExpr( const CodeLocation & loc ); |
---|
[54e41b3] | 388 | VariableExpr( const CodeLocation & loc, const DeclWithType * v ); |
---|
| 389 | |
---|
[cf32116] | 390 | bool get_lvalue() const final; |
---|
| 391 | |
---|
[54e41b3] | 392 | /// generates a function pointer for a given function |
---|
| 393 | static VariableExpr * functionPointer( const CodeLocation & loc, const FunctionDecl * decl ); |
---|
| 394 | |
---|
| 395 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 396 | private: |
---|
| 397 | VariableExpr * clone() const override { return new VariableExpr{ *this }; } |
---|
[f3cc5b6] | 398 | MUTATE_FRIEND |
---|
[54e41b3] | 399 | }; |
---|
| 400 | |
---|
[c36298d] | 401 | /// A compile-time constant. |
---|
| 402 | /// Mostly carries C-source text from parse to code-gen, without interpretation. E.g. strings keep their outer quotes and never have backslashes interpreted. |
---|
| 403 | /// Integer constants get special treatment, e.g. for verifying array operations, when an integer constant occurs as the length of an array. |
---|
[54e41b3] | 404 | class ConstantExpr final : public Expr { |
---|
| 405 | public: |
---|
[c36298d] | 406 | // Representation of this constant, as it occurs in .cfa source and .cfa.cc result. |
---|
[54e41b3] | 407 | std::string rep; |
---|
| 408 | |
---|
[87701b6] | 409 | ConstantExpr( |
---|
[7870799] | 410 | const CodeLocation & loc, const Type * ty, const std::string & r, |
---|
[c36298d] | 411 | std::optional<unsigned long long> i ) |
---|
| 412 | : Expr( loc, ty ), rep( r ), ival( i ) {} |
---|
[87701b6] | 413 | |
---|
[c36298d] | 414 | /// Gets the integer value of this constant, if one is appropriate to its type. |
---|
| 415 | /// Throws a SemanticError if the type is not appropriate for value-as-integer. |
---|
| 416 | /// Suffers an assertion failure the type is appropriate but no integer value was supplied to the constructor. |
---|
[54e41b3] | 417 | long long int intValue() const; |
---|
| 418 | |
---|
| 419 | /// generates a boolean constant of the given bool |
---|
| 420 | static ConstantExpr * from_bool( const CodeLocation & loc, bool b ); |
---|
| 421 | /// generates an integer constant of the given int |
---|
| 422 | static ConstantExpr * from_int( const CodeLocation & loc, int i ); |
---|
| 423 | /// generates an integer constant of the given unsigned long int |
---|
| 424 | static ConstantExpr * from_ulong( const CodeLocation & loc, unsigned long i ); |
---|
| 425 | /// generates a null pointer value for the given type. void * if omitted. |
---|
| 426 | static ConstantExpr * null( const CodeLocation & loc, const Type * ptrType = nullptr ); |
---|
| 427 | |
---|
| 428 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 429 | private: |
---|
| 430 | ConstantExpr * clone() const override { return new ConstantExpr{ *this }; } |
---|
[f3cc5b6] | 431 | MUTATE_FRIEND |
---|
[c36298d] | 432 | |
---|
| 433 | std::optional<unsigned long long> ival; |
---|
| 434 | |
---|
| 435 | // Intended only for legacy support of roundtripping the old AST. |
---|
| 436 | // Captures the very-locally inferred type, before the resolver modifies the type of this ConstantExpression. |
---|
| 437 | // In the old AST it's constExpr->constant.type |
---|
| 438 | ptr<Type> underlyer; |
---|
| 439 | friend class ::ConverterOldToNew; |
---|
| 440 | friend class ::ConverterNewToOld; |
---|
[54e41b3] | 441 | }; |
---|
| 442 | |
---|
| 443 | /// sizeof expression, e.g. `sizeof(int)`, `sizeof 3+4` |
---|
| 444 | class SizeofExpr final : public Expr { |
---|
| 445 | public: |
---|
| 446 | ptr<Expr> expr; |
---|
| 447 | ptr<Type> type; |
---|
| 448 | |
---|
| 449 | SizeofExpr( const CodeLocation & loc, const Expr * e ); |
---|
| 450 | SizeofExpr( const CodeLocation & loc, const Type * t ); |
---|
| 451 | // deliberately no disambiguating overload for nullptr_t |
---|
| 452 | |
---|
| 453 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 454 | private: |
---|
| 455 | SizeofExpr * clone() const override { return new SizeofExpr{ *this }; } |
---|
[f3cc5b6] | 456 | MUTATE_FRIEND |
---|
[54e41b3] | 457 | }; |
---|
| 458 | |
---|
| 459 | /// alignof expression, e.g. `alignof(int)`, `alignof 3+4` |
---|
| 460 | class AlignofExpr final : public Expr { |
---|
| 461 | public: |
---|
| 462 | ptr<Expr> expr; |
---|
| 463 | ptr<Type> type; |
---|
| 464 | |
---|
| 465 | AlignofExpr( const CodeLocation & loc, const Expr * e ); |
---|
| 466 | AlignofExpr( const CodeLocation & loc, const Type * t ); |
---|
| 467 | // deliberately no disambiguating overload for nullptr_t |
---|
| 468 | |
---|
| 469 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 470 | private: |
---|
| 471 | AlignofExpr * clone() const override { return new AlignofExpr{ *this }; } |
---|
[f3cc5b6] | 472 | MUTATE_FRIEND |
---|
[54e41b3] | 473 | }; |
---|
| 474 | |
---|
| 475 | /// offsetof expression before resolver determines field, e.g. `offsetof(MyStruct, myfield)` |
---|
| 476 | class UntypedOffsetofExpr final : public Expr { |
---|
| 477 | public: |
---|
| 478 | ptr<Type> type; |
---|
| 479 | std::string member; |
---|
| 480 | |
---|
| 481 | UntypedOffsetofExpr( const CodeLocation & loc, const Type * ty, const std::string & mem ) |
---|
| 482 | : Expr( loc ), type( ty ), member( mem ) {} |
---|
| 483 | |
---|
| 484 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 485 | private: |
---|
| 486 | UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr{ *this }; } |
---|
[f3cc5b6] | 487 | MUTATE_FRIEND |
---|
[54e41b3] | 488 | }; |
---|
| 489 | |
---|
| 490 | /// offsetof expression after resolver determines field, e.g. `offsetof(MyStruct, myfield)` |
---|
| 491 | class OffsetofExpr final : public Expr { |
---|
| 492 | public: |
---|
| 493 | ptr<Type> type; |
---|
| 494 | readonly<DeclWithType> member; |
---|
| 495 | |
---|
| 496 | OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem ); |
---|
| 497 | |
---|
| 498 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 499 | private: |
---|
| 500 | OffsetofExpr * clone() const override { return new OffsetofExpr{ *this }; } |
---|
[f3cc5b6] | 501 | MUTATE_FRIEND |
---|
[54e41b3] | 502 | }; |
---|
| 503 | |
---|
| 504 | /// a pack of field-offsets for a generic type |
---|
| 505 | class OffsetPackExpr final : public Expr { |
---|
| 506 | public: |
---|
| 507 | ptr<StructInstType> type; |
---|
| 508 | |
---|
| 509 | OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty ); |
---|
| 510 | |
---|
| 511 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 512 | private: |
---|
| 513 | OffsetPackExpr * clone() const override { return new OffsetPackExpr{ *this }; } |
---|
[f3cc5b6] | 514 | MUTATE_FRIEND |
---|
[54e41b3] | 515 | }; |
---|
| 516 | |
---|
| 517 | /// Variants of short-circuiting logical expression |
---|
| 518 | enum LogicalFlag { OrExpr, AndExpr }; |
---|
| 519 | |
---|
| 520 | /// Short-circuiting boolean expression (`&&` or `||`) |
---|
| 521 | class LogicalExpr final : public Expr { |
---|
| 522 | public: |
---|
| 523 | ptr<Expr> arg1; |
---|
| 524 | ptr<Expr> arg2; |
---|
| 525 | LogicalFlag isAnd; |
---|
| 526 | |
---|
| 527 | LogicalExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia ); |
---|
| 528 | |
---|
| 529 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 530 | private: |
---|
| 531 | LogicalExpr * clone() const override { return new LogicalExpr{ *this }; } |
---|
[f3cc5b6] | 532 | MUTATE_FRIEND |
---|
[54e41b3] | 533 | }; |
---|
| 534 | |
---|
| 535 | /// Three-argument conditional e.g. `p ? a : b` |
---|
| 536 | class ConditionalExpr final : public Expr { |
---|
| 537 | public: |
---|
| 538 | ptr<Expr> arg1; |
---|
| 539 | ptr<Expr> arg2; |
---|
| 540 | ptr<Expr> arg3; |
---|
| 541 | |
---|
| 542 | ConditionalExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2, const Expr * a3 ) |
---|
| 543 | : Expr( loc ), arg1( a1 ), arg2( a2 ), arg3( a3 ) {} |
---|
| 544 | |
---|
| 545 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 546 | private: |
---|
| 547 | ConditionalExpr * clone() const override { return new ConditionalExpr{ *this }; } |
---|
[f3cc5b6] | 548 | MUTATE_FRIEND |
---|
[54e41b3] | 549 | }; |
---|
| 550 | |
---|
| 551 | /// Comma expression e.g. `( a , b )` |
---|
| 552 | class CommaExpr final : public Expr { |
---|
| 553 | public: |
---|
| 554 | ptr<Expr> arg1; |
---|
| 555 | ptr<Expr> arg2; |
---|
| 556 | |
---|
[87701b6] | 557 | CommaExpr( const CodeLocation & loc, const Expr * a1, const Expr * a2 ) |
---|
[4e13e2a] | 558 | : Expr( loc ), arg1( a1 ), arg2( a2 ) { |
---|
| 559 | this->result = a2->result; |
---|
| 560 | } |
---|
[54e41b3] | 561 | |
---|
[cf32116] | 562 | bool get_lvalue() const final; |
---|
| 563 | |
---|
[54e41b3] | 564 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 565 | private: |
---|
| 566 | CommaExpr * clone() const override { return new CommaExpr{ *this }; } |
---|
[f3cc5b6] | 567 | MUTATE_FRIEND |
---|
[54e41b3] | 568 | }; |
---|
| 569 | |
---|
[264e691] | 570 | /// A type used as an expression (e.g. a type generator parameter) |
---|
| 571 | class TypeExpr final : public Expr { |
---|
| 572 | public: |
---|
| 573 | ptr<Type> type; |
---|
| 574 | |
---|
| 575 | TypeExpr( const CodeLocation & loc, const Type * t ) : Expr(loc), type(t) {} |
---|
| 576 | |
---|
[69bafd2] | 577 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[264e691] | 578 | private: |
---|
| 579 | TypeExpr * clone() const override { return new TypeExpr{ *this }; } |
---|
[f3cc5b6] | 580 | MUTATE_FRIEND |
---|
[79f7875] | 581 | }; |
---|
| 582 | |
---|
[54e41b3] | 583 | /// A GCC "asm constraint operand" used in an asm statement, e.g. `[output] "=f" (result)`. |
---|
| 584 | /// https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints |
---|
| 585 | class AsmExpr final : public Expr { |
---|
| 586 | public: |
---|
[665f432] | 587 | std::string inout; |
---|
[9b4f329] | 588 | ptr<Expr> constraint; |
---|
| 589 | ptr<Expr> operand; |
---|
| 590 | |
---|
[665f432] | 591 | AsmExpr( const CodeLocation & loc, const std::string & io, const Expr * con, const Expr * op ) |
---|
[9b4f329] | 592 | : Expr( loc ), inout( io ), constraint( con ), operand( op ) {} |
---|
| 593 | |
---|
| 594 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 595 | private: |
---|
| 596 | AsmExpr * clone() const override { return new AsmExpr{ *this }; } |
---|
| 597 | MUTATE_FRIEND |
---|
| 598 | }; |
---|
| 599 | |
---|
[17a0228a] | 600 | /// The application of a function to a set of parameters, along with a set of copy constructor |
---|
[9b4f329] | 601 | /// calls, one for each argument |
---|
| 602 | class ImplicitCopyCtorExpr final : public Expr { |
---|
| 603 | public: |
---|
| 604 | ptr<ApplicationExpr> callExpr; |
---|
| 605 | |
---|
| 606 | ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call ) |
---|
[d908563] | 607 | : Expr( loc, call->result ) { assert( call ); } |
---|
[9b4f329] | 608 | |
---|
| 609 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 610 | private: |
---|
| 611 | ImplicitCopyCtorExpr * clone() const override { return new ImplicitCopyCtorExpr{ *this }; } |
---|
| 612 | MUTATE_FRIEND |
---|
| 613 | }; |
---|
| 614 | |
---|
| 615 | /// Constructor in expression context, e.g. `int * x = alloc() { 42 };` |
---|
| 616 | class ConstructorExpr final : public Expr { |
---|
| 617 | public: |
---|
| 618 | ptr<Expr> callExpr; |
---|
| 619 | |
---|
| 620 | ConstructorExpr( const CodeLocation & loc, const Expr * call ); |
---|
| 621 | |
---|
| 622 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 623 | private: |
---|
| 624 | ConstructorExpr * clone() const override { return new ConstructorExpr{ *this }; } |
---|
| 625 | MUTATE_FRIEND |
---|
| 626 | }; |
---|
| 627 | |
---|
| 628 | /// A C99 compound literal, e.g. `(MyType){ a, b, c }` |
---|
| 629 | class CompoundLiteralExpr final : public Expr { |
---|
| 630 | public: |
---|
| 631 | ptr<Init> init; |
---|
| 632 | |
---|
| 633 | CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i ); |
---|
| 634 | |
---|
[cf32116] | 635 | bool get_lvalue() const final; |
---|
| 636 | |
---|
[9b4f329] | 637 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 638 | private: |
---|
| 639 | CompoundLiteralExpr * clone() const override { return new CompoundLiteralExpr{ *this }; } |
---|
| 640 | MUTATE_FRIEND |
---|
| 641 | }; |
---|
| 642 | |
---|
| 643 | /// A range, e.g. `3 ... 5` or `1~10` |
---|
| 644 | class RangeExpr final : public Expr { |
---|
| 645 | public: |
---|
| 646 | ptr<Expr> low; |
---|
| 647 | ptr<Expr> high; |
---|
| 648 | |
---|
| 649 | RangeExpr( const CodeLocation & loc, const Expr * l, const Expr * h ) |
---|
| 650 | : Expr( loc ), low( l ), high( h ) {} |
---|
| 651 | |
---|
| 652 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 653 | private: |
---|
| 654 | RangeExpr * clone() const override { return new RangeExpr{ *this }; } |
---|
| 655 | MUTATE_FRIEND |
---|
| 656 | }; |
---|
| 657 | |
---|
| 658 | /// A tuple expression before resolution, e.g. `[a, b, c]` |
---|
| 659 | class UntypedTupleExpr final : public Expr { |
---|
| 660 | public: |
---|
| 661 | std::vector<ptr<Expr>> exprs; |
---|
| 662 | |
---|
| 663 | UntypedTupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ) |
---|
| 664 | : Expr( loc ), exprs( std::move(xs) ) {} |
---|
| 665 | |
---|
| 666 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 667 | private: |
---|
| 668 | UntypedTupleExpr * clone() const override { return new UntypedTupleExpr{ *this }; } |
---|
| 669 | MUTATE_FRIEND |
---|
| 670 | }; |
---|
| 671 | |
---|
| 672 | /// A tuple expression after resolution, e.g. `[a, b, c]` |
---|
| 673 | class TupleExpr final : public Expr { |
---|
| 674 | public: |
---|
| 675 | std::vector<ptr<Expr>> exprs; |
---|
| 676 | |
---|
| 677 | TupleExpr( const CodeLocation & loc, std::vector<ptr<Expr>> && xs ); |
---|
| 678 | |
---|
| 679 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 680 | private: |
---|
| 681 | TupleExpr * clone() const override { return new TupleExpr{ *this }; } |
---|
| 682 | MUTATE_FRIEND |
---|
| 683 | }; |
---|
| 684 | |
---|
| 685 | /// An element selection operation on a tuple value, e.g. `t.3` after analysis |
---|
| 686 | class TupleIndexExpr final : public Expr { |
---|
| 687 | public: |
---|
| 688 | ptr<Expr> tuple; |
---|
| 689 | unsigned index; |
---|
| 690 | |
---|
| 691 | TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ); |
---|
| 692 | |
---|
[cf32116] | 693 | bool get_lvalue() const final; |
---|
| 694 | |
---|
[9b4f329] | 695 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 696 | private: |
---|
| 697 | TupleIndexExpr * clone() const override { return new TupleIndexExpr{ *this }; } |
---|
| 698 | MUTATE_FRIEND |
---|
| 699 | }; |
---|
| 700 | |
---|
[17a0228a] | 701 | /// A multiple- or mass-assignment operation, or a tuple ctor/dtor expression. |
---|
| 702 | /// multiple-assignment: both sides of the assignment have tuple type, |
---|
[9b4f329] | 703 | /// e.g. `[a, b, c] = [d, e, f];` |
---|
| 704 | /// mass-assignment: left-hand side has tuple type and right-hand side does not: |
---|
| 705 | /// e.g. `[a, b, c] = 42;` |
---|
| 706 | class TupleAssignExpr final : public Expr { |
---|
| 707 | public: |
---|
| 708 | ptr<StmtExpr> stmtExpr; |
---|
| 709 | |
---|
[17a0228a] | 710 | TupleAssignExpr( |
---|
| 711 | const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, |
---|
[9b4f329] | 712 | std::vector<ptr<ObjectDecl>> && tempDecls ); |
---|
[17a0228a] | 713 | |
---|
[9b4f329] | 714 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[20de6fb] | 715 | |
---|
| 716 | friend class ::ConverterOldToNew; |
---|
| 717 | |
---|
[9b4f329] | 718 | private: |
---|
| 719 | TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; } |
---|
[20de6fb] | 720 | TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s ); |
---|
| 721 | |
---|
[9b4f329] | 722 | MUTATE_FRIEND |
---|
| 723 | }; |
---|
| 724 | |
---|
| 725 | /// A GCC "statement expression", e.g. `({ int x = 5; x })` |
---|
| 726 | class StmtExpr final : public Expr { |
---|
| 727 | public: |
---|
| 728 | ptr<CompoundStmt> stmts; |
---|
| 729 | std::vector<ptr<ObjectDecl>> returnDecls; ///< return variable(s) for statement expression |
---|
| 730 | std::vector<ptr<Expr>> dtors; ///< destructor(s) for return variable(s) |
---|
| 731 | |
---|
| 732 | StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ); |
---|
| 733 | |
---|
| 734 | /// Set the result type of this StmtExpr based on its body |
---|
| 735 | void computeResult(); |
---|
| 736 | |
---|
| 737 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 738 | private: |
---|
| 739 | StmtExpr * clone() const override { return new StmtExpr{ *this }; } |
---|
| 740 | MUTATE_FRIEND |
---|
| 741 | }; |
---|
| 742 | |
---|
| 743 | /// An expression which must only be evaluated once |
---|
| 744 | class UniqueExpr final : public Expr { |
---|
| 745 | static unsigned long long nextId; |
---|
| 746 | public: |
---|
| 747 | ptr<Expr> expr; |
---|
| 748 | ptr<ObjectDecl> object; |
---|
| 749 | ptr<VariableExpr> var; |
---|
| 750 | unsigned long long id; |
---|
| 751 | |
---|
[d76f32c] | 752 | UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1ull ); |
---|
[9b4f329] | 753 | |
---|
| 754 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 755 | private: |
---|
| 756 | UniqueExpr * clone() const override { return new UniqueExpr{ *this }; } |
---|
| 757 | MUTATE_FRIEND |
---|
| 758 | }; |
---|
| 759 | |
---|
| 760 | /// One option for resolving an initializer expression |
---|
| 761 | struct InitAlternative { |
---|
| 762 | ptr<Type> type; |
---|
| 763 | ptr<Designation> designation; |
---|
| 764 | |
---|
| 765 | InitAlternative() = default; |
---|
| 766 | InitAlternative( const Type * ty, const Designation * des ) : type( ty ), designation( des ) {} |
---|
| 767 | }; |
---|
| 768 | |
---|
| 769 | /// Pre-resolution initializer expression |
---|
| 770 | class UntypedInitExpr final : public Expr { |
---|
| 771 | public: |
---|
| 772 | ptr<Expr> expr; |
---|
[60aaa51d] | 773 | std::deque<InitAlternative> initAlts; |
---|
[9b4f329] | 774 | |
---|
[60aaa51d] | 775 | UntypedInitExpr( const CodeLocation & loc, const Expr * e, std::deque<InitAlternative> && as ) |
---|
[9b4f329] | 776 | : Expr( loc ), expr( e ), initAlts( std::move(as) ) {} |
---|
| 777 | |
---|
| 778 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 779 | private: |
---|
| 780 | UntypedInitExpr * clone() const override { return new UntypedInitExpr{ *this }; } |
---|
| 781 | MUTATE_FRIEND |
---|
| 782 | }; |
---|
| 783 | |
---|
| 784 | /// Post-resolution initializer expression |
---|
| 785 | class InitExpr final : public Expr { |
---|
| 786 | public: |
---|
| 787 | ptr<Expr> expr; |
---|
| 788 | ptr<Designation> designation; |
---|
| 789 | |
---|
| 790 | InitExpr( const CodeLocation & loc, const Expr * e, const Designation * des ) |
---|
| 791 | : Expr( loc, e->result ), expr( e ), designation( des ) {} |
---|
| 792 | |
---|
| 793 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 794 | private: |
---|
| 795 | InitExpr * clone() const override { return new InitExpr{ *this }; } |
---|
| 796 | MUTATE_FRIEND |
---|
| 797 | }; |
---|
| 798 | |
---|
| 799 | /// Expression containing a deleted identifier. |
---|
| 800 | /// Internal to resolver. |
---|
| 801 | class DeletedExpr final : public Expr { |
---|
| 802 | public: |
---|
| 803 | ptr<Expr> expr; |
---|
[e67991f] | 804 | readonly<Decl> deleteStmt; |
---|
[9b4f329] | 805 | |
---|
[e67991f] | 806 | DeletedExpr( const CodeLocation & loc, const Expr * e, const Decl * del ) |
---|
[9b4f329] | 807 | : Expr( loc, e->result ), expr( e ), deleteStmt( del ) { assert( expr->result ); } |
---|
| 808 | |
---|
| 809 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 810 | private: |
---|
| 811 | DeletedExpr * clone() const override { return new DeletedExpr{ *this }; } |
---|
| 812 | MUTATE_FRIEND |
---|
| 813 | }; |
---|
| 814 | |
---|
| 815 | /// Use of a default argument. |
---|
| 816 | /// Internal to resolver. |
---|
| 817 | class DefaultArgExpr final : public Expr { |
---|
| 818 | public: |
---|
| 819 | ptr<Expr> expr; |
---|
| 820 | |
---|
| 821 | DefaultArgExpr( const CodeLocation & loc, const Expr * e ) |
---|
| 822 | : Expr( loc, e->result ), expr( e ) { assert( e->result ); } |
---|
| 823 | |
---|
| 824 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 825 | private: |
---|
| 826 | DefaultArgExpr * clone() const override { return new DefaultArgExpr{ *this }; } |
---|
| 827 | MUTATE_FRIEND |
---|
| 828 | }; |
---|
| 829 | |
---|
| 830 | /// C11 _Generic expression |
---|
| 831 | class GenericExpr final : public Expr { |
---|
| 832 | public: |
---|
| 833 | /// One arm of the _Generic expr |
---|
| 834 | struct Association { |
---|
| 835 | ptr<Type> type; |
---|
| 836 | ptr<Expr> expr; |
---|
| 837 | |
---|
| 838 | Association() = default; |
---|
| 839 | // default case |
---|
| 840 | Association( const Expr * e ) : type(), expr( e ) {} |
---|
| 841 | // non-default case |
---|
| 842 | Association( const Type * t, const Expr * e ) : type( t ), expr( e ) {} |
---|
| 843 | }; |
---|
| 844 | |
---|
| 845 | ptr<Expr> control; |
---|
| 846 | std::vector<Association> associations; |
---|
| 847 | |
---|
| 848 | GenericExpr( const CodeLocation & loc, const Expr * ctrl, std::vector<Association> && assns ) |
---|
| 849 | : Expr( loc ), control( ctrl ), associations( std::move(assns) ) {} |
---|
| 850 | |
---|
| 851 | const Expr * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
| 852 | private: |
---|
| 853 | GenericExpr * clone() const override { return new GenericExpr{ *this }; } |
---|
| 854 | MUTATE_FRIEND |
---|
[54e41b3] | 855 | }; |
---|
[6d51bd7] | 856 | |
---|
[246c245] | 857 | |
---|
[79f7875] | 858 | } |
---|
| 859 | |
---|
[f3cc5b6] | 860 | #undef MUTATE_FRIEND |
---|
| 861 | |
---|
[79f7875] | 862 | // Local Variables: // |
---|
| 863 | // tab-width: 4 // |
---|
| 864 | // mode: c++ // |
---|
| 865 | // compile-command: "make install" // |
---|
| 866 | // End: // |
---|