Class ClassHierarchy

java.lang.Object
simula.compiler.utilities.ClassHierarchy

public abstract class ClassHierarchy extends Object

ClasFile coding utility: ClassHierarchy.

Mail from: Adam Sotona adam.sotona@oracle.com on Apr 28, 2024.

Your compiler reached the complexity where you reference generated classes from other generated classes. Class-File API in certain circumstances needs to know some information about the classes referenced from the generated bytecode. Such information is provided in ClassHierarchyInfo using functional interface ClassHierarchyResolver. By default is the information obtained from system class loader. However, the classes you generate are probably not yet known to the system class loader.

You should specify a custom ClassHierarchyResolver for your compiler as a Class-File API option ClassFile.of(ClassFile.ClassHierarchyResolverOption.of(...)).

Here you have multiple options how to provide the missing information using combinations of ClassHierarchyResolver factory methods and custom code:

For example, if the required classes have been already generated and you can provide a physical access to them, you can compose the ClassHierarchyResolver this way:

ClassHierarchyResolver.defaultResolver().orElse(ClassHierarchyResolver. ofResourceParsing(Function<ClassDesc, InputStream>).cached())

Or if you know all the generated classes in advance, you can provide the missing info about the generated classes in a set and map form:

ClassHierarchyResolver.defaultResolver().orElse(ClassHierarchyResolver. of(Collection<ClassDesc> interfaces, Map<ClassDesc, ClassDesc> classToSuperClass))

Or in a form of dynamic direct implementation of the ClassHierarchyResolver:

ClassHierarchyResolver.defaultResolver().orElse(classDesc -> isInterface ? : ClassHierarchyInfo.ofInterface() : ClassHierarchyInfo.ofClass(ClassDesc superClass))

  • Field Details

  • Constructor Details

    • ClassHierarchy

      private ClassHierarchy()
      Default Constructor: NOT USED
  • Method Details

    • init

      public static void init()
      Initiale local variables.
    • getResolver

      public static ClassHierarchyResolver getResolver()
      get the ClassHierarchyResolver.
      Returns:
      the ClassHierarchyResolver.
    • addClassToSuperClass

      public static void addClassToSuperClass(ClassDesc cld, ClassDesc sup)
      Add a class to the classToSuperClass map.
      Parameters:
      cld - a class
      sup - a super class
    • getRealSuper

      public static ClassDesc getRealSuper(ClassDesc sub)
      Get real super class. Ignore RTS_CLASS and RTS_PROCEDURE-
      Parameters:
      sub - a sub class.
      Returns:
      real super class.
    • getRealPrefix

      public static String getRealPrefix(String sub)
      Get real prefix.
      Parameters:
      sub - a sub class.
      Returns:
      real prefix.
    • getClassDesc

      public static ClassDesc getClassDesc(String classID)
      Returns the resulting ClassDesc.
      Parameters:
      classID - class ident.
      Returns:
      the resulting ClassDesc.
    • list

      public static void list()
      Debug utility: list classToSuperClass map.
    • print

      public static void print()
      Debug utility: print classToSuperClass map etc.
    • lookup

      private static ClassHierarchy.Node lookup(String name)
      Debug utility: Lookup a node.
      Parameters:
      name - node's name.
      Returns:
      the node.
    • writeObject

      public static void writeObject(AttributeOutputStream oupt) throws IOException
      Write a ClassHierarchy object to a AttributeOutputStream.
      Parameters:
      oupt - the AttributeOutputStream to write to.
      Throws:
      IOException - if something went wrong.
    • readObject

      public static void readObject(AttributeInputStream inpt) throws IOException
      Read a ClassHierarchy object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Throws:
      IOException - if something went wrong.