mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
Fix a bug
This commit is contained in:
parent
39f646118e
commit
8cbe8f914d
1 changed files with 66 additions and 21 deletions
|
@ -36,7 +36,8 @@ public class GDBTypeParser {
|
||||||
String dataType;
|
String dataType;
|
||||||
String name;
|
String name;
|
||||||
String out;
|
String out;
|
||||||
GDBType gdbType;
|
GDBDerivedType gdbDerivedType;
|
||||||
|
GDBType genericType;
|
||||||
|
|
||||||
public class GDBType {
|
public class GDBType {
|
||||||
public final static int GENERIC = 0;
|
public final static int GENERIC = 0;
|
||||||
|
@ -68,21 +69,31 @@ public class GDBTypeParser {
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GDBDerivedType extends GDBType {
|
public class GDBDerivedType extends GDBType {
|
||||||
GDBType child;
|
|
||||||
int dimension;
|
int dimension;
|
||||||
|
GDBType child;
|
||||||
|
|
||||||
public GDBDerivedType(GDBType c, int i) {
|
public GDBDerivedType(GDBType c, int i) {
|
||||||
this(c, i, 0);
|
this(c, i, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GDBDerivedType(GDBType c, int t, int dim) {
|
public GDBDerivedType(GDBType c, int t, int dim) {
|
||||||
super(t);
|
super(t);
|
||||||
child = c;
|
setChild(c);
|
||||||
dimension = dim;
|
dimension = dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDimension() {
|
||||||
|
return dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChild(GDBType c) {
|
||||||
|
child = c;
|
||||||
|
}
|
||||||
|
|
||||||
public GDBType getChild() {
|
public GDBType getChild() {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
@ -91,10 +102,6 @@ public class GDBTypeParser {
|
||||||
return child != null;
|
return child != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDimension() {
|
|
||||||
return dimension;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
switch (getType()) {
|
switch (getType()) {
|
||||||
|
@ -102,7 +109,7 @@ public class GDBTypeParser {
|
||||||
sb.append(" Function returning " + (hasChild() ? child.toString() : ""));
|
sb.append(" Function returning " + (hasChild() ? child.toString() : ""));
|
||||||
break;
|
break;
|
||||||
case ARRAY:
|
case ARRAY:
|
||||||
sb.append(" Array[" + dimension + "]" + " to " + (hasChild() ? child.toString() : ""));
|
sb.append(" Array[" + dimension + "]" + " of " + (hasChild() ? child.toString() : ""));
|
||||||
break;
|
break;
|
||||||
case REFERENCE:
|
case REFERENCE:
|
||||||
sb.append(" Reference to " + (hasChild() ? child.toString() : ""));
|
sb.append(" Reference to " + (hasChild() ? child.toString() : ""));
|
||||||
|
@ -119,7 +126,10 @@ public class GDBTypeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GDBType getGDBType() {
|
public GDBType getGDBType() {
|
||||||
return gdbType;
|
if (gdbDerivedType != null) {
|
||||||
|
return gdbDerivedType;
|
||||||
|
}
|
||||||
|
return genericType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verbose() {
|
public void verbose() {
|
||||||
|
@ -138,16 +148,16 @@ public class GDBTypeParser {
|
||||||
index = 0;
|
index = 0;
|
||||||
token = "";
|
token = "";
|
||||||
dataType = "";
|
dataType = "";
|
||||||
|
|
||||||
out = "";
|
out = "";
|
||||||
name = "";
|
name = "";
|
||||||
|
gdbDerivedType = null;
|
||||||
|
|
||||||
// Fetch the datatype.
|
// Fetch the datatype.
|
||||||
while (getToken() == NAME) {
|
while (getToken() == NAME) {
|
||||||
dataType += " " + token;
|
dataType += " " + token;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdbType = new GDBType(dataType);
|
genericType = new GDBType(dataType);
|
||||||
|
|
||||||
// After getting the type move back
|
// After getting the type move back
|
||||||
//ungetch();
|
//ungetch();
|
||||||
|
@ -191,18 +201,45 @@ public class GDBTypeParser {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void prependChild(int kind) {
|
||||||
|
prependChild(kind, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void prependChild(int kind, int d) {
|
||||||
|
GDBDerivedType dType = new GDBDerivedType(genericType, kind, d);
|
||||||
|
if (gdbDerivedType != null) {
|
||||||
|
// get to the last node in the list and add the new to it
|
||||||
|
GDBType leaf = genericType;
|
||||||
|
GDBDerivedType node;
|
||||||
|
boolean keepGoing =true;
|
||||||
|
for (node = gdbDerivedType; keepGoing;){
|
||||||
|
leaf = node.getChild();
|
||||||
|
if (leaf instanceof GDBDerivedType) {
|
||||||
|
node = (GDBDerivedType)leaf;
|
||||||
|
} else {
|
||||||
|
keepGoing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.setChild(dType);
|
||||||
|
} else {
|
||||||
|
gdbDerivedType = dType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// method returns the next token
|
// method returns the next token
|
||||||
int getToken() {
|
int getToken() {
|
||||||
token = "";
|
token = "";
|
||||||
|
|
||||||
int c = getch();
|
int c = getch();
|
||||||
char character = (char)c;
|
|
||||||
|
|
||||||
// Skip over any space
|
// Skip over any space
|
||||||
while (isCSpace(c)) {
|
while (isCSpace(c)) {
|
||||||
c = getch();
|
c = getch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char character = (char)c;
|
||||||
|
|
||||||
if (c == '(') {
|
if (c == '(') {
|
||||||
if ((c = getch()) == ')') {
|
if ((c = getch()) == ')') {
|
||||||
token = "()";
|
token = "()";
|
||||||
|
@ -261,11 +298,12 @@ public class GDBTypeParser {
|
||||||
dirdcl();
|
dirdcl();
|
||||||
while (nstar-- > 0) {
|
while (nstar-- > 0) {
|
||||||
out += " pointer to ";
|
out += " pointer to ";
|
||||||
gdbType = new GDBDerivedType(gdbType, GDBDerivedType.POINTER);
|
prependChild(GDBType.POINTER);
|
||||||
}
|
}
|
||||||
while (namp-- > 0) {
|
while (namp-- > 0) {
|
||||||
out += " reference to";
|
out += " reference to ";
|
||||||
gdbType = new GDBDerivedType(gdbType, GDBDerivedType.REFERENCE);
|
prependChild(GDBType.REFERENCE);
|
||||||
|
GDBDerivedType referenceType = new GDBDerivedType(genericType, GDBDerivedType.REFERENCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +331,7 @@ public class GDBTypeParser {
|
||||||
}
|
}
|
||||||
if (type == PARENS) {
|
if (type == PARENS) {
|
||||||
out += " function returning ";
|
out += " function returning ";
|
||||||
gdbType = new GDBDerivedType(gdbType, GDBType.FUNCTION);
|
prependChild(GDBType.FUNCTION);
|
||||||
} else {
|
} else {
|
||||||
int len = 0;
|
int len = 0;
|
||||||
if (token.length() > 0) {
|
if (token.length() > 0) {
|
||||||
|
@ -308,7 +346,7 @@ public class GDBTypeParser {
|
||||||
} else {
|
} else {
|
||||||
out += " array of ";
|
out += " array of ";
|
||||||
}
|
}
|
||||||
gdbType = new GDBDerivedType(gdbType, GDBType.ARRAY, len);
|
prependChild(GDBType.ARRAY, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,6 +356,7 @@ public class GDBTypeParser {
|
||||||
GDBTypeParser parser = new GDBTypeParser();
|
GDBTypeParser parser = new GDBTypeParser();
|
||||||
System.out.println("char **argv");
|
System.out.println("char **argv");
|
||||||
parser.parse("unsigned long long int **argv");
|
parser.parse("unsigned long long int **argv");
|
||||||
|
parser.verbose();
|
||||||
System.out.println(parser.getGDBType());
|
System.out.println(parser.getGDBType());
|
||||||
|
|
||||||
System.out.println("int (*daytab)[13]");
|
System.out.println("int (*daytab)[13]");
|
||||||
|
@ -327,26 +366,32 @@ public class GDBTypeParser {
|
||||||
|
|
||||||
System.out.println("int *daytab[13]");
|
System.out.println("int *daytab[13]");
|
||||||
parser.parse("int *daytab[13]");
|
parser.parse("int *daytab[13]");
|
||||||
|
parser.verbose();
|
||||||
System.out.println(parser.getGDBType());
|
System.out.println(parser.getGDBType());
|
||||||
|
|
||||||
System.out.println("void *comp()");
|
System.out.println("void *comp()");
|
||||||
parser.parse("void *comp()");
|
parser.parse("void *comp()");
|
||||||
|
parser.verbose();
|
||||||
System.out.println(parser.getGDBType());
|
System.out.println(parser.getGDBType());
|
||||||
|
|
||||||
System.out.println("void (*comp)()");
|
System.out.println("void (*comp)()");
|
||||||
parser.parse("void (*comp)()");
|
parser.parse("void (*comp)()");
|
||||||
|
parser.verbose();
|
||||||
System.out.println(parser.getGDBType());
|
System.out.println(parser.getGDBType());
|
||||||
|
|
||||||
System.out.println("int (*func[15])()");
|
System.out.println("int (*func[15])()");
|
||||||
parser.parse("int (*func[15])()");
|
parser.parse("int (*func[15])()");
|
||||||
|
parser.verbose();
|
||||||
System.out.println(parser.getGDBType());
|
System.out.println(parser.getGDBType());
|
||||||
|
|
||||||
System.out.println("char (*(*x())[])()");
|
System.out.println("char (*(*x())[])()");
|
||||||
parser.parse("char (*(*x())[])()");
|
parser.parse("char (*(*x())[])()");
|
||||||
|
parser.verbose();
|
||||||
System.out.println(parser.getGDBType());
|
System.out.println(parser.getGDBType());
|
||||||
|
|
||||||
System.out.println("char (*(*x[3])())[5]");
|
System.out.println("char (*(*x[3])())[5]");
|
||||||
parser.parse("char (*(*x[3])())[5]");
|
parser.parse("char (*(*x[3])())[5]");
|
||||||
|
parser.verbose();
|
||||||
System.out.println(parser.getGDBType());
|
System.out.println(parser.getGDBType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue