001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1997-2004 Gerald Brose.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: */
020:
021: package org.jacorb.idl;
022:
023: /**
024: * @author Gerald Brose
025: * @version $Id: ArrayDeclarator.java,v 1.19 2006/06/19 10:34:57 alphonse.bendt Exp $
026: */
027:
028: import java.io.PrintWriter;
029: import java.util.*;
030:
031: public class ArrayDeclarator extends Declarator {
032: public SymbolList fixed_array_size_list;
033: private int[] dimensions = null;
034:
035: public ArrayDeclarator(int num) {
036: super (num);
037: }
038:
039: public String name() {
040: return name;
041: }
042:
043: /**
044: */
045:
046: public void escapeName() {
047: if (!name.startsWith("_") && lexer.strictJavaEscapeCheck(name)) {
048: name = "_" + name;
049: }
050: }
051:
052: public void setPackage(String s) {
053: s = parser.pack_replace(s);
054: if (pack_name.length() > 0)
055: pack_name = s + "." + pack_name;
056: else
057: pack_name = s;
058:
059: for (Enumeration e = fixed_array_size_list.v.elements(); e
060: .hasMoreElements(); ((FixedArraySize) e.nextElement())
061: .setPackage(s))
062: ;
063:
064: }
065:
066: /**
067: * only needed to overwrite the delegating full_name()
068: * method from superclass Declarator, identical to method in
069: * class IdlSymbol
070: */
071:
072: String full_name() {
073: if (name.length() == 0) {
074: return null;
075: }
076:
077: if (pack_name.length() > 0) {
078: return pack_name + "." + name;
079: }
080:
081: return name;
082: }
083:
084: public void parse() {
085: for (Enumeration e = fixed_array_size_list.v.elements(); e
086: .hasMoreElements(); ((FixedArraySize) e.nextElement())
087: .parse())
088: ;
089:
090: for (Enumeration e = fixed_array_size_list.v.elements(); e
091: .hasMoreElements();)
092: ((FixedArraySize) e.nextElement()).parse();
093: }
094:
095: public void setEnclosingSymbol(IdlSymbol s) {
096: if (enclosing_symbol != null && enclosing_symbol != s) {
097: throw new RuntimeException(
098: "Compiler Error: trying to reassign container for "
099: + name);
100: }
101: enclosing_symbol = s;
102: }
103:
104: public IdlSymbol getEnclosingSymbol() {
105: return enclosing_symbol;
106: }
107:
108: public int[] dimensions() {
109: if (dimensions == null) {
110: Vector dynlist = new Vector();
111: for (Enumeration e = fixed_array_size_list.v.elements(); e
112: .hasMoreElements();)
113: dynlist.addElement(new Integer(((FixedArraySize) e
114: .nextElement()).value()));
115: dimensions = new int[dynlist.size()];
116: for (int i = 0; i < dimensions.length; i++)
117: dimensions[i] = ((Integer) dynlist.elementAt(i))
118: .intValue();
119:
120: }
121: return dimensions;
122: }
123:
124: public String toString() {
125: return name();
126: }
127:
128: public void print(PrintWriter ps) {
129: }
130: }
|