Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

peterschrammel
Copy link
Member

@peterschrammel peterschrammel commented May 5, 2018

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.

Copy link
Collaborator

@tautschnig tautschnig left a 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.

@@ -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)
Copy link
Collaborator

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"

Copy link
Collaborator

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?

Copy link
Member Author

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

@@ -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)
Copy link
Collaborator

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.

OBJ += ../php/php$(LIBEXT)
CP_CXXFLAGS += -DHAVE_PHP
endif

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate commit (see above).

}
std::string description() const override
{
return "ANSI-C 99";
Copy link
Collaborator

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.


irep_idt id() const override
{
return ID_C;
Copy link
Collaborator

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).

}
std::string description() const override
{
return "ANSI-C 99";
Copy link
Collaborator

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"

virtual std::set<std::string> extensions() const
{
return std::set<std::string>();
}
Copy link
Collaborator

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.

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/std_code.h>
#include <util/symbol_table.h>
Copy link
Collaborator

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>
Copy link
Collaborator

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?

@peterschrammel
Copy link
Member Author

@tautschnig, this is ready for re-review.

@peterschrammel
Copy link
Member Author

The TG bump needs to pass before merging this.

#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
Copy link
Collaborator

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.)

std::string &name,
const namespacet &ns) const;

virtual ~language_infot()
Copy link
Collaborator

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;

@peterschrammel peterschrammel force-pushed the language-info branch 6 times, most recently from d34a730 to f1fe412 Compare May 7, 2018 22:42
@peterschrammel
Copy link
Member Author

@tautschnig, please check whether the last commit is what you intended.

@tautschnig
Copy link
Collaborator

@tautschnig, please check whether the last commit is what you intended.

Yes, thank you very much!

@peterschrammel
Copy link
Member Author

TG bump passing...

Copy link
Contributor

@thk123 thk123 left a 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


Module:

Author: Daniel Kroening, [email protected]
Copy link
Contributor

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?

Copy link
Collaborator

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.

{
}

// conversion from expression into string
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not = 0?

Copy link
Member Author

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.

public:
// language id / description

virtual irep_idt id() const = 0;
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor

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

return nullptr;

std::string extension=
std::string(filename, ext_pos+1, std::string::npos);

if(extension=="")
if(extension.empty())
Copy link
Contributor

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 🙂

e_it++)
if(_stricmp(extension.c_str(), e_it->c_str())==0)
return l_it->factory();
for(const auto &ext : extensions)
Copy link
Contributor

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?)

Copy link
Contributor

@thk123 thk123 left a 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

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a 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.

Copy link
Collaborator

@martin-cs martin-cs left a 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
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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.


Module:

Author: Daniel Kroening, [email protected]
Copy link
Collaborator

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) + "'");
}
Copy link
Collaborator

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?

Copy link
Member Author

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.
Copy link
Contributor

@mgudemann mgudemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kroening
Copy link
Member

kroening commented May 8, 2018

langapi is dead and deprecated!

Copy link
Contributor

@smowton smowton left a 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!

@smowton
Copy link
Contributor

smowton commented May 8, 2018

@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?

@peterschrammel
Copy link
Member Author

@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.

@TGWDB
Copy link
Contributor

TGWDB commented Feb 22, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants