OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [CORBA/] [TypeKindNamer.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* primitiveTypes.java --
2
   Copyright (C) 2005 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.CORBA;
40
 
41
import gnu.CORBA.typecodes.PrimitiveTypeCode;
42
import gnu.CORBA.typecodes.RecordTypeCode;
43
 
44
import org.omg.CORBA.TCKind;
45
import org.omg.CORBA.TypeCode;
46
import org.omg.CORBA.TypeCodePackage.BadKind;
47
 
48
/**
49
 * A conveniency method for naming the built-in types.
50
 * This is used in error reporting that is part of the user interface.
51
 *
52
 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
53
 */
54
public class TypeKindNamer
55
{
56
  /**
57
   * Names of the primitve types.
58
   */
59
  protected static final String[] tk =
60
    new String[]
61
    {
62
      "null", "void", "short", "long", "ushort", "ulong", "float", "double",
63
      "boolean", "char", "octet", "any", "TypeCode", "Principal", "objref",
64
      "struct", "union", "enum", "string", "sequence", "array", "alias",
65
      "exception", "longlong", "ulonglong", "longdouble", "wchar", "wstring",
66
      "fixed", "value", "value_box", "native", "abstract_interface"
67
    };
68
 
69
  /**
70
   * Primitve TypeCodes.
71
   */
72
  protected static final TypeCode[] primitveCodes =
73
    new TypeCode[]
74
    {
75
      new PrimitiveTypeCode(TCKind.tk_null),
76
      new PrimitiveTypeCode(TCKind.tk_void),
77
      new PrimitiveTypeCode(TCKind.tk_short),
78
      new PrimitiveTypeCode(TCKind.tk_long),
79
      new PrimitiveTypeCode(TCKind.tk_ushort),
80
      new PrimitiveTypeCode(TCKind.tk_ulong),
81
      new PrimitiveTypeCode(TCKind.tk_float),
82
      new PrimitiveTypeCode(TCKind.tk_double),
83
      new PrimitiveTypeCode(TCKind.tk_boolean),
84
      new PrimitiveTypeCode(TCKind.tk_char),
85
      new PrimitiveTypeCode(TCKind.tk_octet),
86
      new PrimitiveTypeCode(TCKind.tk_any),
87
      new PrimitiveTypeCode(TCKind.tk_TypeCode),
88
      new PrimitiveTypeCode(TCKind.tk_Principal),
89
      new RecordTypeCode(TCKind.tk_objref),
90
      new PrimitiveTypeCode(TCKind.tk_struct),
91
      new PrimitiveTypeCode(TCKind.tk_union),
92
      new PrimitiveTypeCode(TCKind.tk_enum),
93
      new PrimitiveTypeCode(TCKind.tk_string),
94
      new PrimitiveTypeCode(TCKind.tk_sequence),
95
      new PrimitiveTypeCode(TCKind.tk_array),
96
      new PrimitiveTypeCode(TCKind.tk_alias),
97
      new PrimitiveTypeCode(TCKind.tk_except),
98
      new PrimitiveTypeCode(TCKind.tk_longlong),
99
      new PrimitiveTypeCode(TCKind.tk_ulonglong),
100
      new PrimitiveTypeCode(TCKind.tk_longdouble),
101
      new PrimitiveTypeCode(TCKind.tk_wchar),
102
      new PrimitiveTypeCode(TCKind.tk_wstring),
103
      new PrimitiveTypeCode(TCKind.tk_fixed),
104
      new PrimitiveTypeCode(TCKind.tk_value),
105
      new PrimitiveTypeCode(TCKind.tk_value_box),
106
      new PrimitiveTypeCode(TCKind.tk_native),
107
      new PrimitiveTypeCode(TCKind.tk_abstract_interface)
108
    };
109
 
110
  static
111
  {
112
    // The Id of the "abstract object" is defined as empty string.
113
    RecordTypeCode object =
114
      (RecordTypeCode) primitveCodes [ TCKind._tk_objref ];
115
    object.setId("");
116
    object.setName("Object");
117
  }
118
 
119
  /**
120
   * Get the primitive type code.
121
   *
122
   * @return the primitve type code, corresponding the passed value.
123
   *
124
   * @throws BadKind if this is not a primitive type code.
125
   */
126
  public static TypeCode getPrimitveTC(TCKind tc)
127
                                throws BadKind
128
  {
129
    try
130
      {
131
        return primitveCodes [ tc.value() ];
132
      }
133
    catch (ArrayIndexOutOfBoundsException ex)
134
      {
135
        throw new BadKind(tc.value() + " is not a primitve type.");
136
      }
137
  }
138
 
139
  /**
140
   * Get the string name of the passed primitive type.
141
   *
142
   * @param kind the kind of the primitive type the must be defined
143
   * in {@link omg.org.CORBA.TCKind}.
144
   *
145
   * @return the short string name, used in error reporting, etc.
146
   */
147
  public static String nameIt(int kind)
148
  {
149
    try
150
      {
151
        return tk [ kind ];
152
      }
153
    catch (ArrayIndexOutOfBoundsException ex)
154
      {
155
        return "type of kind '" + kind + "'";
156
      }
157
  }
158
 
159
  /**
160
   * Get the string name of the passed primitive type.
161
   *
162
   * @param kind the kind of the primitive type the must be defined
163
   * in {@link omg.org.CORBA.TCKind}.
164
   *
165
   * @return the short string name, used in error reporting, etc.
166
   */
167
  public static String nameIt(TypeCode type)
168
  {
169
    try
170
      {
171
        if (type.kind().value() == TCKind._tk_array)
172
          return "array of " + nameIt(type.content_type());
173
        else if (type.kind().value() == TCKind._tk_sequence)
174
          return "sequence of " + nameIt(type.content_type());
175
        else
176
          return nameIt(type.kind().value());
177
      }
178
    catch (Exception ex)
179
      {
180
        return "type of kind '" + type.kind().value() + "'";
181
      }
182
  }
183
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.