Class StringManager

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.Integer>

    public class StringManager
    extends java.util.LinkedHashMap<java.lang.String,​java.lang.Integer>
    Handle all the constant strings. The constant strings will be write into the data section. At runtime the strings will be instantiate on the fly and hold in a table.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Integer get​(java.lang.Object str)
      Get the positive id for the string.
      (package private) FunctionName getStringConstantFunction()
      Get the function name object for the #stringConstant(int).
      (package private) void prepareFinish​(ModuleWriter writer)
      Finish the prepare.
      private static void writeVaruint32​(int value, java.io.OutputStream out)
      Write an unsigned integer.
      • Methods inherited from class java.util.LinkedHashMap

        clear, containsValue, entrySet, forEach, getOrDefault, keySet, removeEldestEntry, replaceAll, values
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
    • Field Detail

      • stringConstantFunction

        private FunctionName stringConstantFunction
      • stringMemoryOffset

        private int stringMemoryOffset
    • Constructor Detail

      • StringManager

        StringManager​(WasmOptions options)
        Create a new instance.
        Parameters:
        options - compiler properties and shared managers
    • Method Detail

      • get

        public java.lang.Integer get​(@Nonnull
                                     java.lang.Object str)
        Get the positive id for the string.
        Specified by:
        get in interface java.util.Map<java.lang.String,​java.lang.Integer>
        Overrides:
        get in class java.util.LinkedHashMap<java.lang.String,​java.lang.Integer>
        Parameters:
        str - the string
        Returns:
        the id
      • getStringConstantFunction

        @Nonnull
        FunctionName getStringConstantFunction()
        Get the function name object for the #stringConstant(int).
        Returns:
        the name
        See Also:
        #stringConstant(int)
      • prepareFinish

        void prepareFinish​(ModuleWriter writer)
                    throws java.io.IOException
        Finish the prepare. Now no new strings should be added.
        Parameters:
        writer - the targets for the strings
        Throws:
        java.io.IOException - if any I/O error occur
      • writeVaruint32

        private static void writeVaruint32​(@Nonnegative
                                           int value,
                                           java.io.OutputStream out)
                                    throws java.io.IOException
        Write an unsigned integer.
        Parameters:
        value - the value
        out - target stream
        Throws:
        java.io.IOException - if an I/O error occurs.