-
Notifications
You must be signed in to change notification settings - Fork 261
Add option to emit source code to stdout #183
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
Conversation
source/cppfront.cpp
Outdated
@@ -346,6 +353,8 @@ class positional_printer | |||
// remain diff-identical | |||
print_extra("\n"); | |||
} | |||
|
|||
cpp1_filename.empty() ? std::cout<<out.str() : file_out<<out.str(); |
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.
I would use a regular if/else statement here. None of the current code use the ternary operator.
@@ -2853,14 +2867,15 @@ auto main(int argc, char* argv[]) -> int | |||
} | |||
|
|||
if (cmdline.arguments().empty()) { | |||
std::cout << "cppfront: error: no input files\n"; | |||
std::cerr << "cppfront: error: no input files\n"; |
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.
Outputting all errors in stderr is better regardless of whether this feature merges.
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.
Good catch, most of them were going to cerr but I missed these ones, thanks!
source/cppfront.cpp
Outdated
if (!cpp1_filename.empty()) file_out.open(cpp1_filename); | ||
pcomments = &comments; | ||
} | ||
|
||
auto is_open() -> bool { | ||
if (out.is_open()) { | ||
if (file_out.is_open() || cpp1_filename.empty()) { | ||
assert (pcomments && "ICE: if out.is_open, pcomments should also be set"); | ||
} | ||
return out.is_open(); | ||
return file_out.is_open() || cpp1_filename.empty(); | ||
} |
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.
I'd suggest moving the cpp1_filename.empty()
tests to a is_stdout_output()
utility function for clarity.
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 useful to remove the need for a temporary file in build systems on at least Linux and macOS.
I wrote some comments in the spirit of improving code clarity.
Regardless of whether this merge outputting all errors to stderr would be better.
The 4 commits should be squashed into one imo.
add helper function - is_stdout_output
Thanks! Why not use the current i.e., |
What would be beneficial is to have the possibility to run cppfront that writes to |
output to std::out if filename equals "stdout" use stringstream
Thanks for your pull request! It looks like this may be your first contribution to cppfront. Before I can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). I think I sent it a few days ago, but let me know if you need me to resend it. |
Thanks! I've decided to take this but tweak the implementation a little, so I've applied it as a separate commit instead of asking you to make a bunch of small tweaks. Thanks again. |
This simple change allows you to build files directly without any intermediate steps. Previously, to compile a file, you had to first create a
*.cpp
file and then use a compiler. If we add the ability to print*.cpp
file content tostdout
, then we can useg++/clang++
options to makestdin
the source.example commands:
for
g++
./cppfront regression-tests/pure2-hello.cpp2 -e | g++-10 -std=c++2a -x c++ -I include/ -O3 -o pure2-hello -
same for
clang
./cppfront regression-tests/pure2-hello.cpp2 -e | clang++ -std=c++2a -x c++ -I include/ -O3 -o pure2-hello -