0N/A/*
157N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
157N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
157N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
157N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
157N/A * or visit www.oracle.com if you need additional information or have any
157N/A * questions.
0N/A */
0N/A/*
0N/A * COMPONENT_NAME: idl.parser
0N/A *
0N/A * ORIGINS: 27
0N/A *
0N/A * Licensed Materials - Property of IBM
0N/A * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
0N/A * RMI-IIOP v1.0
0N/A *
0N/A */
0N/A
0N/Apackage com.sun.tools.corba.se.idl;
0N/A
0N/A// NOTES:
0N/A
0N/Aimport java.io.PrintWriter;
0N/A
0N/Aimport java.util.Hashtable;
0N/Aimport java.util.Stack;
0N/Aimport java.util.Vector;
0N/A
0N/A/**
0N/A * This is the base class for all symbol table entries.
0N/A * @see AttributeEntry
0N/A * @see ConstEntry
0N/A * @see EnumEntry
0N/A * @see ExceptionEntry
0N/A * @see IncludeEntry
0N/A * @see InterfaceEntry
0N/A * @see MethodEntry
0N/A * @see ModuleEntry
0N/A * @see ParameterEntry
0N/A * @see PragmaEntry
0N/A * @see PrimitiveEntry
0N/A * @see SequenceEntry
0N/A * @see StructEntry
0N/A * @see TypedefEntry
0N/A * @see UnionEntry
0N/A **/
0N/Apublic class SymtabEntry
0N/A{
0N/A public SymtabEntry ()
0N/A {
0N/A initDynamicVars ();
0N/A } // ctor
0N/A
0N/A SymtabEntry (SymtabEntry that, IDLID clone)
0N/A {
0N/A _module = that._module;
0N/A _name = that._name;
0N/A _type = that._type;
0N/A _typeName = that._typeName;
0N/A _sourceFile = that._sourceFile;
0N/A _info = that._info;
0N/A _repID = (RepositoryID)clone.clone ();
0N/A ((IDLID)_repID).appendToName (_name);
0N/A if (that instanceof InterfaceEntry || that instanceof ModuleEntry || that instanceof StructEntry || that instanceof UnionEntry || (that instanceof SequenceEntry && this instanceof SequenceEntry))
0N/A _container = that;
0N/A else
0N/A _container = that._container;
0N/A initDynamicVars ();
0N/A _comment = that._comment; // <21jul1997daz>
0N/A } // ctor
0N/A
0N/A /** This is a shallow copy constructor */
0N/A SymtabEntry (SymtabEntry that)
0N/A {
0N/A _module = that._module;
0N/A _name = that._name;
0N/A _type = that._type;
0N/A _typeName = that._typeName;
0N/A _sourceFile = that._sourceFile;
0N/A _info = that._info;
0N/A _repID = (RepositoryID)that._repID.clone ();
0N/A _container = that._container;
0N/A
0N/A if (_type instanceof ForwardEntry)
0N/A ((ForwardEntry)_type).types.addElement (this);
0N/A
0N/A initDynamicVars ();
0N/A // <21JUL1997>
0N/A _comment = that._comment;
0N/A } // ctor
0N/A
0N/A void initDynamicVars ()
0N/A {
0N/A _dynamicVars = new Vector (maxKey + 1);
0N/A for (int i = 0; i <= maxKey; ++i)
0N/A _dynamicVars.addElement (null);
0N/A } // initDynamicVars
0N/A
0N/A /** This is a shallow copy clone */
0N/A public Object clone ()
0N/A {
0N/A return new SymtabEntry (this);
0N/A } // clone
0N/A
0N/A /** @return the concatenation of the module and the name, delimited by '/'. */
0N/A public final String fullName ()
0N/A {
0N/A return _module.equals ("") ? _name : _module + '/' + _name;
0N/A } // fullName
0N/A
0N/A /** Get the name of this entry's module. If there are modules within
0N/A modules, each module name is separated by '/'.
0N/A @returns this entry's module name. */
0N/A public String module ()
0N/A {
0N/A return _module;
0N/A } // module
0N/A
0N/A /** Set the module for this entry.
0N/A @param newName the new name of the module. */
0N/A public void module (String newName)
0N/A {
0N/A if (newName == null)
0N/A _module = "";
0N/A else
0N/A _module = newName;
0N/A } // module
0N/A
0N/A /** @return the name of this entry. */
0N/A public String name ()
0N/A {
0N/A return _name;
0N/A } // name
0N/A
0N/A /** Set the name.
0N/A @param newName the new name. */
0N/A public void name (String newName)
0N/A {
0N/A if (newName == null)
0N/A _name = "";
0N/A else
0N/A _name = newName;
0N/A
0N/A // Update the RepositoryID
0N/A if (_repID instanceof IDLID)
0N/A ((IDLID)_repID).replaceName (newName);
0N/A } // name
0N/A
0N/A /** @return the type name of this entry. */
0N/A public String typeName ()
0N/A {
0N/A return _typeName;
0N/A } // typeName
0N/A
0N/A protected void typeName (String typeName)
0N/A {
0N/A _typeName = typeName;
0N/A } // typeName
0N/A
0N/A /** @return the type entry of this entry */
0N/A public SymtabEntry type ()
0N/A {
0N/A return _type;
0N/A } // type
0N/A
0N/A public void type (SymtabEntry newType)
0N/A {
0N/A if (newType == null)
0N/A typeName ("");
0N/A else
0N/A typeName (newType.fullName ());
0N/A _type = newType;
0N/A
0N/A if (_type instanceof ForwardEntry)
0N/A ((ForwardEntry)_type).types.addElement (this);
0N/A } // type
0N/A
0N/A /** The file name in which this entry was defined. */
0N/A public IncludeEntry sourceFile ()
0N/A {
0N/A return _sourceFile;
0N/A } // sourceFile
0N/A
0N/A /** The file name in which this entry was defined. */
0N/A public void sourceFile (IncludeEntry file)
0N/A {
0N/A _sourceFile = file;
0N/A } // sourceFile
0N/A
0N/A /** This must be either an InterfaceEntry or a ModuleEntry.
0N/A It can be nothing else. */
0N/A public SymtabEntry container ()
0N/A {
0N/A return _container;
0N/A } // container
0N/A
0N/A /** This must be either an InterfaceEntry or a ModuleEntry.
0N/A It can be nothing else. */
0N/A public void container (SymtabEntry newContainer)
0N/A {
0N/A if (newContainer instanceof InterfaceEntry || newContainer instanceof ModuleEntry)
0N/A _container = newContainer;
0N/A } // container
0N/A
0N/A /** @return the repository ID for this entry. */
0N/A public RepositoryID repositoryID ()
0N/A {
0N/A return _repID;
0N/A } // repositoryID
0N/A
0N/A /** Set the repository ID for this entry.
0N/A @param id the new repository ID. */
0N/A public void repositoryID (RepositoryID id)
0N/A {
0N/A _repID = id;
0N/A } // repositoryID
0N/A
0N/A /** Should this type be emitted? */
0N/A public boolean emit ()
0N/A {
0N/A return _emit && _isReferencable ;
0N/A } // emit
0N/A
0N/A public void emit (boolean emit)
0N/A {
0N/A _emit = emit;
0N/A } // emit
0N/A
0N/A /* <21jul1997daz> Accessors for comment */
0N/A
0N/A public Comment comment()
0N/A {
0N/A return _comment;
0N/A }
0N/A
0N/A public void comment( Comment comment )
0N/A {
0N/A _comment = comment;
0N/A }
0N/A
0N/A public boolean isReferencable()
0N/A {
0N/A return _isReferencable ;
0N/A }
0N/A
0N/A public void isReferencable( boolean value )
0N/A {
0N/A _isReferencable = value ;
0N/A }
0N/A
0N/A static Stack includeStack = new Stack ();
0N/A
0N/A static void enteringInclude ()
0N/A {
0N/A includeStack.push (new Boolean (setEmit));
0N/A setEmit = false;
0N/A } // enteringInclude
0N/A
0N/A static void exitingInclude ()
0N/A {
0N/A setEmit = ((Boolean)includeStack.pop ()).booleanValue ();
0N/A } // exitingInclude
0N/A
0N/A /** Other variables besides the default ones can be dynamically placed
0N/A into SymTabEntry (and therefore on all symbol table entries) by
0N/A extenders. Before such a variable can exist, its key must be
0N/A obtained by calling getVariableKey. */
0N/A public static int getVariableKey ()
0N/A {
0N/A return ++maxKey;
0N/A } // dynamicVariable
0N/A
0N/A /** Other variables besides the default ones can be dynamically placed
0N/A into SymTabEntry (and therefore on all symbol table entries) by
0N/A extenders. This method assigns the value to the variable of the
0N/A given key. A valid key must be obtained by calling the method
0N/A getVariableKey. If the key is invalid, NoSuchFieldException is
0N/A thrown. */
0N/A public void dynamicVariable (int key, Object value) throws NoSuchFieldException
0N/A {
0N/A if (key > maxKey)
0N/A throw new NoSuchFieldException (Integer.toString (key));
0N/A else
0N/A {
0N/A if (key >= _dynamicVars.size ())
0N/A growVars ();
0N/A _dynamicVars.setElementAt (value, key);
0N/A }
0N/A } // dynamicVariable
0N/A
0N/A /** Other variables besides the default ones can be dynamically placed
0N/A into SymTabEntry (and therefore on all symbol table entries) by
0N/A extenders. This method gets the value of the variable of the
0N/A given key. A valid key must be obtained by calling the method
0N/A getVariableKey. If the key is invalid, NoSuchFieldException is
0N/A thrown. */
0N/A public Object dynamicVariable (int key) throws NoSuchFieldException
0N/A {
0N/A if (key > maxKey)
0N/A throw new NoSuchFieldException (Integer.toString (key));
0N/A else
0N/A {
0N/A if (key >= _dynamicVars.size ())
0N/A growVars ();
0N/A return _dynamicVars.elementAt (key);
0N/A }
0N/A } // dynamicVariable
0N/A
0N/A void growVars ()
0N/A {
0N/A int diff = maxKey - _dynamicVars.size () + 1;
0N/A for (int i = 0; i < diff; ++i)
0N/A _dynamicVars.addElement (null);
0N/A } // growVars
0N/A
0N/A /** Invoke a generator. A call to this method is only meaningful
0N/A for subclasses of SymtabEntry. If called on this class, it
0N/A is a no-op.
0N/A @param symbolTable the symbol table is a hash table whose key is
0N/A a fully qualified type name and whose value is a SymtabEntry or
0N/A a subclass of SymtabEntry.
0N/A @param stream the stream to which the generator should sent its output. */
0N/A public void generate (Hashtable symbolTable, PrintWriter stream)
0N/A {
0N/A } // generate
0N/A
0N/A /** Access a generator. A call to this method is only meaningful
0N/A for subclasses of SymtabEntry. If called on this class, it
0N/A is a no-op.
0N/A @return an object which implements the Generator interface. */
0N/A public Generator generator ()
0N/A {
0N/A return null;
0N/A } // generator
0N/A
0N/A static boolean setEmit = true;
0N/A static int maxKey = -1;
0N/A
0N/A private SymtabEntry _container = null;
0N/A private String _module = "";
0N/A private String _name = "";
0N/A private String _typeName = "";
0N/A private SymtabEntry _type = null;
0N/A private IncludeEntry _sourceFile = null;
0N/A private Object _info = null;
0N/A private RepositoryID _repID = new IDLID ("", "", "1.0");
0N/A private boolean _emit = setEmit;
0N/A private Comment _comment = null;
0N/A private Vector _dynamicVars;
0N/A private boolean _isReferencable = true ;
0N/A} // class SymtabEntry
0N/A
0N/A/*=======================================================================================
0N/A DATE<AUTHOR> ACTION
0N/A ---------------------------------------------------------------------------------------
0N/A 21jul1997<daz> Added _comment data member to afford transferring comments from source
0N/A file to target; added acessor methods for comment.
0N/A =======================================================================================*/