View Javadoc

1   /***
2    * Cecilia ADL Compiler
3    * Copyright (C) 2006-2007 STMicroelectronics
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   *
19   * Contact: fractal@objectweb.org
20   *
21   * Author:Ali Erdem Ozcan
22   */
23  
24  package org.objectweb.fractal.cecilia.adl.idl.ast;
25  
26  /**
27   * AST node interface for <code>primitiveType</code> elements.
28   */
29  public interface PrimitiveType extends Type {
30  
31    /** Enumeration of the primitive types. */
32    public static enum PrimitiveTypeEnum {
33      /** The name of the any primitive type. */
34      ANY("any", "void *"),
35  
36      /** The name of the void primitive type. */
37      VOID("void", "void"),
38  
39      /** The name of the boolean primitive type. */
40      BOOLEAN("boolean", "jboolean"),
41  
42      /** The name of the char primitive type. */
43      CHAR("char", "jchar"),
44  
45      /** The name of the byte primitive type. */
46      BYTE("byte", "jbyte"),
47  
48      /** The name of the short primitive type. */
49      SHORT("short", "jshort"),
50  
51      /** The name of the int primitive type. */
52      INT("int", "jint"),
53  
54      /** The name of the long primitive type. */
55      LONG("long", "jlong"),
56  
57      /** The name of the float primitive type. */
58      FLOAT("float", "jfloat"),
59  
60      /** The name of the double primitive type. */
61      DOUBLE("double", "jdouble"),
62  
63      /** The name of the string primitive type. */
64      STRING("string", "char*"),
65  
66      /** The name of the unsigned byte primitive type. */
67      UNSIGNED_BYTE("unsigned byte", "jubyte"),
68  
69      /** The name of the unsigned short primitive type. */
70      UNSIGNED_SHORT("unsigned short", "jushort"),
71  
72      /** The name of the unsigned int primitive type. */
73      UNSIGNED_INT("unsigned int", "juint"),
74  
75      /** The name of the unsigned long primitive type. */
76      UNSIGNED_LONG("unsigned long", "julong"),
77  
78      /** The name of the int8_t primitive type. */
79      INT8_T("int8_t", "int8_t"),
80  
81      /** The name of the uint8_t primitive type. */
82      UINT8_T("uint8_t", "uint8_t"),
83  
84      /** The name of the int16_t primitive type. */
85      INT16_T("int16_t", "int16_t"),
86  
87      /** The name of the uint16_t primitive type. */
88      UINT16_T("uint16_t", "uint16_t"),
89  
90      /** The name of the int32_t primitive type. */
91      INT32_T("int32_t", "int32_t"),
92  
93      /** The name of the uint32_t primitive type. */
94      UINT32_T("uint32_t", "uint32_t"),
95  
96      /** The name of the int64_t primitive type. */
97      INT64_T("int64_t", "int64_t"),
98  
99      /** The name of the uint64_t primitive type. */
100     UINT64_T("uint64_t", "uint64_t"),
101 
102     /** The name of the int_least8_t primitive type. */
103     INT_LEAST8_T("int_least8_t", "int_least8_t"),
104 
105     /** The name of the uint_least8_t primitive type. */
106     UINT_LEAST8_T("uint_least8_t", "uint_least8_t"),
107 
108     /** The name of the int_least16_t primitive type. */
109     INT_LEAST16_T("int_least16_t", "int_least16_t"),
110 
111     /** The name of the uint_least16_t primitive type. */
112     UINT_LEAST16_T("uint_least16_t", "uint_least16_t"),
113 
114     /** The name of the int_least32_t primitive type. */
115     INT_LEAST32_T("int_least32_t", "int_least32_t"),
116 
117     /** The name of the uint_least32_t primitive type. */
118     UINT_LEAST32_T("uint_least32_t", "uint_least32_t"),
119 
120     /** The name of the int_least64_t primitive type. */
121     INT_LEAST64_T("int_least64_t", "int_least64_t"),
122 
123     /** The name of the uint_least64_t primitive type. */
124     UINT_LEAST64_T("uint_least64_t", "uint_least64_t"),
125 
126     /** The name of the int_fast8_t primitive type. */
127     INT_FAST8_T("int_fast8_t", "int_fast8_t"),
128 
129     /** The name of the uint_fast8_t primitive type. */
130     UINT_FAST8_T("uint_fast8_t", "uint_fast8_t"),
131 
132     /** The name of the int_fast16_t primitive type. */
133     INT_FAST16_T("int_fast16_t", "int_fast16_t"),
134 
135     /** The name of the uint_fast16_t primitive type. */
136     UINT_FAST16_T("uint_fast16_t", "uint_fast16_t"),
137 
138     /** The name of the int_fast32_t primitive type. */
139     INT_FAST32_T("int_fast32_t", "int_fast32_t"),
140 
141     /** The name of the uint_fast32_t primitive type. */
142     UINT_FAST32_T("uint_fast32_t", "uint_fast32_t"),
143 
144     /** The name of the int_fast64_t primitive type. */
145     INT_FAST64_T("int_fast64_t", "int_fast64_t"),
146 
147     /** The name of the uint_fast64_t primitive type. */
148     UINT_FAST64_T("uint_fast64_t", "uint_fast64_t"),
149 
150     /** The name of the intptr_t primitive type. */
151     INTPTR_T("intptr_t", "intptr_t"),
152 
153     /** The name of the uintptr_t primitive type. */
154     UINTPTR_T("uintptr_t", "uintptr_t"),
155 
156     /** The name of the intmax_t primitive type. */
157     INTMAX_T("intmax_t", "intmax_t"),
158 
159     /** The name of the uintmax_t primitive type. */
160     UINTMAX_T("uintmax_t", "uintmax_t"),
161 
162     /** The name of the size_t primitive type. */
163     SIZE_T("size_t", "size_t"),
164 
165     /** The name of the size_t primitive type. */
166     PTRDIFF_T("ptrdiff_t", "ptrdiff_t"),
167 
168     /** The name of the size_t primitive type. */
169     WCHAR_T("wchar_t", "wchar_t");
170 
171     private final String idlTypeName;
172     private final String cType;
173 
174     PrimitiveTypeEnum(final String idlType, final String cType) {
175       this.idlTypeName = idlType;
176       this.cType = cType;
177     }
178 
179     /**
180      * @return the IDL representation of the primitive type.
181      */
182     public String getIdlTypeName() {
183       return idlTypeName;
184     }
185 
186     /**
187      * @return the equivalent C type.
188      */
189     public String getCType() {
190       return cType;
191     }
192 
193     /**
194      * Returns the enumeration constant that correspond to the given IDL type
195      * name.
196      * 
197      * @param idlTypeName the name of the primitive type as it is found in the
198      *            IDL.
199      * @return the corresponding enumeration constant.
200      * @throws IllegalArgumentException if the given IDL type name does not
201      *             correspond to a primitive type.
202      */
203     public static PrimitiveTypeEnum fromIDLTypeName(final String idlTypeName) {
204       for (final PrimitiveTypeEnum t : values()) {
205         if (t.idlTypeName.equals(idlTypeName)) {
206           return t;
207         }
208       }
209       throw new IllegalArgumentException(
210           "The given IDL type name does not correspond to a primitive type.");
211     }
212   };
213 
214   /**
215    * Returns the name of the primitive type.
216    * 
217    * @return the name of the primitive type.
218    */
219   String getName();
220 
221   /**
222    * Set the name of the primitive type.
223    * 
224    * @param name the name of the primitive type to be set.
225    */
226   void setName(String name);
227 }