170 likes | 331 Views
SOUL for Java Philippe Demaecker @ PROG pdemaeck@vub.ac.be. Context. O bject oriented s ystems Reason about the structure of OO programs U se explicit logic meta-language : SOUL Smalltalk Open Unification Language. SOUL. Logic meta programming language Written in smalltalk
E N D
Context • Object orientedsystems • Reason about the structure of OO programs • Use explicit logic meta-language: SOUL • Smalltalk Open Unification Language
SOUL • Logic meta programming language • Written in smalltalk • Reasons about structure of smalltalk programs • Class interaction • Implementation strategies • Programming style • Design patterns
SOUL reasoning • SOUL base predicates class(?class) superclass(?super, ?sub) instVar(?class, ?iv) method(?class, ?m) • Used on logic representation of Smalltalk programs
Logic representation class(queue). instVar(queue, contents). method(queue, add, [el], [], statements) • statements = list of logic representation of smalltalk statements
Smalltalk body elements • Simple grammar • Literal • Variable • Assignment • Return statement • Message send • Cascaded message • Block
SOUL for java • Can SOUL be applied to Java? • Represent java classes as logic facts • Focus on class files • Java syntax is complicated • Source code is not always available • Class files have more uniform representation
Classes to clauses: c2c • Written in Java • Extracts information from class files • Represents this information as logic facts • Based on existing class parser: BCEL • Byte Code Engineering Library (formerly JavaClass) • Tested on Drawlets
Used representation (1) class(?class). / interface(?class). accessFlag(?class, ?accessFlag). superclass(?class, ?super). directInterface(?class,?interface).
Used representation (2) fieldAccessFlag(?class, ?field, ?flag). fieldDescriptor(?class, ?field,?returnType).
Used representation (3) methodAccessFlag(?class, ?m, ?argList, ?accessFlag). methodReturnType(…, ?returnType). methodBody(…, ?invokesUsedModifiedsList) • invokespecial(invokation) • putfield/putstatic(fieldName) • getfield/getstatic(fieldName)
c2c example: input class public final class LineNumber implements Cloneable{ private int start_pc; LineNumber(DataInputStream file) throws IOException{ this(file.readUnsignedShort(), file.readUnsignedShort());} public final void dump(DataOutputStream file) throws IOException{ file.writeShort(start_pc); file.writeShort(line_number); } … }
c2c example: output (1) class(LineNumber). classAccessFlag(LineNumber, public). classAccessFlag(LineNumber, final). directInterface(LineNumber, java.lang.Cloneable). superClass(LineNumber, java.lang.Object). fieldAccessFlags(LineNumber, start_pc, private). fieldDescriptor(LineNumber, start_pc, int). methodReturnType(LineNumber, LineNumber, [java.io.DataInputStream], void). methodException(LineNumber, LineNumber, [java.io.DataInputStream], java.io.IOException). methodBody(…).
c2c example: output (2) methodAccessFlag(LineNumber, dump, [java.io.DataOutputStream], public). methodAccessFlag(LineNumber, dump, [java.io.DataOutputStream], final). methodReturnType(LineNumber, dump, [java.io.DataOutputStream], void). methodException(LineNumber, dump, [java.io.DataOutputStream], java.io.IOException). methodBody(LineNumber, dump, [java.io.DataOutputStream], [getfield(start_pc), invokevirtual(java.io.DataOutputStream.writeShort(int)), getfield(line_number), invokevirtual(java.io.DataOutputStream.writeShort(int))]).
c2c example: output (3) getfield(LineNumber, dump, [java.io.DataOutputStream], start_pc). invokevirtual(LineNumber, dump, [java.io.DataOutputStream], java.io.DataOutputStream.writeShort(int)). getfield(LineNumber, dump, [java.io.DataOutputStream], line_number). invokevirtual(LineNumber, dump, [java.io.DataOutputStream], java.io.DataOutputStream.writeShort(int)).
Future work • Write documentation • Optimization: • remove unneeded code/classes • Minor adjustments • Additional options • Integrate in SOUL