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.funcsem

Does semantic analysis for functions.

SpecificationFunctions

Authors:
Walter Bright
License:
Boost License 1.0

Sourcefuncsem.d

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

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

boolonlyOneMain(FuncDeclarationfd);
Only one entry point function is allowed. Print error if more than one.
Parameters:
FuncDeclarationfda "main" function
Returns:
true if haven't seen "main" before
boolisUnique(const FuncDeclarationfd);
Returns:
true if there are no overloads of this function
voidfuncDeclarationSemantic(Scope*sc, FuncDeclarationfuncdecl);
Main semantic routine for functions.
boolfunctionSemantic(FuncDeclarationfd);
Resolve forward reference of function signature - parameter types, return type, and attributes.
Parameters:
FuncDeclarationfdfunction declaration
Returns:
false if any errors exist in the signature.
boolfunctionSemantic3(FuncDeclarationfd);
Resolve forward reference of function body. Returns false if any errors exist in the body.
voiddeclareThis(FuncDeclarationfd, Scope*sc);
Creates and returns the hidden parameters for this function declaration.
Hidden parameters include thethis parameter of a class, struct or nested function and the selector parameter for Objective-C methods.
boolcheckForwardRef(FuncDeclarationfd, Locloc);
Check that this function type is properly resolved. If not, report "forward reference error" and return true.
intfindVtblIndex(FuncDeclarationfd, Dsymbol[]vtbl);
Find index of function in vtbl[0..length] that this function overrides. Prefer an exact match to a covariant one.
Parameters:
FuncDeclarationfdfunction
Dsymbol[]vtblvtable to use
Returns:
-1 didn't find one -2 can't determine because of forward references
BaseClass*overrideInterface(FuncDeclarationfd);
If function is a function in a base class, return that base class.
Parameters:
FuncDeclarationfdfunction
Returns:
base class if overriding, null if not
enumFuncResolveFlag: ubyte;
Flag used byresolveFuncCall.
standard
issue error messages, solve the call.
quiet
do not issue error message on no match, just returnnull.
overloadOnly
only resolve overloads, i.e. do not issue error on ambiguous
ufcs
matches and need explicit this.
trying to resolve UFCS call
FuncDeclarationresolveFuncCall(Locloc, Scope*sc, Dsymbols, Objects*tiargs, Typetthis, ArgumentListargumentList, FuncResolveFlagflags);
Given a symbol that could be either a FuncDeclaration or a function template, resolve it to a function symbol.
Parameters:
Loclocinstantiation location
Scope*scinstantiation scope
Dsymbolsinstantiation symbol
Objects*tiargsinitial list of template arguments
Typetthisif !NULL, thethis argument type
ArgumentListargumentListarguments to function
FuncResolveFlagflagsseeFuncResolveFlag.
Returns:
if match is found, then function symbol, else null
ExpressionaddInvariant(AggregateDeclarationad, VarDeclarationvthis);
Generate Expression to call the invariant.

Inputad aggregate with the invariant vthis variable with 'this'

Returns:
void expression that calls the invariant
FuncDeclarationoverloadExactMatch(FuncDeclarationthisfd, Typet);
Find function in overload list that exactly matches t.
intoverrides(FuncDeclarationfd1, FuncDeclarationfd2);
Determine if fd1 overrides fd2. Return !=0 if it does.
MATCHleastAsSpecialized(FuncDeclarationf, FuncDeclarationg, ArgumentLabels*names);
Determine partial specialization order of functionsf vsg. This is very similar to TemplateDeclaration::leastAsSpecialized().
Parameters:
FuncDeclarationffirst function
FuncDeclarationgsecond function
ArgumentLabels*namesargument Labels of parameters(name and location of the name)
Returns:
match 'this' is at least as specialized as g 0 g is more specialized than 'this'
FuncDeclarationoverloadModMatch(FuncDeclarationthisfd, Locloc, Typetthis, ref boolhasOverloads);
Find function in overload list that matches to the 'this' modifier. There's four result types.
  1. If the 'tthis' matches only one candidate, it's an "exact match". Returns the function and 'hasOverloads' is set to false. eg. If 'tthis" is mutable and there's only one mutable method.
  2. If there's two or more match candidates, but a candidate function will be a "better match". Returns the better match function but 'hasOverloads' is set to true. eg. If 'tthis' is mutable, and there's both mutable and const methods, the mutable method will be a better match.
  3. If there's two or more match candidates, but there's no better match, Returns null and 'hasOverloads' is set to true to represent "ambiguous match". eg. If 'tthis' is mutable, and there's two or more mutable methods.
  4. If there's no candidates, it's "no match" and returns null with error report. e.g. If 'tthis' is const but there's no const methods.
intgetLevelAndCheck(FuncDeclarationfd, Locloc, Scope*sc, FuncDeclarationtarget, Declarationdecl);
Determine lexical level difference fromfd to nested functiontarget. Issue error iffd cannot calltarget.
Parameters:
FuncDeclarationfdfunction
Locloclocation for error messages
Scope*sccontext
FuncDeclarationtargettarget of call
DeclarationdeclTheDeclaration that triggered this check. Used to provide a better error message only.
Returns:
0 same level

0 decrease nesting by number -1 increase nesting by 1 (target is nested within 'fd') LevelError error

voidbuildResultVar(FuncDeclarationfd, Scope*sc, Typetret);
Declare result variable lazily.
StatementmergeFrequire(FuncDeclarationfd, Statementsf, Expressions*params);
Merge into this function the 'in' contracts of all it overrides. 'in's are OR'd together, i.e. only one of them needs to pass.
StatementmergeFrequireInclusivePreview(FuncDeclarationfd, Statementsf, Expressions*params);
Merge into this function the 'in' contracts of all it overrides.
voidbuildEnsureRequire(FuncDeclarationthisfd);
Rewrite contracts as statements.
@safe boolneedsFensure(FuncDeclarationfd);
Determine whether an 'out' contract is declared inside the given function or any of its overrides.
Parameters:
FuncDeclarationfdthe function to search
Returns:
true found an 'out' contract
StatementmergeFensure(FuncDeclarationfd, Statementsf, Identifieroid, Expressions*params);
Merge into this function the 'out' contracts of all it overrides. 'out's are AND'd together, i.e. all of them need to pass.
voidmodifyReturns(FuncLiteralDeclarationfld, Scope*sc, Typetret);
Modify all expression type of return statements to tret.
On function literals, return type may be modified based on the context type after its semantic3 is done, in FuncExp::implicitCastTo.
A function() dg = (){ return new B(); } // OK if is(B : A) == true
If B to A conversion is convariant that requires offseet adjusting, all return statements should be adjusted to return expressions typed A.
@safe boolisRootTraitsCompilesScope(Scope*sc);
When a traits(compiles) is used on a function literal call we need to take into account if the body of the function violates any attributes, however, we must not affect the attribute inference on the outer function. The attributes of the function literal still need to be inferred, therefore we need a way to check for the scope that the traits compiles introduces.
Parameters:
Scope*scscope to be checked for
Returns:
true if the provided scope is the root of the traits compiles list of scopes.
intgetLevel(FuncDeclarationfd1, FuncDeclarationfd2, intintypeof);
Determine lexical level difference fromfd1 to nested functionfd2.
Parameters:
FuncDeclarationfd1function
FuncDeclarationfd2target of call
intintypeof!=0 if inside typeof
Returns:
0 same level

0 decrease nesting by number -1 increase nesting by 1 (fd2 is nested withinfd1) LevelError error,this cannot callfd2

boolcheckEscapingSiblings(FuncDeclarationf, FuncDeclarationouterFunc, void*p = null);
Given a nested function f inside a function outerFunc, check if any sibling callers of f have escaped. If so, mark all the enclosing functions as needing closures. This is recursive: we need to check the callers of our siblings. Note that nested functions can only call lexically earlier nested functions, so loops are impossible.
Parameters:
FuncDeclarationfinner function (nested within outerFunc)
FuncDeclarationouterFuncouter function
void*pfor internal recursion use
Returns:
true if any closures were needed
boolneedsClosure(FuncDeclarationfd);
Look at all the variables in this function that are referenced by nested functions, and determine if a closure needs to be created for them.
boolcheckNRVO(FuncDeclarationfd);
Check all return statements for a function to verify that returning using NRVO is possible.
Returns:
false if the result cannot be returned by hidden reference.
boolsetImpure(FuncDeclarationfd, Locloc, const(char)*fmt, RootObject[]args...);
The function is doing something impure, so mark it as impure.
Parameters:
FuncDeclarationfdfunction declaration to mark
Locloclocation of impure action
const(char)*fmtformat string for error message
RootObject[]argsargument to format string
Returns:
true if there's a purity error
boolisReturnIsolated(FuncDeclarationfd);
See if pointers from function parameters, mutable globals, or uplevel functions could leak into return value.
Returns:
true if the function return value is isolated from any inputs to the function
boolisTypeIsolated(FuncDeclarationfd, Typet);

boolisTypeIsolated(FuncDeclarationfd, Typet, ref StringTable!TypeparentTypes);
See if pointers from function parameters, mutable globals, or uplevel functions could leak into typet.
Parameters:
Typettype to check if it is isolated
Returns:
true ift is isolated from any inputs to the function
intoverloadApply(Dsymbolfstart, scope int delegate(Dsymbol)dg, Scope*sc = null);
Visit each overloaded function/template in turn, and call dg(s) on it. Exit when no more, or dg(s) returns nonzero.
Parameters:
Dsymbolfstartsymbol to start from
int delegate(Dsymbol)dgthe delegate to be called on the overload
Scope*sccontext used to check if symbol is accessible (and therefore visible), can be null
Returns:
==0 continue !=0 done (and the return value from the last dg() call)
boolcheckNestedReference(VarDeclarationvd, Scope*sc, Locloc);
Check to see if this variable is actually in an enclosing function rather than the current one. Update nestedrefs[], closureVars[] and outerVars[].
Returns:
true if error occurs.
boolarrayBoundsCheck(FuncDeclarationfd);
Check to see if array bounds checking code has to be generated
Parameters:
FuncDeclarationfdfunction for which code is to be generated
Returns:
true if do array bounds checking for the given function
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 17:56:29 2026

[8]ページ先頭

©2009-2026 Movatter.jp