gov.llnl.babel.backend.mangler
Class ShaMangler

java.lang.Object
  extended by gov.llnl.babel.backend.mangler.ShaMangler
All Implemented Interfaces:
NameMangler
Direct Known Subclasses:
CMangler, FortranMangler

public class ShaMangler
extends java.lang.Object
implements NameMangler

This class uses the SHA message digest algorithm to generate the mangled part of a shortened identifier. The message digest of the symbol, method and suffix is converted into a sequence of allowable characters. The mangled part of the name may appear random, but it is completely deterministic and reproducible.


Constructor Summary
ShaMangler(int maxNameLen, int maxUnmangled, char[] charSet)
          Create an instance of the ShaMangler.
 
Method Summary
 java.lang.String shortArrayName(java.lang.String symbol, java.lang.String method, java.lang.String suffix)
          Create the short name from the symbol, method and suffix.
 java.lang.String shortName(java.lang.String symbol, java.lang.String suffix)
          Convert a type name to a short length.
 java.lang.String shortName(java.lang.String symbol, java.lang.String method, java.lang.String suffix)
          Create the short name from the symbol, method and suffix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShaMangler

public ShaMangler(int maxNameLen,
                  int maxUnmangled,
                  char[] charSet)
           throws java.security.NoSuchAlgorithmException
Create an instance of the ShaMangler.

Parameters:
maxNameLen - this is the maximum number of characters that a name may contain. For Fortran 90 and strict ANSI C, this would be 31. For strict FORTRAN 77, this would be 6.
maxUnmangled - this indicates how many characters out of maxNameLen should be used for unmangled content.
charSet - this provides the complete set of allowable characters that are considered distinct by the language compiler.
Throws:
java.security.NoSuchAlgorithmException - this will only be thrown if the SHA message digest algorithm is not available.
Method Detail

shortName

public java.lang.String shortName(java.lang.String symbol,
                                  java.lang.String method,
                                  java.lang.String suffix)
                           throws java.io.UnsupportedEncodingException
Create the short name from the symbol, method and suffix. This mangler uses the SHA message digest to generate the extra characters to attempt to avoid a symbol conflict.

Specified by:
shortName in interface NameMangler
Parameters:
symbol - the fully qualified name of the class or interface holding the method. This name has periods separating the different package components and class name.
method - this is the full name of the method. For overloaded methods, this should be the full method name.
suffix - this suffix is used to designate what kind of kind of function name is being generated (i.e., stub, skel, or impl).
Returns:
a string whose length is less than or equal to the maximum allowed length. The name will have an unmangled part and a mangled part (assuming it needs to be shortened).
Throws:
java.io.UnsupportedEncodingException - this exception should never occur because the ISO-8859-1 encoding used by this method is supposed to be available on all JVMs.

shortArrayName

public java.lang.String shortArrayName(java.lang.String symbol,
                                       java.lang.String method,
                                       java.lang.String suffix)
                                throws java.io.UnsupportedEncodingException
Create the short name from the symbol, method and suffix. This mangler uses the SHA message digest to generate the extra characters to attempt to avoid a symbol conflict.

Specified by:
shortArrayName in interface NameMangler
Parameters:
symbol - the fully qualified name of the class or interface holding the method. This name has periods separating the different package components and class name.
method - this is the full name of the method. For overloaded methods, this should be the full method name.
suffix - this suffix is used to designate what kind of kind of function name is being generated (i.e., stub, skel, or impl).
Returns:
a string whose length is less than or equal to the maximum allowed length. The name will have an unmangled part and a mangled part (assuming it needs to be shortened).
Throws:
java.io.UnsupportedEncodingException - this exception should never occur because the ISO-8859-1 encoding used by this method is supposed to be available on all JVMs.

shortName

public java.lang.String shortName(java.lang.String symbol,
                                  java.lang.String suffix)
                           throws java.io.UnsupportedEncodingException
Description copied from interface: NameMangler
Convert a type name to a short length.

Specified by:
shortName in interface NameMangler
Throws:
java.io.UnsupportedEncodingException