Skip to content

Commit 0b476ba

Browse files
committed
JNAerator: fixed parsing of throw() declarations + virtual or private C++ inheritance
1 parent a81821c commit 0b476ba

File tree

6 files changed

+54
-15
lines changed

6 files changed

+54
-15
lines changed

libraries/jnaerator/jnaerator-parser/src/main/antlr3/com/ochafik/lang/jnaerator/parser/ObjCpp.g

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,9 @@ scope ModContext;
836836
'{'
837837
(
838838
(
839-
'public' { $struct.setNextMemberVisibility(Struct.MemberVisibility.Public); } |
840-
'private' { $struct.setNextMemberVisibility(Struct.MemberVisibility.Private); } |
841-
'protected' { $struct.setNextMemberVisibility(Struct.MemberVisibility.Protected); }
839+
{ next("public") }? IDENTIFIER { $struct.setNextMemberVisibility(Struct.MemberVisibility.Public); } |
840+
{ next("private") }? IDENTIFIER { $struct.setNextMemberVisibility(Struct.MemberVisibility.Private); } |
841+
{ next("protected") }? IDENTIFIER { $struct.setNextMemberVisibility(Struct.MemberVisibility.Protected); }
842842
) ':' |
843843
{ next("friend") }? IDENTIFIER friend=declaration ';' {
844844
$struct.addDeclaration(new FriendDeclaration(friend.declaration));
@@ -911,7 +911,7 @@ scope CurrentClass;
911911
( m2=modifiers { modifiers.addAll($m2.modifiers); } )?
912912
(
913913
':'
914-
'public'?//m3=modifiers
914+
( { next("public", "private", "virtual") }? IDENTIFIER )?//m3=modifiers
915915
parent=qualifiedIdentifier
916916
)?
917917
nb=structBody {
@@ -975,11 +975,13 @@ scope Symbols;
975975
$function.setInitializers($s.initializers);
976976
$function.setType(Function.Type.CppMethod);
977977
}
978+
$function.setThrows($s.thrown != null);
979+
$function.setThrown($s.thrown);
978980
$function.setBody($s.body);
979981
}
980982
;
981983

982-
functionDeclarationSuffix returns [List<Arg> args, List<Modifier> postModifiers, List<FunctionCall> initializers, Block body]
984+
functionDeclarationSuffix returns [List<Arg> args, List<Modifier> postModifiers, List<FunctionCall> initializers, Block body, List<TypeRef> thrown]
983985
:
984986
{
985987
$initializers = new ArrayList<FunctionCall>();
@@ -988,6 +990,24 @@ functionDeclarationSuffix returns [List<Arg> args, List<Modifier> postModifiers,
988990
$args = $argList.args;
989991
}
990992
( postMods=modifiers { $postModifiers = $postMods.modifiers; } )?
993+
(
994+
{ next("throw") }? IDENTIFIER {
995+
$thrown = new ArrayList<TypeRef>();
996+
}
997+
'('
998+
(
999+
t1=mutableTypeRef {
1000+
$thrown.add($t1.type);
1001+
}
1002+
(
1003+
','
1004+
tx=mutableTypeRef {
1005+
$thrown.add($tx.type);
1006+
}
1007+
)*
1008+
)?
1009+
')'
1010+
)?
9911011
(
9921012
':'
9931013
i1=constructorInitializer { $initializers.add($i1.init); }

libraries/jnaerator/jnaerator-parser/src/main/java/com/ochafik/lang/jnaerator/parser/Function.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class Function extends Declaration implements Declarator.MutableByDeclara
3636
final List<Arg> args = new ArrayList<Arg>();
3737
final List<TypeRef> thrown = new ArrayList<TypeRef>();
3838
final List<FunctionCall> initializers = new ArrayList<FunctionCall>();
39+
boolean throws_;
3940
Statement.Block body;
4041
Type type;
4142

@@ -55,6 +56,15 @@ public enum Type {
5556
CFunction, ObjCMethod, CppMethod, JavaMethod, StaticInit
5657
}
5758

59+
public boolean getThrows() {
60+
return throws_;
61+
}
62+
63+
public void setThrows(boolean throws_) {
64+
this.throws_ = throws_;
65+
}
66+
67+
5868
public void setInitializers(List<FunctionCall> initializers) {
5969
changeValue(this, this.initializers, initializers);
6070
}

libraries/jnaerator/jnaerator-parser/src/main/java/com/ochafik/lang/jnaerator/parser/Printer.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,19 @@ public void visitFunction(Function e) {
250250
}
251251
append("(").implode(e.getArgs(), ", ").append(")");
252252

253-
if (!e.getThrown().isEmpty())
254-
append(" throws ").implode(e.getThrown(), ", ");
255-
253+
switch (e.getType()) {
254+
case JavaMethod:
255+
if (!e.getThrown().isEmpty())
256+
append(" throws ").implode(e.getThrown(), ", ");
257+
break;
258+
default:
259+
if (e.getThrows()) {
260+
append(" throw(");
261+
implode(e.getThrown(), ", ");
262+
append(")");
263+
}
264+
}
265+
256266
if (!e.getInitializers().isEmpty())
257267
append(" : ").implode(e.getInitializers(), ", ");
258268

libraries/jnaerator/jnaerator/src/main/resources/bridj.jar.files

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
org/bridj/AbstractBridJRuntime.class
22
org/bridj/AbstractIntegral.class
3-
org/bridj/AndroidClassDefiner.class
4-
org/bridj/AndroidSupport.class
53
org/bridj/BitFields$1.class
64
org/bridj/BitFields$2.class
75
org/bridj/BitFields$3.class
@@ -343,18 +341,17 @@ org/objectweb/asm/AnnotationVisitor.class
343341
org/objectweb/asm/AnnotationWriter.class
344342
org/objectweb/asm/Attribute.class
345343
org/objectweb/asm/ByteVector.class
346-
org/objectweb/asm/ClassAdapter.class
347344
org/objectweb/asm/ClassReader.class
348345
org/objectweb/asm/ClassVisitor.class
349346
org/objectweb/asm/ClassWriter.class
350347
org/objectweb/asm/Edge.class
351348
org/objectweb/asm/FieldVisitor.class
352349
org/objectweb/asm/FieldWriter.class
353350
org/objectweb/asm/Frame.class
351+
org/objectweb/asm/Handle.class
354352
org/objectweb/asm/Handler.class
355353
org/objectweb/asm/Item.class
356354
org/objectweb/asm/Label.class
357-
org/objectweb/asm/MethodAdapter.class
358355
org/objectweb/asm/MethodVisitor.class
359356
org/objectweb/asm/MethodWriter.class
360357
org/objectweb/asm/Opcodes.class

libraries/jnaerator/jnaerator/src/test/resources/com/ochafik/lang/jnaerator/parser/ObjCppTest.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ void f() {
2525
--
2626
void f(int __in);
2727
--
28+
void meth(double*) throw(int, SomeEx*);
29+
--
2830
void f(void (*g)());
2931
--
3032
void (*fptr)();

libraries/scripts/listRuntime

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ function listFile {
66

77
# unzip -l jna-jnaerator/target/jna-jnaerator-3.2.7.jar | sed -E 's/^.*[0-9]+:[0-9]+ +//' | grep '\.' | sort | tee jnaerator/src/main/resources/jna-runtime.jar.files
88
# unzip -l jnaerator-runtime/target/jnaerator-runtime-*-shaded.jar | sed -E 's/^.*[0-9]+:[0-9]+ +//' | grep '\.' | sort | tee jnaerator/src/main/resources/jnaerator-runtime.jar.files
9-
# unzip -l ~/nativelibs4java/Runtime/Structs/target/nl4j-runtime-structs-jna-*.jar | sed -E 's/^.*[0-9]+:[0-9]+ +//' | grep '\.' | sort | tee jnaerator/src/main/resources/nl4j-runtime-structs-jna.jar.files
10-
# unzip -l ~/nativelibs4java/Runtime/BridJ/target/bridj-0.6.jar | sed -E 's/^.*[0-9]+:[0-9]+ +//' | grep '\.' | sort | tee jnaerator/src/main/resources/bridj.jar.files
9+
# unzip -l ~/nativelibs4java/Structs/target/nl4j-runtime-structs-jna-*.jar | sed -E 's/^.*[0-9]+:[0-9]+ +//' | grep '\.' | sort | tee jnaerator/src/main/resources/nl4j-runtime-structs-jna.jar.files
10+
# unzip -l ~/nativelibs4java/BridJ/target/bridj-0.6.jar | sed -E 's/^.*[0-9]+:[0-9]+ +//' | grep '\.' | sort | tee jnaerator/src/main/resources/bridj.jar.files
1111

1212
JNA_VERSION=3.4.0
1313
JNAERATOR_VERSION=0.9.10-SNAPSHOT
1414
BRIDJ_VERSION=0.7-SNAPSHOT
1515

1616
listFile ~/.m2/repository/net/java/dev/jna/jna/$JNA_VERSION/jna-$JNA_VERSION.jar jna-runtime.jar.files
1717
listFile jnaerator-runtime/target/jnaerator-runtime-*-shaded.jar jnaerator-runtime.jar.files
18-
listFile ~/nativelibs4java/Runtime/BridJ/target/bridj-$BRIDJ_VERSION.jar bridj.jar.files
18+
listFile ~/nativelibs4java/BridJ/target/bridj-$BRIDJ_VERSION.jar bridj.jar.files
1919

0 commit comments

Comments
 (0)