001: /*
002: * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: /*
026: * COMPONENT_NAME: idl.parser
027: *
028: * ORIGINS: 27
029: *
030: * Licensed Materials - Property of IBM
031: * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
032: * RMI-IIOP v1.0
033: *
034: * @(#)UnionEntry.java 1.20 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl;
038:
039: // NOTES:
040:
041: import java.io.PrintWriter;
042: import java.util.Enumeration;
043: import java.util.Hashtable;
044: import java.util.Vector;
045:
046: import com.sun.tools.corba.se.idl.constExpr.Expression;
047:
048: /**
049: * This is the symbol table entry for unions.
050: **/
051: public class UnionEntry extends SymtabEntry {
052: protected UnionEntry() {
053: super ();
054: } // ctor
055:
056: protected UnionEntry(UnionEntry that) {
057: super (that);
058: if (!name().equals("")) {
059: module(module() + name());
060: name("");
061: }
062: _branches = (Vector) that._branches.clone();
063: _defaultBranch = that._defaultBranch;
064: _contained = that._contained;
065: } // ctor
066:
067: protected UnionEntry(SymtabEntry that, IDLID clone) {
068: super (that, clone);
069: if (module().equals(""))
070: module(name());
071: else if (!name().equals(""))
072: module(module() + "/" + name());
073: } // ctor
074:
075: public Object clone() {
076: return new UnionEntry(this );
077: } // clone
078:
079: /** Invoke the union generator.
080: @param symbolTable the symbol table is a hash table whose key is
081: a fully qualified type name and whose value is a SymtabEntry or
082: a subclass of SymtabEntry.
083: @param stream the stream to which the generator should sent its output.
084: @see SymtabEntry */
085: public void generate(Hashtable symbolTable, PrintWriter stream) {
086: unionGen.generate(symbolTable, this , stream);
087: } // generate
088:
089: /** Access the union generator.
090: @returns an object which implements the UnionGen interface.
091: @see UnionGen */
092: public Generator generator() {
093: return unionGen;
094: } // generator
095:
096: public void addBranch(UnionBranch branch) {
097: _branches.addElement(branch);
098: } // addBranch
099:
100: /** This is a vector of UnionBranch's. */
101: public Vector branches() {
102: return _branches;
103: } // branches
104:
105: /** This TypedefEntry describes the type and name for the default branch.
106: Like the entries in the branches vector, only the type and name fields
107: are pertinent. */
108: public void defaultBranch(TypedefEntry branch) {
109: _defaultBranch = branch;
110: } // defaultBranch
111:
112: /** This TypedefEntry describes the type and name for the default branch.
113: Like the entries in the branches vector, only the type and name fields
114: are pertinent. */
115: public TypedefEntry defaultBranch() {
116: return _defaultBranch;
117: } // defaultBranch
118:
119: public void addContained(SymtabEntry entry) {
120: _contained.addElement(entry);
121: } // addContained
122:
123: /** This is a vector of SymtabEntry's. It itemizes any types which
124: this union contains. For example:
125:
126: <pre>
127: union A
128: switch (long)
129: {
130: case 0: long x;
131: case 1:
132: Struct B
133: {
134: long a;
135: long b;
136: } y;
137: }
138: </pre>
139: Struct B is contained within union A. */
140: public Vector contained() {
141: return _contained;
142: } // contained
143:
144: boolean has(Expression label) {
145: Enumeration eBranches = _branches.elements();
146: while (eBranches.hasMoreElements()) {
147: Enumeration eLabels = ((UnionBranch) eBranches
148: .nextElement()).labels.elements();
149: while (eLabels.hasMoreElements()) {
150: Expression exp = (Expression) eLabels.nextElement();
151: if (exp.equals(label)
152: || exp.value().equals(label.value()))
153: return true;
154: }
155: }
156: return false;
157: } // has
158:
159: boolean has(TypedefEntry typedef) {
160: Enumeration e = _branches.elements();
161: while (e.hasMoreElements()) {
162: UnionBranch branch = (UnionBranch) e.nextElement();
163: if (!branch.typedef.equals(typedef)
164: && branch.typedef.name().equals(typedef.name()))
165: return true;
166: }
167: return false;
168: } // has
169:
170: /** A vector of UnionBranch's. */
171: private Vector _branches = new Vector();
172: private TypedefEntry _defaultBranch = null;
173: private Vector _contained = new Vector();
174:
175: static UnionGen unionGen;
176: } // class UnionEntry
|