Transformation of Java Card into Diet Java
This project presentation explores the transformation of Java Card into Diet Java, focusing on techniques and tools used for this conversion. It introduces the Jive interactive verification environment, addressing the transformation of forbidden constructs and error reporting during compilation. Key tools such as ANTLR and Abstract Syntax Trees (AST) are discussed, alongside difficulties encountered, like nested expressions and execution order. Future work involves transformations of non-strict operators and enhancements for temporary variables. The conclusion highlights the challenges of maintaining intelligibility in transformed code.
Transformation of Java Card into Diet Java
E N D
Presentation Transcript
Semester Project Presentation Transformation of Java Card into Diet Java • Erich Laube <laubee@student.ethz.ch>
Overview Introduction to Jive and Background Transformation Basics Examples Future Work Conclusion
Jive Java Interactive Verification Environment Code (Java) vs. Specification (JML) Diet Java
Goals • Transformation of forbidden constructs. • Reporting errors at compile time for constructs that are not transformed.
Involved Tools • ANTLR • parser, lexer • Abstract Syntax Tree (AST) • Multijava • java compiler • static checks, type information • JML • Multijava enhanced with JML
Difficulties • Tracking (nested Expressions) • Still knowing where one is • Execution order • Genericity • Constructs forbidden in program but allowed in specification part • large amount of node classes • non-uniform node layout
Try-Catch • Only one Catch per Try • done in Grammar file try { // something } catch (Exception1 e1){ // handler1 } catch (Exception2 e2){ // handler2 } try{ try { // something } catch (Exception1 e1){ // handler1 } } catch (Exception2 e2){ // handler2 }
Do While => While do { [body] } while (cond) [body] while (cond){ [body] } do { if (x) break; } while (cond) if (x) break; while (cond){ if (x) break; } { boolean b = true while (b){ if (x) break; b = cond; } } { boolean b = true while (b||cond){ if (x) break; b = false }}
Constructors • conversion to method: • alter all constructor calls • find them, spread all over the code • call constructor of super method • create default constructor method • but only if no other constructor specified • special case: this() calls • call the initializer method (not always there) • also needs a JML specification
Constructor conversion example Class K extends M{ int f; K(int i){ super(i); f = i; } K(){ this(2); } } Class K extends M{ int f = 2; K(int i){ super(i); f = i; } K(){ this(f); } } Class K extends M{ int f; void °cK(int i){ super.°cM(i); f = i; } void °cK(){ °cK(2); } } Class K extends M{ int f; °inst_init(){ f = 2; } void °cK(int i){ °inst_init(); super.°cM(i); f = i; } void °cK(){ °inst_init(); °cK(f); } } Class K extends M{ int f; boolean °init; void°inst_init(){ if (°init){} else { f = 2; °init = true; }} void °cK(int i){ super.°cM(i); °inst_init(); f = i;} void °cK(){ °inst_init(); °cK(f); } }
Future Work • Remaining Transformations • non-strict operators • pre- and postfix operators (++,--) • inner classes • Optimizations: • reuse temporary variables • simple trafos for simple cases
Conclusion • Many constructs covered • Mangled code: • difficult for user to still understand • Interesting and complex project
Implemented Transformations • constructors • nonstatic initializers • variable initializers • local variables only at beginning of blocks • short if, for and do-loops, switch-blocks • multiple catch blocks for a try-block • casts within expressions • array access within expressions • compound assignment • assignment within expressions • assignments with side effects (partially) • pre- and postfix operators (partially)
Grammar File (ANTLR) • Passes every code construct • No Type Information • Also affects JML part • Work done here: • finding and forbidding • types • simple transformations • If-then-else • Try-catch
Abstract Syntax Tree (Multijava) • Statements • can hold more Statements • can hold Expressions • Expressions • never hold Statements • can hold further Expressions