Synopsis - Synopsis/Processors/AccessRestrictor.py

File: Synopsis/Processors/AccessRestrictor.py

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

Generated on Thu Apr 16 16:27:12 2009 by
synopsis (version devel)