|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.stringtemplate.v4.Interpreter
public class Interpreter
This class knows how to execute template bytecodes relative to a particular STGroup. To execute the byte codes, we need an output stream and a reference to an ST an instance. That instance's impl field points at a CompiledST, which contains all of the byte codes and other information relevant to execution. This interpreter is a stack-based bytecode interpreter. All operands go onto an operand stack. If the group that we're executing relative to has debug set, we track interpreter events. For now, I am only tracking instance creation events. These are used by STViz to pair up output chunks with the template expressions that generate them. We create a new interpreter for each ST.render(), DebugST.inspect, or DebugST.getEvents() invocation.
| Nested Class Summary | |
|---|---|
static interface |
Interpreter.OpcodeImpl
|
static class |
Interpreter.Option
|
| Field Summary | |
|---|---|
static int[] |
count
|
static int |
DEFAULT_OPERAND_STACK_SIZE
|
protected java.util.List<InterpEvent> |
events
Track everything happening in interp if debug across all templates |
protected java.util.List<java.lang.String> |
executeTrace
If debug mode, track trace here |
static java.util.Set<java.lang.String> |
predefinedAnonSubtemplateAttributes
|
static boolean |
trace
Dump bytecode instructions as we execute them? |
| Constructor Summary | |
|---|---|
Interpreter(STGroup group)
|
|
Interpreter(STGroup group,
ErrorManager errMgr)
|
|
Interpreter(STGroup group,
java.util.Locale locale)
|
|
Interpreter(STGroup group,
java.util.Locale locale,
ErrorManager errMgr)
|
|
| Method Summary | |
|---|---|
protected int |
_exec(STWriter out,
ST self)
|
protected void |
addToList(java.util.List<java.lang.Object> list,
java.lang.Object o)
|
static java.lang.Object |
convertAnythingIteratableToIterator(java.lang.Object o)
|
static java.util.Iterator |
convertAnythingToIterator(java.lang.Object o)
|
static void |
dumpOpcodeFreq()
|
int |
exec(STWriter out,
ST self)
Execute template self and return how many characters it wrote to out |
java.lang.Object |
first(java.lang.Object v)
Return the first attribute if multiple valued or the attribute itself if single-valued. |
java.util.List<InterpEvent> |
getEvents()
|
java.util.List<InterpEvent> |
getEvents(ST st)
|
java.util.List<java.lang.String> |
getExecutionTrace()
|
protected int |
getExprStartChar(ST self)
|
protected int |
getExprStopChar(ST self)
|
protected java.lang.Object |
getObjectProperty(STWriter out,
ST self,
java.lang.Object o,
java.lang.Object property)
|
static int |
getShort(byte[] memory,
int index)
|
protected void |
indent(STWriter out,
ST self,
int strIndex)
|
java.lang.Object |
last(java.lang.Object v)
Return the last attribute if multiple valued or the attribute itself if single-valued. |
java.lang.Object |
length(java.lang.Object v)
Return the length of a mult-valued attribute or 1 if it is a single attribute. |
protected void |
map(ST self,
java.lang.Object attr,
ST st)
|
protected void |
printForTrace(java.lang.StringBuilder tr,
java.lang.Object o)
|
java.lang.Object |
rest(java.lang.Object v)
Return everything but the first attribute if multiple valued or null if single-valued. |
java.lang.Object |
reverse(java.lang.Object v)
Return a list with the same elements as v but in reverse order. |
protected java.util.List<ST> |
rot_map_iterator(ST self,
java.util.Iterator attr,
java.util.List<ST> prototypes)
|
protected void |
rot_map(ST self,
java.lang.Object attr,
java.util.List<ST> prototypes)
|
void |
setDefaultArguments(STWriter out,
ST invokedST)
Set any default argument values that were not set by the invoking template or by setAttribute directly. |
protected void |
setFirstArgument(ST self,
ST st,
java.lang.Object attr)
|
java.lang.Object |
strip(java.lang.Object v)
Return a new list w/o null values. |
protected boolean |
testAttributeTrue(java.lang.Object a)
|
protected java.lang.String |
toString(STWriter out,
ST self,
java.lang.Object value)
|
protected void |
trace(ST self,
int ip)
|
java.lang.Object |
trunc(java.lang.Object v)
Return all but the last element. |
protected int |
writeIterator(STWriter out,
ST self,
java.lang.Object o,
java.lang.String[] options)
|
protected int |
writeObject(STWriter out,
ST self,
java.lang.Object o,
java.lang.String[] options)
Generic method to emit text for an object. |
protected int |
writeObjectNoOptions(STWriter out,
ST self,
java.lang.Object o)
Write out an expression result that doesn't use expression options. |
protected int |
writeObjectWithOptions(STWriter out,
ST self,
java.lang.Object o,
java.lang.Object[] options)
Write out an expression result that uses expression options. |
protected int |
writePOJO(STWriter out,
java.lang.Object o,
java.lang.String[] options)
|
protected ST.AttributeList |
zip_map(ST self,
java.util.List<java.lang.Object> exprs,
ST prototype)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_OPERAND_STACK_SIZE
public static final java.util.Set<java.lang.String> predefinedAnonSubtemplateAttributes
public static boolean trace
protected java.util.List<InterpEvent> events
protected java.util.List<java.lang.String> executeTrace
public static int[] count
| Constructor Detail |
|---|
public Interpreter(STGroup group)
public Interpreter(STGroup group,
java.util.Locale locale)
public Interpreter(STGroup group,
ErrorManager errMgr)
public Interpreter(STGroup group,
java.util.Locale locale,
ErrorManager errMgr)
| Method Detail |
|---|
public static void dumpOpcodeFreq()
public int exec(STWriter out,
ST self)
protected int _exec(STWriter out,
ST self)
protected void indent(STWriter out,
ST self,
int strIndex)
protected int writeObjectNoOptions(STWriter out,
ST self,
java.lang.Object o)
protected int writeObjectWithOptions(STWriter out,
ST self,
java.lang.Object o,
java.lang.Object[] options)
protected int writeObject(STWriter out,
ST self,
java.lang.Object o,
java.lang.String[] options)
protected int writeIterator(STWriter out,
ST self,
java.lang.Object o,
java.lang.String[] options)
throws java.io.IOException
java.io.IOException
protected int writePOJO(STWriter out,
java.lang.Object o,
java.lang.String[] options)
throws java.io.IOException
java.io.IOExceptionprotected int getExprStartChar(ST self)
protected int getExprStopChar(ST self)
protected void map(ST self,
java.lang.Object attr,
ST st)
protected void rot_map(ST self,
java.lang.Object attr,
java.util.List<ST> prototypes)
protected java.util.List<ST> rot_map_iterator(ST self,
java.util.Iterator attr,
java.util.List<ST> prototypes)
protected ST.AttributeList zip_map(ST self,
java.util.List<java.lang.Object> exprs,
ST prototype)
protected void setFirstArgument(ST self,
ST st,
java.lang.Object attr)
protected void addToList(java.util.List<java.lang.Object> list,
java.lang.Object o)
public java.lang.Object first(java.lang.Object v)
public java.lang.Object last(java.lang.Object v)
public java.lang.Object rest(java.lang.Object v)
public java.lang.Object trunc(java.lang.Object v)
public java.lang.Object strip(java.lang.Object v)
public java.lang.Object reverse(java.lang.Object v)
public java.lang.Object length(java.lang.Object v)
protected java.lang.String toString(STWriter out,
ST self,
java.lang.Object value)
public static java.lang.Object convertAnythingIteratableToIterator(java.lang.Object o)
public static java.util.Iterator convertAnythingToIterator(java.lang.Object o)
protected boolean testAttributeTrue(java.lang.Object a)
protected java.lang.Object getObjectProperty(STWriter out,
ST self,
java.lang.Object o,
java.lang.Object property)
public void setDefaultArguments(STWriter out,
ST invokedST)
protected void trace(ST self,
int ip)
protected void printForTrace(java.lang.StringBuilder tr,
java.lang.Object o)
public java.util.List<InterpEvent> getEvents()
public java.util.List<InterpEvent> getEvents(ST st)
public java.util.List<java.lang.String> getExecutionTrace()
public static int getShort(byte[] memory,
int index)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||