mjc

org.multijava.mjc
Class CMethod

java.lang.Object
  extended byorg.multijava.util.Utils
      extended byorg.multijava.mjc.CMember
          extended byorg.multijava.mjc.CMethod
All Implemented Interfaces:
Cloneable, Comparable, Constants, Constants
Direct Known Subclasses:
CBinaryMethod, CSourceMethod

public abstract class CMethod
extends CMember
implements Comparable

This class represents an actual method, whether generated from source code or read from a class file. It includes the type signature of the method and operations for checking the method's applicability and whether it is more specfic than a given method.


Field Summary
private  boolean cachedPure
          The pureness of this method.
protected  CContextType declarationContext
          The context in which this method was declared.
private  CClassType[] exceptions
           
protected  CMethod generatefrom
           
private  int gfID
          Integers used in bodyIdent() to give a unique name to a multimethod's associated $body method.
private  boolean isMixedPleomorphic
          Indicates whether this method is pleomorphic with one external generic function and one or more internal generic functions.
private  int methodID
           
 boolean needsPrivacyModifierRemoved
          Indicates whether this method should have its privacy modifier removed for the purposes of code generation.
private  CMethodSet overriddenMethodSet
          The set of methods overridden by this method, may be null.
private  CSpecializedType[] parameters
           
private  boolean pureCached
          Indicates if the pureness of this method has been calculated and cached in the field cachedPure.
private  boolean purityWasChanged
          Indicates if the pureness of this method was inherited from a supermethod or a class/interface.
private  CClassType receiverType
           
private  CType returnType
           
protected  BitSet specArgs
          If this is a top method, we record which arguments of the generic function are specialized.
 boolean synthetic
           
protected  CMethod topConcreteMethod
          The top concrete method of the generic function to which this belongs.
private  CTypeVariable[] typevariables
           
 
Fields inherited from class org.multijava.mjc.CMember
 
Fields inherited from class org.multijava.util.Utils
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO
 
Fields inherited from interface org.multijava.mjc.Constants
ACC_MODIFIER_FLAGS_MASK, ACC_NON_NULL, ACC_NON_NULL_BY_DEFAULT, ACC_NULLABLE, ACC_NULLABLE_BY_DEFAULT, ACC_PURE, ACCESS_FLAG_ARRAY, ACCESS_FLAG_NAMES, AMID_JAVA_MATH, AMID_MAX, AMID_SAFE_MATH, CMP_VERSION, IMPLICITLY_NON_NULL, JAV_ASSERTION_ERROR, JAV_CLASS, JAV_CLASSLOADER, JAV_CLASSNOTFOUND_EXCEPTION, JAV_CLONE, JAV_CLONEABLE, JAV_CONSTRUCTOR, JAV_ERROR, JAV_EXCEPTION, JAV_INIT, JAV_LENGTH, JAV_NAME_SEPARATOR, JAV_NOCLASSDEFFOUND_ERROR, JAV_OBJECT, JAV_OUTER_THIS, JAV_RMJ_RUNTIME_EXCEPTION, JAV_RUNTIME, JAV_RUNTIME_EXCEPTION, JAV_SERIALIZABLE, JAV_STATIC_INIT, JAV_STRING, JAV_STRINGBUFFER, JAV_SUPER, JAV_THIS, JAV_THROWABLE, MJ_ANCHOR, NULLITY_MODS, OPE_BAND, OPE_BNOT, OPE_BOR, OPE_BSR, OPE_BXOR, OPE_EQ, OPE_GE, OPE_GT, OPE_LAND, OPE_LE, OPE_LNOT, OPE_LOR, OPE_LT, OPE_MINUS, OPE_NE, OPE_PERCENT, OPE_PLUS, OPE_POSTDEC, OPE_POSTINC, OPE_PREDEC, OPE_PREINC, OPE_SIMPLE, OPE_SL, OPE_SLASH, OPE_SR, OPE_STAR, TID_ARRAY, TID_BOOLEAN, TID_BYTE, TID_CHAR, TID_CLASS, TID_DOUBLE, TID_FLOAT, TID_INT, TID_LONG, TID_MAX, TID_SHORT, TID_VOID, UNIV_ARRAY_TMP, UNIV_TMP
 
Fields inherited from interface org.multijava.util.classfile.Constants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VOLATILE, ATT_ANCHOR, ATT_BRIDGE, ATT_CODE, ATT_CONSTANTVALUE, ATT_DEPRECATED, ATT_DISPATCHER, ATT_EXCEPTIONS, ATT_GENERIC, ATT_GENERIC_FUNCTIONS, ATT_INNERCLASSES, ATT_LINENUMBERTABLE, ATT_LOCALVARIABLETABLE, ATT_MM_BODY, ATT_REDIRECTOR, ATT_RMJ_GLUE, ATT_RMJ_SIGNATURE, ATT_RUNTIME_VISIBLE_ANNOTATIONS, ATT_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, ATT_SIGNATURE, ATT_SOURCEFILE, ATT_SYNTHETIC, ATT_UNIVERSE_FIELD, ATT_UNIVERSE_METHOD, ATT_UNIVERSE_VERSION, CST_CLASS, CST_DOUBLE, CST_FIELD, CST_FLOAT, CST_INTEGER, CST_INTERFACEMETHOD, CST_LONG, CST_METHOD, CST_NAMEANDTYPE, CST_STRING, CST_UTF8, ENV_DEBUG_MODE, ENV_USE_CACHE, JAVA_MAGIC, JAVA_MAJOR, JAVA_MINOR, MAX_CODE_PER_METHOD, opc_aaload, opc_aastore, opc_aconst_null, opc_aload, opc_aload_0, opc_aload_1, opc_aload_2, opc_aload_3, opc_anewarray, opc_areturn, opc_arraylength, opc_astore, opc_astore_0, opc_astore_1, opc_astore_2, opc_astore_3, opc_athrow, opc_baload, opc_bastore, opc_bipush, opc_caload, opc_castore, opc_checkcast, opc_d2f, opc_d2i, opc_d2l, opc_dadd, opc_daload, opc_dastore, opc_dcmpg, opc_dcmpl, opc_dconst_0, opc_dconst_1, opc_ddiv, opc_dload, opc_dload_0, opc_dload_1, opc_dload_2, opc_dload_3, opc_dmul, opc_dneg, opc_drem, opc_dreturn, opc_dstore, opc_dstore_0, opc_dstore_1, opc_dstore_2, opc_dstore_3, opc_dsub, opc_dup, opc_dup2, opc_dup2_x1, opc_dup2_x2, opc_dup_x1, opc_dup_x2, opc_f2d, opc_f2i, opc_f2l, opc_fadd, opc_faload, opc_fastore, opc_fcmpg, opc_fcmpl, opc_fconst_0, opc_fconst_1, opc_fconst_2, opc_fdiv, opc_fload, opc_fload_0, opc_fload_1, opc_fload_2, opc_fload_3, opc_fmul, opc_fneg, opc_frem, opc_freturn, opc_fstore, opc_fstore_0, opc_fstore_1, opc_fstore_2, opc_fstore_3, opc_fsub, opc_getfield, opc_getstatic, opc_goto, opc_goto_w, opc_i2b, opc_i2c, opc_i2d, opc_i2f, opc_i2l, opc_i2s, opc_iadd, opc_iaload, opc_iand, opc_iastore, opc_iconst_0, opc_iconst_1, opc_iconst_2, opc_iconst_3, opc_iconst_4, opc_iconst_5, opc_iconst_m1, opc_idiv, opc_if_acmpeq, opc_if_acmpne, opc_if_icmpeq, opc_if_icmpge, opc_if_icmpgt, opc_if_icmple, opc_if_icmplt, opc_if_icmpne, opc_ifeq, opc_ifge, opc_ifgt, opc_ifle, opc_iflt, opc_ifne, opc_ifnonnull, opc_ifnull, opc_iinc, opc_iload, opc_iload_0, opc_iload_1, opc_iload_2, opc_iload_3, opc_imul, opc_ineg, opc_instanceof, opc_invokeinterface, opc_invokespecial, opc_invokestatic, opc_invokevirtual, opc_ior, opc_irem, opc_ireturn, opc_ishl, opc_ishr, opc_istore, opc_istore_0, opc_istore_1, opc_istore_2, opc_istore_3, opc_isub, opc_iushr, opc_ixor, opc_jsr, opc_jsr_w, opc_l2d, opc_l2f, opc_l2i, opc_ladd, opc_laload, opc_land, opc_lastore, opc_lcmp, opc_lconst_0, opc_lconst_1, opc_ldc, opc_ldc2_w, opc_ldc_w, opc_ldiv, opc_lload, opc_lload_0, opc_lload_1, opc_lload_2, opc_lload_3, opc_lmul, opc_lneg, opc_lookupswitch, opc_lor, opc_lrem, opc_lreturn, opc_lshl, opc_lshr, opc_lstore, opc_lstore_0, opc_lstore_1, opc_lstore_2, opc_lstore_3, opc_lsub, opc_lushr, opc_lxor, opc_monitorenter, opc_monitorexit, opc_multianewarray, opc_new, opc_newarray, opc_nop, opc_pop, opc_pop2, opc_putfield, opc_putstatic, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_swap, opc_tableswitch, opc_wide, opc_xxxunusedxxx, POO_ASCII_CONSTANT, POO_CLASS_CONSTANT, POO_DOUBLE_CONSTANT, POO_FLOAT_CONSTANT, POO_INTEGER_CONSTANT, POO_LONG_CONSTANT, POO_NAT_CONSTANT, POO_REF_CONSTANT, POO_STRING_CONSTANT, TYP_ADDRESS, TYP_DOUBLE, TYP_FLOAT, TYP_INT, TYP_LONG, TYP_REFERENCE, TYP_VOID
 
Constructor Summary
CMethod(MemberAccess access, String ident, CType returnType, CSpecializedType[] parameters, CClassType[] exceptions, CTypeVariable[] typevariables, boolean deprecated, CContextType declarationContext)
          Constructs a method member.
 
Method Summary
abstract  CAmbiguousDispatcherClass ambiguousDispatcherClass()
          Returns the ambiguous-method dispatcher class for this.
abstract  CClass anchorClass()
          Returns the $anchor class for this generic function.
 boolean apparentlySpecializes(CMethod other)
           
 boolean apparentlySpecializes(CMethod other, CClassType[] args)
          Checks whether this method apparently specializes a given method.
 boolean apparentlySpecializes(CMethod other, CClassType[] args, boolean enableUniv)
           
protected  String bodyGenericSignature()
           
protected  String bodyIdent()
           
protected  String bodySignature()
           
 int compareTo(Object o)
          Allows methods to be sorted.
 CContextType declarationContext()
          Returns the declaration context.
abstract  CDispatcherSignature dispatcherSignature()
          Returns the $signature class for this.
 boolean equalParameters(CMethod other)
          Returns true if the given method and this method have parameters with the same types.
 boolean equalParametersNoUniverses(CMethod other)
           
 boolean equals(Object other)
          Returns true if the given object is a CMethod and the two methods have same signature.
abstract  int functionNumber()
          Returns the function field number for this generic function within its $anchor class.
 boolean genDispatch(CodeSequence code, CodeLabel nextAlternative, CMethod topConcreteMethod, String dispatcherName)
          Generates the dispatch code for the specialized arguments of this method.
 GenericFunctionInfo genGenericFunctionInfo()
          Generates the generic function information for this required when generating a class file, or returns null if this method requires no such information.
 void genGenFuncInvocation(CodeSequence code, boolean nonVirtual)
          Generates a sequence of bytecode for invoking this method, assuming appropriate argument values have already been pushed to the JVM stack.
 ArrayList genMethodInfo()
          Generate the method information for this for constructing a class file [JVM2 4.6].
 CMethod getGenerateFrom()
           
 String getGenericSignature()
           
 CMethod getMethod()
           
 String getSignature()
          Returns the bytecode type signature of this method as seen by callers.
 BitSet getSpecArgs()
          Return the bit set indicating which arguments of the associated generic function are specialized.
 CTypeVariable[] getTypeVariable()
           
 int hashCode()
          Returns the hash code for this, calculated from the hash codes of the methods identifier, receiver, and argument types.
 boolean hasSameSignature(CMethod other)
          Has this method the same signature as the one given as argument ?
 boolean hasSameSignature(CMethod other, CClassType[] substitution)
          Has this method the same signature as the one given as argument ?
 boolean hasSameSignatureNoUniverses(CMethod other)
           
 boolean isAbstract()
          Returns true iff this method is abstract.
 boolean isApplicable(String ident, CType recvType, CType[] actuals, CClassType[] args)
          Returns true if this method is applicable to a method call with the given identifier and actual (static) argument types.
private  boolean isApplicableArgTypes(CType recvType, CType[] actuals, boolean initStyleCheck, CClassType[] args)
          Returns true if the given actual argument types are assignable to this methods formals and receiver.
 boolean isConstructor()
          Returns true iff this method is a constructor.
 boolean isExternal()
          Indicates whether this method is external, i.e., whether its host is different than its logical owner.
 boolean isGenericMethod()
          whether this method is generic or not
 boolean isInExternalGF()
          Indicates whether this method belongs to an external generic function.
 boolean isLocalTo(CContextType context)
          Indicates whether this method is declared local to the given context.
 boolean isMixedPleomorphic()
          Indicates whether this method is pleomorphic with one external generic function and one or more internal generic functions.
 boolean isMoreSpecificThan(CMethod other)
           
 boolean isMoreSpecificThan(CMethod other, boolean b)
           
 boolean isMoreSpecificThan(CMethod other, CClassType[] args)
          Returns true if this method is strictly more specific than the given method.
 boolean isMoreSpecificThan(CMethod other, CClassType[] args, boolean intrsDoNotExtendObject)
          Returns true if this method is strictly more specific than the given method.
 boolean isMoreSpecificThan(CMethod other, CClassType[] args, boolean intrsDoNotExtendObject, boolean enableUniv)
           
 boolean isNative()
          Returns true iff this method is native.
 boolean isPure()
          Returns true if this method is pure.
private  boolean isPureInherited()
          Returns true if this method inherits pureness from its owner or supertypes, including both superclasses and interfaces.
 boolean isSynthetic()
           
 CTypeVariable lookupTypeVariable(String ident)
           
protected  String mmGenericSignature()
           
protected  String mmSignature()
          Returns the type signature of this method in the multimethod descriptor format, which is like a regular bytecode method descriptor but includes explicit specializers.
protected  CMethodSet overriddenMethodSet()
          Returns the set of methods overridden by this method, may be null.
 CSpecializedType[] parameters()
          Returns the static and dynamic types of this methods parameters.
 int parametersSize()
          Returns the size (in stack slots) of the parameters of this.
abstract  void plantFunctionRef(CodeSequence code)
          Generates bytecode to put a reference to the external function field for the external generic function on the JVM stack.
protected  void plantMMInvocation(CodeSequence code, String dispatcherName)
          Plants an invocation of the multimethod body represented by this.
abstract  void plantOldFunctionRef(CodeSequence code, boolean forSuper, boolean fromOuter)
          Generates bytecode to put a reference to the oldFunction field for the external generic function on the JVM stack.
protected  void plantSelfArguments(CodeSequence code, CMethod topConcreteMethod)
          Plants bytecode to push the arguments for a call to this multimethod body from within a dispatcher of this generic function.
 boolean purityWasChanged()
          This method can be used to determine that the purity of this method was not given explicitly by the programmer, but inherited from an overridden method or the class/interface.
 CType receiverType()
          Returns the type of this methods receiver.
 CType returnType()
           
 void setGenerateFrom(CMethod me)
           
 void setIDs(int gfID, int mID)
          Set the method's gfID and methodID, used to give its associated $body method (if any) a unique name.
protected  void setIsMixedPleomorphic()
          Indicates that this method is pleomorphic with one external generic function and one or more internal generic functions.
 CMethodSet setOverriddenMethodSet()
          A version that uses default parameters.
protected  CMethodSet setOverriddenMethodSet(CClassType[] args, ArrayList needbridge, CContextType context)
          Calculates and returns the set of methods overridden by this method.
protected  void setParameters(CSpecializedType[] parameters)
           
protected  void setReturnType(CType type)
           
 void setSynthetic(boolean syn)
           
 void setThrowables(Set throwables)
          Set the exceptions that may be thrown by this method.
 boolean specializes(CMethod other)
          Checks whether this method specializes a given method.
protected  void swallowReceiver()
          Swallow the receiver, which is passed as the first argument to an external generic function.
 CClassType[] throwables()
           
 CMethod topConcreteMethod()
          Finds the top concrete method of the generic function to which this belongs.
 String toString()
          Returns a human-readable string representation of this method signature.
protected  String toString(boolean omitReceiver)
          Utility method allows the generation of a string representation of this with or without the receiver type.
 
Methods inherited from class org.multijava.mjc.CMember
access, addModifiers, deprecated, getCClass, getCCompilationUnit, getField, getIdent, getJavaName, getOwnerName, getQualNameWithSeparator, hasDefaultAccess, hasProtectedVisibilityIn, host, ident, isAccessibleFrom, isDeclaredNonNull, isDeprecated, isFinal, isLocalTo, isPrivate, isProtected, isPublic, isStatic, modifiers, owner, qualifiedName, setModifiers
 
Methods inherited from class org.multijava.util.Utils
assertTrue, assertTrue, combineArrays, escapeString, escapeString, fail, fail, getFilePath, hasFlag, hasOtherFlags, parsePathParts, relativePathTo, splitQualifiedName, splitQualifiedName, stripJavaModifiers, stripNonJavaModifiers, stripPrivateModifier, unescapeString, vectorToArray, vectorToIntArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

cachedPure

private boolean cachedPure
The pureness of this method. We cache this value because it's expensive to calculate it to inheritance. An overriding method inherits the pureness of the overridden methods.


pureCached

private boolean pureCached
Indicates if the pureness of this method has been calculated and cached in the field cachedPure.


purityWasChanged

private boolean purityWasChanged
Indicates if the pureness of this method was inherited from a supermethod or a class/interface.


overriddenMethodSet

private CMethodSet overriddenMethodSet
The set of methods overridden by this method, may be null.


receiverType

private CClassType receiverType

returnType

private CType returnType

parameters

private CSpecializedType[] parameters

exceptions

private CClassType[] exceptions

declarationContext

protected CContextType declarationContext
The context in which this method was declared. Used for resolving the top method of the generic function to which this belongs.


topConcreteMethod

protected CMethod topConcreteMethod
The top concrete method of the generic function to which this belongs.


specArgs

protected BitSet specArgs
If this is a top method, we record which arguments of the generic function are specialized. An argument is specialized if there is some method in the generic function that specializes on it.


isMixedPleomorphic

private boolean isMixedPleomorphic
Indicates whether this method is pleomorphic with one external generic function and one or more internal generic functions.


needsPrivacyModifierRemoved

public boolean needsPrivacyModifierRemoved
Indicates whether this method should have its privacy modifier removed for the purposes of code generation. This is the case if the method is private and either a constructor or in an external gf, but it is also accessed by an enclosing or nested class. We should really probably use javac-style accessor methods, as we do for all other kinds of privileged access scenarios.


gfID

private int gfID
Integers used in bodyIdent() to give a unique name to a multimethod's associated $body method. This is needed to handle value dispatching, where the different multimethods have the same type signature, so static overloading cannot be used to disambiguate them. The gfID is shared for all methods of the same gf declared in the same class. The methodID is unique to this method (as compared to the methodIDs of other methods of this gf declared in the same class).


methodID

private int methodID

typevariables

private CTypeVariable[] typevariables

generatefrom

protected CMethod generatefrom

synthetic

public boolean synthetic
Constructor Detail

CMethod

public CMethod(MemberAccess access,
               String ident,
               CType returnType,
               CSpecializedType[] parameters,
               CClassType[] exceptions,
               CTypeVariable[] typevariables,
               boolean deprecated,
               CContextType declarationContext)
Constructs a method member.

Parameters:
access - contains the info used to determine accessibility of this method
ident - the ident of this method
returnType - the return type of this method
parameters - the parameters type of this method
exceptions - a list of all exceptions of the throws list
deprecated - is this method deprecated
declarationContext - the context in which this method is declared
Method Detail

declarationContext

public CContextType declarationContext()
Returns the declaration context.


receiverType

public CType receiverType()
Returns the type of this methods receiver.


getMethod

public CMethod getMethod()
Overrides:
getMethod in class CMember
Returns:
the interface

returnType

public final CType returnType()
Returns:
the type of this field

parameters

public final CSpecializedType[] parameters()
Returns the static and dynamic types of this methods parameters.

Returns:
the static and dynamic types of this methods parameters

parametersSize

public final int parametersSize()
Returns the size (in stack slots) of the parameters of this.


setParameters

protected final void setParameters(CSpecializedType[] parameters)

setReturnType

protected final void setReturnType(CType type)

getSignature

public String getSignature()
Returns the bytecode type signature of this method as seen by callers. I.e., the signature based on the generic function's static argument types.


getGenericSignature

public String getGenericSignature()

throwables

public CClassType[] throwables()
Returns:
the exceptions that can be thrown by this method

setThrowables

public void setThrowables(Set throwables)
Set the exceptions that may be thrown by this method. Used by the typecheck methods for static and instance initializers since the throwable exceptions for such code are only know after the body is checked.

Parameters:
throwables - the exceptions that can be thrown by this method

isInExternalGF

public boolean isInExternalGF()
                       throws UnpositionedError
Indicates whether this method belongs to an external generic function.

Returns:
true iff the top method of the generic function to which this belongs is external
Throws:
UnpositionedError - if the top method of the generic function is ambiguous

 assignable topConcreteMethod;
 

hasSameSignature

public boolean hasSameSignature(CMethod other,
                                CClassType[] substitution)
Has this method the same signature as the one given as argument ? NOTE: return type not considered

Parameters:
other - the method to compare to

equalParametersNoUniverses

public boolean equalParametersNoUniverses(CMethod other)

hasSameSignatureNoUniverses

public boolean hasSameSignatureNoUniverses(CMethod other)

hasSameSignature

public boolean hasSameSignature(CMethod other)
Has this method the same signature as the one given as argument ? NOTE: return type not considered

Parameters:
other - the method to compare to

topConcreteMethod

public CMethod topConcreteMethod()
                          throws UnpositionedError
Finds the top concrete method of the generic function to which this belongs. Registers any specialized argument positions of this with the top method.

 requires topConcreteMethod != null || declarationContext != null || 
          (* this is overridden in subclass to not depend on 
		   declarationContext *);
 assignable topConcreteMethod;
 ensures topConcreteMethod != null;
 

Returns:
the top method of the generic function to which this belongs
Throws:
UnpositionedError

getSpecArgs

public BitSet getSpecArgs()
Return the bit set indicating which arguments of the associated generic function are specialized. This field is only used by top methods.


setIDs

public void setIDs(int gfID,
                   int mID)
Set the method's gfID and methodID, used to give its associated $body method (if any) a unique name.


isNative

public boolean isNative()
Returns true iff this method is native.


isAbstract

public boolean isAbstract()
Returns true iff this method is abstract.


isConstructor

public boolean isConstructor()
Returns true iff this method is a constructor.


isExternal

public boolean isExternal()
Indicates whether this method is external, i.e., whether its host is different than its logical owner.

Returns:
true iff this method is external

isLocalTo

public boolean isLocalTo(CContextType context)
Indicates whether this method is declared local to the given context.

Parameters:
context - the context in which to check
Returns:
whether this method is declared local to the given context

setIsMixedPleomorphic

protected void setIsMixedPleomorphic()
Indicates that this method is pleomorphic with one external generic function and one or more internal generic functions.


isMixedPleomorphic

public boolean isMixedPleomorphic()
Indicates whether this method is pleomorphic with one external generic function and one or more internal generic functions.


equalParameters

public boolean equalParameters(CMethod other)
Returns true if the given method and this method have parameters with the same types.

Parameters:
other - the CMethod to compare this to

equals

public boolean equals(Object other)
Returns true if the given object is a CMethod and the two methods have same signature.

Overrides:
equals in class Object
Parameters:
other - the object to compare this to

hashCode

public int hashCode()
Returns the hash code for this, calculated from the hash codes of the methods identifier, receiver, and argument types.

Overrides:
hashCode in class Object
Returns:
the hash code for this

compareTo

public int compareTo(Object o)
Allows methods to be sorted. Comparison is by identifier only.

Specified by:
compareTo in interface Comparable
Parameters:
o - the method to be compared with
Returns:
-1, 0, 1 based on identifiers, see String.compareTo

isApplicable

public boolean isApplicable(String ident,
                            CType recvType,
                            CType[] actuals,
                            CClassType[] args)
Returns true if this method is applicable to a method call with the given identifier and actual (static) argument types.

Parameters:
ident - the identifier to match
recvType - receiver type
actuals - the method call static argument types
Returns:
true if this method is applicable

isApplicableArgTypes

private boolean isApplicableArgTypes(CType recvType,
                                     CType[] actuals,
                                     boolean initStyleCheck,
                                     CClassType[] args)
Returns true if the given actual argument types are assignable to this methods formals and receiver.

Parameters:
recvType - receiver type
actuals - the method call static argument types
initStyleCheck - if true then perform an initializer applicability check (i.e., receiver types must be equal), otherwise perform a pointwise subtype check on the argument type tuples
Returns:
true if the given actual argument types are assignable to this methods formals WMD: method also needs to check for the universe modifiers of the arguments.

isMoreSpecificThan

public boolean isMoreSpecificThan(CMethod other,
                                  CClassType[] args)
Returns true if this method is strictly more specific than the given method. This does not mean that this method specializes the given method.

Parameters:
other - the method to compare to
Returns:
true if this method is more specific than other

isMoreSpecificThan

public boolean isMoreSpecificThan(CMethod other)

isMoreSpecificThan

public boolean isMoreSpecificThan(CMethod other,
                                  boolean b)

isMoreSpecificThan

public boolean isMoreSpecificThan(CMethod other,
                                  CClassType[] args,
                                  boolean intrsDoNotExtendObject)
Returns true if this method is strictly more specific than the given method. This does not mean that this method specializes the given method.

Parameters:
other - the method to compare to
intrsDoNotExtendObject - true if we should not treat interfaces as inheriting from Object
Returns:
true if this method is more specific than other

isMoreSpecificThan

public boolean isMoreSpecificThan(CMethod other,
                                  CClassType[] args,
                                  boolean intrsDoNotExtendObject,
                                  boolean enableUniv)

apparentlySpecializes

public boolean apparentlySpecializes(CMethod other,
                                     CClassType[] args)

Checks whether this method apparently specializes a given method. This method apparently specializes other iff this method is more specific than other, the two methods' static parameter types are identical, and the receiver type of this is a (possibly reflexive) subtype of the receiver type of other.

This relationship is apparently because other is not necessarily visible to this. For example, other could be a method of an external generic function that is not imported in the context of the declaration of this.

Parameters:
other - the method to compare to
Returns:
true if this method apparently specializes other
See Also:
specializes(CMethod)

apparentlySpecializes

public boolean apparentlySpecializes(CMethod other,
                                     CClassType[] args,
                                     boolean enableUniv)

apparentlySpecializes

public boolean apparentlySpecializes(CMethod other)

specializes

public boolean specializes(CMethod other)
                    throws UnpositionedError

Checks whether this method specializes a given method. This method specializes other iff this method apparently specializes other, and the two methods have belong to the same generic function as determined by their top methods.

Parameters:
other - the method to compare to

 requires other != null;
 assignable topConcreteMethod, other.topConcreteMethod;
 ensures \result <==> this.topConcreteMethod == other.topConcreteMethod
                        && this.apparentlySpecializes( other );
 
Returns:
true if this method specializes other
Throws:
UnpositionedError - if the top method of either this or other is ambiguous
See Also:
apparentlySpecializes(CMethod)

toString

public String toString()
Returns a human-readable string representation of this method signature. Add token reference information once this is made available in CMember (see TODO list).!FIXME!

Overrides:
toString in class Object
Returns:
a human-readable string representation of this

toString

protected String toString(boolean omitReceiver)
Utility method allows the generation of a string representation of this with or without the receiver type.


getTypeVariable

public CTypeVariable[] getTypeVariable()
Returns:
the type variables of this method

isGenericMethod

public boolean isGenericMethod()
whether this method is generic or not


lookupTypeVariable

public CTypeVariable lookupTypeVariable(String ident)

isPure

public boolean isPure()
Returns true if this method is pure. A method is pure if it is annotated with the pure modifier or it inherits pureness from its owner or supertypes. A non-static method (including a constructor) is pure if its owner class or interface is pure, or if it overrides a pure method inherited from supertypes (classes and interfaces).


purityWasChanged

public boolean purityWasChanged()
This method can be used to determine that the purity of this method was not given explicitly by the programmer, but inherited from an overridden method or the class/interface.


isPureInherited

private boolean isPureInherited()
Returns true if this method inherits pureness from its owner or supertypes, including both superclasses and interfaces.


setOverriddenMethodSet

public CMethodSet setOverriddenMethodSet()
                                  throws UnpositionedError
A version that uses default parameters. This method is public, because it is also called from JML.

Throws:
UnpositionedError

setOverriddenMethodSet

protected CMethodSet setOverriddenMethodSet(CClassType[] args,
                                            ArrayList needbridge,
                                            CContextType context)
                                     throws UnpositionedError
Calculates and returns the set of methods overridden by this method. Caches the result for later calls to overriddenMethodSet().

Throws:
UnpositionedError

overriddenMethodSet

protected CMethodSet overriddenMethodSet()
Returns the set of methods overridden by this method, may be null.


swallowReceiver

protected void swallowReceiver()
Swallow the receiver, which is passed as the first argument to an external generic function.

 requires topConcreteMethod != null && topConcreteMethod.isExternal();
 assignable parameters;
 ensures parameters.length == \old(parameters).length + 1;
 ensures parameters[0].staticType() == topConcreteMethod.receiverType();
 ensures parameters[0].dynamicType() == this.receiverType();
 


genGenFuncInvocation

public void genGenFuncInvocation(CodeSequence code,
                                 boolean nonVirtual)
Generates a sequence of bytecode for invoking this method, assuming appropriate argument values have already been pushed to the JVM stack.

Parameters:
code - the code sequence
nonVirtual - force non-virtual dispatching if possible (ignored if this method belongs to an interface or is external)

 requires topConcreteMethod != null;
 

plantFunctionRef

public abstract void plantFunctionRef(CodeSequence code)
Generates bytecode to put a reference to the external function field for the external generic function on the JVM stack.

   requires this.isExternal();
 


plantOldFunctionRef

public abstract void plantOldFunctionRef(CodeSequence code,
                                         boolean forSuper,
                                         boolean fromOuter)
Generates bytecode to put a reference to the oldFunction field for the external generic function on the JVM stack.

   requires this.isExternal();
 

Parameters:
code - the code sequence to add the bytecode to
forSuper - if true, then this is for a super send, which, under RMJ, should start from the oldSuperFunction rather than oldFunction
fromOuter - if true, then generates a reference that works from the outer class context, otherwise generates a reference that works from within the dispatcher class

dispatcherSignature

public abstract CDispatcherSignature dispatcherSignature()
Returns the $signature class for this.

   requires this.isExternal();
 


ambiguousDispatcherClass

public abstract CAmbiguousDispatcherClass ambiguousDispatcherClass()
Returns the ambiguous-method dispatcher class for this. (RMJ only.)

   requires this.isExternal();
 


anchorClass

public abstract CClass anchorClass()
Returns the $anchor class for this generic function.

 requires this.isExternal();
 


functionNumber

public abstract int functionNumber()
Returns the function field number for this generic function within its $anchor class.

 requires this.isExternal();
 


genDispatch

public boolean genDispatch(CodeSequence code,
                           CodeLabel nextAlternative,
                           CMethod topConcreteMethod,
                           String dispatcherName)
Generates the dispatch code for the specialized arguments of this method. Generated code implements the following pseudocode:

if ( !(this is applicable) ) then goto nextAlternative;
execute this method body;
 

Returns:
true if any applicability test code was required

plantSelfArguments

protected void plantSelfArguments(CodeSequence code,
                                  CMethod topConcreteMethod)
Plants bytecode to push the arguments for a call to this multimethod body from within a dispatcher of this generic function. After executing the generated code the JVM stack will include the arguments of the generic function, cast to the appropriate dynamic types.


plantMMInvocation

protected void plantMMInvocation(CodeSequence code,
                                 String dispatcherName)
Plants an invocation of the multimethod body represented by this.


bodyIdent

protected String bodyIdent()

bodySignature

protected String bodySignature()

bodyGenericSignature

protected String bodyGenericSignature()

mmSignature

protected String mmSignature()
Returns the type signature of this method in the multimethod descriptor format, which is like a regular bytecode method descriptor but includes explicit specializers.


mmGenericSignature

protected String mmGenericSignature()

genMethodInfo

public ArrayList genMethodInfo()
Generate the method information for this for constructing a class file [JVM2 4.6].

Returns:
an ArrayList of MethodInfo, just a single element here, but overridden in CSourceDispatcherMethod to include separate elements for the dispatcher and each multimethod body

genGenericFunctionInfo

public GenericFunctionInfo genGenericFunctionInfo()
Generates the generic function information for this required when generating a class file, or returns null if this method requires no such information.


getGenerateFrom

public CMethod getGenerateFrom()

setGenerateFrom

public void setGenerateFrom(CMethod me)

isSynthetic

public boolean isSynthetic()

setSynthetic

public void setSynthetic(boolean syn)

mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.