-
Notifications
You must be signed in to change notification settings - Fork 273
Factor out language_infot from languaget #2157
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
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 decided to ignore the don't-review-request... Just one genuine error spotted, otherwise nit-picks.
src/clobber/CMakeLists.txt
Outdated
@@ -25,8 +25,6 @@ target_link_libraries(clobber-lib | |||
) | |||
|
|||
add_if_library(clobber-lib bv_refinement) | |||
add_if_library(clobber-lib specc) | |||
add_if_library(clobber-lib php) |
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.
Wishlist: Could those changes (and related ones) go in a separate commit, please?
@@ -38,8 +38,6 @@ Author: Daniel Kroening, [email protected] | |||
|
|||
#include <cbmc/version.h> | |||
|
|||
// #include "clobber_instrumenter.h" | |||
|
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.
Maybe a "Clobber: cleanup" commit?
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.
Moved into a separate PR: #2159
src/goto-analyzer/CMakeLists.txt
Outdated
@@ -23,8 +23,6 @@ target_link_libraries(goto-analyzer-lib | |||
|
|||
add_if_library(goto-analyzer-lib java_bytecode) | |||
add_if_library(goto-analyzer-lib jsil) | |||
add_if_library(goto-analyzer-lib specc) | |||
add_if_library(goto-analyzer-lib php) |
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.
To go in the cleanup commit.
src/clobber/Makefile
Outdated
OBJ += ../php/php$(LIBEXT) | ||
CP_CXXFLAGS += -DHAVE_PHP | ||
endif | ||
|
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.
Separate commit (see above).
src/ansi-c/ansi_c_language_info.h
Outdated
} | ||
std::string description() const override | ||
{ | ||
return "ANSI-C 99"; |
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.
Correct copy&paste, but we have meanwhile gone well beyond "ANSI" C.
src/jsil/jsil_language_info.h
Outdated
|
||
irep_idt id() const override | ||
{ | ||
return ID_C; |
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.
Copy&paste error: "jsil" (should probably introduce an ID_jsil
).
src/jsil/jsil_language_info.h
Outdated
} | ||
std::string description() const override | ||
{ | ||
return "ANSI-C 99"; |
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.
Copy&paste error, was "Javascript Intermediate Language"
src/langapi/language_info.h
Outdated
virtual std::set<std::string> extensions() const | ||
{ | ||
return std::set<std::string>(); | ||
} |
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.
Shouldn't these also be = 0
? Those default implementations make no sense.
unit/analyses/dependence_graph.cpp
Outdated
#include <util/arith_tools.h> | ||
#include <util/c_types.h> | ||
#include <util/std_code.h> | ||
#include <util/symbol_table.h> |
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.
Nit pick: I'm not sure this is a value-adding change? We usually do grouping by directories.
#include <testing-utils/catch.hpp> | ||
#include <util/expr.h> | ||
#include <util/namespace.h> | ||
#include <util/std_code.h> |
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.
As above: does this add value?
51ea214
to
8f35ddb
Compare
8f35ddb
to
37a2317
Compare
@tautschnig, this is ready for re-review. |
The TG bump needs to pass before merging this. |
src/cbmc/cbmc_languages.cpp
Outdated
#include <ansi-c/ansi_c_language.h> | ||
#include <cpp/cpp_language.h> | ||
#include <ansi-c/ansi_c_language_info.h> | ||
#include <cpp/cpp_language_info.h> | ||
|
||
#ifdef HAVE_JSIL |
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.
Would you be ok to add a commit to this PR that removes all occurrences of HAVE_JSIL
from the codebase? It's not used consistently and thus doesn't really make sense. (Else it can happen in some later PR, once this is merged.)
src/langapi/language_info.h
Outdated
std::string &name, | ||
const namespacet &ns) const; | ||
|
||
virtual ~language_infot() |
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.
Nit pick: you might use = default;
d34a730
to
f1fe412
Compare
@tautschnig, please check whether the last commit is what you intended. |
Yes, thank you very much! |
f1fe412
to
5cc171e
Compare
TG bump passing... |
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.
Just some minor changes, no need for re-review, will approve once I've checked TG bump
src/ansi-c/ansi_c_language_info.cpp
Outdated
|
||
Module: | ||
|
||
Author: Daniel Kroening, [email protected] |
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 this be Diffblue ltd
?
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.
If it is a new file written by a Diffblue employee, yes.
src/cpp/cpp_language_info.h
Outdated
{ | ||
} | ||
|
||
// conversion from expression into string |
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.
Either remove or turn into doxygen comment
|
||
Module: Java Bytecode Language | ||
|
||
Author: Peter Schrammel |
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.
And this should probably also be Diffblue ltd?
/// \param ns: a namespace | ||
/// \return false if conversion succeeds | ||
virtual bool | ||
from_expr(const exprt &expr, std::string &code, const namespacet &ns) const; |
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.
Why not = 0
?
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.
Yes, that could be considered.
src/langapi/language_info.h
Outdated
public: | ||
// language id / description | ||
|
||
virtual irep_idt id() const = 0; |
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.
Please document these
for(const auto &language : languages) | ||
if(mode == language.mode) | ||
return language.factory(); | ||
for(const auto &language_info : languages) |
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.
Inner content spread over multiple lines so please wrap in braces
/// \return the language info (assumes that the language has been registered) | ||
const language_infot &get_language_info_from_mode(const irep_idt &mode) | ||
{ | ||
for(const auto &language_info : languages) |
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.
Inner content spread over multiple lines so please wrap in braces
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.
Also mild preference to use above method
src/langapi/mode.cpp
Outdated
return nullptr; | ||
|
||
std::string extension= | ||
std::string(filename, ext_pos+1, std::string::npos); | ||
|
||
if(extension=="") | ||
if(extension.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.
Random fixes makes this long commit even harder to review - please avoid in future 🙂
src/langapi/mode.cpp
Outdated
e_it++) | ||
if(_stricmp(extension.c_str(), e_it->c_str())==0) | ||
return l_it->factory(); | ||
for(const auto &ext : extensions) |
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.
to avoid having two variables called extension
(one abbreviated) could you rename either the original or the new one to something more descriptive? (e.g. language_extension
vs file_extension
perhaps?)
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.
TG pointer looks OK too
5cc171e
to
4cec117
Compare
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.
Looks like a reasonable cleanup to me.
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.
Perhaps I am being unobservant but it seems like this could also tidy up some of the expr2c, expr2java, expr2internalstringinmadeuplanguage, expr2yetanotherformatbutwithdifferentprecedence mess.
@@ -16,6 +16,7 @@ target_link_libraries(cbmc-lib | |||
goto-instrument-lib | |||
goto-programs | |||
goto-symex | |||
jsil |
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.
The "remove conditional inclusion of JSIL" patch seems to be unrelated to the PR. It may well be a good idea (Do we need conditional compilation of features? If so, what is the policy?) but at the moment it is not explained or justified.
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.
See thread above - requested by @tautschnig due to inconsistent use.
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 agree that it would better fit a separate PR, but that PR would necessarily depend on this one because of overlapping changes, hence adding it in here seemed ok to me.
src/ansi-c/ansi_c_language_info.cpp
Outdated
|
||
Module: | ||
|
||
Author: Daniel Kroening, [email protected] |
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.
If it is a new file written by a Diffblue employee, yes.
} | ||
|
||
INVARIANT(false, "unregistered language `" + id2string(mode) + "'"); | ||
} |
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.
Unreachable? Is this really an invariant?
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.
You may call it that way, but I'd like to attach an error message to it ;)
Previously, using language-specific methods such as from_expr() required creating a new languaget instance which could be potentially costly. This commit introduces a language_infot class that offers language-specific methods that don't require parsing functionality. language_infot is now used for language registration (instead of language_entryt). The immutable registered *_language_infot instances are shared among the corresponding *_languaget instances that are requested by the get_language_from_* functions.
4cec117
to
17e1325
Compare
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.
LGTM
langapi is dead and deprecated! |
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.
Looks great, thanks for making the effort!
@kroening how would you prefer to do a language-specific thing, like "for the language relating to this symbol, get usual file extension" for example? |
@smowton, the suggestion is to move the language-specific dispatch from the global language registry to the driver program. I.e. everything that requires something language-specific will be parametrised by a function that performs the language-specific dispatch. The presumption is that this will only be necessary in very few cases (show_goto_trace, etc). The advantage is that we can get rid of a global variable. |
This appears to be a nice to do, but is quite out of date. Closing since there seems to be a low likelihood of progress on this at the moment. Encourage the author to rebase and reopen if they would like this merged. If you believe this closure is erroneous please reopen this PR. |
Prerequisite for #2127 and #2098 to make access to language-specific methods more efficient.
Previously, using language-specific methods such as
from_expr() required creating a new languaget instance
which could be potentially costly.
This PR introduces a language_infot class that offers
language-specific methods that don't require parsing
functionality. language_infot is now used for language
registration (instead of language_entryt). The immutable
registered *_language_infot instances are shared among the
corresponding languaget instances that are requested by
the get_language_from functions.