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: Change String toPrint() to use StringBuilder.


The branch, master has been updated
       via  18589ae514ca25c5d0b835874bd3427670deff44 (commit)
       via  db7a941d50cd2eb3e71501e81ab2fdc0c3733f4f (commit)
      from  9e8ccab1c41936bc9a9fb1bac879fc07fe75114d (commit)

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

- Log -----------------------------------------------------------------
commit 18589ae514ca25c5d0b835874bd3427670deff44
Author: Stan Cox <scox@redhat.com>
Date:   Tue Dec 11 22:04:29 2007 -0500

    Change String toPrint() to use StringBuilder.
    
    * PointerType.java (toPrint): Detect ptr to array and ptr to function cases.

commit db7a941d50cd2eb3e71501e81ab2fdc0c3733f4f
Author: Stan Cox <scox@redhat.com>
Date:   Tue Dec 11 16:54:57 2007 -0500

    Change String toPrint() to use StringBuilder.
    
    * Type.java (toPrint(StringBuilder, int)): Change signature from Writer
    to StringBuilder.
    Change all callers.
    (String toPrint()): Change to use StringBuilder.
    ArrayType.java (toPrint): Use typeStringBuilder for return type.
    * CompositeType.java (toPrint): Use memberStringBuilder for members.
    * FunctionType.java (toPrint): Use parmStringBuilder for parameters.
    * PointerType.java (toPrint): Detect ptr to array and ptr to function cases.

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

Summary of changes:
 frysk-core/frysk/hpd/ChangeLog                     |    4 +
 frysk-core/frysk/hpd/EvalCommands.java             |    3 +-
 frysk-core/frysk/pkglibdir/ChangeLog               |    5 +
 frysk-core/frysk/pkglibdir/funit-class.cxx         |   54 +++++++-------
 frysk-core/frysk/pkglibdir/gen-type-funit-tests.py |   49 ++++++------
 frysk-core/frysk/value/ArithmeticType.java         |    5 +-
 frysk-core/frysk/value/ArrayType.java              |   19 ++---
 frysk-core/frysk/value/ChangeLog                   |   10 +++
 frysk-core/frysk/value/CompositeType.java          |   65 ++++++----------
 frysk-core/frysk/value/EnumType.java               |   22 +++---
 frysk-core/frysk/value/FunctionType.java           |   28 ++++---
 frysk-core/frysk/value/PointerType.java            |   81 +++++++++++---------
 frysk-core/frysk/value/Type.java                   |   11 ++-
 frysk-core/frysk/value/TypeDecorator.java          |   13 ++--
 frysk-core/frysk/value/TypeDef.java                |    5 +-
 frysk-core/frysk/value/UnknownType.java            |    8 +-
 frysk-core/frysk/value/Variable.java               |    4 +-
 frysk-core/frysk/value/VoidType.java               |    4 +-
 18 files changed, 207 insertions(+), 183 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index c096d29..4e7bb82 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,7 @@
+2007-12-11  Stan Cox  <scox@redhat.com>
+
+	* EvalCommands.java (Printer.TYPE): Change to use "String toPrint()"
+
 2007-12-11  Andrew Cagney  <cagney@redhat.com>
 
 	* MultiLevelCommand.java (interpret(CLI,Input)): Add comment on
diff --git a/frysk-core/frysk/hpd/EvalCommands.java b/frysk-core/frysk/hpd/EvalCommands.java
index d318040..cdf6c9a 100644
--- a/frysk-core/frysk/hpd/EvalCommands.java
+++ b/frysk-core/frysk/hpd/EvalCommands.java
@@ -71,8 +71,7 @@ abstract class EvalCommands extends ParameterizedCommand {
 	static final Printer TYPE = new Printer() {
 		void print(Expression e, PrintWriter writer, Format format,
 			   ByteBuffer memory) {
-		    e.getType().toPrint(writer, 0);
-		    writer.println();
+		    writer.println(e.getType().toPrint());
 		}
 	    };
 	static final Printer TREE = new Printer() {
diff --git a/frysk-core/frysk/pkglibdir/ChangeLog b/frysk-core/frysk/pkglibdir/ChangeLog
index 0c0318f..dbac245 100644
--- a/frysk-core/frysk/pkglibdir/ChangeLog
+++ b/frysk-core/frysk/pkglibdir/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-11  Stan Cox  <scox@redhat.com>
+
+	* funit-class.cxx: Tweak whitespace.
+	* gen-type-funit-tests.py: Tweak whitespace.
+
 2007-12-11 Teresa Thomas <tthomas@redhat.com>
 
 	* funit-addresses.c: Add long double types.
diff --git a/frysk-core/frysk/pkglibdir/funit-class.cxx b/frysk-core/frysk/pkglibdir/funit-class.cxx
index a595b71..01f0b65 100644
--- a/frysk-core/frysk/pkglibdir/funit-class.cxx
+++ b/frysk-core/frysk/pkglibdir/funit-class.cxx
@@ -74,18 +74,18 @@ private:
 // Type: class Type {
 // Type:  public:
 // Type:   struct Base1 {
-// Type:     const char * msg;
-// Type:     void Base1 (const char * );
+// Type:     const char *msg;
+// Type:     void Base1 (const char *);
 // Type:     void ~Base1 ();
 // Type:   } ;
 // Type:   struct Base2 {
-// Type:     const char * msg;
-// Type:     void Base2 (const char * );
+// Type:     const char *msg;
+// Type:     void Base2 (const char *);
 // Type:     void ~Base2 ();
 // Type:   } ;
 // Type:  private:
-// Type:   const char * note;
-// Type:   void Type (const char * ,const char * ,const char * );
+// Type:   const char *note;
+// Type:   void Type (const char *,const char *,const char *);
 // Type:   void ~Type ();
 // Type: }
 
@@ -95,18 +95,18 @@ Type mb("static", "main", "mb");
 // Type: class Type {
 // Type:  public:
 // Type:   struct Base1 {
-// Type:     const char * msg;
-// Type:     void Base1 (const char * );
+// Type:     const char *msg;
+// Type:     void Base1 (const char *);
 // Type:     void ~Base1 ();
 // Type:   } ;
 // Type:   struct Base2 {
-// Type:     const char * msg;
-// Type:     void Base2 (const char * );
+// Type:     const char *msg;
+// Type:     void Base2 (const char *);
 // Type:     void ~Base2 ();
 // Type:   } ;
 // Type:  private:
-// Type:   const char * note;
-// Type:   void Type (const char * ,const char * ,const char * );
+// Type:   const char *note;
+// Type:   void Type (const char *,const char *,const char *);
 // Type:   void ~Type ();
 // Type: }
 
@@ -116,27 +116,27 @@ Type new_base = Type ("new base", "main", "new_base");
 // Type: class Derived {
 // Type:  public:
 // Type:   struct Base3 {
-// Type:     int  () * * _vptr.Base3;
-// Type:     void Base3 (void * const & );
+// Type:     int (**_vptr.Base3) ();
+// Type:     void Base3 (void * const &);
 // Type:     void Base3 ();
-// Type:     char do_this (char );
-// Type:     short int do_this (short int );
-// Type:     int do_this (int );
-// Type:     float do_this (float );
+// Type:     char do_this (char);
+// Type:     short int do_this (short int);
+// Type:     int do_this (int);
+// Type:     float do_this (float);
 // Type:     void ~Base3 ();
 // Type:   } ;
-// Type:   void Derived (void * const & );
+// Type:   void Derived (void * const &);
 // Type:   void Derived ();
-// Type:   char do_this (char );
-// Type:   short int do_this (short int );
-// Type:   int do_this (int );
-// Type:   float do_this (float );
+// Type:   char do_this (char);
+// Type:   short int do_this (short int);
+// Type:   int do_this (int);
+// Type:   float do_this (float);
 // Type:   void ~Derived ();
 // Type:  private:
-// Type:   char do_this_impl<char> (char );
-// Type:   short int do_this_impl<short int> (short int );
-// Type:   int do_this_impl<int> (int );
-// Type:   float do_this_impl<float> (float );
+// Type:   char do_this_impl<char> (char);
+// Type:   short int do_this_impl<short int> (short int);
+// Type:   int do_this_impl<int> (int);
+// Type:   float do_this_impl<float> (float);
 // Type: }
 
 Derived xyz;
diff --git a/frysk-core/frysk/pkglibdir/gen-type-funit-tests.py b/frysk-core/frysk/pkglibdir/gen-type-funit-tests.py
index 1597c5e..e7a845c 100644
--- a/frysk-core/frysk/pkglibdir/gen-type-funit-tests.py
+++ b/frysk-core/frysk/pkglibdir/gen-type-funit-tests.py
@@ -13,7 +13,10 @@ class c:
             var_suffix = "_var"
         else:
             var_suffix = ""
-        self.c_file.write(type + " " + var + var_suffix + type_arr)
+        if (type.endswith("*")):
+            self.c_file.write(type + var + var_suffix + type_arr)
+        else:
+            self.c_file.write(type + " " + var + var_suffix + type_arr)
         self.c_file.write(" unused")
         if initial != "":
             self.write(" = " + initial)
@@ -217,7 +220,7 @@ c_file.add('''struct {
     .float_var=2.802597E-45,
   },
 }}''', " [2]")
-c_file.add("struct {\n  int * ptr;\n}", "arr_struct_ptr", "{{&one},{&two}}", " [2]")
+c_file.add("struct {\n  int *ptr;\n}", "arr_struct_ptr", "{{&one},{&two}}", " [2]")
 c_file.add('''union {
   int arr_int[2];
   float arr_float[2];
@@ -254,12 +257,12 @@ c_file.add('''union {
     .int_var=2,
   },
 }}''', " [2]")
-c_file.add("union {\n  int * ptr;\n}", "arr_union_ptr", "{{&one}, {&two}}", " [2]", )
+c_file.add("union {\n  int *ptr;\n}", "arr_union_ptr", "{{&one}, {&two}}", " [2]", )
 # ??? fails
 # c_file.add("int (*", "arr_ptr_arr", "{&arr_int, &arr_int}", " [2])[2]")
 c_file.add("struct {\n  int int_var;\n} *", "arr_ptr_struct", "", " [2]")
 c_file.add("union {\n  int int_var;\n  float float_var;\n} *", "arr_ptr_union", "", " [2]")
-c_file.add("int * *", "arr_ptr_ptr", "", " [2]")
+c_file.add("int **", "arr_ptr_ptr", "", " [2]")
 c_file.add("struct {\n  int int_var;\n} (*", "ptr_arr_struct", "", ")[2]")
 c_file.add("union {\n  int int_var;\n} (*", "ptr_arr_union", "", ")[2]")
 c_file.add("int * (*", "ptr_arr_ptr", "", ")[2]")
@@ -349,7 +352,7 @@ c_file.add('''struct {
   },
 }''')
 c_file.add('''struct {
-  int * ptr_int;
+  int *ptr_int;
 }''', "struct_ptr", "{&one}")
 c_file.add('''union {
   int arr_int[4];
@@ -379,7 +382,7 @@ c_file.add('''union {
   },
 }''')
 c_file.add('''union {
-  int * ptr_int;
+  int *ptr_int;
 }''', "union_ptr", "{&one}")
 c_file.add('''struct {
   int int_var;
@@ -458,7 +461,7 @@ c_file.add('''struct {
 }''')
 c_file.add('''struct {
   struct {
-    int * ptr_int;
+    int *ptr_int;
   } sp;
 }''', "struct_struct_ptr", "{{&three}}")
 c_file.add('''struct {
@@ -500,24 +503,24 @@ c_file.add('''struct {
 }''')
 c_file.add('''struct {
   union {
-    int * ptr_int;
+    int *ptr_int;
   } union_ptr;
 }''', "struct_union_ptr", "{{&four}}")
 c_file.add('''struct {
-  int (* ptr_arr)[4];
+  int (*ptr_arr)[4];
 }''', "struct_ptr_arr", "")
 c_file.add('''struct {
   struct {
     int int_var;
-  } * ptr_struct;
+  } *ptr_struct;
 }''', "struct_ptr_struct", "")
 c_file.add('''struct {
   union {
     int int_var;
-  } * ptr_union;
+  } *ptr_union;
 }''', "struct_ptr_union", "")
 c_file.add('''struct {
-  int * * ptr_ptr;
+  int **ptr_ptr;
 }''', "struct_ptr_ptr", "")
 c_file.add('''union {
   int arr_int[2][2];
@@ -593,7 +596,7 @@ c_file.add('''union {
 }''')
 c_file.add('''union {
   struct {
-    int * ptr_int;
+    int *ptr_int;
   } struct_ptr;
 }''', "union_struct_ptr", "{{&one}}")
 c_file.add('''union {
@@ -635,25 +638,25 @@ c_file.add('''union {
 }''')
 c_file.add('''union {
   union {
-    int * ptr_int;
-    float * ptr_float;
+    int *ptr_int;
+    float *ptr_float;
   } union_ptr;
 }''', "union_union_ptr", "{{&one}}")
 c_file.add('''union {
-  int (* ptr_arr)[4];
+  int (*ptr_arr)[4];
 }''', "union_ptr_arr", "")
 c_file.add('''union {
   struct {
     int int_var;
-  } * ptr_struct;
+  } *ptr_struct;
 }''', "union_ptr_struct", "")
 c_file.add('''union {
   union {
     int int_var;
-  } * ptr_union;
+  } *ptr_union;
 }''', "union_ptr_union", "")
 c_file.add('''union {
-  int * * ptr_ptr;
+  int **ptr_ptr;
 }''', "union_ptr_ptr", "")
 c_file.add('''struct {
   int arr_int[4];
@@ -669,7 +672,7 @@ c_file.add('''struct {
   } union_a;
 } *''', "ptr_struct_union", "")
 c_file.add('''struct {
-  int * ptr_int;
+  int *ptr_int;
 } *''', "ptr_struct_ptr", "")
 c_file.add('''union {
   int arr_int[4];
@@ -685,14 +688,14 @@ c_file.add('''union {
   } union_a;
 } *''', "ptr_union_union", "")
 c_file.add('''union {
-  int * ptr_int;
+  int *ptr_int;
 } *''', "ptr_union_ptr", "")
 c_file.add('''struct {
   int int_var;
-} * *''', "ptr_ptr_struct", "")
+} **''', "ptr_ptr_struct", "")
 c_file.add('''union {
   int int_var;
-} * *''', "ptr_ptr_union", "")
+} **''', "ptr_ptr_union", "")
 
 c_file.add('''enum  {\n  red = 0,\n  green = 1,\n  blue = 2\n}''', "primary_colors", "red")
 c_file.add('''enum colors {\n  orange = 0,\n  yellow = 1,\n  violet = 2,\n  indigo = 3\n}''', "rainbow_colors", "orange")
diff --git a/frysk-core/frysk/value/ArithmeticType.java b/frysk-core/frysk/value/ArithmeticType.java
index a0fc2d7..449e97d 100644
--- a/frysk-core/frysk/value/ArithmeticType.java
+++ b/frysk-core/frysk/value/ArithmeticType.java
@@ -40,7 +40,6 @@
 package frysk.value;
 
 import inua.eio.ByteOrder;
-import java.io.PrintWriter;
 import java.math.BigInteger;
 
 /**
@@ -70,8 +69,8 @@ public abstract class ArithmeticType
 	return var1.assign(var2);
     }
 
-    public void toPrint(PrintWriter writer, int indent) {
-	writer.print(getName());
+    public void toPrint(StringBuilder stringBuilder, int indent) {
+	stringBuilder.insert(0, getName());
     }
 
     /**
diff --git a/frysk-core/frysk/value/ArrayType.java b/frysk-core/frysk/value/ArrayType.java
index c3a38ff..afdec44 100644
--- a/frysk-core/frysk/value/ArrayType.java
+++ b/frysk-core/frysk/value/ArrayType.java
@@ -275,20 +275,19 @@ public class ArrayType
 	return noNullByte;
     }
 
-    public void toPrint(PrintWriter writer, String s, int indent) {
-	type.toPrint(writer, indent);
-	writer.print(" " + s);
+    public void toPrint(StringBuilder stringBuilder, int indent) {
+	StringBuilder typeStringBuilder = new StringBuilder();
+	type.toPrint(typeStringBuilder, indent);
+	if (indent == 0)
+	    typeStringBuilder.append(" ");
+	stringBuilder.insert(0, typeStringBuilder);
 	for(int i = 0; i < this.dimension.length; i++) {
-	    writer.print("[");
-	    writer.print(dimension[i]);
-	    writer.print("]");
+	    stringBuilder.append("[");
+	    stringBuilder.append(dimension[i]);
+	    stringBuilder.append("]");
 	}
     }
     
-    public void toPrint(PrintWriter writer, int indent) {
-	this.toPrint(writer, "", indent);
-    }
-    
     /* getALUs are double dispatch functions to determine 
      * the ArithmeticUnit for an operation between two types.
      */    
diff --git a/frysk-core/frysk/value/ChangeLog b/frysk-core/frysk/value/ChangeLog
index 2572fde..968ef85 100644
--- a/frysk-core/frysk/value/ChangeLog
+++ b/frysk-core/frysk/value/ChangeLog
@@ -1,3 +1,13 @@
+2007-12-11  Stan Cox  <scox@redhat.com>
+
+	* Type.java (toPrint(StringBuilder, int)): Change signature from
+	Writer to StringBuilder. Change all callers.
+	(String toPrint()): Change to use StringBuilder.
+	* ArrayType.java (toPrint): Use typeStringBuilder for return type.
+	* CompositeType.java (toPrint): Use memberStringBuilder for members.
+	* FunctionType.java (toPrint): Use parmStringBuilder for parameters.
+	* PointerType.java (toPrint): Detect ptr to array and ptr to function.
+
 007-12-11  Sami Wagiaalla  <swagiaal@redhat.com>
 
 	* CompositeType.java: Member now has a LineColPair element.
diff --git a/frysk-core/frysk/value/CompositeType.java b/frysk-core/frysk/value/CompositeType.java
index a39148b..3a26ecb 100644
--- a/frysk-core/frysk/value/CompositeType.java
+++ b/frysk-core/frysk/value/CompositeType.java
@@ -284,7 +284,7 @@ public abstract class CompositeType
 	writer.print("}");
     }
 
-    public void toPrint(PrintWriter writer, int indentation) {
+    public void toPrint(StringBuilder stringBuilderParm, int indentation) {
 	if (indentation == 0)
 	    indentation = 2;
 	String indentPrefix = "";
@@ -292,10 +292,11 @@ public abstract class CompositeType
 	    indentPrefix = indentPrefix + " ";
 
 	// {class,union,struct} NAME
-	writer.print(getPrefix());
+	StringBuilder stringBuilder = new StringBuilder();
+	stringBuilder.append(getPrefix());
 	if (getName() != null && getName().length() > 0) {
-	    writer.print(" ");
-	    writer.print(getName());
+	    stringBuilder.append(" ");
+	    stringBuilder.append(getName());
 	}
 	// : public PARENT ...
 	boolean first = true;
@@ -307,57 +308,42 @@ public abstract class CompositeType
 	    if (!member.inheritance)
 		break;
 	    if (first) {
-		writer.print(" : ");
+		stringBuilder.append(" : ");
 		first = false;
 	    } else {
-		writer.print(", ");
+		stringBuilder.append(", ");
 	    }
 	    if (member.access != null) {
-		writer.print(member.access.toPrint());
-		writer.print(" ");
+		stringBuilder.append(member.access.toPrint());
+		stringBuilder.append(" ");
 	    }
-	    writer.print(member.type.getName());
+	    stringBuilder.append(member.type.getName());
 	    member = null;
 	}
 	// { content ... }
 	Access previousAccess = null;
-	writer.print(" {\n");
+	stringBuilder.append(" {\n");
 
+	StringBuilder memberStringBuilder = new StringBuilder();
 	while (member != null) {
-	    boolean printName = true;
 	    if (member.access != previousAccess) {
 		previousAccess = member.access;
 		if (member.access != null) {
-		    writer.print(" ");
-		    writer.print(member.access.toPrint());
-		    writer.print(":\n");
+		    stringBuilder.append(" ");
+		    stringBuilder.append(member.access.toPrint());
+		    stringBuilder.append(":\n");
 		}
 	    }
-	    writer.print(indentPrefix);
-	    if (member.type instanceof ArrayType) {
-		// For handling int x[2]
-		printName = false;
-		((ArrayType) member.type).toPrint(writer, member.name, indentation + 2);
-	    }
-	    else if (member.type instanceof PointerType) {
-		// For handling int (*x)[2]
-		printName = false;
-		((PointerType) member.type).toPrint(writer, " " + member.name,
-						    indentation + 2);
-	    }
-	    else
-		member.type.toPrint (writer, indentation + 2);
-	    if (member.type instanceof frysk.value.FunctionType)
-		printName = false;
-	    if (printName) {
-		writer.print(" ");
-		writer.print(member.name);
-	    }
+	    memberStringBuilder.delete(0, memberStringBuilder.length());
+	    memberStringBuilder.append(" " + member.name);
+	    member.type.toPrint(memberStringBuilder, indentation + 2);
+	    memberStringBuilder.insert(0, indentPrefix);
+	    stringBuilder.append(memberStringBuilder);
 	    if (member.bitSize > 0) {
-		writer.print(":");
-		writer.print(member.bitSize);
+		stringBuilder.append(":");
+		stringBuilder.append(member.bitSize);
 	    }
-	    writer.print(";\n");
+	    stringBuilder.append(";\n");
 	    // Advance
 	    if (i.hasNext())
 		member = (DynamicMember)i.next();
@@ -365,8 +351,9 @@ public abstract class CompositeType
 		member = null;
 	}
 	for (int indent = 1; indent <= indentation - 2; indent++)
-	    writer.print(" ");
-	writer.print("}");
+	    stringBuilder.append(" ");
+	stringBuilder.append("}");
+	stringBuilderParm.insert(0, stringBuilder);
     }
     
     public Value member(Value var1, String member)
diff --git a/frysk-core/frysk/value/EnumType.java b/frysk-core/frysk/value/EnumType.java
index de97044..67583fe 100644
--- a/frysk-core/frysk/value/EnumType.java
+++ b/frysk-core/frysk/value/EnumType.java
@@ -104,26 +104,26 @@ public class EnumType extends IntegerTypeDecorator
 	    format.print(writer, location, this);
     }
 


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]