-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1431 from thk123/feature/java-load-class-utility
Created utility function for loading a class file
- Loading branch information
Showing
10 changed files
with
107 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ void concreteMethod() { | |
} | ||
} | ||
|
||
class Extendor extends A { | ||
class Extender extends A { | ||
void method() { | ||
|
||
} | ||
|
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+80 Bytes
(130%)
unit/java_bytecode/java_bytecode_convert_class/Implementor.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*******************************************************************\ | ||
Module: Unit test utilities | ||
Author: DiffBlue Limited. All rights reserved. | ||
\*******************************************************************/ | ||
|
||
#include "load_java_class.h" | ||
#include <catch.hpp> | ||
#include <iostream> | ||
|
||
#include <util/config.h> | ||
#include <util/language.h> | ||
#include <util/suffix.h> | ||
|
||
#include <java_bytecode/java_bytecode_language.h> | ||
|
||
/// Go through the process of loading, typechecking 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. | ||
/// \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) | ||
{ | ||
// We don't expect the .class suffix to allow us to check the name of the | ||
// class | ||
PRECONDITION(!has_suffix(java_class_name, ".class")); | ||
|
||
// Configure the path loading | ||
cmdlinet command_line; | ||
command_line.set("java-cp-include-files", class_path); | ||
config.java.classpath.clear(); | ||
config.java.classpath.push_back(class_path); | ||
|
||
symbol_tablet new_symbol_table; | ||
|
||
std::unique_ptr<languaget>java_lang(new_java_bytecode_language()); | ||
|
||
std::istringstream java_code_stream("ignored"); | ||
null_message_handlert message_handler; | ||
|
||
// Configure the language, load the class files | ||
java_lang->get_language_options(command_line); | ||
java_lang->set_message_handler(message_handler); | ||
java_lang->parse(java_code_stream, java_class_name + ".class"); | ||
java_lang->typecheck(new_symbol_table, ""); | ||
java_lang->final(new_symbol_table); | ||
|
||
// Verify that the class was loaded | ||
const std::string class_symbol_name="java::"+java_class_name; | ||
REQUIRE(new_symbol_table.has_symbol(class_symbol_name)); | ||
const symbolt &class_symbol=new_symbol_table.lookup(class_symbol_name); | ||
REQUIRE(class_symbol.is_type); | ||
const typet &class_type=class_symbol.type; | ||
REQUIRE(class_type.id()==ID_struct); | ||
|
||
// if this fails it indicates the class was not loaded | ||
// Check your working directory and the class path is correctly configured | ||
// as this often indicates that one of these is wrong. | ||
REQUIRE_FALSE(class_type.get_bool(ID_incomplete_class)); | ||
return new_symbol_table; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/*******************************************************************\ | ||
Module: Unit test utilities | ||
Author: DiffBlue Limited. All rights reserved. | ||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Utility for loading and parsing a specified java class file, returning | ||
/// the symbol table generated by this. | ||
|
||
#ifndef CPROVER_SRC_JAVA_BYTECODE_LOAD_JAVA_CLASS_H | ||
#define CPROVER_SRC_JAVA_BYTECODE_LOAD_JAVA_CLASS_H | ||
|
||
#include <util/symbol_table.h> | ||
|
||
symbol_tablet load_java_class( | ||
const std::string &java_class_name, | ||
const std::string &class_path); | ||
|
||
#endif // CPROVER_SRC_JAVA_BYTECODE_LOAD_JAVA_CLASS_H |