Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow down context.virtualize at function level #658

Merged
merged 5 commits into from
Mar 21, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 41 additions & 29 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,10 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
}
}

type = postDeclarator(context, decl, dcl, dcl.type);
saudet marked this conversation as resolved.
Show resolved Hide resolved
context = new Context(context);
context.virtualize &= type.virtual;

List<Declarator> prevDcl = new ArrayList<Declarator>();
boolean first = true;
for (int n = -2; n < Integer.MAX_VALUE; n++) {
Expand Down Expand Up @@ -2440,32 +2444,8 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
}
}

// check for const, other attributes, and pure virtual functions, ignoring the body if present
for (Token token = tokens.get(); !token.match(Token.EOF); token = tokens.get()) {
if (token.match(Token.CONST, Token.__CONST, Token.CONSTEXPR)) {
decl.constMember = true;
token = tokens.next();
} else if (token.match(Token.OVERRIDE)) {
type.virtual = true;
// token = tokens.next();
// let through for user defined annotations
}
if (token.match('&', "&&")) {
// ignore?
token = tokens.next();
}
Attribute attr = attribute();
if (attr != null && attr.annotation) {
dcl.type.annotations += attr.javaName;
} else if (attr == null) {
break;
}
}
if (tokens.get().match("->")) {
// auto type
tokens.next();
type = type(context);
}
type = postDeclarator(context, decl, dcl, type);
saudet marked this conversation as resolved.
Show resolved Hide resolved

if (tokens.get().match('{')) {
body();
} else {
Expand Down Expand Up @@ -2527,7 +2507,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
}

// add @Const annotation only for const virtual functions
if (decl.constMember && type.virtual && context.virtualize) {
if (decl.constMember && context.virtualize) {
if (type.annotations.contains("@Const")) {
type.annotations = incorporateConstAnnotation(type.annotations, 2, true);
} else {
Expand All @@ -2536,7 +2516,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
}

// add @Virtual annotation on user request only, inherited through context
if (type.virtual && context.virtualize) {
if (context.virtualize) {
modifiers = "@Virtual" + (decl.abstractMember ? "(true) " : " ")
+ (context.inaccessible ? "protected native " : "public native ");
}
Expand Down Expand Up @@ -2591,7 +2571,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
first = false;
if (extraDecl != null) declList.add(extraDecl);
}
if (type.virtual && context.virtualize) {
if (context.virtualize) {
// Prevent creation of overloads, that are not supported by the generated C++ proxy class.
break;
}
Expand All @@ -2604,6 +2584,38 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
return true;
}

/** Parse function declaration or definition after parameters:
* const, attributes, trailing type, pure virtual functions.
* Updates dcl, decl and/or type accordingly. */
Type postDeclarator(Context context, Declaration decl, Declarator dcl, Type type) throws ParserException {
for (Token token = tokens.get(); !token.match(Token.EOF); token = tokens.get()) {
if (token.match(Token.CONST, Token.__CONST, Token.CONSTEXPR)) {
decl.constMember = true;
token = tokens.next();
} else if (token.match(Token.OVERRIDE)) {
type.virtual = true;
// token = tokens.next();
// let through for user defined annotations
}
if (token.match('&', "&&") || token.match(Token.VOLATILE)) {
// ignore?
token = tokens.next();
}
Attribute attr = attribute();
if (attr != null && attr.annotation) {
dcl.type.annotations += attr.javaName;
} else if (attr == null) {
break;
}
}
if (tokens.get().match("->")) {
// auto type
tokens.next();
type = type(context);
}
return type;
}

boolean variable(Context context, DeclarationList declList) throws ParserException {
int backIndex = tokens.index;
String spacing = tokens.get().spacing;
Expand Down