-
Notifications
You must be signed in to change notification settings - Fork 104
#174 remove line markers from output using -P on the command line #704
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -799,7 +799,8 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, | |
| else | ||
| fileindex = location.fileIndex; | ||
|
|
||
| lineDirective(fileindex, line, location); | ||
| if (!dui.ignoreLineDirectives) | ||
| lineDirective(fileindex, line, location); | ||
| } | ||
|
|
||
| continue; | ||
|
|
@@ -3223,7 +3224,7 @@ std::pair<simplecpp::FileData *, bool> simplecpp::FileDataCache::tryload(FileDat | |
| return {id_it->second, false}; | ||
| } | ||
|
|
||
| auto *const data = new FileData {path, TokenList(path, filenames, {}, outputList)}; | ||
| auto *const data = new FileData {path, TokenList(path, filenames, dui, outputList)}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve Passing |
||
|
|
||
| if (dui.removeComments) | ||
| data->tokens.removeComments(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2731,6 +2731,19 @@ static void location12() | |
| } | ||
|
|
||
|
|
||
| static void location13() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve This test only covers a |
||
| { | ||
| simplecpp::DUI dui; | ||
| dui.ignoreLineDirectives = true; | ||
|
|
||
| const char code[] = | ||
| "#line 3 \"file.c\"\n" | ||
| "__LINE__ __FILE__\n"; | ||
| ASSERT_EQUALS("\n" | ||
| "2 \"\"", | ||
| preprocess(code, dui)); | ||
| } | ||
|
|
||
| static void missingHeader1() | ||
| { | ||
| const char code[] = "#include \"notexist.h\"\n"; | ||
|
|
@@ -4750,6 +4763,7 @@ static void runTests(int argc, char **argv, Input input) | |
| TEST_CASE(location10); | ||
| TEST_CASE(location11); | ||
| TEST_CASE(location12); | ||
| TEST_CASE(location13); | ||
|
|
||
| TEST_CASE(missingHeader1); | ||
| TEST_CASE(missingHeader2); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve
I don't think this implements what #174 asks for.
gcc -E -Psuppresses the linemarkers in the output; it does not ignore#linedirectives in the input. In simplecpp the output markers come fromTokenList::stringify(), which writes#line N "file"whenever the file changes or the line goes backwards. Those are untouched by this PR, so includes still produce markers:Ignoring input
#linealso changes semantics in a way gcc's-Pdoes not:__LINE__/__FILE__and the locations in error messages no longer follow the#linedirective (withgcc -E -P,#line 10 "foo.c"still affects__LINE__/__FILE__).Suggestion: make this an output option instead, e.g. a parameter to
stringify()(or a separate print loop in main.cpp) that skips writing the#linemarkers, and leave the tokenizer/DUI unchanged.