1 1.1 mrg 2 1.1 mrg /* Compiler implementation of the D programming language 3 1.1.1.3 mrg * Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved 4 1.1 mrg * written by Walter Bright 5 1.1.1.3 mrg * https://www.digitalmars.com 6 1.1 mrg * Distributed under the Boost Software License, Version 1.0. 7 1.1.1.3 mrg * https://www.boost.org/LICENSE_1_0.txt 8 1.1 mrg * https://github.com/dlang/dmd/blob/master/src/dmd/expression.h 9 1.1 mrg */ 10 1.1 mrg 11 1.1 mrg #pragma once 12 1.1 mrg 13 1.1.1.3 mrg #include "ast_node.h" 14 1.1 mrg #include "globals.h" 15 1.1 mrg #include "arraytypes.h" 16 1.1 mrg #include "visitor.h" 17 1.1 mrg #include "tokens.h" 18 1.1 mrg 19 1.1.1.3 mrg #include "root/complex_t.h" 20 1.1.1.3 mrg #include "root/dcompat.h" 21 1.1.1.3 mrg #include "root/optional.h" 22 1.1 mrg 23 1.1 mrg class Type; 24 1.1 mrg class TypeVector; 25 1.1 mrg struct Scope; 26 1.1 mrg class TupleDeclaration; 27 1.1 mrg class VarDeclaration; 28 1.1 mrg class FuncDeclaration; 29 1.1 mrg class FuncLiteralDeclaration; 30 1.1 mrg class CtorDeclaration; 31 1.1 mrg class Dsymbol; 32 1.1 mrg class ScopeDsymbol; 33 1.1 mrg class Expression; 34 1.1 mrg class Declaration; 35 1.1 mrg class StructDeclaration; 36 1.1 mrg class TemplateInstance; 37 1.1 mrg class TemplateDeclaration; 38 1.1 mrg class ClassDeclaration; 39 1.1 mrg class OverloadSet; 40 1.1 mrg class StringExp; 41 1.1 mrg struct UnionExp; 42 1.1 mrg #ifdef IN_GCC 43 1.1 mrg typedef union tree_node Symbol; 44 1.1 mrg #else 45 1.1 mrg struct Symbol; // back end symbol 46 1.1 mrg #endif 47 1.1 mrg 48 1.1 mrg void expandTuples(Expressions *exps); 49 1.1 mrg bool isTrivialExp(Expression *e); 50 1.1.1.3 mrg bool hasSideEffect(Expression *e, bool assumeImpureCalls = false); 51 1.1 mrg 52 1.1.1.3 mrg enum BE : int32_t; 53 1.1.1.3 mrg BE canThrow(Expression *e, FuncDeclaration *func, bool mustNotThrow); 54 1.1 mrg 55 1.1.1.3 mrg typedef unsigned char OwnedBy; 56 1.1.1.3 mrg enum 57 1.1 mrg { 58 1.1 mrg OWNEDcode, // normal code expression in AST 59 1.1 mrg OWNEDctfe, // value expression for CTFE 60 1.1 mrg OWNEDcache // constant value cached for CTFE 61 1.1 mrg }; 62 1.1 mrg 63 1.1.1.3 mrg #define WANTvalue 0 // default 64 1.1.1.3 mrg #define WANTexpand 1 // expand const/immutable variables if possible 65 1.1 mrg 66 1.1.1.3 mrg /** 67 1.1.1.3 mrg * Specifies how the checkModify deals with certain situations 68 1.1.1.3 mrg */ 69 1.1.1.3 mrg enum class ModifyFlags 70 1.1.1.3 mrg { 71 1.1.1.3 mrg /// Issue error messages on invalid modifications of the variable 72 1.1.1.3 mrg none, 73 1.1.1.3 mrg /// No errors are emitted for invalid modifications 74 1.1.1.3 mrg noError = 0x1, 75 1.1.1.3 mrg /// The modification occurs for a subfield of the current variable 76 1.1.1.3 mrg fieldAssign = 0x2, 77 1.1.1.3 mrg }; 78 1.1.1.3 mrg 79 1.1.1.3 mrg class Expression : public ASTNode 80 1.1 mrg { 81 1.1 mrg public: 82 1.1.1.3 mrg EXP op; // to minimize use of dynamic_cast 83 1.1 mrg unsigned char size; // # of bytes in Expression so we can copy() it 84 1.1 mrg unsigned char parens; // if this is a parenthesized expression 85 1.1.1.3 mrg Type *type; // !=NULL means that semantic() has been run 86 1.1.1.3 mrg Loc loc; // file location 87 1.1 mrg 88 1.1 mrg static void _init(); 89 1.1 mrg Expression *copy(); 90 1.1 mrg virtual Expression *syntaxCopy(); 91 1.1 mrg 92 1.1 mrg // kludge for template.isExpression() 93 1.1.1.3 mrg DYNCAST dyncast() const { return DYNCAST_EXPRESSION; } 94 1.1 mrg 95 1.1.1.3 mrg const char *toChars() const; 96 1.1 mrg void error(const char *format, ...) const; 97 1.1 mrg void warning(const char *format, ...) const; 98 1.1 mrg void deprecation(const char *format, ...) const; 99 1.1 mrg 100 1.1 mrg virtual dinteger_t toInteger(); 101 1.1 mrg virtual uinteger_t toUInteger(); 102 1.1 mrg virtual real_t toReal(); 103 1.1 mrg virtual real_t toImaginary(); 104 1.1 mrg virtual complex_t toComplex(); 105 1.1 mrg virtual StringExp *toStringExp(); 106 1.1 mrg virtual bool isLvalue(); 107 1.1 mrg virtual Expression *toLvalue(Scope *sc, Expression *e); 108 1.1 mrg virtual Expression *modifiableLvalue(Scope *sc, Expression *e); 109 1.1.1.3 mrg Expression *implicitCastTo(Scope *sc, Type *t); 110 1.1.1.3 mrg MATCH implicitConvTo(Type *t); 111 1.1.1.3 mrg Expression *castTo(Scope *sc, Type *t); 112 1.1.1.3 mrg virtual Expression *resolveLoc(const Loc &loc, Scope *sc); 113 1.1 mrg virtual bool checkType(); 114 1.1 mrg virtual bool checkValue(); 115 1.1.1.3 mrg bool checkDeprecated(Scope *sc, Dsymbol *s); 116 1.1 mrg virtual Expression *addDtorHook(Scope *sc); 117 1.1 mrg Expression *addressOf(); 118 1.1 mrg Expression *deref(); 119 1.1 mrg 120 1.1.1.3 mrg Expression *optimize(int result, bool keepLvalue = false); 121 1.1 mrg 122 1.1 mrg // Entry point for CTFE. 123 1.1 mrg // A compile-time result is required. Give an error if not possible 124 1.1.1.3 mrg Expression *ctfeInterpret(); 125 1.1.1.3 mrg int isConst(); 126 1.1.1.3 mrg virtual Optional<bool> toBool(); 127 1.1 mrg virtual bool hasCode() 128 1.1 mrg { 129 1.1 mrg return true; 130 1.1 mrg } 131 1.1 mrg 132 1.1.1.3 mrg IntegerExp* isIntegerExp(); 133 1.1.1.3 mrg ErrorExp* isErrorExp(); 134 1.1.1.3 mrg VoidInitExp* isVoidInitExp(); 135 1.1.1.3 mrg RealExp* isRealExp(); 136 1.1.1.3 mrg ComplexExp* isComplexExp(); 137 1.1.1.3 mrg IdentifierExp* isIdentifierExp(); 138 1.1.1.3 mrg DollarExp* isDollarExp(); 139 1.1.1.3 mrg DsymbolExp* isDsymbolExp(); 140 1.1.1.3 mrg ThisExp* isThisExp(); 141 1.1.1.3 mrg SuperExp* isSuperExp(); 142 1.1.1.3 mrg NullExp* isNullExp(); 143 1.1.1.3 mrg StringExp* isStringExp(); 144 1.1.1.3 mrg TupleExp* isTupleExp(); 145 1.1.1.3 mrg ArrayLiteralExp* isArrayLiteralExp(); 146 1.1.1.3 mrg AssocArrayLiteralExp* isAssocArrayLiteralExp(); 147 1.1.1.3 mrg StructLiteralExp* isStructLiteralExp(); 148 1.1.1.3 mrg TypeExp* isTypeExp(); 149 1.1.1.3 mrg ScopeExp* isScopeExp(); 150 1.1.1.3 mrg TemplateExp* isTemplateExp(); 151 1.1.1.3 mrg NewExp* isNewExp(); 152 1.1.1.3 mrg NewAnonClassExp* isNewAnonClassExp(); 153 1.1.1.3 mrg SymOffExp* isSymOffExp(); 154 1.1.1.3 mrg VarExp* isVarExp(); 155 1.1.1.3 mrg OverExp* isOverExp(); 156 1.1.1.3 mrg FuncExp* isFuncExp(); 157 1.1.1.3 mrg DeclarationExp* isDeclarationExp(); 158 1.1.1.3 mrg TypeidExp* isTypeidExp(); 159 1.1.1.3 mrg TraitsExp* isTraitsExp(); 160 1.1.1.3 mrg HaltExp* isHaltExp(); 161 1.1.1.3 mrg IsExp* isExp(); 162 1.1.1.3 mrg MixinExp* isMixinExp(); 163 1.1.1.3 mrg ImportExp* isImportExp(); 164 1.1.1.3 mrg AssertExp* isAssertExp(); 165 1.1.1.3 mrg DotIdExp* isDotIdExp(); 166 1.1.1.3 mrg DotTemplateExp* isDotTemplateExp(); 167 1.1.1.3 mrg DotVarExp* isDotVarExp(); 168 1.1.1.3 mrg DotTemplateInstanceExp* isDotTemplateInstanceExp(); 169 1.1.1.3 mrg DelegateExp* isDelegateExp(); 170 1.1.1.3 mrg DotTypeExp* isDotTypeExp(); 171 1.1.1.3 mrg CallExp* isCallExp(); 172 1.1.1.3 mrg AddrExp* isAddrExp(); 173 1.1.1.3 mrg PtrExp* isPtrExp(); 174 1.1.1.3 mrg NegExp* isNegExp(); 175 1.1.1.3 mrg UAddExp* isUAddExp(); 176 1.1.1.3 mrg ComExp* isComExp(); 177 1.1.1.3 mrg NotExp* isNotExp(); 178 1.1.1.3 mrg DeleteExp* isDeleteExp(); 179 1.1.1.3 mrg CastExp* isCastExp(); 180 1.1.1.3 mrg VectorExp* isVectorExp(); 181 1.1.1.3 mrg VectorArrayExp* isVectorArrayExp(); 182 1.1.1.3 mrg SliceExp* isSliceExp(); 183 1.1.1.3 mrg ArrayLengthExp* isArrayLengthExp(); 184 1.1.1.3 mrg ArrayExp* isArrayExp(); 185 1.1.1.3 mrg DotExp* isDotExp(); 186 1.1.1.3 mrg CommaExp* isCommaExp(); 187 1.1.1.3 mrg IntervalExp* isIntervalExp(); 188 1.1.1.3 mrg DelegatePtrExp* isDelegatePtrExp(); 189 1.1.1.3 mrg DelegateFuncptrExp* isDelegateFuncptrExp(); 190 1.1.1.3 mrg IndexExp* isIndexExp(); 191 1.1.1.3 mrg PostExp* isPostExp(); 192 1.1.1.3 mrg PreExp* isPreExp(); 193 1.1.1.3 mrg AssignExp* isAssignExp(); 194 1.1.1.3 mrg ConstructExp* isConstructExp(); 195 1.1.1.3 mrg BlitExp* isBlitExp(); 196 1.1.1.3 mrg AddAssignExp* isAddAssignExp(); 197 1.1.1.3 mrg MinAssignExp* isMinAssignExp(); 198 1.1.1.3 mrg MulAssignExp* isMulAssignExp(); 199 1.1.1.3 mrg DivAssignExp* isDivAssignExp(); 200 1.1.1.3 mrg ModAssignExp* isModAssignExp(); 201 1.1.1.3 mrg AndAssignExp* isAndAssignExp(); 202 1.1.1.3 mrg OrAssignExp* isOrAssignExp(); 203 1.1.1.3 mrg XorAssignExp* isXorAssignExp(); 204 1.1.1.3 mrg PowAssignExp* isPowAssignExp(); 205 1.1.1.3 mrg ShlAssignExp* isShlAssignExp(); 206 1.1.1.3 mrg ShrAssignExp* isShrAssignExp(); 207 1.1.1.3 mrg UshrAssignExp* isUshrAssignExp(); 208 1.1.1.3 mrg CatAssignExp* isCatAssignExp(); 209 1.1.1.3 mrg AddExp* isAddExp(); 210 1.1.1.3 mrg MinExp* isMinExp(); 211 1.1.1.3 mrg CatExp* isCatExp(); 212 1.1.1.3 mrg MulExp* isMulExp(); 213 1.1.1.3 mrg DivExp* isDivExp(); 214 1.1.1.3 mrg ModExp* isModExp(); 215 1.1.1.3 mrg PowExp* isPowExp(); 216 1.1.1.3 mrg ShlExp* isShlExp(); 217 1.1.1.3 mrg ShrExp* isShrExp(); 218 1.1.1.3 mrg UshrExp* isUshrExp(); 219 1.1.1.3 mrg AndExp* isAndExp(); 220 1.1.1.3 mrg OrExp* isOrExp(); 221 1.1.1.3 mrg XorExp* isXorExp(); 222 1.1.1.3 mrg LogicalExp* isLogicalExp(); 223 1.1.1.3 mrg InExp* isInExp(); 224 1.1.1.3 mrg RemoveExp* isRemoveExp(); 225 1.1.1.3 mrg EqualExp* isEqualExp(); 226 1.1.1.3 mrg IdentityExp* isIdentityExp(); 227 1.1.1.3 mrg CondExp* isCondExp(); 228 1.1.1.3 mrg GenericExp* isGenericExp(); 229 1.1.1.3 mrg DefaultInitExp* isDefaultInitExp(); 230 1.1.1.3 mrg FileInitExp* isFileInitExp(); 231 1.1.1.3 mrg LineInitExp* isLineInitExp(); 232 1.1.1.3 mrg ModuleInitExp* isModuleInitExp(); 233 1.1.1.3 mrg FuncInitExp* isFuncInitExp(); 234 1.1.1.3 mrg PrettyFuncInitExp* isPrettyFuncInitExp(); 235 1.1.1.3 mrg ClassReferenceExp* isClassReferenceExp(); 236 1.1.1.3 mrg ThrownExceptionExp* isThrownExceptionExp(); 237 1.1.1.3 mrg UnaExp* isUnaExp(); 238 1.1.1.3 mrg BinExp* isBinExp(); 239 1.1.1.3 mrg BinAssignExp* isBinAssignExp(); 240 1.1.1.3 mrg 241 1.1.1.3 mrg void accept(Visitor *v) { v->visit(this); } 242 1.1 mrg }; 243 1.1 mrg 244 1.1 mrg class IntegerExp : public Expression 245 1.1 mrg { 246 1.1 mrg public: 247 1.1 mrg dinteger_t value; 248 1.1 mrg 249 1.1.1.3 mrg static IntegerExp *create(const Loc &loc, dinteger_t value, Type *type); 250 1.1.1.3 mrg static void emplace(UnionExp *pue, const Loc &loc, dinteger_t value, Type *type); 251 1.1.1.3 mrg bool equals(const RootObject *o) const; 252 1.1 mrg dinteger_t toInteger(); 253 1.1 mrg real_t toReal(); 254 1.1 mrg real_t toImaginary(); 255 1.1 mrg complex_t toComplex(); 256 1.1.1.3 mrg Optional<bool> toBool(); 257 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 258 1.1 mrg void accept(Visitor *v) { v->visit(this); } 259 1.1 mrg dinteger_t getInteger() { return value; } 260 1.1 mrg void setInteger(dinteger_t value); 261 1.1.1.3 mrg template<int v> 262 1.1.1.3 mrg static IntegerExp literal(); 263 1.1 mrg }; 264 1.1 mrg 265 1.1 mrg class ErrorExp : public Expression 266 1.1 mrg { 267 1.1 mrg public: 268 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 269 1.1 mrg void accept(Visitor *v) { v->visit(this); } 270 1.1 mrg 271 1.1 mrg static ErrorExp *errorexp; // handy shared value 272 1.1 mrg }; 273 1.1 mrg 274 1.1 mrg class RealExp : public Expression 275 1.1 mrg { 276 1.1 mrg public: 277 1.1 mrg real_t value; 278 1.1 mrg 279 1.1.1.3 mrg static RealExp *create(const Loc &loc, real_t value, Type *type); 280 1.1.1.3 mrg static void emplace(UnionExp *pue, const Loc &loc, real_t value, Type *type); 281 1.1.1.3 mrg bool equals(const RootObject *o) const; 282 1.1 mrg dinteger_t toInteger(); 283 1.1 mrg uinteger_t toUInteger(); 284 1.1 mrg real_t toReal(); 285 1.1 mrg real_t toImaginary(); 286 1.1 mrg complex_t toComplex(); 287 1.1.1.3 mrg Optional<bool> toBool(); 288 1.1 mrg void accept(Visitor *v) { v->visit(this); } 289 1.1 mrg }; 290 1.1 mrg 291 1.1 mrg class ComplexExp : public Expression 292 1.1 mrg { 293 1.1 mrg public: 294 1.1 mrg complex_t value; 295 1.1 mrg 296 1.1.1.3 mrg static ComplexExp *create(const Loc &loc, complex_t value, Type *type); 297 1.1.1.3 mrg static void emplace(UnionExp *pue, const Loc &loc, complex_t value, Type *type); 298 1.1.1.3 mrg bool equals(const RootObject *o) const; 299 1.1 mrg dinteger_t toInteger(); 300 1.1 mrg uinteger_t toUInteger(); 301 1.1 mrg real_t toReal(); 302 1.1 mrg real_t toImaginary(); 303 1.1 mrg complex_t toComplex(); 304 1.1.1.3 mrg Optional<bool> toBool(); 305 1.1 mrg void accept(Visitor *v) { v->visit(this); } 306 1.1 mrg }; 307 1.1 mrg 308 1.1 mrg class IdentifierExp : public Expression 309 1.1 mrg { 310 1.1 mrg public: 311 1.1 mrg Identifier *ident; 312 1.1 mrg 313 1.1.1.3 mrg static IdentifierExp *create(const Loc &loc, Identifier *ident); 314 1.1 mrg bool isLvalue(); 315 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 316 1.1 mrg void accept(Visitor *v) { v->visit(this); } 317 1.1 mrg }; 318 1.1 mrg 319 1.1 mrg class DollarExp : public IdentifierExp 320 1.1 mrg { 321 1.1 mrg public: 322 1.1 mrg void accept(Visitor *v) { v->visit(this); } 323 1.1 mrg }; 324 1.1 mrg 325 1.1 mrg class DsymbolExp : public Expression 326 1.1 mrg { 327 1.1 mrg public: 328 1.1 mrg Dsymbol *s; 329 1.1 mrg bool hasOverloads; 330 1.1 mrg 331 1.1.1.3 mrg DsymbolExp *syntaxCopy(); 332 1.1 mrg bool isLvalue(); 333 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 334 1.1 mrg void accept(Visitor *v) { v->visit(this); } 335 1.1 mrg }; 336 1.1 mrg 337 1.1 mrg class ThisExp : public Expression 338 1.1 mrg { 339 1.1 mrg public: 340 1.1 mrg VarDeclaration *var; 341 1.1 mrg 342 1.1.1.3 mrg ThisExp *syntaxCopy(); 343 1.1.1.3 mrg Optional<bool> toBool(); 344 1.1 mrg bool isLvalue(); 345 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 346 1.1 mrg 347 1.1 mrg void accept(Visitor *v) { v->visit(this); } 348 1.1 mrg }; 349 1.1 mrg 350 1.1 mrg class SuperExp : public ThisExp 351 1.1 mrg { 352 1.1 mrg public: 353 1.1 mrg void accept(Visitor *v) { v->visit(this); } 354 1.1 mrg }; 355 1.1 mrg 356 1.1 mrg class NullExp : public Expression 357 1.1 mrg { 358 1.1 mrg public: 359 1.1.1.3 mrg bool equals(const RootObject *o) const; 360 1.1.1.3 mrg Optional<bool> toBool(); 361 1.1 mrg StringExp *toStringExp(); 362 1.1 mrg void accept(Visitor *v) { v->visit(this); } 363 1.1 mrg }; 364 1.1 mrg 365 1.1 mrg class StringExp : public Expression 366 1.1 mrg { 367 1.1 mrg public: 368 1.1 mrg void *string; // char, wchar, or dchar data 369 1.1 mrg size_t len; // number of chars, wchars, or dchars 370 1.1 mrg unsigned char sz; // 1: char, 2: wchar, 4: dchar 371 1.1 mrg unsigned char committed; // !=0 if type is committed 372 1.1 mrg utf8_t postfix; // 'c', 'w', 'd' 373 1.1 mrg OwnedBy ownedByCtfe; 374 1.1 mrg 375 1.1.1.3 mrg static StringExp *create(const Loc &loc, const char *s); 376 1.1.1.3 mrg static StringExp *create(const Loc &loc, const void *s, d_size_t len); 377 1.1.1.3 mrg static void emplace(UnionExp *pue, const Loc &loc, const char *s); 378 1.1.1.3 mrg bool equals(const RootObject *o) const; 379 1.1.1.3 mrg char32_t getCodeUnit(d_size_t i) const; 380 1.1.1.3 mrg void setCodeUnit(d_size_t i, char32_t c); 381 1.1 mrg StringExp *toStringExp(); 382 1.1 mrg StringExp *toUTF8(Scope *sc); 383 1.1.1.3 mrg Optional<bool> toBool(); 384 1.1 mrg bool isLvalue(); 385 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 386 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 387 1.1 mrg void accept(Visitor *v) { v->visit(this); } 388 1.1 mrg size_t numberOfCodeUnits(int tynto = 0) const; 389 1.1 mrg void writeTo(void* dest, bool zero, int tyto = 0) const; 390 1.1 mrg }; 391 1.1 mrg 392 1.1 mrg // Tuple 393 1.1 mrg 394 1.1 mrg class TupleExp : public Expression 395 1.1 mrg { 396 1.1 mrg public: 397 1.1 mrg Expression *e0; // side-effect part 398 1.1 mrg /* Tuple-field access may need to take out its side effect part. 399 1.1 mrg * For example: 400 1.1 mrg * foo().tupleof 401 1.1 mrg * is rewritten as: 402 1.1 mrg * (ref __tup = foo(); tuple(__tup.field0, __tup.field1, ...)) 403 1.1 mrg * The declaration of temporary variable __tup will be stored in TupleExp::e0. 404 1.1 mrg */ 405 1.1 mrg Expressions *exps; 406 1.1 mrg 407 1.1.1.3 mrg static TupleExp *create(const Loc &loc, Expressions *exps); 408 1.1.1.3 mrg TupleExp *syntaxCopy(); 409 1.1.1.3 mrg bool equals(const RootObject *o) const; 410 1.1 mrg 411 1.1 mrg void accept(Visitor *v) { v->visit(this); } 412 1.1 mrg }; 413 1.1 mrg 414 1.1 mrg class ArrayLiteralExp : public Expression 415 1.1 mrg { 416 1.1 mrg public: 417 1.1 mrg Expression *basis; 418 1.1 mrg Expressions *elements; 419 1.1 mrg OwnedBy ownedByCtfe; 420 1.1 mrg 421 1.1.1.3 mrg static ArrayLiteralExp *create(const Loc &loc, Expressions *elements); 422 1.1.1.3 mrg static void emplace(UnionExp *pue, const Loc &loc, Expressions *elements); 423 1.1.1.3 mrg ArrayLiteralExp *syntaxCopy(); 424 1.1.1.3 mrg bool equals(const RootObject *o) const; 425 1.1.1.3 mrg Expression *getElement(d_size_t i); // use opIndex instead 426 1.1.1.3 mrg Expression *opIndex(d_size_t i); 427 1.1.1.3 mrg Optional<bool> toBool(); 428 1.1 mrg StringExp *toStringExp(); 429 1.1 mrg 430 1.1 mrg void accept(Visitor *v) { v->visit(this); } 431 1.1 mrg }; 432 1.1 mrg 433 1.1 mrg class AssocArrayLiteralExp : public Expression 434 1.1 mrg { 435 1.1 mrg public: 436 1.1 mrg Expressions *keys; 437 1.1 mrg Expressions *values; 438 1.1 mrg OwnedBy ownedByCtfe; 439 1.1 mrg 440 1.1.1.3 mrg bool equals(const RootObject *o) const; 441 1.1.1.3 mrg AssocArrayLiteralExp *syntaxCopy(); 442 1.1.1.3 mrg Optional<bool> toBool(); 443 1.1 mrg 444 1.1 mrg void accept(Visitor *v) { v->visit(this); } 445 1.1 mrg }; 446 1.1 mrg 447 1.1 mrg class StructLiteralExp : public Expression 448 1.1 mrg { 449 1.1 mrg public: 450 1.1 mrg StructDeclaration *sd; // which aggregate this is for 451 1.1 mrg Expressions *elements; // parallels sd->fields[] with NULL entries for fields to skip 452 1.1 mrg Type *stype; // final type of result (can be different from sd's type) 453 1.1 mrg 454 1.1 mrg Symbol *sym; // back end symbol to initialize with literal 455 1.1 mrg 456 1.1.1.3 mrg /** pointer to the origin instance of the expression. 457 1.1.1.3 mrg * once a new expression is created, origin is set to 'this'. 458 1.1.1.3 mrg * anytime when an expression copy is created, 'origin' pointer is set to 459 1.1.1.3 mrg * 'origin' pointer value of the original expression. 460 1.1.1.3 mrg */ 461 1.1 mrg StructLiteralExp *origin; 462 1.1 mrg 463 1.1 mrg // those fields need to prevent a infinite recursion when one field of struct initialized with 'this' pointer. 464 1.1 mrg StructLiteralExp *inlinecopy; 465 1.1 mrg 466 1.1.1.3 mrg /** anytime when recursive function is calling, 'stageflags' marks with bit flag of 467 1.1.1.3 mrg * current stage and unmarks before return from this function. 468 1.1.1.3 mrg * 'inlinecopy' uses similar 'stageflags' and from multiple evaluation 'doInline' 469 1.1.1.3 mrg * (with infinite recursion) of this expression. 470 1.1.1.3 mrg */ 471 1.1 mrg int stageflags; 472 1.1 mrg 473 1.1.1.3 mrg bool useStaticInit; // if this is true, use the StructDeclaration's init symbol 474 1.1.1.3 mrg bool isOriginal; // used when moving instances to indicate `this is this.origin` 475 1.1.1.3 mrg OwnedBy ownedByCtfe; 476 1.1.1.3 mrg 477 1.1.1.3 mrg static StructLiteralExp *create(const Loc &loc, StructDeclaration *sd, void *elements, Type *stype = NULL); 478 1.1.1.3 mrg bool equals(const RootObject *o) const; 479 1.1.1.3 mrg StructLiteralExp *syntaxCopy(); 480 1.1 mrg Expression *getField(Type *type, unsigned offset); 481 1.1 mrg int getFieldIndex(Type *type, unsigned offset); 482 1.1 mrg Expression *addDtorHook(Scope *sc); 483 1.1.1.3 mrg Expression *toLvalue(Scope *sc, Expression *e); 484 1.1 mrg 485 1.1 mrg void accept(Visitor *v) { v->visit(this); } 486 1.1 mrg }; 487 1.1 mrg 488 1.1 mrg class TypeExp : public Expression 489 1.1 mrg { 490 1.1 mrg public: 491 1.1.1.3 mrg TypeExp *syntaxCopy(); 492 1.1 mrg bool checkType(); 493 1.1 mrg bool checkValue(); 494 1.1 mrg void accept(Visitor *v) { v->visit(this); } 495 1.1 mrg }; 496 1.1 mrg 497 1.1 mrg class ScopeExp : public Expression 498 1.1 mrg { 499 1.1 mrg public: 500 1.1 mrg ScopeDsymbol *sds; 501 1.1 mrg 502 1.1.1.3 mrg ScopeExp *syntaxCopy(); 503 1.1 mrg bool checkType(); 504 1.1 mrg bool checkValue(); 505 1.1 mrg void accept(Visitor *v) { v->visit(this); } 506 1.1 mrg }; 507 1.1 mrg 508 1.1 mrg class TemplateExp : public Expression 509 1.1 mrg { 510 1.1 mrg public: 511 1.1 mrg TemplateDeclaration *td; 512 1.1 mrg FuncDeclaration *fd; 513 1.1 mrg 514 1.1 mrg bool isLvalue(); 515 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 516 1.1 mrg bool checkType(); 517 1.1 mrg bool checkValue(); 518 1.1 mrg void accept(Visitor *v) { v->visit(this); } 519 1.1 mrg }; 520 1.1 mrg 521 1.1 mrg class NewExp : public Expression 522 1.1 mrg { 523 1.1 mrg public: 524 1.1.1.3 mrg /* newtype(arguments) 525 1.1 mrg */ 526 1.1 mrg Expression *thisexp; // if !NULL, 'this' for class being allocated 527 1.1 mrg Type *newtype; 528 1.1 mrg Expressions *arguments; // Array of Expression's 529 1.1 mrg 530 1.1 mrg Expression *argprefix; // expression to be evaluated just before arguments[] 531 1.1 mrg 532 1.1 mrg CtorDeclaration *member; // constructor function 533 1.1.1.3 mrg bool onstack; // allocate on stack 534 1.1.1.3 mrg bool thrownew; // this NewExp is the expression of a ThrowStatement 535 1.1 mrg 536 1.1.1.3 mrg static NewExp *create(const Loc &loc, Expression *thisexp, Type *newtype, Expressions *arguments); 537 1.1.1.3 mrg NewExp *syntaxCopy(); 538 1.1 mrg 539 1.1 mrg void accept(Visitor *v) { v->visit(this); } 540 1.1 mrg }; 541 1.1 mrg 542 1.1 mrg class NewAnonClassExp : public Expression 543 1.1 mrg { 544 1.1 mrg public: 545 1.1.1.3 mrg /* class baseclasses { } (arguments) 546 1.1 mrg */ 547 1.1 mrg Expression *thisexp; // if !NULL, 'this' for class being allocated 548 1.1 mrg ClassDeclaration *cd; // class being instantiated 549 1.1 mrg Expressions *arguments; // Array of Expression's to call class constructor 550 1.1 mrg 551 1.1.1.3 mrg NewAnonClassExp *syntaxCopy(); 552 1.1 mrg void accept(Visitor *v) { v->visit(this); } 553 1.1 mrg }; 554 1.1 mrg 555 1.1 mrg class SymbolExp : public Expression 556 1.1 mrg { 557 1.1 mrg public: 558 1.1 mrg Declaration *var; 559 1.1.1.3 mrg Dsymbol *originalScope; 560 1.1 mrg bool hasOverloads; 561 1.1 mrg 562 1.1 mrg void accept(Visitor *v) { v->visit(this); } 563 1.1 mrg }; 564 1.1 mrg 565 1.1 mrg // Offset from symbol 566 1.1 mrg 567 1.1 mrg class SymOffExp : public SymbolExp 568 1.1 mrg { 569 1.1 mrg public: 570 1.1 mrg dinteger_t offset; 571 1.1 mrg 572 1.1.1.3 mrg Optional<bool> toBool(); 573 1.1 mrg 574 1.1 mrg void accept(Visitor *v) { v->visit(this); } 575 1.1 mrg }; 576 1.1 mrg 577 1.1 mrg // Variable 578 1.1 mrg 579 1.1 mrg class VarExp : public SymbolExp 580 1.1 mrg { 581 1.1 mrg public: 582 1.1.1.3 mrg bool delegateWasExtracted; 583 1.1.1.3 mrg static VarExp *create(const Loc &loc, Declaration *var, bool hasOverloads = true); 584 1.1.1.3 mrg bool equals(const RootObject *o) const; 585 1.1 mrg bool isLvalue(); 586 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 587 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 588 1.1 mrg 589 1.1 mrg void accept(Visitor *v) { v->visit(this); } 590 1.1 mrg }; 591 1.1 mrg 592 1.1 mrg // Overload Set 593 1.1 mrg 594 1.1 mrg class OverExp : public Expression 595 1.1 mrg { 596 1.1 mrg public: 597 1.1 mrg OverloadSet *vars; 598 1.1 mrg 599 1.1 mrg bool isLvalue(); 600 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 601 1.1 mrg void accept(Visitor *v) { v->visit(this); } 602 1.1 mrg }; 603 1.1 mrg 604 1.1 mrg // Function/Delegate literal 605 1.1 mrg 606 1.1 mrg class FuncExp : public Expression 607 1.1 mrg { 608 1.1 mrg public: 609 1.1 mrg FuncLiteralDeclaration *fd; 610 1.1 mrg TemplateDeclaration *td; 611 1.1 mrg TOK tok; 612 1.1 mrg 613 1.1.1.3 mrg bool equals(const RootObject *o) const; 614 1.1.1.3 mrg FuncExp *syntaxCopy(); 615 1.1.1.3 mrg const char *toChars() const; 616 1.1 mrg bool checkType(); 617 1.1 mrg bool checkValue(); 618 1.1 mrg 619 1.1 mrg void accept(Visitor *v) { v->visit(this); } 620 1.1 mrg }; 621 1.1 mrg 622 1.1 mrg // Declaration of a symbol 623 1.1 mrg 624 1.1 mrg // D grammar allows declarations only as statements. However in AST representation 625 1.1 mrg // it can be part of any expression. This is used, for example, during internal 626 1.1 mrg // syntax re-writes to inject hidden symbols. 627 1.1 mrg class DeclarationExp : public Expression 628 1.1 mrg { 629 1.1 mrg public: 630 1.1 mrg Dsymbol *declaration; 631 1.1 mrg 632 1.1.1.3 mrg DeclarationExp *syntaxCopy(); 633 1.1 mrg 634 1.1 mrg bool hasCode(); 635 1.1 mrg 636 1.1 mrg void accept(Visitor *v) { v->visit(this); } 637 1.1 mrg }; 638 1.1 mrg 639 1.1 mrg class TypeidExp : public Expression 640 1.1 mrg { 641 1.1 mrg public: 642 1.1 mrg RootObject *obj; 643 1.1 mrg 644 1.1.1.3 mrg TypeidExp *syntaxCopy(); 645 1.1 mrg void accept(Visitor *v) { v->visit(this); } 646 1.1 mrg }; 647 1.1 mrg 648 1.1 mrg class TraitsExp : public Expression 649 1.1 mrg { 650 1.1 mrg public: 651 1.1 mrg Identifier *ident; 652 1.1 mrg Objects *args; 653 1.1 mrg 654 1.1.1.3 mrg TraitsExp *syntaxCopy(); 655 1.1 mrg void accept(Visitor *v) { v->visit(this); } 656 1.1 mrg }; 657 1.1 mrg 658 1.1 mrg class HaltExp : public Expression 659 1.1 mrg { 660 1.1 mrg public: 661 1.1 mrg void accept(Visitor *v) { v->visit(this); } 662 1.1 mrg }; 663 1.1 mrg 664 1.1 mrg class IsExp : public Expression 665 1.1 mrg { 666 1.1 mrg public: 667 1.1 mrg /* is(targ id tok tspec) 668 1.1 mrg * is(targ id == tok2) 669 1.1 mrg */ 670 1.1 mrg Type *targ; 671 1.1 mrg Identifier *id; // can be NULL 672 1.1 mrg Type *tspec; // can be NULL 673 1.1 mrg TemplateParameters *parameters; 674 1.1.1.3 mrg TOK tok; // ':' or '==' 675 1.1.1.3 mrg TOK tok2; // 'struct', 'union', etc. 676 1.1 mrg 677 1.1.1.3 mrg IsExp *syntaxCopy(); 678 1.1 mrg void accept(Visitor *v) { v->visit(this); } 679 1.1 mrg }; 680 1.1 mrg 681 1.1 mrg /****************************************************************/ 682 1.1 mrg 683 1.1 mrg class UnaExp : public Expression 684 1.1 mrg { 685 1.1 mrg public: 686 1.1 mrg Expression *e1; 687 1.1 mrg Type *att1; // Save alias this type to detect recursion 688 1.1 mrg 689 1.1.1.3 mrg UnaExp *syntaxCopy(); 690 1.1 mrg Expression *incompatibleTypes(); 691 1.1.1.3 mrg Expression *resolveLoc(const Loc &loc, Scope *sc); 692 1.1 mrg 693 1.1 mrg void accept(Visitor *v) { v->visit(this); } 694 1.1 mrg }; 695 1.1 mrg 696 1.1 mrg class BinExp : public Expression 697 1.1 mrg { 698 1.1 mrg public: 699 1.1 mrg Expression *e1; 700 1.1 mrg Expression *e2; 701 1.1 mrg 702 1.1 mrg Type *att1; // Save alias this type to detect recursion 703 1.1 mrg Type *att2; // Save alias this type to detect recursion 704 1.1 mrg 705 1.1.1.3 mrg BinExp *syntaxCopy(); 706 1.1 mrg Expression *incompatibleTypes(); 707 1.1 mrg 708 1.1 mrg Expression *reorderSettingAAElem(Scope *sc); 709 1.1 mrg 710 1.1 mrg void accept(Visitor *v) { v->visit(this); } 711 1.1 mrg }; 712 1.1 mrg 713 1.1 mrg class BinAssignExp : public BinExp 714 1.1 mrg { 715 1.1 mrg public: 716 1.1 mrg bool isLvalue(); 717 1.1 mrg Expression *toLvalue(Scope *sc, Expression *ex); 718 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 719 1.1 mrg void accept(Visitor *v) { v->visit(this); } 720 1.1 mrg }; 721 1.1 mrg 722 1.1 mrg /****************************************************************/ 723 1.1 mrg 724 1.1.1.3 mrg class MixinExp : public UnaExp 725 1.1 mrg { 726 1.1 mrg public: 727 1.1 mrg void accept(Visitor *v) { v->visit(this); } 728 1.1 mrg }; 729 1.1 mrg 730 1.1 mrg class ImportExp : public UnaExp 731 1.1 mrg { 732 1.1 mrg public: 733 1.1 mrg void accept(Visitor *v) { v->visit(this); } 734 1.1 mrg }; 735 1.1 mrg 736 1.1 mrg class AssertExp : public UnaExp 737 1.1 mrg { 738 1.1 mrg public: 739 1.1 mrg Expression *msg; 740 1.1 mrg 741 1.1.1.3 mrg AssertExp *syntaxCopy(); 742 1.1.1.3 mrg 743 1.1.1.3 mrg void accept(Visitor *v) { v->visit(this); } 744 1.1.1.3 mrg }; 745 1.1.1.3 mrg 746 1.1.1.3 mrg class ThrowExp : public UnaExp 747 1.1.1.3 mrg { 748 1.1.1.3 mrg public: 749 1.1.1.3 mrg ThrowExp *syntaxCopy(); 750 1.1 mrg 751 1.1 mrg void accept(Visitor *v) { v->visit(this); } 752 1.1 mrg }; 753 1.1 mrg 754 1.1 mrg class DotIdExp : public UnaExp 755 1.1 mrg { 756 1.1 mrg public: 757 1.1 mrg Identifier *ident; 758 1.1 mrg bool noderef; // true if the result of the expression will never be dereferenced 759 1.1 mrg bool wantsym; // do not replace Symbol with its initializer during semantic() 760 1.1.1.3 mrg bool arrow; // ImportC: if -> instead of . 761 1.1 mrg 762 1.1.1.3 mrg static DotIdExp *create(const Loc &loc, Expression *e, Identifier *ident); 763 1.1 mrg void accept(Visitor *v) { v->visit(this); } 764 1.1 mrg }; 765 1.1 mrg 766 1.1 mrg class DotTemplateExp : public UnaExp 767 1.1 mrg { 768 1.1 mrg public: 769 1.1 mrg TemplateDeclaration *td; 770 1.1 mrg 771 1.1.1.2 mrg bool checkType(); 772 1.1.1.2 mrg bool checkValue(); 773 1.1 mrg void accept(Visitor *v) { v->visit(this); } 774 1.1 mrg }; 775 1.1 mrg 776 1.1 mrg class DotVarExp : public UnaExp 777 1.1 mrg { 778 1.1 mrg public: 779 1.1 mrg Declaration *var; 780 1.1 mrg bool hasOverloads; 781 1.1 mrg 782 1.1 mrg bool isLvalue(); 783 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 784 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 785 1.1 mrg void accept(Visitor *v) { v->visit(this); } 786 1.1 mrg }; 787 1.1 mrg 788 1.1 mrg class DotTemplateInstanceExp : public UnaExp 789 1.1 mrg { 790 1.1 mrg public: 791 1.1 mrg TemplateInstance *ti; 792 1.1 mrg 793 1.1.1.3 mrg DotTemplateInstanceExp *syntaxCopy(); 794 1.1 mrg bool findTempDecl(Scope *sc); 795 1.1.1.3 mrg bool checkType(); 796 1.1.1.3 mrg bool checkValue(); 797 1.1 mrg void accept(Visitor *v) { v->visit(this); } 798 1.1 mrg }; 799 1.1 mrg 800 1.1 mrg class DelegateExp : public UnaExp 801 1.1 mrg { 802 1.1 mrg public: 803 1.1 mrg FuncDeclaration *func; 804 1.1 mrg bool hasOverloads; 805 1.1.1.3 mrg VarDeclaration *vthis2; // container for multi-context 806 1.1 mrg 807 1.1 mrg 808 1.1 mrg void accept(Visitor *v) { v->visit(this); } 809 1.1 mrg }; 810 1.1 mrg 811 1.1 mrg class DotTypeExp : public UnaExp 812 1.1 mrg { 813 1.1 mrg public: 814 1.1 mrg Dsymbol *sym; // symbol that represents a type 815 1.1 mrg 816 1.1 mrg void accept(Visitor *v) { v->visit(this); } 817 1.1 mrg }; 818 1.1 mrg 819 1.1 mrg class CallExp : public UnaExp 820 1.1 mrg { 821 1.1 mrg public: 822 1.1 mrg Expressions *arguments; // function arguments 823 1.1 mrg FuncDeclaration *f; // symbol to call 824 1.1 mrg bool directcall; // true if a virtual call is devirtualized 825 1.1.1.3 mrg bool inDebugStatement; // true if this was in a debug statement 826 1.1.1.3 mrg bool ignoreAttributes; // don't enforce attributes (e.g. call @gc function in @nogc code) 827 1.1.1.3 mrg VarDeclaration *vthis2; // container for multi-context 828 1.1.1.3 mrg 829 1.1.1.3 mrg static CallExp *create(const Loc &loc, Expression *e, Expressions *exps); 830 1.1.1.3 mrg static CallExp *create(const Loc &loc, Expression *e); 831 1.1.1.3 mrg static CallExp *create(const Loc &loc, Expression *e, Expression *earg1); 832 1.1.1.3 mrg static CallExp *create(const Loc &loc, FuncDeclaration *fd, Expression *earg1); 833 1.1 mrg 834 1.1.1.3 mrg CallExp *syntaxCopy(); 835 1.1 mrg bool isLvalue(); 836 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 837 1.1 mrg Expression *addDtorHook(Scope *sc); 838 1.1 mrg 839 1.1 mrg void accept(Visitor *v) { v->visit(this); } 840 1.1 mrg }; 841 1.1 mrg 842 1.1 mrg class AddrExp : public UnaExp 843 1.1 mrg { 844 1.1 mrg public: 845 1.1 mrg void accept(Visitor *v) { v->visit(this); } 846 1.1 mrg }; 847 1.1 mrg 848 1.1 mrg class PtrExp : public UnaExp 849 1.1 mrg { 850 1.1 mrg public: 851 1.1 mrg bool isLvalue(); 852 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 853 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 854 1.1 mrg 855 1.1 mrg void accept(Visitor *v) { v->visit(this); } 856 1.1 mrg }; 857 1.1 mrg 858 1.1 mrg class NegExp : public UnaExp 859 1.1 mrg { 860 1.1 mrg public: 861 1.1 mrg void accept(Visitor *v) { v->visit(this); } 862 1.1 mrg }; 863 1.1 mrg 864 1.1 mrg class UAddExp : public UnaExp 865 1.1 mrg { 866 1.1 mrg public: 867 1.1 mrg void accept(Visitor *v) { v->visit(this); } 868 1.1 mrg }; 869 1.1 mrg 870 1.1 mrg class ComExp : public UnaExp 871 1.1 mrg { 872 1.1 mrg public: 873 1.1 mrg void accept(Visitor *v) { v->visit(this); } 874 1.1 mrg }; 875 1.1 mrg 876 1.1 mrg class NotExp : public UnaExp 877 1.1 mrg { 878 1.1 mrg public: 879 1.1 mrg void accept(Visitor *v) { v->visit(this); } 880 1.1 mrg }; 881 1.1 mrg 882 1.1 mrg class DeleteExp : public UnaExp 883 1.1 mrg { 884 1.1 mrg public: 885 1.1 mrg bool isRAII; 886 1.1 mrg void accept(Visitor *v) { v->visit(this); } 887 1.1 mrg }; 888 1.1 mrg 889 1.1 mrg class CastExp : public UnaExp 890 1.1 mrg { 891 1.1 mrg public: 892 1.1 mrg // Possible to cast to one type while painting to another type 893 1.1 mrg Type *to; // type to cast to 894 1.1 mrg unsigned char mod; // MODxxxxx 895 1.1 mrg 896 1.1.1.3 mrg CastExp *syntaxCopy(); 897 1.1.1.3 mrg bool isLvalue(); 898 1.1.1.3 mrg Expression *toLvalue(Scope *sc, Expression *e); 899 1.1 mrg 900 1.1 mrg void accept(Visitor *v) { v->visit(this); } 901 1.1 mrg }; 902 1.1 mrg 903 1.1 mrg class VectorExp : public UnaExp 904 1.1 mrg { 905 1.1 mrg public: 906 1.1 mrg TypeVector *to; // the target vector type before semantic() 907 1.1 mrg unsigned dim; // number of elements in the vector 908 1.1 mrg OwnedBy ownedByCtfe; 909 1.1 mrg 910 1.1.1.3 mrg static VectorExp *create(const Loc &loc, Expression *e, Type *t); 911 1.1.1.3 mrg static void emplace(UnionExp *pue, const Loc &loc, Expression *e, Type *t); 912 1.1.1.3 mrg VectorExp *syntaxCopy(); 913 1.1 mrg void accept(Visitor *v) { v->visit(this); } 914 1.1 mrg }; 915 1.1 mrg 916 1.1 mrg class VectorArrayExp : public UnaExp 917 1.1 mrg { 918 1.1 mrg public: 919 1.1 mrg bool isLvalue(); 920 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 921 1.1 mrg void accept(Visitor *v) { v->visit(this); } 922 1.1 mrg }; 923 1.1 mrg 924 1.1 mrg class SliceExp : public UnaExp 925 1.1 mrg { 926 1.1 mrg public: 927 1.1 mrg Expression *upr; // NULL if implicit 0 928 1.1 mrg Expression *lwr; // NULL if implicit [length - 1] 929 1.1 mrg VarDeclaration *lengthVar; 930 1.1 mrg bool upperIsInBounds; // true if upr <= e1.length 931 1.1 mrg bool lowerIsLessThanUpper; // true if lwr <= upr 932 1.1 mrg bool arrayop; // an array operation, rather than a slice 933 1.1 mrg 934 1.1.1.3 mrg SliceExp *syntaxCopy(); 935 1.1 mrg bool isLvalue(); 936 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 937 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 938 1.1.1.3 mrg Optional<bool> toBool(); 939 1.1 mrg 940 1.1 mrg void accept(Visitor *v) { v->visit(this); } 941 1.1 mrg }; 942 1.1 mrg 943 1.1 mrg class ArrayLengthExp : public UnaExp 944 1.1 mrg { 945 1.1 mrg public: 946 1.1 mrg void accept(Visitor *v) { v->visit(this); } 947 1.1 mrg }; 948 1.1 mrg 949 1.1 mrg class IntervalExp : public Expression 950 1.1 mrg { 951 1.1 mrg public: 952 1.1 mrg Expression *lwr; 953 1.1 mrg Expression *upr; 954 1.1 mrg 955 1.1.1.3 mrg IntervalExp *syntaxCopy(); 956 1.1 mrg void accept(Visitor *v) { v->visit(this); } 957 1.1 mrg }; 958 1.1 mrg 959 1.1 mrg class DelegatePtrExp : public UnaExp 960 1.1 mrg { 961 1.1 mrg public: 962 1.1 mrg bool isLvalue(); 963 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 964 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 965 1.1 mrg void accept(Visitor *v) { v->visit(this); } 966 1.1 mrg }; 967 1.1 mrg 968 1.1 mrg class DelegateFuncptrExp : public UnaExp 969 1.1 mrg { 970 1.1 mrg public: 971 1.1 mrg bool isLvalue(); 972 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 973 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 974 1.1 mrg void accept(Visitor *v) { v->visit(this); } 975 1.1 mrg }; 976 1.1 mrg 977 1.1 mrg // e1[a0,a1,a2,a3,...] 978 1.1 mrg 979 1.1 mrg class ArrayExp : public UnaExp 980 1.1 mrg { 981 1.1 mrg public: 982 1.1 mrg Expressions *arguments; // Array of Expression's 983 1.1 mrg size_t currentDimension; // for opDollar 984 1.1 mrg VarDeclaration *lengthVar; 985 1.1 mrg 986 1.1.1.3 mrg ArrayExp *syntaxCopy(); 987 1.1 mrg bool isLvalue(); 988 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 989 1.1 mrg 990 1.1 mrg void accept(Visitor *v) { v->visit(this); } 991 1.1 mrg }; 992 1.1 mrg 993 1.1 mrg /****************************************************************/ 994 1.1 mrg 995 1.1 mrg class DotExp : public BinExp 996 1.1 mrg { 997 1.1 mrg public: 998 1.1 mrg void accept(Visitor *v) { v->visit(this); } 999 1.1 mrg }; 1000 1.1 mrg 1001 1.1 mrg class CommaExp : public BinExp 1002 1.1 mrg { 1003 1.1 mrg public: 1004 1.1 mrg bool isGenerated; 1005 1.1 mrg bool allowCommaExp; 1006 1.1 mrg bool isLvalue(); 1007 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 1008 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 1009 1.1.1.3 mrg Optional<bool> toBool(); 1010 1.1 mrg Expression *addDtorHook(Scope *sc); 1011 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1012 1.1 mrg }; 1013 1.1 mrg 1014 1.1 mrg class IndexExp : public BinExp 1015 1.1 mrg { 1016 1.1 mrg public: 1017 1.1 mrg VarDeclaration *lengthVar; 1018 1.1 mrg bool modifiable; 1019 1.1 mrg bool indexIsInBounds; // true if 0 <= e2 && e2 <= e1.length - 1 1020 1.1 mrg 1021 1.1.1.3 mrg IndexExp *syntaxCopy(); 1022 1.1 mrg bool isLvalue(); 1023 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 1024 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 1025 1.1 mrg 1026 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1027 1.1 mrg }; 1028 1.1 mrg 1029 1.1 mrg /* For both i++ and i-- 1030 1.1 mrg */ 1031 1.1 mrg class PostExp : public BinExp 1032 1.1 mrg { 1033 1.1 mrg public: 1034 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1035 1.1 mrg }; 1036 1.1 mrg 1037 1.1 mrg /* For both ++i and --i 1038 1.1 mrg */ 1039 1.1 mrg class PreExp : public UnaExp 1040 1.1 mrg { 1041 1.1 mrg public: 1042 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1043 1.1 mrg }; 1044 1.1 mrg 1045 1.1.1.3 mrg enum class MemorySet 1046 1.1 mrg { 1047 1.1.1.3 mrg none = 0, // simple assignment 1048 1.1 mrg blockAssign = 1, // setting the contents of an array 1049 1.1 mrg referenceInit = 2 // setting the reference of STCref variable 1050 1.1 mrg }; 1051 1.1 mrg 1052 1.1 mrg class AssignExp : public BinExp 1053 1.1 mrg { 1054 1.1 mrg public: 1055 1.1.1.3 mrg MemorySet memset; 1056 1.1 mrg 1057 1.1 mrg bool isLvalue(); 1058 1.1 mrg Expression *toLvalue(Scope *sc, Expression *ex); 1059 1.1 mrg 1060 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1061 1.1 mrg }; 1062 1.1 mrg 1063 1.1 mrg class ConstructExp : public AssignExp 1064 1.1 mrg { 1065 1.1 mrg public: 1066 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1067 1.1 mrg }; 1068 1.1 mrg 1069 1.1 mrg class BlitExp : public AssignExp 1070 1.1 mrg { 1071 1.1 mrg public: 1072 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1073 1.1 mrg }; 1074 1.1 mrg 1075 1.1 mrg class AddAssignExp : public BinAssignExp 1076 1.1 mrg { 1077 1.1 mrg public: 1078 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1079 1.1 mrg }; 1080 1.1 mrg 1081 1.1 mrg class MinAssignExp : public BinAssignExp 1082 1.1 mrg { 1083 1.1 mrg public: 1084 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1085 1.1 mrg }; 1086 1.1 mrg 1087 1.1 mrg class MulAssignExp : public BinAssignExp 1088 1.1 mrg { 1089 1.1 mrg public: 1090 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1091 1.1 mrg }; 1092 1.1 mrg 1093 1.1 mrg class DivAssignExp : public BinAssignExp 1094 1.1 mrg { 1095 1.1 mrg public: 1096 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1097 1.1 mrg }; 1098 1.1 mrg 1099 1.1 mrg class ModAssignExp : public BinAssignExp 1100 1.1 mrg { 1101 1.1 mrg public: 1102 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1103 1.1 mrg }; 1104 1.1 mrg 1105 1.1 mrg class AndAssignExp : public BinAssignExp 1106 1.1 mrg { 1107 1.1 mrg public: 1108 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1109 1.1 mrg }; 1110 1.1 mrg 1111 1.1 mrg class OrAssignExp : public BinAssignExp 1112 1.1 mrg { 1113 1.1 mrg public: 1114 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1115 1.1 mrg }; 1116 1.1 mrg 1117 1.1 mrg class XorAssignExp : public BinAssignExp 1118 1.1 mrg { 1119 1.1 mrg public: 1120 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1121 1.1 mrg }; 1122 1.1 mrg 1123 1.1 mrg class PowAssignExp : public BinAssignExp 1124 1.1 mrg { 1125 1.1 mrg public: 1126 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1127 1.1 mrg }; 1128 1.1 mrg 1129 1.1 mrg class ShlAssignExp : public BinAssignExp 1130 1.1 mrg { 1131 1.1 mrg public: 1132 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1133 1.1 mrg }; 1134 1.1 mrg 1135 1.1 mrg class ShrAssignExp : public BinAssignExp 1136 1.1 mrg { 1137 1.1 mrg public: 1138 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1139 1.1 mrg }; 1140 1.1 mrg 1141 1.1 mrg class UshrAssignExp : public BinAssignExp 1142 1.1 mrg { 1143 1.1 mrg public: 1144 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1145 1.1 mrg }; 1146 1.1 mrg 1147 1.1 mrg class CatAssignExp : public BinAssignExp 1148 1.1 mrg { 1149 1.1 mrg public: 1150 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1151 1.1 mrg }; 1152 1.1 mrg 1153 1.1 mrg class AddExp : public BinExp 1154 1.1 mrg { 1155 1.1 mrg public: 1156 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1157 1.1 mrg }; 1158 1.1 mrg 1159 1.1 mrg class MinExp : public BinExp 1160 1.1 mrg { 1161 1.1 mrg public: 1162 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1163 1.1 mrg }; 1164 1.1 mrg 1165 1.1 mrg class CatExp : public BinExp 1166 1.1 mrg { 1167 1.1 mrg public: 1168 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1169 1.1 mrg }; 1170 1.1 mrg 1171 1.1 mrg class MulExp : public BinExp 1172 1.1 mrg { 1173 1.1 mrg public: 1174 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1175 1.1 mrg }; 1176 1.1 mrg 1177 1.1 mrg class DivExp : public BinExp 1178 1.1 mrg { 1179 1.1 mrg public: 1180 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1181 1.1 mrg }; 1182 1.1 mrg 1183 1.1 mrg class ModExp : public BinExp 1184 1.1 mrg { 1185 1.1 mrg public: 1186 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1187 1.1 mrg }; 1188 1.1 mrg 1189 1.1 mrg class PowExp : public BinExp 1190 1.1 mrg { 1191 1.1 mrg public: 1192 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1193 1.1 mrg }; 1194 1.1 mrg 1195 1.1 mrg class ShlExp : public BinExp 1196 1.1 mrg { 1197 1.1 mrg public: 1198 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1199 1.1 mrg }; 1200 1.1 mrg 1201 1.1 mrg class ShrExp : public BinExp 1202 1.1 mrg { 1203 1.1 mrg public: 1204 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1205 1.1 mrg }; 1206 1.1 mrg 1207 1.1 mrg class UshrExp : public BinExp 1208 1.1 mrg { 1209 1.1 mrg public: 1210 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1211 1.1 mrg }; 1212 1.1 mrg 1213 1.1 mrg class AndExp : public BinExp 1214 1.1 mrg { 1215 1.1 mrg public: 1216 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1217 1.1 mrg }; 1218 1.1 mrg 1219 1.1 mrg class OrExp : public BinExp 1220 1.1 mrg { 1221 1.1 mrg public: 1222 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1223 1.1 mrg }; 1224 1.1 mrg 1225 1.1 mrg class XorExp : public BinExp 1226 1.1 mrg { 1227 1.1 mrg public: 1228 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1229 1.1 mrg }; 1230 1.1 mrg 1231 1.1.1.3 mrg class LogicalExp : public BinExp 1232 1.1 mrg { 1233 1.1 mrg public: 1234 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1235 1.1 mrg }; 1236 1.1 mrg 1237 1.1 mrg class CmpExp : public BinExp 1238 1.1 mrg { 1239 1.1 mrg public: 1240 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1241 1.1 mrg }; 1242 1.1 mrg 1243 1.1 mrg class InExp : public BinExp 1244 1.1 mrg { 1245 1.1 mrg public: 1246 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1247 1.1 mrg }; 1248 1.1 mrg 1249 1.1 mrg class RemoveExp : public BinExp 1250 1.1 mrg { 1251 1.1 mrg public: 1252 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1253 1.1 mrg }; 1254 1.1 mrg 1255 1.1 mrg // == and != 1256 1.1 mrg 1257 1.1 mrg class EqualExp : public BinExp 1258 1.1 mrg { 1259 1.1 mrg public: 1260 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1261 1.1 mrg }; 1262 1.1 mrg 1263 1.1 mrg // is and !is 1264 1.1 mrg 1265 1.1 mrg class IdentityExp : public BinExp 1266 1.1 mrg { 1267 1.1 mrg public: 1268 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1269 1.1 mrg }; 1270 1.1 mrg 1271 1.1 mrg /****************************************************************/ 1272 1.1 mrg 1273 1.1 mrg class CondExp : public BinExp 1274 1.1 mrg { 1275 1.1 mrg public: 1276 1.1 mrg Expression *econd; 1277 1.1 mrg 1278 1.1.1.3 mrg CondExp *syntaxCopy(); 1279 1.1 mrg bool isLvalue(); 1280 1.1 mrg Expression *toLvalue(Scope *sc, Expression *e); 1281 1.1 mrg Expression *modifiableLvalue(Scope *sc, Expression *e); 1282 1.1 mrg void hookDtors(Scope *sc); 1283 1.1 mrg 1284 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1285 1.1 mrg }; 1286 1.1 mrg 1287 1.1.1.3 mrg class GenericExp : Expression 1288 1.1.1.3 mrg { 1289 1.1.1.3 mrg Expression *cntlExp; 1290 1.1.1.3 mrg Types *types; 1291 1.1.1.3 mrg Expressions *exps; 1292 1.1.1.3 mrg 1293 1.1.1.3 mrg GenericExp *syntaxCopy(); 1294 1.1.1.3 mrg 1295 1.1.1.3 mrg void accept(Visitor *v) { v->visit(this); } 1296 1.1.1.3 mrg }; 1297 1.1.1.3 mrg 1298 1.1 mrg /****************************************************************/ 1299 1.1 mrg 1300 1.1 mrg class DefaultInitExp : public Expression 1301 1.1 mrg { 1302 1.1 mrg public: 1303 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1304 1.1 mrg }; 1305 1.1 mrg 1306 1.1 mrg class FileInitExp : public DefaultInitExp 1307 1.1 mrg { 1308 1.1 mrg public: 1309 1.1.1.3 mrg Expression *resolveLoc(const Loc &loc, Scope *sc); 1310 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1311 1.1 mrg }; 1312 1.1 mrg 1313 1.1 mrg class LineInitExp : public DefaultInitExp 1314 1.1 mrg { 1315 1.1 mrg public: 1316 1.1.1.3 mrg Expression *resolveLoc(const Loc &loc, Scope *sc); 1317 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1318 1.1 mrg }; 1319 1.1 mrg 1320 1.1 mrg class ModuleInitExp : public DefaultInitExp 1321 1.1 mrg { 1322 1.1 mrg public: 1323 1.1.1.3 mrg Expression *resolveLoc(const Loc &loc, Scope *sc); 1324 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1325 1.1 mrg }; 1326 1.1 mrg 1327 1.1 mrg class FuncInitExp : public DefaultInitExp 1328 1.1 mrg { 1329 1.1 mrg public: 1330 1.1.1.3 mrg Expression *resolveLoc(const Loc &loc, Scope *sc); 1331 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1332 1.1 mrg }; 1333 1.1 mrg 1334 1.1 mrg class PrettyFuncInitExp : public DefaultInitExp 1335 1.1 mrg { 1336 1.1 mrg public: 1337 1.1.1.3 mrg Expression *resolveLoc(const Loc &loc, Scope *sc); 1338 1.1 mrg void accept(Visitor *v) { v->visit(this); } 1339 1.1 mrg }; 1340 1.1 mrg 1341 1.1 mrg /****************************************************************/ 1342 1.1 mrg 1343 1.1 mrg /* A type meant as a union of all the Expression types, 1344 1.1 mrg * to serve essentially as a Variant that will sit on the stack 1345 1.1 mrg * during CTFE to reduce memory consumption. 1346 1.1 mrg */ 1347 1.1 mrg struct UnionExp 1348 1.1 mrg { 1349 1.1 mrg UnionExp() { } // yes, default constructor does nothing 1350 1.1 mrg 1351 1.1 mrg UnionExp(Expression *e) 1352 1.1 mrg { 1353 1.1 mrg memcpy(this, (void *)e, e->size); 1354 1.1 mrg } 1355 1.1 mrg 1356 1.1 mrg /* Extract pointer to Expression 1357 1.1 mrg */ 1358 1.1 mrg Expression *exp() { return (Expression *)&u; } 1359 1.1 mrg 1360 1.1 mrg /* Convert to an allocated Expression 1361 1.1 mrg */ 1362 1.1 mrg Expression *copy(); 1363 1.1 mrg 1364 1.1 mrg private: 1365 1.1 mrg // Ensure that the union is suitably aligned. 1366 1.1 mrg #if defined(__GNUC__) || defined(__clang__) 1367 1.1 mrg __attribute__((aligned(8))) 1368 1.1 mrg #elif defined(_MSC_VER) 1369 1.1 mrg __declspec(align(8)) 1370 1.1 mrg #elif defined(__DMC__) 1371 1.1 mrg #pragma pack(8) 1372 1.1 mrg #endif 1373 1.1 mrg union 1374 1.1 mrg { 1375 1.1 mrg char exp [sizeof(Expression)]; 1376 1.1 mrg char integerexp[sizeof(IntegerExp)]; 1377 1.1 mrg char errorexp [sizeof(ErrorExp)]; 1378 1.1 mrg char realexp [sizeof(RealExp)]; 1379 1.1 mrg char complexexp[sizeof(ComplexExp)]; 1380 1.1 mrg char symoffexp [sizeof(SymOffExp)]; 1381 1.1 mrg char stringexp [sizeof(StringExp)]; 1382 1.1 mrg char arrayliteralexp [sizeof(ArrayLiteralExp)]; 1383 1.1 mrg char assocarrayliteralexp [sizeof(AssocArrayLiteralExp)]; 1384 1.1 mrg char structliteralexp [sizeof(StructLiteralExp)]; 1385 1.1 mrg char nullexp [sizeof(NullExp)]; 1386 1.1 mrg char dotvarexp [sizeof(DotVarExp)]; 1387 1.1 mrg char addrexp [sizeof(AddrExp)]; 1388 1.1 mrg char indexexp [sizeof(IndexExp)]; 1389 1.1 mrg char sliceexp [sizeof(SliceExp)]; 1390 1.1 mrg char vectorexp [sizeof(VectorExp)]; 1391 1.1 mrg } u; 1392 1.1 mrg #if defined(__DMC__) 1393 1.1 mrg #pragma pack() 1394 1.1 mrg #endif 1395 1.1 mrg }; 1396 1.1 mrg 1397 1.1 mrg /****************************************************************/ 1398 1.1 mrg 1399 1.1.1.3 mrg class ObjcClassReferenceExp : public Expression 1400 1.1.1.3 mrg { 1401 1.1.1.3 mrg public: 1402 1.1.1.3 mrg ClassDeclaration* classDeclaration; 1403 1.1 mrg 1404 1.1.1.3 mrg void accept(Visitor *v) { v->visit(this); } 1405 1.1.1.3 mrg }; 1406