Class ToStringGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.ToStringGenerator
Generates synthetic IR for the _string ($) operator.
The generated code follows this pattern:
String _string():
// Guard: if no field (own or super) is set, return UNSET
if this is empty -> return unset String
result = "ClassName("
// Super FIRST (base-to-derived), via super.$() - honours a user-defined super $:
if super has $:
result = result + super.$() // nested: an unset super propagates (copy-left)
// Then each own field, unconditionally (no isSet guard):
for each field:
[result = result + ", " if not the first element]
result = result + "fieldName="
result = result + field.$() // unset field -> result becomes unset (copy-left)
result = result + ")"
return result
Key semantic requirements:
- Renders inherited fields by calling
super.$()(NOT by reading super's fields): a user-defined super $ may render more than just fields and must be honoured, so the super string is treated as opaque and nested -Cat(Animal(name=Felix), breed=Siamese) - Copy-left String join:
String._addis set only when BOTH operands are set, so any unset field (or unset super) propagates and the WHOLE $ becomes unset - the string twin of the AND-model ? operator. There is nofield=?placeholder. - Format: "ClassName(field1=value1, field2=value2)" (simple class name, not fully qualified)
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractSyntheticGenerator
AbstractSyntheticGenerator.ScopeSetup -
Field Summary
Fields inherited from class AbstractSyntheticGenerator
stackContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerate(MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol) Generate the _string operator IR for the given aggregate.Methods inherited from class AbstractSyntheticGenerator
aggregateHasOperator, constructorCall, createDebugInfo, createSynthesisScope, generateAnyFieldSetGuard, generateBinaryOperatorGuards, generateBooleanBranch, generateFieldLoad, generateFieldLoad, generateFieldSetStatusCheck, generateIsSetGuard, generateIsSetGuard, generateLabelName, generateResultReturnBlock, generateResultReturnBlock, generateStringLiteralLoad, generateTempName, generateThisIsSetGuard, generateThisIsSetGuard, generateUnsetReturnBlockWithLabel, generateUnsetReturnBlockWithLabel, getBitsTypeName, getBooleanTypeName, getIntegerTypeName, getReturnBlockHelper, getStringTypeName, getSuperTypeName, getSyntheticFields, getTypeName, getVoidTypeName, initializeScope, initializeScopeNoReturn, isAnyType, isTraitType, methodCall, superHasOperator
-
Constructor Details
-
ToStringGenerator
ToStringGenerator(IRGenerationContext stackContext)
-
-
Method Details
-
generate
Generate the _string operator IR for the given aggregate.- Parameters:
operatorSymbol- The _string operator symbolaggregateSymbol- The aggregate containing the operator- Returns:
- List of IR instructions implementing the operator
-