Package org.qdl_lang.evaluate
Class MetaEvaluator
- java.lang.Object
-
- org.qdl_lang.evaluate.AbstractEvaluator
-
- org.qdl_lang.evaluate.MetaEvaluator
-
- All Implemented Interfaces:
Serializable
,EvaluatorInterface
public class MetaEvaluator extends AbstractEvaluator
This is charged with managing the build-in functions as well as any that the user defines.Created by Jeff Gaynor
on 1/16/20 at 6:14 AM- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.qdl_lang.evaluate.AbstractEvaluator
AbstractEvaluator.CommonKeyIterator, AbstractEvaluator.fPointer, AbstractEvaluator.fpResult
-
-
Field Summary
Fields Modifier and Type Field Description static int
META_BASE_VALUE
protected static List<String>
systemNamespaces
-
Fields inherited from class org.qdl_lang.evaluate.AbstractEvaluator
bigArgList, bigArgList0, FILE_OP_AUTO, FILE_OP_BINARY, FILE_OP_INPUT_STREAM, FILE_OP_TEXT_INI, FILE_OP_TEXT_STEM, FILE_OP_TEXT_STRING, FILE_OP_TEXT_WITHOUT_LIST_INI, fNames, MAX_ARG_COUNT
-
Fields inherited from interface org.qdl_lang.evaluate.EvaluatorInterface
UNKNOWN_VALUE
-
-
Constructor Summary
Constructors Constructor Description MetaEvaluator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static void
addE(int index, AbstractEvaluator evaluator)
Add evaluator at a given index in the listprotected static void
addE(AbstractEvaluator evaluator)
Add evaluator to the end of the list.void
addEvaluator(int index, AbstractEvaluator evaluator)
void
addEvaluator(AbstractEvaluator evaluator)
boolean
dispatch(Polyad polyad, State state)
Does the actual evaluation of thePolyad
.boolean
evaluate(String alias, Polyad polyad, State state)
boolean
evaluate(Polyad polyad, State state)
Decides if aPolyad
is evaluated by this evaluator and if not, returns false, if so, it evaluates it and returns true.boolean
evaluateNEW(Polyad polyad, State state)
Proposed method to allow for overriding base system functions.boolean
evaluateOLD(Polyad polyad, State state)
int[]
getArgCount(String name)
Given the name of a built in function, find the number of possible arguments it can take.FunctionEvaluator
getFunctionEvaluator()
String[]
getFunctionNames()
static MetaEvaluator
getInstance()
Factory method.String
getNamespace()
static List<String>
getSystemNamespaces()
int
getType(String name)
boolean
isBuiltIin(String moduleName, String functionName)
Check that a FQ function exists.static boolean
isSystemNS(String name)
TreeSet<String>
listFunctions(boolean listFQ)
void
setFunctionEvaluator(FunctionEvaluator functionEvaluator)
static void
setMetaEvaluator(MetaEvaluator metaEvaluator)
-
Methods inherited from class org.qdl_lang.evaluate.AbstractEvaluator
areAllBigDecimals, areAllBoolean, areAllLongs, areAllNumbers, areAllSets, areAllStems, areAllStrings, areAnyBigDecimals, areNoneStems, bdEquals, checkNull, checkNull, convertArgsToStem, finishExpr, getBigArgList, getBigArgList0, getCommonKeys, getFQFunctionNames, getFunctionReferenceNode, getFunctionReferenceNode, getOperator, getOrCreateStem, isBigDecimal, isBoolean, isBuiltInFunction, isFunctionRef, isLong, isNumber, isScalar, isSet, isStem, isStemList, isString, process1, process2, process2, process3, processSet1, processSet2, processSet2, processStem1, processStem2, processStem3, resolveResourceToFile, tempFname, toBD, toConstants, toStem
-
-
-
-
Field Detail
-
META_BASE_VALUE
public static final int META_BASE_VALUE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static MetaEvaluator getInstance()
Factory method. You should not override this class to add more of your own evaluators. Just get the instance andaddEvaluator(int, AbstractEvaluator)
to it at index 0 (or it will get missed -- last index is for functions and throws and exception if no function found. It will snoop through your evaluator too. If you are writing your own evaluator, your type numbers should be negative.- Returns:
-
addE
protected static void addE(int index, AbstractEvaluator evaluator)
Add evaluator at a given index in the list- Parameters:
index
-evaluator
-
-
addE
protected static void addE(AbstractEvaluator evaluator)
Add evaluator to the end of the list.- Parameters:
evaluator
-
-
getArgCount
public int[] getArgCount(String name)
Given the name of a built in function, find the number of possible arguments it can take. This is needed for resolving function references.- Parameters:
name
-- Returns:
-
getFunctionEvaluator
public FunctionEvaluator getFunctionEvaluator()
-
setFunctionEvaluator
public void setFunctionEvaluator(FunctionEvaluator functionEvaluator)
-
isSystemNS
public static boolean isSystemNS(String name)
-
getNamespace
public String getNamespace()
-
setMetaEvaluator
public static void setMetaEvaluator(MetaEvaluator metaEvaluator)
-
addEvaluator
public void addEvaluator(AbstractEvaluator evaluator)
-
addEvaluator
public void addEvaluator(int index, AbstractEvaluator evaluator)
-
getType
public int getType(String name)
-
evaluate
public boolean evaluate(Polyad polyad, State state)
Description copied from class:AbstractEvaluator
Decides if aPolyad
is evaluated by this evaluator and if not, returns false, if so, it evaluates it and returns true. This function actually just dispatches it toAbstractEvaluator.dispatch(Polyad, State)
where the work is done and manages putting better trace information in if there is a failure.- Overrides:
evaluate
in classAbstractEvaluator
- Returns:
-
dispatch
public boolean dispatch(Polyad polyad, State state)
Description copied from class:AbstractEvaluator
Does the actual evaluation of thePolyad
.- Specified by:
dispatch
in classAbstractEvaluator
- Returns:
-
evaluateNEW
public boolean evaluateNEW(Polyad polyad, State state)
Proposed method to allow for overriding base system functions. Maybe. Still have to decide if this is really a great idea. This can actually the evaluteOLD completely BUT because this requires exception handling to decide if a function is user defined, the performance is slower by a good 15%.To do this right will require that the function Evaluator handle missing functions differently. Probably a fairly substantial rewrite for not much of a clear purpose at this point (4/27/2022)
- Parameters:
polyad
-state
-- Returns:
-
isBuiltIin
public boolean isBuiltIin(String moduleName, String functionName)
Check that a FQ function exists. This is used withjisSystemNS(String)
to check if the namespace exists in the first place.- Parameters:
moduleName
-functionName
-- Returns:
-
evaluate
public boolean evaluate(String alias, Polyad polyad, State state)
- Overrides:
evaluate
in classAbstractEvaluator
-
listFunctions
public TreeSet<String> listFunctions(boolean listFQ)
- Specified by:
listFunctions
in interfaceEvaluatorInterface
- Overrides:
listFunctions
in classAbstractEvaluator
-
getFunctionNames
public String[] getFunctionNames()
- Specified by:
getFunctionNames
in classAbstractEvaluator
-
-