Skip to content

Commit 5912a04

Browse files
author
thk123
committed
Refactored java_load_class to allow specifying different cmd line args
This will allow adding a lazy version. Don't set flags on optiont that take the default value anyway
1 parent 1e7f2bc commit 5912a04

File tree

5 files changed

+89
-4
lines changed

5 files changed

+89
-4
lines changed

unit/testing-utils/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SRC = \
22
c_to_expr.cpp \
3+
free_form_cmdline.cpp \
34
load_java_class.cpp \
45
require_expr.cpp \
56
require_goto_statements.cpp \
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************\
2+
3+
Module: Unit test utilities
4+
5+
Author: DiffBlue Limited.
6+
7+
\*******************************************************************/
8+
9+
#include "free_form_cmdline.h"
10+
11+
/// Create a command line option that can be set
12+
/// \param flag_name: The name of the command line option to support
13+
void free_form_cmdlinet::create_flag(const std::string &flag_name)
14+
{
15+
optiont option;
16+
option.optstring = flag_name;
17+
options.push_back(option);
18+
}
19+
20+
/// Equivalent to specifying --flag for the command line
21+
/// \param flag: The name of the flag to specify
22+
void free_form_cmdlinet::add_flag(std::string flag)
23+
{
24+
create_flag(flag);
25+
set(flag);
26+
}
27+
28+
/// Equivalent to specifying --flag value
29+
/// \param flag: The name of the flag to specify
30+
/// \param value: The value to the set the command line option to
31+
void free_form_cmdlinet::add_option(std::string flag, std::string value)
32+
{
33+
create_flag(flag);
34+
set(flag, value);
35+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************\
2+
3+
Module: Unit test utilities
4+
5+
Author: DiffBlue Limited.
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_TESTING_UTILS_FREE_FORM_CMDLINE_H
10+
#define CPROVER_TESTING_UTILS_FREE_FORM_CMDLINE_H
11+
12+
#include <util/cmdline.h>
13+
14+
/// An implementation of cmdlinet to be used in tests. It does not require
15+
/// specifying exactly what flags are supported and instead allows setting any
16+
/// flag
17+
class free_form_cmdlinet : public cmdlinet
18+
{
19+
public:
20+
void add_flag(std::string flag);
21+
void add_option(std::string flag, std::string value);
22+
23+
private:
24+
void create_flag(const std::string &flag_name);
25+
};
26+
27+
#endif // CPROVER_TESTING_UTILS_FREE_FORM_CMDLINE_H

unit/testing-utils/load_java_class.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
\*******************************************************************/
88

99
#include "load_java_class.h"
10+
#include "free_form_cmdline.h"
1011
#include <testing-utils/catch.hpp>
1112
#include <iostream>
1213

1314
#include <util/config.h>
14-
#include <util/options.h>
1515
#include <util/suffix.h>
1616

1717
#include <goto-programs/lazy_goto_model.h>
@@ -51,7 +51,8 @@ symbol_tablet load_java_class(
5151
const std::string &java_class_name,
5252
const std::string &class_path,
5353
const std::string &main,
54-
std::unique_ptr<languaget> &&java_lang)
54+
std::unique_ptr<languaget> &&java_lang,
55+
const cmdlinet &command_line)
5556
{
5657
// We expect the name of the class without the .class suffix to allow us to
5758
// check it
@@ -66,8 +67,6 @@ symbol_tablet load_java_class(
6667
message_handler);
6768

6869
// Configure the path loading
69-
cmdlinet command_line;
70-
command_line.set("java-cp-include-files", class_path);
7170
config.java.classpath.clear();
7271
config.java.classpath.push_back(class_path);
7372
config.main = main;
@@ -109,3 +108,18 @@ symbol_tablet load_java_class(
109108
REQUIRE_FALSE(class_type.get_bool(ID_incomplete_class));
110109
return std::move(maybe_goto_model->symbol_table);
111110
}
111+
112+
symbol_tablet load_java_class(
113+
const std::string &java_class_name,
114+
const std::string &class_path,
115+
const std::string &main,
116+
std::unique_ptr<languaget> &&java_lang)
117+
{
118+
cmdlinet command_line;
119+
// TODO(tkiley): This doesn't do anything as "java-cp-include-files" is an
120+
// TODO(tkiley): unknown argument. This could be changed by using the
121+
// TODO(tkiley): free_form_cmdlinet
122+
command_line.set("java-cp-include-files", class_path);
123+
return load_java_class(
124+
java_class_name, class_path, main, std::move(java_lang), command_line);
125+
}

unit/testing-utils/load_java_class.h

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <goto-programs/goto_model.h>
1919

2020
#include <langapi/language.h>
21+
#include <util/cmdline.h>
2122

2223
symbol_tablet load_java_class(
2324
const std::string &java_class_name,
@@ -30,4 +31,11 @@ symbol_tablet load_java_class(
3031
const std::string &main,
3132
std::unique_ptr<languaget> &&java_lang);
3233

34+
symbol_tablet load_java_class(
35+
const std::string &java_class_name,
36+
const std::string &class_path,
37+
const std::string &main,
38+
std::unique_ptr<languaget> &&java_lang,
39+
const cmdlinet &command_line);
40+
3341
#endif // CPROVER_TESTING_UTILS_LOAD_JAVA_CLASS_H

0 commit comments

Comments
 (0)