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