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

Mark functions from c includes with noexception #84

Merged
merged 1 commit into from
Mar 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Parser(Logger logger, Properties properties, String lineSeparator) {
this.logger = p.logger;
this.properties = p.properties;
this.infoMap = p.infoMap;
this.tokens = new TokenIndexer(infoMap, new Tokenizer(text).tokenize());
this.tokens = new TokenIndexer(infoMap, new Tokenizer(text).tokenize(), false);
this.lineSeparator = p.lineSeparator;
}

Expand Down Expand Up @@ -1518,6 +1518,9 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
return true;
} else if (type.staticMember || context.javaName == null) {
modifiers = "public static native ";
if (tokens.isCFile) {
modifiers = "@NoException " + modifiers;
}
}

List<Declarator> prevDcl = new ArrayList<Declarator>();
Expand Down Expand Up @@ -2667,7 +2670,11 @@ void declarations(Context context, DeclarationList declList) throws ParserExcept
}
}

void parse(Context context, DeclarationList declList, String[] includePath, String include) throws IOException, ParserException {
void parse(Context context,
DeclarationList declList,
String[] includePath,
String include,
boolean isCFile) throws IOException, ParserException {
List<Token> tokenList = new ArrayList<Token>();
File file = null;
String filename = include;
Expand Down Expand Up @@ -2717,7 +2724,7 @@ void parse(Context context, DeclarationList declList, String[] includePath, Stri
token.type = Token.COMMENT;
token.spacing = "\n";
tokenList.add(token);
tokens = new TokenIndexer(infoMap, tokenList.toArray(new Token[tokenList.size()]));
tokens = new TokenIndexer(infoMap, tokenList.toArray(new Token[tokenList.size()]), isCFile);
declarations(context, declList);
}

Expand All @@ -2727,9 +2734,18 @@ public File parse(String outputDirectory, String[] classPath, Class cls) throws
public File parse(File outputDirectory, String[] classPath, Class cls) throws IOException, ParserException {
ClassProperties allProperties = Loader.loadProperties(cls, properties, true);
ClassProperties clsProperties = Loader.loadProperties(cls, properties, false);

// Capture c-includes from "class" and "all" properties
List<String> cIncludes = new ArrayList<>();
cIncludes.addAll(clsProperties.get("platform.cinclude"));
cIncludes.addAll(allProperties.get("platform.cinclude"));

// Capture class includes
List<String> clsIncludes = new ArrayList<String>();
clsIncludes.addAll(clsProperties.get("platform.include"));
clsIncludes.addAll(clsProperties.get("platform.cinclude"));

// Capture all includes
List<String> allIncludes = new ArrayList<String>();
allIncludes.addAll(allProperties.get("platform.include"));
allIncludes.addAll(allProperties.get("platform.cinclude"));
Expand Down Expand Up @@ -2804,14 +2820,16 @@ public File parse(File outputDirectory, String[] classPath, Class cls) throws IO
DeclarationList declList = new DeclarationList();
for (String include : allIncludes) {
if (!clsIncludes.contains(include)) {
parse(context, declList, includePaths, include);
boolean isCFile = cIncludes.contains(include);
parse(context, declList, includePaths, include, isCFile);
}
}
declList = new DeclarationList(declList);
containers(context, declList);
for (String include : clsIncludes) {
if (allIncludes.contains(include)) {
parse(context, declList, includePaths, include);
boolean isCFile = cIncludes.contains(include);
parse(context, declList, includePaths, include, isCFile);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/bytedeco/javacpp/tools/TokenIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
* @author Samuel Audet
*/
class TokenIndexer {
TokenIndexer(InfoMap infoMap, Token[] array) {
TokenIndexer(InfoMap infoMap, Token[] array, boolean isCFile) {
this.infoMap = infoMap;
this.array = array;
this.isCFile = isCFile;
}

/** Set to true to disable temporarily the preprocessor. */
Expand All @@ -45,6 +46,8 @@ class TokenIndexer {
Token[] array = null;
/** The current index, in the array of tokens. Used by {@link #get(int)} and {@link #next()}. */
int index = 0;
/** Whether the file came from the C-include path */
final boolean isCFile;

Token[] filter(Token[] array, int index) {
if (index + 1 < array.length && array[index].match('#') &&
Expand Down