dmd.sideeffect
Find side-effects of expressions.
License
Source: sideeffect.d
Documentation: https://dlang.org/phobos/dmd_sideeffect.html
-
Declaration
bool
isTrivialExp
(Expressione
);Front-end expression rewriting should create temporary variables for non trivial sub-expressions in order to:
- save evaluation order
- prevent sharing of sub-expression in AST
-
Declaration
bool
hasSideEffect
(Expressione
, boolassumeImpureCalls
= false);Determine if Expression has any side effects.
Parameters
Expression
e
the expression
bool
assumeImpureCalls
whether function calls should always be assumed to be impure (
e
.g. debug is allowed to violate purity) -
Declaration
int
callSideEffectLevel
(FuncDeclarationf
);Determine if the call of
f
, or function type or delegate type t1, has any side effects.Return Value
0 has any side effects 1 nothrow + constant purity 2 nothrow + strong purity
-
Declaration
bool
discardValue
(Expressione
);The result of this expression will be discarded. Print error messages if the operation has no side effects (and hence is meaningless).
Return Value
true
if expression has no side effects -
Declaration
VarDeclaration
copyToTemp
(StorageClassstc
, const char[]name
, Expressione
);Build a temporary variable to copy the value of
e
into.Parameters
StorageClass
stc
storage classes will be added to the made temporary variable
char[]
name
name
for temporary variableExpression
e
original expression
Return Value
Newly created temporary variable.
-
Declaration
Expression
extractSideEffect
(Scope*sc
, const char[]name
, ref Expressione0
, Expressione
, boolalwaysCopy
= false);Build a temporary variable to extract
e
's evaluation, ife
is not trivial.Parameters
Scope*
sc
scope
char[]
name
name
for temporary variableExpression
e0
a new side effect part will be appended to it.
Expression
e
original expression
bool
alwaysCopy
if
true
, build new temporary variable even ife
is trivial.Return Value
When
e
is trivial andalwaysCopy
==false
,e
itself is returned. Otherwise, a new VarExp is returned.Note:
e
's lvalue-ness will be handled well by STC.ref_ or STC.rvalue.