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.dfa.fast.expression
Expression walker for the fast Data Flow Analysis engine.
This module tracks how values flow through expressions.
It is responsible for:
- Tracking Assignments: Updating the state of variables when they are written to.
- Inferring Facts: Learning about variables from conditions (e.g., if (ptr)).
- Handling Function Calls: Managing side effects and return values.
- Modeling Arithmetic: Tracking ranges of values (Point Analysis) to detect overflows.
Authors:
License:
Source dfa/fast/expression.d
Documentation https://dlang.org/phobos/dmd_dfa_fast_expression.html
- struct
ExpressionWalker; - Visits Expression nodes to track data flow.This struct implements the logic for how expressions affect the DFA state. It translates AST operations (like +, =, ==) into DFALatticeRef updates.
- DFALatticeRef
seeAssign(DFAVar*assignTo, boolconstruct, DFALatticeReflr, ref Locloc, boolisBlit= false, intalteredState= 0); - Handles variable assignment (e.g., x = y).This function updates the
assignTovariable in the current scope to reflect the new state derived fromlr(the right-hand side).Parameters:DFAVar* assignToThe variable being written to. bool constructTrue if this is an initialization (e.g., int x = 5;), false if reassignment. DFALatticeRef lrThe lattice state of the value being assigned. Loc locSource file location of the assignment. bool isBlitTrue if the assignment is a bitwise copy (blit). int alteredStateAn integer representing a specific state alteration or flag. - DFALatticeRef
seeEqual(DFALatticeReflhs, DFALatticeRefrhs, booltruthiness, TypelhsType, TyperhsType); - Handles equality checks (e.g., x == y).This is critical for control flow. If the DFA sees if (x == null), this function records that relationship so the StatementWalker can create a scope where x is known to be null.
- DFALatticeRef
seeEqualIdentity(DFALatticeReflhs, DFALatticeRefrhs, booltruthiness, TypelhsType, TyperhsType); - Handles equality checks (e.g., x is y).This is critical for control flow. If the DFA sees if (x == null), this function records that relationship so the StatementWalker can create a scope where x is known to be null.
- DFALatticeRef
walk(Expressionexpr); - The main dispatch loop for expressions.Visits an expression node and returns the resulting Lattice state. This handles the recursion for complex expressions like (a + b) * c.Returns:A DFALatticeRef representing the computed value/state of the expression.
- DFALatticeRef
walkCondition(Expressionexpr, out intpredicateNegation); - Walks an expression that is used for a condition i.e. and if statement. Tells you if the expression for the gate variable, will be exact, vs negated state. Applying by test is for when (expr) > 0, use 0 for unknown, 1 is <= 0 and 2 is > 0Returns:0 for unknown negation, 1 or has been negated from gate variable or 2 if it hasn't been.
Copyright © 1999-2026 by the D Language Foundation | Page generated by
Ddoc on Wed Aug 5 15:48:35 2026