1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# $Id: AccessRestrictor.py,v 1.3 2003/11/11 06:03:59 stefan Exp $
#
# Copyright (C) 2000 Stefan Seefeld
# Copyright (C) 2000 Stephen Davies
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#
from Synopsis.Processor import Processor, Parameter
from Synopsis import AST, Type, Util
import string
class AccessRestrictor(Processor, AST.Visitor):
"""This class processes declarations, and removes those that need greated
access than the maximum passed to the constructor"""
access = Parameter(None, 'specify up to which accessibility level the interface should be documented')
def __init__(self):
self.__scopestack = []
self.__currscope = []
def process(self, ast, **kwds):
self.set_parameters(kwds)
self.ast = self.merge_input(ast)
if self.access is not None:
for decl in ast.declarations():
decl.accept(self)
ast.declarations()[:] = self.__currscope
return self.output_and_return_ast()
def push(self):
self.__scopestack.append(self.__currscope)
self.__currscope = []
def pop(self, decl):
self.__currscope = self.__scopestack.pop()
self.__currscope.append(decl)
def add(self, decl):
self.__currscope.append(decl)
def visitDeclaration(self, decl):
if decl.accessibility() > self.access: return
self.add(decl)
def visitScope(self, scope):
if scope.accessibility() > self.access: return
self.push()
for decl in scope.declarations():
decl.accept(self)
scope.declarations()[:] = self.__currscope
self.pop(scope)
linkerOperation = AccessRestrictor
|