Class HashCodeGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.HashCodeGenerator
Generates synthetic IR for the _hashcode (#?) operator.
The generated code follows this pattern:
Integer _hashcode():
// Guard: if object is unset, return UNSET
if !this._isSet() -> return unset Integer
// Initialize with field set status as base hash
status = this._fieldSetStatus() // Returns Bits
result = status._hashcode() // Convert Bits to Integer
// For each field:
if field._isSet():
fieldHash = field.#?()
result = result * 31
result = result + fieldHash
return result
Key semantic requirements:
- Returns UNSET Integer if this._isSet() is false (empty objects have no hash)
- Only SET fields contribute to hash
- Field set status (as Bits) is hashed as base value
- Uses polynomial hash: result = result * 31 + fieldHash
- Objects with different set/unset patterns have different hashes
The inclusion of _fieldSetStatus()._hashcode() as the initial hash value ensures that two objects with the same set field values but different unset fields will produce different hash codes.
The ? guard ensures consistency: operations on empty objects propagate uncertainty.
-
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 _hashcode operator IR for the given aggregate.Methods inherited from class AbstractSyntheticGenerator
aggregateHasOperator, createDebugInfo, createSynthesisScope, generateAnyFieldSetGuard, generateBinaryOperatorGuards, generateBooleanBranch, generateBooleanReturnBlock, generateConstructorCall, generateConstructorCall, generateConstructorCall, generateConstructorCallWithArgs, generateFieldLoad, generateFieldLoad, generateFieldSetStatusCheck, generateIsSetGuard, generateIsSetGuard, generateLabelName, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateResultReturnBlock, generateResultReturnBlock, generateStringLiteralLoad, generateTempName, generateThisIsSetGuard, generateThisIsSetGuard, generateUnsetReturnBlock, generateUnsetReturnBlockWithLabel, generateUnsetReturnBlockWithLabel, getBitsTypeName, getBooleanTypeName, getIntegerTypeName, getReturnBlockHelper, getStringTypeName, getSuperTypeName, getSyntheticFields, getTypeName, getVoidTypeName, initializeScope, isAnyType, superHasOperator
-
Constructor Details
-
HashCodeGenerator
HashCodeGenerator(IRGenerationContext stackContext)
-
-
Method Details
-
generate
Generate the _hashcode operator IR for the given aggregate.- Parameters:
operatorSymbol- The _hashcode operator symbolaggregateSymbol- The aggregate containing the operator- Returns:
- List of IR instructions implementing the operator
-