Synopsis - Cross-Reference
File: /Synopsis/Parsers/IDL/idltype.cc1// -*- 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, 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.cc,v 1.10.2.1 2003/03/23 21:01:44 dgrisby Exp $ 30// $Log: idltype.cc,v $ 31// Revision 1.10.2.1 2003/03/23 21:01:44 dgrisby 32// Start of omniORB 4.1.x development branch. 33// 34// Revision 1.7.2.4 2001/10/17 16:48:34 dpg1 35// Minor error message tweaks 36// 37// Revision 1.7.2.3 2000/11/01 12:45:57 dpg1 38// Update to CORBA 2.4 specification. 39// 40// Revision 1.7.2.2 2000/10/27 16:31:10 dpg1 41// Clean up of omniidl dependencies and types, from omni3_develop. 42// 43// Revision 1.7.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.8 2000/07/13 15:25:52 dpg1 47// Merge from omni3_develop for 3.0 release. 48// 49// Revision 1.5.2.1 2000/03/06 10:40:29 dpg1 50// Typo in string constant. 51// 52// Revision 1.5 1999/11/17 17:16:59 dpg1 53// Changes to remove static initialisation of objects. 54// 55// Revision 1.4 1999/11/04 17:16:54 dpg1 56// Changes for NT. 57// 58// Revision 1.3 1999/11/02 17:07:24 dpg1 59// Changes to compile on Solaris. 60// 61// Revision 1.2 1999/10/29 15:44:14 dpg1 62// DeclaredType() now takes extra DeclRepoId* argument. 63// 64// Revision 1.1 1999/10/27 14:05:54 dpg1 65// *** empty log message *** 66// 67 68#include <idltype.h> 69#include <idlast.h> 70#include <idlerr.h> 71 72const char* 73IdlType:: 74kindAsString() const 75{ 76 switch(kind_) { 77 case tk_null: return "null"; 78 case tk_void: return "void"; 79 case tk_short: return "short"; 80 case tk_long: return "long"; 81 case tk_ushort: return "unsigned short"; 82 case tk_ulong: return "unsigned long"; 83 case tk_float: return "float"; 84 case tk_double: return "double"; 85 case tk_boolean: return "boolean"; 86 case tk_char: return "char"; 87 case tk_octet: return "octet"; 88 case tk_any: return "any"; 89 case tk_TypeCode: return "CORBA::TypeCode"; 90 case tk_Principal: return "CORBA::Principal"; 91 case tk_objref: return "interface"; 92 case tk_struct: return "struct"; 93 case tk_union: return "union"; 94 case tk_enum: return "enum"; 95 case tk_string: return "string"; 96 case tk_sequence: return "sequence"; 97 case tk_array: return "array"; 98 case tk_alias: return "typedef"; 99 case tk_except: return "exception"; 100 case tk_longlong: return "long long"; 101 case tk_ulonglong: return "unsigned long long"; 102 case tk_longdouble: return "long double"; 103 case tk_wchar: return "wchar"; 104 case tk_wstring: return "wstring"; 105 case tk_fixed: return "fixed"; 106 case tk_value: return "value"; 107 case tk_value_box: return "value box"; 108 case tk_native: return "native"; 109 case tk_abstract_interface: return "abstract interface"; 110 case tk_local_interface: return "local interface"; 111 case ot_structforward: return "forward struct"; 112 case ot_unionforward: return "forward union"; 113 } 114 assert(0); 115 return ""; // To keep MSVC happy 116} 117 118IdlType* 119IdlType:: 120unalias() 121{ 122 IdlType* t = this; 123 while (t && t->kind() == tk_alias) { 124 if (((Declarator*)((DeclaredType*)t)->decl())->sizes()) break; 125 t = ((Declarator*)((DeclaredType*)t)->decl())->alias()->aliasType(); 126 } 127 return t; 128} 129 130 131IdlType* 132IdlType:: 133scopedNameToType(const char* file, int line, const ScopedName* sn) 134{ 135 const Scope::Entry* se = Scope::current()->findForUse(sn, file, line); 136 137 if (se) { 138 if (se->kind() == Scope::Entry::E_DECL) { 139 IdlType *t = se->idltype(); 140 if (t) return t; 141 } 142 char* ssn = sn->toString(); 143 IdlError(file, line, "'%s' is not a type", ssn); 144 IdlErrorCont(se->file(), se->line(), "('%s' declared here)", ssn); 145 delete [] ssn; 146 } 147 return 0; 148} 149 150// Static type object pointers 151IDL_Boolean IdlType::initialised_ = 0; 152BaseType* BaseType::nullType = 0; 153BaseType* BaseType::voidType = 0; 154BaseType* BaseType::shortType = 0; 155BaseType* BaseType::longType = 0; 156BaseType* BaseType::ushortType = 0; 157BaseType* BaseType::ulongType = 0; 158BaseType* BaseType::floatType = 0; 159BaseType* BaseType::doubleType = 0; 160BaseType* BaseType::booleanType = 0; 161BaseType* BaseType::charType = 0; 162BaseType* BaseType::octetType = 0; 163BaseType* BaseType::anyType = 0; 164BaseType* BaseType::TypeCodeType = 0; 165BaseType* BaseType::PrincipalType = 0; 166BaseType* BaseType::longlongType = 0; 167BaseType* BaseType::ulonglongType = 0; 168BaseType* BaseType::longdoubleType = 0; 169BaseType* BaseType::wcharType = 0; 170StringType* StringType::unboundedStringType = 0; 171WStringType* WStringType::unboundedWStringType = 0; 172DeclaredType* DeclaredType::corbaObjectType = 0; 173 174 175void 176IdlType:: 177init() 178{ 179 if (!initialised_) { 180 BaseType::nullType = new BaseType(IdlType::tk_null); 181 BaseType::voidType = new BaseType(IdlType::tk_void); 182 BaseType::shortType = new BaseType(IdlType::tk_short); 183 BaseType::longType = new BaseType(IdlType::tk_long); 184 BaseType::ushortType = new BaseType(IdlType::tk_ushort); 185 BaseType::ulongType = new BaseType(IdlType::tk_ulong); 186 BaseType::floatType = new BaseType(IdlType::tk_float); 187 BaseType::doubleType = new BaseType(IdlType::tk_double); 188 BaseType::booleanType = new BaseType(IdlType::tk_boolean); 189 BaseType::charType = new BaseType(IdlType::tk_char); 190 BaseType::octetType = new BaseType(IdlType::tk_octet); 191 BaseType::anyType = new BaseType(IdlType::tk_any); 192 BaseType::TypeCodeType = new BaseType(IdlType::tk_TypeCode); 193 BaseType::PrincipalType = new BaseType(IdlType::tk_Principal); 194 BaseType::longlongType = new BaseType(IdlType::tk_longlong); 195 BaseType::ulonglongType = new BaseType(IdlType::tk_ulonglong); 196 BaseType::longdoubleType = new BaseType(IdlType::tk_longdouble); 197 BaseType::wcharType = new BaseType(IdlType::tk_wchar); 198 StringType::unboundedStringType = new StringType(0); 199 WStringType::unboundedWStringType = new WStringType(0); 200 DeclaredType::corbaObjectType = new DeclaredType(IdlType::tk_objref, 201 0, 0); 202 initialised_ = 1; 203 } 204}