shevek / jcpp Goto Github PK
View Code? Open in Web Editor NEWThe C Preprocessor as a Java library
Home Page: http://www.anarres.org/projects/jcpp/
License: Apache License 2.0
The C Preprocessor as a Java library
Home Page: http://www.anarres.org/projects/jcpp/
License: Apache License 2.0
Hello!
Is jcpp
capable of lexing and removing C++ style line comments?
// This is a comment
I can't see anything in the API to do this, and there doesn't seem to be a Feature
value that would enable it. I'm seeing line comments in the output of the preprocessor, so presumably it doesn't do it by default, either.
Hi Shevek,
In pop_source() you have:
return line_token(t.getLine() + 1, t.getName(), "2");
It seems like there should be no "+ 1" there since it creates
line number mismatch.
Thanks,
Igor
Issue separated from #23 as that has a patch and this has not.
jcpp should support __VA_ARGS__
.
Here's a fix ready to be cherry-picked from JNAerator's fork:
(can send a PR, but it currently depends on #4)
Just wanted to try out this project, but ran into some issues. After patching #40, I run into this:
$ ./gradlew run --args="--help"
> Task :compileJava
[...]
> Task :run FAILED
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NullPointerException
at org.anarres.cpp.BuildMetadata.<init>(BuildMetadata.java:40)
at org.anarres.cpp.BuildMetadata.getInstance(BuildMetadata.java:29)
at org.anarres.cpp.Main.run(Main.java:61)
at org.anarres.cpp.Main.main(Main.java:51)
FAILURE: Build failed with an exception.
[...]
It looks like it's failing to load /META-INF/jcpp.properties
from the built resources. I don't see any file with that name, though.
It links to http://shevek.github.io/jcpp/docs/cobertura/, but that page returns a 404 Not Found error.
gcc pack more than six sequent empty line into one line with using of # directive
like this one:
before:
\r
\r
\r
\r
\r
\r
void foo(){}
after:
# 6 "filename.ext"
void foo(){}
https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
this is dramatically decrease size of output file
When we define a multi-line macro, such as:
6: #define THREE 1 \
7: + \
8: 2
we could expect that calling token.getLine() for Token representing number "2" would return line 8, but surprisingly the entire define definition is regarded as one-line preprocessor directive, so the result is 6.
The tokens list representing macro THREE:
[HASH@6,0]:"#"
[IDENTIFIER@6,1]:"define"
[IDENTIFIER@6,8]:"A"
[(@6,9]:"("
[IDENTIFIER@6,10]:"a"
[,@6,11]:","
[IDENTIFIER@6,13]:"b"
[)@6,14]:")"
[IDENTIFIER@6,16]:"a"
[WHITESPACE@6,17]:" "
[+@6,21]:"+"
[WHITESPACE@6,22]:" "
[IDENTIFIER@6,26]:"b"
[NL@6,27]:"
I'm aware that tokens list in Macro is not public, but still line and column numbers should be correct.
Will this work?
}
if (include(quoteincludepath, name))
return;
+ } else {
+ int idx = name.indexOf('/');
+ if (idx != -1) {
+ String frameworkName = name.substring(0, idx);
+ String headerName = name.substring(idx + 1);
+ String headerPath = frameworkName + ".framework/Headers/" + headerName;
+ if (include(frameworkspath, headerPath))
+ return;
+ }
}
if (include(sysincludepath, name))
Hello there!
I thought about extending jcpp to support preprocessing of GLSL (OpenGL Shading Language). This would require to add new preprocessor directives such as "#version" and "#extension", which can be basically ignored in my case. I'm currently modifying the classes as I need them but you might be interested in adding the ability to just extend your preprocessor in a more reasonable fashion for such use cases. Such as adding hooks or just subclassing Preprocessor or something similar.
Regards
Holger
Hello!
Any chance you'll be publishing Automatic-Module-Name
entries for the jcpp
jar?
http://blog.joda.org/2017/05/java-se-9-jpms-automatic-modules.html
I'd suggest: Automatic-Module-Name: org.anarres.jcpp
Although jcpp parses #include_next
, it doesn't seem to skip the current file's directory.
See http://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html
Here's a fix from JNAerator's fork:
Preprocessor hangs up when the /* */ comment is not closed.
The simplest possible test case:
/*<EOF>
Hi Shevek,
In Preprocessor.pragma() you use token() (2 times). I am almost sure
it meant to be source_token() or _token(). Am I right?Thanks,
Igor
There were two problems using the ANT build task for JCPP under windows:
1- "etc/global.xml", line 15
there is an absolute path reference to /usr/share/ant/lib
It is better to use the ANT property ${ant.home} instead, so the script will also work in different installations:
<fileset dir="${ant.home}/lib">
2- "etc/targets/global-javadoc.xml", line 51:
the javadoc task makes a reference to directory "${global.dir.etc}/javadoc" ()
When I use a fresh copy from the sources, this directory does not exists, so the javadoc task fails (aborting the build process). A good workaround is to create this directory if it does not exists, before the javadoc task is called. So I've inserted the following two lines at line 6 of "etc/targets/global-javadoc.xml":
<!-- create javadoc etc directory if it does not exist-->
<mkdir dir="${global.dir.etc}/javadoc" />
Hello! The following file yields a ClassCastException
:
#define EXAMPLE_X 'a'
#if EXAMPLE == EXAMPLE_X
#endif
I have a small repro case here:
https://github.com/io7m/jcpp-bug-20170423
The bug appears to be at:
https://github.com/shevek/jcpp/blob/master/src/main/java/org/anarres/cpp/Preprocessor.java#L1598
The value held by the token isn't a Character
but a String
.
JCPP cannot handle absolute paths in include directives. They are treated as relative. For example,
will not work. On the other hand
will work looking for the file in the current directory.
Input (groovy):
def pp = new Preprocessor();
pp.addInput(new StringLexerSource("""
#define ONE(arg) one_##arg
#define TWO(arg) ONE(two_##arg)
TWO(good)
TWO( /* evil newline */
bad)
ONE(good)
ONE( /* evil newline */
bad)
""", true))
println new CppReader(pp).text.trim()
Output:
one_two_good
one_two_ bad
one_good
one_
bad
Expected output:
one_two_good
one_two_bad
one_good
one_bad
There is no wiki either.
Lots of headers on Windows use #pragma once
instead of ifndef
guards (or at least, used to use it when I last checked), so this feature is quite important.
JNAerator uses a hack that involves overriding Preprocessor.include (using a forked jcpp where this is possible), but it would be great if jcpp had native support for this (err... maybe it does already, thanks for letting me know in that case :-))
Since this commit ca42036 the occurrence of minus sign followed by a number constant is returned by preprocessor as a single token. I wonder why the minus sign is not considered to be a separate token (as it was previously)? Is it required by some preprocessor specification?
The Input Stream:
aaa,,
Parses as:
Returning fresh token [IDENTIFIER@1,0]:"aaa"
pp: Returning [IDENTIFIER@1,0]:"aaa"
Returning fresh token [,@1,3]:","
pp: Returning [,@1,3]:","
Returning fresh token [,@1,3]:","
pp: Returning [,@1,3]:","
pp: Returning [EOF]:<265>
The column information of the seconds comma should be 4.
The JCPP version is 1.2.6
ochafik@5b44dee#commitcomment-5110790
Always call getMacro() not macros.get() in Preprocessor.
When Main run fails, it does not return with nonzero exit code, which means that in a shell script, an invoker does not have a way to know that the process failed.
Hi!
When comments are not passed through (KEEPCOMMENTS or KEEPALLCOMMENTS
are not set), it is better to generate #line after /* ... */ or to pull
new lines form the comment to preserve in-to-out line
numbering correspondence. Of course, whoever wants the correspondence
has a way around: enable comments.
Thanks,
Igor
NullPointerException
is thrown for source.setActive(true)
in Preprocessor._token()
when #endif
is missing and #ifdef
is satisfied.
Here is a simple test case:
#define D
#ifdef D
int a = 1;
#else
int a = 2;
<EOF>
Similarly for:
#ifndef D
int a = 1;
#else
int a = 2;
<EOF>
Float number "0.1" parsed as three tokens: octal numeric "0", dot ".", numeric "0" intead of float numeric "0.1".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.