We stipulate the existence of 27 Prolog predicates ("accessors") that have certain expected behavior but whose formal definitions are not given in this specification.
-
classClassName(Class, ClassName)
Extracts the name,
ClassName, of the classClass. -
classIsInterface(Class)
True iff the class,
Class, is an interface. -
classIsNotFinal(Class)
True iff the class,
Class, is not afinalclass. -
classSuperClassName(Class, SuperClassName)
Extracts the name,
SuperClassName, of the superclass of classClass. -
classInterfaces(Class, Interfaces)
Extracts a list,
Interfaces, of the direct superinterfaces of the classClass. -
classMethods(Class, Methods)
Extracts a list,
Methods, of the methods declared in the classClass. -
classDeclaresMember(Class, MemberName, MemberDescriptor)
Asserts that a class,
Class, declares a field or method with nameMemberNameand descriptorMemberDescriptor. This assertion does not consider members declared in the superclasses or superinterfaces ofClass. -
classDefiningLoader(Class, Loader)
Extracts the defining class loader,
Loader, of the classClass. -
isBootstrapLoader(Loader)
True iff the class loader
Loaderis the bootstrap class loader. -
loadedClass(Name, InitiatingLoader, ClassDefinition)
True iff there exists a class named
Namewhose representation (in accordance with this specification) when loaded by the class loaderInitiatingLoaderisClassDefinition. -
methodName(Method, Name)
Extracts the name,
Name, of the methodMethod. -
methodAccessFlags(Method, AccessFlags)
Extracts the access flags,
AccessFlags, of the methodMethod. -
methodDescriptor(Method, Descriptor)
Extracts the descriptor,
Descriptor, of the methodMethod. -
methodAttributes(Method, Attributes)
Extracts a list,
Attributes, of the attributes of the methodMethod.Each attribute is represented as a functor application of the form
attribute(AttributeName, AttributeContents), whereAttributeNameis the name of the attribute. The format of the attribute's contents is unspecified. -
isInit(Method)
True iff
Method(regardless of class) is<init>. -
isNotFinal(Method, Class)
True iff
Methodin classClassis notfinal. -
isStatic(Method, Class)
True iff
Methodin classClassisstatic. -
isNotStatic(Method, Class)
True iff
Methodin classClassis notstatic. -
isPrivate(Method, Class)
True iff
Methodin classClassisprivate. -
isNotPrivate(Method, Class)
True iff
Methodin classClassis notprivate. -
isProtected(MemberClass, MemberName, MemberDescriptor)
True iff there is a member named
MemberNamewith descriptorMemberDescriptorin the classMemberClassand it isprotected. -
isNotProtected(MemberClass, MemberName, MemberDescriptor)
True iff there is a member named
MemberNamewith descriptorMemberDescriptorin the classMemberClassand it is notprotected. -
parseFieldDescriptor(Descriptor, Type)
Converts a field descriptor,
Descriptor, into the corresponding verification typeType(§4.10.1.2). -
parseMethodDescriptor(Descriptor, ArgTypeList, ReturnType)
Converts a method descriptor,
Descriptor, into a list of verification types,ArgTypeList, corresponding to the method argument types, and a verification type,ReturnType, corresponding to the return type. -
parseCodeAttribute(Class, Method, FrameSize, MaxStack, ParsedCode, Handlers, StackMap)
Extracts the instruction stream,
ParsedCode, of the methodMethodinClass, as well as the maximum operand stack size,MaxStack, the maximal number of local variables,FrameSize, the exception handlers,Handlers, and the stack mapStackMap.The representation of the instruction stream and stack map attribute must be as specified in §4.10.1.3 and §4.10.1.4.
-
samePackageName(Class1, Class2)
True iff the package names of
Class1andClass2are the same. -
differentPackageName(Class1, Class2)
True iff the package names of
Class1andClass2are different.
When type checking a method's body, it is convenient to access information about the method. For this purpose, we define an environment, a six-tuple consisting of:
- a class
- a method
- the declared return type of the method
- the instructions in a method
- the maximal size of the operand stack
- a list of exception handlers
We specify accessors to extract information from the environment.
allInstructions(Environment, Instructions) :-
Environment = environment(_Class, _Method, _ReturnType,
Instructions, _, _).
exceptionHandlers(Environment, Handlers) :-
Environment = environment(_Class, _Method, _ReturnType,
_Instructions, _, Handlers).
maxOperandStackLength(Environment, MaxStack) :-
Environment = environment(_Class, _Method, _ReturnType,
_Instructions, MaxStack, _Handlers).
thisClass(Environment, class(ClassName, L)) :-
Environment = environment(Class, _Method, _ReturnType,
_Instructions, _, _),
classDefiningLoader(Class, L),
classClassName(Class, ClassName).
thisMethodReturnType(Environment, ReturnType) :-
Environment = environment(_Class, _Method, ReturnType,
_Instructions, _, _).
We specify additional predicates to extract higher-level information from the environment.
offsetStackFrame(Environment, Offset, StackFrame) :-
allInstructions(Environment, Instructions),
member(stackMap(Offset, StackFrame), Instructions).
currentClassLoader(Environment, Loader) :-
thisClass(Environment, class(_, Loader)).
Finally, we specify a general predicate used throughout the type rules:
notMember(_, []).
notMember(X, [A | More]) :- X \= A, notMember(X, More).
The principle guiding the determination as to which accessors are stipulated and which are fully specified is that we do not want to over-specify the representation of the class file. Providing specific accessors to the Class or Method term would force us to completely specify the format for a Prolog term representing the class file.