diff options
author | Shevek <[email protected]> | 2009-02-06 01:10:48 +0000 |
---|---|---|
committer | Shevek <[email protected]> | 2009-02-06 01:10:48 +0000 |
commit | 24cb38b8398ddc3bc70a544c98a0acb3366ff8bc (patch) | |
tree | 84adb390dd167c189f94a7cf1952ca36903aeda6 /src/java/org | |
parent | aba944f23747fdf35e890020cdbbca722bbaaacf (diff) |
start on objc
Diffstat (limited to 'src/java/org')
-rw-r--r-- | src/java/org/anarres/cpp/Feature.java | 5 | ||||
-rw-r--r-- | src/java/org/anarres/cpp/Macro.java | 25 | ||||
-rw-r--r-- | src/java/org/anarres/cpp/Preprocessor.java | 45 | ||||
-rw-r--r-- | src/java/org/anarres/cpp/Source.java | 3 |
4 files changed, 71 insertions, 7 deletions
diff --git a/src/java/org/anarres/cpp/Feature.java b/src/java/org/anarres/cpp/Feature.java index 935a94b..649f135 100644 --- a/src/java/org/anarres/cpp/Feature.java +++ b/src/java/org/anarres/cpp/Feature.java @@ -32,5 +32,8 @@ public enum Feature { /** Preserves comments in the lexed output. */ KEEPCOMMENTS, VERBOSE, - DEBUG + DEBUG, + + /** Supports lexing of objective-C. */ + OBJCSYNTAX } diff --git a/src/java/org/anarres/cpp/Macro.java b/src/java/org/anarres/cpp/Macro.java index c357493..b62810b 100644 --- a/src/java/org/anarres/cpp/Macro.java +++ b/src/java/org/anarres/cpp/Macro.java @@ -29,6 +29,7 @@ import java.util.List; * extra tokens {@link Token#M_ARG} and {@link Token#M_STRING}. */ public class Macro { + private Source source; private String name; /* It's an explicit decision to keep these around here. We don't * need to; the argument token type is M_ARG and the value @@ -38,13 +39,35 @@ public class Macro { private boolean variadic; private List<Token> tokens; - public Macro(String name) { + public Macro(Source source, String name) { + this.source = source; this.name = name; this.args = null; this.variadic = false; this.tokens = new ArrayList<Token>(); } + public Macro(String name) { + this(null, name); + } + + /** + * Sets the Source from which this macro was parsed. + */ + public void setSource(Source s) { + this.source = s; + } + + /** + * Returns the Source from which this macro was parsed. + * + * This method may return null if the macro was not parsed + * from a regular file. + */ + public Source getSource() { + return source; + } + /** * Returns the name of this macro. */ diff --git a/src/java/org/anarres/cpp/Preprocessor.java b/src/java/org/anarres/cpp/Preprocessor.java index 195a822..2f3e593 100644 --- a/src/java/org/anarres/cpp/Preprocessor.java +++ b/src/java/org/anarres/cpp/Preprocessor.java @@ -74,8 +74,24 @@ is what the flags mean: */ public class Preprocessor implements Closeable { - private static final Macro __LINE__ = new Macro("__LINE__"); - private static final Macro __FILE__ = new Macro("__FILE__"); + private static final Source INTERNAL = new Source() { + @Override + public Token token() + throws IOException, + LexerException { + throw new LexerException("Cannot read from " + getName()); + } + @Override + public String getPath() { + return "<internal-data>"; + } + @Override + public String getName() { + return "internal data"; + } + }; + private static final Macro __LINE__ = new Macro(INTERNAL, "__LINE__"); + private static final Macro __FILE__ = new Macro(INTERNAL, "__FILE__"); private List<Source> inputs; @@ -87,6 +103,7 @@ public class Preprocessor implements Closeable { /* Support junk to make it work like cpp */ private List<String> quoteincludepath; /* -iquote */ private List<String> sysincludepath; /* -I */ + private List<String> frameworkspath; private Set<Feature> features; private Set<Warning> warnings; private VirtualFileSystem filesystem; @@ -383,10 +400,28 @@ public class Preprocessor implements Closeable { } /** + * Sets the Objective-C frameworks path used by this Preprocessor. + */ + /* Note for future: Create an IncludeHandler? */ + public void setFrameworksPath(List<String> path) { + this.frameworkspath = path; + } + + /** + * Returns the Objective-C frameworks path used by this + * Preprocessor. + * + * This list may be freely modified by user code. + */ + public List<String> getFrameworksPath() { + return frameworkspath; + } + + /** * Returns the Map of Macros parsed during the run of this * Preprocessor. */ - protected Map<String,Macro> getMacros() { + public Map<String,Macro> getMacros() { return macros; } @@ -712,7 +747,7 @@ public class Preprocessor implements Closeable { } else if (m == __FILE__) { StringBuilder buf = new StringBuilder("\""); - String name = source.getName(); + String name = getSource().getName(); if (name == null) name = "<no file>"; for (int i = 0; i < name.length(); i++) { @@ -799,7 +834,7 @@ public class Preprocessor implements Closeable { return source_skipline(false); } - Macro m = new Macro(name); + Macro m = new Macro(getSource(), name); List<String> args; tok = source_token(); diff --git a/src/java/org/anarres/cpp/Source.java b/src/java/org/anarres/cpp/Source.java index d69a5c2..49277c7 100644 --- a/src/java/org/anarres/cpp/Source.java +++ b/src/java/org/anarres/cpp/Source.java @@ -143,6 +143,9 @@ public abstract class Source implements Iterable<Token>, Closeable { return null; } + /** + * Returns the human-readable name of the current Source. + */ /* pp */ String getName() { Source parent = getParent(); if (parent != null) |