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():
// Initialize with field set status as base hash
result = this._fieldSetStatus()
// For each field:
if field._isSet():
fieldHash = field.#?()
result = result * 31
result = result + fieldHash
return result
Key semantic requirements:
- Returns Integer (always set - hash of "nothing" is valid)
- Only SET fields contribute to hash
- Field set status bitmask is included as base hash
- Uses polynomial hash: result = result * 31 + fieldHash
- Objects with different set/unset patterns have different hashes
The inclusion of _fieldSetStatus() as the initial hash value ensures that two objects with the same set field values but different unset fields will produce different hash codes.
-
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
createDebugInfo, generateBooleanReturnBlock, generateConstructorCall, generateFieldLoad, generateIsSetGuard, generateLabelName, generateMethodCall, generateTempName, generateThisIsSetGuard, generateUnsetReturnBlock, getBooleanTypeName, getIntegerTypeName, getStringTypeName, getSuperTypeName, getSyntheticFields, getTypeName, getVoidTypeName, 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
-