We stipulate the existence of 17 Prolog predicates ("accessors") that have certain expected behavior but whose formal definitions are not given in this specification. The Prolog term Class, as used here, represents a binary class or interface that has been successfully loaded (§5.3); the Prolog term Method represents a method of a Class; and the Prolog term Loader represents a class loader of a Class. This specification does not mandate a precise structure for these entities.
-
classClassName(Class, ClassName)
Extracts the name,
ClassName, of the classClass. -
classIsInterface(Class)
True iff the class,
Class, is an interface. -
classSuperClassName(Class, SuperClassName)
Extracts the name,
SuperClassName, of the superclass of classClass. -
classInterfaceNames(Class, InterfaceNames)
Extracts a list,
InterfaceNames, of the names of the direct superinterfaces of 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. -
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).The verification type derived from descriptor types
byte,short,boolean, andchar, when not used as array component types, isint. -
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.The verification type derived from descriptor types
byte,short,boolean, andchar, when not used as array component types, isint. A void return is represented with the special symbolvoid. -
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.
The above accessors are used to define loadedSuperclasses, which produces a list of a class's superclasses by recurring on each class's direct superclass until Object, which has no superclass, is reached.
loadedSuperclasses(Class, [ Superclass | Rest ]) :-
classSuperClassName(Class, SuperclassName),
classDefiningLoader(Class, L),
loadedClass(SuperclassName, L, Superclass),
loadedSuperclasses(Superclass, Rest).
loadedSuperclasses(Class, []) :-
\+ classSuperClassName(Class, _).
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 (or
void) - 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).
currentClassLoader(Environment, Loader) :-
Environment = environment(Class, _Method, _ReturnType,
_Instructions, _, _),
classDefiningLoader(Class, Loader).
thisClass(Environment, Class) :-
Environment = environment(Class, _Method, _ReturnType,
_Instructions, _, _).
thisType(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, _, _).
offsetStackFrame(Environment, Offset, StackFrame) :-
allInstructions(Environment, Instructions),
member(stackMap(Offset, StackFrame), Instructions).
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.