org.antlr.runtime.debug.Profiler Class Reference

Inheritance diagram for org.antlr.runtime.debug.Profiler:

Inheritance graph
[legend]
Collaboration diagram for org.antlr.runtime.debug.Profiler:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Profiler ()
 Profiler (DebugParser parser)
void enterRule (String grammarFileName, String ruleName)
void exitRule (String grammarFileName, String ruleName)
void examineRuleMemoization (IntStream input, int ruleIndex, int stopIndex, String ruleName)
void memoize (IntStream input, int ruleIndex, int ruleStartIndex, String ruleName)
void location (int line, int pos)
void enterDecision (int decisionNumber, boolean couldBacktrack)
void exitDecision (int decisionNumber)
void consumeToken (Token token)
boolean inDecision ()
void consumeHiddenToken (Token token)
void LT (int i, Token t)
void beginBacktrack (int level)
void endBacktrack (int level, boolean successful)
void mark (int i)
void rewind (int i)
void rewind ()
void recognitionException (RecognitionException e)
void semanticPredicate (boolean result, String predicate)
void terminate ()
void setParser (DebugParser parser)
String toNotifyString ()
String toString ()
ProfileStats getReport ()
DoubleKeyMap getDecisionStats ()
List getDecisionEvents ()
String getDecisionStatsDump ()
int getNumberOfHiddenTokens (int i, int j)

Static Public Member Functions

static String toString (ProfileStats stats)

Public Attributes

DebugParser parser = null

Static Public Attributes

static final String DATA_SEP = "\t"
static final String newline = System.getProperty("line.separator")
static final String Version = "3"
static final String RUNTIME_STATS_FILENAME = "runtime.stats"

Protected Member Functions

DecisionEvent currentDecision ()
int[] trim (int[] X, int n)
int[] toArray (List a)
String locationDescription ()
String locationDescription (String file, String rule, int line, int pos)

Protected Attributes

int ruleLevel = 0
Token lastRealTokenTouchedInDecision
Set< String > uniqueRules = new HashSet<String>()
Stack< String > currentGrammarFileName = new Stack()
Stack< String > currentRuleName = new Stack()
Stack< Integer > currentLine = new Stack()
Stack< Integer > currentPos = new Stack()
DoubleKeyMap< String, Integer,
DecisionDescriptor
decisions
List< DecisionEventdecisionEvents = new ArrayList<DecisionEvent>()
Stack< DecisionEventdecisionStack = new Stack<DecisionEvent>()
int backtrackDepth

Package Attributes

ProfileStats stats = new ProfileStats()

Static Package Attributes

static boolean dump = false

Classes

class  DecisionDescriptor
class  DecisionEvent
class  ProfileStats


Detailed Description

Using the debug event interface, track what is happening in the parser and record statistics about the runtime.

Definition at line 38 of file Profiler.java.


Constructor & Destructor Documentation

org.antlr.runtime.debug.Profiler.Profiler (  ) 

Definition at line 148 of file Profiler.java.

org.antlr.runtime.debug.Profiler.Profiler ( DebugParser  parser  ) 

Definition at line 151 of file Profiler.java.


Member Function Documentation

void org.antlr.runtime.debug.Profiler.enterRule ( String  grammarFileName,
String  ruleName 
)

The parser has just entered a rule. No decision has been made about which alt is predicted. This is fired AFTER init actions have been executed. Attributes are defined and available etc... The grammarFileName allows composite grammars to jump around among multiple grammar files.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 155 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.exitRule ( String  grammarFileName,
String  ruleName 
)

This is the last thing executed before leaving a rule. It is executed even if an exception is thrown. This is triggered after error reporting and recovery have occurred (unless the exception is not caught in this rule). This implies an "exitAlt" event. The grammarFileName allows composite grammars to jump around among multiple grammar files.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 165 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.examineRuleMemoization ( IntStream  input,
int  ruleIndex,
int  stopIndex,
String  ruleName 
)

Track memoization; this is not part of standard debug interface but is triggered by profiling. Code gen inserts an override for this method in the recognizer, which triggers this method. Called from alreadyParsedRule().

Definition at line 176 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.memoize ( IntStream  input,
int  ruleIndex,
int  ruleStartIndex,
String  ruleName 
)

Warning: doesn't track success/failure, just unique recording event

Definition at line 197 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.location ( int  line,
int  pos 
)

To watch a parser move through the grammar, the parser needs to inform the debugger what line/charPos it is passing in the grammar. For now, this does not know how to switch from one grammar to the other and back for island grammars etc...

This should also allow breakpoints because the debugger can stop the parser whenever it hits this line/pos.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 208 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.enterDecision ( int  decisionNumber,
boolean  couldBacktrack 
)

Every decision, fixed k or arbitrary, has an enter/exit event so that a GUI can easily track what LT/consume events are associated with prediction. You will see a single enter/exit subrule but multiple enter/exit decision events, one for each loop iteration.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 213 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.exitDecision ( int  decisionNumber  ) 

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 243 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.consumeToken ( Token  t  ) 

An input token was consumed; matched by any kind of element. Trigger after the token was matched by things like match(), matchAny().

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 258 of file Profiler.java.

boolean org.antlr.runtime.debug.Profiler.inDecision (  ) 

The parser is in a decision if the decision depth > 0. This works for backtracking also, which can have nested decisions.

Definition at line 282 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.consumeHiddenToken ( Token  t  ) 

An off-channel input token was consumed. Trigger after the token was matched by things like match(), matchAny(). (unless of course the hidden token is first stuff in the input stream).

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 286 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.LT ( int  i,
Token  t 
)

Track refs to lookahead if in a fixed/nonfixed decision.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 293 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.beginBacktrack ( int  level  ) 

Track backtracking decisions. You'll see a fixed or cyclic decision and then a backtrack.

enter rule ... enter decision LA and possibly consumes (for cyclic DFAs) begin backtrack level mark m rewind m end backtrack level, success exit decision ... exit rule

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 338 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.endBacktrack ( int  level,
boolean  successful 
)

Successful or not, track how much lookahead synpreds use

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 350 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.mark ( int  marker  ) 

The parser is going to look arbitrarily ahead; mark this location, the token stream's marker is sent in case you need it.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 356 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.rewind ( int  marker  ) 

After an arbitrairly long lookahead as with a cyclic DFA (or with any backtrack), this informs the debugger that stream should be rewound to the position associated with marker.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 361 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.rewind (  ) 

Rewind to the input position of the last marker. Used currently only after a cyclic DFA and just before starting a sem/syn predicate to get the input position back to the start of the decision. Do not "pop" the marker off the state. mark(i) and rewind(i) should balance still.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 366 of file Profiler.java.

DecisionEvent org.antlr.runtime.debug.Profiler.currentDecision (  )  [protected]

Definition at line 372 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.recognitionException ( RecognitionException  e  ) 

A recognition exception occurred such as NoViableAltException. I made this a generic event so that I can alter the exception hierachy later without having to alter all the debug objects.

Upon error, the stack of enter rule/subrule must be properly unwound. If no viable alt occurs it is within an enter/exit decision, which also must be rewound. Even the rewind for each mark must be unwount. In the Java target this is pretty easy using try/finally, if a bit ugly in the generated code. The rewind is generated in DFA.predict() actually so no code needs to be generated for that. For languages w/o this "finally" feature (C++?), the target implementor will have to build an event stack or something.

Across a socket for remote debugging, only the RecognitionException data fields are transmitted. The token object or whatever that caused the problem was the last object referenced by LT. The immediately preceding LT event should hold the unexpected Token or char.

Here is a sample event trace for grammar:

b : C ({;}A|B) // {;} is there to prevent A|B becoming a set | D ;

The sequence for this rule (with no viable alt in the subrule) for input 'c c' (there are 3 tokens) is:

commence LT(1) enterRule b location 7 1 enter decision 3 LT(1) exit decision 3 enterAlt1 location 7 5 LT(1) consumeToken [c/<4>,1:0] location 7 7 enterSubRule 2 enter decision 2 LT(1) LT(1) recognitionException NoViableAltException 2 1 2 exit decision 2 exitSubRule 2 beginResync LT(1) consumeToken [c/<4>,1:1] LT(1) endResync LT(-1) exitRule b terminate

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 376 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.semanticPredicate ( boolean  result,
String  predicate 
)

A semantic predicate was evaluate with this result and action text

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 380 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.terminate (  ) 

Parsing is over; successfully or not. Mostly useful for telling remote debugging listeners that it's time to quit. When the rule invocation level goes to zero at the end of a rule, we are done parsing.

Reimplemented from org.antlr.runtime.debug.BlankDebugEventListener.

Definition at line 391 of file Profiler.java.

void org.antlr.runtime.debug.Profiler.setParser ( DebugParser  parser  ) 

Definition at line 433 of file Profiler.java.

String org.antlr.runtime.debug.Profiler.toNotifyString (  ) 

Definition at line 439 of file Profiler.java.

String org.antlr.runtime.debug.Profiler.toString (  ) 

Definition at line 501 of file Profiler.java.

ProfileStats org.antlr.runtime.debug.Profiler.getReport (  ) 

Definition at line 505 of file Profiler.java.

DoubleKeyMap org.antlr.runtime.debug.Profiler.getDecisionStats (  ) 

Definition at line 521 of file Profiler.java.

List org.antlr.runtime.debug.Profiler.getDecisionEvents (  ) 

Definition at line 525 of file Profiler.java.

static String org.antlr.runtime.debug.Profiler.toString ( ProfileStats  stats  )  [static]

Definition at line 529 of file Profiler.java.

String org.antlr.runtime.debug.Profiler.getDecisionStatsDump (  ) 

Definition at line 652 of file Profiler.java.

int [] org.antlr.runtime.debug.Profiler.trim ( int[]  X,
int  n 
) [protected]

Definition at line 692 of file Profiler.java.

int [] org.antlr.runtime.debug.Profiler.toArray ( List  a  )  [protected]

Definition at line 701 of file Profiler.java.

int org.antlr.runtime.debug.Profiler.getNumberOfHiddenTokens ( int  i,
int  j 
)

Get num hidden tokens between i..j inclusive

Definition at line 711 of file Profiler.java.

String org.antlr.runtime.debug.Profiler.locationDescription (  )  [protected]

Definition at line 723 of file Profiler.java.

String org.antlr.runtime.debug.Profiler.locationDescription ( String  file,
String  rule,
int  line,
int  pos 
) [protected]

Definition at line 731 of file Profiler.java.


Member Data Documentation

final String org.antlr.runtime.debug.Profiler.DATA_SEP = "\t" [static]

Definition at line 39 of file Profiler.java.

final String org.antlr.runtime.debug.Profiler.newline = System.getProperty("line.separator") [static]

Definition at line 40 of file Profiler.java.

boolean org.antlr.runtime.debug.Profiler.dump = false [static, package]

Definition at line 42 of file Profiler.java.

final String org.antlr.runtime.debug.Profiler.Version = "3" [static]

Because I may change the stats, I need to track that for later computations to be consistent.

Definition at line 116 of file Profiler.java.

final String org.antlr.runtime.debug.Profiler.RUNTIME_STATS_FILENAME = "runtime.stats" [static]

Definition at line 117 of file Profiler.java.

Ack, should not store parser; can't do remote stuff. Well, we pass input stream around too so I guess it's ok.

Definition at line 122 of file Profiler.java.

Definition at line 126 of file Profiler.java.

Definition at line 128 of file Profiler.java.

Set<String> org.antlr.runtime.debug.Profiler.uniqueRules = new HashSet<String>() [protected]

Definition at line 129 of file Profiler.java.

Stack<String> org.antlr.runtime.debug.Profiler.currentGrammarFileName = new Stack() [protected]

Definition at line 130 of file Profiler.java.

Stack<String> org.antlr.runtime.debug.Profiler.currentRuleName = new Stack() [protected]

Definition at line 131 of file Profiler.java.

Stack<Integer> org.antlr.runtime.debug.Profiler.currentLine = new Stack() [protected]

Definition at line 132 of file Profiler.java.

Stack<Integer> org.antlr.runtime.debug.Profiler.currentPos = new Stack() [protected]

Definition at line 133 of file Profiler.java.

DoubleKeyMap<String,Integer, DecisionDescriptor> org.antlr.runtime.debug.Profiler.decisions [protected]

Initial value:

                new DoubleKeyMap<String,Integer, DecisionDescriptor>()

Definition at line 137 of file Profiler.java.

Definition at line 141 of file Profiler.java.

Definition at line 142 of file Profiler.java.

Definition at line 144 of file Profiler.java.

Definition at line 146 of file Profiler.java.


The documentation for this class was generated from the following file:

Generated on Tue Jul 19 11:42:08 2011 for ANTLR API by  doxygen 1.5.5