dmd.expression
Specification ($LINK2 https://dlang.org/spec/expression.html, Expressions)
Source expression.d
Documentation https://dlang.org/phobos/dmd_expression.html
- inout(Expression)lastComma(inout Expressione);
- Find the last non-comma expression.Parameters:Expression eExpressions connected by commas Returns:right-most non-comma expression
- voidexpandTuples(Expressions*exps, Identifiers*names= null);
- Expand tuples in-place.Example When there's a call f(10, pair: AliasSeq!(20, 30), single: 40), the input is: exps= [10, (20, 30), 40]names= [null, "pair", "single"] The arrays will be modified to:exps= [10, 20, 30, 40]names= [null, "pair", null, "single"]Parameters:Expressions* expsarray of Expressions Identifiers* namesoptional array of names corresponding to Expressions 
- @safe TemplateDeclarationgetFuncTemplateDecl(Dsymbols);
- Ifsis a function template, i.e. the only member of a template and that member is a function, return that template.Parameters:Dsymbol ssymbol that might be a function template Returns:template for that function, otherwise null
- @safe DotIdExptypeDotIdExp(Locloc, Typetype, Identifierident);
- TypeDotIdExp
- VarDeclarationexpToVariable(Expressione, out intderef);
- Given an Expression, find the variable it really is.For example, a[index] is really a, and s.f is really s.Parameters:Expression eExpression to look at int derefnumber of dereferences encountered Returns:variable if there is one, null if not
- abstract classExpression: dmd.ast_node.ASTNode;
- 
- Typetype;
- Usually, this starts out as null and gets set to the final expression type by expressionSemantic. However, for some expressions (such as TypeExp,RealExp, VarExp), the field can get set to an assigned type before running semantic. See expressionSemanticDone
- final pure nothrow @nogc @safe size_tsize() const;
- Returns:class instance size of this expression (implemented manually because extern(C++))
- static voiddeinitialize();
- Deinitializes the global state of the compiler.This can be used to restore the state set by _init to its original state.
- final Expressioncopy();
- Does not do a deep copy.
- static @safe Expressioncombine(Expressione1, Expressione2);
- Combine e1 and e2 by CommaExp if both are not NULL.
- static @trusted ExpressionextractLast(Expressione, out Expressione0);
- If 'e' is a tree of commas, returns the rightmost expression by stripping off it from the tree. The remained part of the tree is returned via e0. Otherwise 'e' is directly returned and e0 is set to NULL.
- boolisLvalue();
- Return !=0 if expression is an lvalue.
- boolcheckType();
- Check that the expression has a valid type. If not, generates an error "... has no type".Returns:true if the expression is not valid.Note When this function returns true, checkValue() should also return true. 
- final ExpressionaddressOf();
- Take address of expression.
- final Expressionderef();
- If this is a reference, dereference it.
- boolisIdentical(const Expressione) const;
- Identical, not just equal. I.e. NaNs with different bit patterns are not identical
- Optional!booltoBool();
- Statically evaluate this expression to a bool if possibleReturns:an optional thath either contains the value or is empty
 
- classIntegerExp: dmd.expression.Expression;
- A compile-time known integer value- IntegerExpliteral(int v)();
- Use this instead of creating new instances for commonly used literals such as 0 or 1.Parameters v = The value of the expression Returns:A static instance of the expression, typed as Tint32.
- static IntegerExpcreateBool(boolb);
- Use this instead of creating new instances for commonly used bools.Parameters b = The value of the expression Returns:A static instance of the expression, typed as Type.tbool.
 
- classErrorExp: dmd.expression.Expression;
- Use this expression for error recovery.It should behave as a 'sink' to prevent further cascaded error messages.
- classVoidInitExp: dmd.expression.Expression;
- An uninitialized value, generated from void initializers.- VarDeclarationvar;
- the variable from where the void value came from, null if not known
- @safe this(VarDeclarationvar);
- Useful for error messages
 
- classRealExp: dmd.expression.Expression;
- A compile-time known floating point number
- classComplexExp: dmd.expression.Expression;
- A compile-time complex number (deprecated)
- classIdentifierExp: dmd.expression.Expression;
- An identifier in the context of an expression (as opposed to a declaration)int x; // VarDeclaration with Identifier x++; // PostExp with IdentifierExp 
- classDollarExp: dmd.expression.IdentifierExp;
- The dollar operator used when indexing or slicing an array. E.g a[$], a[1 .. $] etc.
- classDsymbolExp: dmd.expression.Expression;
- Won't be generated by parser.
- classThisExp: dmd.expression.Expression;
- classSuperExp: dmd.expression.ThisExp;
- classNullExp: dmd.expression.Expression;
- A compile-time known null value
- classStringExp: dmd.expression.Expression;
- 
- boolcommitted;
- Whether the string literal's type is fixedExample wstring x = "abc"; // OK, string literal is flexible wstring y = cast(string) "abc"; // Error: type was committed after cast 
- boolhexString;
- If the string is parsed from a hex string literal
- size_tnumberOfCodeUnits(inttynto= 0) const;
- Return the number of code units the string would be if it were re-encoded as tynto.Parameters:int tyntocode unit type of the target encoding Returns:number of code units
- voidwriteTo(void*dest, boolzero, inttyto= 0) const;
- Write the contents of the string to dest. Use numberOfCodeUnits() to determine size of result.Parameters:void* destdestination int tytoencoding type of the result bool zeroadd terminating 0 
- pure dchargetCodeUnit(size_ti) const;
- Get the code unit at index iParameters:size_t iindex Returns:code unit at index i
- pure dinteger_tgetIndex(size_ti) const;
- Returns:integer at indexi
- voidsetCodeUnit(size_ti, dcharc);
- Set the code unit at index i to cParameters:size_t iindex dchar ccode unit to set it to 
- pure nothrow @nogc intcompare(const StringExpse2) const;
- Compare two StringExp by length, then valueThe comparison is not the usual C-style comparison as seen with strcmp or memcmp, but instead first compare based on the length. This allows both faster lookup and sorting when comparing sparse data. This ordering scheme is relied on by the string-switching feature. Code in Druntime's core.internal.switch_ relies on this ordering when doing a binary search among case statements. Both StringExp should be of the same encoding.Parameters:StringExp se2String expression to compare this to Returns:0 when this is equal to se2, a value greater than 0 if this should be considered greater thanse2, and a value less than 0 if this is lesser thanse2.
- const(char)[]toStringz() const;
- Convert string contents to a 0 terminated string, allocated by mem.xmalloc().
- const(ubyte)[]peekData() const;
- Get a slice of the data.
- ubyte[]borrowData();
- Borrow a slice of the data, so the caller can modify it in-place (!)
- voidsetData(void*s, size_tlen, ubytesz);
- Set new string data. this becomes the new owner of the data.
 
- classTupleExp: dmd.expression.Expression;
- A sequence of expressionsalias AliasSeq(T...) = T; alias Tup = AliasSeq!(3, int, "abc"); 
- classArrayLiteralExp: dmd.expression.Expression;
- [ e1, e2, e3, ... ]- Expressionbasis;
- If !is null, elements[] can be sparse and basis is used for the "default" element value. In other words, non-null elements[i] overrides this 'basis' value.
 
- classAssocArrayLiteralExp: dmd.expression.Expression;
- [ key0 : value0, key1 : value1, ... ]- Expressionlowering;
- Lower to core.internal.newaa for static initializaton
 
- classStructLiteralExp: dmd.expression.Expression;
- sd( e1, e2, e3, ... )- StructDeclarationsd;
- which aggregate this is for
- Expressions*elements;
- parallels sd.fields[] with null entries for fields to skip
- Typestype;
- final type of result (can be different from sd's type)
- void*sym;
- back end symbol to initialize with literal (used as a Symbol*)
- StructLiteralExpinlinecopy;
- those fields need to prevent a infinite recursion when one field of struct initialized with 'this' pointer.
- StructLiteralExporigin;
- pointer to the origin instance of the expression. once a new expression is created, origin is set to 'this'. anytime when an expression copy is created, 'origin' pointer is set to 'origin' pointer value of the original expression.
- enumStageFlags: ubyte;
- anytime when recursive function is calling, 'stageflags' marks with bit flag of current stage and unmarks before return from this function. 'inlinecopy' uses similar 'stageflags' and from multiple evaluation 'doInline' (with infinite recursion) of this expression.- scrub
- scrubReturnValue is running
- searchPointers
- hasNonConstPointers is running
- optimize
- optimize is running
- apply
- apply is running
- inlineScan
- inlineScan is running
- toCBuffer
- toCBuffer is running
 
- ExpressiongetField(Typetype, uintoffset);
- Gets expression at offset of type. Returns NULL if not found.
- intgetFieldIndex(Typetype, uintoffset);
- Get index of field. Returns -1 if not found.
 
- classCompoundLiteralExp: dmd.expression.Expression;
- C11 6.5.2.5 ( type-name ) { initializer-list }- Initializerinitializer;
- initializer-list
 
- classTypeExp: dmd.expression.Expression;
- Mainly just a placeholder
- classScopeExp: dmd.expression.Expression;
- Mainly just a placeholder of Package, Module, Nspace, and TemplateInstance (including TemplateMixin)A template instance that requires IFTI: foo!tiargs(fargs) // foo!tiargs is left until CallExp::semantic() or resolveProperties()
- classTemplateExp: dmd.expression.Expression;
- Mainly just a placeholder
- classNewExp: dmd.expression.Expression;
- newtype(arguments)- ArgumentListargumentList();
- Puts the arguments and names into an ArgumentList for easily passing them around. The fields are still separate for backwards compatibility
 
- classNewAnonClassExp: dmd.expression.Expression;
- class baseclasses { } (arguments)
- classSymbolExp: dmd.expression.Expression;
- classSymOffExp: dmd.expression.SymbolExp;
- Offset from symbol
- classVarExp: dmd.expression.SymbolExp;
- Variable
- classOverExp: dmd.expression.Expression;
- Overload Set
- classFuncExp: dmd.expression.Expression;
- Function/Delegate literal
- classDeclarationExp: dmd.expression.Expression;
- Declaration of a symbolD grammar allows declarations only as statements. However in AST representation it can be part of any expression. This is used, for example, during internal syntax re-writes to inject hidden symbols.
- classTypeidExp: dmd.expression.Expression;
- typeid(int)
- classTraitsExp: dmd.expression.Expression;
- _traits(identifier, args...)
- classHaltExp: dmd.expression.Expression;
- Generates a halt instructionassert(0) gets rewritten to this with CHECKACTION.halt
- classIsExp: dmd.expression.Expression;
- is(targ id tok tspec) is(targ id == tok2)
- abstract classUnaExp: dmd.expression.Expression;
- Base class for unary operators- final voidsetNoderefOperand();
- Mark the operand as will never be dereferenced, which is useful info for @safe checks. Do before semantic() on operands rewrites them.
 
- abstract classBinExp: dmd.expression.Expression;
- Base class for binary operators- final voidsetNoderefOperands();
- Mark the operands as will never be dereferenced, which is useful info for @safe checks. Do before semantic() on operands rewrites them.
 
- classBinAssignExp: dmd.expression.BinExp;
- Binary operator assignment, += -= *= etc.
- classMixinExp: dmd.expression.Expression;
- A string mixin, mixin("x")
- classImportExp: dmd.expression.UnaExp;
- An import expression, import("file.txt")Not to be confused with module imports, import std.stdio, which is an ImportStatement https://dlang.org/spec/expression.html#import_expressions
- classAssertExp: dmd.expression.UnaExp;
- An assert expression, assert(x == y)
- classThrowExp: dmd.expression.UnaExp;
- throw <e1> as proposed by DIP 1034.Replacement for the deprecated ThrowStatement that can be nested in other expression.
- classDotIdExp: dmd.expression.UnaExp;
- classDotTemplateExp: dmd.expression.UnaExp;
- Mainly just a placeholder
- classDotVarExp: dmd.expression.UnaExp;
- classDotTemplateInstanceExp: dmd.expression.UnaExp;
- foo.bar!(args)
- classDelegateExp: dmd.expression.UnaExp;
- classDotTypeExp: dmd.expression.UnaExp;
- structArgumentList;
- The arguments of a function callContains a list of expressions. If it is a named argument, the names list has a non-null entry at the same index.- pure nothrow @nogc @safe boolhasNames() const;
- Returns:whether this argument list contains any named arguments
 
- classCallExp: dmd.expression.UnaExp;
- 
- boolinDebugStatement;
- true if this was in a debug statement
- boolignoreAttributes;
- don't enforce attributes (e.g. call @gc function in @nogc code)
- boolisUfcsRewrite;
- the first argument was pushed in here by a UFCS rewrite
- ArgumentListargumentList();
- Puts the arguments and names into an ArgumentList for easily passing them around. The fields are still separate for backwards compatibility
- this(Locloc, FuncDeclarationfd, Expressionearg1);
- Instatiates a new function call expressionParameters:Loc loclocation FuncDeclaration fdthe declaration of the function to call Expression earg1the function argument 
- static CallExpcreate(Locloc, FuncDeclarationfd, Expressionearg1);
- Creates a new function call expressionParameters:Loc loclocation FuncDeclaration fdthe declaration of the function to call Expression earg1the function argument 
 
- TypeFunctioncalledFunctionType(CallExpce);
- Get the called function type from a call expressionParameters:CallExp cefunction call expression. Must have had semantic analysis done. Returns:called function type, or null if error / no semantic analysis done
- classAddrExp: dmd.expression.UnaExp;
- The 'address of' operator, &p
- classPtrExp: dmd.expression.UnaExp;
- The pointer dereference operator, *p
- classNegExp: dmd.expression.UnaExp;
- The negation operator, -x
- classUAddExp: dmd.expression.UnaExp;
- The unary add operator, +x
- classComExp: dmd.expression.UnaExp;
- The bitwise complement operator, ~x
- classNotExp: dmd.expression.UnaExp;
- The logical not operator, !x
- classDeleteExp: dmd.expression.UnaExp;
- The delete operator, delete x (deprecated)
- classCastExp: dmd.expression.UnaExp;
- The type cast operator, cast(T) xIt's possible to cast to one type while painting to another type https://dlang.org/spec/expression.html#cast_expressions
- classVectorExp: dmd.expression.UnaExp;
- classVectorArrayExp: dmd.expression.UnaExp;
- e1.array property for vectors.
- classSliceExp: dmd.expression.UnaExp;
- e1 [lwr .. upr]- @safe this(Locloc, Expressione1, IntervalExpie);
 
- classArrayLengthExp: dmd.expression.UnaExp;
- The .length property of an array
- classArrayExp: dmd.expression.UnaExp;
- e1 [ a0, a1, a2, a3 ,... ]
- classDotExp: dmd.expression.BinExp;
- classCommaExp: dmd.expression.BinExp;
- 
- const boolisGenerated;
- This is needed because AssignExp rewrites CommaExp, hence it needs to trigger the deprecation.
- boolallowCommaExp;
- Temporary variable to enable / disable deprecation of comma expression depending on the context. Since most constructor calls are rewritting, the only place where false will be passed will be from the parser.
- static @safe voidallow(Expressionexp);
- If the argument is a CommaExp, set a flag to prevent deprecation messagesIt's impossible to know from CommaExp.semantic if the result will be used, hence when there is a result (type != void), a deprecation message is always emitted. However, some construct can produce a result but won't use it (ExpStatement and for loop increment). Those should call this function to prevent unwanted deprecations to be emitted.Parameters:Expression expAn expression that discards its result. If the argument is null or not a CommaExp, nothing happens. 
 
- classIntervalExp: dmd.expression.Expression;
- Mainly just a placeholder
- classDelegatePtrExp: dmd.expression.UnaExp;
- The dg.ptr property, pointing to the delegate's 'context'c.f.DelegateFuncptrExp for the delegate's function pointer dg.funcptr
- classDelegateFuncptrExp: dmd.expression.UnaExp;
- The dg.funcptr property, pointing to the delegate's functionc.f.DelegatePtrExp for the delegate's function pointer dg.ptr
- classIndexExp: dmd.expression.BinExp;
- e1 [ e2 ]
- classPostExp: dmd.expression.BinExp;
- The postfix increment/decrement operator, i++ / i--
- classPreExp: dmd.expression.UnaExp;
- The prefix increment/decrement operator, ++i / --i
- classAssignExp: dmd.expression.BinExp;
- The assignment / initialization operator, =Note operator assignment op= has a different base class, BinAssignExp - @safe this(Locloc, Expressione1, Expressione2);
 
- classLoweredAssignExp: dmd.expression.AssignExp;
- When an assignment expression is lowered to a druntime call this class is used to store the lowering. It essentially behaves the same as an AssignExp, but it is used to not waste space for other AssignExp that are not lowered to anything.
- classConstructExp: dmd.expression.AssignExp;
- classBlitExp: dmd.expression.AssignExp;
- A bit-for-bit copy from e2 to e1
- classAddAssignExp: dmd.expression.BinAssignExp;
- x += y
- classMinAssignExp: dmd.expression.BinAssignExp;
- x -= y
- classMulAssignExp: dmd.expression.BinAssignExp;
- x *= y
- classDivAssignExp: dmd.expression.BinAssignExp;
- x /= y
- classModAssignExp: dmd.expression.BinAssignExp;
- x %= y
- classAndAssignExp: dmd.expression.BinAssignExp;
- x &= y
- classOrAssignExp: dmd.expression.BinAssignExp;
- x |= y
- classXorAssignExp: dmd.expression.BinAssignExp;
- x ^= y
- classPowAssignExp: dmd.expression.BinAssignExp;
- x ^^= y
- classShlAssignExp: dmd.expression.BinAssignExp;
- x <<= y
- classShrAssignExp: dmd.expression.BinAssignExp;
- x >>= y
- classUshrAssignExp: dmd.expression.BinAssignExp;
- x >>>= y
- classCatAssignExp: dmd.expression.BinAssignExp;
- The ~= operator.It can have one of the following operators: EXP.concatenateAssign - appending T[] to T[] EXP.concatenateElemAssign - appending T to T[] EXP.concatenateDcharAssign - appending dchar to T[] The parser initially sets it to EXP.concatenateAssign, and semantic() later decides which of the three it will be set to.
- classCatElemAssignExp: dmd.expression.CatAssignExp;
- The ~= operator when appending a single element
- classCatDcharAssignExp: dmd.expression.CatAssignExp;
- The ~= operator when appending a single dchar
- classAddExp: dmd.expression.BinExp;
- The addition operator, x + y
- classMinExp: dmd.expression.BinExp;
- The minus operator, x - y
- classCatExp: dmd.expression.BinExp;
- The concatenation operator, x ~ y
- classMulExp: dmd.expression.BinExp;
- The multiplication operator, x * y
- classDivExp: dmd.expression.BinExp;
- The division operator, x / y
- classModExp: dmd.expression.BinExp;
- The modulo operator, x % y
- classPowExp: dmd.expression.BinExp;
- The 'power' operator, x ^^ y
- classShlExp: dmd.expression.BinExp;
- The 'shift left' operator, x << y
- classShrExp: dmd.expression.BinExp;
- The 'shift right' operator, x >> y
- classUshrExp: dmd.expression.BinExp;
- The 'unsigned shift right' operator, x >>> y
- classAndExp: dmd.expression.BinExp;
- The bitwise 'and' operator, x & y
- classOrExp: dmd.expression.BinExp;
- The bitwise 'or' operator, x | y
- classXorExp: dmd.expression.BinExp;
- The bitwise 'xor' operator, x ^ y
- classLogicalExp: dmd.expression.BinExp;
- The logical 'and' / 'or' operator, X && Y / X || Y
- classCmpExp: dmd.expression.BinExp;
- A comparison operator, < <= > >=op is one of: EXP.lessThan, EXP.lessOrEqual, EXP.greaterThan, EXP.greaterOrEqual https://dlang.org/spec/expression.html#relation_expressions
- classInExp: dmd.expression.BinExp;
- The in operator, "a" in ["a": 1]Note x !in y is rewritten to !(x in y) in the parser https://dlang.org/spec/expression.html#in_expressions
- classRemoveExp: dmd.expression.BinExp;
- Associative array removal, aa.remove(arg)This deletes the key e1 from the associative array e2
- classEqualExp: dmd.expression.BinExp;
- == and !=EXP.equal and EXP.notEqual https://dlang.org/spec/expression.html#equality_expressions
- classIdentityExp: dmd.expression.BinExp;
- is and !isEXP.identity and EXP.notIdentity https://dlang.org/spec/expression.html#identity_expressions
- classCondExp: dmd.expression.BinExp;
- The ternary operator, econd ? e1 : e2
- classDefaultInitExp: dmd.expression.Expression;
- A special keyword when used as a function's default argumentWhen possible, special keywords are resolved in the parser, but when appearing as a default argument, they result in an expression deriving from this base class that is resolved for each function call.const x = __LINE__; // resolved in the parser void foo(string file = __FILE__, int line = __LINE__); // DefaultInitExp https://dlang.org/spec/expression.html#specialkeywords- @safe this(Locloc, EXPop);
- Parameters:Loc loclocation EXP opEXP.prettyFunction, EXP.functionString, EXP.moduleString, EXP.line, EXP.file, EXP.fileFullPath 
 
- classFileInitExp: dmd.expression.DefaultInitExp;
- The __FILE__ token as a default argument
- classLineInitExp: dmd.expression.DefaultInitExp;
- The __LINE__ token as a default argument
- classModuleInitExp: dmd.expression.DefaultInitExp;
- The __MODULE__ token as a default argument
- classFuncInitExp: dmd.expression.DefaultInitExp;
- The __FUNCTION__ token as a default argument
- classPrettyFuncInitExp: dmd.expression.DefaultInitExp;
- The __PRETTY_FUNCTION__ token as a default argument
- classClassReferenceExp: dmd.expression.Expression;
- A reference to a class, or an interface. We need this when we point to a base class (we must record what the type is).
- classCTFEExp: dmd.expression.Expression;
- This type is only used by the interpreter.
- classThrownExceptionExp: dmd.expression.Expression;
- Fake class which holds the thrown exception. Used for implementing exception handling.
- classObjcClassReferenceExp: dmd.expression.Expression;
- Objective-C class reference expression.Used to get the metaclass of an Objective-C class, NSObject.Class.
- classGenericExp: dmd.expression.Expression;
- C11 6.5.1.1 Generic Selection For ImportC- ExpressioncntlExp;
- controlling expression of a generic selection (not evaluated)
- Types*types;
- type-names for generic associations (null entry for default)
- Expressions*exps;
- 1:1 mapping of typeNames to exps
 
- boolisArrayConstruction(const Identifierid);
- Verify if the given identifier is d_array{,set}ctor.Parameters:Identifier idthe identifier to verify Returns:true if the identifier corresponds to a construction runtime hook, false otherwise.