We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 967bf89 commit b5a262aCopy full SHA for b5a262a
4 files changed
src/main/java/org/bridj/demangling/Demangler.java
@@ -560,10 +560,14 @@ public String toString() {
560
public static class PointerTypeRef extends TypeRef {
561
562
public TypeRef pointedType;
563
+ public boolean isReference;
564
+ public boolean isConst;
565
- public PointerTypeRef(TypeRef pointedType) {
566
+ public PointerTypeRef(TypeRef pointedType, boolean isConst, boolean isReference) {
567
assert pointedType != null;
568
this.pointedType = pointedType;
569
+ this.isReference = isReference;
570
+ this.isConst = isConst;
571
}
572
573
@Override
@@ -573,7 +577,7 @@ public StringBuilder getQualifiedName(StringBuilder b, boolean generic) {
577
574
578
575
579
public String toString() {
576
- return pointedType + "*";
580
+ return (isConst ? "const " : "") + pointedType + (isReference ? "&" : "*");
581
582
583
@@ -600,8 +604,8 @@ public boolean matches(Type type, Annotations annotations) {
600
604
601
605
602
606
603
- protected static TypeRef pointerType(TypeRef tr) {
- return new PointerTypeRef(tr);
607
+ protected static TypeRef pointerType(TypeRef tr, boolean isConst, boolean isReference) {
608
+ return new PointerTypeRef(tr, isConst, isReference);
609
610
611
protected static TypeRef classType(final Class<?> c, Class<? extends Annotation>... annotations) {
src/main/java/org/bridj/demangling/GCC4Demangler.java
@@ -96,12 +96,12 @@ private String nextShortcutId() {
96
return n == -1 ? "_" : Integer.toString(n, 36).toUpperCase() + "_";
97
98
99
- private TypeRef parsePointerType(boolean memorizePointed) throws DemanglingException {
+ private TypeRef parsePointerType(boolean memorizePointed, boolean isConst, boolean isReference) throws DemanglingException {
100
String subId = memorizePointed ? nextShortcutId() : null;
101
TypeRef pointed = parseType();
102
if (memorizePointed)
103
typeShortcuts.put(subId, pointed);
104
- TypeRef res = pointerType(pointed);
+ TypeRef res = pointerType(pointed, isConst, isReference);
105
String id = nextShortcutId();
106
typeShortcuts.put(id, res);
107
return res;
@@ -180,9 +180,12 @@ public TypeRef parseType() throws DemanglingException {
180
181
182
183
+ case 'R': // Reference: TODO: treat const ref as a value.
184
case 'P': {
185
char nextChar = peekChar();
- return parsePointerType(nextChar == 'K' || nextChar == 'N');
186
+ boolean isReference = c == 'R';
187
+ boolean isConst = nextChar == 'K';
188
+ return parsePointerType(isConst || nextChar == 'N', isConst, isReference);
189
190
case 'F': {
191
// TODO parse function type correctly !!!
@@ -196,7 +199,7 @@ public TypeRef parseType() throws DemanglingException {
196
199
expectChars('E');
197
200
return new FunctionTypeRef(mr);
198
201
- case 'K':
202
+ case 'K': // const?
203
return parseType();
204
case 'v': // char
205
return classType(Void.TYPE);
src/main/java/org/bridj/demangling/VC9Demangler.java
@@ -395,6 +395,8 @@ TypeRef parseType(boolean allowVoid) throws DemanglingException {
395
case 'Q': // const pointer
396
case 'R': // volatile pointer
397
case 'S': // const volatile pointer
398
+ boolean isReference = c == 'A' || c == 'B';
399
+ boolean isConst = c == 'Q' || c == 'S';
400
if (!consumeCharsIf('$', 'A')) // __gc
401
{
402
consumeCharsIf('$', 'B'); // __pin
@@ -408,11 +410,11 @@ TypeRef parseType(boolean allowVoid) throws DemanglingException {
408
410
indices[i] = parseNumber(false);
409
411
412
- tr = pointerType(parseType(true));
413
+ tr = pointerType(parseType(true), isConst, isReference);
414
} else {
415
MemberRef mr = new MemberRef();
416
parseFunctionProperty(mr);
- tr = pointerType(new FunctionTypeRef(mr));
417
+ tr = pointerType(new FunctionTypeRef(mr), isConst, isReference);
418
419
addBackRef(tr);
420
return tr;
src/test/java/org/bridj/DemanglingTest.java
@@ -390,9 +390,9 @@ public void gccMemoryShortcuts() {
390
demangle(null, "_Z15shortcutsSimplePPPPccS_S0_S1_S2_PS2_", "null shortcutsSimple(byte****, byte, byte*, byte**, byte***, byte****, byte*****)");
391
392
demangle(null, "__Z1fPsS_", "null f(short*, short*)");
393
- demangle(null, "__Z1fPKsS_", "null f(short*, short)");
394
- demangle(null, "__Z1fPKsS0_", "null f(short*, short*)");
- demangle(null, "__Z1fPKcS0_S0_PKsS2_PKdS4_", "null f(byte*, byte*, byte*, short*, short*, double*, double*)");
+ demangle(null, "__Z1fPKsS_", "null f(const short*, short)");
+ demangle(null, "__Z1fPKsS0_", "null f(const short*, const short*)");
+ demangle(null, "__Z1fPKcS0_S0_PKsS2_PKdS4_", "null f(const byte*, const byte*, const byte*, const short*, const short*, const double*, const double*)");
demangle(null, "__ZN1AC2EPS_PS0_S1_", "null A.(A*, A**, A**)");
/*
*
0 commit comments