Synopsis - Cross-Reference
File: Synopsis/Processors/Transformer.py1# 2# Copyright (C) 2005 Stefan Seefeld 3# All rights reserved. 4# Licensed to the public under the terms of the GNU LGPL (>= 2), 5# see the file COPYING for details. 6# 7 8from Synopsis import ASG 9from Synopsis.Processor import Processor 10 11class Transformer(Processor, ASG.Visitor): 12 """A class that creates a new ASG from an old one. This is a helper base for 13 more specialized classes that manipulate the ASG based on 14 the comments in the nodes""" 15 16 def __init__(self, **kwds): 17 """Constructor""" 18 19 Processor.__init__(self, **kwds) 20 self.__scopes = [] 21 self.__current = [] 22 23 def process(self, ir, **kwds): 24 25 self.set_parameters(kwds) 26 self.ir = self.merge_input(ir) 27 28 for decl in ir.asg.declarations: 29 decl.accept(self) 30 31 self.finalize() 32 return self.output_and_return_ir() 33 34 def finalize(self): 35 """replace the ASG with the newly created one""" 36 37 self.ir.asg.declarations[:] = self.__current 38 39 def push(self): 40 """Pushes the current scope onto the stack and starts a new one""" 41 42 self.__scopes.append(self.__current) 43 self.__current = [] 44 45 def pop(self, decl): 46 """Pops the current scope from the stack, and appends the given 47 declaration to it""" 48 49 self.__current = self.__scopes.pop() 50 self.__current.append(decl) 51 52 def add(self, decl): 53 """Adds the given decl to the current scope""" 54 55 self.__current.append(decl) 56 57 def current_scope(self): 58 """Returns the current scope: a list of declarations""" 59 60 return self.__current 61 62 def visit_builtin(self, decl): 63 64 self.visit_declaration(decl) 65
Generated on Tue May 13 02:39:23 2008 by
synopsis (version 0.10)
synopsis (version 0.10)