1 // -*- c++ -*-
2 // Package : omniidl
3 // idltype.cc Created on: 1999/10/21
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, see http://www.gnu.org/licenses/
22 //
23 // Description:
24 //
25 // Type objects
26
27 #include <idltype.h>
28 #include <idlast.h>
29 #include <idlerr.h>
30
31 const char*
32 IdlType::
kindAsString() const33 kindAsString() const
34 {
35 switch(kind_) {
36 case tk_null: return "null";
37 case tk_void: return "void";
38 case tk_short: return "short";
39 case tk_long: return "long";
40 case tk_ushort: return "unsigned short";
41 case tk_ulong: return "unsigned long";
42 case tk_float: return "float";
43 case tk_double: return "double";
44 case tk_boolean: return "boolean";
45 case tk_char: return "char";
46 case tk_octet: return "octet";
47 case tk_any: return "any";
48 case tk_TypeCode: return "CORBA::TypeCode";
49 case tk_Principal: return "CORBA::Principal";
50 case tk_objref: return "interface";
51 case tk_struct: return "struct";
52 case tk_union: return "union";
53 case tk_enum: return "enum";
54 case tk_string: return "string";
55 case tk_sequence: return "sequence";
56 case tk_array: return "array";
57 case tk_alias: return "typedef";
58 case tk_except: return "exception";
59 case tk_longlong: return "long long";
60 case tk_ulonglong: return "unsigned long long";
61 case tk_longdouble: return "long double";
62 case tk_wchar: return "wchar";
63 case tk_wstring: return "wstring";
64 case tk_fixed: return "fixed";
65 case tk_value: return "value";
66 case tk_value_box: return "value box";
67 case tk_native: return "native";
68 case tk_abstract_interface: return "abstract interface";
69 case tk_local_interface: return "local interface";
70 case ot_structforward: return "forward struct";
71 case ot_unionforward: return "forward union";
72 }
73 assert(0);
74 return ""; // To keep MSVC happy
75 }
76
77 IdlType*
78 IdlType::
unalias()79 unalias()
80 {
81 IdlType* t = this;
82 while (t && t->kind() == tk_alias) {
83 if (((Declarator*)((DeclaredType*)t)->decl())->sizes()) break;
84 t = ((Declarator*)((DeclaredType*)t)->decl())->alias()->aliasType();
85 }
86 return t;
87 }
88
89
90 IdlType*
91 IdlType::
scopedNameToType(const char * file,int line,const ScopedName * sn)92 scopedNameToType(const char* file, int line, const ScopedName* sn)
93 {
94 const Scope::Entry* se = Scope::current()->findForUse(sn, file, line);
95
96 if (se) {
97 if (se->kind() == Scope::Entry::E_DECL) {
98 IdlType *t = se->idltype();
99 if (t) return t;
100 }
101 char* ssn = sn->toString();
102 IdlError(file, line, "'%s' is not a type", ssn);
103 IdlErrorCont(se->file(), se->line(), "('%s' declared here)", ssn);
104 delete [] ssn;
105 }
106 return 0;
107 }
108
109 // Static type object pointers
110 IDL_Boolean IdlType::initialised_ = 0;
111 BaseType* BaseType::nullType = 0;
112 BaseType* BaseType::voidType = 0;
113 BaseType* BaseType::shortType = 0;
114 BaseType* BaseType::longType = 0;
115 BaseType* BaseType::ushortType = 0;
116 BaseType* BaseType::ulongType = 0;
117 BaseType* BaseType::floatType = 0;
118 BaseType* BaseType::doubleType = 0;
119 BaseType* BaseType::booleanType = 0;
120 BaseType* BaseType::charType = 0;
121 BaseType* BaseType::octetType = 0;
122 BaseType* BaseType::anyType = 0;
123 BaseType* BaseType::TypeCodeType = 0;
124 BaseType* BaseType::PrincipalType = 0;
125 BaseType* BaseType::longlongType = 0;
126 BaseType* BaseType::ulonglongType = 0;
127 BaseType* BaseType::longdoubleType = 0;
128 BaseType* BaseType::wcharType = 0;
129 StringType* StringType::unboundedStringType = 0;
130 WStringType* WStringType::unboundedWStringType = 0;
131 DeclaredType* DeclaredType::corbaObjectType = 0;
132
133
134 void
135 IdlType::
init()136 init()
137 {
138 if (!initialised_) {
139 BaseType::nullType = new BaseType(IdlType::tk_null);
140 BaseType::voidType = new BaseType(IdlType::tk_void);
141 BaseType::shortType = new BaseType(IdlType::tk_short);
142 BaseType::longType = new BaseType(IdlType::tk_long);
143 BaseType::ushortType = new BaseType(IdlType::tk_ushort);
144 BaseType::ulongType = new BaseType(IdlType::tk_ulong);
145 BaseType::floatType = new BaseType(IdlType::tk_float);
146 BaseType::doubleType = new BaseType(IdlType::tk_double);
147 BaseType::booleanType = new BaseType(IdlType::tk_boolean);
148 BaseType::charType = new BaseType(IdlType::tk_char);
149 BaseType::octetType = new BaseType(IdlType::tk_octet);
150 BaseType::anyType = new BaseType(IdlType::tk_any);
151 BaseType::TypeCodeType = new BaseType(IdlType::tk_TypeCode);
152 BaseType::PrincipalType = new BaseType(IdlType::tk_Principal);
153 BaseType::longlongType = new BaseType(IdlType::tk_longlong);
154 BaseType::ulonglongType = new BaseType(IdlType::tk_ulonglong);
155 BaseType::longdoubleType = new BaseType(IdlType::tk_longdouble);
156 BaseType::wcharType = new BaseType(IdlType::tk_wchar);
157 StringType::unboundedStringType = new StringType(0);
158 WStringType::unboundedWStringType = new WStringType(0);
159 DeclaredType::corbaObjectType = new DeclaredType(IdlType::tk_objref,
160 0, 0);
161 initialised_ = 1;
162 }
163 }
164