Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Linker/AccessRestrictor.py
    1| # $Id: AccessRestrictor.py,v 1.1 2002/08/23 04:37:26 chalky Exp $
    2| #
    3| # This file is a part of Synopsis.
    4| # Copyright (C) 2000, 2001 Stefan Seefeld
    5| # Copyright (C) 2000, 2001 Stephen Davies
    6| #
    7| # Synopsis is free software; you can redistribute it and/or modify it
    8| # under the terms of the GNU General Public License as published by
    9| # the Free Software Foundation; either version 2 of the License, or
   10| # (at your option) any later version.
   11| #
   12| # This program is distributed in the hope that it will be useful,
   13| # but WITHOUT ANY WARRANTY; without even the implied warranty of
   14| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15| # General Public License for more details.
   16| #
   17| # You should have received a copy of the GNU General Public License
   18| # along with this program; if not, write to the Free Software
   19| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   20| # 02111-1307, USA.
   21| #
   22| # $Log: AccessRestrictor.py,v $
   23| # Revision 1.1  2002/08/23 04:37:26  chalky
   24| # Huge refactoring of Linker to make it modular, and use a config system similar
   25| # to the HTML package
   26| #
   27| 
   28| import string
   29| 
   30| from Synopsis.Core import AST, Type, Util
   31| 
   32| from Linker import config, Operation
   33| 
   34| class AccessRestrictor(AST.Visitor):
   35|     """This class processes declarations, and removes those that need greated
   36|     access than the maximum passed to the constructor"""
   37|     def __init__(self):
   38|         self.__max = config.max_access
   39|         self.__scopestack = []
   40|         self.__currscope = []
   41|     def execute(self, ast):
   42|         if self.__max is None: return
   43|         declarations = ast.declarations()
   44|         for decl in declarations:
   45|             decl.accept(self)
   46|         declarations[:] = self.__currscope
   47|     def push(self):
   48|         self.__scopestack.append(self.__currscope)
   49|         self.__currscope = []
   50|     def pop(self, decl):
   51|         self.__currscope = self.__scopestack.pop()
   52|         self.__currscope.append(decl)
   53|     def add(self, decl):
   54|         self.__currscope.append(decl)
   55|     def currscope(self): return self.__currscope
   56| 
   57|     def visitDeclaration(self, decl):
   58|         if decl.accessibility() > self.__max: return
   59|         self.add(decl)
   60|     def visitScope(self, scope):
   61|         if scope.accessibility() > self.__max: return
   62|         self.push()
   63|         for decl in scope.declarations():
   64|             decl.accept(self)
   65|         scope.declarations()[:] = self.__currscope
   66|         self.pop(scope)
   67| 
   68| linkerOperation = AccessRestrictor