public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: tthomas@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Implement decrement, increment; arithmetic minus, plus operations.
Date: Tue, 18 Mar 2008 21:50:00 -0000	[thread overview]
Message-ID: <20080318215030.8962.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  7821ab11bdda699d0fc127060371de639968e157 (commit)
      from  60b3e338ecd23f9bf5a2f67a7d7c177f90c640ba (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 7821ab11bdda699d0fc127060371de639968e157
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Tue Mar 18 17:33:19 2008 -0400

    Implement decrement, increment; arithmetic minus, plus operations.
    
    frysk-core/frysk/expr/ChangeLog:
    2008-03-18  Teresa Thomas  <tthomas@redhat.com>
    
    	* CExpr.g (ARITHMETIC_PLUS): New
    	(ARITHMETIC_MINUS): New
    	(PREINCREMENT, PREDECREMENT): New
    	(POSTINCREMENT, POSTDECREMENT): New
    	* CExprEvaluator.g: Implement above ops.
    	* TestArithmetics.java (testAdd): Add tests.
    	* TestbedSymTab.java (kappa): New.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/expr/CExpr.g              |   34 ++++++++++++++++-------
 frysk-core/frysk/expr/CExprEvaluator.g     |   41 ++++++++++++++++++++++++++++
 frysk-core/frysk/expr/ChangeLog            |   10 +++++++
 frysk-core/frysk/expr/TestArithmetics.java |   12 +++++++-
 frysk-core/frysk/expr/TestbedSymTab.java   |    4 ++-
 5 files changed, 89 insertions(+), 12 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/expr/CExpr.g b/frysk-core/frysk/expr/CExpr.g
index 6681f0a..dd58ef3 100644
--- a/frysk-core/frysk/expr/CExpr.g
+++ b/frysk-core/frysk/expr/CExpr.g
@@ -116,6 +116,12 @@ imaginaryTokenDefinitions
 	SIZEOF
 	INDEX
 	SLICE
+	ARITHMETIC_PLUS
+	ARITHMETIC_MINUS
+	PREINCREMENT
+	PREDECREMENT
+	POSTINCREMENT
+	POSTDECREMENT	
     ;
 
 /** 
@@ -130,7 +136,7 @@ start
   *  This rule looks for comma separated expressions.
   */
 expressionList
-    :   (PLUS!)? expression (COMMA! expression)*
+    :   expression (COMMA! expression)*
         {#expressionList = #(#[EXPR_LIST,"Expr list"], expressionList);}
         ;
 
@@ -280,12 +286,20 @@ prefix_expression
         { ## = #(#[SIZEOF, "Size_Of"], #expr); 
         }
         //sizeof (type)
-    |   PLUSPLUS^ prefix_expression
-    |   MINUSMINUS^ prefix_expression
+    |   PLUSPLUS^ pp_expr: prefix_expression 
+        { ## = #([PREINCREMENT, "Preincrement"], #pp_expr);    
+        }
+    |   MINUSMINUS^ mm_expr: prefix_expression
+        { ## = #([PREDECREMENT, "Preincrement"], #mm_expr);    
+        }    
     |   TILDE^ prefix_expression 
     |   NOT^ prefix_expression   
-    |   MINUS^ prefix_expression       
-    |   PLUS^ prefix_expression
+    |   MINUS^ n_expr: prefix_expression
+        { ## = #([ARITHMETIC_MINUS, "Arithmetic_minus"], #n_expr);    
+        }          
+    |   PLUS^ p_expr: prefix_expression 
+        { ## = #([ARITHMETIC_PLUS, "Arithmetic_plus"], #p_expr);    
+        }
     |   AMPERSAND addr_expr: prefix_expression
         { ## = #([ADDRESS_OF, "Address_Of"], #addr_expr);    
         }         
@@ -328,12 +342,12 @@ postfix_expression!
 	   )    
          | LPAREN! expressionList RPAREN!  
    	 | PLUSPLUS  
-   	       { astPostExpr = #(PLUSPLUS, #astPostExpr); 
-   	       }
+   	   { astPostExpr = #(#[POSTINCREMENT, "Postincrement"], #astPostExpr); 
+   	   }
    	 | MINUSMINUS
-   	       { astPostExpr = #(MINUSMINUS, #astPostExpr); 
-   	       }
-   	    )*
+   	   { astPostExpr = #(#[POSTDECREMENT, "Postdecrement"], #astPostExpr); 
+   	   }
+   	   )*
    	 )      
     { ## = #astPostExpr; }       
     ;           
diff --git a/frysk-core/frysk/expr/CExprEvaluator.g b/frysk-core/frysk/expr/CExprEvaluator.g
index 7285f90..24f6f08 100644
--- a/frysk-core/frysk/expr/CExprEvaluator.g
+++ b/frysk-core/frysk/expr/CExprEvaluator.g
@@ -279,6 +279,47 @@ expr returns [Value returnVar=null]
             returnVar = v1.getType().getALU(exprSymTab.getWordSize())
                         .bitWiseComplement(v1); 
         }
+    |   #(ARITHMETIC_PLUS  v1=expr) {
+            returnVar = v1; 
+        }    
+    |   #(ARITHMETIC_MINUS  v1=expr) {
+            Value zero = longType.createValue(0);
+            returnVar = v1.getType().getALU(zero.getType(), 
+                        exprSymTab.getWordSize())
+                        .subtract(zero, v1); 
+        }              
+    |   #(PREINCREMENT  v1=expr) {
+            Value one = longType.createValue(1);
+            v1.assign(v1.getType().getALU(one.getType(), 
+                      exprSymTab.getWordSize())
+                     .add(one, v1)); 
+            returnVar = v1; 
+        }       
+    |   #(PREDECREMENT  v1=expr) {
+            Value one = longType.createValue(1);
+            v1.assign(v1.getType().getALU(one.getType(), 
+                      exprSymTab.getWordSize())
+                     .subtract(v1, one)); 
+            returnVar = v1;     
+        }   
+    |   #(POSTINCREMENT  v1=expr) {
+            Value one = longType.createValue(1);
+            v1.assign(v1.getType().getALU(one.getType(), 
+                      exprSymTab.getWordSize())
+                      .add(one, v1)); 
+            returnVar = (v1.getType().getALU(one.getType(), 
+                         exprSymTab.getWordSize())
+                        .subtract(v1, one));                      
+        }       
+    |   #(POSTDECREMENT  v1=expr) {
+            Value one = longType.createValue(1);            
+            v1.assign(v1.getType().getALU(one.getType(), 
+                      exprSymTab.getWordSize())
+                     .subtract(v1, one));  
+            returnVar = (v1.getType().getALU(one.getType(), 
+                         exprSymTab.getWordSize())
+                        .add(v1, one));                         
+        }          
     |   #(COND_EXPR  log_expr=expr v1=expr v2=expr) {
             returnVar = ((log_expr.getType().getALU(log_expr.getType(), 
                         exprSymTab.getWordSize())
diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog
index bd4811d..20320ce 100644
--- a/frysk-core/frysk/expr/ChangeLog
+++ b/frysk-core/frysk/expr/ChangeLog
@@ -1,3 +1,13 @@
+2008-03-18  Teresa Thomas  <tthomas@redhat.com>
+
+	* CExpr.g (ARITHMETIC_PLUS): New
+	(ARITHMETIC_MINUS): New 
+	(PREINCREMENT, PREDECREMENT): New
+	(POSTINCREMENT, POSTDECREMENT): New
+	* CExprEvaluator.g: Implement above ops.
+	* TestArithmetics.java (testAdd): Add tests.
+	* TestbedSymTab.java (kappa): New.
+	
 2008-03-11  Teresa Thomas  <tthomas@redhat.com>
 
 	* CExpr.g: Allow +expression.
diff --git a/frysk-core/frysk/expr/TestArithmetics.java b/frysk-core/frysk/expr/TestArithmetics.java
index 7968a76..ad8ed4e 100644
--- a/frysk-core/frysk/expr/TestArithmetics.java
+++ b/frysk-core/frysk/expr/TestArithmetics.java
@@ -54,6 +54,8 @@ public class TestArithmetics extends TestCase {
     }
     public void testAdd() {
 	checkScratchExpr("1 + 2", 3);
+	checkScratchExpr("+1 + +3*2", 7);
+	checkScratchExpr("+1 + (-3)*2", -5);
     }
 
     private void checkVariableExpr(String expr, long value) {
@@ -64,7 +66,15 @@ public class TestArithmetics extends TestCase {
     public void testMember() {
 	checkVariableExpr("a.alpha", 0x01020304);
     }
-
+    
+    public void testIncrement() {
+	checkVariableExpr("a.kappa++ + ++a.kappa", 4); 
+    }
+    
+    public void testDecrement() {
+	checkVariableExpr("a.kappa-- + --a.kappa", 0); 
+    }
+    
     private void checkErrorExpr(String input, String error) {
 	Throwable t = null;
 	try {
diff --git a/frysk-core/frysk/expr/TestbedSymTab.java b/frysk-core/frysk/expr/TestbedSymTab.java
index 88c1994..556c653 100644
--- a/frysk-core/frysk/expr/TestbedSymTab.java
+++ b/frysk-core/frysk/expr/TestbedSymTab.java
@@ -63,12 +63,14 @@ class TestbedSymTab implements ExprSymTab {
 	.addMember("alpha", scratchSourceLocation, StandardTypes.INT32B_T, 0, null)
 	.addMember("beta", scratchSourceLocation, StandardTypes.INT32B_T, 4, null)
 	.addMember("gamma", scratchSourceLocation, StandardTypes.INT16B_T, 8, null)
+	.addMember("kappa", scratchSourceLocation, StandardTypes.INT32B_T, 12, null)	
 	.addBitFieldMember("iota", scratchSourceLocation, StandardTypes.INT32B_T, 8, null, 16, 8) // 0x0000ff00
 	.addBitFieldMember("epsilon", scratchSourceLocation, StandardTypes.INT32B_T, 8, null, 24, 8); // 0x000000ff
     private byte[] buf = {
 	0x01, 0x02, 0x03, 0x04, // alpha
 	0x05, 0x06, 0x07, 0x08, // beta
-	0x09, 0x10, 0x11, 0x12  // gama, iota, epsilon
+	0x09, 0x10, 0x11, 0x12, // gama, iota, epsilon
+	0x00, 0x00, 0x00, 0x01  // kappa
     };
     private Value c1 = new Value(classType, new ScratchLocation(buf));
 


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-03-18 21:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080318215030.8962.qmail@sourceware.org \
    --to=tthomas@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).