gov.llnl.babel.backend.mangler

Class ShaMangler

Implemented Interfaces:
NameMangler
Known Direct 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

String
shortArrayName(String symbol, String method, String suffix)
Create the short name from the symbol, method and suffix.
String
shortName(String symbol, String suffix)
String
shortName(String symbol, String method, String suffix)
Create the short name from the symbol, method and suffix.

Constructor Details

ShaMangler

public ShaMangler(int maxNameLen,
                  int maxUnmangled,
                  char[] charSet)
            throws 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.

Method Details

shortArrayName

public String shortArrayName(String symbol,
                             String method,
                             String suffix)
            throws 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).

shortName

public String shortName(String symbol,
                        String suffix)
            throws UnsupportedEncodingException
Specified by:
shortName in interface NameMangler

shortName

public String shortName(String symbol,
                        String method,
                        String suffix)
            throws 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).