Class DeclaredFunction<T extends org.antlr.v4.runtime.ParserRuleContext>
- Type Parameters:
T- the concrete type of body context
This class encapsulates the ANTLR parse-tree context of a function declaration and exposes its semantic components, including the function name, parameters, body, return type, and asynchronous modifier.
A DeclaredFunction is a concrete, immutable declaration with respect
to its identity and scope; however, some derived properties (such as resolved
parameter and return types) may be computed lazily during later compilation
phases.
- Author:
- Chakib Daii
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanIndicates whether the function is declared as asynchronous.private final TThe parse context for the function body block.private final StringThe name of the implementation.private final StringThe name of the function.private final NaftahParser.FunctionDeclarationContextThe original ANTLR parse context for the function declaration.private List<DeclaredParameter>The list of parameters declared for the function.private final NaftahParser.ParameterDeclarationListContextThe parse context for the parameter declaration list.private JavaTypeThe resolved return type of the function.private final NaftahParser.ReturnTypeContextThe parse context for the return type.Fields inherited from class org.daiitech.naftah.builtin.lang.Declaration
depth -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDeclaredFunction(int depth, NaftahParser.FunctionDeclarationContext originalContext, String implementationName) Creates aDeclaredFunctionfrom its parsed function declaration. -
Method Summary
Modifier and TypeMethodDescriptiongetBody()Returns the context for the function body block.Returns the internal implementation name of this function.getName()Returns the name of the function.Returns the original function declaration context.Returns the list of declared parameters.Returns the context for the parameter declaration list.Returns the resolved return type of the function.Returns the context for the return type.booleanisAsync()Returns whether this function is asynchronous.static <T extends org.antlr.v4.runtime.ParserRuleContext>
DeclaredFunction<T>of(int depth, NaftahParser.FunctionDeclarationContext originalContext, String implementationName) Creates aDeclaredFunctionfrom a parsed function declaration.voidsetParameters(List<DeclaredParameter> parameters) Sets the list of declared parameters.voidsetReturnType(JavaType returnType) Sets the resolved return type of the function.toString()Returns a string representation of the declared function in Arabic.Methods inherited from class org.daiitech.naftah.builtin.lang.Declaration
getDepth
-
Field Details
-
originalContext
The original ANTLR parse context for the function declaration. -
name
The name of the function. -
implementationName
The name of the implementation. -
async
private final boolean asyncIndicates whether the function is declared as asynchronous. -
parametersContext
The parse context for the parameter declaration list. -
body
The parse context for the function body block. -
returnTypeContext
The parse context for the return type. -
parameters
The list of parameters declared for the function. -
returnType
The resolved return type of the function.
-
-
Constructor Details
-
DeclaredFunction
private DeclaredFunction(int depth, NaftahParser.FunctionDeclarationContext originalContext, String implementationName) Creates aDeclaredFunctionfrom its parsed function declaration.This constructor initializes the semantic representation of a function using information extracted from the ANTLR parse tree. It captures the function's name, async modifier, parameters, return type, and body, while retaining the original parse context for later analysis or code generation.
This constructor is private and is intended to be used by factory methods within this class.
- Parameters:
depth- The lexical scope depth at which the function is declared.originalContext- The ANTLR parse-tree context representing the function declaration.implementationName- The internal or generated name used to identify this function during compilation or code generation.
-
-
Method Details
-
of
public static <T extends org.antlr.v4.runtime.ParserRuleContext> DeclaredFunction<T> of(int depth, NaftahParser.FunctionDeclarationContext originalContext, String implementationName) Creates aDeclaredFunctionfrom a parsed function declaration.This factory method constructs a semantic representation of a function using the provided ANTLR parse-tree context. It delegates initialization to the private constructor and associates the function with its lexical scope depth and internal implementation name.
- Parameters:
depth- The lexical scope depth at which the function is declared.originalContext- The ANTLR parse-tree context representing the function declaration.implementationName- The internal or generated name used to identify this function during compilation or code generation.- Returns:
- A newly created
DeclaredFunctioninstance.
-
getOriginalContext
Returns the original function declaration context.- Returns:
- the function declaration context
-
getName
Returns the name of the function.- Returns:
- the function name
-
getImplementationName
Returns the internal implementation name of this function.This name is used internally (for example, during name mangling, linking, or code generation) and may differ from the function’s declared source-level name.
- Returns:
- The internal implementation name associated with this function.
-
isAsync
public boolean isAsync()Returns whether this function is asynchronous.An asynchronous function executes in its own task and must be awaited if its result is required before proceeding.
- Returns:
trueif the function is asynchronous;falseotherwise
-
getParametersContext
Returns the context for the parameter declaration list.- Returns:
- the parameters context
-
getParameters
Returns the list of declared parameters.- Returns:
- the list of parameters
-
setParameters
Sets the list of declared parameters.- Parameters:
parameters- the parameters to set
-
getBody
Returns the context for the function body block.- Returns:
- the function body context
-
getReturnTypeContext
Returns the context for the return type.- Returns:
- the return type context
-
getReturnType
Returns the resolved return type of the function.- Returns:
- the return type
-
setReturnType
Sets the resolved return type of the function.- Parameters:
returnType- the return type to set
-
toString
Returns a string representation of the declared function in Arabic.
-