-
Notifications
You must be signed in to change notification settings - Fork 274
Crangler #6367
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
Crangler #6367
Conversation
Two high-level comments:
|
1c86b88
to
df0c3f4
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6367 +/- ##
===========================================
- Coverage 76.00% 75.96% -0.05%
===========================================
Files 1527 1541 +14
Lines 164454 165017 +563
===========================================
+ Hits 125000 125349 +349
- Misses 39454 39668 +214
Continue to review full report at Codecov.
|
{ | ||
if(cmdline.args.empty()) | ||
{ | ||
std::cerr << "please give a configuration file\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.
Use error logging via the message handler instead?
auto id = line.substr(8, space_pos - 8); | ||
auto value = line.substr(space_pos + 1, std::string::npos); | ||
map[id].value = value; |
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.
Do we need to care about #undef
and a possible re-definition?
for(auto &t : tokens) | ||
{ | ||
if(is_identifier(t)) | ||
{ | ||
auto m_it = map.find(t.text); | ||
if(m_it != map.end()) | ||
{ | ||
out << m_it->second.value; | ||
} | ||
else | ||
out << t.text; | ||
} | ||
else | ||
out << t.text; | ||
} |
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.
What about macros that use other macros? What about macros that take parameters (see getc_unlocked(fp)
example in the comment)?
public: | ||
struct definet | ||
{ | ||
optionalt<std::vector<std::string>> parameters; |
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.
Never used (although they'd need to be taken into account).
std::vector<std::string> argv = {"cc", "-E", source_file}; | ||
|
||
for(const auto &include : c_wrangler.includes) | ||
{ | ||
argv.push_back("-I"); | ||
argv.push_back(include); | ||
} | ||
|
||
for(const auto &define : c_wrangler.defines) | ||
argv.push_back(std::string("-D") + define); | ||
|
||
std::ostringstream result; | ||
|
||
auto run_result = run("cc", argv, "", result, ""); | ||
if(run_result != 0) | ||
throw system_exceptiont("preprocessing " + source_file + " has failed"); | ||
|
||
return result.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.
Should we have a Windows/MSVC version thereof?
std::vector<std::string> argv = {"cc", "-E", "-dM", source_file}; | ||
|
||
for(const auto &include : config.includes) | ||
{ | ||
argv.push_back("-I"); | ||
argv.push_back(include); | ||
} | ||
|
||
std::ostringstream result; | ||
|
||
auto run_result = run("cc", argv, "", result, ""); | ||
if(run_result != 0) | ||
throw system_exceptiont("preprocessing " + source_file + " has failed"); | ||
|
||
c_definest defines; | ||
defines.parse(result.str()); | ||
return defines; |
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.
Windows/MSVC?
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.
Approving after some further out-of-band discussion. In addition to my earlier comments: some further tests and/or documentation would be really helpful.
84c6a3b
to
daacc1f
Compare
9a8ddb6
to
39462d6
Compare
c4b4049
to
6816e48
Compare
This is a command-line utility that makes changes to a preprocessed C file that are prescribed in a JSON configuration file. The initial set of transformations is as follows. * add a contract (pre/post/assigns) to a named C function * add a loop invariant to a loop identified by the name of the function its in and a loop number * remove the 'static' storage classifier from a function The resulting source file is written to standard output or to file specified in the JSON configuration.
To avoid having to list large numbers of functions for mangling, permit regular expressions as function name entries in the JSON configuration file.
Just like functions, objects can be file-local. To support accessing them, permit removing "static" from objects as well.
We might still want to add a capability to perform name mangling, but once done we should be able to get rid of the |
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 approval for the Cmake/make aspects as these were blocked by OpenSource/Codeowner
This adds a new command-line tool, which replaces current flows that enact changes to the program that is analysed. The new flow is to make these changes before parsing, which enables more far-reaching changes and changes that depend on scoped identifiers.