idlast.py

来自「编译工具」· Python 代码 · 共 1,144 行 · 第 1/3 页

PY
1,144
字号
# -*- python -*-#                           Package   : omniidl# idlast.py                 Created on: 1999/10/27#			    Author    : Duncan Grisby (dpg1)##    Copyright (C) 1999 AT&T Laboratories Cambridge##  This file is part of omniidl.##  omniidl is free software; you can redistribute it and/or modify it#  under the terms of the GNU General Public License as published by#  the Free Software Foundation; either version 2 of the License, or#  (at your option) any later version.##  This program is distributed in the hope that it will be useful,#  but WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU#  General Public License for more details.##  You should have received a copy of the GNU General Public License#  along with this program; if not, write to the Free Software#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA#  02111-1307, USA.## Description:#   #   Python definitions for abstract syntax tree classes# $Id: idlast.py,v 1.15.2.7 2002/09/21 21:07:51 dgrisby Exp $# $Log: idlast.py,v $# Revision 1.15.2.7  2002/09/21 21:07:51  dgrisby# Support ValueBase in omniidl. (No use to omniORB yet...)## Revision 1.15.2.6  2001/08/29 11:55:23  dpg1# Enumerator nodes record their value.## Revision 1.15.2.5  2001/06/08 17:12:25  dpg1# Merge all the bug fixes from omni3_develop.## Revision 1.15.2.4  2000/11/01 15:57:03  dpg1# More updates for 2.4.## Revision 1.15.2.3  2000/11/01 12:45:59  dpg1# Update to CORBA 2.4 specification.## Revision 1.15.2.2  2000/10/10 10:18:54  dpg1# Update omniidl front-end from omni3_develop.## Revision 1.13.2.4  2000/08/29 10:20:29  dpg1# Operations and attributes now have repository ids.## Revision 1.13.2.3  2000/06/29 14:08:11  dpg1# Incorrect visitor method called for Value nodes.## Revision 1.13.2.2  2000/06/08 14:36:21  dpg1# Comments and pragmas are now objects rather than plain strings, so# they can have file,line associated with them.## Revision 1.13.2.1  2000/03/06 15:03:45  dpg1# Minor bug fixes to omniidl. New -nf and -k flags.## Revision 1.13  1999/11/29 16:43:51  dpg1# Forgot a case in registerDecl().## Revision 1.12  1999/11/29 15:04:47  dpg1# Fixed bug in clear().## Revision 1.11  1999/11/25 11:20:33  dpg1# Tidy documentation changes.## Revision 1.10  1999/11/23 09:52:11  dpg1# Dumb bug where maps weren't cleared between runs.## Revision 1.9  1999/11/15 15:49:23  dpg1# Documentation strings.## Revision 1.8  1999/11/11 15:55:30  dpg1# Python back-end interface now supports valuetype declarations.# Back-ends still don't support them, though.## Revision 1.7  1999/11/02 17:07:24  dpg1# Changes to compile on Solaris.## Revision 1.6  1999/11/02 10:01:46  dpg1# Minor fixes.## Revision 1.5  1999/11/01 20:19:55  dpg1# Support for union switch types declared inside the switch statement.## Revision 1.4  1999/11/01 16:39:01  dpg1# Small fixes and cosmetic changes.## Revision 1.3  1999/11/01 10:05:01  dpg1# New file attribute to AST.## Revision 1.2  1999/10/29 18:19:39  dpg1# Clean up## Revision 1.1  1999/10/29 15:47:08  dpg1# First revision.#"""Classes and functions for handling the IDL Abstract Syntax TreeFunction:  findDecl(scopedName) -- find a Decl object given a fully-scoped                          name, represented as a list of strings.                          eg. ::foo::bar::baz is represented as                          ['foo', 'bar', 'baz'].Classes:  AST          -- top level of Abstract Syntax Tree.  Decl         -- base of all declarations.  DeclRepoId   -- mixin class for Decls with repository ids.  Pragma       -- record of an unknown pragma  Comment      -- record of a comment  Module       -- module declaration.  Interface    -- interface declaration.  Forward      -- forward-declared interface.  Const        -- constant declaration.  Declarator   -- declarator used in typedef, struct members, etc.  Typedef      -- typedef.  Member       -- member of a struct or exception.  Struct       -- struct declaration.  Exception    -- exception declaration.  CaseLabel    -- case label within a union.  UnionCase    -- one case within a union.  Union        -- union declaration.  Enumerator   -- enumerator of an enum.  Enum         -- enum declaration.  Attribute    -- attribute declaration.  Parameter    -- parameter of an operation of factory.  Operation    -- operation declaration.  Native       -- native declaration.  StateMember  -- state member of a valuetype.  Factory      -- factory method of a valuetype.  ValueForward -- forward-declared valuetype.  ValueBox     -- boxed value declaration.  ValueAbs     -- abstract valuetype declaration.  Value        -- valuetype declaration."""import idlutilimport idlvisitorclass AST:    """Class for top-level Abstract Syntax Tree.Functions:  file()          -- the file name of the main IDL file.  declarations()  -- list of Decl objects corresponding to declarations                     at file scope.  pragmas()       -- list of Pragma objects containing #pragmas which                     occurred before any declarations. Later #pragmas                     are attached to Decl objects.  comments()      -- list of Comment objects containing comments which                     occurred before any declarations.  accept(visitor) -- visitor pattern accept. See idlvisitor.py."""    def __init__(self, file, declarations, pragmas, comments):        self.__file         = file        self.__declarations = declarations        self.__pragmas      = pragmas        self.__comments     = comments    def file(self):            return self.__file    def declarations(self):    return self.__declarations    def pragmas(self):         return self.__pragmas    def comments(self):        return self.__comments    def accept(self, visitor): visitor.visitAST(self)class Decl:    """Base class for all declarations.Functions:  file()          -- the IDL file this declaration came from.  line()          -- the line number within the file.  mainFile()      -- boolean: true if the file was the main IDL file;                     false if it was an included file.  pragmas()       -- list of Pragma objects containing #pragmas which                     immediately followed this declaration.  comments()      -- list of Comment objects containing comments which                     immediately followed this declaration.  accept(visitor) -- visitor pattern accept. See idlvisitor.py."""    def __init__(self, file, line, mainFile, pragmas, comments):        self.__file     = file        self.__line     = line        self.__mainFile = mainFile        self.__builtIn  = 0        self.__pragmas  = pragmas        self.__comments = comments    def accept(self, visitor): pass    def file(self):     return self.__file    def line(self):     return self.__line    def mainFile(self): return self.__mainFile    def builtIn(self):  return self.__builtIn    def pragmas(self):  return self.__pragmas    def comments(self): return self.__commentsclass DeclRepoId :    """Mixin class for Decls which have a Repository IdFunctions:  identifier() -- name of the declaration as a string  scopedName() -- list of strings forming the fully-scoped name of the                  declaration. e.g. ::foo::bar::baz is represented as                  ['foo', 'bar', 'baz'].  repoId()     -- repository identifier for this declaration."""    def __init__(self, identifier, scopedName, repoId):        self.__identifier = identifier        self.__scopedName = scopedName        self.__repoId     = repoId    def identifier(self): return self.__identifier    def scopedName(self): return self.__scopedName    def repoId(self):     return self.__repoId# Pragmas and commentsclass Pragma :    """Class containing information about an unknown pragmaFunctions:  text()    -- text of the pragma  __str__() -- same as text()  file()    -- file containing the pragma  line()    -- line number in file"""    def __init__(self, text, file, line):        self.__text = text        self.__file = file        self.__line = line    def text(self)    : return self.__text    def __str__(self) : return self.__text    def file(self)    : return self.__file    def line(self)    : return self.__lineclass Comment :    """Class containing information about a commentFunctions:  text()    -- text of the comment  __str__() -- same as text()  file()    -- file containing the comment  line()    -- line number in file"""    def __init__(self, text, file, line):        self.__text = text        self.__file = file        self.__line = line    def text(self)    : return self.__text    def __str__(self) : return self.__text    def file(self)    : return self.__file    def line(self)    : return self.__line# Concrete declaration objectsclass Module (Decl, DeclRepoId):    """Module declaration (Decl, DeclRepoId)Functions:  definitions()   -- list of Decl objects declared within this module.  continuations() -- list containing continuations of this module.                     When modules are re-opened, multiple Module                     objects with the same name appear in the                     enclosing Module or AST object. In case it's                     useful, the first Module object for a particular                     module has a list containing continuations of                     that module. You will probably not have any use                     for this."""    def __init__(self, file, line, mainFile, pragmas, comments,                 identifier, scopedName, repoId,                 definitions):        Decl.__init__(self, file, line, mainFile, pragmas, comments)        DeclRepoId.__init__(self, identifier, scopedName, repoId)        self.__definitions  = definitions        self._continuations = []    def accept(self, visitor): visitor.visitModule(self)    def definitions(self):   return self.__definitions    def continuations(self): return self._continuationsclass Interface (Decl, DeclRepoId):    """Interface declaration (Decl, DeclRepoId)Functions:  abstract()     -- boolean: true if the interface is declared abstract.  local()        -- boolean: true if the interface is declared local.  inherits()     -- list of Interface objects from which this one                    inherits.  contents()     -- list of Decl objects for all items declared within                    this interface.  declarations() -- subset of contents() containing types, constants                    and exceptions.  callables()    -- subset of contents() containing Operations and                    Attributes."""    def __init__(self, file, line, mainFile, pragmas, comments,                 identifier, scopedName, repoId,                 abstract, local, inherits):        Decl.__init__(self, file, line, mainFile, pragmas, comments)        DeclRepoId.__init__(self, identifier, scopedName, repoId)        self.__abstract     = abstract        self.__local        = local        self.__inherits     = inherits        self.__contents     = []        self.__declarations = []        self.__callables    = []    def _setContents(self, contents):        self.__contents     = contents        self.__declarations = filter(lambda c: not (isinstance(c, Attribute) or                                                    isinstance(c, Operation)),                                     contents)        self.__callables    = filter(lambda c: (isinstance(c, Attribute) or                                                isinstance(c, Operation)),                                     contents)    def accept(self, visitor): visitor.visitInterface(self)    def abstract(self):     return self.__abstract    def local(self):        return self.__local    def inherits(self):     return self.__inherits    def contents(self):     return self.__contents    def declarations(self): return self.__declarations    def callables(self):    return self.__callablesclass Forward (Decl, DeclRepoId):    """Forward-declared interface (Decl, DeclRepoId)Functions:  abstract() -- boolean: true if the interface is declared abstract.  local()    -- boolean: true if the interface is declared local.  fullDecl() -- Interface object corresponding to full interface                declaration or None if there is no full declaration."""    def __init__(self, file, line, mainFile, pragmas, comments,                 identifier, scopedName, repoId,                 abstract, local):        Decl.__init__(self, file, line, mainFile, pragmas, comments)        DeclRepoId.__init__(self, identifier, scopedName, repoId)        self.__abstract = abstract        self.__local    = local        self._fullDecl  = None        self._more      = []    def accept(self, visitor): visitor.visitForward(self)    def abstract(self): return self.__abstract    def local(self):    return self.__abstract    def fullDecl(self): return self._fullDecl

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?