Synopsis - Cross-Reference

File: /Synopsis/Parsers/IDL/idltype.h
  1// -*- c++ -*-
  2//                          Package   : omniidl
  3// idltype.h                Created on: 1999/10/18
  4//			    Author    : Duncan Grisby (dpg1)
  5//
  6//    Copyright (C) 1999 AT&T Laboratories Cambridge
  7//
  8//  This file is part of omniidl.
  9//
 10//  omniidl is free software; you can redistribute it and/or modify it
 11//  under the terms of the GNU General Public License as published by
 12//  the Free Software Foundation; either version 2 of the License, or
 13//  (at your option) any later version.
 14//
 15//  This program is distributed in the hope that it will be useful,
 16//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 17//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18//  General Public License for more details.
 19//
 20//  You should have received a copy of the GNU General Public License
 21//  along with this program; if not, write to the Free Software
 22//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 23//  02111-1307, USA.
 24//
 25// Description:
 26//   
 27//   Type objects
 28
 29// $Id: idltype.h,v 1.8.2.1 2003/03/23 21:01:44 dgrisby Exp $
 30// $Log: idltype.h,v $
 31// Revision 1.8.2.1  2003/03/23 21:01:44  dgrisby
 32// Start of omniORB 4.1.x development branch.
 33//
 34// Revision 1.5.2.4  2001/03/13 10:32:13  dpg1
 35// Fixed point support.
 36//
 37// Revision 1.5.2.3  2000/11/01 12:45:57  dpg1
 38// Update to CORBA 2.4 specification.
 39//
 40// Revision 1.5.2.2  2000/10/27 16:31:10  dpg1
 41// Clean up of omniidl dependencies and types, from omni3_develop.
 42//
 43// Revision 1.5.2.1  2000/07/17 10:36:05  sll
 44// Merged from omni3_develop the diff between omni3_0_0_pre3 and omni3_0_0.
 45//
 46// Revision 1.6  2000/07/13 15:25:52  dpg1
 47// Merge from omni3_develop for 3.0 release.
 48//
 49// Revision 1.3  1999/11/17 17:16:59  dpg1
 50// Changes to remove static initialisation of objects.
 51//
 52// Revision 1.2  1999/10/29 15:44:23  dpg1
 53// DeclaredType() now takes extra DeclRepoId* argument.
 54//
 55// Revision 1.1  1999/10/27 14:05:54  dpg1
 56// *** empty log message ***
 57//
 58
 59#ifndef _idltype_h_
 60#define _idltype_h_
 61
 62#include <idlutil.h>
 63#include <idlvisitor.h>
 64#include <idlscope.h>
 65
 66// Note on Type object memory management
 67//
 68// All type objects which can be are statically allocated; all others
 69// are allocated on the heap. When Decl objects receive a pointer to a
 70// type object, they should call its shouldDelete() function to see if
 71// they are responsible for deleting the object. This only returns
 72// true for those heap-allocated objects which do not have an
 73// associated Decl object. Type objects created by Decl constructors
 74// must be deleted by the Decls' destructors.
 75
 76
 77class IdlType {
 78public:
 79
 80  enum Kind {
 81    tk_null               = 0,
 82    tk_void               = 1,
 83    tk_short              = 2,
 84    tk_long               = 3,
 85    tk_ushort             = 4,
 86    tk_ulong              = 5,
 87    tk_float              = 6,
 88    tk_double             = 7,
 89    tk_boolean            = 8,
 90    tk_char	          = 9,
 91    tk_octet              = 10,
 92    tk_any	          = 11,
 93    tk_TypeCode           = 12,
 94    tk_Principal          = 13,
 95    tk_objref             = 14,
 96    tk_struct             = 15,
 97    tk_union              = 16,
 98    tk_enum	          = 17,
 99    tk_string             = 18,
100    tk_sequence           = 19,
101    tk_array              = 20,
102    tk_alias              = 21,
103    tk_except             = 22,
104    tk_longlong           = 23,
105    tk_ulonglong          = 24,
106    tk_longdouble         = 25,
107    tk_wchar              = 26,
108    tk_wstring            = 27,
109    tk_fixed              = 28,
110    tk_value              = 29,
111    tk_value_box          = 30,
112    tk_native             = 31,
113    tk_abstract_interface = 32,
114    tk_local_interface    = 33,
115
116    // omniidl-specific kinds
117    ot_structforward      = 100,
118    ot_unionforward       = 101
119  };
120
121  IdlType(Kind k) : kind_(k), local_(0) { }
122  virtual ~IdlType() {};
123
124  Kind        kind()         const { return kind_; }
125  const char* kindAsString() const;
126
127  IDL_Boolean local()        const { return local_; }
128  void        setLocal()           { local_ = 1; }
129  // True if this is a "local" type which must not be transmitted
130  // across the network.
131
132  IdlType*    unalias();
133  // Return an equivalent IdlType object with aliases stripped.
134
135  virtual IDL_Boolean shouldDelete() = 0;
136
137  virtual void accept(TypeVisitor& visitor) = 0;
138
139  // Find a type given a name. Marks the name used in current scope
140  static IdlType* scopedNameToType(const char* file, int line,
141				   const ScopedName* sn);
142  static void init();
143
144private:
145  Kind        kind_;
146  IDL_Boolean local_;
147  static IDL_Boolean initialised_;
148};
149
150
151class BaseType : public IdlType {
152public:
153  BaseType(Kind k) : IdlType(k) {}
154  virtual ~BaseType() {}
155
156  IDL_Boolean shouldDelete() { return 0; }
157
158  void accept(TypeVisitor& visitor) { visitor.visitBaseType(this); }
159
160  // Static base type singletons
161  static BaseType* nullType;
162  static BaseType* voidType;
163  static BaseType* shortType;
164  static BaseType* longType;
165  static BaseType* ushortType;
166  static BaseType* ulongType;
167  static BaseType* floatType;
168  static BaseType* doubleType;
169  static BaseType* booleanType;
170  static BaseType* charType;
171  static BaseType* octetType;
172  static BaseType* anyType;
173  static BaseType* TypeCodeType;
174  static BaseType* PrincipalType;
175  static BaseType* longlongType;
176  static BaseType* ulonglongType;
177  static BaseType* longdoubleType;
178  static BaseType* wcharType;
179};
180
181
182//
183// Strings can be used like base types without a declaration. eg:
184//
185//   void op(in string<10> s);
186//
187// therefore, the String type must include its bound here, rather than
188// relying on looking at the corresponding declaration
189//
190
191class StringType : public IdlType {
192public:
193
194  StringType(IDL_ULong bound) : IdlType(tk_string), bound_(bound) { }
195  virtual ~StringType() {}
196
197  IDL_ULong   bound()        { return bound_; }
198  IDL_Boolean shouldDelete() { return bound_ ? 1 : 0; }
199
200  void accept(TypeVisitor& visitor) { visitor.visitStringType(this); }
201
202  static StringType* unboundedStringType;
203
204private:
205  IDL_ULong bound_;
206};
207
208
209class WStringType : public IdlType {
210public:
211  WStringType(IDL_ULong bound) : IdlType(tk_wstring), bound_(bound) { }
212  virtual ~WStringType() {}
213
214  IDL_ULong   bound()        { return bound_; }
215  IDL_Boolean shouldDelete() { return bound_ ? 1 : 0; }
216
217  void accept(TypeVisitor& visitor) { visitor.visitWStringType(this); }
218
219  static WStringType* unboundedWStringType;
220
221private:
222  IDL_ULong bound_;
223};
224
225//
226// Sequences are never declared. They either appear as
227//
228//   typedef sequence <...> ...
229//
230// or inside a struct or union
231//
232
233class SequenceType : public IdlType {
234public:
235  SequenceType(IdlType* seqType, IDL_ULong bound) :
236    IdlType(tk_sequence), seqType_(seqType), bound_(bound)
237  {
238    if (seqType && seqType->local()) setLocal();
239  }
240
241  virtual ~SequenceType() {}
242
243  IdlType*    seqType()      { return seqType_; }
244  IDL_ULong   bound()        { return bound_; }
245  IDL_Boolean shouldDelete() { return 1; }
246
247  void accept(TypeVisitor& visitor) { visitor.visitSequenceType(this); }
248
249private:
250  IdlType*     seqType_;
251  IDL_ULong bound_;
252};
253
254//
255// Same goes for fixed
256//
257
258class FixedType : public IdlType {
259public:
260  FixedType(IDL_Short digits, IDL_Short scale) :
261    IdlType(tk_fixed), digits_(digits), scale_(scale) { }
262
263  virtual ~FixedType() {}
264
265  IDL_UShort  digits()       { return digits_; }
266  IDL_UShort  scale()        { return scale_; }
267  IDL_Boolean shouldDelete() { return 1; }
268
269  void accept(TypeVisitor& visitor) { visitor.visitFixedType(this); }
270
271private:
272  IDL_UShort digits_;
273  IDL_UShort scale_;
274};
275
276
277//
278// All other types must be declared, at least implicitly, so they have
279// an associated declaration object
280//
281
282class Decl;
283class DeclRepoId;
284
285class DeclaredType : public IdlType {
286public:
287  DeclaredType(Kind k, Decl* decl, DeclRepoId* declRepoId)
288    : IdlType(k), decl_(decl), declRepoId_(declRepoId) {}
289
290  virtual ~DeclaredType() {}
291
292  Decl*       decl()         { return decl_; }
293  DeclRepoId* declRepoId()   { return declRepoId_; }
294
295  IDL_Boolean shouldDelete() { return 0; }
296
297  void accept(TypeVisitor& visitor) { visitor.visitDeclaredType(this); }
298
299  static DeclaredType* corbaObjectType;
300
301private:
302  Decl*       decl_;
303  DeclRepoId* declRepoId_;
304};
305
306
307//
308// TypeSpec class is used to distinguish simple_type_spec from
309// constr_type_spec in the grammar
310//
311
312class TypeSpec {
313public:
314  TypeSpec(IdlType* type, IDL_Boolean constr)
315    : type_(type), constr_(constr) {}
316  ~TypeSpec() {}
317
318  IdlType*    type()   const { return type_; }
319  IDL_Boolean constr() const { return constr_; }
320
321private:
322  IdlType*    type_;
323  IDL_Boolean constr_;
324};
325
326
327#endif // _idltype_h_