From e7368edc54db0eece229e4fcad82b6b354cc44b0 Mon Sep 17 00:00:00 2001
From: Ludovic Apvrille <ludovic.apvrille@telecom-paris.fr>
Date: Thu, 25 Apr 2024 11:32:54 +0200
Subject: [PATCH] Adding test for timer attribute in int expr

---
 .../java/avatartranslator/AvatarError.java    |  7 +-
 .../avatartranslator/AvatarSyntaxChecker.java | 82 ++++++++++++++++++-
 .../avatartranslator/AvatarTransition.java    |  2 +-
 .../AvatarIBSStdParserTest.java               |  6 ++
 ...rIntegerExprParsingAndEvaluationTests.java |  1 +
 5 files changed, 95 insertions(+), 3 deletions(-)

diff --git a/src/main/java/avatartranslator/AvatarError.java b/src/main/java/avatartranslator/AvatarError.java
index c4cc8d85a5..ab7c09fd12 100644
--- a/src/main/java/avatartranslator/AvatarError.java
+++ b/src/main/java/avatartranslator/AvatarError.java
@@ -69,7 +69,12 @@ public class AvatarError {
                     "Invalid attribute in action on signal",
                     "Invalid type in signal definition",
                     "Invalid int expression in action on signal",
-                    /*20*/"Invalid bool expression in action on signal"
+                    /*20*/"Invalid bool expression in action on signal",
+                    "Invalid number of parameters in action",
+                    "Invalid integer value in method call",
+                    "Invalid boolean value in method call",
+                    "Invalid expression in method call",
+                    /*25*/"Invalid type in method call"
             };
 
 
diff --git a/src/main/java/avatartranslator/AvatarSyntaxChecker.java b/src/main/java/avatartranslator/AvatarSyntaxChecker.java
index 0884006619..71530c87ae 100644
--- a/src/main/java/avatartranslator/AvatarSyntaxChecker.java
+++ b/src/main/java/avatartranslator/AvatarSyntaxChecker.java
@@ -529,13 +529,93 @@ public class AvatarSyntaxChecker {
             if (asm != null) {
                 for (AvatarStateMachineElement asme : asm.getListOfElements()) {
                     if (asme instanceof AvatarTransition) {
-                        
+                        for(AvatarAction aa: ((AvatarTransition)(asme)).getActions()) {
+                            AvatarError ae = checkAction(avspec, block, ((AvatarTransition)(asme)), aa);
+                            if (ae != null)
+                                errors.add( ae );
+                        }
                     }
                 }
             }
         }
         return errors;
     }
+    public static AvatarError checkAction(AvatarSpecification avspec, AvatarBlock block, AvatarTransition asme, AvatarAction aa) {
+        if (aa instanceof AvatarTermFunction) {
+            AvatarTermFunction atf = (AvatarTermFunction) aa;
+
+            int size = atf.getMethod().getListOfAttributes().size();
+
+            if (size != atf.getArgs().components.size()) {
+                AvatarError error = new AvatarError(avspec);
+                error.block = block;
+                error.firstAvatarElement = atf;
+                error.error = 21;
+                return error;
+            }
+
+            for(int i=0; i<size; i++) {
+                // Check that each value correspond to the expected type
+                AvatarAttribute param = atf.getMethod().getListOfAttributes().get(i);
+                AvatarTerm term = atf.getArgs().components.get(i);
+
+
+                if (term instanceof AvatarAttribute) {
+                    if ( ((AvatarAttribute)term).getType() != param.getType()) {
+                        AvatarError error = new AvatarError(avspec);
+                        error.block = block;
+                        error.firstAvatarElement = asme;
+                        error.error = 25;
+                        return error;
+                    }
+                } else {
+                    String value = term.toString();
+                    TraceManager.addDev("Value:>" + value + "< of class>" + term.getClass().toString() + "<");
+                    if (param.getType() == AvatarType.INTEGER) {
+                        TraceManager.addDev("Trying to parse int expr: " + value);
+                        AvatarIBSExpressions.IExpr e1 = AvatarIBSolver.parseInt(block, value);
+                        if (e1 == null) {
+                            TraceManager.addDev("Parse error in int expr: " + value);
+                            AvatarError error = new AvatarError(avspec);
+                            error.block = block;
+                            error.firstAvatarElement = asme;
+                            error.error = 22;
+                            return error;
+                        }
+                        TraceManager.addDev("Parse ok in int expr: " + value);
+                    } else if (param.getType() == AvatarType.BOOLEAN) {
+                        IBSExpressions.BExpr e1 = AvatarIBSolver.parseBool(block, value);
+                        if (e1 == null) {
+                            AvatarError error = new AvatarError(avspec);
+                            error.block = block;
+                            error.firstAvatarElement = asme;
+                            error.error = 23;
+                            return error;
+                        }
+                    } else {
+                        AvatarError error = new AvatarError(avspec);
+                        error.block = block;
+                        error.firstAvatarElement = asme;
+                        error.error = 18;
+                        return error;
+                    }
+                }
+
+
+
+
+            }
+        }
+
+        // We assume that this is a variable setting, possibly with a method call
+
+
+
+
+        return null;
+
+    }
+
 
 
     public static int isAValidGuard(AvatarSpecification _as, AvatarStateMachineOwner _ab, String _guard) {
diff --git a/src/main/java/avatartranslator/AvatarTransition.java b/src/main/java/avatartranslator/AvatarTransition.java
index 0d8c3f612a..c1bc9b4aee 100644
--- a/src/main/java/avatartranslator/AvatarTransition.java
+++ b/src/main/java/avatartranslator/AvatarTransition.java
@@ -102,7 +102,7 @@ public class AvatarTransition extends AvatarStateMachineElement {
 
     public AvatarTransition(AvatarStateMachineOwner _block, String _name, Object _referenceObject) {
         super(_name, _referenceObject, _block);
-        actions = new LinkedList<AvatarAction>();
+        actions = new LinkedList<>();
         this.guard = new AvatarGuardEmpty();
         this.block = _block;
         guardSolver = null;
diff --git a/ttool/src/test/java/avatartranslator/AvatarIBSStdParserTest.java b/ttool/src/test/java/avatartranslator/AvatarIBSStdParserTest.java
index a3edd47ab6..2afac7aac6 100644
--- a/ttool/src/test/java/avatartranslator/AvatarIBSStdParserTest.java
+++ b/ttool/src/test/java/avatartranslator/AvatarIBSStdParserTest.java
@@ -81,6 +81,9 @@ public class AvatarIBSStdParserTest {
         block1.addAttribute(a1);
         AvatarAttribute b1 = new AvatarAttribute("key2", AvatarType.BOOLEAN, block1, null);
         block1.addAttribute(b1);
+
+        AvatarAttribute t = new AvatarAttribute("t", AvatarType.TIMER, block1, null);
+        block1.addAttribute(t);
         
         x1.setInitialValue("10");
         y1.setInitialValue("5");
@@ -277,6 +280,9 @@ public class AvatarIBSStdParserTest {
         //assertTrue(e15!=null);
         //TraceManager.addDev("Testing e15 done");
 
+        AvatarIBSExpressions.IExpr e16 = AvatarIBSolver.parseInt(block1,"t+3");
+        assertTrue(e16!=null);
+
 
         assertTrue(e1.eval(specBlock) == 15);
         assertTrue(e2.eval(specBlock));
diff --git a/ttool/src/test/java/avatartranslator/AvatarIntegerExprParsingAndEvaluationTests.java b/ttool/src/test/java/avatartranslator/AvatarIntegerExprParsingAndEvaluationTests.java
index d94a42b4e3..c9e7f0f81f 100644
--- a/ttool/src/test/java/avatartranslator/AvatarIntegerExprParsingAndEvaluationTests.java
+++ b/ttool/src/test/java/avatartranslator/AvatarIntegerExprParsingAndEvaluationTests.java
@@ -142,6 +142,7 @@ public class AvatarIntegerExprParsingAndEvaluationTests {
 
         testExpr("x  = x*((x + y)*z + (x+z)/z)/x", 36, true);
 
+
     }
 
 
-- 
GitLab