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