180 likes | 301 Views
Implementation of a Modular OCL Compiler. Frank Finger TU Dresden. Outline. Vision Features of the Compiler Problems with OCL Demonstration Discussion. Java Code Generator. public class Customer { ... }. Vision. UML Model. OCL. What happens to the OCL constraints?.
E N D
Implementation of a Modular OCL Compiler Frank Finger TU Dresden
Outline • Vision • Features of the Compiler • Problems with OCL • Demonstration • Discussion
Java Code Generator public class Customer { ... } Vision UML Model OCL What happens to the OCL constraints?
Java Code Generator OCL to Java Generator public class Customer { ... public boolean assert() { ... } } Vision UML Model OCL
Role of the Compiler context Customer inv: cards->forAll(printedName=self.name) public boolean assert() { final OclAnyImpl tudOclNode0=Ocl.toOclAnyImpl( Ocl.getFor(this) ); final OclSet tudOclNode1=Ocl.toOclSet(tudOclNode0.getFeature("cards")); final OclIterator tudOclIter0=tudOclNode1.getIterator(); final OclBooleanEvaluatable tudOclEval0=new OclBooleanEvaluatable() { public OclBoolean evaluate() { final OclString tudOclNode2= ...tudOclIter0.getValue()...getFeature("printedName"); final OclString tudOclNode3=Ocl.toOclString(tudOclNode0.getFeature("name")); final OclBoolean tudOclNode4=tudOclNode2.isEqualTo(tudOclNode3); return tudOclNode4; } }; final OclBoolean tudOclNode5=tudOclNode1.forAll(tudOclIter0, tudOclEval0); return tudOclNode5.isTrue(); }
Demands • modular architecture • adaptable for different target languages • Java code generator • configurable normalization steps • close to specification (OCL 1.3)
Architecture parser OCL model information sem. analysis normalization target code code gen.
Normalization • faciliates code generation • no fixed normal form • configurable normalization steps • expand multiple iterators ("->forAll(i1, i2|...") • insert type information • expand shorthand for collect • ... • configured to suit target language
problems with OCL • Are keywords reserved? (issue 3138) • Can type names begin with a lower-case character? (issue posted) • Which expressions may contain let expressions? (issue 3148) • What happens if the value of a constraint is undefined? (no issue so far)(true / false / malformed constraint)
X Y A B type checking problems • empty collections • equality is defined on arbitrary operands • semantics of qualifiers (7.5.5 vs. 7.5.7) • What is the type of "if ... then a else b endif"?
resume • OCL compiler is availablehttp://www-st.inf.tu-dresden.de/ocl(including Java sources) • code generator for SQL integrity conditions is being implemented • to do: CASE tool integration • demonstration
Role of the Compiler context Customer inv: cards->forAll(printedName=self.name) public boolean assert() { final OclAnyImpl tudOclNode0=Ocl.toOclAnyImpl( Ocl.getFor(this) ); final OclSet tudOclNode1=Ocl.toOclSet(tudOclNode0.getFeature("cards")); final OclIterator tudOclIter0=tudOclNode1.getIterator(); final OclBooleanEvaluatable tudOclEval0=new OclBooleanEvaluatable() { public OclBoolean evaluate() { final OclString tudOclNode2= ...tudOclIter0.getValue()...getFeature("printedName"); final OclString tudOclNode3=Ocl.toOclString(tudOclNode0.getFeature("name")); final OclBoolean tudOclNode4=tudOclNode2.isEqualTo(tudOclNode3); return tudOclNode4; } }; final OclBoolean tudOclNode5=tudOclNode1.forAll(tudOclIter0, tudOclEval0); return tudOclNode5.isTrue(); }