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: /**
024: * @author Gerald Brose
025: * @version $Id: ElementSpec.java,v 1.20 2006/06/19 10:34:57 alphonse.bendt Exp $
026: */
027:
028: public class ElementSpec extends IdlSymbol {
029: public TypeSpec typeSpec = new TypeSpec(new_num());
030: public Declarator declarator = null;
031: private UnionType containingUnion;
032:
033: public ElementSpec(int num) {
034: super (num);
035: }
036:
037: public void setPackage(String s) {
038: s = parser.pack_replace(s);
039: if (pack_name.length() > 0)
040: pack_name = s + "." + pack_name;
041: else
042: pack_name = s;
043: typeSpec.setPackage(s);
044: declarator.setPackage(s);
045: }
046:
047: public void setUnion(UnionType ut) {
048: containingUnion = ut;
049:
050: // If its a constrType and is a pseudoscope add union name
051: if (typeSpec.typeSpec() instanceof ConstrTypeSpec) {
052: String tmpRef = ((ConstrTypeSpec) typeSpec.typeSpec()).c_type_spec.pack_name;
053:
054: if (tmpRef.endsWith("PackagePackage")
055: || !tmpRef.startsWith("_")
056: && tmpRef.endsWith("Package")) {
057: tmpRef = tmpRef.substring(0, tmpRef
058: .lastIndexOf("Package"));
059: }
060: if (ScopedName.isPseudoScope(tmpRef)) {
061: ((ConstrTypeSpec) typeSpec.typeSpec()).c_type_spec.pack_name = ((ConstrTypeSpec) typeSpec
062: .typeSpec()).c_type_spec.pack_name
063: + "." + ut.name + "Package";
064: }
065: }
066: }
067:
068: public void setEnclosingSymbol(IdlSymbol s) {
069: typeSpec.setEnclosingSymbol(s);
070: declarator.setEnclosingSymbol(s);
071: }
072:
073: public void parse() {
074: if (logger.isDebugEnabled()) {
075: logger.debug("EelementSpec.parse(): element_spec is "
076: + typeSpec.typeSpec().getClass().getName());
077: }
078:
079: if (typeSpec.typeSpec() instanceof TemplateTypeSpec
080: || typeSpec.typeSpec() instanceof ConstrTypeSpec) {
081: typeSpec.parse();
082: if (typeSpec.typeSpec() instanceof SequenceType) {
083: TypeSpec ts = ((SequenceType) typeSpec.typeSpec())
084: .elementTypeSpec().typeSpec();
085: SequenceType seqTs = (SequenceType) typeSpec.typeSpec();
086: while (ts instanceof SequenceType) {
087: seqTs = (SequenceType) ts;
088: ts = ((SequenceType) ts.typeSpec())
089: .elementTypeSpec().typeSpec();
090: }
091:
092: // if( ts.typeName().equals( containingUnion.typeName() ) ||
093: if (ScopedName.isRecursionScope(ts.typeName())) {
094: ((SequenceType) seqTs.typeSpec()).setRecursive();
095: }
096: }
097: } else if (typeSpec.typeSpec() instanceof ScopedName) {
098: TypeSpec ts = ((ScopedName) typeSpec.typeSpec())
099: .resolvedTypeSpec();
100: if (ts.typeName().equals(containingUnion.typeName())) {
101: parser.error("Illegal recursion in union "
102: + containingUnion.full_name(), token);
103: }
104:
105: containingUnion.addImportedName(ts.typeName());
106:
107: // if( ts != null )
108:
109: // fix for bug#115: only set the element spec's type spec to the resolved
110: // type if it is not an Interface! Otherwise the compile may loop!
111: if (!(ts instanceof ConstrTypeSpec && ((ConstrTypeSpec) ts)
112: .declaration() instanceof Interface)) {
113: typeSpec = ts;
114: }
115: }
116:
117: try {
118: NameTable.define(containingUnion.full_name() + "."
119: + declarator.name(), "declarator");
120: } catch (NameAlreadyDefined nad) {
121: parser.error("Declarator " + declarator.name()
122: + " already defined in union "
123: + containingUnion.full_name(), token);
124: }
125:
126: if (logger.isDebugEnabled()) {
127: logger.debug("ElementSpec.parse-end(): element_spec is "
128: + typeSpec.typeSpec().getClass().getName());
129: }
130: }
131:
132: public void print(java.io.PrintWriter ps) {
133: if (typeSpec.typeSpec() instanceof TemplateTypeSpec
134: || typeSpec.typeSpec() instanceof ConstrTypeSpec) {
135: typeSpec.print(ps);
136: }
137: }
138: }
|