Synopsis - Cross-Reference
File: Synopsis/Processors/TypedefFolder.py1# 2# Copyright (C) 2008 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.Processor import * 9from Synopsis import ASG 10 11class TypedefFolder(Processor, ASG.Visitor): 12 """Fold (anonymous) types into enclosing typedefs.""" 13 14 anonymous_only = Parameter(True, "Whether or not folding should be restricted to unnamed types.") 15 16 def process(self, ir, **kwds): 17 18 self.set_parameters(kwds) 19 self.ir = self.merge_input(ir) 20 21 self.scopes = [] 22 # Iterate over a copy so we can safely modify 23 # the original in the process. 24 decls = ir.asg.declarations[:] 25 for d in decls: 26 d.accept(self) 27 return self.output_and_return_ir() 28 29 def visit_scope(self, s): 30 31 self.scopes.append(s) 32 decls = s.declarations[:] 33 for d in decls: 34 d.accept(self) 35 self.scopes.pop() 36 37 def visit_typedef(self, t): 38 39 if t.constr: 40 if self.verbose: print 'replace', t.alias.name, 'by', t.name 41 alias = self.ir.asg.types.pop(t.alias.name) 42 alias.declaration.name = alias.name = t.name 43 self.ir.asg.types[alias.name] = alias 44 if len(self.scopes): 45 decls = self.scopes[-1].declarations 46 else: 47 decls = self.ir.asg.declarations 48 del decls[decls.index(t)] 49 50 if type(alias.declaration) == ASG.Class: 51 i = len(alias.declaration.name) 52 for d in alias.declaration.declarations: 53 d.name = d.name[:i-1] + (alias.name[-1],) + d.name[i:] 54
Generated on Tue May 13 02:39:19 2008 by
synopsis (version 0.10)
synopsis (version 0.10)