Class SyntheticMethodCallBuilder
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.support.SyntheticMethodCallBuilder
Fluent builder for generating method and constructor call IR instructions.
Replaces the 6+ overloaded generateMethodCall methods and
generateConstructorCall variants with a self-documenting fluent API.
Method call examples:
// No-arg method call
methodCall()
.on(target, targetType)
.method("_isSet")
.returning(booleanType)
.into(resultVar)
.build(ctx);
// Single-arg method call
methodCall()
.on(target, targetType)
.method("_eq")
.arg(otherVar, otherType)
.returning(booleanType)
.into(resultVar)
.build(ctx);
// Trait call (invokeinterface)
methodCall()
.on(fieldVar, traitType)
.method("_isSet")
.returning(booleanType)
.traitCall()
.into(resultVar)
.build(ctx);
// Void method call (no result variable)
methodCall()
.on(target, targetType)
.method("_unSet")
.returning(voidType)
.buildVoid(ctx);
// Super call (uses invokespecial, not invokevirtual)
methodCall()
.onSuper(superType)
.method("_eq")
.arg(paramVar, superType)
.returning(booleanType)
.into(resultVar)
.build(ctx);
// Static call
methodCall()
.onStatic(stringType)
.method("_of")
.arg(primitiveVar, "java.lang.String")
.returning(stringType)
.into(resultVar)
.build(ctx);
Constructor call examples:
// No-arg constructor
constructorCall()
.type(booleanType)
.into(resultVar)
.build(ctx);
// Constructor with args
constructorCall()
.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).
-
Method Summary
Modifier and TypeMethodDescriptionAdd a single argument to the method call.Add multiple arguments to the method call.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.buildVoid(SynthesisScope ctx) Build the IR instructions for a void method call using a SynthesisScope context.static SyntheticMethodCallBuilderCreate a builder for a constructor call.Set the variable to store the result into.Set the method name to call.static SyntheticMethodCallBuilderCreate a builder for a method call.Set the target object and its type for an instance method call.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).Set the type for a constructor call.
-
Method Details
-
methodCall
Create a builder for a method call.- Returns:
- A new builder configured for method calls
-
constructorCall
Create a builder for a constructor call.- Returns:
- A new builder configured for constructor calls
-
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
-
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
-
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
-
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
-