Class SyntheticMethodCallBuilder
Replaces the 6+ overloaded generateMethodCall methods and
generateConstructorCall variants with a self-documenting fluent API.
Method call examples:
// No-arg method call
new SyntheticMethodCallBuilder(typeLinkage)
.on(target, targetType)
.method("_isSet")
.returning(booleanType)
.into(resultVar)
.build(ctx);
// Single-arg method call
new SyntheticMethodCallBuilder(typeLinkage)
.on(target, targetType)
.method("_eq")
.arg(otherVar, otherType)
.returning(booleanType)
.into(resultVar)
.build(ctx);
// Trait call (invokeinterface)
new SyntheticMethodCallBuilder(typeLinkage)
.on(fieldVar, traitType)
.method("_isSet")
.returning(booleanType)
.traitCall()
.into(resultVar)
.build(ctx);
// Void method call (no result variable)
new SyntheticMethodCallBuilder(typeLinkage)
.on(target, targetType)
.method("_unSet")
.returning(voidType)
.buildVoid(ctx);
// Super call (uses invokespecial, not invokevirtual)
new SyntheticMethodCallBuilder(typeLinkage)
.onSuper(superType)
.method("_eq")
.arg(paramVar, superType)
.returning(booleanType)
.into(resultVar)
.build(ctx);
// Static call
new SyntheticMethodCallBuilder(typeLinkage)
.onStatic(stringType)
.method("_of")
.arg(primitiveVar, "java.lang.String")
.returning(stringType)
.into(resultVar)
.build(ctx);
Constructor call examples:
// No-arg constructor
new SyntheticMethodCallBuilder(typeLinkage).forConstructor()
.type(booleanType)
.into(resultVar)
.build(ctx);
// Constructor with args
new SyntheticMethodCallBuilder(typeLinkage).forConstructor()
.type(bitsType)
.arg(emptyStringVar, stringType)
.into(resultVar)
.build(ctx);
The builder handles CALL + RETAIN + SCOPE_REGISTER automatically, skipping memory management for primitive return types (boolean, int, void).
-
Constructor Summary
ConstructorsConstructorDescriptionSyntheticMethodCallBuilder(TypeLinkage typeLinkage) A builder for a method call;forConstructor()makes it a constructor call. -
Method Summary
Modifier and TypeMethodDescriptionAdd a single argument to the method call.Add multiple arguments to the method call.Run the NAMED type's own implementation, even when the receiver's class overrides it (D38) - seeCallDetails.Build the IR instructions for this call using explicit debugInfo and scopeId.build(SynthesisScope ctx) Build the IR instructions for this call using a SynthesisScope context.The call instruction alone, for a caller that states the result's owner itself.buildReturning(String returnVariable, DebugInfo debugInfo, String scopeId) buildReturning(String, SynthesisScope)with explicit debugInfo and scopeId.buildReturning(String returnVariable, SynthesisScope ctx) Build the call and hand its result straight to the returning variable: the result is made forrtnand nothing else, so it is moved there (OwnershipStatements.returnFresh(String, String, DebugInfo)) rather than registered with the scope and copied.Build the IR instructions for a void method call using explicit debugInfo and scopeId.buildVoid(SynthesisScope ctx) Build the IR instructions for a void method call using a SynthesisScope context.Make this a constructor call (<init>); call it first, before the type and arguments.Set the variable to store the result into.Set the method name to call.Set the target object and its type for an instance method call.The same target, but named by its resolved SYMBOL so the dispatch flag can be derived from it.Set up for a static method call (no target object).Set the target as "super" for a super method call.Set the return type of the method.Mark this as a trait call (uses invokeinterface instead of invokevirtual).traitCallIf(boolean condition) Mark this as a trait call only when the condition holds - use when the receiver may or may not be a trait (e.g.Set the type for a constructor call.
-
Constructor Details
-
SyntheticMethodCallBuilder
A builder for a method call;forConstructor()makes it a constructor call.- Parameters:
typeLinkage- THE answer to "is the type this call names externally linked" (isExternTarget)
-
-
Method Details
-
forConstructor
Make this a constructor call (<init>); call it first, before the type and arguments.- Returns:
- This builder
-
on
Set the target object and its type for an instance method call.The call will use invokevirtual unless
traitCall()oronSuper(String)is used.- Parameters:
target- The variable to call the method on (e.g., "this", "param", a temp)targetType- The fully qualified type name of the target- Returns:
- This builder
-
on
The same target, but named by its resolved SYMBOL so the dispatch flag can be derived from it.The builder otherwise holds only a type NAME, and so had to decide
isVirtualCallfrom the call SHAPE alone - which made everythis.m()virtual, including on closed types. A closed enum's synthesised_inc()renderedthis._isSet()as virtual while the same operator on the same type rendered non-virtual everywhere else. Openness is a property of the type, so pass the symbol wherever the caller holds one; sites that do not are left on the shape-only answer rather than being given a fabricated default.- Parameters:
target- The variable to call the method ontargetTypeSymbol- The target's type as a resolved symbol - supplies BOTH the emitted name and the dispatch flag, so the two cannot disagree- Returns:
- This builder
-
onSuper
Set the target as "super" for a super method call.Super calls use invokespecial (not invokevirtual) to bypass virtual dispatch.
- Parameters:
superType- The fully qualified type name of the super class- Returns:
- This builder
-
onStatic
Set up for a static method call (no target object).- Parameters:
staticType- The fully qualified type name containing the static method- Returns:
- This builder
-
type
Set the type for a constructor call.- Parameters:
typeName- The fully qualified type name to construct- Returns:
- This builder
-
method
Set the method name to call.- Parameters:
name- The method name (e.g., "_eq", "_cmp", "_isSet")- Returns:
- This builder
-
arg
Add a single argument to the method call.- Parameters:
argVar- The argument variable nameargType- The fully qualified type of the argument- Returns:
- This builder
-
args
Add multiple arguments to the method call.- Parameters:
argVars- The argument variable namesargTypes- The fully qualified types of the arguments- Returns:
- This builder
-
returning
Set the return type of the method.- Parameters:
type- The fully qualified return type name- Returns:
- This builder
-
into
Set the variable to store the result into.- Parameters:
var- The result variable name- Returns:
- This builder
-
traitCall
Mark this as a trait call (uses invokeinterface instead of invokevirtual).- Returns:
- This builder
-
boundToNamedType
Run the NAMED type's own implementation, even when the receiver's class overrides it (D38) - seeCallDetails. Needs the target as a SYMBOL (on(String, ISymbol)): only a call that would otherwise dispatch (an open type) is marked; a call to a closed type is already bound to it, so it is left as it is.- Returns:
- This builder
-
traitCallIf
Mark this as a trait call only when the condition holds - use when the receiver may or may not be a trait (e.g. a field whose type is a trait needs INVOKEINTERFACE, otherwise INVOKEVIRTUAL). PassTraitCall.requiredForValue(field).- Parameters:
condition- true if the receiver type is a trait- Returns:
- This builder
-
build
Build the IR instructions for this call using a SynthesisScope context.Generates CALL + RETAIN + SCOPE_REGISTER for non-primitive return types. For primitive return types (boolean, int), only CALL is generated.
- Parameters:
ctx- The synthesis scope providing debugInfo and scopeId- Returns:
- List of IR instructions for the call
-
build
-
buildCall
-
buildReturning
Build the call and hand its result straight to the returning variable: the result is made forrtnand nothing else, so it is moved there (OwnershipStatements.returnFresh(String, String, DebugInfo)) rather than registered with the scope and copied. Nothing may read the result after this.- Parameters:
returnVariable- the returning variable, empty herectx- the synthesis scope providing debugInfo and scopeId- Returns:
- the call and the move into the returning variable
-
buildReturning
-
buildVoid
Build the IR instructions for a void method call using a SynthesisScope context.Equivalent to setting resultVar to null and building. No RETAIN or SCOPE_REGISTER is emitted.
- Parameters:
ctx- The synthesis scope providing debugInfo and scopeId- Returns:
- List of IR instructions for the void call
-
buildVoid
Build the IR instructions for a void method call using explicit debugInfo and scopeId.Equivalent to setting resultVar to null and building. No RETAIN or SCOPE_REGISTER is emitted.
- Parameters:
debugInfo- Debug information for the instructionsscopeId- Current scope ID for memory management- Returns:
- List of IR instructions for the void call
-