Class LiteralExtractor
Converts ANTLR parse tree literal contexts into ConstantValue instances
for the value tracking analyzer. Supports integer, boolean, string, float, character,
date, time, datetime, and millisecond literals.
The EK9 grammar uses labeled alternatives for the literal rule, so the concrete context types are subclasses of LiteralContext (IntegerLiteralContext, etc.).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionExtract a constant value from an assignment expression context.Extract a constant value from an expression context.Extract a constant value directly from a literal context.
-
Constructor Details
-
LiteralExtractor
public LiteralExtractor()
-
-
Method Details
-
extractFromAssignment
Extract a constant value from an assignment expression context.Handles both simple literals (
5) and negated literals (-5).- Parameters:
assignExpr- the assignment expression to examine- Returns:
- a ConstantValue if the expression is a literal, null otherwise
-
extractFromLiteral
Extract a constant value directly from a literal context. -
extractFromExpression
Extract a constant value from an expression context.As well as bare literals this folds COMPUTED constant expressions, so that
not true,true and falseand~(true and not false)are each recognised as the constant they are. Without folding such an initialiser reads as "unknown", and analyses built on this extractor - guarded assignment (E08095), the always-true/false conditions (E08086/E08087) - silently give up on it.Returns null when the expression is not a compile-time constant.
-