This is the mail archive of the frysk-cvs@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[SCM] master: Add type walker to determine expression type w/o expression evaluation.


The branch, master has been updated
       via  e1ebce24e45ed9778fa430444318ec8f92de1f5e (commit)
       via  5138ba73250295a77b1d6f666efe041b538b9226 (commit)
       via  93d1d6d7d44a4327226790d11e9d09f84d87b5af (commit)
      from  6b4ece3ca0b83c39da674d765d8a30bf773bebb4 (commit)

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

- Log -----------------------------------------------------------------
commit e1ebce24e45ed9778fa430444318ec8f92de1f5e
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Mon Mar 31 17:09:42 2008 -0400

    Add type walker to determine expression type w/o expression evaluation.
    
    frysk-core/frysk/expr/ChangeLog:
    2008-03-31  Teresa Thomas  <tthomas@redhat.com>
    
    	* CTypeEvaluator.g: New file.
    	* Expression.java (getType): Use CTypeEvaluator.
    	* TestArithmetics.java (testTypes): New.

commit 5138ba73250295a77b1d6f666efe041b538b9226
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Mon Mar 31 16:52:47 2008 -0400

    Add getMemberType, getSliceType to Type system.
    
    frysk-core/frysk/value/ChangeLog:
    2008-03-31  Teresa Thomas  <tthomas@redhat.com>
    
    	* CompositeType.java (getMemberType): New.
    	* ArrayType.java (getSliceType): New.
    	* PointerType.java (getSliceType): New.
    	* Type.java (getSliceType): New.
    	(getType): New.

commit 93d1d6d7d44a4327226790d11e9d09f84d87b5af
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Mon Mar 31 16:47:26 2008 -0400

    Add getter methods for expression result type.
    
    frysk-core/frysk/value/ChangeLog:
    2008-03-31  Teresa Thomas  <tthomas@redhat.com>
    
    	* ArithmeticUnit.java (getResultType): New.
    	(getIntResultType): New.
    	* IntegerUnit.java (IntegerUnit): Remove
    	irrelevant comment.

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

Summary of changes:
 frysk-core/frysk/expr/CTypeEvaluator.g     |  287 ++++++++++++++++++++++++++++
 frysk-core/frysk/expr/ChangeLog            |    6 +
 frysk-core/frysk/expr/Expression.java      |    8 +-
 frysk-core/frysk/expr/TestArithmetics.java |   13 ++
 frysk-core/frysk/value/ArithmeticUnit.java |   15 ++
 frysk-core/frysk/value/ArrayType.java      |    6 +
 frysk-core/frysk/value/ChangeLog           |   13 ++
 frysk-core/frysk/value/CompositeType.java  |   10 +-
 frysk-core/frysk/value/IntegerUnit.java    |    1 -
 frysk-core/frysk/value/PointerType.java    |    8 +-
 frysk-core/frysk/value/Type.java           |   14 ++
 11 files changed, 373 insertions(+), 8 deletions(-)
 create mode 100644 frysk-core/frysk/expr/CTypeEvaluator.g

First 500 lines of diff:
diff --git a/frysk-core/frysk/expr/CTypeEvaluator.g b/frysk-core/frysk/expr/CTypeEvaluator.g
new file mode 100644
index 0000000..dd2a91d
--- /dev/null
+++ b/frysk-core/frysk/expr/CTypeEvaluator.g
@@ -0,0 +1,287 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008 Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+
+header
+{
+// This file is part of the program FRYSK.
+//
+// Copyright 2008 Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+    package frysk.expr;
+
+    import frysk.value.ArithmeticType;
+    import frysk.value.SignedType;
+    import frysk.value.PointerType;
+    import frysk.value.CharType;
+    import frysk.value.ArrayType;
+    import frysk.value.FloatingPointType;
+    import frysk.value.CompositeType;
+    import frysk.value.Value;
+    import frysk.value.Type;
+    import frysk.expr.ExprSymTab;
+    import inua.eio.ByteOrder;
+}
+
+class CTypeEvaluator extends TreeParser;
+
+
+options {
+    importVocab=CExprParser;
+}
+
+{
+    ArithmeticType longType;
+    ArithmeticType intType;
+    ArithmeticType shortType;
+    FloatingPointType doubleType;
+    FloatingPointType floatType;
+    CharType charType;
+    PointerType charPointerType;
+    private ExprSymTab exprSymTab;
+
+    public CTypeEvaluator(ExprSymTab symTab) {
+	    exprSymTab = symTab;
+        shortType = new SignedType("short", ByteOrder.LITTLE_ENDIAN, 2);
+        intType = new SignedType("int", ByteOrder.LITTLE_ENDIAN, 4);
+        longType = new SignedType("long", ByteOrder.LITTLE_ENDIAN, exprSymTab.getWordSize());
+        floatType = new FloatingPointType("float", ByteOrder.LITTLE_ENDIAN, 4);
+        doubleType = new FloatingPointType("double", ByteOrder.LITTLE_ENDIAN, 8);
+        charType = new CharType("char", ByteOrder.LITTLE_ENDIAN, 1, true);
+        charPointerType = new PointerType("char*", ByteOrder.LITTLE_ENDIAN, 
+                                          exprSymTab.getWordSize(), charType);
+    }
+}
+
+primitiveType
+    :   "boolean"
+    |   "char"
+    |   "byte"
+    |   "short"
+    |   "int"
+    |   "long"
+    |   "float"
+    |   "double"
+    ;
+        
+typeCast
+    :   primitiveType (STAR)?
+    ;        
+
+identifier returns [String idSpelling=null]
+    :   ident:IDENT  {idSpelling=ident.getText();} ;
+
+expr returns [Type returnVar=null] 
+{ Type t1, t2; String s1;}
+
+    :   (   #(PLUS t1=expr t2=expr)
+          | #(MINUS t1=expr t2=expr)
+          | #(STAR t1=expr t2=expr)
+          | #(DIVIDE t1=expr t2=expr)
+          | #(MOD t1=expr t2=expr)
+        ) {	
+             returnVar = t1.getALU(t2,
+                         exprSymTab.getWordSize())
+                         .getResultType();  
+        }
+    |   (   #(SHIFTLEFT  t1=expr t2=expr) 
+          | #(SHIFTRIGHT  t1=expr t2=expr)
+          | #(AMPERSAND  t1=expr t2=expr)
+          | #(BITWISEXOR  t1=expr t2=expr)
+          | #(BITWISEOR  t1=expr t2=expr)
+        ) {
+             returnVar = t1.getALU(t2, 
+                         exprSymTab.getWordSize())
+                         .getResultType();  
+        }
+    |   (   #(AND  t1=expr t2=expr) 
+          | #(OR  t1=expr t2=expr)   
+          | #(NOT  t1=expr )
+        ) {
+            returnVar = t1.getALU(exprSymTab.getWordSize())
+                        .getIntResultType(); 
+        }
+    |   (   #(LESSTHAN  t1=expr t2=expr) 
+          | #(GREATERTHAN  t1=expr t2=expr)
+          | #(LESSTHANOREQUALTO  t1=expr t2=expr)
+          | #(GREATERTHANOREQUALTO  t1=expr t2=expr)
+          | #(EQUAL  t1=expr t2=expr)
+          | #(NOTEQUAL  t1=expr t2=expr)
+        ) {
+             returnVar = t1.getALU(t2, 
+                         exprSymTab.getWordSize())
+                         .getIntResultType();  
+        }
+   |    #(ADDRESS_OF t1=expr ) {
+            PointerType pointerType = new PointerType
+                                         ("*", ByteOrder.LITTLE_ENDIAN, 
+                                          exprSymTab.getWordSize(), t1);
+            returnVar = pointerType;
+        }
+    |   #(MEMORY t1=expr ) {
+            returnVar = ((PointerType)t1).getType();
+        } 
+    |   (   #(TILDE t1=expr) 
+          | #(ARITHMETIC_PLUS  t1=expr)
+          | #(ARITHMETIC_MINUS  t1=expr)
+          | #(MINUS t1=expr )
+        ) {
+            returnVar = t1;
+        }
+    |   (   #(PREINCREMENT t1=expr)  
+          | #(PREDECREMENT  t1=expr)
+          | #(POSTINCREMENT  t1=expr)
+          | #(POSTDECREMENT  t1=expr) 
+        ) {
+            returnVar = t1; 
+        }
+    |   #(COND_EXPR expr t1=expr t2=expr) {
+            // FIXME: Is this a good enough estimate of result
+            // type without actually evaluating conditional
+            // expressions?
+            returnVar = (t1.getSize()> t2.getSize())? t1:t2;
+        }
+    |   OCTALINT  {
+            returnVar = longType;
+        }
+    |   DECIMALINT  {
+            returnVar = longType;
+        }
+    |   HEXADECIMALINT  {
+            returnVar = longType;
+        }
+    |   FLOAT  {
+            returnVar = floatType;
+        }
+    |   DOUBLE  {
+            returnVar = doubleType;
+        }
+    |   (   #(ASSIGNEQUAL t1=expr t2=expr) 
+          | #(PLUSEQUAL t1=expr t2=expr)
+          | #(MINUSEQUAL t1=expr t2=expr)
+          | #(TIMESEQUAL t1=expr t2=expr)
+          | #(DIVIDEEQUAL t1=expr t2=expr)
+          | #(MODEQUAL t1=expr t2=expr)
+          | #(SHIFTLEFTEQUAL t1=expr t2=expr) 
+          | #(SHIFTRIGHTEQUAL t1=expr t2=expr) 
+          | #(BITWISEANDEQUAL t1=expr t2=expr) 
+          | #(BITWISEXOREQUAL t1=expr t2=expr) 
+          | #(BITWISEOREQUAL t1=expr t2=expr) 
+        ) {
+            returnVar = t1;
+        }
+    |   #(CAST pt:typeCast t2=expr) { 	
+  	      if(pt.getText().compareTo("long") == 0) {
+	        returnVar = longType;
+	      }
+	      else if(pt.getText().compareTo("int") == 0) {
+	         returnVar = intType;
+	      }
+	      else if(pt.getText().compareTo("short") == 0) {
+  	         returnVar = shortType;
+	      }
+	      else if(pt.getText().compareTo("double") == 0) {
+	         returnVar = doubleType;
+	      }
+	      else if(pt.getText().compareTo("float") == 0) {
+  	         returnVar = floatType;
+	      }
+	      // XXX: Implement casts for other pointer types as well
+	      else if(t2.getName().compareTo("*") ==  0) {
+	        if (pt.getText().compareTo("char") == 0) {	  
+	          returnVar = charPointerType;
+	        }
+          }
+        }
+    |   #(EXPR_LIST t1=expr) {
+            returnVar = t1;
+        }  
+    |   #(SIZEOF t1=expr) {
+           returnVar = longType; 
+        }    
+    |   #(INDEX t1=expr t2=expr) {
+            returnVar = t1.getType();
+        }  
+    |   #(SLICE t1=expr t2=expr expr) {
+            returnVar = t1.getSliceType();
+        }
+    |   #(MEMBER t1=expr s1=identifier) {
+            returnVar = ((CompositeType)t1).getMemberType(s1);
+        } 
+    |   ident:IDENT  {
+            returnVar = ((Type)exprSymTab.getValue(ident.getText()).getType());
+        }
+    |   tident:TAB_IDENT  {
+            returnVar = ((Type)exprSymTab.getValue(tident.getText()).getType());
+        }
+    ;
diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog
index c600ad9..66b4dcc 100644
--- a/frysk-core/frysk/expr/ChangeLog
+++ b/frysk-core/frysk/expr/ChangeLog
@@ -1,3 +1,9 @@
+2008-03-31  Teresa Thomas  <tthomas@redhat.com>
+
+	* CTypeEvaluator.g: New file.
+	* Expression.java (getType): Use CTypeEvaluator.
+	* TestArithmetics.java (testTypes): New.
+		
 2008-03-18  Andrew Cagney  <cagney@redhat.com>
 
 	* TestCompletion.java (testCompleteStructMember()): Add "kappa" to
diff --git a/frysk-core/frysk/expr/Expression.java b/frysk-core/frysk/expr/Expression.java
index 1196026..9432417 100644
--- a/frysk-core/frysk/expr/Expression.java
+++ b/frysk-core/frysk/expr/Expression.java
@@ -80,9 +80,11 @@ public class Expression {
      * Determine the expressions result type.
      */
     public Type getType() {
-	// XXX: Fixme; should be walking the tree, not evaluating the
-	// expresision.
-	return getValue().getType();
+	try {
+	    return new CTypeEvaluator(symTab).expr(ast);
+	} catch (antlr.RecognitionException r) {    
+	    throw new RuntimeException(r);
+	}  
     }
 
     /**
diff --git a/frysk-core/frysk/expr/TestArithmetics.java b/frysk-core/frysk/expr/TestArithmetics.java
index ad8ed4e..f537eaa 100644
--- a/frysk-core/frysk/expr/TestArithmetics.java
+++ b/frysk-core/frysk/expr/TestArithmetics.java
@@ -95,4 +95,17 @@ public class TestArithmetics extends TestCase {
     public void testTokenError() {
 	checkErrorExpr("1...2", "unexpected input: expecting '.', found '2'");
     }
+    
+    // Testing types
+    private void checkExprType (String expr, String resultType){
+	ExprSymTab symTab = new TestbedSymTab();
+	Expression e = ExpressionFactory.parse(symTab, expr);
+	assertEquals(expr, resultType, e.getType().getName());
+    }
+
+    public void testTypes() {
+	checkExprType("++a.kappa", "int32b_t");
+	checkExprType("a.alpha", "int32b_t");
+	checkExprType("a.alpha/1.0", "double");
+    }
 }
diff --git a/frysk-core/frysk/value/ArithmeticUnit.java b/frysk-core/frysk/value/ArithmeticUnit.java
index 897fd9a..b3ec914 100644
--- a/frysk-core/frysk/value/ArithmeticUnit.java
+++ b/frysk-core/frysk/value/ArithmeticUnit.java
@@ -68,6 +68,21 @@ public abstract class ArithmeticUnit
 	this.wordSize = wordSize;
     }
     
+    /**
+     * Use to get result type of multiplicative, additive,
+     * shift, bitwise and assigment expressions.
+     */
+    public ArithmeticType getResultType() {
+	return retType;
+    }
+    /**
+     * Use to get result type of relational, equality
+     * and logical expressions.
+     */
+    public ArithmeticType getIntResultType() {
+	return intType;
+    }
+    
     // Multiplicative and Additive expressions
     public Value add(Value v1, Value v2) {
 	throw new InvalidOperatorException
diff --git a/frysk-core/frysk/value/ArrayType.java b/frysk-core/frysk/value/ArrayType.java
index afdec44..6865556 100644
--- a/frysk-core/frysk/value/ArrayType.java
+++ b/frysk-core/frysk/value/ArrayType.java
@@ -196,6 +196,12 @@ public class ArrayType
         
     }
     
+    public Type getSliceType() {
+	ArrayList dims = new ArrayList();
+	dims.add(new Integer(-1));
+	return new ArrayType(type, 0, dims);
+    }    
+    
     /**
      * Dereference operation on array type.
      */
diff --git a/frysk-core/frysk/value/ChangeLog b/frysk-core/frysk/value/ChangeLog
index 1c12e22..16d0ca2 100644
--- a/frysk-core/frysk/value/ChangeLog
+++ b/frysk-core/frysk/value/ChangeLog
@@ -1,3 +1,16 @@
+2008-03-31  Teresa Thomas  <tthomas@redhat.com>
+
+	* CompositeType.java (getMemberType): New.
+	* ArrayType.java (getSliceType): New.
+	* PointerType.java (getSliceType): New.
+	* Type.java (getSliceType): New.
+	(getType): New.
+	
+	* ArithmeticUnit.java (getResultType): New.
+	(getIntResultType): New.
+	* IntegerUnit.java (IntegerUnit): Remove 
+	irrelevant comment.
+
 2008-03-15  Andrew Cagney  <cagney@redhat.com>
 
 	* Variable.java: Update; TypeEntry -> TypeFactory.
diff --git a/frysk-core/frysk/value/CompositeType.java b/frysk-core/frysk/value/CompositeType.java
index fd6f325..a3fcd28 100644
--- a/frysk-core/frysk/value/CompositeType.java
+++ b/frysk-core/frysk/value/CompositeType.java
@@ -395,14 +395,18 @@ public abstract class CompositeType
 	stringBuilderParm.insert(0, stringBuilder);
     }
     
-    public Value member(Value var1, String member)
-    {
+    public Value member(Value var1, String member) {
 	DynamicMember mem = (DynamicMember)nameToMember.get(member);
 	if (mem == null)
 	    throw new RuntimeException("Invalid data member: " + member);
 	return mem.getValue (var1);
     }
-
+    
+    public Type getMemberType(String member) {
+	DynamicMember mem = (DynamicMember)nameToMember.get(member);
+	return mem.type;
+    }
+    
     public boolean completeMember(String incomplete, List candidates) {
 	int completions = 0;
 	for (Iterator i = nameToMember.keySet().iterator(); i.hasNext(); ) {
diff --git a/frysk-core/frysk/value/IntegerUnit.java b/frysk-core/frysk/value/IntegerUnit.java
index 73f2d2d..66bea73 100644
--- a/frysk-core/frysk/value/IntegerUnit.java
+++ b/frysk-core/frysk/value/IntegerUnit.java
@@ -56,7 +56,6 @@ public class IntegerUnit
     
     public IntegerUnit (IntegerType t1, int wordSize) {
 	super (wordSize);
-	// Return type should be the larger type.
 	retType =  t1 ;
     }    
 
diff --git a/frysk-core/frysk/value/PointerType.java b/frysk-core/frysk/value/PointerType.java
index 84f5b92..88dce56 100644
--- a/frysk-core/frysk/value/PointerType.java
+++ b/frysk-core/frysk/value/PointerType.java
@@ -179,7 +179,13 @@ public class PointerType
 
 	return new Value(resultType, loc);
     }
-
+    
+    public Type getSliceType() {
+	ArrayList dims = new ArrayList();
+	dims.add(new Integer(-1));
+	return new ArrayType(type, 0, dims);
+    }
+    
     /* getALUs are double dispatch functions to determine
      * the ArithmeticUnit for an operation between two types.
      */
diff --git a/frysk-core/frysk/value/Type.java b/frysk-core/frysk/value/Type.java
index dbb3d69..84f01a9 100644
--- a/frysk-core/frysk/value/Type.java
+++ b/frysk-core/frysk/value/Type.java
@@ -186,6 +186,20 @@ public abstract class Type {
     	throw new InvalidOperatorException(this, "slice");	
     }
     
+    /**
+     * Get the type of slice.
+     */
+    public Type getSliceType() {
+	throw new InvalidOperatorException(this, "sliceType");
+    }
+    
+    /**
+     * Return the element type for array or pointer type.
+     */
+    public Type getType () {
+	throw new InvalidOperatorException(this, "getElementType");
+    }
+    
    /**
      * Assign VALUE to LOCATION; possibly performing type-conversion.
      */


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]