aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShevek <[email protected]>2013-12-28 07:43:37 -0800
committerShevek <[email protected]>2013-12-28 07:43:37 -0800
commit5d0f965e856b587148e4982d7a57ae9290081536 (patch)
tree0dba86d7c472351f92cea74cacc25ee83cb74827 /src
parent4193b7effd117c31c15452aa7beef48ee29d79c2 (diff)
Preprocessor: Look at include_next; some null-guards.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/anarres/cpp/Preprocessor.java21
-rw-r--r--src/main/java/org/anarres/cpp/Source.java2
2 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/org/anarres/cpp/Preprocessor.java b/src/main/java/org/anarres/cpp/Preprocessor.java
index 6fb3249..e4ecdc1 100644
--- a/src/main/java/org/anarres/cpp/Preprocessor.java
+++ b/src/main/java/org/anarres/cpp/Preprocessor.java
@@ -1104,17 +1104,22 @@ public class Preprocessor implements Closeable {
/**
* Handles an include directive.
*/
- private void include(String parent, int line,
- @Nonnull String name, boolean quoted)
+ private void include(
+ @CheckForNull String parent, int line,
+ @Nonnull String name, boolean quoted, boolean next)
throws IOException,
LexerException {
VirtualFile pdir = null;
if (quoted) {
- VirtualFile pfile = filesystem.getFile(parent);
- pdir = pfile.getParentFile();
- VirtualFile ifile = pdir.getChildFile(name);
- if (include(ifile))
- return;
+ if (parent != null) {
+ VirtualFile pfile = filesystem.getFile(parent);
+ pdir = pfile.getParentFile();
+ }
+ if (pdir != null) {
+ VirtualFile ifile = pdir.getChildFile(name);
+ if (include(ifile))
+ return;
+ }
if (include(quoteincludepath, name))
return;
}
@@ -1187,7 +1192,7 @@ public class Preprocessor implements Closeable {
}
/* Do the inclusion. */
- include(source.getPath(), tok.getLine(), name, quoted);
+ include(source.getPath(), tok.getLine(), name, quoted, next);
/* 'tok' is the 'nl' after the include. We use it after the
* #line directive. */
diff --git a/src/main/java/org/anarres/cpp/Source.java b/src/main/java/org/anarres/cpp/Source.java
index 532f5fc..ef20803 100644
--- a/src/main/java/org/anarres/cpp/Source.java
+++ b/src/main/java/org/anarres/cpp/Source.java
@@ -19,6 +19,7 @@ package org.anarres.cpp;
import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
+import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import static org.anarres.cpp.Token.*;
@@ -127,6 +128,7 @@ public abstract class Source implements Iterable<Token>, Closeable {
* it will ask the parent Source, and so forth recursively.
* If no Source on the stack is a FileLexerSource, returns null.
*/
+ @CheckForNull
/* pp */ String getPath() {
Source parent = getParent();
if (parent != null)