dmd.initsem
Semantic analysis of initializers.
License
Source: initsem.d
Documentation: https://dlang.org/phobos/dmd_initsem.html
-
Declaration
Expression
toAssocArrayLiteral
(ArrayInitializerai
);If possible, convert array initializer to associative array initializer.
Parameters
ArrayInitializer
ai
array initializer to be converted
Return Value
The converted associative array initializer or ErrorExp if
is not an associative array initializer.ai
-
Declaration
Initializer
initializerSemantic
(Initializerinit
, Scope*sc
, ref Typetx
, NeedInterpretneedInterpret
);Perform semantic analysis on
init
.Parameters
Initializer
init
Initializer AST node
Scope*
sc
context
Type
tx
type that the initializer needs to become. If
tx
is an incomplete type and the initializer completes it, it is updated to be the complete type. ImportC has incomplete typesNeedInterpret
needInterpret
if CTFE needs to be run on this, such as if it is the initializer for a const declaration
Return Value
Initializer
with completed semantic analysis,ErrorInitializer
if errors were encountered -
Declaration
Initializer
inferType
(Initializerinit
, Scope*sc
);Translate
init
to anExpression
in order to infer the type.Parameters
Initializer
init
Initializer
AST nodeScope*
sc
context
Return Value
an equivalent
ExpInitializer
if successful, orErrorInitializer
if it cannot be translated -
Declaration
Expression
initializerToExpression
(Initializerinit
, Typeitype
= null, const boolisCfile
= false);Translate
init
to anExpression
.Parameters
Initializer
init
Initializer
AST nodeType
itype
if not
null
, type to coerce expression tobool
isCfile
default initializers are different with C
Return Value
Expression
created,null
if cannot,ErrorExp
for other errors -
Declaration
Expressions*
resolveStructLiteralNamedArgs
(StructDeclarationsd
, Typet
, Scope*sc
, Lociloc
, Identifier[]names
, scope Expression delegate(size_t i, Type fieldType)getExp
, scope Loc delegate(size_t i)getLoc
);Given the
names
and values of aStructInitializer
orCallExp
, resolve it to a list of expressions to construct aStructLiteralExp
.Parameters
StructDeclaration
sd
struct
Type
t
type of struct (potentially including qualifiers such as
const
orimmutable
)Scope*
sc
scope of the expression initializing the struct
Loc
iloc
location of expression initializing the struct
Identifier[]
names
identifiers passed in argument list,
null
entries for positional argumentsExpression delegate(size_t i, Type fieldType)
getExp
function that, given an index into
and destination type, returns the initializing expressionnames
Loc delegate(size_t i)
getLoc
function that, given an index into
, returns a location for error messagesnames
Return Value
list of expressions ordered to the struct's fields, or
null
on error