Skip to content

Commit 67b125b

Browse files
committed
Fix second parsing pass for class/record types
Carry on parsing a class/record if the superclass is undefined, check if a parsed class already exists (which it should in the second pass), and if yes, only set the superclass, which should now be available.
1 parent 7005759 commit 67b125b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/gir2java/GirParser.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,24 @@ private void parseRecordOrClass(Element root, ParsingContext context) {
464464

465465
JCodeModel cm = (JCodeModel) context.getCmNode();
466466
String name = root.getAttributeValue("name");
467+
468+
//Check if this is a retry
469+
ConvertedType existingMapping = context.lookupType(name);
470+
if (existingMapping != null) {
471+
//It is, superclass name can't be null
472+
String superclassName = root.getAttributeValue("parent");
473+
ConvertedType superclassConvType = context.lookupType(superclassName);
474+
if (superclassConvType == null) {
475+
System.out.println("Something is wrong, superclass " + superclassName + " of " + name + " still undefined");
476+
return;
477+
} else {
478+
//a class defined in a gir is always mapped to a JDefinedClass
479+
JDefinedClass jClass = (JDefinedClass) existingMapping.getJType();
480+
jClass._extends((JClass)superclassConvType.getJType());
481+
return;
482+
}
483+
}
484+
467485
String className = context.getCurrentPackage() + '.' + context.getExtra(Constants.CONTEXT_EXTRA_PREFIX) + NameUtils.neutralizeKeyword(name);
468486

469487
Set<String> foundTypes = (Set<String>)context.getExtra(Constants.CONTEXT_EXTRA_DEFINED_TYPES);
@@ -497,7 +515,7 @@ private void parseRecordOrClass(Element root, ParsingContext context) {
497515
(Set<ParsingSnapshot>) context.getExtra(Constants.CONTEXT_EXTRA_SNAPSHOTS);
498516

499517
snapshots.add(new ParsingSnapshot(context, root));
500-
return;
518+
System.out.println("Superclass " + superclassName + " undefined, trying record/class " + name + " again later");
501519
}
502520
}
503521

@@ -509,9 +527,9 @@ private void parseRecordOrClass(Element root, ParsingContext context) {
509527

510528
parsedClass.init().add(cm.ref(BridJ.class).staticInvoke("register"));
511529

512-
if (superclassConvType == null) {
530+
if (superclassName == null) {
513531
parsedClass._extends(StructObject.class);
514-
} else {
532+
} else if(superclassConvType != null) {
515533
parsedClass._extends((JClass)superclassConvType.getJType());
516534
System.out.println(className + " extends " + superclassConvType);
517535
}

0 commit comments

Comments
 (0)