1 /*
   2  * Copyright 2000-2005 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *  
  23  */
  24 
  25 package sun.jvm.hotspot.types;
  26 
  27 import java.util.*;
  28 
  29 /** This is the top-level interface which describes C++ classes and
  30     primitive types as well as enough about Java primitive and object
  31     types to allow the oop hierarchy to be constructed. */
  32 
  33 public interface Type {
  34   public String getName();
  35 
  36   /* The supertype of this type. May be null for top-level classes and
  37      primitive types. NOTE that multiple inheritance is currently not
  38      handled. However, it could (probably) be by making this return a
  39      list and adding appropriate routines to cast an address of one
  40      type to another. */
  41   public Type getSuperclass();
  42 
  43   /** The size in bytes, at the machine level, of this type. This
  44       should be equivalent to the sizeof operator -- i.e., should
  45       include any compiler-inserted fields like the vtbl for C++
  46       types. */
  47   public long getSize();
  48 
  49   /** Indicates whether this type is a C integer type -- regardless of
  50       size or signedness. */
  51   public boolean isCIntegerType();
  52 
  53   /** Indicates whether this type is const char*. */
  54   public boolean isCStringType();
  55 
  56   /** Indicates whether this type is one of the Java primitive types. */
  57   public boolean isJavaPrimitiveType();
  58 
  59   /** Indicates whether this type is an oop type in the VM. */
  60   public boolean isOopType();
  61 
  62   /** Indicates whether this type is a pointer type. */
  63   public boolean isPointerType();
  64 
  65   /** This is permissive and returns the CField regardless of its type
  66       as long as it is present. Returns null if the field was not
  67       found, unless throwExceptionIfNotFound is true, in which case a
  68       RuntimeException is thrown (for debugging purposes). */
  69   public Field getField(String fieldName, boolean searchSuperclassFields,
  70                         boolean throwExceptionIfNotFound);
  71 
  72   /** This is permissive and returns the CField regardless of its type
  73       as long as it is present -- it is equivalent to
  74       getField(fieldName, searchSuperclassFields, true). Throws a
  75       RuntimeException if the field was not found. */
  76   public Field getField(String fieldName, boolean searchSuperclassFields);
  77 
  78   /** This is permissive and returns the CField regardless of its type
  79       as long as it is present. This does not search superclasses'
  80       fields; it is equivalent to getField(fieldName, false). Throws a
  81       RuntimeException if the field was not found. */
  82   public Field getField(String fieldName);
  83 
  84   /** If there is a mismatch between the declared type and the type
  85       which would otherwise be returned from this routine, it throws a
  86       WrongTypeException. declaredType must not be null. Throws a
  87       RuntimeException if field was otherwise not found. */
  88   public Field getField(String fieldName, Type declaredType,
  89                         boolean searchSuperclassFields) throws WrongTypeException;
  90 
  91   /** If there is a mismatch between the declared type and the type
  92       which would otherwise be returned from this routine, it throws a
  93       WrongTypeException. declaredType must not be null. This does not
  94       search superclasses' fields; it is equivalent to
  95       getField(fieldName, declaredType, false). Throws a
  96       RuntimeException if field was otherwise not found. */
  97   public Field getField(String fieldName, Type declaredType) throws WrongTypeException;
  98 
  99   /** Iterate over all of the fields in this type but <B>not</B> in
 100       any of its superclasses. The returned Iterator's "remove" method
 101       must not be called. */
 102   public Iterator getFields();
 103 
 104   /** <P> These accessors are designed to allow strong type checking
 105       of certain well-known types of fields, specifically Java
 106       primitive and oop types. Specialized fields for all primitive
 107       types, as well as oop fields, are required to have strong type
 108       checking and a WrongTypeException should be thrown if the given
 109       field is not precisely of the given type. Address and Oop fields
 110       are more permissive to reduce the complexity of the initial
 111       implementation. </P>
 112 
 113       <P> These accessors do not search the superclass's fields. </P>
 114   */
 115   public JBooleanField       getJBooleanField      (String fieldName) throws WrongTypeException;
 116   public JByteField          getJByteField         (String fieldName) throws WrongTypeException;
 117   public JCharField          getJCharField         (String fieldName) throws WrongTypeException;
 118   public JDoubleField        getJDoubleField       (String fieldName) throws WrongTypeException;
 119   public JFloatField         getJFloatField        (String fieldName) throws WrongTypeException;
 120   public JIntField           getJIntField          (String fieldName) throws WrongTypeException;
 121   public JLongField          getJLongField         (String fieldName) throws WrongTypeException;
 122   public JShortField         getJShortField        (String fieldName) throws WrongTypeException;
 123   public CIntegerField       getCIntegerField      (String fieldName) throws WrongTypeException;
 124   public OopField            getOopField           (String fieldName) throws WrongTypeException;
 125   public AddressField        getAddressField       (String fieldName);
 126 }