svn commit: r15052 - branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2008-06-23 08:28:11-0700
New Revision: 15052

Modified:
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ContextApplicable.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
   branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java

Log:
working on the ocl interpreter

Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ContextApplicable.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ContextApplicable.java?view=diff&rev=15052&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ContextApplicable.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ContextApplicable.java&r1=15051&r2=15052
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ContextApplicable.java	(original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/ContextApplicable.java	2008-06-23 08:28:11-0700
@@ -32,6 +32,8 @@
 
 import tudresden.ocl.parser.analysis.DepthFirstAdapter;
 import tudresden.ocl.parser.node.AClassifierContext;
+import tudresden.ocl.parser.node.APostStereotype;
+import tudresden.ocl.parser.node.APreStereotype;
 
 /**
  * Checks the context clause of the OCL expression to verify if it
@@ -86,5 +88,23 @@
 
     }
     
+    /**
+     * @param node
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#inAPreStereotype(tudresden.ocl.parser.node.APreStereotype)
+     */
+    public void inAPreStereotype(APreStereotype node)
+    {
+        applicable = false;
+    }
+    
+
+    /**
+     * @param node
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#inAPostStereotype(tudresden.ocl.parser.node.APostStereotype)
+     */
+    public void inAPostStereotype(APostStereotype node)
+    {
+        applicable = false;
+    }
     
 }

Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java?view=diff&rev=15052&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&r1=15051&r2=15052
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java	(original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java	2008-06-23 08:28:11-0700
@@ -25,9 +25,21 @@
 package org.argouml.profile.internal.ocl;
 
 import java.util.HashMap;
+import java.util.Stack;
+
+import org.apache.log4j.Logger;
 
 import tudresden.ocl.parser.analysis.DepthFirstAdapter;
-import tudresden.ocl.parser.node.Start;
+import tudresden.ocl.parser.node.AAdditiveExpression;
+import tudresden.ocl.parser.node.AConstraintBody;
+import tudresden.ocl.parser.node.AExpression;
+import tudresden.ocl.parser.node.AIfExpression;
+import tudresden.ocl.parser.node.ALogicalExpression;
+import tudresden.ocl.parser.node.ARelationalExpression;
+import tudresden.ocl.parser.node.Node;
+import tudresden.ocl.parser.node.PAdditiveExpressionTail;
+import tudresden.ocl.parser.node.PLetExpression;
+import tudresden.ocl.parser.node.PLogicalExpressionTail;
 
 /**
  * Evaluates the OCL invariant 
@@ -36,7 +48,13 @@
  */
 public class EvaluateInvariant extends DepthFirstAdapter {
 
+    /**
+     * Logger.
+     */
+    private static final Logger LOG = Logger.getLogger(EvaluateInvariant.class);
+    
     private boolean ok = true;
+    private Stack<Object> st = new Stack<Object>();
     private HashMap<String, Object> vt = new HashMap<String,Object>();
     private Object currentValue = null;
     
@@ -55,9 +73,150 @@
     public boolean isOK() {
         return ok;
     }
+  
+    /**
+     * @param node
+     * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAConstraintBody(tudresden.ocl.parser.node.AConstraintBody)
+     */
+    public void caseAConstraintBody(AConstraintBody node)
+    {
+        inAConstraintBody(node);
+        if(node.getStereotype() != null)
+        {
+            node.getStereotype().apply(this);
+        }
+        if(node.getName() != null)
+        {
+            node.getName().apply(this);
+        }
+        if(node.getColon() != null)
+        {
+            node.getColon().apply(this);
+        }
+        if(node.getExpression() != null)
+        {            
+            st.removeAllElements();
+            node.getExpression().apply(this);
+            Object top = st.pop();
+            if (top instanceof Boolean) {
+                ok = (Boolean)top;
+            } else {
+                LOG.debug("Invariant does not evaluate to a Boolean! st = "
+                        + st);                
+                ok = false;
+            }
+        }
+        outAConstraintBody(node);
+    }    
+
+    public void caseAIfExpression(AIfExpression node)
+    {            
+        inAIfExpression(node);
+        if(node.getTIf() != null)
+        {
+            node.getTIf().apply(this);
+        }
+        if(node.getIfBranch() != null)
+        {
+            node.getIfBranch().apply(this);
+        }        
 
-    public void outStart(Start node) {
+        boolean iftest = (Boolean)st.pop();
         
+        if(node.getTThen() != null)
+        {
+            node.getTThen().apply(this);
+        }
+        if(node.getThenBranch() != null)
+        {
+            node.getThenBranch().apply(this);
+            if (!iftest) // if "if" wasn't ok, forget if
+                st.pop();
+        }
+        if(node.getTElse() != null)
+        {
+            node.getTElse().apply(this);
+        }
+        if(node.getElseBranch() != null)
+        {
+            node.getElseBranch().apply(this);
+            if (iftest) // if "if" was ok, forget else
+                st.pop();
+        }
+        if(node.getEndif() != null)
+        {
+            node.getEndif().apply(this);
+        }
+        outAIfExpression(node);
+    }
+    
+    public void caseAExpression(AExpression node)
+    {
+        inAExpression(node);
+        {
+            Object temp[] = node.getLetExpression().toArray();
+            for(int i = 0; i < temp.length; i++)
+            {
+                ((PLetExpression) temp[i]).apply(this);
+            }
+        }
+        if(node.getLogicalExpression() != null)
+        {
+            node.getLogicalExpression().apply(this);
+        }
+        outAExpression(node);
+    }
+    
+    public void caseALogicalExpression(ALogicalExpression node)
+    {
+        inALogicalExpression(node);
+        if(node.getRelationalExpression() != null)
+        {
+            node.getRelationalExpression().apply(this);
+        }
+        {
+            Object temp[] = node.getLogicalExpressionTail().toArray();
+            for(int i = 0; i < temp.length; i++)
+            {
+                ((PLogicalExpressionTail) temp[i]).apply(this);
+            }
+        }
+        outALogicalExpression(node);
+    }
+    
+    public void caseARelationalExpression(ARelationalExpression node)
+    {
+        inARelationalExpression(node);
+        if(node.getAdditiveExpression() != null)
+        {
+            node.getAdditiveExpression().apply(this);
+        }
+        if(node.getRelationalExpressionTail() != null)
+        {
+            node.getRelationalExpressionTail().apply(this);
+        }
+        outARelationalExpression(node);
+    }
+    
+    public void caseAAdditiveExpression(AAdditiveExpression node)
+    {
+        inAAdditiveExpression(node);
+        if(node.getMultiplicativeExpression() != null)
+        {
+            node.getMultiplicativeExpression().apply(this);
+        }
+        {
+            Object temp[] = node.getAdditiveExpressionTail().toArray();
+            for(int i = 0; i < temp.length; i++)
+            {
+                ((PAdditiveExpressionTail) temp[i]).apply(this);
+            }
+        }
+        outAAdditiveExpression(node);
+    }
+    
+    public void defaultIn(Node node)
+    {
+        LOG.debug("Entering: " + node.getClass() + "\n VALUE: " + node);
     }
-
 }

Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java?view=diff&rev=15052&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&r1=15051&r2=15052
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java	(original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java	2008-06-23 08:28:11-0700
@@ -30,7 +30,6 @@
 
 import org.apache.log4j.Logger;
 
-import sun.org.mozilla.javascript.internal.EvaluatorException;
 import tudresden.ocl.parser.OclParser;
 import tudresden.ocl.parser.lexer.Lexer;
 import tudresden.ocl.parser.node.Start;
@@ -46,7 +45,7 @@
     /**
      * Logger.
      */
-    private static final Logger LOG = Logger.getLogger(CrOCL.class);
+    private static final Logger LOG = Logger.getLogger(OclInterpreter.class);
 
     /**
      * Parser OCL tree
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.