src/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/Util.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25 /*
aoqi@0 26 * COMPONENT_NAME: idl.toJava
aoqi@0 27 *
aoqi@0 28 * ORIGINS: 27
aoqi@0 29 *
aoqi@0 30 * Licensed Materials - Property of IBM
aoqi@0 31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
aoqi@0 32 * RMI-IIOP v1.0
aoqi@0 33 *
aoqi@0 34 */
aoqi@0 35
aoqi@0 36 package com.sun.tools.corba.se.idl.toJavaPortable;
aoqi@0 37
aoqi@0 38 // Notes:
aoqi@0 39 // -F46838.4<klr> Ported -td option from toJava.
aoqi@0 40 // -10/17/98 KLR Ported fix for d48911 from toJava
aoqi@0 41 // -10/18/98 KLR Ported fix from toJava for "unsigned long" constants
aoqi@0 42 // -F46082.51<daz> Removed code to collect makefile list generation inforamtion
aoqi@0 43 // from getStream(); see f46830.
aoqi@0 44 // -F46082.51<daz> Removed -stateful feature: methods javaStatefulName(String)
aoqi@0 45 // and javaStatefulName(SymtabEntry) are obsolete, supplanted by javaName().
aoqi@0 46 // -D54640<daz> Represent unsigned long long expressions with their computed
aoqi@0 47 // value rather than their actual representation (see notes in method
aoqi@0 48 // parseTerminal(), parseBinary(), and parseUnary().)
aoqi@0 49 // -D58319<daz> Add getVersion() method.
aoqi@0 50 // -D48034<daz> Import Helper classes for typedef struct members when generating
aoqi@0 51 // helper. See method addImportLines().
aoqi@0 52 // -D59851<daz> Modify to enable QuickTest build. (pending)
aoqi@0 53 // -D42256<daz> Determine import lines for template types, which may specify any
aoqi@0 54 // positive int., constant expression for a boundary. Such expression containing
aoqi@0 55 // non-literal contansts previously caused problems when appearing in constructs
aoqi@0 56 // structs, unions, exceptions, typedefs, operation types and parameters,
aoqi@0 57 // attributes; and of course, sequences, strings.
aoqi@0 58 // -D59063<daz> Add helper for global exception to stub import list.
aoqi@0 59 // -D58951<daz> Publicise members for QuickTest.
aoqi@0 60 // -D59421<klr> Change ValueBaseHolder to SerializableHolder
aoqi@0 61 // -D59596<klr> Prevent accesses to elements of empty Vectors.
aoqi@0 62 // -D59771<daz> Add import stmt for Helper of global type in stubs.
aoqi@0 63 // -D59355<daz> Remove target dir. from filename when writing to prolog.
aoqi@0 64 // -D59437<daz> Fill typename information for value boxes.
aoqi@0 65 // -D62023<klr> Don't import ValueBase*
aoqi@0 66 // -D62023<klr> Add corbaLevel
aoqi@0 67
aoqi@0 68 import java.io.File;
aoqi@0 69 import java.io.PrintWriter;
aoqi@0 70 import java.math.BigInteger;
aoqi@0 71 import java.text.DateFormat;
aoqi@0 72 import java.util.Date;
aoqi@0 73 import java.util.Enumeration;
aoqi@0 74 import java.util.Hashtable;
aoqi@0 75 import java.util.Locale;
aoqi@0 76 import java.util.Vector;
aoqi@0 77
aoqi@0 78 import com.sun.tools.corba.se.idl.ConstEntry;
aoqi@0 79 import com.sun.tools.corba.se.idl.EnumEntry;
aoqi@0 80 import com.sun.tools.corba.se.idl.ExceptionEntry;
aoqi@0 81 import com.sun.tools.corba.se.idl.GenFileStream;
aoqi@0 82 import com.sun.tools.corba.se.idl.InterfaceEntry;
aoqi@0 83 import com.sun.tools.corba.se.idl.MethodEntry;
aoqi@0 84 import com.sun.tools.corba.se.idl.NativeEntry;
aoqi@0 85 import com.sun.tools.corba.se.idl.ParameterEntry;
aoqi@0 86 import com.sun.tools.corba.se.idl.PrimitiveEntry;
aoqi@0 87 import com.sun.tools.corba.se.idl.SequenceEntry;
aoqi@0 88 import com.sun.tools.corba.se.idl.StringEntry;
aoqi@0 89 import com.sun.tools.corba.se.idl.StructEntry;
aoqi@0 90 import com.sun.tools.corba.se.idl.SymtabEntry;
aoqi@0 91 import com.sun.tools.corba.se.idl.TypedefEntry;
aoqi@0 92 import com.sun.tools.corba.se.idl.UnionBranch;
aoqi@0 93 import com.sun.tools.corba.se.idl.UnionEntry;
aoqi@0 94 import com.sun.tools.corba.se.idl.ValueEntry;
aoqi@0 95 import com.sun.tools.corba.se.idl.ValueBoxEntry;
aoqi@0 96 import com.sun.tools.corba.se.idl.InterfaceState;
aoqi@0 97
aoqi@0 98 import com.sun.tools.corba.se.idl.constExpr.*;
aoqi@0 99
aoqi@0 100 /**
aoqi@0 101 * Class Util is a repository of static members available for general
aoqi@0 102 * use by the IDL parser framework and any generator extensions.
aoqi@0 103 **/
aoqi@0 104 public class Util extends com.sun.tools.corba.se.idl.Util
aoqi@0 105 {
aoqi@0 106 // <d58319>
aoqi@0 107 /**
aoqi@0 108 * Fetch the version number of this build of the IDL-to-Java (portable)
aoqi@0 109 * compiler from the appropriate properties file.
aoqi@0 110 * @return the version number of this compiler build.
aoqi@0 111 **/
aoqi@0 112 public static String getVersion ()
aoqi@0 113 {
aoqi@0 114 return com.sun.tools.corba.se.idl.Util.getVersion ("com/sun/tools/corba/se/idl/toJavaPortable/toJavaPortable.prp");
aoqi@0 115 } // getVersion
aoqi@0 116
aoqi@0 117 /**
aoqi@0 118 * This method is called by Setup.preEmit, so
aoqi@0 119 * symbolTable is available for all Util methods.
aoqi@0 120 **/
aoqi@0 121 static void setSymbolTable (Hashtable symtab)
aoqi@0 122 {
aoqi@0 123 symbolTable = symtab;
aoqi@0 124 } // setSymbolTable
aoqi@0 125
aoqi@0 126 public static void setPackageTranslation( Hashtable pkgtrans )
aoqi@0 127 {
aoqi@0 128 packageTranslation = pkgtrans ;
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 public static boolean isInterface (String name)
aoqi@0 132 {
aoqi@0 133 return isInterface (name, symbolTable);
aoqi@0 134 } // isInterface
aoqi@0 135
aoqi@0 136 static String arrayInfo (Vector arrayInfo)
aoqi@0 137 {
aoqi@0 138 int arrays = arrayInfo.size ();
aoqi@0 139 String info = "";
aoqi@0 140 Enumeration e = arrayInfo.elements ();
aoqi@0 141 while (e.hasMoreElements ())
aoqi@0 142 info = info + '[' + parseExpression ((Expression)e.nextElement ()) + ']';
aoqi@0 143 return info;
aoqi@0 144 } // arrayInfo
aoqi@0 145
aoqi@0 146 // <d58951> static String sansArrayInfo (Vector arrayInfo)
aoqi@0 147 public static String sansArrayInfo (Vector arrayInfo)
aoqi@0 148 {
aoqi@0 149 int arrays = arrayInfo.size ();
aoqi@0 150 String brackets = "";
aoqi@0 151 for (int i = 0; i < arrays; ++i)
aoqi@0 152 brackets = brackets + "[]";
aoqi@0 153 return brackets;
aoqi@0 154 } // sansArrayInfo
aoqi@0 155
aoqi@0 156 // <d58951> static String sansArrayInfo (String name)
aoqi@0 157 static public String sansArrayInfo (String name)
aoqi@0 158 {
aoqi@0 159 int index = name.indexOf ('[');
aoqi@0 160 if (index >= 0)
aoqi@0 161 {
aoqi@0 162 String array = name.substring (index);
aoqi@0 163 name = name.substring (0, index);
aoqi@0 164 while (!array.equals (""))
aoqi@0 165 {
aoqi@0 166 name = name + "[]";
aoqi@0 167 array = array.substring (array.indexOf (']') + 1);
aoqi@0 168 }
aoqi@0 169 }
aoqi@0 170 return name;
aoqi@0 171 } // sansArrayInfo
aoqi@0 172
aoqi@0 173 /**
aoqi@0 174 * Given a symbol table entry, return the name of
aoqi@0 175 * the file which should be created.
aoqi@0 176 **/
aoqi@0 177 public static String fileName (SymtabEntry entry, String extension )
aoqi@0 178 {
aoqi@0 179 NameModifier nm = new NameModifierImpl() ;
aoqi@0 180 return fileName( entry, nm, extension ) ;
aoqi@0 181 } // fileName
aoqi@0 182
aoqi@0 183 public static String fileName (SymtabEntry entry, NameModifier modifier, String extension )
aoqi@0 184 {
aoqi@0 185 // This may not be the most appropriate place for
aoqi@0 186 // the mkdir calls, but it's common to everything:
aoqi@0 187 String pkg = containerFullName (entry.container ());
aoqi@0 188 if (pkg != null && !pkg.equals (""))
aoqi@0 189 mkdir (pkg);
aoqi@0 190
aoqi@0 191 String name = entry.name ();
aoqi@0 192 name = modifier.makeName( name ) + extension ;
aoqi@0 193 if (pkg != null && !pkg.equals (""))
aoqi@0 194 name = pkg + '/' + name;
aoqi@0 195
aoqi@0 196 return name.replace ('/', File.separatorChar);
aoqi@0 197 } // fileName
aoqi@0 198
aoqi@0 199 public static GenFileStream stream (SymtabEntry entry, String extension)
aoqi@0 200 {
aoqi@0 201 NameModifier nm = new NameModifierImpl() ;
aoqi@0 202 return stream(entry, nm, extension);
aoqi@0 203 } // stream
aoqi@0 204
aoqi@0 205 public static GenFileStream stream (SymtabEntry entry, NameModifier modifier, String extension )
aoqi@0 206 {
aoqi@0 207 return getStream ( fileName (entry,modifier,extension), entry ) ;
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 public static GenFileStream getStream (String name, SymtabEntry entry)
aoqi@0 211 {
aoqi@0 212 // <f46838.4>
aoqi@0 213 String absPathName = ((Arguments)Compile.compiler.arguments).targetDir + name;
aoqi@0 214 if (Compile.compiler.arguments.keepOldFiles && new File (absPathName).exists ())
aoqi@0 215 return null;
aoqi@0 216 else
aoqi@0 217 // Write the data to the file stream
aoqi@0 218 return new GenFileStream (absPathName);
aoqi@0 219 } // getStream
aoqi@0 220
aoqi@0 221 public static String containerFullName( SymtabEntry container)
aoqi@0 222 {
aoqi@0 223 String name = doContainerFullName( container ) ;
aoqi@0 224 if (packageTranslation.size() > 0)
aoqi@0 225 name = translate( name ) ;
aoqi@0 226 return name ;
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 public static String translate( String name )
aoqi@0 230 {
aoqi@0 231 String head = name ;
aoqi@0 232 String tail = "" ;
aoqi@0 233 int index ;
aoqi@0 234 String trname ;
aoqi@0 235
aoqi@0 236 // Check for package name translations, starting with the
aoqi@0 237 // most specific match.
aoqi@0 238 do {
aoqi@0 239 trname = (String)(packageTranslation.get( head )) ;
aoqi@0 240 if (trname != null)
aoqi@0 241 return trname + tail ;
aoqi@0 242
aoqi@0 243 index = head.lastIndexOf( '/' ) ;
aoqi@0 244 if (index >= 0) {
aoqi@0 245 tail = head.substring( index ) + tail ;
aoqi@0 246 head = head.substring( 0, index ) ;
aoqi@0 247 }
aoqi@0 248 } while (index >= 0) ;
aoqi@0 249
aoqi@0 250 return name ;
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 private static String doContainerFullName (SymtabEntry container)
aoqi@0 254 {
aoqi@0 255 String name = "";
aoqi@0 256
aoqi@0 257 if (container == null)
aoqi@0 258 name = "";
aoqi@0 259 else
aoqi@0 260 {
aoqi@0 261 if (container instanceof InterfaceEntry ||
aoqi@0 262 container instanceof StructEntry ||
aoqi@0 263 container instanceof UnionEntry)
aoqi@0 264 name = container.name () + "Package";
aoqi@0 265 else
aoqi@0 266 name = container.name ();
aoqi@0 267
aoqi@0 268 if (container.container () != null &&
aoqi@0 269 !container.container ().name ().equals (""))
aoqi@0 270 name = doContainerFullName (container.container ()) + '/' + name;
aoqi@0 271 }
aoqi@0 272
aoqi@0 273 return name;
aoqi@0 274 } // doContainerFullName
aoqi@0 275
aoqi@0 276 /**
aoqi@0 277 * Given a SymtabEntry, return the string which should be used
aoqi@0 278 * for this entry. Enums are converted to ints, typedefs and
aoqi@0 279 * sequences are converted to their info types. javaQualifiedName
aoqi@0 280 * does not do any of these conversions.
aoqi@0 281 **/
aoqi@0 282 public static String javaName (SymtabEntry entry)
aoqi@0 283 {
aoqi@0 284 // First get the real name of this type
aoqi@0 285 String name = "";
aoqi@0 286 if (entry instanceof TypedefEntry || entry instanceof SequenceEntry)
aoqi@0 287 try
aoqi@0 288 {
aoqi@0 289 name = sansArrayInfo ((String)entry.dynamicVariable (Compile.typedefInfo));
aoqi@0 290 }
aoqi@0 291 catch (NoSuchFieldException e)
aoqi@0 292 {
aoqi@0 293 name = entry.name ();
aoqi@0 294 }
aoqi@0 295 else if (entry instanceof PrimitiveEntry)
aoqi@0 296 name = javaPrimName (entry.name ());
aoqi@0 297 else if (entry instanceof StringEntry)
aoqi@0 298 name = "String";
aoqi@0 299 else if (entry instanceof NativeEntry)
aoqi@0 300 name = javaNativeName (entry.name());
aoqi@0 301 else if (entry instanceof ValueEntry && entry.name ().equals ("ValueBase"))
aoqi@0 302 name = "java.io.Serializable";
aoqi@0 303 else if (entry instanceof ValueBoxEntry)
aoqi@0 304 {
aoqi@0 305 ValueBoxEntry v = (ValueBoxEntry) entry;
aoqi@0 306 TypedefEntry member = ((InterfaceState) v.state ().elementAt (0)).entry;
aoqi@0 307 SymtabEntry mType = member.type ();
aoqi@0 308 if (mType instanceof PrimitiveEntry)
aoqi@0 309 {
aoqi@0 310 name = containerFullName (entry.container ());
aoqi@0 311 if (!name.equals (""))
aoqi@0 312 name = name + '.';
aoqi@0 313 name = name + entry.name ();
aoqi@0 314 }
aoqi@0 315 else
aoqi@0 316 name = javaName (mType);
aoqi@0 317 }
aoqi@0 318 else
aoqi@0 319 {
aoqi@0 320 name = containerFullName (entry.container ());
aoqi@0 321 if (name.equals (""))
aoqi@0 322 name = entry.name ();
aoqi@0 323 else
aoqi@0 324 name = name + '.' + entry.name ();
aoqi@0 325 }
aoqi@0 326
aoqi@0 327 // Make it a fully package-qualified name
aoqi@0 328 return name.replace ('/', '.');
aoqi@0 329 } // javaName
aoqi@0 330
aoqi@0 331 public static String javaPrimName (String name)
aoqi@0 332 {
aoqi@0 333 if (name.equals ("long") || name.equals ("unsigned long"))
aoqi@0 334 name = "int";
aoqi@0 335 else if (name.equals ("octet"))
aoqi@0 336 name = "byte";
aoqi@0 337 // "unisigned long long" exceeds Java long.
aoqi@0 338 else if (name.equals ("long long") || name.equals ("unsigned long long"))
aoqi@0 339 name = "long";
aoqi@0 340 else if (name.equals ("wchar"))
aoqi@0 341 name = "char";
aoqi@0 342 else if (name.equals ("unsigned short"))
aoqi@0 343 name = "short";
aoqi@0 344 else if (name.equals ("any"))
aoqi@0 345 name = "org.omg.CORBA.Any";
aoqi@0 346 else if (name.equals ("TypeCode"))
aoqi@0 347 name = "org.omg.CORBA.TypeCode";
aoqi@0 348 else if (name.equals ("Principal")) // <d61961>
aoqi@0 349 name = "org.omg.CORBA.Principal";
aoqi@0 350 return name;
aoqi@0 351 } // javaPrimName
aoqi@0 352
aoqi@0 353 public static String javaNativeName (String name)
aoqi@0 354 {
aoqi@0 355
aoqi@0 356 // translations for Native declarations according to CORBA 2.3 spec
aoqi@0 357
aoqi@0 358 if (name.equals ("AbstractBase") || name.equals ("Cookie"))
aoqi@0 359 name = "java.lang.Object";
aoqi@0 360 else if (name.equals ("Servant"))
aoqi@0 361 name = "org.omg.PortableServer.Servant";
aoqi@0 362 else if (name.equals ("ValueFactory"))
aoqi@0 363 name = "org.omg.CORBA.portable.ValueFactory";
aoqi@0 364 return name;
aoqi@0 365 }
aoqi@0 366
aoqi@0 367
aoqi@0 368 /**
aoqi@0 369 * Given a symtabEntry, return the name of this entry. This
aoqi@0 370 * method does not do any conversions like javaName does.
aoqi@0 371 **/
aoqi@0 372 public static String javaQualifiedName (SymtabEntry entry)
aoqi@0 373 {
aoqi@0 374 String name = "";
aoqi@0 375 if (entry instanceof PrimitiveEntry)
aoqi@0 376 name = javaPrimName (entry.name ());
aoqi@0 377 else if (entry instanceof StringEntry)
aoqi@0 378 name = "String";
aoqi@0 379 else if (entry instanceof ValueEntry && entry.name ().equals ("ValueBase"))
aoqi@0 380 name = "java.io.Serializable";
aoqi@0 381 else
aoqi@0 382 {
aoqi@0 383 SymtabEntry container = entry.container ();
aoqi@0 384 if (container != null)
aoqi@0 385 name = container.name ();
aoqi@0 386 if (name.equals (""))
aoqi@0 387 name = entry.name ();
aoqi@0 388 else
aoqi@0 389 name = containerFullName (entry.container ()) + '.' + entry.name ();
aoqi@0 390 }
aoqi@0 391 return name.replace ('/', '.');
aoqi@0 392 } // javaQualifiedName
aoqi@0 393
aoqi@0 394 // <f46082.03> Publicize for extensions.
aoqi@0 395 //static String collapseName (String name)
aoqi@0 396
aoqi@0 397 /**
aoqi@0 398 * Collapse primitive type names.
aoqi@0 399 **/
aoqi@0 400 public static String collapseName (String name)
aoqi@0 401 {
aoqi@0 402 if (name.equals ("unsigned short"))
aoqi@0 403 name = "ushort";
aoqi@0 404 else if (name.equals ("unsigned long"))
aoqi@0 405 name = "ulong";
aoqi@0 406 else if (name.equals ("unsigned long long"))
aoqi@0 407 name = "ulonglong";
aoqi@0 408 else if (name.equals ("long long"))
aoqi@0 409 name = "longlong";
aoqi@0 410 return name;
aoqi@0 411 } // collapseName
aoqi@0 412
aoqi@0 413 /**
aoqi@0 414 *
aoqi@0 415 **/
aoqi@0 416 public static SymtabEntry typeOf (SymtabEntry entry)
aoqi@0 417 {
aoqi@0 418 while (entry instanceof TypedefEntry && ((TypedefEntry)entry).arrayInfo ().isEmpty () && !(entry.type () instanceof SequenceEntry))
aoqi@0 419 entry = entry.type ();
aoqi@0 420 return entry;
aoqi@0 421 } // typeOf
aoqi@0 422
aoqi@0 423 /**
aoqi@0 424 * Fill the info field with the full name (with array info) of the type.
aoqi@0 425 **/
aoqi@0 426 static void fillInfo (SymtabEntry infoEntry)
aoqi@0 427 {
aoqi@0 428 String arrayInfo = "";
aoqi@0 429 SymtabEntry entry = infoEntry;
aoqi@0 430 boolean alreadyHave = false;
aoqi@0 431
aoqi@0 432 do
aoqi@0 433 {
aoqi@0 434 try
aoqi@0 435 {
aoqi@0 436 alreadyHave = entry.dynamicVariable (Compile.typedefInfo) != null;
aoqi@0 437 }
aoqi@0 438 catch (NoSuchFieldException e)
aoqi@0 439 {}
aoqi@0 440 // If this entry's info has already been processed
aoqi@0 441 // don't bother processing it again, just take it.
aoqi@0 442 if (!alreadyHave)
aoqi@0 443 {
aoqi@0 444 if (entry instanceof TypedefEntry)
aoqi@0 445 arrayInfo = arrayInfo + arrayInfo (((TypedefEntry)entry).arrayInfo ());
aoqi@0 446 else if (entry instanceof SequenceEntry)
aoqi@0 447 {
aoqi@0 448 Expression maxSize = ((SequenceEntry)entry).maxSize ();
aoqi@0 449 if (maxSize == null)
aoqi@0 450 arrayInfo = arrayInfo + "[]";
aoqi@0 451 else
aoqi@0 452 arrayInfo = arrayInfo + '[' + parseExpression (maxSize) + ']';
aoqi@0 453 }
aoqi@0 454 if (entry.type () == null)
aoqi@0 455 {
aoqi@0 456 // <d59437> Suppress this message. It tells the developer nothing, and
aoqi@0 457 // this path does not cause the algorithm to fail. Value boxes may
aoqi@0 458 // contain anonymous types, like a struct or enum.
aoqi@0 459 //System.err.println (getMessage ("PreEmit.indeterminateTypeInfo", entry.typeName ()));
aoqi@0 460 }
aoqi@0 461 else
aoqi@0 462 entry = entry.type ();
aoqi@0 463 }
aoqi@0 464 } while (!alreadyHave && entry != null &&
aoqi@0 465 (entry instanceof TypedefEntry || entry instanceof SequenceEntry));
aoqi@0 466 // <d59437> Value boxes may contain types lacking typename info., which
aoqi@0 467 // causes the 2nd case, below, to fail with exception when retrieving the
aoqi@0 468 // javaName().
aoqi@0 469 if (entry instanceof ValueBoxEntry)
aoqi@0 470 fillValueBoxInfo ((ValueBoxEntry)entry);
aoqi@0 471 try
aoqi@0 472 {
aoqi@0 473 if (alreadyHave)
aoqi@0 474 infoEntry.dynamicVariable (Compile.typedefInfo, (String)entry.dynamicVariable (Compile.typedefInfo) + arrayInfo);
aoqi@0 475 else
aoqi@0 476 infoEntry.dynamicVariable (Compile.typedefInfo, javaName (entry) + arrayInfo);
aoqi@0 477 }
aoqi@0 478 catch (NoSuchFieldException e)
aoqi@0 479 {}
aoqi@0 480 } // fillInfo
aoqi@0 481
aoqi@0 482 // <d59437>
aoqi@0 483 /**
aoqi@0 484 *
aoqi@0 485 **/
aoqi@0 486 static void fillValueBoxInfo (ValueBoxEntry vb)
aoqi@0 487 {
aoqi@0 488 SymtabEntry stateMember = (((InterfaceState) vb.state ().elementAt (0)).entry);
aoqi@0 489 if (stateMember.type() != null)
aoqi@0 490 Util.fillInfo (stateMember.type ());
aoqi@0 491 Util.fillInfo (stateMember);
aoqi@0 492 } // fillValueBoxInfo
aoqi@0 493
aoqi@0 494 /**
aoqi@0 495 *
aoqi@0 496 **/
aoqi@0 497 public static String holderName (SymtabEntry entry)
aoqi@0 498 {
aoqi@0 499 String name;
aoqi@0 500 if (entry instanceof PrimitiveEntry)
aoqi@0 501 if (entry.name ().equals ("any"))
aoqi@0 502 name = "org.omg.CORBA.AnyHolder";
aoqi@0 503 else if (entry.name ().equals ("TypeCode"))
aoqi@0 504 name = "org.omg.CORBA.TypeCodeHolder";
aoqi@0 505 else if (entry.name ().equals ("Principal")) // <d61961>
aoqi@0 506 name = "org.omg.CORBA.PrincipalHolder";
aoqi@0 507 else
aoqi@0 508 name = "org.omg.CORBA." + capitalize (javaQualifiedName (entry)) + "Holder";
aoqi@0 509 else if (entry instanceof TypedefEntry)
aoqi@0 510 {
aoqi@0 511 TypedefEntry td = (TypedefEntry)entry;
aoqi@0 512 if (!td.arrayInfo ().isEmpty () || td.type () instanceof SequenceEntry)
aoqi@0 513 name = javaQualifiedName (entry) + "Holder";
aoqi@0 514 else
aoqi@0 515 name = holderName (entry.type ());
aoqi@0 516 }
aoqi@0 517 else if (entry instanceof StringEntry)
aoqi@0 518 name = "org.omg.CORBA.StringHolder";
aoqi@0 519 else if (entry instanceof ValueEntry)
aoqi@0 520 {
aoqi@0 521 if (entry.name ().equals ("ValueBase"))
aoqi@0 522 name = "org.omg.CORBA.ValueBaseHolder"; // <d59421>, <d60929>
aoqi@0 523 else
aoqi@0 524 name = javaName (entry) + "Holder";
aoqi@0 525 } else if (entry instanceof NativeEntry) {
aoqi@0 526 // do not attach holder to the translation for Native Entries, e.g.
aoqi@0 527 // for Cookie it should be CookieHolder instead of java.lang.ObjectHolder
aoqi@0 528 // returns the complete name for the package, etc.
aoqi@0 529 name = javaQualifiedName(entry) + "Holder";
aoqi@0 530 }
aoqi@0 531 else
aoqi@0 532 name = javaName (entry) + "Holder";
aoqi@0 533 return name;
aoqi@0 534 } // holderName
aoqi@0 535
aoqi@0 536 /**
aoqi@0 537 * <d61056>
aoqi@0 538 **/
aoqi@0 539 public static String helperName (SymtabEntry entry, boolean qualifiedName)
aoqi@0 540 {
aoqi@0 541 if (entry instanceof ValueEntry)
aoqi@0 542 if (entry.name ().equals ("ValueBase"))
aoqi@0 543 return "org.omg.CORBA.ValueBaseHelper";
aoqi@0 544
aoqi@0 545 if (qualifiedName)
aoqi@0 546 return javaQualifiedName (entry) + "Helper";
aoqi@0 547 else
aoqi@0 548 return javaName (entry) + "Helper";
aoqi@0 549 } // helperName
aoqi@0 550
aoqi@0 551 public static final short
aoqi@0 552 TypeFile = 0,
aoqi@0 553 StubFile = 1,
aoqi@0 554 HelperFile = 2,
aoqi@0 555 HolderFile = 3,
aoqi@0 556 StateFile = 4;
aoqi@0 557
aoqi@0 558 /**
aoqi@0 559 *
aoqi@0 560 **/
aoqi@0 561 public static void writePackage (PrintWriter stream, SymtabEntry entry)
aoqi@0 562 {
aoqi@0 563 writePackage (stream, entry, TypeFile);
aoqi@0 564 } // writePackage
aoqi@0 565
aoqi@0 566 /**
aoqi@0 567 *
aoqi@0 568 **/
aoqi@0 569 public static void writePackage (PrintWriter stream, SymtabEntry entry, String name, short type)
aoqi@0 570 {
aoqi@0 571 if (name != null && !name.equals (""))
aoqi@0 572 {
aoqi@0 573 stream.println ("package " + name.replace ('/', '.') + ';');
aoqi@0 574
aoqi@0 575 // This type is in a module. Just in case it refers to types
aoqi@0 576 // in the unnamed module, add an import statement for each of
aoqi@0 577 // those types.
aoqi@0 578 if (!Compile.compiler.importTypes.isEmpty ())
aoqi@0 579 {
aoqi@0 580 stream.println ();
aoqi@0 581 Vector v = addImportLines (entry, Compile.compiler.importTypes, type);
aoqi@0 582 printImports (v, stream);
aoqi@0 583 }
aoqi@0 584 }
aoqi@0 585 } // writePackage
aoqi@0 586
aoqi@0 587 /**
aoqi@0 588 *
aoqi@0 589 **/
aoqi@0 590 public static void writePackage (PrintWriter stream, SymtabEntry entry, short type)
aoqi@0 591 {
aoqi@0 592 String fullName = containerFullName (entry.container ());
aoqi@0 593 if (fullName != null && !fullName.equals (""))
aoqi@0 594 {
aoqi@0 595 stream.println ("package " + fullName.replace ('/', '.') + ';');
aoqi@0 596 // This type is in a module. Just in case it refers to types
aoqi@0 597 // in the unnamed module, add an import statement for each of
aoqi@0 598 // those types.
aoqi@0 599 if ((type != HolderFile || entry instanceof TypedefEntry) && !Compile.compiler.importTypes.isEmpty ())
aoqi@0 600 {
aoqi@0 601 stream.println ();
aoqi@0 602 Vector v = addImportLines (entry, Compile.compiler.importTypes, type);
aoqi@0 603 printImports (v, stream);
aoqi@0 604 }
aoqi@0 605 /*
aoqi@0 606 Enumeration e = Compile.compiler.importTypes.elements ();
aoqi@0 607 while (e.hasMoreElements ())
aoqi@0 608 {
aoqi@0 609 SymtabEntry i = (SymtabEntry)e.nextElement ();
aoqi@0 610 // Write import for type
aoqi@0 611 if (!(i instanceof TypedefEntry))
aoqi@0 612 stream.println ("import " + i.name () + ';');
aoqi@0 613
aoqi@0 614 // Write import for Helper
aoqi@0 615 if (!(i instanceof ConstEntry))
aoqi@0 616 stream.println ("import " + i.name () + "Helper;");
aoqi@0 617
aoqi@0 618 // Write import for Holder
aoqi@0 619 if (!(i instanceof ConstEntry))
aoqi@0 620 if (!(i instanceof TypedefEntry) || (i.type () instanceof SequenceEntry || !((TypedefEntry)i).arrayInfo ().isEmpty ()))
aoqi@0 621 stream.println ("import " + i.name () + "Holder;");
aoqi@0 622 }
aoqi@0 623 */
aoqi@0 624 }
aoqi@0 625 } // writePackage
aoqi@0 626
aoqi@0 627 /**
aoqi@0 628 *
aoqi@0 629 **/
aoqi@0 630 static private void printImports (Vector importList, PrintWriter stream)
aoqi@0 631 {
aoqi@0 632 Enumeration e = importList.elements ();
aoqi@0 633 while (e.hasMoreElements ())
aoqi@0 634 stream.println ("import " + (String)e.nextElement () + ';');
aoqi@0 635 } // printImport
aoqi@0 636
aoqi@0 637 /**
aoqi@0 638 *
aoqi@0 639 **/
aoqi@0 640 static private void addTo (Vector importList, String name)
aoqi@0 641 {
aoqi@0 642 // REVISIT - <d62023-klr> was also importing ValueBaseHolder and Helper
aoqi@0 643 if (name.startsWith ("ValueBase")) // don't import ValueBase*
aoqi@0 644 if ((name.compareTo ("ValueBase") == 0) ||
aoqi@0 645 (name.compareTo ("ValueBaseHolder") == 0) ||
aoqi@0 646 (name.compareTo ("ValueBaseHelper") == 0))
aoqi@0 647 return;
aoqi@0 648 if (!importList.contains (name))
aoqi@0 649 importList.addElement (name);
aoqi@0 650 } // addTo
aoqi@0 651
aoqi@0 652 /**
aoqi@0 653 *
aoqi@0 654 **/
aoqi@0 655 static private Vector addImportLines (SymtabEntry entry, Vector importTypes, short type)
aoqi@0 656 {
aoqi@0 657 Vector importList = new Vector ();
aoqi@0 658 if (entry instanceof ConstEntry)
aoqi@0 659 {
aoqi@0 660 ConstEntry c = (ConstEntry)entry;
aoqi@0 661 Object cvalue = c.value ().value ();
aoqi@0 662 if (cvalue instanceof ConstEntry && importTypes.contains (cvalue))
aoqi@0 663 addTo (importList, ((ConstEntry)cvalue).name ());
aoqi@0 664 }
aoqi@0 665 else if (entry instanceof ValueEntry && type == HelperFile) // <d59512>
aoqi@0 666 {
aoqi@0 667 // This code inspired by ValueGen.getConcreteBaseTypeCode(). Helper method
aoqi@0 668 // type() could be invoked against a global valuetype.
aoqi@0 669 if (((ValueEntry)entry).derivedFrom ().size () > 0) // <59596> KLR HACK
aoqi@0 670 {
aoqi@0 671 ValueEntry base = (ValueEntry)((ValueEntry)entry).derivedFrom ().elementAt (0);
aoqi@0 672 String baseName = base.name ();
aoqi@0 673 if (!"ValueBase".equals (baseName))
aoqi@0 674 if (importTypes.contains (base))
aoqi@0 675 addTo (importList, baseName + "Helper");
aoqi@0 676 }
aoqi@0 677 }
aoqi@0 678 else if (entry instanceof InterfaceEntry && (type == TypeFile || type == StubFile))
aoqi@0 679 {
aoqi@0 680 InterfaceEntry i = (InterfaceEntry)entry;
aoqi@0 681
aoqi@0 682 if (i instanceof ValueEntry) // <d59512>
aoqi@0 683 {
aoqi@0 684 // Examine interface parents in supports vector.
aoqi@0 685 Enumeration e = ((ValueEntry)i).supports ().elements ();
aoqi@0 686 while (e.hasMoreElements ())
aoqi@0 687 {
aoqi@0 688 SymtabEntry parent = (SymtabEntry)e.nextElement ();
aoqi@0 689 if (importTypes.contains (parent))
aoqi@0 690 {
aoqi@0 691 addTo (importList, parent.name () + "Operations");
aoqi@0 692 }
aoqi@0 693 // If this is a stub, then recurse to the parents
aoqi@0 694 if (type == StubFile)
aoqi@0 695 {
aoqi@0 696 if (importTypes.contains (parent))
aoqi@0 697 addTo (importList, parent.name ());
aoqi@0 698 Vector subImportList = addImportLines (parent, importTypes, StubFile);
aoqi@0 699 Enumeration en = subImportList.elements ();
aoqi@0 700 while (en.hasMoreElements ())
aoqi@0 701 {
aoqi@0 702 addTo (importList, (String)en.nextElement ());
aoqi@0 703 }
aoqi@0 704 }
aoqi@0 705 }
aoqi@0 706 }
aoqi@0 707 // Interface or valuetype -- Examine interface and valuetype parents,
aoqi@0 708 // Look through derivedFrom vector
aoqi@0 709 Enumeration e = i.derivedFrom ().elements ();
aoqi@0 710 while (e.hasMoreElements ())
aoqi@0 711 {
aoqi@0 712 SymtabEntry parent = (SymtabEntry)e.nextElement ();
aoqi@0 713 if (importTypes.contains (parent))
aoqi@0 714 {
aoqi@0 715 addTo (importList, parent.name ());
aoqi@0 716 // <d59512> Always add both imports, even though superfluous. Cannot
aoqi@0 717 // tell when writing Operations or Signature interface!
aoqi@0 718 if (!(parent instanceof ValueEntry)) // && parent.name ().equals ("ValueBase")))
aoqi@0 719 addTo (importList, parent.name () + "Operations");
aoqi@0 720 }
aoqi@0 721 // If this is a stub, then recurse to the parents
aoqi@0 722 if (type == StubFile)
aoqi@0 723 {
aoqi@0 724 Vector subImportList = addImportLines (parent, importTypes, StubFile);
aoqi@0 725 Enumeration en = subImportList.elements ();
aoqi@0 726 while (en.hasMoreElements ())
aoqi@0 727 {
aoqi@0 728 addTo (importList, (String)en.nextElement ());
aoqi@0 729 }
aoqi@0 730 }
aoqi@0 731 }
aoqi@0 732 // Look through methods vector
aoqi@0 733 e = i.methods ().elements ();
aoqi@0 734 while (e.hasMoreElements ())
aoqi@0 735 {
aoqi@0 736 MethodEntry m = (MethodEntry)e.nextElement ();
aoqi@0 737
aoqi@0 738 // Look at method type
aoqi@0 739 SymtabEntry mtype = typeOf (m.type ());
aoqi@0 740 if (mtype != null && importTypes.contains (mtype))
aoqi@0 741 if (type == TypeFile || type == StubFile)
aoqi@0 742 {
aoqi@0 743 addTo (importList, mtype.name ());
aoqi@0 744 addTo (importList, mtype.name () + "Holder");
aoqi@0 745 if (type == StubFile)
aoqi@0 746 addTo (importList, mtype.name () + "Helper");
aoqi@0 747 }
aoqi@0 748 checkForArrays (mtype, importTypes, importList);
aoqi@0 749 // <d42256> Print import lines for globals constants and constants
aoqi@0 750 // within global interfaces.
aoqi@0 751 if (type == StubFile)
aoqi@0 752 checkForBounds (mtype, importTypes, importList);
aoqi@0 753
aoqi@0 754 // Look through exceptions
aoqi@0 755 Enumeration exEnum = m.exceptions ().elements ();
aoqi@0 756 while (exEnum.hasMoreElements ())
aoqi@0 757 {
aoqi@0 758 ExceptionEntry ex = (ExceptionEntry)exEnum.nextElement ();
aoqi@0 759 if (importTypes.contains (ex))
aoqi@0 760 {
aoqi@0 761 addTo (importList, ex.name ());
aoqi@0 762 addTo (importList, ex.name () + "Helper"); // <d59063>
aoqi@0 763 }
aoqi@0 764 }
aoqi@0 765
aoqi@0 766 // Look through parameters
aoqi@0 767 Enumeration parms = m.parameters ().elements ();
aoqi@0 768 while (parms.hasMoreElements ())
aoqi@0 769 {
aoqi@0 770 ParameterEntry parm = (ParameterEntry)parms.nextElement ();
aoqi@0 771 SymtabEntry parmType = typeOf (parm.type ());
aoqi@0 772 if (importTypes.contains (parmType))
aoqi@0 773 {
aoqi@0 774 // <d59771> Helper needed in stubs.
aoqi@0 775 if (type == StubFile)
aoqi@0 776 addTo (importList, parmType.name () + "Helper");
aoqi@0 777 if (parm.passType () == ParameterEntry.In)
aoqi@0 778 addTo (importList, parmType.name ());
aoqi@0 779 else
aoqi@0 780 addTo (importList, parmType.name () + "Holder");
aoqi@0 781 }
aoqi@0 782 checkForArrays (parmType, importTypes, importList);
aoqi@0 783 // <d42256>
aoqi@0 784 if (type == StubFile)
aoqi@0 785 checkForBounds (parmType, importTypes, importList);
aoqi@0 786 }
aoqi@0 787 }
aoqi@0 788 }
aoqi@0 789 else if (entry instanceof StructEntry)
aoqi@0 790 {
aoqi@0 791 StructEntry s = (StructEntry)entry;
aoqi@0 792
aoqi@0 793 // Look through the members
aoqi@0 794 Enumeration members = s.members ().elements ();
aoqi@0 795 while (members.hasMoreElements ())
aoqi@0 796 {
aoqi@0 797 SymtabEntry member = (TypedefEntry)members.nextElement ();
aoqi@0 798 // <d48034> Need to add helper name for typedef members. This name
aoqi@0 799 // is referenced at typecode generation in Helper class.
aoqi@0 800 SymtabEntry memberType = member.type ();
aoqi@0 801 member = typeOf (member);
aoqi@0 802 if (importTypes.contains (member))
aoqi@0 803 {
aoqi@0 804 // If this IS a typedef, then there are only Helper/Holder classes.
aoqi@0 805 //if (!(member instanceof TypedefEntry))
aoqi@0 806 // <d59437> Valueboxes
aoqi@0 807 if (!(member instanceof TypedefEntry) && !(member instanceof ValueBoxEntry))
aoqi@0 808 addTo (importList, member.name ());
aoqi@0 809 // <d48034> Add helper name of alias, too, if member is a typedef.
aoqi@0 810 //if (type == HelperFile)
aoqi@0 811 // addTo (importList, member.name () + "Helper");
aoqi@0 812 if (type == HelperFile)
aoqi@0 813 {
aoqi@0 814 addTo (importList, member.name () + "Helper");
aoqi@0 815 if (memberType instanceof TypedefEntry)
aoqi@0 816 addTo (importList, memberType.name () + "Helper");
aoqi@0 817 }
aoqi@0 818 }
aoqi@0 819 checkForArrays (member, importTypes, importList);
aoqi@0 820 checkForBounds (member, importTypes, importList);
aoqi@0 821 }
aoqi@0 822 }
aoqi@0 823 else if (entry instanceof TypedefEntry)
aoqi@0 824 {
aoqi@0 825 TypedefEntry t = (TypedefEntry)entry;
aoqi@0 826 String arrays = checkForArrayBase (t, importTypes, importList);
aoqi@0 827 if (type == HelperFile)
aoqi@0 828 {
aoqi@0 829 checkForArrayDimensions (arrays, importTypes, importList);
aoqi@0 830 try
aoqi@0 831 {
aoqi@0 832 String name = (String)t.dynamicVariable (Compile.typedefInfo);
aoqi@0 833 int index = name.indexOf ('[');
aoqi@0 834 if (index >= 0)
aoqi@0 835 name = name.substring (0, index);
aoqi@0 836 // See if the base type should be added to the list.
aoqi@0 837 SymtabEntry typeEntry = (SymtabEntry)symbolTable.get (name);
aoqi@0 838 if (typeEntry != null && importTypes.contains (typeEntry))
aoqi@0 839 addTo (importList, typeEntry.name () + "Helper");
aoqi@0 840 }
aoqi@0 841 catch (NoSuchFieldException e)
aoqi@0 842 {}
aoqi@0 843
aoqi@0 844 // <d42256> Typedefs for global bounded strings need import
aoqi@0 845 // statement when bound expression contains non-literal constants.
aoqi@0 846 checkForBounds (typeOf (t), importTypes, importList);
aoqi@0 847 }
aoqi@0 848 Vector subImportList = addImportLines (t.type (), importTypes, type);
aoqi@0 849 Enumeration e = subImportList.elements ();
aoqi@0 850 while (e.hasMoreElements ())
aoqi@0 851 addTo (importList, (String)e.nextElement ());
aoqi@0 852 }
aoqi@0 853 else if (entry instanceof UnionEntry)
aoqi@0 854 {
aoqi@0 855 UnionEntry u = (UnionEntry)entry;
aoqi@0 856
aoqi@0 857 // Look at the discriminant type
aoqi@0 858 SymtabEntry utype = typeOf (u.type ());
aoqi@0 859 if (utype instanceof EnumEntry && importTypes.contains (utype))
aoqi@0 860 addTo (importList, utype.name ());
aoqi@0 861
aoqi@0 862 // Look through the branches
aoqi@0 863 Enumeration branches = u.branches ().elements ();
aoqi@0 864 while (branches.hasMoreElements ())
aoqi@0 865 {
aoqi@0 866 UnionBranch branch = (UnionBranch)branches.nextElement ();
aoqi@0 867 SymtabEntry branchEntry = typeOf (branch.typedef);
aoqi@0 868 if (importTypes.contains (branchEntry))
aoqi@0 869 {
aoqi@0 870 addTo (importList, branchEntry.name ());
aoqi@0 871 if (type == HelperFile)
aoqi@0 872 addTo (importList, branchEntry.name () + "Helper");
aoqi@0 873 }
aoqi@0 874 checkForArrays (branchEntry, importTypes, importList);
aoqi@0 875 // <d42256>
aoqi@0 876 checkForBounds (branchEntry, importTypes, importList);
aoqi@0 877 }
aoqi@0 878 }
aoqi@0 879
aoqi@0 880 // If a typedef is not a sequence or an array, only holders and
aoqi@0 881 // helpers are generated for it. Remove references to such
aoqi@0 882 // class names.
aoqi@0 883 Enumeration en = importList.elements ();
aoqi@0 884 while (en.hasMoreElements ())
aoqi@0 885 {
aoqi@0 886 String name = (String)en.nextElement ();
aoqi@0 887 SymtabEntry e = (SymtabEntry)symbolTable.get (name);
aoqi@0 888 if (e != null && e instanceof TypedefEntry)
aoqi@0 889 {
aoqi@0 890 TypedefEntry t = (TypedefEntry)e;
aoqi@0 891 if (t.arrayInfo ().size () == 0 || !(t.type () instanceof SequenceEntry))
aoqi@0 892 importList.removeElement (name);
aoqi@0 893 }
aoqi@0 894 }
aoqi@0 895 return importList;
aoqi@0 896 } // addImportLines
aoqi@0 897
aoqi@0 898 /**
aoqi@0 899 *
aoqi@0 900 **/
aoqi@0 901 static private void checkForArrays (SymtabEntry entry, Vector importTypes, Vector importList)
aoqi@0 902 {
aoqi@0 903 if (entry instanceof TypedefEntry)
aoqi@0 904 {
aoqi@0 905 TypedefEntry t = (TypedefEntry)entry;
aoqi@0 906 String arrays = checkForArrayBase (t, importTypes, importList);
aoqi@0 907 checkForArrayDimensions (arrays, importTypes, importList);
aoqi@0 908 }
aoqi@0 909 } // checkForArrays
aoqi@0 910
aoqi@0 911 /**
aoqi@0 912 *
aoqi@0 913 **/
aoqi@0 914 static private String checkForArrayBase (TypedefEntry t, Vector importTypes, Vector importList)
aoqi@0 915 {
aoqi@0 916 String arrays = "";
aoqi@0 917 try
aoqi@0 918 {
aoqi@0 919 String name = (String)t.dynamicVariable (Compile.typedefInfo);
aoqi@0 920 int index = name.indexOf ('[');
aoqi@0 921 if (index >= 0)
aoqi@0 922 {
aoqi@0 923 arrays = name.substring (index);
aoqi@0 924 name = name.substring (0, index);
aoqi@0 925 }
aoqi@0 926
aoqi@0 927 // See if the base type should be added to the list.
aoqi@0 928 SymtabEntry typeEntry = (SymtabEntry)symbolTable.get (name);
aoqi@0 929 if (typeEntry != null && importTypes.contains (typeEntry))
aoqi@0 930 addTo (importList, typeEntry.name ());
aoqi@0 931 }
aoqi@0 932 catch (NoSuchFieldException e)
aoqi@0 933 {}
aoqi@0 934 return arrays;
aoqi@0 935 } // checkForArrayBase
aoqi@0 936
aoqi@0 937 /**
aoqi@0 938 *
aoqi@0 939 **/
aoqi@0 940 static private void checkForArrayDimensions (String arrays, Vector importTypes, Vector importList)
aoqi@0 941 {
aoqi@0 942 // See if any of the arrays contain a constentry.
aoqi@0 943 // If so, see if it should be added to the list.
aoqi@0 944 while (!arrays.equals (""))
aoqi@0 945 {
aoqi@0 946 int index = arrays.indexOf (']');
aoqi@0 947 String dim = arrays.substring (1, index);
aoqi@0 948 arrays = arrays.substring (index + 1);
aoqi@0 949 SymtabEntry constant = (SymtabEntry)symbolTable.get (dim);
aoqi@0 950 if (constant == null)
aoqi@0 951 {
aoqi@0 952 // A constant expr could be of the form <const> OR
aoqi@0 953 // <interface>.<const>. This if branch checks for that case.
aoqi@0 954 int i = dim.lastIndexOf ('.');
aoqi@0 955 if (i >= 0)
aoqi@0 956 constant = (SymtabEntry)symbolTable.get (dim.substring (0, i));
aoqi@0 957 }
aoqi@0 958 if (constant != null && importTypes.contains (constant))
aoqi@0 959 addTo (importList, constant.name ());
aoqi@0 960 }
aoqi@0 961 } // checkForArrayDimensions
aoqi@0 962
aoqi@0 963 // <d42256> Call the following method when its necessary to determine the
aoqi@0 964 // the import types for IDL constructs containing arbitrary positive int.
aoqi@0 965 // expressions, which may specify non-literal constants.
aoqi@0 966
aoqi@0 967 /**
aoqi@0 968 * Determine the import lines for template types.
aoqi@0 969 **/
aoqi@0 970 static private void checkForBounds (SymtabEntry entry, Vector importTypes, Vector importList)
aoqi@0 971 {
aoqi@0 972 // Obtain actual type, just to be complete.
aoqi@0 973 SymtabEntry entryType = entry;
aoqi@0 974 while (entryType instanceof TypedefEntry)
aoqi@0 975 entryType = entryType.type ();
aoqi@0 976
aoqi@0 977 if (entryType instanceof StringEntry && ((StringEntry)entryType).maxSize () != null)
aoqi@0 978 checkForGlobalConstants (((StringEntry)entryType).maxSize ().rep (), importTypes, importList);
aoqi@0 979 else
aoqi@0 980 if (entryType instanceof SequenceEntry && ((SequenceEntry)entryType).maxSize () != null)
aoqi@0 981 checkForGlobalConstants (((SequenceEntry)entryType).maxSize ().rep (), importTypes, importList);
aoqi@0 982 } // checkForBounds
aoqi@0 983
aoqi@0 984 /**
aoqi@0 985 * Extract the global constants from the supplied integer expression
aoqi@0 986 * representation (string) and add them to the supplied import list.
aoqi@0 987 **/
aoqi@0 988 static private void checkForGlobalConstants (String exprRep, Vector importTypes, Vector importList)
aoqi@0 989 {
aoqi@0 990 // NOTE: Do not use '/' as a delimiter. Symbol table names use '/' as a
aoqi@0 991 // delimiter and would not be otherwise properly collected. Blanks and
aoqi@0 992 // arithmetic symbols do not appear in tokens, except for '/'.
aoqi@0 993 java.util.StringTokenizer st = new java.util.StringTokenizer (exprRep, " +-*()~&|^%<>");
aoqi@0 994 while (st.hasMoreTokens ())
aoqi@0 995 {
aoqi@0 996 String token = st.nextToken ();
aoqi@0 997 // When token contains '/', it represents the division symbol or
aoqi@0 998 // a nested type (e.g., I/x). Ignore the division symbol, and don't
aoqi@0 999 // forget constants declared within global interfaces!
aoqi@0 1000 if (!token.equals ("/"))
aoqi@0 1001 {
aoqi@0 1002 SymtabEntry typeEntry = (SymtabEntry)symbolTable.get (token);
aoqi@0 1003 if (typeEntry instanceof ConstEntry)
aoqi@0 1004 {
aoqi@0 1005 int slashIdx = token.indexOf ('/');
aoqi@0 1006 if (slashIdx < 0) // Possible global constant
aoqi@0 1007 {
aoqi@0 1008 if (importTypes.contains (typeEntry))
aoqi@0 1009 addTo (importList, typeEntry.name ());
aoqi@0 1010 }
aoqi@0 1011 else // Possible constant in global interface
aoqi@0 1012 {
aoqi@0 1013 SymtabEntry constContainer = (SymtabEntry)symbolTable.get (token.substring (0, slashIdx));
aoqi@0 1014 if (constContainer instanceof InterfaceEntry && importTypes.contains (constContainer))
aoqi@0 1015 addTo (importList, constContainer.name ());
aoqi@0 1016 }
aoqi@0 1017 }
aoqi@0 1018 }
aoqi@0 1019 }
aoqi@0 1020 } // checkForGlobalConstants
aoqi@0 1021
aoqi@0 1022 /**
aoqi@0 1023 *
aoqi@0 1024 **/
aoqi@0 1025 public static void writeInitializer (String indent, String name, String arrayDcl, SymtabEntry entry, PrintWriter stream)
aoqi@0 1026 {
aoqi@0 1027 if (entry instanceof TypedefEntry)
aoqi@0 1028 {
aoqi@0 1029 TypedefEntry td = (TypedefEntry)entry;
aoqi@0 1030 writeInitializer (indent, name, arrayDcl + sansArrayInfo (td.arrayInfo ()), td.type (), stream);
aoqi@0 1031 }
aoqi@0 1032 else if (entry instanceof SequenceEntry)
aoqi@0 1033 writeInitializer (indent, name, arrayDcl + "[]", entry.type (), stream);
aoqi@0 1034 else if (entry instanceof EnumEntry)
aoqi@0 1035 if (arrayDcl.length () > 0)
aoqi@0 1036 stream.println (indent + javaName (entry) + ' ' + name + arrayDcl + " = null;");
aoqi@0 1037 else
aoqi@0 1038 stream.println (indent + javaName (entry) + ' ' + name + " = null;");
aoqi@0 1039 else if (entry instanceof PrimitiveEntry)
aoqi@0 1040 {
aoqi@0 1041 boolean array = arrayDcl.length () > 0;
aoqi@0 1042 String tname = javaPrimName (entry.name ());
aoqi@0 1043 if (tname.equals ("boolean"))
aoqi@0 1044 stream.println (indent + "boolean " + name + arrayDcl + " = " + (array ? "null;" : "false;"));
aoqi@0 1045 else if (tname.equals ("org.omg.CORBA.TypeCode"))
aoqi@0 1046 stream.println (indent + "org.omg.CORBA.TypeCode " + name + arrayDcl + " = null;");
aoqi@0 1047 else if (tname.equals ("org.omg.CORBA.Any"))
aoqi@0 1048 stream.println (indent + "org.omg.CORBA.Any " + name + arrayDcl + " = null;");
aoqi@0 1049 else if (tname.equals ("org.omg.CORBA.Principal")) // <d61961>
aoqi@0 1050 stream.println (indent + "org.omg.CORBA.Principal " + name + arrayDcl + " = null;");
aoqi@0 1051 else
aoqi@0 1052 stream.println (indent + tname + ' ' + name + arrayDcl + " = " + (array ? "null;" : '(' + tname + ")0;"));
aoqi@0 1053 }
aoqi@0 1054 // <f46082.51> Remove -stateful feature. This case is identical to next one
aoqi@0 1055 // because javaName() supplants javaStatefulName().
aoqi@0 1056 //else if (entry instanceof InterfaceEntry && ((InterfaceEntry)entry).state () != null)
aoqi@0 1057 // stream.println (indent + javaStatefulName ((InterfaceEntry)entry) + ' ' + name + arrayDcl + " = null;");
aoqi@0 1058 else
aoqi@0 1059 stream.println (indent + javaName (entry) + ' ' + name + arrayDcl + " = null;");
aoqi@0 1060 } // writeInitializer
aoqi@0 1061
aoqi@0 1062 /**
aoqi@0 1063 *
aoqi@0 1064 **/
aoqi@0 1065 public static void writeInitializer (String indent, String name, String arrayDcl, SymtabEntry entry, String initializer, PrintWriter stream)
aoqi@0 1066 {
aoqi@0 1067 if (entry instanceof TypedefEntry)
aoqi@0 1068 {
aoqi@0 1069 TypedefEntry td = (TypedefEntry)entry;
aoqi@0 1070 writeInitializer (indent, name, arrayDcl + sansArrayInfo (td.arrayInfo ()), td.type (), initializer, stream);
aoqi@0 1071 }
aoqi@0 1072 else if (entry instanceof SequenceEntry)
aoqi@0 1073 writeInitializer (indent, name, arrayDcl + "[]", entry.type (), initializer, stream);
aoqi@0 1074 else if (entry instanceof EnumEntry)
aoqi@0 1075 if (arrayDcl.length () > 0)
aoqi@0 1076 stream.println (indent + javaName (entry) + ' ' + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1077 else
aoqi@0 1078 stream.println (indent + javaName (entry) + ' ' + name + " = " + initializer + ';');
aoqi@0 1079 else if (entry instanceof PrimitiveEntry)
aoqi@0 1080 {
aoqi@0 1081 boolean array = arrayDcl.length () > 0;
aoqi@0 1082 String tname = javaPrimName (entry.name ());
aoqi@0 1083 if (tname.equals ("boolean"))
aoqi@0 1084 stream.println (indent + "boolean " + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1085 else if (tname.equals ("org.omg.CORBA.TypeCode"))
aoqi@0 1086 stream.println (indent + "org.omg.CORBA.TypeCode " + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1087 else if (tname.equals ("org.omg.CORBA.Any"))
aoqi@0 1088 stream.println (indent + "org.omg.CORBA.Any " + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1089 else if (tname.equals ("org.omg.CORBA.Principal")) // <d61961>
aoqi@0 1090 stream.println (indent + "org.omg.CORBA.Principal " + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1091 else
aoqi@0 1092 stream.println (indent + tname + ' ' + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1093 }
aoqi@0 1094 // <f46082.51> Remove -stateful feature. This case is identical to next one
aoqi@0 1095 // because javaName() supplants javaStatefulName().
aoqi@0 1096 //else if (entry instanceof InterfaceEntry && ((InterfaceEntry)entry).state () != null)
aoqi@0 1097 // stream.println (indent + javaStatefulName ((InterfaceEntry)entry) + ' ' + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1098 else
aoqi@0 1099 stream.println (indent + javaName (entry) + ' ' + name + arrayDcl + " = " + initializer + ';');
aoqi@0 1100 } // writeInitializer
aoqi@0 1101
aoqi@0 1102 /**
aoqi@0 1103 *
aoqi@0 1104 **/
aoqi@0 1105 public static void mkdir (String name)
aoqi@0 1106 {
aoqi@0 1107 String targetDir = ((Arguments)Compile.compiler.arguments).targetDir; // F46838.4
aoqi@0 1108 name = (targetDir + name).replace ('/', File.separatorChar); // F46838.4
aoqi@0 1109 File pkg = new File (name);
aoqi@0 1110 if (!pkg.exists ())
aoqi@0 1111 if (!pkg.mkdirs ())
aoqi@0 1112 System.err.println (getMessage ("Util.cantCreatePkg", name));
aoqi@0 1113 } // mkdir
aoqi@0 1114
aoqi@0 1115 /**
aoqi@0 1116 *
aoqi@0 1117 **/
aoqi@0 1118 public static void writeProlog (PrintWriter stream, String filename)
aoqi@0 1119 {
aoqi@0 1120 // <d59355> Remove target directory
aoqi@0 1121 String targetDir = ((Arguments)Compile.compiler.arguments).targetDir;
aoqi@0 1122 if (targetDir != null)
aoqi@0 1123 filename = filename.substring (targetDir.length ());
aoqi@0 1124 stream.println ();
aoqi@0 1125 stream.println ("/**");
aoqi@0 1126 stream.println ("* " + filename.replace (File.separatorChar, '/') +
aoqi@0 1127 " .");
aoqi@0 1128 stream.println ("* " + Util.getMessage ("toJavaProlog1",
aoqi@0 1129 Util.getMessage ("Version.product", Util.getMessage ("Version.number"))));
aoqi@0 1130 // <d48911> Do not introduce invalid escape characters into comment! <daz>
aoqi@0 1131 //stream.println ("* " + Util.getMessage ("toJavaProlog2", Compile.compiler.arguments.file));
aoqi@0 1132 stream.println ("* " + Util.getMessage ("toJavaProlog2", Compile.compiler.arguments.file.replace (File.separatorChar, '/')));
aoqi@0 1133
aoqi@0 1134 ///////////////
aoqi@0 1135 // This SHOULD work, but there's a bug in the JDK.
aoqi@0 1136 // stream.println ("* " + DateFormat.getDateTimeInstance (DateFormat.FULL, DateFormat.FULL, Locale.getDefault ()).format (new Date ()));
aoqi@0 1137 // This gets around the bug:
aoqi@0 1138
aoqi@0 1139 DateFormat formatter = DateFormat.getDateTimeInstance (DateFormat.FULL, DateFormat.FULL, Locale.getDefault ());
aoqi@0 1140
aoqi@0 1141 // Japanese-specific workaround. JDK bug 4069784 being repaired by JavaSoft.
aoqi@0 1142 // Keep this transient solution until bug fix is reported.cd .
aoqi@0 1143
aoqi@0 1144 if (Locale.getDefault () == Locale.JAPAN)
aoqi@0 1145 formatter.setTimeZone (java.util.TimeZone.getTimeZone ("JST"));
aoqi@0 1146 else
aoqi@0 1147 formatter.setTimeZone (java.util.TimeZone.getDefault ());
aoqi@0 1148
aoqi@0 1149 stream.println ("* " + formatter.format (new Date ()));
aoqi@0 1150
aoqi@0 1151 // <daz>
aoqi@0 1152 ///////////////
aoqi@0 1153
aoqi@0 1154 stream.println ("*/");
aoqi@0 1155 stream.println ();
aoqi@0 1156 } // writeProlog
aoqi@0 1157
aoqi@0 1158 // keywords ending in Holder or Helper or Package have '_' prepended.
aoqi@0 1159 // These prepended underscores must not be part of anything sent
aoqi@0 1160 // across the wire, so these two methods are provided to strip them
aoqi@0 1161 // off.
aoqi@0 1162
aoqi@0 1163 /**
aoqi@0 1164 *
aoqi@0 1165 **/
aoqi@0 1166 public static String stripLeadingUnderscores (String string)
aoqi@0 1167 {
aoqi@0 1168 while (string.startsWith ("_"))
aoqi@0 1169 string = string.substring (1);
aoqi@0 1170 return string;
aoqi@0 1171 } // stripLeadingUnderscores
aoqi@0 1172
aoqi@0 1173 /**
aoqi@0 1174 *
aoqi@0 1175 **/
aoqi@0 1176 public static String stripLeadingUnderscoresFromID (String string)
aoqi@0 1177 {
aoqi@0 1178 String stringPrefix = "";
aoqi@0 1179 int slashIndex = string.indexOf (':');
aoqi@0 1180 if (slashIndex >= 0)
aoqi@0 1181 do
aoqi@0 1182 {
aoqi@0 1183 stringPrefix = stringPrefix + string.substring (0, slashIndex + 1);
aoqi@0 1184 string = string.substring (slashIndex + 1);
aoqi@0 1185 while (string.startsWith ("_"))
aoqi@0 1186 string = string.substring (1);
aoqi@0 1187 slashIndex = string.indexOf ('/');
aoqi@0 1188 } while (slashIndex >= 0);
aoqi@0 1189 return stringPrefix + string;
aoqi@0 1190 } // stripLeadingUnderscoresFromID
aoqi@0 1191
aoqi@0 1192 /**
aoqi@0 1193 *
aoqi@0 1194 **/
aoqi@0 1195 public static String parseExpression (Expression e)
aoqi@0 1196 {
aoqi@0 1197 if (e instanceof Terminal)
aoqi@0 1198 return parseTerminal ((Terminal)e);
aoqi@0 1199 else if (e instanceof BinaryExpr)
aoqi@0 1200 return parseBinary ((BinaryExpr)e);
aoqi@0 1201 else if (e instanceof UnaryExpr)
aoqi@0 1202 return parseUnary ((UnaryExpr)e);
aoqi@0 1203 else
aoqi@0 1204 return "(UNKNOWN_VALUE)"; // This shouldn't happen unless someone slips
aoqi@0 1205 // in another type of expression.
aoqi@0 1206 } // parseExpression
aoqi@0 1207
aoqi@0 1208 /**
aoqi@0 1209 *
aoqi@0 1210 **/
aoqi@0 1211 static String parseTerminal (Terminal e)
aoqi@0 1212 {
aoqi@0 1213 if (e.value () instanceof ConstEntry)
aoqi@0 1214 {
aoqi@0 1215 ConstEntry c = (ConstEntry)e.value ();
aoqi@0 1216 if (c.container () instanceof InterfaceEntry)
aoqi@0 1217 return javaQualifiedName (c.container ()) + '.' + c.name ();
aoqi@0 1218 else
aoqi@0 1219 return javaQualifiedName (c) + ".value";
aoqi@0 1220 }
aoqi@0 1221 else if (e.value () instanceof Expression)
aoqi@0 1222 return '(' + parseExpression ((Expression)e.value ()) + ')';
aoqi@0 1223 else if (e.value () instanceof Character)
aoqi@0 1224 {
aoqi@0 1225 if (((Character)e.value ()).charValue () == '\013')
aoqi@0 1226 // e.rep is \v. \v for vertical tab is meaningless in Java.
aoqi@0 1227 return "'\\013'";
aoqi@0 1228 else if (((Character)e.value ()).charValue () == '\007')
aoqi@0 1229 // e.rep is \a. \a for alert is meaningless in Java.
aoqi@0 1230 return "'\\007'";
aoqi@0 1231 else if (e.rep ().startsWith ("'\\x"))
aoqi@0 1232 return hexToOctal (e.rep ());
aoqi@0 1233 else if (e.rep ().equals ("'\\?'"))
aoqi@0 1234 return "'?'";
aoqi@0 1235 else
aoqi@0 1236 return e.rep ();
aoqi@0 1237 }
aoqi@0 1238 else if (e.value () instanceof Boolean)
aoqi@0 1239 return e.value ().toString ();
aoqi@0 1240
aoqi@0 1241 // <d54640> If value is type "unsigned long long" (ull) and its magnitude
aoqi@0 1242 // is greater than the maximal Java long (i.e., IDL long long) value, then
aoqi@0 1243 // return its signed representation rather than its actual representation.
aoqi@0 1244 /*
aoqi@0 1245 // Support long long
aoqi@0 1246 //else if (e.value () instanceof Long)
aoqi@0 1247 else if (e.value () instanceof BigInteger &&
aoqi@0 1248 (e.type ().indexOf ("long long") >= 0 || e.type ().equals ("unsigned long"))) // <klr>
aoqi@0 1249 {
aoqi@0 1250 String rep = e.rep ();
aoqi@0 1251 int index = rep.indexOf (')');
aoqi@0 1252 if (index < 0)
aoqi@0 1253 return rep + 'L';
aoqi@0 1254 else
aoqi@0 1255 return rep.substring (0, index) + 'L' + rep.substring (index);
aoqi@0 1256 }
aoqi@0 1257 */
aoqi@0 1258 else if (e.value () instanceof BigInteger)
aoqi@0 1259 {
aoqi@0 1260 // Get the correct primitive type. Since integer types (octet, short,
aoqi@0 1261 // long, long long, unsigned short, unsigned long, unsigned long long)
aoqi@0 1262 // could be aliased (typedef'ed) to any arbitrary levels, the code
aoqi@0 1263 // below walks up the alias chain to get to the primitive type.
aoqi@0 1264
aoqi@0 1265 // Get the symbol table entry corresponding to the 'type'.
aoqi@0 1266 SymtabEntry typeEntry = (SymtabEntry) symbolTable.get(e.type());
aoqi@0 1267
aoqi@0 1268 // Get to the primitive type.
aoqi@0 1269 while (typeEntry.type() != null) {
aoqi@0 1270 typeEntry = typeEntry.type();
aoqi@0 1271 }
aoqi@0 1272 String type = typeEntry.name();
aoqi@0 1273
aoqi@0 1274 if (type.equals("unsigned long long") &&
aoqi@0 1275 ((BigInteger)e.value ()).compareTo (Expression.llMax) > 0) // value > long long Max?
aoqi@0 1276 {
aoqi@0 1277 // Convert to signed value, which will always be negative.
aoqi@0 1278 BigInteger v = (BigInteger)e.value ();
aoqi@0 1279 v = v.subtract (Expression.twoPow64);
aoqi@0 1280 int index = e.rep ().indexOf (')');
aoqi@0 1281 if (index < 0)
aoqi@0 1282 return v.toString () + 'L';
aoqi@0 1283 else
aoqi@0 1284 return '(' + v.toString () + 'L' + ')';
aoqi@0 1285 }
aoqi@0 1286 else if ( type.indexOf("long long") >= 0 || type.equals("unsigned long") )
aoqi@0 1287 {
aoqi@0 1288 String rep = e.rep ();
aoqi@0 1289 int index = rep.indexOf (')');
aoqi@0 1290 if (index < 0)
aoqi@0 1291 return rep + 'L';
aoqi@0 1292 else
aoqi@0 1293 return rep.substring (0, index) + 'L' + rep.substring (index);
aoqi@0 1294 }
aoqi@0 1295 else
aoqi@0 1296 return e.rep ();
aoqi@0 1297 } // end <d54640>
aoqi@0 1298 else
aoqi@0 1299 return e.rep ();
aoqi@0 1300 } // parseTerminal
aoqi@0 1301
aoqi@0 1302 /**
aoqi@0 1303 *
aoqi@0 1304 **/
aoqi@0 1305 static String hexToOctal (String hex)
aoqi@0 1306 {
aoqi@0 1307 // The format of hex is '/xXX' where XX is one or two hex digits.
aoqi@0 1308 // This statement pulls off XX.
aoqi@0 1309 hex = hex.substring (3, hex.length () - 1);
aoqi@0 1310 return "'\\" + Integer.toString (Integer.parseInt (hex, 16), 8) + "'";
aoqi@0 1311 } // hexToOctal
aoqi@0 1312
aoqi@0 1313 /**
aoqi@0 1314 *
aoqi@0 1315 **/
aoqi@0 1316 static String parseBinary (BinaryExpr e)
aoqi@0 1317 {
aoqi@0 1318 String castString = "";
aoqi@0 1319 if (e.value () instanceof Float || e.value () instanceof Double)
aoqi@0 1320 {
aoqi@0 1321 castString = "(double)";
aoqi@0 1322 if (!(e instanceof Plus || e instanceof Minus ||
aoqi@0 1323 e instanceof Times || e instanceof Divide))
aoqi@0 1324 System.err.println ("Operator " + e.op () + " is invalid on floating point numbers");
aoqi@0 1325 }
aoqi@0 1326 else if (e.value () instanceof Number)
aoqi@0 1327 {
aoqi@0 1328 if (e.type (). indexOf ("long long") >= 0)
aoqi@0 1329 castString = "(long)";
aoqi@0 1330 else
aoqi@0 1331 castString = "(int)";
aoqi@0 1332 }
aoqi@0 1333 else
aoqi@0 1334 {
aoqi@0 1335 castString = "";
aoqi@0 1336 System.err.println ("Unknown type in constant expression");
aoqi@0 1337 }
aoqi@0 1338
aoqi@0 1339 // <d54640> Must emit value rather than representation when type "unsigned
aoqi@0 1340 // long long" (ull) because emitted binary arithmetic expressions containing
aoqi@0 1341 // ull's converted to long (i.e., IDL long long) do not always compute to
aoqi@0 1342 // the correct result.
aoqi@0 1343
aoqi@0 1344 //return castString + '(' + parseExpression (e.left ()) + ' ' + e.op () + ' ' + parseExpression (e.right ()) + ')';
aoqi@0 1345 if (e.type ().equals ("unsigned long long"))
aoqi@0 1346 {
aoqi@0 1347 BigInteger value = (BigInteger)e.value ();
aoqi@0 1348 if (value.compareTo (Expression.llMax) > 0) // value > long long max?
aoqi@0 1349 value = value.subtract (Expression.twoPow64); // Convert to Java long (signed)
aoqi@0 1350 return castString + '(' + value.toString () + 'L' + ')';
aoqi@0 1351 }
aoqi@0 1352 else
aoqi@0 1353 return castString + '(' + parseExpression (e.left ()) + ' ' + e.op () + ' ' + parseExpression (e.right ()) + ')';
aoqi@0 1354 // <d54640> end
aoqi@0 1355 } // parseBinary
aoqi@0 1356
aoqi@0 1357 /**
aoqi@0 1358 *
aoqi@0 1359 **/
aoqi@0 1360 static String parseUnary (UnaryExpr e)
aoqi@0 1361 {
aoqi@0 1362 if (!(e.value () instanceof Number))
aoqi@0 1363 return "(UNKNOWN_VALUE)"; // This shouldn't happen if the parser checked the expression types correctly.
aoqi@0 1364 else if ((e.value () instanceof Float || e.value () instanceof Double) && e instanceof Not)
aoqi@0 1365 return "(UNKNOWN_VALUE)"; // This shouldn't happen if the parser checked the expression types correctly.
aoqi@0 1366 else
aoqi@0 1367 {
aoqi@0 1368 String castString = "";
aoqi@0 1369 if (e.operand ().value () instanceof Float ||
aoqi@0 1370 e.operand ().value () instanceof Double)
aoqi@0 1371 castString = "(double)";
aoqi@0 1372 // Support long long.
aoqi@0 1373 //else
aoqi@0 1374 // castString = "(long)";
aoqi@0 1375 else if (e.type (). indexOf ("long long") >= 0)
aoqi@0 1376 castString = "(long)";
aoqi@0 1377 else
aoqi@0 1378 castString = "(int)";
aoqi@0 1379
aoqi@0 1380 // <d54640> Must emit value rather than representation when type is
aoqi@0 1381 // "unsigned long long" (ull) because emitted unary arithmetic expressions
aoqi@0 1382 // containing a ull converted to long (i.e., IDL long long) do not always
aoqi@0 1383 // compute to the correct result.
aoqi@0 1384
aoqi@0 1385 //return castString + e.op () + parseExpression (e.operand ());
aoqi@0 1386 if (e.type ().equals ("unsigned long long"))
aoqi@0 1387 {
aoqi@0 1388 BigInteger value = (BigInteger)e.value ();
aoqi@0 1389 if (value.compareTo (Expression.llMax) > 0) // value > long long max?
aoqi@0 1390 value = value.subtract (Expression.twoPow64); // Convert to Java long (signed)
aoqi@0 1391 return castString + '(' + value.toString () + 'L' + ')';
aoqi@0 1392 }
aoqi@0 1393 else
aoqi@0 1394 return castString + e.op () + parseExpression (e.operand ());
aoqi@0 1395 // end <d54640>
aoqi@0 1396 }
aoqi@0 1397 } // parseUnary
aoqi@0 1398
aoqi@0 1399 /**
aoqi@0 1400 *
aoqi@0 1401 **/
aoqi@0 1402 public static boolean IDLEntity (SymtabEntry entry)
aoqi@0 1403 {
aoqi@0 1404 boolean rc = true;
aoqi@0 1405 if (entry instanceof PrimitiveEntry || entry instanceof StringEntry)
aoqi@0 1406 rc = false;
aoqi@0 1407 else if (entry instanceof TypedefEntry)
aoqi@0 1408 rc = IDLEntity (entry.type ());
aoqi@0 1409 return rc;
aoqi@0 1410 } // IDLEntity
aoqi@0 1411
aoqi@0 1412 // <d62023>
aoqi@0 1413 /**
aoqi@0 1414 * @return true if the current setting of corbaLevel is within delta of
aoqi@0 1415 * the range min <= corbaLevel <= max
aoqi@0 1416 **/
aoqi@0 1417 public static boolean corbaLevel (float min, float max)
aoqi@0 1418 {
aoqi@0 1419 float level = Compile.compiler.arguments.corbaLevel;
aoqi@0 1420 float delta = 0.001f;
aoqi@0 1421 if ((level - min + delta >= 0.0f) && (max - level + delta >= 0.0f))
aoqi@0 1422 return true;
aoqi@0 1423 else
aoqi@0 1424 return false;
aoqi@0 1425 } // corbaLevel
aoqi@0 1426
aoqi@0 1427 static Hashtable symbolTable = new Hashtable ();
aoqi@0 1428 static Hashtable packageTranslation = new Hashtable() ;
aoqi@0 1429 } // class Util

mercurial