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

Mon, 04 May 2009 18:40:45 -0700

author
tbell
date
Mon, 04 May 2009 18:40:45 -0700
changeset 72
e149090eb21a
parent 1
55540e827aef
child 158
91006f157c46
permissions
-rw-r--r--

6529590: flaw in com.sun.corba.se.impl.presentation.rmi.IDLNameTranslatorImpl
Reviewed-by: darcy

duke@1 1 /*
duke@1 2 * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25 /*
duke@1 26 * COMPONENT_NAME: idl.toJava
duke@1 27 *
duke@1 28 * ORIGINS: 27
duke@1 29 *
duke@1 30 * Licensed Materials - Property of IBM
duke@1 31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
duke@1 32 * RMI-IIOP v1.0
duke@1 33 *
duke@1 34 */
duke@1 35
duke@1 36 package com.sun.tools.corba.se.idl.toJavaPortable;
duke@1 37
duke@1 38 // NOTES:
duke@1 39
duke@1 40 import java.util.Enumeration;
duke@1 41 import java.util.Hashtable;
duke@1 42
duke@1 43 import com.sun.tools.corba.se.idl.*;
duke@1 44
duke@1 45 // This class is passed through the JavaGenerator.HelperType methods.
duke@1 46 // It is ONLY used when a recursive sequence is detected. ie.
duke@1 47 //
duke@1 48 // struct S1
duke@1 49 // {
duke@1 50 // sequence <S1> others;
duke@1 51 // };
duke@1 52
duke@1 53 /**
duke@1 54 *
duke@1 55 **/
duke@1 56 public class TCOffsets
duke@1 57 {
duke@1 58 /**
duke@1 59 * Return -1 if the given name is not in the list of types.
duke@1 60 **/
duke@1 61 public int offset (String name)
duke@1 62 {
duke@1 63 Integer value = (Integer)tcs.get (name);
duke@1 64 return value == null ? -1 : value.intValue ();
duke@1 65 } // offset
duke@1 66
duke@1 67 /**
duke@1 68 *
duke@1 69 **/
duke@1 70 public void set (SymtabEntry entry)
duke@1 71 {
duke@1 72 if (entry == null)
duke@1 73 offset += 8;
duke@1 74 else
duke@1 75 {
duke@1 76 tcs.put (entry.fullName (), new Integer (offset));
duke@1 77 offset += 4;
duke@1 78 String repID = Util.stripLeadingUnderscoresFromID (entry.repositoryID ().ID ());
duke@1 79 if (entry instanceof InterfaceEntry)
duke@1 80 offset += alignStrLen (repID) + alignStrLen (entry.name ());
duke@1 81 else if (entry instanceof StructEntry)
duke@1 82 offset += alignStrLen (repID) + alignStrLen (entry.name ()) + 4;
duke@1 83 else if (entry instanceof UnionEntry)
duke@1 84 offset += alignStrLen (repID) + alignStrLen (entry.name ()) + 12;
duke@1 85 else if (entry instanceof EnumEntry)
duke@1 86 {
duke@1 87 offset += alignStrLen (repID) + alignStrLen (entry.name ()) + 4;
duke@1 88 Enumeration e = ((EnumEntry)entry).elements ().elements ();
duke@1 89 while (e.hasMoreElements ())
duke@1 90 offset += alignStrLen ((String)e.nextElement ());
duke@1 91 }
duke@1 92 else if (entry instanceof StringEntry)
duke@1 93 offset += 4;
duke@1 94 else if (entry instanceof TypedefEntry)
duke@1 95 {
duke@1 96 offset += alignStrLen (repID) + alignStrLen (entry.name ());
duke@1 97 if (((TypedefEntry)entry).arrayInfo ().size () != 0)
duke@1 98 offset += 8;
duke@1 99 }
duke@1 100 }
duke@1 101 } // set
duke@1 102
duke@1 103 /**
duke@1 104 * Return the full length of the string type: 4 byte length, x bytes for
duke@1 105 * string + 1 for the null terminator, align it so it ends on a 4-byte
duke@1 106 * boundary. This method assumes the string starts at a 4-byte boundary
duke@1 107 * since it doesn't do any leading alignment.
duke@1 108 **/
duke@1 109 public int alignStrLen (String string)
duke@1 110 {
duke@1 111 int len = string.length () + 1;
duke@1 112 int align = 4 - (len % 4);
duke@1 113 if (align == 4) align = 0;
duke@1 114 return len + align + 4;
duke@1 115 } // alignStrLen
duke@1 116
duke@1 117 /**
duke@1 118 *
duke@1 119 **/
duke@1 120 public void setMember (SymtabEntry entry)
duke@1 121 {
duke@1 122 offset += alignStrLen (entry.name ());
duke@1 123 if (((TypedefEntry)entry).arrayInfo ().size () != 0)
duke@1 124 offset += 4;
duke@1 125 } // setMember
duke@1 126
duke@1 127 /**
duke@1 128 *
duke@1 129 **/
duke@1 130 public int currentOffset ()
duke@1 131 {
duke@1 132 return offset;
duke@1 133 } // currentOffset
duke@1 134
duke@1 135 /**
duke@1 136 *
duke@1 137 **/
duke@1 138 public void bumpCurrentOffset (int value)
duke@1 139 {
duke@1 140 offset += value;
duke@1 141 } // bumpCurrentOffset
duke@1 142
duke@1 143 private Hashtable tcs = new Hashtable ();
duke@1 144 private int offset = 0;
duke@1 145 } // class TCOffsets

mercurial