The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
ControlFlow.DotVisitor Class Reference
Inheritance diagram for ControlFlow.DotVisitor:
Collaboration diagram for ControlFlow.DotVisitor:

Public Member Functions

 __init__ (self)
 
 enter (self, visitee)
 
 leave (self, visitee)
 
 collapse_identical_ancestors (self, thetype)
 
 is_needed (self, visitee)
 
 write (self, filename)
 

Public Attributes

list nodes = []
 
list edges = []
 
int number = 0
 
list stack = []
 
dict ids = {}
 

Detailed Description

Definition at line 249 of file ControlFlow.py.

Constructor & Destructor Documentation

◆ __init__()

ControlFlow.DotVisitor.__init__ ( self)

Definition at line 250 of file ControlFlow.py.

250 def __init__(self):
251 self.nodes = []
252 self.edges = []
253 self.number = 0
254 self.stack = []
255 self.ids = {}
256

Member Function Documentation

◆ collapse_identical_ancestors()

ControlFlow.DotVisitor.collapse_identical_ancestors ( self,
thetype )
If AND nodes are inside AND nodes, the graph could be simplified
to not contain those (same true for OR and ordered)

Definition at line 292 of file ControlFlow.py.

292 def collapse_identical_ancestors(self, thetype):
293 """
294 If AND nodes are inside AND nodes, the graph could be simplified
295 to not contain those (same true for OR and ordered)
296 """
297 if len(self.stack) != 0:
298 mother = self.stack[-1][1]
299 for entry in self.stack[::-1]:
300 if not isinstance(entry[0], thetype):
301 break
302 mother = entry[1]
303 return mother
304 return None
305

◆ enter()

ControlFlow.DotVisitor.enter ( self,
visitee )

Definition at line 257 of file ControlFlow.py.

257 def enter(self, visitee):
258 if visitee not in self.ids:
259 self.number += 1
260 dot_id = self.ids[visitee] = "T%s" % self.number
261 dot_id = self.ids[visitee]
262 mother = None
263 if self.is_needed(visitee):
264 if isinstance(visitee, ControlFlowLeaf):
265 entry = '%s [label="%s", shape=box]' % (dot_id, visitee.name())
266 elif isinstance(visitee, OrNode):
267 entry = '%s [label="OR", shape=invhouse]' % dot_id
268 elif isinstance(visitee, AndNode):
269 entry = '%s [label="AND", shape=invhouse]' % dot_id
270 elif isinstance(visitee, OrderedNode):
271 entry = '%s [label=">>", shape=point]' % dot_id
272 elif isinstance(visitee, InvertNode):
273 entry = '%s [label="NOT", shape=circle, color=red]' % dot_id
274 elif isinstance(visitee, par):
275 entry = '%s [label="PAR", shape=circle]' % dot_id
276 elif isinstance(visitee, seq):
277 entry = '%s [label="SEQ", shape=circle]' % dot_id
278 else:
279 entry = '%s [label="%s", shape=circle]' % (dot_id, type(visitee))
280 self.nodes.append(entry)
281 if len(self.stack) != 0:
282 mother = self.collapse_identical_ancestors(type(self.stack[-1][0]))
283 if not mother:
284 mother = self.stack[-1][1]
285 edge = "%s->%s" % (dot_id, mother)
286 self.edges.append(edge)
287 self.stack.append((visitee, dot_id))
288

◆ is_needed()

ControlFlow.DotVisitor.is_needed ( self,
visitee )
Check whether this node is actually needed

Definition at line 306 of file ControlFlow.py.

306 def is_needed(self, visitee):
307 """
308 Check whether this node is actually needed
309 """
310 if len(self.stack) != 0:
311 return not isinstance(visitee, type(self.stack[-1][0]))
312 return True
313

◆ leave()

ControlFlow.DotVisitor.leave ( self,
visitee )

Definition at line 289 of file ControlFlow.py.

289 def leave(self, visitee):
290 self.stack.pop()
291

◆ write()

ControlFlow.DotVisitor.write ( self,
filename )

Definition at line 314 of file ControlFlow.py.

314 def write(self, filename):
315 output = """
316digraph graphname {
317rankdir=LR
318
319%s
320
321%s
322
323}
324""" % (
325 "\n".join(self.nodes),
326 "\n".join(self.edges),
327 )
328
329 with open(filename, "w") as outfile:
330 outfile.write(output)
331
332

Member Data Documentation

◆ edges

list ControlFlow.DotVisitor.edges = []

Definition at line 252 of file ControlFlow.py.

◆ ids

dict ControlFlow.DotVisitor.ids = {}

Definition at line 255 of file ControlFlow.py.

◆ nodes

list ControlFlow.DotVisitor.nodes = []

Definition at line 251 of file ControlFlow.py.

◆ number

int ControlFlow.DotVisitor.number = 0

Definition at line 253 of file ControlFlow.py.

◆ stack

ControlFlow.DotVisitor.stack = []

Definition at line 254 of file ControlFlow.py.


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