Class AbstractProtelisAST<T>
- java.lang.Object
-
- org.protelis.lang.interpreter.impl.AbstractProtelisAST<T>
-
- Type Parameters:
T- annotation type
- All Implemented Interfaces:
java.io.Serializable,ProtelisAST<T>,WithBytecode
- Direct Known Subclasses:
AbstractPersistedTree,AlignedMap,All,AssignmentOp,BinaryOp,ConditionalSideEffect,Constant,CreateTuple,Env,FunctionCall,GenericHoodCall,HoodCall,If,Invoke,JvmConstant,NBRCall,Self,TernaryOp,UnaryOp,Variable
public abstract class AbstractProtelisAST<T> extends java.lang.Object implements ProtelisAST<T>, WithBytecode
Basic implementation of anProtelisAST.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractProtelisAST(Metadata metadata, java.util.List<ProtelisAST<?>> branch)protectedAbstractProtelisAST(Metadata metadata, ProtelisAST<?>... branch)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringbranchesToString()protected java.lang.StringbranchesToString(java.lang.CharSequence separator, java.lang.CharSequence prefix, java.lang.CharSequence postfix)Returns aStringrepresenting the branches of this tree with the specified format.Teval(ExecutionContext context)Evaluates the program using the passedExecutionContext.protected abstract Tevaluate(ExecutionContext context)Evaluates this AST node.protected voidforEach(java.util.function.Consumer<? super ProtelisAST<?>> action)Facility to run lambdas across all the branches.protected voidforEachWithIndex(java.util.function.BiConsumer<java.lang.Integer,? super ProtelisAST<?>> action)Facility to run lambdas across all the branches.ProtelisAST<?>getBranch(int i)java.util.List<ProtelisAST<?>>getBranches()protected intgetBranchesNumber()MetadatagetMetadata()java.lang.StringgetName()protected booleanisNullable()protected static java.lang.StringstringFor(ProtelisAST<?> tree)A String representation of anProtelisAST.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.protelis.lang.interpreter.util.WithBytecode
getBytecode
-
-
-
-
Constructor Detail
-
AbstractProtelisAST
protected AbstractProtelisAST(Metadata metadata, ProtelisAST<?>... branch)
- Parameters:
metadata- AMetadataobject containing information about the code that generated this AST node.branch- the branches for this tree
-
AbstractProtelisAST
protected AbstractProtelisAST(Metadata metadata, java.util.List<ProtelisAST<?>> branch)
- Parameters:
metadata- AMetadataobject containing information about the code that generated this AST node.branch- the branches for this tree
-
-
Method Detail
-
branchesToString
protected final java.lang.String branchesToString()
- Returns:
- a
Stringrepresenting the branches of this tree, in the format (b1, b2, ..., bn).
-
branchesToString
protected final java.lang.String branchesToString(java.lang.CharSequence separator, java.lang.CharSequence prefix, java.lang.CharSequence postfix)Returns aStringrepresenting the branches of this tree with the specified format.- Parameters:
separator- the separatorCharSequenceprefix- the prefixpostfix- the postfix- Returns:
- a
Stringrepresenting the branches of this tree with the specified format.
-
eval
public final T eval(ExecutionContext context)
Description copied from interface:ProtelisASTEvaluates the program using the passedExecutionContext.- Specified by:
evalin interfaceProtelisAST<T>- Parameters:
context- the execution context- Returns:
- the AST evaluation
-
evaluate
protected abstract T evaluate(ExecutionContext context)
Evaluates this AST node. This method can throw any exception,AbstractProtelisASTtakes care of storing the necessary metadata.- Parameters:
context- the execution context- Returns:
- the result of the evaluation
-
forEach
protected final void forEach(java.util.function.Consumer<? super ProtelisAST<?>> action)
Facility to run lambdas across all the branches.- Parameters:
action- the Consumer to execute
-
isNullable
protected boolean isNullable()
- Returns:
- true if this node can get annotated with null values - namely, if it is an interaction with Java
-
forEachWithIndex
protected final void forEachWithIndex(java.util.function.BiConsumer<java.lang.Integer,? super ProtelisAST<?>> action)
Facility to run lambdas across all the branches.- Parameters:
action- the Consumer to execute
-
getBranch
public final ProtelisAST<?> getBranch(int i)
- Specified by:
getBranchin interfaceProtelisAST<T>- Parameters:
i- the index- Returns:
- the i-th branch of the evaluation tree
-
getBranches
public final java.util.List<ProtelisAST<?>> getBranches()
- Specified by:
getBranchesin interfaceProtelisAST<T>- Returns:
- a view of the branches of the tree
-
getBranchesNumber
protected final int getBranchesNumber()
- Returns:
- the number of branches
-
getMetadata
public final Metadata getMetadata()
- Specified by:
getMetadatain interfaceProtelisAST<T>- Returns:
- A
Metadataobject containing information about the code that generated this AST node.
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceProtelisAST<T>- Returns:
- The name of the operation
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
stringFor
protected static final java.lang.String stringFor(ProtelisAST<?> tree)
A String representation of anProtelisAST. I- Parameters:
tree- the tree to stringify- Returns:
- if the tree it is not erased (i.e., contains a value), returns a
stringified version of such value. Otherwise, returns the branch name
via
getName()
-
-