Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

dmd.expressionsem

Semantic analysis of expressions.

Specification($LINK2https://dlang.org/spec/expression.html, Expressions)

Authors:
Walter Bright
License:
Boost License 1.0

Sourceexpressionsem.d

Documentationhttps://dlang.org/phobos/dmd_expressionsem.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/expressionsem.d

boolisIdentical(const Expression_this, const Expressione);
Identical, not just equal. I.e. NaNs with different bit patterns are not identical
boolexpressionsToString(ref OutBufferbuf, Scope*sc, Expressions*exps, Locloc, const(char)*fmt, boolexpandTuples);
Perform semantic analysis and CTFE on expressions to produce a string.
Parameters:
OutBufferbufappend generated string to buffer
Scope*sccontext
Expressions*expsarray of Expressions
Locloclocation of the pragma / mixin where this conversion was requested, for supplemental error
const(char)*fmtformat string for supplemental error. May contain 1%s which prints the faulty expression
boolexpandTupleswhether tuples should be expanded rather than printed as tuple syntax
Returns:
true on error
boolhasRegularCtor(StructDeclarationsd, boolignoreDisabled);
Verifies whether the struct declaration has a constructor that is not a copy constructor. Optionally, it can check whether the struct declaration has a regular constructor, that is not disabled.
Parameters:
StructDeclarationsdstruct declaration
boolignoreDisabledtrue to ignore disabled constructors
Returns:
true, if the struct has a regular (optionally, not disabled) constructor, false otherwise.
FuncDeclarationhasThis(Scope*sc);
Determine ifthis is available by walking up the enclosing scopes until a function is found.
Parameters:
Scope*scwhere to start looking for the enclosing function
Returns:
Found function if it satisfiesisThis(), otherwisenull
StringExpsemanticString(Scope*sc, Expressionexp, const char*s);
Resolveexp as a compile-time known string.
Parameters:
Scope*scscope
ExpressionexpExpression which expected as a string
char*sWhat the string is expected for, will be used in error diagnostic.
Returns:
String literal, ornull if error happens.
StringExptoUTF8(StringExpse, Scope*sc);
Convert string to char[].
ExpressionincompatibleTypes(BinExpe, Scope*sc = null);
The types for a binary expression are incompatible. Print error message.
Returns:
ErrorExp
TupleDeclarationisAliasThisTuple(Expressione);
Expand alias this tuples.
ExpressionaddressOf(Expressione);
Take address of expression.
ExpressiongetField(StructLiteralExpsle, Typetype, uintoffset);
Gets expression at offset of type. Returns NULL if not found.
ExpressionresolveOpDollar(Scope*sc, ArrayExpae, out Expressionpe0);
Runs semantic on ae.arguments. Declares temporary variables if '$' was used.
ExpressionresolveOpDollar(Scope*sc, ArrayExpae, IntervalExpie, ref Expressionpe0);
Runs semantic on se.lwr and se.upr. Declares a temporary variable if '$' was used.
Returns:
ae, or ErrorExp if errors occurred
boolarrayExpressionSemantic(Expression[]exps, Scope*sc, boolpreserveErrors = false);
Perform semantic() on an array of Expressions.
ExpressiondoCopyOrMove(Scope*sc, Expressione, Typet, boolnrvo, boolmove = false);
Handle the postblit call on lvalue, or the move of rvalue.
Parameters:
Scope*scthe scope where the expression is encountered
Expressionethe expression the needs to be moved or copied (source)
Typetif the struct defines a copy constructor, the type of the destination (can be NULL)
boolnrvotrue if the generated copy can be treated as NRVO
boolmovetrue to allow a move constructor to be used, false to prevent infinite recursion
Returns:
The expression that copy constructs or moves the value.
ExpressionvalueNoDtor(Expressione);
If we want the value of this expression, but do not want to call the destructor on it.
ExpressionresolvePropertiesOnly(Scope*sc, Expressione1);
If e1 is a property function (template), resolve it.
ExpressionsymbolToExp(Dsymbols, Locloc, Scope*sc, boolhasOverloads);
Turn symbols into the expression it represents.
Parameters:
Dsymbolssymbol to resolve
Locloclocation of use ofs
Scope*sccontext
boolhasOverloadsapplies ifs represents a function. true means it's overloaded and will be resolved later, false means it's the exact function symbol.
Returns:
s turned into an expression,ErrorExp if an error occurred
voidcheckOverriddenDtor(FuncDeclarationf, Scope*sc, Locloc, scope bool function(DtorDeclaration)check, const stringcheckName);
Checks whetherf is a generatedDtorDeclaration that hides a user-defined one which passescheck whilef doesn't (e.g. when the user defined dtor is pure but the generated dtor is not). In that case the method will identify and print all members causing the attribute missmatch.
Parameters:
FuncDeclarationfpotentialDtorDeclaration
Scope*scscope
Locloclocation
bool function(DtorDeclaration)checkcurrent check (e.g. whether it's pure)
stringcheckNamethe kind of check (e.g."pure")
voiderrorSupplementalInferredAttr(FuncDeclarationfd, intmaxDepth, booldeprecation, STCstc, ErrorSinkeSink);
Print the reason whyfd was inferred@system as a supplemental error
Parameters:
FuncDeclarationfdfunction to check
intmaxDepthup to how many functions deep to report errors
booldeprecationprint deprecations instead of errors
STCstcstorage class of attribute to check
ErrorSinkeSinkwhere the error messages go
PackageresolveIsPackage(Dsymbolsym);
Determines whether a symbol represents a module or package (Used as a helper for is(type == module) and is(type == package))
Parameters:
Dsymbolsymthe symbol to be checked
Returns:
the symbol whichsym represents (ornull if it doesn't represent aPackage)
DsymbolgetDsymbol(RootObjectoarg);
If oarg represents a Dsymbol, return that Dsymbol
Parameters:
RootObjectoargargument to check
Returns:
Dsymbol if a symbol, null if not
ExpressiontrySemantic(Expressionexp, Scope*sc);
Try to run semantic routines. If they fail, return NULL.
ExpressiontrySemanticAliasThis(Expressionexp, Scope*sc, Type[2]aliasThisStop);
Try expression semantic onexp, gagging semantic errors, but don't resolve alias this on a BinExp when the lhs or rhs has the corresponding type inaliasThisStop (SeeisRecursiveAliasThis).
Parameters:
Expressionexpexpression to try semantic on
Scope*scscope
Type[2]aliasThisStoppair of recursive alias this types to stop endless recursion
Returns:
exp after expression semantic, ornull on error
ExpressionunaSemantic(UnaExpe, Scope*sc);
Helper function for easy error propagation. If error occurs, returns ErrorExp. Otherwise returns NULL.
ExpressionbinSemantic(BinExpe, Scope*sc);
Helper function for easy error propagation. If error occurs, returns ErrorExp. Otherwise returns NULL.
ExpressiondotIdSemanticProp(DotIdExpexp, Scope*sc, boolgag);
Resolve properties, i.e.e1.ident, without seeing UFCS.
Parameters:
DotIdExpexpexpression to resolve
Scope*sccontext
boolgagdo not emit error messages, just returnnull
Returns:
resolved expression, null if error
ExpressiondotTemplateSemanticProp(DotTemplateInstanceExpexp, Scope*sc, boolgag);
Resolvee1.ident!tiargs without seeing UFCS.
Parameters:
DotTemplateInstanceExpexptheDotTemplateInstanceExp to resolve
Scope*scthe semantic scope
boolgagstop "not a property" error and returnnull.
Returns:
null if error or not found, or the resolved expression.
boolcheckValue(Expressione);
Check that the expression has a valid value. If not, generates an error "... has no value".`
Parameters:
Expressioneexpression to check
Returns:
true if the expression is not valid or hasvoid type.
boolcheckSharedAccess(Expressione, Scope*sc, boolreturnRef = false);
If expression is shared, check that we can access it. Give error message if not.
Parameters:
Expressioneexpression to check
Scope*sccontext
boolreturnRefWhether this expression is for areturn statement off aref function, in which case a single level of dereference is allowed (e.g.shared(int)*).
Returns:
true on error
ExpressionresolveLoc(Expressionexp, Locloc, Scope*sc);
Resolve __FILE__, __LINE__, __MODULE__, __FUNCTION__, __PRETTY_FUNCTION__, _FILE_FULL_PATH__ to loc.
ExpressionaddDtorHook(Expressione, Scope*sc);
Destructors are attached to VarDeclarations. Hence, if expression returns a temp that needs a destructor, make sure and create a VarDeclaration for that temp.
ExpressiontoLvalue(Expression_this, Scope*sc, const(char)*action, Expressioneorig = null);
Try to convert an expression to be an lvalue.
Give error if we are not an lvalue.
Parameters:
Expression_thisexpression to convert
Scope*scscope
const(char)*actionfor error messages, what the lvalue is needed for (e.g. take address of for&x, modify forx++)
Expressioneorigoriginal un-lowered expression for error messages, in case of recursive calls; null means use_this
Returns:
converted expression, orErrorExp on error
ModifiablecheckModifiable(Expressionexp, Scope*sc, ModifyFlagsflag = ModifyFlags.none);
Parameters:
Expressionexpexpression to check if modifiable
Scope*scscope
ModifyFlagsflagnoError - do not issue error message for invalid modification fieldAssign - exp is a DotVarExp and a subfield of the leftmost variable is modified
Returns:
Whether the type is modifiable
ExpressionmodifiableLvalue(Expression_this, Scope*sc, Expressioneorig = null);
Similar totoLvalue, but also enforce it is mutable or raise an error.
Parameters:
Expression_thisExpression to convert
Scope*scscope
Expressioneorigoriginal / un-lowered expression to print in error messages, if null default to_this
Returns:
_this converted to an lvalue, or anErrorExp
boolcheckAddressable(Expressione, Scope*sc, const(char)*action);
This check ensures that the object inexp can have its address taken, or issue a diagnostic error.
Parameters:
Expressioneexpression to check
Scope*sccontext
const(char)*actionfor error messages, what the address is needed for (e.g. ref return, indexing an array)
Returns:
true if the expression is addressable
ExpressiongetThisSkipNestedFuncs(Locloc, Scope*sc, Dsymbols, AggregateDeclarationad, Expressione1, Typet, Dsymbolvar, boolflag = false);
Helper function forgetRightThis(). Getsthis of the next outer aggregate.
Parameters:
Locloclocation to use for error messages
Scope*sccontext
Dsymbolsthe parent symbol of the existingthis
AggregateDeclarationadstruct or class we need the correctthis for
Expressione1existingthis
Typettype of the existingthis
Dsymbolvarthe specific member of ad we're accessing
boolflagif true, returnnull instead of throwing an error
Returns:
Expression representing thethis for the var
boolverifyHookExist(Locloc, ref Scopesc, Identifierid, stringdescription, Identifiermodule_ = Id.object);
Make sure that the runtime hookid exists.
Parameters:
Locloclocation to use for error messages
Scopesccurrent scope
Identifieridthe hook identifier
stringdescriptionwhat the hook does
Identifiermodule_what module the hook is located in
Returns:
abool indicating if the hook is present.
ExpressiongetVarExp(EnumMemberem, Locloc, Scope*sc);
Returnsem as a VariableExp
Parameters:
EnumMemberemthe EnumMember to wrap
Locloclocation of use of em
Scope*scscope of use of em
Returns:
VarExp referenceingem or ErrorExp ifem if disabled/deprecated
ExpressiontoBoolean(Expressionexp, Scope*sc);
Try to treatexp as a boolean,
Parameters:
Expressionexpthe expression
Scope*scscope to evaluteexp in
Returns:
Modified expression on success, ErrorExp on error
boolevalStaticCondition(Scope*sc, Expressionoriginal, Expressione, out boolerrors, Expressions*negatives = null);
Semantically analyze and then evaluate a static condition at compile time. This is special because short circuit operators &&, || and ?: at the top level are not semantically analyzed if the result of the expression is not necessary.
Parameters:
Scope*scinstantiating scope
Expressionoriginaloriginal expression, for error messages
Expressioneresulting expression
boolerrorsset totrue if errors occurred
Expressions*negativesarray to store negative clauses
Returns:
true if evaluates to true
boolcheckFrameAccess(Locloc, Scope*sc, AggregateDeclarationad, size_tiStart = 0);
Check to see the aggregate type is nested and its context pointer is accessible from the current scope. Returns true if error occurs.
enumModifiable: int;
Return value forcheckModifiable
no
Not modifiable
yes
Modifiable (the type is mutable)
initialization
Modifiable because it is initialization
enumModifyFlags: int;
Specifies how the checkModify deals with certain situations
none
Issue error messages on invalid modifications of the variable
noError
No errors are emitted for invalid modifications
fieldAssign
The modification occurs for a subfield of the current variable
voidsemanticTypeInfo(Scope*sc, Typet);
Request additional semantic analysis for TypeInfo generation.
Parameters:
Scope*sccontext
Typettype that TypeInfo is being generated for
boolcheckDisabled(Declarationd, Locloc, Scope*sc, boolisAliasedDeclaration = false);
Issue an error if an attempt to call a disabled method is made
If the declaration is disabled but inside a disabled function, returnstrue but do not issue an error message.
Parameters:
DeclarationdDeclaration to check
LoclocLocation information of the call
Scope*scScope in which the call occurs
boolisAliasedDeclarationiftrue searches overload set
Returns:
true if thisDeclaration is@disabled,false otherwise.
ExpressiongetConstInitializer(VarDeclarationvd, boolneedFullType = true);
If variable has a constant expression initializer, get it. Otherwise, return null.
boolfill(StructDeclarationsd, Locloc, ref Expressionselements, boolctorinit);
Fill out remainder of elements[] with default initializers for fields[].
Parameters:
StructDeclarationsdstruct
Locloclocation
Expressionselementsexplicit arguments which given to construct object.
boolctorinittrue if the elements will be used for default initialization.
Returns:
false if any errors occur. Otherwise, returns true and the missing arguments will be pushed in elements[].
voidlowerNonArrayAggregate(StaticForeachsfe, Scope*sc);
Lower any aggregate that is not an array to an array using a regular foreach loop within CTFE. If there are multiplestatic foreach loop variables, an array of tuples is generated. In thise case, the fieldneedExpansion is set to true to indicate that the static foreach loop expansion will need to expand the tuples into multiple variables.
For example,static foreach (x; range) { ... } is lowered to:
static foreach (x; { typeof({ foreach (x; range) return x; }())[] _res; foreach (x; range) _res ~= x; return _res; }()) { ... }
Finally, calllowerArrayAggregate to turn the produced array into an expression tuple.
Parameters:
StaticForeachsfeThe 'static foreach'.
Scope*scThe current scope.
voidprepare(StaticForeachsfe, Scope*sc);
Performstatic foreach lowerings that are necessary in order to finally expand thestatic foreach usingdmd.statementsem.makeTupleForeach.
voidlowerArrayAggregate(StaticForeachsfe, Scope*sc);
Turn an aggregate which is an array into an expression tuple of its elements. I.e., lower static foreach (x; [1, 2, 3, 4]) { ... } to static foreach (x; AliasSeq!(1, 2, 3, 4)) { ... }
DsymbolsearchCtor(AggregateDeclarationad);
Look for constructor declaration.
voidmarkArrayExpModifiable(ArrayExpae);
mark ArrayExp on the left side of an assignment recursively as modifiable before semantic analysis to defer potential lowerings into the assignment when the right side of the expression is analyzed, too, i.e.
a[i][j] = 1
is parsed to
AssignExp(ArrayExp(ArrayExp(Id('a'), Id('i')), Id('j')), 1)
ArrayExp is converted to IndexExp during semantic analysis, but the lowering for IndexExp on associative arrays is different for reading or writing. For struct types, it can even depend on the right hand side of an assignment.
Parameters:
ArrayExpaethe ArrayExp to mark
ExpressionlowerAAIndexRead(IndexExpie, Scope*sc);
convert an IndexExp on an associative arrayaa[key] to_d_aaGetRvalueX!(K,V)(aa, key)[0]
Parameters:
IndexExpiethe IndexExp to lower
Scope*sccontext
Returns:
on success, the lowered expression that is still an IndexExp with itsloweredFrom field set to the original expression on failure, null is returned
ExpressionrevertIndexAssignToRvalues(IndexExpie, Scope*sc);
in a multi-dimensional array assignment without the out-most access being to an AA, convert AA accesses back to rvalues
Parameters:
IndexExpiethe IndexExp to lower
Scope*sccontext
Returns:
the lowered expression if the assignment was actually on an associative array, the original expression otherwise, an ErorrExp on failure
ExpressionrewriteIndexAssign(BinExpexp, Scope*sc, Type[2]aliasThisStop);
rewrite multi-dimensional array modifying assignments on associative arrays
Parameters:
BinExpexpthe assignment expression, AssignExp, ConstructExp, BinAssignExp or PostExp
Scope*sccontext
Type[2]aliasThisStopfor recursion check onalias this
Returns:
the lowered expression if the assignment was actually on an associative array, null if no modifying index expression was found on the lhs of the assignemnt
BitFieldDeclarationisBitField(Expressione);
Get bitfield from expression.
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 17:56:28 2026

[8]ページ先頭

©2009-2026 Movatter.jp