org.eclipse.ocl.examples.codegen.analyzer
Class FieldingAnalyzer

java.lang.Object
  extended by org.eclipse.ocl.examples.codegen.analyzer.FieldingAnalyzer
Direct Known Subclasses:
OCLinEcoreCodeGenerator.EcoreFieldingAnalyzer

public class FieldingAnalyzer
extends java.lang.Object

A FieldingAnalyzer identifies the necessary catches and throws.

Caught or Thrown Consumer Requirements

Most AST nodes just propagate invalid and so use of Java exception is convenient and efficient.

Caught Requirements

The only AST nodes that respond to invalid are validating operations, so it might seem appropriate to just catch all validating operation inputs.

However VariableExps enable a value computed elsewhere to be re-used. Therefore if the re-use is by a validating operation, the computation elsewhere must be caught in the sharing LetExp.

Algorithm

Pass 1

A tree descent/ascent maintains a set of external variable references from a node and its descendants. Wherever a validating operation is encountered on the ascent, all external references from source and parameters are marked as caught variables.

Pass 2

A tree descent/ascent computes the isCaught state of all nodes. On the ascent children with incompatible isCaught state are corrected by insertion of a CGCaughtExp to catch a not-isCaught or a CHThrowExp to throw an isCaught..


Nested Class Summary
static class FieldingAnalyzer.AnalysisVisitor
           
static class FieldingAnalyzer.RewriteVisitor
           
 
Field Summary
protected  CodeGenAnalyzer analyzer
           
 
Constructor Summary
FieldingAnalyzer(CodeGenAnalyzer analyzer)
           
 
Method Summary
 void analyze(CGElement cgTree, boolean mustBeCaught)
           
protected  FieldingAnalyzer.AnalysisVisitor createAnalysisVisitor()
           
protected  FieldingAnalyzer.RewriteVisitor createRewriteVisitor(java.util.Set<CGVariable> caughtVariables)
           
protected  boolean isValidating(org.eclipse.emf.ecore.EObject eObject)
           
 void setCaught(java.util.Set<CGVariable> catchers)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

analyzer

@NonNull
protected final CodeGenAnalyzer analyzer
Constructor Detail

FieldingAnalyzer

public FieldingAnalyzer(@NonNull
                        CodeGenAnalyzer analyzer)
Method Detail

analyze

public void analyze(@NonNull
                    CGElement cgTree,
                    boolean mustBeCaught)

createAnalysisVisitor

@NonNull
protected FieldingAnalyzer.AnalysisVisitor createAnalysisVisitor()

createRewriteVisitor

@NonNull
protected FieldingAnalyzer.RewriteVisitor createRewriteVisitor(@NonNull
                                                                       java.util.Set<CGVariable> caughtVariables)

isValidating

protected boolean isValidating(org.eclipse.emf.ecore.EObject eObject)

setCaught

public void setCaught(@Nullable
                      java.util.Set<CGVariable> catchers)