Skip to content

Commit 2d2b048

Browse files
committed
fix "const char*" issue with gcc4: better and sounder handling of shortcuts
The const case is a special case as we erase the constness in the internal representation. This way, what is a special type "const char" is a plain one "char" for bridj, but still need to be shorcut. - tested with "mvn -Dtest=org.bridj.DemanglingTest test" - complex template test still/now passing - with the help of the convenient http://demangler.com/
1 parent d9993eb commit 2d2b048

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/main/java/org/bridj/demangling/GCC4Demangler.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ private String nextShortcutId() {
8888
}
8989

9090
private TypeRef parsePointerType(boolean memorizePointed, boolean isConst, boolean isReference) throws DemanglingException {
91-
String subId = memorizePointed ? nextShortcutId() : null;
9291
TypeRef pointed = parseType();
93-
if (memorizePointed)
92+
if (memorizePointed) { // force-save the pointed type (used for the case of "const" that is erased (ignored) in bridj internal representation
93+
String subId = memorizePointed ? nextShortcutId() : null;
9494
typeShortcuts.put(subId, pointed);
95+
}
9596
TypeRef res = pointerType(pointed, isConst, isReference);
9697
String id = nextShortcutId();
9798
typeShortcuts.put(id, res);
@@ -177,7 +178,7 @@ public TypeRef parseType() throws DemanglingException {
177178
char nextChar = peekChar();
178179
boolean isReference = c == 'R';
179180
boolean isConst = nextChar == 'K';
180-
return parsePointerType(isConst || nextChar == 'N', isConst, isReference);
181+
return parsePointerType(isConst, isConst, isReference);
181182
}
182183
case 'F': {
183184
// TODO parse function type correctly !!!
@@ -263,7 +264,6 @@ private String parseSimpleOrComplexIdentInto(List<IdentLike> res, boolean isPars
263264
}
264265
}
265266
if (shouldContinue) {
266-
int initialNextShortcutId = nextShortcutId;
267267
do {
268268
String id = nextShortcutId(); // we get the id before parsing the part (might be template parameters and we need to get the ids in the right order)
269269
newlyAddedShortcutForThisType = id;
@@ -273,8 +273,8 @@ private String parseSimpleOrComplexIdentInto(List<IdentLike> res, boolean isPars
273273
parsePossibleTemplateArguments(res);
274274
} while (Character.isDigit(peekChar()) || peekChar() == 'C' || peekChar() == 'D');
275275
if (isParsingNonShortcutableElement) {
276-
//prefixShortcuts.remove(previousShortcutId()); // correct the fact that we parsed one too much
277-
nextShortcutId = initialNextShortcutId;
276+
nextShortcutId--;
277+
newlyAddedShortcutForThisType = null;
278278
}
279279
}
280280
parsePossibleTemplateArguments(res);
@@ -434,9 +434,6 @@ public MemberRef parseSymbol() throws DemanglingException {
434434
mr.setMemberName(ns.remove(ns.size() - 1));
435435
if (!ns.isEmpty()) {
436436
ClassRef parent = new ClassRef(ensureOfType(ns.remove(ns.size() - 1), Ident.class));
437-
if (mr.getMemberName() == SpecialName.Constructor || mr.getMemberName() == SpecialName.SpecialConstructor) {
438-
typeShortcuts.put(nextShortcutId(), parent);
439-
}
440437
if (!ns.isEmpty()) {
441438
parent.setEnclosingType(new NamespaceRef(ns.toArray()));
442439
}

0 commit comments

Comments
 (0)