Class AbstractSyntheticGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
- Direct Known Subclasses:
CompareGenerator, CopyGenerator, DerivedComparisonGenerator, EqualsGenerator, FieldSetStatusGenerator, HashCodeGenerator, IsSetGenerator, NotEqualsGenerator, ToStringGenerator
Base class for synthetic operator generators.
Provides common patterns and utilities used by all synthetic generators:
- IsSet guard generation for this and parameters
- Unset return block generation
- Field iteration utilities
- Memory management (RETAIN/SCOPE_REGISTER) patterns
All generated IR follows the EK9 tri-state semantics where operations return unset if any operand is unset.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSyntheticGenerator(IRGenerationContext stackContext) Create a new synthetic generator with the given context. -
Method Summary
Modifier and TypeMethodDescriptionprotected DebugInfocreateDebugInfo(ISymbol symbol) Create debug info from a symbol's source token.generateBooleanReturnBlock(boolean value, String returnVarName, DebugInfo debugInfo, String scopeId) Generate a return block that returns a specific boolean value (true or false).generateConstructorCall(String resultVar, String typeName, DebugInfo debugInfo, String scopeId) Generate a constructor call to create a new instance.generateFieldLoad(String targetVar, String objectVar, String fieldName, DebugInfo debugInfo, String scopeId) Generate field load instruction with memory management.generateIsSetGuard(String variableName, String typeName, DebugInfo debugInfo, String unsetLabel, String scopeId) Generate isSet guard check for a variable with branch to unset return.protected StringgenerateLabelName(String prefix) Generate a label name with the given prefix.generateMethodCall(String resultVar, String targetVar, String targetType, String methodName, List<String> arguments, List<String> parameterTypes, String returnType, DebugInfo debugInfo, String scopeId) Generate a method call on a variable with result storage and memory management.protected StringGenerate a temporary variable name.generateThisIsSetGuard(String aggregateTypeName, DebugInfo debugInfo, String unsetLabel, String scopeId) Generate isSet guard check for 'this' with branch to unset return.generateUnsetReturnBlock(String returnTypeName, String returnVarName, DebugInfo debugInfo, String scopeId) Generate the return_unset basic block that returns an unset value.protected StringGet the Boolean type name from the EK9 type system.protected StringGet the Integer type name from the EK9 type system.protected StringGet the String type name from the EK9 type system.protected StringgetSuperTypeName(AggregateSymbol aggregateSymbol) Get the fully qualified name of the super aggregate.getSyntheticFields(AggregateSymbol aggregateSymbol) Get all fields from an aggregate that should be included in synthetic operations.protected StringgetTypeName(ISymbol symbol) Get the fully qualified name for a type.protected StringGet the Void type name from the EK9 type system.protected booleanisAnyType(IAggregateSymbol type) Check if the given type is the Any type.protected booleansuperHasOperator(AggregateSymbol aggregateSymbol, String operatorName) Check if the super aggregate has a specific operator defined.
-
Field Details
-
stackContext
-
-
Constructor Details
-
AbstractSyntheticGenerator
Create a new synthetic generator with the given context.- Parameters:
stackContext- The IR generation context
-
-
Method Details
-
getTypeName
-
getBooleanTypeName
Get the Boolean type name from the EK9 type system. -
getIntegerTypeName
Get the Integer type name from the EK9 type system. -
getStringTypeName
Get the String type name from the EK9 type system. -
getVoidTypeName
Get the Void type name from the EK9 type system. -
generateTempName
Generate a temporary variable name. -
generateLabelName
-
createDebugInfo
-
generateThisIsSetGuard
protected List<IRInstr> generateThisIsSetGuard(String aggregateTypeName, DebugInfo debugInfo, String unsetLabel, String scopeId) Generate isSet guard check for 'this' with branch to unset return.Pattern:
_temp = CALL this._isSet() -> Boolean RETAIN _temp SCOPE_REGISTER _temp, scope_id _temp_val = UNBOX _temp -> boolean BRANCH_IF_FALSE _temp_val -> unset_label
- Parameters:
aggregateTypeName- The fully qualified type name of the aggregatedebugInfo- Debug information for the instructionsunsetLabel- Label to branch to if unsetscopeId- Current scope ID for memory management- Returns:
- List of IR instructions for the guard
-
generateIsSetGuard
protected List<IRInstr> generateIsSetGuard(String variableName, String typeName, DebugInfo debugInfo, String unsetLabel, String scopeId) Generate isSet guard check for a variable with branch to unset return.The check generates:
1. _temp = CALL variable._isSet() -> Boolean 2. RETAIN/SCOPE_REGISTER _temp 3. _tempBool = CALL _temp._true() -> boolean (primitive) 4. RETAIN/SCOPE_REGISTER _tempBool 5. BRANCH_FALSE _tempBool, unsetLabel
- Parameters:
variableName- The variable to checktypeName- The fully qualified type name of the variabledebugInfo- Debug information for the instructionsunsetLabel- Label to branch to if unsetscopeId- Current scope ID for memory management- Returns:
- List of IR instructions for the guard
-
generateUnsetReturnBlock
protected List<IRInstr> generateUnsetReturnBlock(String returnTypeName, String returnVarName, DebugInfo debugInfo, String scopeId) Generate the return_unset basic block that returns an unset value.Pattern for Boolean return:
return_unset: _result = CALL Boolean._new() -> Boolean RETAIN _result STORE rtn = _result SCOPE_EXIT scope_id RETURN rtn- Parameters:
returnTypeName- The type of value to return (e.g., Boolean, Integer)returnVarName- The name of the return variable (typically "rtn")debugInfo- Debug information for the instructionsscopeId- Current scope ID for cleanup- Returns:
- List of IR instructions for the unset return block
-
generateBooleanReturnBlock
protected List<IRInstr> generateBooleanReturnBlock(boolean value, String returnVarName, DebugInfo debugInfo, String scopeId) Generate a return block that returns a specific boolean value (true or false).- Parameters:
value- The boolean value to return (true or false)returnVarName- The name of the return variabledebugInfo- Debug informationscopeId- Current scope ID- Returns:
- List of IR instructions
-
getSyntheticFields
Get all fields from an aggregate that should be included in synthetic operations.This returns only the direct properties of the aggregate, not inherited ones. Inherited fields are handled by calling super's synthetic operators.
- Parameters:
aggregateSymbol- The aggregate to get fields from- Returns:
- List of field symbols
-
superHasOperator
Check if the super aggregate has a specific operator defined.- Parameters:
aggregateSymbol- The aggregate whose super we're checkingoperatorName- The operator name (e.g., "==", "<=>")- Returns:
- true if super has the operator, false otherwise
-
isAnyType
Check if the given type is the Any type. -
getSuperTypeName
Get the fully qualified name of the super aggregate.- Parameters:
aggregateSymbol- The aggregate to get super from- Returns:
- The super type name, or empty string if no super (other than Any)
-
generateFieldLoad
protected List<IRInstr> generateFieldLoad(String targetVar, String objectVar, String fieldName, DebugInfo debugInfo, String scopeId) Generate field load instruction with memory management.Pattern:
_temp = LOAD this.fieldName -> FieldType RETAIN _temp SCOPE_REGISTER _temp, scope_id
- Parameters:
targetVar- The variable to store the loaded valueobjectVar- The object to load from (typically "this" or "other")fieldName- The field name to loaddebugInfo- Debug informationscopeId- Current scope ID- Returns:
- List of IR instructions
-
generateConstructorCall
protected List<IRInstr> generateConstructorCall(String resultVar, String typeName, DebugInfo debugInfo, String scopeId) Generate a constructor call to create a new instance.Pattern:
_result = CALL (Type)Type.<init>() [pure=true, complexity=1, effects=RETURN_MUTATION] RETAIN _result SCOPE_REGISTER _result, scope_id
- Parameters:
resultVar- Variable to store resulttypeName- Fully qualified type name to constructdebugInfo- Debug informationscopeId- Current scope ID- Returns:
- List of IR instructions
-
generateMethodCall
protected List<IRInstr> generateMethodCall(String resultVar, String targetVar, String targetType, String methodName, List<String> arguments, List<String> parameterTypes, String returnType, DebugInfo debugInfo, String scopeId) Generate a method call on a variable with result storage and memory management.- Parameters:
resultVar- Variable to store resulttargetVar- Variable to call method on (null for static calls)targetType- Fully qualified type name of the targetmethodName- Method to callarguments- Method argument variable namesparameterTypes- Parameter types (must match arguments)returnType- Return type of methoddebugInfo- Debug informationscopeId- Current scope ID- Returns:
- List of IR instructions
-