From: Stan Cox <scox@redhat.com>
To: Andrew Cagney <cagney@redhat.com>
Cc: Frysk List <frysk@sourceware.org>
Subject: Re: generating type tests
Date: Mon, 15 Oct 2007 19:13:00 -0000 [thread overview]
Message-ID: <1192475232.2947.164.camel@multics.rdu.redhat.com> (raw)
In-Reply-To: <47139B3A.3000101@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 426 bytes --]
On Mon, 2007-10-15 at 12:54 -0400, Andrew Cagney wrote:
> Can you post the patch?
(Note: this is a "make it work" patch.)
ArrayType: Handle 'int (*x) [N]'
Actually we probably want to display it as 'int (*) [N}'
(minus the name)
PointerType: Handle 'int (*x) []'
CompositeType: Handle 'struct {struct {..}}' and 'int (*x) []'
TypeDecorator: Handle 'const int * x' versus 'int * const x'
[-- Attachment #2: ,cvsdiff --]
[-- Type: text/plain, Size: 5889 bytes --]
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/ArrayType.java,v
retrieving revision 1.37
diff -u -p -r1.37 ArrayType.java
--- value/ArrayType.java 6 Sep 2007 14:26:09 -0000 1.37
+++ value/ArrayType.java 12 Oct 2007 20:37:02 -0000
@@ -204,14 +204,17 @@ public class ArrayType
}
}
- public void toPrint(PrintWriter writer) {
+ public void toPrint(String s, PrintWriter writer) {
type.toPrint(writer);
- writer.print(" [");
+ writer.print(" " + s);
for(int i = 0; i < this.dimension.length; i++) {
- if (i > 0)
- writer.print(",");
+ writer.print("[");
writer.print(dimension[i]);
+ writer.print("]");
}
- writer.print("]");
+ }
+
+ public void toPrint(PrintWriter writer) {
+ this.toPrint("", writer);
}
}
Index: value/CompositeType.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/CompositeType.java,v
retrieving revision 1.2
diff -u -p -r1.2 CompositeType.java
--- value/CompositeType.java 6 Sep 2007 20:48:09 -0000 1.2
+++ value/CompositeType.java 12 Oct 2007 20:37:02 -0000
@@ -259,16 +261,21 @@ abstract class CompositeType
writer.print("}");
}
- public void toPrint(PrintWriter writer) {
+ public void toPrint(int indentation, PrintWriter writer) {
// FIXME: going away.
if (this.isTypedef() && this.getName() != null
- && this.getName().length() > 0) {
+ && this.getName().length() > 0) {
writer.print(this.getName());
return;
}
+
+ String indentPrefix = "";
+ for (int indent = 1; indent <= indentation; indent++)
+ indentPrefix = indentPrefix + " ";
+
// {class,union,struct} NAME
writer.print(getPrefix());
- if (getName() != null) {
+ if (getName() != null && getName().length() > 0) {
writer.print(" ");
writer.print(getName());
}
@@ -278,7 +285,7 @@ abstract class CompositeType
Iterator i = members.iterator();
// Types this inherits come first; print them out.
while (i.hasNext()) {
- member = (Member)i.next();
+ member = (Member) i.next();
if (!member.inheritance)
break;
if (first) {
@@ -289,7 +296,6 @@ abstract class CompositeType
}
if (member.access != null) {
writer.print(member.access.toPrint());
- writer.print(" ");
}
writer.print(member.type.getName());
member = null;
@@ -297,7 +303,9 @@ abstract class CompositeType
// { content ... }
Access previousAccess = null;
writer.print(" {\n");
+
while (member != null) {
+ boolean printName = true;
if (member.access != previousAccess) {
previousAccess = member.access;
if (member.access != null) {
@@ -306,12 +314,25 @@ abstract class CompositeType
writer.print(":\n");
}
}
- writer.print(" ");
- if (member.type.isTypedef())
+ writer.print(indentPrefix);
+
+ if (member.type instanceof TypeDef)
writer.print(member.type.getName());
+ else if (member.type instanceof CompositeType)
+ ((CompositeType) member.type).toPrint(indentation + 2, writer);
+ else if (member.type instanceof ArrayType) {
+ printName = false;
+ ((ArrayType) member.type).toPrint(member.name, writer);
+ }
+ else if (member.type instanceof PointerType) {
+ printName = false;
+ ((PointerType) member.type).toPrint(" " + member.name, writer);
+ }
else
member.type.toPrint(writer);
- if (!(member.type instanceof frysk.value.FunctionType)) {
+ if (member.type instanceof frysk.value.FunctionType)
+ printName = false;
+ if (printName) {
writer.print(" ");
writer.print(member.name);
}
@@ -322,10 +343,16 @@ abstract class CompositeType
writer.print(";\n");
// Advance
if (i.hasNext())
- member = (Member)i.next();
+ member = (Member) i.next();
else
member = null;
}
+ for (int indent = 1; indent <= indentation - 2; indent++)
+ writer.print(" ");
writer.print("}");
}
+
+ public void toPrint(PrintWriter writer) {
+ this.toPrint(2, writer);
+ }
}
Index: value/PointerType.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/PointerType.java,v
retrieving revision 1.23
diff -u -p -r1.23 PointerType.java
--- value/PointerType.java 21 Sep 2007 20:21:07 -0000 1.23
+++ value/PointerType.java 12 Oct 2007 20:37:02 -0000
@@ -93,11 +93,20 @@ public class PointerType
}
}
- public void toPrint(PrintWriter writer) {
- type.toPrint(writer);
- writer.print(" *");
+ public void toPrint(String s, PrintWriter writer) {
+ if (type instanceof ArrayType) {
+ ((ArrayType)type).toPrint("(*" + s + ")", writer);
+ }
+ else {
+ type.toPrint(writer);
+ writer.print(" *" + s);
+ }
}
+ public void toPrint(PrintWriter writer) {
+ this.toPrint("", writer);
+ }
+
protected Type clone(IntegerType accessor) {
return new PointerType(getName(), order(), getSize(), type, accessor);
}
Index: value/TypeDecorator.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/value/TypeDecorator.java,v
retrieving revision 1.5
diff -u -p -r1.5 TypeDecorator.java
--- value/TypeDecorator.java 6 Sep 2007 03:19:07 -0000 1.5
+++ value/TypeDecorator.java 12 Oct 2007 20:37:02 -0000
@@ -77,9 +77,14 @@ abstract class TypeDecorator extends Typ
* A guess; sub classes should override.
*/
public void toPrint(PrintWriter writer) {
- writer.print(getName());
- writer.print(" ");
- decorated.toPrint(writer);
+ if (getUltimateType() instanceof PointerType) {
+ decorated.toPrint(writer);
+ writer.print(" " + getName());
+ }
+ else {
+ writer.print(getName() + " ");
+ decorated.toPrint(writer);
+ }
}
public Value add(Value var1, Value var2) {
return decorated.add(var1, var2);
next prev parent reply other threads:[~2007-10-15 19:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-12 21:18 Stan Cox
2007-10-12 22:54 ` Andrew Cagney
2007-10-15 2:10 ` Stan Cox
2007-10-15 16:50 ` Andrew Cagney
2007-10-16 19:47 ` Stan Cox
2007-10-17 11:12 ` Stan Cox
2007-10-15 16:56 ` Andrew Cagney
2007-10-15 19:13 ` Stan Cox [this message]
2007-10-18 16:16 ` Stan Cox
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=1192475232.2947.164.camel@multics.rdu.redhat.com \
--to=scox@redhat.com \
--cc=cagney@redhat.com \
--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).