diff options
author | Shevek <[email protected]> | 2015-05-19 13:33:20 -0700 |
---|---|---|
committer | Shevek <[email protected]> | 2015-05-19 13:33:20 -0700 |
commit | 26f43a21561cdc5586ba8a8af78c548def36b3f2 (patch) | |
tree | 5159d6f6798eab1504b25798248a0f2f0e5ab3ea | |
parent | 1ebba3bd75e2abea1b70ed36b5ffaa66f91d0649 (diff) |
Fix #27: Don't preprocess pragma tokens.
-rw-r--r-- | src/main/java/org/anarres/cpp/Preprocessor.java | 6 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/PragmaTest.java | 39 | ||||
-rw-r--r-- | src/test/resources/pragma.c | 8 |
3 files changed, 51 insertions, 2 deletions
diff --git a/src/main/java/org/anarres/cpp/Preprocessor.java b/src/main/java/org/anarres/cpp/Preprocessor.java index 59d8ba8..1be126f 100644 --- a/src/main/java/org/anarres/cpp/Preprocessor.java +++ b/src/main/java/org/anarres/cpp/Preprocessor.java @@ -1322,7 +1322,7 @@ public class Preprocessor implements Closeable { NAME: for (;;) { - Token tok = token(); + Token tok = source_token(); switch (tok.getType()) { case EOF: /* There ought to be a newline before EOF. @@ -1344,6 +1344,8 @@ public class Preprocessor implements Closeable { name = tok; break NAME; default: + warning(tok, + "Illegal #" + "pragma " + tok.getText()); return source_skipline(false); } } @@ -1352,7 +1354,7 @@ public class Preprocessor implements Closeable { List<Token> value = new ArrayList<Token>(); VALUE: for (;;) { - tok = token(); + tok = source_token(); switch (tok.getType()) { case EOF: /* There ought to be a newline before EOF. diff --git a/src/test/java/org/anarres/cpp/PragmaTest.java b/src/test/java/org/anarres/cpp/PragmaTest.java new file mode 100644 index 0000000..342bd52 --- /dev/null +++ b/src/test/java/org/anarres/cpp/PragmaTest.java @@ -0,0 +1,39 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.anarres.cpp; + +import com.google.common.base.Charsets; +import com.google.common.io.CharSource; +import com.google.common.io.CharStreams; +import com.google.common.io.Files; +import java.io.File; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.junit.Assert.*; + +/** + * + * @author shevek + */ +public class PragmaTest { + + private static final Logger LOG = LoggerFactory.getLogger(PragmaTest.class); + + @Test + public void testPragma() throws Exception { + File file = new File("build/resources/test/pragma.c"); + assertTrue(file.exists()); + + CharSource source = Files.asCharSource(file, Charsets.UTF_8); + CppReader r = new CppReader(source.openBufferedStream()); + r.getPreprocessor().setListener(new DefaultPreprocessorListener()); + String output = CharStreams.toString(r); + r.close(); + LOG.info("Output: " + output); + // assertTrue(output.contains("absolute-result")); + } +} diff --git a/src/test/resources/pragma.c b/src/test/resources/pragma.c new file mode 100644 index 0000000..6018958 --- /dev/null +++ b/src/test/resources/pragma.c @@ -0,0 +1,8 @@ + +#pragma +#pragma once +#pragma foo(bar) +#pragma #pragma +#pragma #include <stdio.h> +#pragma #include + |