Skip to content

Allow callers of load_java_class to pass the name of the main function #1699

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions unit/testing-utils/load_java_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,39 @@

#include <java_bytecode/java_bytecode_language.h>

/// Go through the process of loading, typechecking and finalising loading a
/// Go through the process of loading, type-checking and finalising loading a
/// specific class file to build the symbol table.
/// \param java_class_name: The name of the class file to load. It should not
/// include the .class extension.
/// \param class_path: The path to load the class from. Should be relative to
/// the unit directory.
/// \param main: The name of the main function or "" to use the default
/// behaviour to find a main function.
/// \return The symbol table that is generated by parsing this file.
symbol_tablet load_java_class(
const std::string &java_class_name,
const std::string &class_path)
const std::string &class_path,
const std::string &main)
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the documentation with an explanation of the default behaviour ("" for main)

{
return load_java_class(
java_class_name, class_path, new_java_bytecode_language());
java_class_name, class_path, main, new_java_bytecode_language());
}

/// Go through the process of loading, type-checking and finalising loading a
/// specific class file to build the symbol table.
/// \param java_class_name: The name of the class file to load. It should not
/// include the .class extension.
/// \param class_path: The path to load the class from. Should be relative to
/// the unit directory.
/// \param main: The name of the main function or "" to use the default
/// behaviour to find a main function.
/// \param java_lang: The language implementation to use for the loading,
/// which will be destroyed by this function.
/// \return The symbol table that is generated by parsing this file.
symbol_tablet load_java_class(
const std::string &java_class_name,
const std::string &class_path,
const std::string &main,
std::unique_ptr<languaget> &&java_lang)
{
// We expect the name of the class without the .class suffix to allow us to
Expand All @@ -58,6 +73,7 @@ symbol_tablet load_java_class(
command_line.set("java-cp-include-files", class_path);
config.java.classpath.clear();
config.java.classpath.push_back(class_path);
config.main = main;

// Add the language to the model
language_filet &lf=lazy_goto_model.add_language_file(filename);
Expand Down
4 changes: 3 additions & 1 deletion unit/testing-utils/load_java_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

symbol_tablet load_java_class(
const std::string &java_class_name,
const std::string &class_path);
const std::string &class_path,
const std::string &main = "");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a sensible default because config.main == "" => use the main method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is now indicated in the documentation.


symbol_tablet load_java_class(
const std::string &java_class_name,
const std::string &class_path,
const std::string &main,
std::unique_ptr<languaget> &&java_lang);

#endif // CPROVER_TESTING_UTILS_LOAD_JAVA_CLASS_H