Class EnrichedControlFlowGenerator
java.lang.Object
org.ek9lang.compiler.fuzz.EnrichedControlFlowGenerator
Generates enriched control flow constructs for template enrichment: if/else, guards,
switch, for/while loops, try-catch, and enriched statements. Each construct uses
type-aware expressions from the harvested type information.
Extracted from
TemplateEnrichmentGenerator.-
Method Summary
Modifier and TypeMethodDescription(package private) static voidappendBody(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Append body content for a control flow block.(package private) static voidappendCrossTypeInteractions(StringBuilder sb, String indent, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Append cross-type interactions that generate semantically incorrect but syntactically valid EK9 code.(package private) static voidappendEnrichedControlFlow(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Main dispatch: randomly selects a control flow construct to append.(package private) static voidappendEnrichedStatement(StringBuilder sb, String indent, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Append a leaf statement: method call, print, operator use, or function call.(package private) static voidappendForIn(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendForInGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendForRange(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendIfElse(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendIfGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendStream(StringBuilder sb, String indent, Map<String, String> constructedTypes, List<HarvestedType> types, Random random) (package private) static voidappendSwitch(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendSwitchGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendTryCatch(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendWhile(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static voidappendWhileGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) (package private) static booleanCheck whether we can provide arguments for all parameters of a function, either from constructed instances or as built-in type literals.(package private) static StringExtract the base type name from a constructedTypes key.(package private) static List<HarvestedFunction> findCallableFunction(List<HarvestedFunction> functions, Map<String, String> constructedTypes) Find harvested functions that return a non-Void value and whose parameters we can satisfy from constructed instances or literals.(package private) static HarvestedTypefindTypeByName(String name, List<HarvestedType> types) Find a harvested type by name from the types list.(package private) static StringgenerateCondition(Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Generate a condition expression by calling a harvested function and checking isSet on the result.(package private) static booleanhasOperator(HarvestedType type, String operatorName) Check whether a harvested type has a specific operator.(package private) static booleanshouldNestAtDepth(int depth, Random random) Decreasing nesting probability: 80% at depth 0, 50% at depth 1, 20% at depth 2+.
-
Method Details
-
appendEnrichedControlFlow
static void appendEnrichedControlFlow(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Main dispatch: randomly selects a control flow construct to append. -
appendIfElse
static void appendIfElse(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendIfGuard
static void appendIfGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendSwitch
static void appendSwitch(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendSwitchGuard
static void appendSwitchGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendForRange
static void appendForRange(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendForIn
static void appendForIn(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendWhile
static void appendWhile(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendForInGuard
static void appendForInGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendWhileGuard
static void appendWhileGuard(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendTryCatch
static void appendTryCatch(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) -
appendStream
static void appendStream(StringBuilder sb, String indent, Map<String, String> constructedTypes, List<HarvestedType> types, Random random) -
appendEnrichedStatement
static void appendEnrichedStatement(StringBuilder sb, String indent, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Append a leaf statement: method call, print, operator use, or function call. Only uses $instance when the type has operator $, otherwise uses ? 30% chance of cross-type method call when multiple types are constructed. -
appendCrossTypeInteractions
static void appendCrossTypeInteractions(StringBuilder sb, String indent, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Append cross-type interactions that generate semantically incorrect but syntactically valid EK9 code. This pushes programs deeper into the compiler pipeline before triggering errors, targeting E03xxx (type mismatch), E05xxx (no such method), E07xxx (incompatible assignment). -
hasOperator
Check whether a harvested type has a specific operator. -
findTypeByName
Find a harvested type by name from the types list. -
extractBaseTypeName
-
appendBody
static void appendBody(StringBuilder sb, String indent, int depth, int maxDepth, Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Append body content for a control flow block. Recurses with decreasing probability based on depth. -
shouldNestAtDepth
Decreasing nesting probability: 80% at depth 0, 50% at depth 1, 20% at depth 2+. -
generateCondition
static String generateCondition(Map<String, String> constructedTypes, List<HarvestedType> types, List<HarvestedFunction> functions, Random random) Generate a condition expression by calling a harvested function and checking isSet on the result. The compiler's data flow analysis does not trace through function calls, so the result is "runtime unknown" — avoiding E08086 (condition always true). Falls back to instance isSet check only when no callable functions are available. -
findCallableFunction
static List<HarvestedFunction> findCallableFunction(List<HarvestedFunction> functions, Map<String, String> constructedTypes) Find harvested functions that return a non-Void value and whose parameters we can satisfy from constructed instances or literals. -
canSatisfyParams
-