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.funcsem
Does semantic analysis for functions.
Specification Functions
Authors:
License:
Source funcsem.d
Documentation https://dlang.org/phobos/dmd_funcsem.html
- void
funcDeclarationSemantic
(Scope*sc
, FuncDeclarationfuncdecl
); - Main semantic routine for functions.
- bool
functionSemantic
(FuncDeclarationfd
); - Resolve forward reference of function signature - parameter types, return type, and attributes.Parameters:
FuncDeclaration fd
function declaration Returns:false if any errors exist in the signature. - bool
functionSemantic3
(FuncDeclarationfd
); - Resolve forward reference of function body. Returns false if any errors exist in the body.
- void
declareThis
(FuncDeclarationfd
, Scope*sc
); - Creates and returns the hidden parameters for this function declaration.Hidden parameters include the this parameter of a class, struct or nested function and the selector parameter for Objective-C methods.
- bool
checkForwardRef
(FuncDeclarationfd
, const ref Locloc
); - Check that this function type is properly resolved. If not, report "forward reference error" and return true.
- int
findVtblIndex
(FuncDeclarationfd
, Dsymbol[]vtbl
); - Find index of function in vtbl[0..length] that this function overrides. Prefer an exact match to a covariant one.Parameters:
FuncDeclaration fd
function Dsymbol[] vtbl
vtable 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:
FuncDeclaration fd
function Returns:base class if overriding, null if not - enum
FuncResolveFlag
: ubyte; - Flag used by resolveFuncCall.
standard
- issue error messages, solve the call.
quiet
- do not issue error message on no match, just return null.
overloadOnly
- only resolve overloads, i.e. do not issue error on ambiguous
ufcs
- matches and need explicit this.trying to resolve UFCS call
- FuncDeclaration
resolveFuncCall
(const ref 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:
Loc loc
instantiation location Scope* sc
instantiation scope Dsymbol s
instantiation symbol Objects* tiargs
initial list of template arguments Type tthis
if !NULL, the this argument type ArgumentList argumentList
arguments to function FuncResolveFlag flags
see FuncResolveFlag. Returns:if match is found, then function symbol, else null - Expression
addInvariant
(AggregateDeclarationad
, VarDeclarationvthis
); - Generate Expression to call the invariant.
Input ad aggregate with the invariant vthis variable with 'this'
Returns:void expression that calls the invariant - FuncDeclaration
overloadExactMatch
(FuncDeclarationthisfd
, Typet
); - Find function in overload list that exactly matches t.
- FuncDeclaration
overloadModMatch
(FuncDeclarationthisfd
, const ref Locloc
, Typetthis
, ref boolhasOverloads
); - Find function in overload list that matches to the 'this' modifier. There's four result types.
- 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.
- 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.
- 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.
- 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.
- int
getLevelAndCheck
(FuncDeclarationfd
, const ref Locloc
, Scope*sc
, FuncDeclarationtarget
, Declarationdecl
); - Determine lexical level difference from
fd
to nested functiontarget
. Issue error iffd
cannot calltarget
.Parameters:FuncDeclaration fd
function Loc loc
location for error messages Scope* sc
context FuncDeclaration target
target of call Declaration decl
The Declaration that triggered this check. Used to provide a better error message only. Returns:0 same level0 decrease nesting by number -1 increase nesting by 1 (
target
is nested within 'fd') LevelError error - bool
canInferAttributes
(FuncDeclarationfd
, Scope*sc
); - Decide if attributes for this function can be inferred from examining the function body.Returns:true if can
- bool
checkNestedReference
(FuncDeclarationfd
, Scope*sc
, const ref Locloc
); - In the current function, we are calling 'this' function.
- Check to see if the current function can call 'this' function, issue error if not.
- If the current function is not the parent of 'this' function, then add the current function to the list of siblings of 'this' function.
- If the current function is a literal, and it's accessing an uplevel scope, then mark it as a delegate.
- void
buildResultVar
(FuncDeclarationfd
, Scope*sc
, Typetret
); - Declare result variable lazily.
- Statement
mergeFrequire
(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.
- Statement
mergeFrequireInclusivePreview
(FuncDeclarationfd
, Statementsf
, Expressions*params
); - Merge into this function the 'in' contracts of all it overrides.
- void
buildEnsureRequire
(FuncDeclarationthisfd
); - Rewrite contracts as statements.
- Statement
mergeFensure
(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.
- void
modifyReturns
(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.
- bool
isRootTraitsCompilesScope
(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* sc
scope to be checked for Returns:true if the provided scope is the root of the traits compiles list of scopes. - bool
setUnsafe
(Scope*sc
, boolgag
= false, Locloc
= Loc.init, const(char)*fmt
= null, RootObjectarg0
= null, RootObjectarg1
= null, RootObjectarg2
= null); - A statement / expression in this scope is not @safe, so mark the enclosing function as @systemParameters:
Scope* sc
scope that the unsafe statement / expression is in bool gag
surpress error message (used in escape.d) Loc loc
location of error const(char)* fmt
printf-style format string RootObject arg0
(optional) argument for first %s format specifier RootObject arg1
(optional) argument for second %s format specifier RootObject arg2
(optional) argument for third %s format specifier Returns:whether there's a safe error - bool
setUnsafePreview
(Scope*sc
, FeatureStatefs
, boolgag
, Locloc
, const(char)*msg
, RootObjectarg0
= null, RootObjectarg1
= null, RootObjectarg2
= null); - Like setUnsafe, but for safety errors still behind preview switchesGiven a FeatureState
fs
, for example dip1000 / dip25 / systemVariables, the behavior changes based on the setting:- In case of -revert=
fs
, it does nothing. - In case of -preview=
fs
, it's the same as setUnsafe - By default, print a deprecation in @safe functions, or store an attribute violation in inferred functions.
Parameters:Scope* sc
used to find affected function/variable, and for checking whether we are in a deprecated / speculative scope FeatureState fs
feature state from the preview flag bool gag
surpress error message Loc loc
location of error const(char)* msg
printf-style format string RootObject arg0
(optional) argument for first %s format specifier RootObject arg1
(optional) argument for second %s format specifier RootObject arg2
(optional) argument for third %s format specifier Returns:whether an actual safe error (not deprecation) occured - In case of -revert=
Copyright © 1999-2024 by the D Language Foundation | Page generated by
Ddoc on (no date time)