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 using
			a local clone.
		
	dmd.expressionsem
Semantic analysis of expressions.
Specification ($LINK2 https://dlang.org/spec/expression.html, Expressions)
Authors: 
License: 
Source expressionsem.d
Documentation https://dlang.org/phobos/dmd_expressionsem.html
- boolexpressionsToString(ref OutBufferbuf, Scope*sc, Expressions*exps, Locloc, const(char)*fmt, boolexpandTuples);
- Perform semantic analysis and CTFE on expressions to produce a string.Parameters:OutBuffer bufappend generated string to buffer Scope* sccontext Expressions* expsarray of Expressions Loc loclocation 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 bool expandTupleswhether tuples should be expanded rather than printed as tuple syntax Returns:true on error
- FuncDeclarationhasThis(Scope*sc);
- Determine if this 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 satisfies isThis(), otherwise null
- StringExpsemanticString(Scope*sc, Expressionexp, const char*s);
- Resolveexpas a compile-time known string.Parameters:Scope* scscope Expression expExpression which expected as a string char* sWhat the string is expected for, will be used in error diagnostic. Returns:String literal, or null 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.
- 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 Expression ethe expression the needs to be moved or copied (source) Type tif the struct defines a copy constructor, the type of the destination (can be NULL) bool nrvotrue if the generated copy can be treated as NRVO bool movetrue 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 symbolsinto the expression it represents.Parameters:Dsymbol ssymbol to resolve Loc loclocation of use of sScope* sccontext bool hasOverloadsapplies if srepresents a function. true means it's overloaded and will be resolved later, false means it's the exact function symbol.Returns:sturned into an expression, ErrorExp if an error occurred
- voidcheckOverriddenDtor(FuncDeclarationf, Scope*sc, Locloc, scope bool function(DtorDeclaration)check, const stringcheckName);
- Checks whetherfis a generated DtorDeclaration that hides a user-defined one which passescheckwhilefdoesn'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:FuncDeclaration fpotential DtorDeclaration Scope* scscope Loc loclocation bool function(DtorDeclaration) checkcurrent check (e.g. whether it's pure) string checkNamethe kind of check (e.g. "pure") 
- voiderrorSupplementalInferredAttr(FuncDeclarationfd, intmaxDepth, booldeprecation, STCstc, ErrorSinkeSink);
- Print the reason whyfdwas inferred @system as a supplemental errorParameters:FuncDeclaration fdfunction to check int maxDepthup to how many functions deep to report errors bool deprecationprint deprecations instead of errors STC stcstorage class of attribute to check ErrorSink eSinkwhere 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:Dsymbol symthe symbol to be checked Returns:the symbol whichsymrepresents (or null if it doesn't represent a Package)
- 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(See isRecursiveAliasThis).Parameters:Expression expexpression to try semantic on Scope* scscope Type[2] aliasThisStoppair of recursive alias this types to stop endless recursion Returns:exp after expression semantic, or null 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:DotIdExp expexpression to resolve Scope* sccontext bool gagdo not emit error messages, just return null Returns:resolved expression, null if error
- ExpressiondotTemplateSemanticProp(DotTemplateInstanceExpexp, Scope*sc, boolgag);
- Resolve e1.ident!tiargs without seeing UFCS.Parameters:DotTemplateInstanceExp expthe DotTemplateInstanceExp to resolve Scope* scthe semantic scope bool gagstop "not a property" error and return null. 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:Expression eexpression to check Returns:true if the expression is not valid or has void type.
- boolcheckSharedAccess(Expressione, Scope*sc, boolreturnRef= false);
- If expression is shared, check that we can access it. Give error message if not.Parameters:Expression eexpression to check Scope* sccontext bool returnRefWhether this expression is for a return statement off a ref 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);
- Try to convert an expression to be an lvalue.Give error if we're 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 for x++) Returns:converted expression, or ErrorExp on error
- ModifiablecheckModifiable(Expressionexp, Scope*sc, ModifyFlagsflag= ModifyFlags.none);
- Parameters sc: scope flag: 1: do not issue error message for invalid modification 2: the exp is a DotVarExp and a subfield of the leftmost variable is modified Returns:Whether the type is modifiable
- ExpressionmodifiableLvalue(Expression_this, Scope*sc);
- Similar to toLvalue, but also enforce it is mutable or raise an error.Parameters:Expression _thisExpression to convert Scope* scscope Returns:_thisconverted to an lvalue, or an ErrorExp
- boolcheckAddressable(Expressione, Scope*sc);
- This check ensures that the object in exp can have its address taken, or issue a diagnostic error.Parameters:Expression eexpression to check Scope* sccontext Returns:true if the expression is addressable
- ExpressiongetThisSkipNestedFuncs(Locloc, Scope*sc, Dsymbols, AggregateDeclarationad, Expressione1, Typet, Dsymbolvar, boolflag= false);
- Helper function for getRightThis(). Gets this of the next outer aggregate.Parameters:Loc loclocation to use for error messages Scope* sccontext Dsymbol sthe parent symbol of the existing this AggregateDeclaration adstruct or class we need the correct this for Expression e1existing this Type ttype of the existing this Dsymbol varthe specific member of ad we're accessing bool flagif true, return null instead of throwing an error Returns:Expression representing the this for the var
- boolverifyHookExist(Locloc, ref Scopesc, Identifierid, stringdescription, Identifiermodule_= Id.object);
- Make sure that the runtime hookidexists.Parameters:Loc loclocation to use for error messages Scope sccurrent scope Identifier idthe hook identifier string descriptionwhat the hook does Identifier module_what module the hook is located in Returns:a bool indicating if the hook is present.
- ExpressiongetVarExp(EnumMemberem, Locloc, Scope*sc);
- Returnsemas a VariableExpParameters:EnumMember emthe EnumMember to wrap Loc loclocation of use of em Scope* scscope of use of em Returns:VarExp referenceingemor ErrorExp ifemif disabled/deprecated
- ExpressiontoBoolean(Expressionexp, Scope*sc);
- Try to treatexpas a boolean,Parameters:Expression expthe expression Scope* scscope to evalute expinReturns: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 Expression originaloriginal expression, for error messages Expression eresulting expression bool errorsset to true 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 for checkModifiable- 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 Type ttype 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 madeIf the declaration is disabled but inside a disabled function, returns true but do not issue an error message.Parameters:Declaration dDeclaration to check Loc locLocation information of the call Scope* scScope in which the call occurs bool isAliasedDeclarationif true searches overload set Returns:true if this Declaration is @disabled, false otherwise.
- boolfill(StructDeclarationsd, Locloc, ref Expressionselements, boolctorinit);
- Fill out remainder of elements[] with default initializers for fields[].Parameters:StructDeclaration sdstruct Loc loclocation Expressions elementsexplicit arguments which given to construct object. bool ctorinittrue 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 multiple static foreach loop variables, an array of tuples is generated. In thise case, the field needExpansion 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, call lowerArrayAggregate to turn the produced array into an expression tuple.Parameters:StaticForeach sfeThe 'static foreach'. Scope* scThe current scope. 
- voidprepare(StaticForeachsfe, Scope*sc);
- Perform static foreach lowerings that are necessary in order to finally expand the static foreach using dmd.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)) { ... }
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:27:54 2025