changes: now Inference engine works fine with the EyeTracking benchmark.
authoryeom <yeom>
Sun, 4 Nov 2012 07:24:34 +0000 (07:24 +0000)
committeryeom <yeom>
Sun, 4 Nov 2012 07:24:34 +0000 (07:24 +0000)
13 files changed:
Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java
Robust/src/Analysis/SSJava/FlowDownCheck.java
Robust/src/Analysis/SSJava/FlowGraph.java
Robust/src/Analysis/SSJava/FlowNode.java
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java
Robust/src/Benchmarks/SSJava/EyeTracking/EyePosition.java
Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/DeviationScanner.java
Robust/src/Benchmarks/SSJava/EyeTrackingInfer/LEA.java
Robust/src/ClassLibrary/SSJava/SSJAVA.java
Robust/src/ClassLibrary/SSJavaInfer/SSJAVA.java
Robust/src/ClassLibrary/SSJavaInfer/String.java

index c1f482419fe6af507ba347ac155485b36d79064e..fabdf9dbbdbe09f2fb0f0f7c7c9b9618d53be0de 100644 (file)
@@ -1941,7 +1941,7 @@ public class DefinitelyWrittenCheck {
 
       // arg idx is starting from 'this' arg
       if (fc.getThis() != null) {
 
       // arg idx is starting from 'this' arg
       if (fc.getThis() != null) {
-        NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
+        NTuple<Location> thisLocationPath = deriveLocationTuple(fc.getMethod(), fc.getThis());
         if (thisLocationPath != null) {
           mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
         }
         if (thisLocationPath != null) {
           mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
         }
@@ -2621,7 +2621,6 @@ public class DefinitelyWrittenCheck {
   }
 
   private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
   }
 
   private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
-
     assert td.getType() != null;
 
     if (mapDescriptorToLocationPath.containsKey(td)) {
     assert td.getType() != null;
 
     if (mapDescriptorToLocationPath.containsKey(td)) {
index d9bc290e585b035f10f39b7cf0061b101e8fd9f2..5bce89cc1d66caa7c03194173f6a3bdcd1e1d178 100644 (file)
@@ -1743,13 +1743,10 @@ public class FlowDownCheck {
         Set<FlatNode> flatNodeSet = ssjava.getBuildFlat().getFlatNodeSet(an);
         for (Iterator iterator = flatNodeSet.iterator(); iterator.hasNext();) {
           FlatNode fn = (FlatNode) iterator.next();
         Set<FlatNode> flatNodeSet = ssjava.getBuildFlat().getFlatNodeSet(an);
         for (Iterator iterator = flatNodeSet.iterator(); iterator.hasNext();) {
           FlatNode fn = (FlatNode) iterator.next();
-          System.out.println("SAMEHEIGHT!");
           ssjava.addSameHeightWriteFlatNode(fn);
         }
 
           ssjava.addSameHeightWriteFlatNode(fn);
         }
 
-      } else {
-        System.out.println("NOT SAME HEIGHT!");
-      }
+      } 
 
     } else {
       destLocation =
 
     } else {
       destLocation =
index b9a39f7d16bbe2f80e787dc49b40a6909868fee1..4054f701a78eef73b4eed01519d7151e7f2d6275 100644 (file)
@@ -318,7 +318,7 @@ public class FlowGraph {
     addOutEdge(fromNode, edge);
     addInEdge(toNode, edge);
 
     addOutEdge(fromNode, edge);
     addInEdge(toNode, edge);
 
-    System.out.println("add a new edge=" + edge);
+    // System.out.println("add a new edge=" + edge);
   }
 
   private void addInEdge(FlowNode toNode, FlowEdge edge) {
   }
 
   private void addInEdge(FlowNode toNode, FlowEdge edge) {
@@ -859,4 +859,20 @@ public class FlowGraph {
     bw.write("}\n");
   }
 
     bw.write("}\n");
   }
 
+  public void removeEdge(NTuple<Descriptor> from, NTuple<Descriptor> to) {
+
+    Set<FlowEdge> toberemoved = new HashSet<FlowEdge>();
+    Set<FlowEdge> edgeSet = getOutEdgeSet(getFlowNode(from));
+
+    for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
+      FlowEdge flowEdge = (FlowEdge) iterator.next();
+      if (flowEdge.getInitTuple().equals(from) && flowEdge.getEndTuple().equals(to)) {
+        toberemoved.add(flowEdge);
+      }
+    }
+
+    edgeSet.removeAll(toberemoved);
+
+  }
+
 }
\ No newline at end of file
 }
\ No newline at end of file
index 0c83d7563af61d96fcaa78e7786821de74a3916c..d170494f8a3c32ee9aef5f696f446760af5ab24d 100644 (file)
@@ -30,6 +30,8 @@ public class FlowNode {
 
   private boolean isFormHolder = false;
 
 
   private boolean isFormHolder = false;
 
+  private NTuple<Descriptor> baseTuple;
+
   public boolean isIntermediate() {
     return isIntermediate;
   }
   public boolean isIntermediate() {
     return isIntermediate;
   }
@@ -46,6 +48,14 @@ public class FlowNode {
     return isFormHolder;
   }
 
     return isFormHolder;
   }
 
+  public void setBaseTuple(NTuple<Descriptor> in) {
+    baseTuple = in;
+  }
+
+  public NTuple<Descriptor> getBaseTuple() {
+    return baseTuple;
+  }
+
   public Set<FlowNode> getFieldNodeSet() {
     return fieldNodeSet;
   }
   public Set<FlowNode> getFieldNodeSet() {
     return fieldNodeSet;
   }
index 5502eb8808d6f36baba01c80a23d71373384cd2c..8c1c97926e25814c8f21649d7c1c6bed7ba6b612 100644 (file)
@@ -586,12 +586,33 @@ public class LocationInference {
         System.out.println("###RETURN COMP LOC=" + returnLoc);
         NTuple<Location> returnLocTuple = returnLoc.getTuple();
         NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
         System.out.println("###RETURN COMP LOC=" + returnLoc);
         NTuple<Location> returnLocTuple = returnLoc.getTuple();
         NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
+        System.out.println("###basetuple=" + baseTuple);
         NTuple<Descriptor> newReturnTuple = baseTuple.clone();
         for (int i = 1; i < returnLocTuple.size(); i++) {
           newReturnTuple.add(returnLocTuple.get(i).getLocDescriptor());
         }
         System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple);
         NTuple<Descriptor> newReturnTuple = baseTuple.clone();
         for (int i = 1; i < returnLocTuple.size(); i++) {
           newReturnTuple.add(returnLocTuple.get(i).getLocDescriptor());
         }
         System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple);
+
+        FlowReturnNode holderNode = callerFlowGraph.getFlowReturnNode(min);
+        NodeTupleSet holderTupleSet =
+            getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), holderNode);
+
         callerFlowGraph.getFlowReturnNode(min).setNewTuple(newReturnTuple);
         callerFlowGraph.getFlowReturnNode(min).setNewTuple(newReturnTuple);
+
+        // then need to remove old constraints
+        // TODO SAT
+        System.out.println("###REMOVE OLD CONSTRAINTS=" + holderNode);
+        for (Iterator<NTuple<Descriptor>> iter = holderTupleSet.iterator(); iter.hasNext();) {
+          NTuple<Descriptor> tupleFromHolder = iter.next();
+          Set<FlowEdge> holderOutEdge = callerFlowGraph.getOutEdgeSet(holderNode);
+          for (Iterator iterator2 = holderOutEdge.iterator(); iterator2.hasNext();) {
+            FlowEdge outEdge = (FlowEdge) iterator2.next();
+            NTuple<Descriptor> toberemovedTuple = outEdge.getEndTuple();
+            System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple);
+            callerFlowGraph.removeEdge(tupleFromHolder, toberemovedTuple);
+          }
+        }
+
       } else {
         // if the return loc set was empty and later pcloc was connected to the return loc
         // need to make sure that return loc reflects to this changes.
       } else {
         // if the return loc set was empty and later pcloc was connected to the return loc
         // need to make sure that return loc reflects to this changes.
@@ -677,6 +698,7 @@ public class LocationInference {
             System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple
                 + "-> globalParamLocTuple=" + globalParamLocTuple);
             hasChanges = true;
             System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple
                 + "-> globalParamLocTuple=" + globalParamLocTuple);
             hasChanges = true;
+            System.out.println("B1");
             globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple);
           }
         }
             globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple);
           }
         }
@@ -692,6 +714,8 @@ public class LocationInference {
                       + "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple="
                       + globalParamLocTuple);
               hasChanges = true;
                       + "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple="
                       + globalParamLocTuple);
               hasChanges = true;
+              System.out.println("B2");
+
               globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple);
             }
           }
               globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple);
             }
           }
@@ -1308,6 +1332,7 @@ public class LocationInference {
 
     MethodDescriptor md = (MethodDescriptor) targetLocalLoc.getDescriptor();
     FlowGraph flowGraph = getFlowGraph(md);
 
     MethodDescriptor md = (MethodDescriptor) targetLocalLoc.getDescriptor();
     FlowGraph flowGraph = getFlowGraph(md);
+
     FlowNode flowNode = flowGraph.getFlowNode(node.getDescTuple());
     Set<FlowNode> reachableSet = flowGraph.getReachFlowNodeSetFrom(flowNode);
 
     FlowNode flowNode = flowGraph.getFlowNode(node.getDescTuple());
     Set<FlowNode> reachableSet = flowGraph.getReachFlowNodeSetFrom(flowNode);
 
@@ -1737,6 +1762,7 @@ public class LocationInference {
       // Location loc = new Location(md, dstVarDesc);
       // dstLocTuple.add(loc);
       // }
       // Location loc = new Location(md, dstVarDesc);
       // dstLocTuple.add(loc);
       // }
+      System.out.println("B11");
 
       globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple);
 
 
       globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple);
 
@@ -1849,6 +1875,8 @@ public class LocationInference {
         if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
           for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) {
             NTuple<Location> pcLocTuple = (NTuple<Location>) iterator2.next();
         if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
           for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) {
             NTuple<Location> pcLocTuple = (NTuple<Location>) iterator2.next();
+            System.out.println("B12");
+
             callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple);
           }
         }
             callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple);
           }
         }
@@ -1864,11 +1892,11 @@ public class LocationInference {
     GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
     GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
 
     GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
     GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
 
-    // System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode);
+    System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode);
 
     NTuple<Location> callerSrcNodeLocTuple =
         translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
 
     NTuple<Location> callerSrcNodeLocTuple =
         translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
-    // System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
+    System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
 
     if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
 
 
     if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
 
@@ -1880,7 +1908,9 @@ public class LocationInference {
             translateToCallerLocTuple(min, mdCallee, mdCaller, outNode.getLocTuple());
         // System.out.println("outNode=" + outNode + "   callerDstNodeLocTuple="
         // + callerDstNodeLocTuple);
             translateToCallerLocTuple(min, mdCallee, mdCaller, outNode.getLocTuple());
         // System.out.println("outNode=" + outNode + "   callerDstNodeLocTuple="
         // + callerDstNodeLocTuple);
-        if (callerDstNodeLocTuple != null) {
+        if (callerSrcNodeLocTuple != null && callerDstNodeLocTuple != null
+            && callerSrcNodeLocTuple.size() > 0 && callerDstNodeLocTuple.size() > 0) {
+          System.out.println("B3");
           callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
         }
       }
           callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
         }
       }
@@ -1941,7 +1971,7 @@ public class LocationInference {
 
       TypeDescriptor type = ((FieldDescriptor) desc).getType();
       if (type.isArray()) {
 
       TypeDescriptor type = ((FieldDescriptor) desc).getType();
       if (type.isArray()) {
-        return false;
+        return !type.isPrimitive();
       } else {
         return type.isPtr();
       }
       } else {
         return type.isPtr();
       }
@@ -1949,7 +1979,7 @@ public class LocationInference {
     } else if (desc instanceof VarDescriptor) {
       TypeDescriptor type = ((VarDescriptor) desc).getType();
       if (type.isArray()) {
     } else if (desc instanceof VarDescriptor) {
       TypeDescriptor type = ((VarDescriptor) desc).getType();
       if (type.isArray()) {
-        return false;
+        return !type.isPrimitive();
       } else {
         return type.isPtr();
       }
       } else {
         return type.isPtr();
       }
@@ -2338,6 +2368,60 @@ public class LocationInference {
 
   private void constructHierarchyGraph() {
 
 
   private void constructHierarchyGraph() {
 
+    LinkedList<MethodDescriptor> methodDescList =
+        (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
+
+    while (!methodDescList.isEmpty()) {
+      MethodDescriptor md = methodDescList.removeLast();
+      if (state.SSJAVADEBUG) {
+        HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
+        System.out.println();
+        System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
+        constructHierarchyGraph(md, hierarchyGraph);
+        mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
+
+      }
+    }
+
+    setupToAnalyze();
+    while (!toAnalyzeIsEmpty()) {
+      ClassDescriptor cd = toAnalyzeNext();
+      HierarchyGraph graph = getHierarchyGraph(cd);
+      for (Iterator iter = cd.getFields(); iter.hasNext();) {
+        FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
+        if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
+          graph.getHNode(fieldDesc);
+        }
+      }
+    }
+
+    Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      Descriptor key = (Descriptor) iterator.next();
+      HierarchyGraph graph = getHierarchyGraph(key);
+
+      Set<HNode> nodeToBeConnected = new HashSet<HNode>();
+      for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
+        HNode node = (HNode) iterator2.next();
+        if (!node.isSkeleton() && !node.isCombinationNode()) {
+          if (graph.getIncomingNodeSet(node).size() == 0) {
+            nodeToBeConnected.add(node);
+          }
+        }
+      }
+
+      for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
+        HNode node = (HNode) iterator2.next();
+        System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
+        graph.addEdge(graph.getHNode(TOPDESC), node);
+      }
+
+    }
+
+  }
+
+  private void constructHierarchyGraph2() {
+
     // do fixed-point analysis
 
     LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
     // do fixed-point analysis
 
     LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
@@ -2547,6 +2631,9 @@ public class LocationInference {
           System.out.println("-srcCurTuple=" + srcCurTuple + "  dstCurTuple=" + dstCurTuple
               + "  srcNode=" + srcNode + "   dstNode=" + dstNode);
 
           System.out.println("-srcCurTuple=" + srcCurTuple + "  dstCurTuple=" + dstCurTuple
               + "  srcNode=" + srcNode + "   dstNode=" + dstNode);
 
+          // srcCurTuple = translateBaseTuple(srcNode, srcCurTuple);
+          // dstCurTuple = translateBaseTuple(dstNode, dstCurTuple);
+
           if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
               && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
 
           if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
               && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
 
@@ -2611,6 +2698,31 @@ public class LocationInference {
 
   }
 
 
   }
 
+  private NTuple<Descriptor> translateBaseTuple(FlowNode flowNode, NTuple<Descriptor> inTuple) {
+
+    if (flowNode.getBaseTuple() != null) {
+
+      NTuple<Descriptor> translatedTuple = new NTuple<Descriptor>();
+
+      NTuple<Descriptor> baseTuple = flowNode.getBaseTuple();
+
+      for (int i = 0; i < baseTuple.size(); i++) {
+        translatedTuple.add(baseTuple.get(i));
+      }
+
+      for (int i = 1; i < inTuple.size(); i++) {
+        translatedTuple.add(inTuple.get(i));
+      }
+
+      System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple);
+      return translatedTuple;
+
+    } else {
+      return inTuple;
+    }
+
+  }
+
   private MethodSummary getMethodSummary(MethodDescriptor md) {
     if (!mapDescToLocationSummary.containsKey(md)) {
       mapDescToLocationSummary.put(md, new MethodSummary(md));
   private MethodSummary getMethodSummary(MethodDescriptor md) {
     if (!mapDescToLocationSummary.containsKey(md)) {
       mapDescToLocationSummary.put(md, new MethodSummary(md));
@@ -3262,6 +3374,8 @@ public class LocationInference {
             if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) {
               flowNodeLowerthanPCLocSet.add(node);
               fg.addValueFlowEdge(pcDescTuple, node.getDescTuple());
             if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) {
               flowNodeLowerthanPCLocSet.add(node);
               fg.addValueFlowEdge(pcDescTuple, node.getDescTuple());
+              System.out.println("B10");
+
               subGlobalFlowGraph.addValueFlowEdge(pcLocTuple,
                   translateToLocTuple(md, node.getDescTuple()));
             }
               subGlobalFlowGraph.addValueFlowEdge(pcLocTuple,
                   translateToLocTuple(md, node.getDescTuple()));
             }
@@ -3276,7 +3390,7 @@ public class LocationInference {
           System.out.println("#########################################");
           for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) {
             FlowNode lowerNode = (FlowNode) iterator.next();
           System.out.println("#########################################");
           for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) {
             FlowNode lowerNode = (FlowNode) iterator.next();
-            if (lowerNode.getCompositeLocation() == null) {
+            if (lowerNode.getDescTuple().size() == 1 && lowerNode.getCompositeLocation() == null) {
               NTuple<Location> lowerLocTuple = translateToLocTuple(md, lowerNode.getDescTuple());
               CompositeLocation newComp =
                   calculateCompositeLocationFromSubGlobalGraph(md, lowerNode);
               NTuple<Location> lowerLocTuple = translateToLocTuple(md, lowerNode.getDescTuple());
               CompositeLocation newComp =
                   calculateCompositeLocationFromSubGlobalGraph(md, lowerNode);
@@ -4723,6 +4837,7 @@ public class LocationInference {
     fn.setDeclarationNode();
 
     if (dn.getExpression() != null) {
     fn.setDeclarationNode();
 
     if (dn.getExpression() != null) {
+      System.out.println("-analyzeFlowDeclarationNode=" + dn.printNode(0));
 
       NodeTupleSet nodeSetRHS = new NodeTupleSet();
       analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null,
 
       NodeTupleSet nodeSetRHS = new NodeTupleSet();
       analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null,
@@ -4751,9 +4866,22 @@ public class LocationInference {
       GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
       for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
         NTuple<Location> calleeReturnLocTuple = iterator.next();
       GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
       for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
         NTuple<Location> calleeReturnLocTuple = iterator.next();
+        System.out.println("B7");
+
         globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
       }
 
         globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
       }
 
+      for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
+          .hasNext();) {
+        NTuple<Location> implicitGlobalTuple = iterator.next();
+        System.out.println("B8");
+
+        globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS));
+      }
+
+      System.out.println("-nodeSetRHS=" + nodeSetRHS);
+      System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
+
     }
 
   }
     }
 
   }
@@ -5001,6 +5129,13 @@ public class LocationInference {
 
         assert (baseNodeSet.size() == 1);
         NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
 
         assert (baseNodeSet.size() == 1);
         NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
+        if (baseTuple.get(0) instanceof InterDescriptor) {
+          if (baseTuple.size() > 1) {
+            throw new Error();
+          }
+          FlowNode interNode = getFlowGraph(mdCaller).getFlowNode(baseTuple);
+          baseTuple = translateBaseTuple(interNode, baseTuple);
+        }
         mapMethodInvokeNodeToBaseTuple.put(min, baseTuple);
 
         if (!min.getMethod().isStatic()) {
         mapMethodInvokeNodeToBaseTuple.put(min, baseTuple);
 
         if (!min.getMethod().isStatic()) {
@@ -5024,7 +5159,8 @@ public class LocationInference {
               // nodeSet.addTuple(inFlowTuple);
               System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + "  from="
                   + mdCallee.getThis());
               // nodeSet.addTuple(inFlowTuple);
               System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + "  from="
                   + mdCallee.getThis());
-              tupleSet.addTuple(inFlowTuple);
+              // tupleSet.addTuple(inFlowTuple);
+              tupleSet.addTuple(baseTuple);
             } else {
               // TODO
               System.out.println("returnNode=" + returnNode);
             } else {
               // TODO
               System.out.println("returnNode=" + returnNode);
@@ -5110,7 +5246,7 @@ public class LocationInference {
       }
 
       if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) {
       }
 
       if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) {
-        FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min);
+        FlowReturnNode returnHolderNode = getFlowGraph(mdCaller).createReturnNode(min);
 
         if (needToGenerateInterLoc(tupleSet)) {
           System.out.println("20");
 
         if (needToGenerateInterLoc(tupleSet)) {
           System.out.println("20");
@@ -5136,17 +5272,26 @@ public class LocationInference {
             }
           }
 
             }
           }
 
-          setNode.addTuple(interTuple);
-          System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + setNode);
+          returnHolderNode.addTuple(interTuple);
+          // TODO
+          nodeSet.addTuple(interTuple);
+          System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode);
 
         } else {
 
         } else {
-          setNode.addTupleSet(tupleSet);
-          System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + setNode);
-
+          returnHolderNode.addTupleSet(tupleSet);
+          System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + returnHolderNode);
         }
         // setNode.addTupleSet(tupleSet);
         }
         // setNode.addTupleSet(tupleSet);
-        nodeSet.addTuple(setNode.getDescTuple());
+        // NodeTupleSet setFromReturnNode=new NodeTupleSet();
+        // setFromReturnNode.addTuple(tuple);
+
+        NodeTupleSet holderTupleSet =
+            getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), returnHolderNode);
 
 
+        System.out.println("HOLDER TUPLe SET=" + holderTupleSet);
+        nodeSet.addTupleSet(holderTupleSet);
+
+        nodeSet.addTuple(returnHolderNode.getDescTuple());
       }
 
       // propagateFlowsFromCallee(min, md, min.getMethod());
       }
 
       // propagateFlowsFromCallee(min, md, min.getMethod());
@@ -5175,6 +5320,47 @@ public class LocationInference {
 
   }
 
 
   }
 
+  private NodeTupleSet getNodeTupleSetFromReturnNode(FlowGraph fg, FlowReturnNode node) {
+    NodeTupleSet nts = new NodeTupleSet();
+
+    Set<NTuple<Descriptor>> returnSet = node.getReturnTupleSet();
+
+    for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
+      FlowNode flowNode = fg.getFlowNode(tuple);
+      if (flowNode instanceof FlowReturnNode) {
+        returnSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
+      } else {
+        returnSet.add(tuple);
+      }
+    }
+
+    for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator.next();
+      nts.addTuple(nTuple);
+    }
+
+    return nts;
+
+  }
+
+  private Set<NTuple<Descriptor>> recurGetNode(FlowGraph fg, FlowReturnNode rnode) {
+
+    Set<NTuple<Descriptor>> tupleSet = new HashSet<NTuple<Descriptor>>();
+
+    Set<NTuple<Descriptor>> returnSet = rnode.getReturnTupleSet();
+    for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
+      NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
+      FlowNode flowNode = fg.getFlowNode(tuple);
+      if (flowNode instanceof FlowReturnNode) {
+        tupleSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
+      }
+      tupleSet.add(tuple);
+    }
+
+    return tupleSet;
+  }
+
   private NTuple<Descriptor> generateArgTuple(MethodDescriptor mdCaller, NodeTupleSet argTupleSet) {
 
     int size = 0;
   private NTuple<Descriptor> generateArgTuple(MethodDescriptor mdCaller, NodeTupleSet argTupleSet) {
 
     int size = 0;
@@ -5222,7 +5408,7 @@ public class LocationInference {
     }
     // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
     Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
     }
     // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
     Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
-    System.out.println("inNode=" + inNode + "  reachalbeSet=" + reachableSet);
+    // System.out.println("inNode=" + inNode + "  reachalbeSet=" + reachableSet);
 
     for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
       FlowNode fn = (FlowNode) iterator.next();
 
     for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
       FlowNode fn = (FlowNode) iterator.next();
@@ -5290,6 +5476,8 @@ public class LocationInference {
         NTuple<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
           NTuple<Descriptor> arrTuple = arrIter.next();
         NTuple<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
           NTuple<Descriptor> arrTuple = arrIter.next();
+          System.out.println("B4");
+
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple));
         }
       }
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple));
         }
       }
@@ -5307,7 +5495,8 @@ public class LocationInference {
 
         if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
           System.out.println("1");
 
         if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
           System.out.println("1");
-          NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
+          FlowNode interNode = getFlowGraph(md).createIntermediateNode();
+          NTuple<Descriptor> interTuple = interNode.getDescTuple();
 
           for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) {
             NTuple<Descriptor> higherTuple = iter.next();
 
           for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) {
             NTuple<Descriptor> higherTuple = iter.next();
@@ -5321,6 +5510,7 @@ public class LocationInference {
           if (base != null) {
             fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
                 getClassTypeDescriptor(base.get(base.size() - 1)));
           if (base != null) {
             fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
                 getClassTypeDescriptor(base.get(base.size() - 1)));
+            interNode.setBaseTuple(base);
           }
         }
       }
           }
         }
       }
@@ -5557,6 +5747,8 @@ public class LocationInference {
         for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
             .hasNext();) {
           NTuple<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
             .hasNext();) {
           NTuple<Location> calleeReturnLocTuple = iterator.next();
+          System.out.println("B9");
+
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
               translateToLocTuple(md, flowFieldTuple));
         }
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
               translateToLocTuple(md, flowFieldTuple));
         }
@@ -5689,6 +5881,8 @@ public class LocationInference {
           NTuple<Descriptor> callerLHSTuple = iter2.next();
           System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
               + translateToLocTuple(md, callerLHSTuple));
           NTuple<Descriptor> callerLHSTuple = iter2.next();
           System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
               + translateToLocTuple(md, callerLHSTuple));
+          System.out.println("B5");
+
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
               translateToLocTuple(md, callerLHSTuple));
         }
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
               translateToLocTuple(md, callerLHSTuple));
         }
@@ -5699,6 +5893,8 @@ public class LocationInference {
         NTuple<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
           NTuple<Descriptor> callerLHSTuple = iter2.next();
         NTuple<Location> calleeReturnLocTuple = iterator.next();
         for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
           NTuple<Descriptor> callerLHSTuple = iter2.next();
+          System.out.println("B6");
+
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
               translateToLocTuple(md, callerLHSTuple));
           System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> "
           globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
               translateToLocTuple(md, callerLHSTuple));
           System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> "
index 851a99bd805802bb4f0c11587dda1bd276ecddf5..c635d89a9508558c793ec5fd7301cf5a0379046b 100644 (file)
 public class DeviationScanner {\r
 \r
   @LOC("DEV")\r
 public class DeviationScanner {\r
 \r
   @LOC("DEV")\r
-  private EyePosition eyePositions[];\r
-\r
-  // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),\r
-  // RIGHT(-1, 0), LEFT_DOWN(\r
-  // +1, +1), DOWN(0, +1), RIGHT_DOWN(-1, +1);\r
+  private int x[];\r
+  @LOC("DEV")\r
+  private int y[];\r
 \r
   public static final int LEFT_UP = 0;\r
   public static final int UP = 1;\r
 \r
   public static final int LEFT_UP = 0;\r
   public static final int UP = 1;\r
@@ -44,23 +42,18 @@ public class DeviationScanner {
   public static final int RIGHT_DOWN = 8;\r
 \r
   public DeviationScanner() {\r
   public static final int RIGHT_DOWN = 8;\r
 \r
   public DeviationScanner() {\r
-    eyePositions = new EyePosition[3];\r
+    x = new int[3];\r
+    y = new int[3];\r
+    SSJAVA.arrayinit(x, -1);\r
+    SSJAVA.arrayinit(y, -1);\r
   }\r
 \r
   }\r
 \r
-  @LATTICE("THIS<C,C<IN,THISLOC=THIS")\r
-  public void addEyePosition(@LOC("IN") EyePosition eyePosition) {\r
-\r
-    // for (@LOC("THIS,DeviationScanner.C") int i = 1; i < 3; i++) {\r
-    // eyePositions[i - 1] = eyePositions[i];\r
-    // eyePositions[i] = null;\r
-    // }\r
-    // eyePositions[eyePositions.length - 1] = eyePosition;\r
-\r
-    SSJAVA.append(eyePositions, eyePosition);\r
-\r
+  @LATTICE("THIS<IN,THISLOC=THIS")\r
+  public void addEyePosition(@LOC("IN") int inx, @LOC("IN") int iny) {\r
+    SSJAVA.append(x, inx);\r
+    SSJAVA.append(y, iny);\r
   }\r
 \r
   }\r
 \r
-  // @LATTICE("OUT<DEV,DEV<C,C<THIS,THIS<IN,C*,DEV*,OUT*,THISLOC=THIS,RETURNLOC=OUT")\r
   @LATTICE("THIS<C,THIS<IN,THISLOC=THIS,C*")\r
   @RETURNLOC("THIS,DeviationScanner.DEV")\r
   public int scanForDeviation(@LOC("IN") Rectangle2D faceRect) {\r
   @LATTICE("THIS<C,THIS<IN,THISLOC=THIS,C*")\r
   @RETURNLOC("THIS,DeviationScanner.DEV")\r
   public int scanForDeviation(@LOC("IN") Rectangle2D faceRect) {\r
@@ -68,7 +61,7 @@ public class DeviationScanner {
     @LOC("THIS,DeviationScanner.DEV") int deviation = NONE;\r
 \r
     for (@LOC("C") int i = 0; i < 3; i++) {\r
     @LOC("THIS,DeviationScanner.DEV") int deviation = NONE;\r
 \r
     for (@LOC("C") int i = 0; i < 3; i++) {\r
-      if (eyePositions[i] == null) {\r
+      if (x[i] == -1) {\r
         return deviation;\r
       }\r
     }\r
         return deviation;\r
       }\r
     }\r
@@ -79,8 +72,8 @@ public class DeviationScanner {
     @LOC("THIS,DeviationScanner.DEV") int lastIdx = -1;\r
     for (@LOC("THIS,DeviationScanner.DEV") int i = 0; i < 3; ++i) {\r
       if (lastIdx != -1) {\r
     @LOC("THIS,DeviationScanner.DEV") int lastIdx = -1;\r
     for (@LOC("THIS,DeviationScanner.DEV") int i = 0; i < 3; ++i) {\r
       if (lastIdx != -1) {\r
-        deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX());\r
-        deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY());\r
+        deviationX += (x[i] - x[lastIdx]);\r
+        deviationY += (y[i] - y[lastIdx]);\r
       }\r
       lastIdx = i;\r
     }\r
       }\r
       lastIdx = i;\r
     }\r
@@ -105,11 +98,9 @@ public class DeviationScanner {
     deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);\r
 \r
     if (deviation != NONE) {\r
     deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);\r
 \r
     if (deviation != NONE) {\r
-      eyePositions = new EyePosition[3];\r
+      SSJAVA.arrayinit(x, -1);\r
+      SSJAVA.arrayinit(y, -1);\r
     }\r
     }\r
-    // System.out.println(String.format("%.2f%% | %.2f%% => %d and %d >>> %s",\r
-    // deviationX*100, deviationY*100, deviationAbsoluteX, deviationAbsoluteY,\r
-    // deviation.toString()));\r
 \r
     return deviation;\r
   }\r
 \r
     return deviation;\r
   }\r
@@ -140,11 +131,6 @@ public class DeviationScanner {
     return -1;\r
   }\r
 \r
     return -1;\r
   }\r
 \r
-  public void clear() {\r
-    System.out.println("CLEAR");\r
-    eyePositions = new EyePosition[3];\r
-  }\r
-\r
   public String toStringDeviation(@LOC("IN") int dev) {\r
     if (dev == LEFT_UP) {\r
       return "LEFT_UP";\r
   public String toStringDeviation(@LOC("IN") int dev) {\r
     if (dev == LEFT_UP) {\r
       return "LEFT_UP";\r
index 8422220a1d6898e58e288792631597a1da431c0f..f5edbb88756f50f66d1512ac7cb43fbdaa16ee57 100644 (file)
@@ -29,23 +29,6 @@ public class EyePosition {
   private int x;
   @LOC("POS")
   private int y;
   private int x;
   @LOC("POS")
   private int y;
-  @LOC("POS") private double facex;
-  @LOC("POS") private double facey;
-  @LOC("POS") private double facewidth;
-  @LOC("POS") private double faceheight;
-
-  // private Rectangle2D faceRect;
-
-  // public EyePosition(Point p, Rectangle2D faceRect) {
-  // this(p.x, p.y, faceRect);
-  // }
-  //
-  // public EyePosition(int x, int y, Rectangle2D faceRect) {
-  // this.x = x;
-  // this.y = y;
-  // this.faceRect = faceRect;
-  // }
 
   public EyePosition(int x, int y) {
     this.x = x;
 
   public EyePosition(int x, int y) {
     this.x = x;
@@ -64,36 +47,6 @@ public class EyePosition {
     return "(" + x + "," + y + ")";
   }
 
     return "(" + x + "," + y + ")";
   }
 
-  // public Deviation getDeviation(EyePosition oldEyePosition) {
-  // if (oldEyePosition == null) return Deviation.NONE;
-  //
-  // //first we check if the faceRects are corresponding
-  // double widthChange = (this.faceRect.getWidth() -
-  // oldEyePosition.faceRect.getWidth()) / this.faceRect.getWidth();
-  // if (widthChange > 0.1) return Deviation.NONE;
-  //
-  // int maxDeviationX = (int)Math.round(this.faceRect.getWidth() / 4f);
-  // int maxDeviationY = (int)Math.round(this.faceRect.getWidth() / 8f);
-  // int minDeviation = (int)Math.round(this.faceRect.getWidth() / 16f);
-  //
-  // int deviationX = Math.abs(x - oldEyePosition.x);
-  // int directionX = sgn(x - oldEyePosition.x);
-  // if (deviationX < minDeviation || deviationX > maxDeviationX) directionX =
-  // 0;
-  //
-  // int deviationY = Math.abs(y - oldEyePosition.y);
-  // int directionY = sgn(y - oldEyePosition.y);
-  // if (deviationY < minDeviation || deviationY > maxDeviationY) directionY =
-  // 0;
-  //
-  // double deviationXPercent = deviationX / this.faceRect.getWidth();
-  // double deviationYPercent = deviationY / this.faceRect.getWidth();
-  //
-  // System.out.println(String.format("devX: %.2f | devY: %.2f",
-  // deviationXPercent*100f, deviationYPercent*100f));
-  // return Deviation.getDirectionFor(directionX, directionY);
-  // }
-
   private static int sgn(int i) {
     if (i > 0)
       return 1;
   private static int sgn(int i) {
     if (i > 0)
       return 1;
index 3197ac346b65d411f101ce459bbe4ba80b838754..9e944aa26333dfc7f1c9a076b79ff7f1ff422152 100644 (file)
@@ -1,3 +1,5 @@
+import Benchmarks.SSJava.EyeTrackingInfer.EyePosition;
+
 /*
  * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
  * 
 /*
  * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
  * 
 /**
  * This is the main class of LEA.
  * <p>
 /**
  * This is the main class of LEA.
  * <p>
- * It uses a face detection algorithm to find an a face within the provided
- * image(s). Then it searches for the eye in a region where it most likely
- * located and traces its position relative to the face and to the last known
- * position. The movements are estimated by comparing more than one movement. If
- * a movement is distinctly pointing to a direction it is recognized and all
- * listeners get notified.
+ * It uses a face detection algorithm to find an a face within the provided image(s). Then it
+ * searches for the eye in a region where it most likely located and traces its position relative to
+ * the face and to the last known position. The movements are estimated by comparing more than one
+ * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners
+ * get notified.
  * <p>
  * The notification is designed as observer pattern. You simply call
  * <p>
  * The notification is designed as observer pattern. You simply call
- * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an
- * implementation of <code>IEyeMovementListener</code> to LEA. When a face is
- * recognized/lost or whenever an eye movement is detected LEA will call the
- * appropriate methods of the listener
+ * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an implementation of
+ * <code>IEyeMovementListener</code> to LEA. When a face is recognized/lost or whenever an eye
+ * movement is detected LEA will call the appropriate methods of the listener
  * <p>
  * <p>
- * LEA also needs an image source implementing the <code>ICaptureDevice</code>.
- * One image source proxy to the <code>Java Media Framework</code> is included (
- * <code>JMFCaptureDevice</code>).
+ * LEA also needs an image source implementing the <code>ICaptureDevice</code>. One image source
+ * proxy to the <code>Java Media Framework</code> is included ( <code>JMFCaptureDevice</code>).
  * <p>
  * Example (for using LEA with <code>Java Media Framework</code>):
  * <p>
  * <p>
  * Example (for using LEA with <code>Java Media Framework</code>):
  * <p>
  * LEA lea = new LEA(new JMFCaptureDevice(), true);
  * </code>
  * <p>
  * LEA lea = new LEA(new JMFCaptureDevice(), true);
  * </code>
  * <p>
- * This will start LEA with the first available JMF datasource with an extra
- * status window showing if face/eye has been detected successfully. Please note
- * that face detection needs about 2 seconds to find a face. After detection the
- * following face detection is much faster.
+ * This will start LEA with the first available JMF datasource with an extra status window showing
+ * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds
+ * to find a face. After detection the following face detection is much faster.
  * 
  * @author Florian Frankenberger
  */
  * 
  * @author Florian Frankenberger
  */
-@LATTICE("LAST<DEV,DEV<POS,POS<IMPL")
+@LATTICE("LAST<DEV,DEV<E,E<POS,POS<IMPL")
 @METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
 public class LEA {
 
   @LOC("IMPL")
   private LEAImplementation implementation;
 @METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
 public class LEA {
 
   @LOC("IMPL")
   private LEAImplementation implementation;
-  @LOC("LAST")
-  private FaceAndEyePosition lastPositions = new FaceAndEyePosition(-1,-1,-1,-1, null);
   @LOC("DEV")
   private DeviationScanner deviationScanner = new DeviationScanner();
 
   @LOC("DEV")
   private DeviationScanner deviationScanner = new DeviationScanner();
 
@@ -68,18 +64,17 @@ public class LEA {
   }
 
   /**
   }
 
   /**
-   * Clears the internal movement buffer. If you just capture some of the eye
-   * movements you should call this every time you start recording the
-   * movements. Otherwise you may get notified for movements that took place
-   * BEFORE you started recording.
+   * Clears the internal movement buffer. If you just capture some of the eye movements you should
+   * call this every time you start recording the movements. Otherwise you may get notified for
+   * movements that took place BEFORE you started recording.
    */
   public void clear() {
     // this.imageProcessor.clearDeviationScanner();
   }
 
   /**
    */
   public void clear() {
     // this.imageProcessor.clearDeviationScanner();
   }
 
   /**
-   * @METHOD To test LEA with the first capture device from the
-   *         <code>Java Media Framework</code> just start from here.
+   * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
+   *         just start from here.
    * 
    * @param args
    * @throws Exception
    * 
    * @param args
    * @throws Exception
@@ -95,7 +90,7 @@ public class LEA {
     @LOC("C") int i = 0;
 
     SSJAVA: while (true) {
     @LOC("C") int i = 0;
 
     SSJAVA: while (true) {
-      @LOC("IMG") Image image =  ImageReader.getImage();
+      @LOC("IMG") Image image = ImageReader.getImage();
       if (image == null) {
         break;
       }
       if (image == null) {
         break;
       }
@@ -105,12 +100,11 @@ public class LEA {
     System.out.println("Done.");
 
   }
     System.out.println("Done.");
 
   }
-  
 
   private void processImage(@LOC("IN") Image image) {
     @LOC("THIS,LEA.POS") FaceAndEyePosition positions = implementation.getEyePosition(image);
 
   private void processImage(@LOC("IN") Image image) {
     @LOC("THIS,LEA.POS") FaceAndEyePosition positions = implementation.getEyePosition(image);
-    // if (positions.getEyePosition() != null) {
-    deviationScanner.addEyePosition(positions.getEyePosition());
+    deviationScanner.addEyePosition(positions.getEyePosition().getX(), positions.getEyePosition()
+        .getY());
     @LOC("THIS,LEA.DEV,DeviationScanner.DEV") int deviation =
         deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
     if (deviation != DeviationScanner.NONE) {
     @LOC("THIS,LEA.DEV,DeviationScanner.DEV") int deviation =
         deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
     if (deviation != DeviationScanner.NONE) {
@@ -118,7 +112,6 @@ public class LEA {
       // notifyEyeMovementListenerEyeMoved(deviation);
     }
     // }
       // notifyEyeMovementListenerEyeMoved(deviation);
     }
     // }
-    lastPositions = positions;
   }
 
 }
   }
 
 }
index 4cc353e02d7ba3f92b068672561ef7e8d442c553..412d9e23a4e67ff61ff5b9b77028441ca9d9f79a 100644 (file)
  * @author Florian Frankenberger\r
  */\r
 \r
  * @author Florian Frankenberger\r
  */\r
 \r
-\r
 public class DeviationScanner {\r
 \r
 public class DeviationScanner {\r
 \r
-  \r
-  private EyePosition eyePositions[];\r
+  private int x[];\r
+  private int y[];\r
 \r
   // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),\r
   // RIGHT(-1, 0), LEFT_DOWN(\r
 \r
   // LEFT_UP(+1, -1), UP(0, -1), RIGHT_UP(-1, -1), LEFT(+1, 0), NONE(0, 0),\r
   // RIGHT(-1, 0), LEFT_DOWN(\r
@@ -44,55 +43,47 @@ public class DeviationScanner {
   public static final int RIGHT_DOWN = 8;\r
 \r
   public DeviationScanner() {\r
   public static final int RIGHT_DOWN = 8;\r
 \r
   public DeviationScanner() {\r
-    eyePositions = new EyePosition[3];\r
+    x = new int[3];\r
+    y = new int[3];\r
+    SSJAVA.arrayinit(x, -1);\r
+    SSJAVA.arrayinit(y, -1);\r
   }\r
 \r
   }\r
 \r
-  \r
-  public void addEyePosition( EyePosition eyePosition) {\r
-\r
-    // for ( int i = 1; i < 3; i++) {\r
-    // eyePositions[i - 1] = eyePositions[i];\r
-    // eyePositions[i] = null;\r
-    // }\r
-    // eyePositions[eyePositions.length - 1] = eyePosition;\r
-\r
-    SSJAVA.append(eyePositions, eyePosition);\r
-\r
+  public void addEyePosition(int inx, int iny) {\r
+    SSJAVA.append(x, inx);\r
+    SSJAVA.append(y, iny);\r
   }\r
 \r
   }\r
 \r
-  // \r
-  \r
-  \r
-  public int scanForDeviation( Rectangle2D faceRect) {\r
+  public int scanForDeviation(Rectangle2D faceRect) {\r
 \r
 \r
-     int deviation = NONE;\r
+    int deviation = NONE;\r
 \r
 \r
-    for ( int i = 0; i < 3; i++) {\r
-      if (eyePositions[i] == null) {\r
+    for (int i = 0; i < 3; i++) {\r
+      if (x[i] == -1) {\r
         return deviation;\r
       }\r
     }\r
 \r
         return deviation;\r
       }\r
     }\r
 \r
-     double deviationX = 0;\r
-     double deviationY = 0;\r
+    double deviationX = 0;\r
+    double deviationY = 0;\r
 \r
 \r
-     int lastIdx = -1;\r
-    for ( int i = 0; i < 3; ++i) {\r
+    int lastIdx = -1;\r
+    for (int i = 0; i < 3; ++i) {\r
       if (lastIdx != -1) {\r
       if (lastIdx != -1) {\r
-        deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX());\r
-        deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY());\r
+        deviationX += (x[i] - x[lastIdx]);\r
+        deviationY += (y[i] - y[lastIdx]);\r
       }\r
       lastIdx = i;\r
     }\r
 \r
       }\r
       lastIdx = i;\r
     }\r
 \r
-     final double deviationPercentX = 0.04;\r
-     final double deviationPercentY = 0.04;\r
+    final double deviationPercentX = 0.04;\r
+    final double deviationPercentY = 0.04;\r
 \r
     deviationX /= faceRect.getWidth();\r
     deviationY /= faceRect.getWidth();\r
 \r
 \r
     deviationX /= faceRect.getWidth();\r
     deviationY /= faceRect.getWidth();\r
 \r
-     int deviationAbsoluteX = 0;\r
-     int deviationAbsoluteY = 0;\r
+    int deviationAbsoluteX = 0;\r
+    int deviationAbsoluteY = 0;\r
     if (deviationX > deviationPercentX)\r
       deviationAbsoluteX = 1;\r
     if (deviationX < -deviationPercentX)\r
     if (deviationX > deviationPercentX)\r
       deviationAbsoluteX = 1;\r
     if (deviationX < -deviationPercentX)\r
@@ -105,17 +96,14 @@ public class DeviationScanner {
     deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);\r
 \r
     if (deviation != NONE) {\r
     deviation = getDirectionFor(deviationAbsoluteX, deviationAbsoluteY);\r
 \r
     if (deviation != NONE) {\r
-      eyePositions = new EyePosition[3];\r
+      SSJAVA.arrayinit(x, -1);\r
+      SSJAVA.arrayinit(y, -1);\r
     }\r
     }\r
-    // System.out.println(String.format("%.2f%% | %.2f%% => %d and %d >>> %s",\r
-    // deviationX*100, deviationY*100, deviationAbsoluteX, deviationAbsoluteY,\r
-    // deviation.toString()));\r
 \r
     return deviation;\r
   }\r
 \r
 \r
     return deviation;\r
   }\r
 \r
-  \r
-  public int getDirectionFor( int directionX,  int directionY) {\r
+  public int getDirectionFor(int directionX, int directionY) {\r
 \r
     if (directionX == +1 && directionY == -1) {\r
       return LEFT_UP;\r
 \r
     if (directionX == +1 && directionY == -1) {\r
       return LEFT_UP;\r
@@ -140,12 +128,7 @@ public class DeviationScanner {
     return -1;\r
   }\r
 \r
     return -1;\r
   }\r
 \r
-  public void clear() {\r
-    System.out.println("CLEAR");\r
-    eyePositions = new EyePosition[3];\r
-  }\r
-\r
-  public String toStringDeviation( int dev) {\r
+  public String toStringDeviation(int dev) {\r
     if (dev == LEFT_UP) {\r
       return "LEFT_UP";\r
     } else if (dev == UP) {\r
     if (dev == LEFT_UP) {\r
       return "LEFT_UP";\r
     } else if (dev == UP) {\r
index 40479eb13d2f377e3f7bd3770b17c53b53274b3b..7db95e6af7b7ca7cec50d664502f2349f6c330f5 100644 (file)
 /**
  * This is the main class of LEA.
  * <p>
 /**
  * This is the main class of LEA.
  * <p>
- * It uses a face detection algorithm to find an a face within the provided
- * image(s). Then it searches for the eye in a region where it most likely
- * located and traces its position relative to the face and to the last known
- * position. The movements are estimated by comparing more than one movement. If
- * a movement is distinctly pointing to a direction it is recognized and all
- * listeners get notified.
+ * It uses a face detection algorithm to find an a face within the provided image(s). Then it
+ * searches for the eye in a region where it most likely located and traces its position relative to
+ * the face and to the last known position. The movements are estimated by comparing more than one
+ * movement. If a movement is distinctly pointing to a direction it is recognized and all listeners
+ * get notified.
  * <p>
  * The notification is designed as observer pattern. You simply call
  * <p>
  * The notification is designed as observer pattern. You simply call
- * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an
- * implementation of <code>IEyeMovementListener</code> to LEA. When a face is
- * recognized/lost or whenever an eye movement is detected LEA will call the
- * appropriate methods of the listener
+ * <code>addEyeMovementListener(IEyeMovementListener)</code> to add an implementation of
+ * <code>IEyeMovementListener</code> to LEA. When a face is recognized/lost or whenever an eye
+ * movement is detected LEA will call the appropriate methods of the listener
  * <p>
  * <p>
- * LEA also needs an image source implementing the <code>ICaptureDevice</code>.
- * One image source proxy to the <code>Java Media Framework</code> is included (
- * <code>JMFCaptureDevice</code>).
+ * LEA also needs an image source implementing the <code>ICaptureDevice</code>. One image source
+ * proxy to the <code>Java Media Framework</code> is included ( <code>JMFCaptureDevice</code>).
  * <p>
  * Example (for using LEA with <code>Java Media Framework</code>):
  * <p>
  * <p>
  * Example (for using LEA with <code>Java Media Framework</code>):
  * <p>
  * LEA lea = new LEA(new JMFCaptureDevice(), true);
  * </code>
  * <p>
  * LEA lea = new LEA(new JMFCaptureDevice(), true);
  * </code>
  * <p>
- * This will start LEA with the first available JMF datasource with an extra
- * status window showing if face/eye has been detected successfully. Please note
- * that face detection needs about 2 seconds to find a face. After detection the
- * following face detection is much faster.
+ * This will start LEA with the first available JMF datasource with an extra status window showing
+ * if face/eye has been detected successfully. Please note that face detection needs about 2 seconds
+ * to find a face. After detection the following face detection is much faster.
  * 
  * @author Florian Frankenberger
  */
 
  * 
  * @author Florian Frankenberger
  */
 
-
 public class LEA {
 
 public class LEA {
 
-  
   private LEAImplementation implementation;
   private LEAImplementation implementation;
-  
-  private FaceAndEyePosition lastPositions = new FaceAndEyePosition(-1,-1,-1,-1, null);
-  
+
   private DeviationScanner deviationScanner = new DeviationScanner();
 
   public LEA() {
   private DeviationScanner deviationScanner = new DeviationScanner();
 
   public LEA() {
@@ -68,18 +60,17 @@ public class LEA {
   }
 
   /**
   }
 
   /**
-   * Clears the internal movement buffer. If you just capture some of the eye
-   * movements you should call this every time you start recording the
-   * movements. Otherwise you may get notified for movements that took place
-   * BEFORE you started recording.
+   * Clears the internal movement buffer. If you just capture some of the eye movements you should
+   * call this every time you start recording the movements. Otherwise you may get notified for
+   * movements that took place BEFORE you started recording.
    */
   public void clear() {
     // this.imageProcessor.clearDeviationScanner();
   }
 
   /**
    */
   public void clear() {
     // this.imageProcessor.clearDeviationScanner();
   }
 
   /**
-   * @METHOD To test LEA with the first capture device from the
-   *         <code>Java Media Framework</code> just start from here.
+   * @METHOD To test LEA with the first capture device from the <code>Java Media Framework</code>
+   *         just start from here.
    * 
    * @param args
    * @throws Exception
    * 
    * @param args
    * @throws Exception
@@ -89,13 +80,12 @@ public class LEA {
     lea.doRun();
   }
 
     lea.doRun();
   }
 
-  
   public void doRun() {
 
   public void doRun() {
 
-     int i = 0;
+    int i = 0;
 
     SSJAVA: while (true) {
 
     SSJAVA: while (true) {
-       Image image =  ImageReader.getImage();
+      Image image = ImageReader.getImage();
       if (image == null) {
         break;
       }
       if (image == null) {
         break;
       }
@@ -105,19 +95,16 @@ public class LEA {
     System.out.println("Done.");
 
   }
     System.out.println("Done.");
 
   }
-  
 
 
-  private void processImage( Image image) {
-     FaceAndEyePosition positions = implementation.getEyePosition(image);
-    // if (positions.getEyePosition() != null) {
-    deviationScanner.addEyePosition(positions.getEyePosition());
-     int deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
+  private void processImage(Image image) {
+    FaceAndEyePosition positions = implementation.getEyePosition(image);
+    EyePosition eye = positions.getEyePosition();
+    deviationScanner.addEyePosition(eye.getX(),eye.getY());
+    Rectangle2D face = positions.getFacePosition();
+    int deviation = deviationScanner.scanForDeviation(face);// positions.getEyePosition().getDeviation(lastPositions.getEyePosition());
     if (deviation != DeviationScanner.NONE) {
       System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation));
     if (deviation != DeviationScanner.NONE) {
       System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation));
-      // notifyEyeMovementListenerEyeMoved(deviation);
     }
     }
-    // }
-    lastPositions = positions;
   }
 
 }
   }
 
 }
index 8e49e948aefabd9c68187fec1113977cd1abccb0..19f74024d9b59e8fc4ab57f6d0bf33b3e56c172b 100644 (file)
@@ -61,9 +61,24 @@ public class SSJAVA {
   static void append(Object array[], Object item) {
     for (int i = 1; i < array.length; i++) {
       array[i - 1] = array[i];
   static void append(Object array[], Object item) {
     for (int i = 1; i < array.length; i++) {
       array[i - 1] = array[i];
-      array[i]=null;
+      array[i] = null;
     }
     array[array.length - 1] = item;
   }
     }
     array[array.length - 1] = item;
   }
+  
+  static void append(int array[], int item) {
+    for (int i = 1; i < array.length; i++) {
+      array[i - 1] = array[i];
+      array[i] = 0;
+    }
+    array[array.length - 1] = item;
+  }
+
+
+  static void arrayinit(Object array[]) {
+    for (int i = 1; i < array.length; i++) {
+      array[i] = null;
+    }
+  }
 
 }
 
 }
index 0fe1de15fccce172eed9d06d78ced50252d03dfc..9d0e25e614c88ed6d7aa348de8c17d750c59caf9 100644 (file)
@@ -66,4 +66,18 @@ public class SSJAVA {
     array[array.length - 1] = item;
   }
 
     array[array.length - 1] = item;
   }
 
+  static void append(int array[], int item) {
+    for (int i = 1; i < array.length; i++) {
+      array[i - 1] = array[i];
+      array[i] = 0;
+    }
+    array[array.length - 1] = item;
+  }
+
+  static void arrayinit(Object array[]) {
+    for (int i = 1; i < array.length; i++) {
+      array[i] = null;
+    }
+  }
+
 }
 }
index e2b6d7e49bbbe87d1c8c4b641676104f7e808e0a..fa0365895b72da616c20afde01fe22c9b25d06e0 100644 (file)
@@ -321,7 +321,7 @@ public class String {
       length = length + 1;
     } while (tmp != 0);
 
       length = length + 1;
     } while (tmp != 0);
 
-    char chararray[];
+    char[] chararray;
     if (x < 0)
       chararray = new char[length + 1];
     else
     if (x < 0)
       chararray = new char[length + 1];
     else