001: package org.jacorb.idl;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import java.util.*;
024:
025: public class SwitchBody extends IdlSymbol {
026: /** holds case list */
027: public Vector caseListVector = new Vector();
028:
029: TypeSpec ts = null;
030: UnionType myUnion = null;
031:
032: public SwitchBody(int num) {
033: super (num);
034: }
035:
036: public void setTypeSpec(TypeSpec s) {
037: ts = s;
038: for (Enumeration e = caseListVector.elements(); e
039: .hasMoreElements();) {
040: Case c = (Case) e.nextElement();
041: c.setPackage(pack_name);
042: c.setTypeSpec(s);
043: }
044: }
045:
046: /**
047: * pass a reference to the containing union through
048: * to the case elements, which pass it on
049: */
050:
051: public void setUnion(UnionType ut) {
052: myUnion = ut;
053: for (Enumeration e = caseListVector.elements(); e
054: .hasMoreElements();) {
055: Case c = (Case) e.nextElement();
056: c.setUnion(ut);
057: }
058: }
059:
060: public void setEnclosingSymbol(IdlSymbol s) {
061: if (enclosing_symbol != null && enclosing_symbol != s)
062: throw new RuntimeException(
063: "Compiler Error: trying to reassign container for "
064: + name);
065: enclosing_symbol = s;
066: for (Enumeration e = caseListVector.elements(); e
067: .hasMoreElements();)
068: ((IdlSymbol) e.nextElement()).setEnclosingSymbol(s);
069: }
070:
071: public void setPackage(String s) {
072: s = parser.pack_replace(s);
073: if (pack_name.length() > 0)
074: pack_name = s + "." + pack_name;
075: else
076: pack_name = s;
077:
078: if (ts != null)
079: ts.setPackage(s);
080: }
081:
082: /**
083: * do the parsing
084: */
085:
086: public void parse() {
087: Map usedLabelNames = new HashMap();
088:
089: for (Enumeration e = caseListVector.elements(); e
090: .hasMoreElements();) {
091: Case theCase = (Case) e.nextElement();
092: theCase.parse();
093:
094: // get all case labels and check for duplicates
095:
096: IdlSymbol[] labels = theCase.getLabels();
097:
098: for (int i = 0; i < labels.length; i++) {
099: if (labels[i] != null) // null means default
100: {
101: IdlSymbol sym = (IdlSymbol) usedLabelNames
102: .get(labels[i].toString());
103:
104: if (sym != null) {
105: parser
106: .error("Duplicate case label <"
107: + sym.toString() + ">", sym
108: .get_token());
109: }
110:
111: usedLabelNames.put(labels[i].toString(), labels[i]);
112: }
113: }
114: }
115: usedLabelNames.clear();
116:
117: ts.parse();
118: myUnion.addImportedName(ts.typeName());
119:
120: }
121:
122: public void print(java.io.PrintWriter ps) {
123: for (Enumeration e = caseListVector.elements(); e
124: .hasMoreElements();) {
125: Case c = (Case) e.nextElement();
126: c.print(ps);
127: }
128: }
129: }
|