Skip to content

Commit b473638

Browse files
author
Matthias Güdemann
committed
take comments into account
1 parent 3d009a9 commit b473638

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

src/java_bytecode/jar_file.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Author: Daniel Kroening, [email protected]
88

99
#include <cstring>
1010
#include <cassert>
11-
#include <json/json_parser.h>
1211
#include <unordered_set>
13-
#include "jar_file.h"
12+
13+
#include <json/json_parser.h>
1414
#include <util/suffix.h>
15-
#include <iostream>
15+
#include "jar_file.h"
1616
/*******************************************************************\
1717
1818
Function: jar_filet::open
@@ -54,9 +54,11 @@ void jar_filet::open(
5454
get_message_handler(),
5555
json_cp_config))
5656
throw "cannot read JSON input configuration for JAR loading";
57-
assert(json_cp_config.is_object() && "JSON has wrong format");
57+
if(!json_cp_config.is_object())
58+
throw "the JSON file has a wrong format";
5859
jsont include_files=json_cp_config["classFiles"];
59-
assert(include_files.is_array() && "JSON has wrong format");
60+
if(!include_files.is_array())
61+
throw "the JSON file has a wrong format";
6062
for(const jsont &file_entry : include_files.array)
6163
{
6264
assert(file_entry.is_string());
@@ -84,7 +86,7 @@ void jar_filet::open(
8486
add_file|=std::regex_match(file_name, string_matcher, regex_matcher);
8587
// load .class file only if it is in the match set
8688
else
87-
add_file|=set_matcher.count(file_name)>0;
89+
add_file|=set_matcher.find(file_name)!=set_matcher.end();
8890
if(add_file)
8991
{
9092
index.push_back(file_name);

src/java_bytecode/jar_file.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ class jar_filet:public messaget
2222
{
2323
public:
2424
jar_filet():mz_ok(false) { }
25-
inline explicit jar_filet(const std::string &file_name) { }
2625

2726
~jar_filet();
2827

2928
void open(std::string &java_cp_include_files, const std::string &);
3029

3130
// Test for error; 'true' means we are good.
32-
inline explicit operator bool() const { return mz_ok; }
31+
explicit operator bool() const { return mz_ok; }
3332

3433
typedef std::vector<std::string> indext;
3534
indext index;
@@ -45,8 +44,6 @@ class jar_filet:public messaget
4544
protected:
4645
mz_zip_archive zip;
4746
bool mz_ok;
48-
std::string matcher;
49-
std::map<int, int> index_map;
5047
};
5148

5249
class jar_poolt:public messaget
@@ -56,9 +53,11 @@ class jar_poolt:public messaget
5653
{
5754
java_cp_include_files=_java_cp_include_files;
5855
}
56+
5957
jar_filet &operator()(const std::string &file_name)
6058
{
61-
assert(!java_cp_include_files.empty() && "class regexp cannot be empty");
59+
if(java_cp_include_files.empty())
60+
throw "class regexp cannot be empty";
6261
file_mapt::iterator it=file_map.find(file_name);
6362
if(it==file_map.end())
6463
{

src/java_bytecode/java_bytecode_language.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,36 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
5656
lazy_methods_mode=LAZY_METHODS_MODE_CONTEXT_INSENSITIVE;
5757
else
5858
lazy_methods_mode=LAZY_METHODS_MODE_EAGER;
59+
5960
if(cmd.isset("java-cp-include-files"))
60-
java_cp_include_files=cmd.get_value("java-cp-include-files");
61-
else
62-
java_cp_include_files=".*";
63-
// load file list from JSON file
64-
if(java_cp_include_files[0]=='@')
6561
{
66-
jsont json_cp_config;
67-
if(parse_json(
68-
java_cp_include_files.substr(1),
69-
get_message_handler(),
70-
json_cp_config))
71-
throw "cannot read JSON input configuration for JAR loading";
72-
assert(json_cp_config.is_object() && "JSON has wrong format");
73-
jsont include_files=json_cp_config["jar"];
74-
assert(include_files.is_array() && "JSON has wrong format");
75-
// add jars from JSON config file to classpath
76-
for(const jsont &file_entry : include_files.array)
62+
java_cp_include_files=cmd.get_value("java-cp-include-files");
63+
// load file list from JSON file
64+
if(java_cp_include_files[0]=='@')
7765
{
78-
assert(file_entry.is_string() && has_suffix(file_entry.value, ".jar"));
79-
config.java.classpath.push_back(file_entry.value);
66+
jsont json_cp_config;
67+
if(parse_json(
68+
java_cp_include_files.substr(1),
69+
get_message_handler(),
70+
json_cp_config))
71+
throw "cannot read JSON input configuration for JAR loading";
72+
73+
if(!json_cp_config.is_object())
74+
throw "the JSON file has a wrong format";
75+
jsont include_files=json_cp_config["jar"];
76+
if(!include_files.is_array())
77+
throw "the JSON file has a wrong format";
78+
79+
// add jars from JSON config file to classpath
80+
for(const jsont &file_entry : include_files.array)
81+
{
82+
assert(file_entry.is_string() && has_suffix(file_entry.value, ".jar"));
83+
config.java.classpath.push_back(file_entry.value);
84+
}
8085
}
8186
}
87+
else
88+
java_cp_include_files=".*";
8289
}
8390

8491
/*******************************************************************\

src/java_bytecode/java_class_loader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class java_class_loadert:public messaget
2020
{
2121
public:
2222
java_bytecode_parse_treet &operator()(const irep_idt &);
23+
2324
void set_java_cp_include_files(std::string &java_cp_include_files)
2425
{
2526
jar_pool.set_java_cp_include_files(java_cp_include_files);

0 commit comments

Comments
 (0)