Computer Laboratory

tesla::internal::NFAParser Class Reference

Detailed Description

Definition at line 78 of file Automaton.cpp.

Public Member Functions

 NFAParser (const AutomatonDescription &A, const Usage *Use, const AutomataMap *Descriptions=NULL)
 
NFAParserAllowSubAutomata (bool Allow)
 
void Parse (OwningPtr< NFA > &Out, unsigned int id)
 Parse the NFA, assign it ID id and put it in Out. More...
 

Constructor & Destructor Documentation

tesla::internal::NFAParser::NFAParser ( const AutomatonDescription A,
const Usage Use,
const AutomataMap Descriptions = NULL 
)
inline

Definition at line 80 of file Automaton.cpp.

83  : Automaton(A), Use(Use), Descriptions(Descriptions),
84  SubAutomataAllowed(true)
85  {
86  }

Member Function Documentation

NFAParser & tesla::internal::NFAParser::AllowSubAutomata ( bool  Allow)

Definition at line 260 of file Automaton.cpp.

Referenced by tesla::NFA::Link().

260  {
261  assert(Allow || Descriptions != NULL && "need a source of subautomata");
262  SubAutomataAllowed = Allow;
263 
264  return *this;
265 }

+ Here is the caller graph for this function:

void tesla::internal::NFAParser::Parse ( OwningPtr< NFA > &  Out,
unsigned int  id 
)

Parse the NFA, assign it ID id and put it in Out.

Parameters
[out]Outwhere to store the NFA
[in]idan integer ID for the resulting NFA

Definition at line 267 of file Automaton.cpp.

References tesla::Usage::beginning, tesla::State::Builder::Build(), tesla::Transition::Copy(), tesla::debugs(), tesla::Usage::end, tesla::Transition::FieldAssign, tesla::Transition::Fn, tesla::Transition::GroupClasses(), tesla::State::NewBuilder(), tesla::Transition::Now, tesla::Transition::Null, tesla::panic(), tesla::State::Builder::SetRefCount(), tesla::State::Builder::SetStartState(), tesla::ShortName(), and tesla::Transition::SubAutomaton.

Referenced by tesla::NFA::Link(), and tesla::NFA::Parse().

267  {
268  debugs("tesla.automata.parsing")
269  << "Parsing '" << ShortName(Automaton.identifier()) << "'...\n";
270 
271  size_t VariableRefs = 0;
272  for (auto A : Automaton.argument())
273  if (A.type() == Argument::Variable)
274  VariableRefs++;
275 
276  Start = State::NewBuilder(States)
277  .SetStartState()
278  .SetRefCount(VariableRefs)
279  .Build();
280 
281  // Parse the automaton entry point, if provided...
282  if (Use && Use->has_beginning()) {
283  Start = Parse(Use->beginning(), *Start, true);
284  if (!Start) {
285  string Str;
286  TextFormat::PrintToString(Use->beginning(), &Str);
287  panic("failed to parse automaton 'beginning' event: " + Str);
288  }
289  }
290 
291  // Parse the main automaton itself.
292  State *End = Parse(Automaton.expression(), *Start);
293  if (!End)
294  panic("failed to parse automaton '" + ShortName(Automaton.identifier()));
295 
296  // Parse the automaton finalisation point, if provided...
297  if (Use && Use->has_end()) {
298  End = Parse(Use->end(), *End, false, true);
299  if (!End) {
300  string Str;
301  TextFormat::PrintToString(Use->end(), &Str);
302  panic("failed to parse automaton 'end' event: " + Str);
303  }
304  }
305 
306  // Handle out-of-scope events: if we observe one, we it should cause us to
307  // stay in the post-initialisation state.
308  debugs("tesla.automata.parsing.out-of-scope") << "out-of-scope events:\n";
309  vector<const Transition*> OutOfScope;
310  for (const Transition *T : Transitions) {
311  // Have we already noted an equivalent out-of-scope transition?
312  //
313  // This check is subtly different from looping over the equivalence
314  // classes created below: that equivalence is based on the transition's
315  // input event only, so transitions in the same equivalence class can have
316  // different in-scope vs out-of-scope characteristics.
317  bool AlreadyHave = false;
318  for (const Transition *Existing : OutOfScope)
319  if (Existing->EquivalentTo(*T)) {
320  AlreadyHave = true;
321  break;
322  }
323 
324  if (!AlreadyHave && !T->IsStrict() && !T->RequiresInit()) {
325  OutOfScope.push_back(T);
326  debugs("tesla.automata.parsing.out-of-scope")
327  << " " << T->String() << "\n";
328  }
329  }
330 
331  for (auto *T : OutOfScope) {
332  State& Destination = *(T->RequiresCleanup() ? End : Start);
333 
334  switch (T->getKind()) {
335  case Transition::Now: // fall through
336  case Transition::Null: // fall through
338  break;
339 
340  case Transition::FieldAssign: // fall through
341  case Transition::Fn:
342  Transition::Copy(*Start, Destination, T, Transitions, true);
343  break;
344  }
345  }
346 
347  const Identifier &ID = Automaton.identifier();
348 
349  string Description;
350  TextFormat::PrintToString(Automaton, &Description);
351 
352  TransitionSets TEquivClasses;
353  Transition::GroupClasses(Transitions, TEquivClasses);
354 
355  Out.reset(new NFA(id, Automaton, Use, ShortName(ID), States, TEquivClasses));
356 
357  debugs("tesla.automata.parsing") << "parsed '" << Out->Name() << "'.\n\n";
358 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


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