Class SyntheticOperatorGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.SyntheticOperatorGenerator
Main coordinator for synthetic operator generation.
This class dispatches synthetic operator/method generation to the appropriate specialized generator based on the operator type. All synthetic generation happens at IR level, producing complete instruction sequences that backends can translate directly.
Supported Operators
For records and classes:
- _eq - Field-by-field equality comparison
- _neq - Delegates to _eq and negates
- _hashcode - Combined hash of all fields
- _string - String representation of all fields
- _copy - Copy all fields from source
For enumerations:
- _eq, _neq, _cmp, _lt, _lte, _gt, _gte - Ordinal-based comparisons
- _string, _promote - Return enum value name
- _json - JSON representation of enum name
- _hashcode - Hash of ordinal
- _isSet - Check if ordinal is set
- _prefix, _suffix - First and last enum values
- String-param comparisons - Convert string to enum then compare
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSyntheticOperatorGenerator(IRGenerationContext stackContext) Create a new synthetic operator generator. -
Method Summary
Modifier and TypeMethodDescriptiongenerateEnumConstructor(MethodSymbol constructorSymbol, AggregateSymbol aggregateSymbol) Generate IR for a parameterized enum constructor (copy or String).generateMethod(MethodSymbol methodSymbol, AggregateSymbol aggregateSymbol) Generate IR for a synthetic regular method (non-operator).generateOperator(MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol) Generate IR for a synthetic operator.
-
Constructor Details
-
SyntheticOperatorGenerator
Create a new synthetic operator generator.- Parameters:
stackContext- The IR generation context for accessing state
-
-
Method Details
-
generateOperator
public OperationInstr generateOperator(MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol) Generate IR for a synthetic operator.Dispatches to the appropriate specialized generator based on the operator name. Returns a complete
OperationInstrwith fully populated IR instructions.- Parameters:
operatorSymbol- The synthetic operator method symbolaggregateSymbol- The aggregate (class/record/enumeration) containing the operator- Returns:
- The populated OperationInstr with generated IR body
-
generateMethod
Generate IR for a synthetic regular method (non-operator).Handles methods like _isSet that are auto-generated based on aggregate properties.
- Parameters:
methodSymbol- The synthetic method symbolaggregateSymbol- The aggregate containing the method- Returns:
- The populated OperationInstr with generated IR body
-
generateEnumConstructor
public OperationInstr generateEnumConstructor(MethodSymbol constructorSymbol, AggregateSymbol aggregateSymbol) Generate IR for a parameterized enum constructor (copy or String).The default no-arg constructor is handled by AbstractDfnGenerator.processSyntheticConstructor. This method handles the copy and String constructors specific to enumerations.
- Parameters:
constructorSymbol- The constructor method symbolaggregateSymbol- The enumeration aggregate- Returns:
- The populated OperationInstr with generated IR body
-