Skip to content

Commit

Permalink
#972: Refactored exception handling for Script Options parser (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben authored Oct 10, 2024
1 parent b37f762 commit 7756307
Show file tree
Hide file tree
Showing 35 changed files with 188 additions and 170 deletions.
4 changes: 2 additions & 2 deletions exaudfclient/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cc_binary(
name = "exaudfclient_bin",
srcs = ["exaudfclient.cc", "//base:load_dynamic"],
linkopts = ["-ldl"], # needed for dynamicly loading libexaudflib_complete.so into another linker namespace
deps = ["//base/exaudflib:header", "//base:debug_message_h"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+
deps = ["//base/exaudflib:header", "//base/utils:utils"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+
["//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory"],
defines = VM_ENABLED_DEFINES,
data = ["//base:libexaudflib_complete.so"]
Expand All @@ -100,7 +100,7 @@ cc_binary(
name = "exaudfclient_static_bin",
srcs = ["exaudfclient.cc", "//base:load_dynamic"],
linkopts = ["-ldl"], # needed for dynamicly loading libexaudflib_complete.so into another linker namespace
deps = ["//base/exaudflib:header", "//base:debug_message_h"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+
deps = ["//base/exaudflib:header", "//base/utils:utils"]+VM_ENABLED_DEPS+VM_PYTHON3_DEPS+
["//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory"] +
[ "@zmq//:zmq", "@protobuf//:protobuf"],
defines = VM_ENABLED_DEFINES,
Expand Down
8 changes: 1 addition & 7 deletions exaudfclient/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ exports_files(["filter_swig_code.py", "build_integrated.py",

load("//:variables.bzl", "VM_ENABLED_DEFINES")

cc_library(
name = "debug_message_h",
hdrs = [
"debug_message.h"
],
)

cc_library(
name = "load_dynamic",
srcs = [
"load_dynamic.cc"
],
deps = ["//base/exaudflib:header", "//base:debug_message_h", "//base/exaudflib:exaudflib-deps"],
deps = ["//base/exaudflib:header", "//base/utils:utils", "//base/exaudflib:exaudflib-deps"],
defines = VM_ENABLED_DEFINES,
)

Expand Down
2 changes: 1 addition & 1 deletion exaudfclient/base/benchmark_container/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ cc_library(
name = "benchmark_container",
srcs = ["benchmark_container.cc","benchmark_container.h"],
hdrs = ["benchmark_container.h"],
deps = ["//base/exaudflib:exaudflib-deps","//base/exaudflib:header", "//base:debug_message_h"]+["//base/script_options_parser:scriptoptionlines"]
deps = ["//base/exaudflib:exaudflib-deps","//base/exaudflib:header", "//base/utils:utils"]+["//base/script_options_parser:scriptoptionlines"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ENABLE_BENCHMARK_VM
#endif

#include "base/debug_message.h"
#include "base/utils/debug_message.h"
#include "benchmark_container.h"
#include <iostream>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion exaudfclient/base/exaudflib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ cc_library(
"impl/swig/swig_general_iterator.h", "impl/swig/swig_general_iterator.cc"],
defines = VM_ENABLED_DEFINES,
linkstatic = False, # Needs to be false, because otherwise we might get missing symbols when loading exaudflib_complete.so
deps = [":exaudflib-deps", ":zmqcontainer", "@zmq//:zmq", ":header", "//base:debug_message_h"],
deps = [":exaudflib-deps", ":zmqcontainer", "@zmq//:zmq", ":header", "//base/utils:utils"],
)
2 changes: 1 addition & 1 deletion exaudfclient/base/exaudflib/impl/check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <atomic>


#include "base/debug_message.h"
#include "base/utils/debug_message.h"

namespace exaudflib {
namespace check {
Expand Down
2 changes: 1 addition & 1 deletion exaudfclient/base/exaudflib/impl/exaudflib_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <fstream>
#include <functional>

#include "base/debug_message.h"
#include "base/utils/debug_message.h"

// swig lib
#include <limits>
Expand Down
2 changes: 1 addition & 1 deletion exaudfclient/base/exaudflib/impl/socket_high_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "base/exaudflib/swig/swig_common.h"
#include "base/exaudflib/vm/swig_vm.h"
#include <sys/resource.h>
#include "base/debug_message.h"
#include "base/utils/debug_message.h"

namespace exaudflib {
namespace socket_high_level {
Expand Down
2 changes: 1 addition & 1 deletion exaudfclient/base/exaudflib/impl/socket_low_level.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "base/exaudflib/impl/socket_low_level.h"
#include "base/exaudflib/impl/check.h"
#include "base/debug_message.h"
#include "base/utils/debug_message.h"
#include <mutex>
#include <iostream>
#include <unistd.h>
Expand Down
2 changes: 1 addition & 1 deletion exaudfclient/base/javacontainer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ cc_library(
srcs = [":javacontainer.cc", ":javacontainer.h", ":javacontainer_impl.cc", ":javacontainer_impl.h", ":dummy"],
hdrs = [":filter_swig_code_exascript_java_h", "exascript_java_jni_decl.h"],
deps = ["@ssl//:ssl","@java//:java", ":exascript_java", "//base/exaudflib:header",
"//base:debug_message_h","//base/javacontainer/script_options:java_script_option_lines",
"//base/utils:utils","//base/javacontainer/script_options:java_script_option_lines",
"//base/swig_factory:swig_factory_if"],
# copts= ["-O0","-fno-lto"],
alwayslink=True,
Expand Down
6 changes: 3 additions & 3 deletions exaudfclient/base/javacontainer/javacontainer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "exascript_java_jni_decl.h"

#include "base/debug_message.h"
#include "base/utils/debug_message.h"
#include "base/javacontainer/javacontainer.h"
#include "base/javacontainer/javacontainer_impl.h"
#include "base/javacontainer/script_options/extractor.h"
Expand All @@ -35,8 +35,8 @@ JavaVMImpl::JavaVMImpl(bool checkOnly, bool noJNI, SwigFactory& swigFactory)
m_exaJavaPath = "/exaudf/base/javacontainer"; // TODO hardcoded path

JavaScriptOptions::ScriptOptionLinesParserLegacy scriptOptionsParser;
JavaScriptOptions::Extractor extractor(scriptOptionsParser, swigFactory,
[&](const std::string &msg){throwException(msg);});

JavaScriptOptions::Extractor extractor(scriptOptionsParser, swigFactory);

DBG_FUNC_CALL(cerr,extractor.extract(m_scriptCode)); // To be called before scripts are imported. Otherwise, the script classname from an imported script could be used

Expand Down
5 changes: 3 additions & 2 deletions exaudfclient/base/javacontainer/script_options/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc_library(
hdrs = [":extractor.h", ":parser_legacy.h"],
srcs = [":parser.h", ":converter.h", ":converter.cc", ":parser_legacy.cc", ":extractor.cc",
":keywords.h", ":checksum.h", ":checksum.cc"],
deps = ["//base/script_options_parser/legacy:script_option_lines_parser_legacy", "//base:debug_message_h",
"//base/exaudflib:header", "//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory_if"],
deps = ["//base/script_options_parser/legacy:script_option_lines_parser_legacy", "//base/utils:utils",
"//base/exaudflib:header", "//base/exaudflib:exaudflib-deps", "//base/swig_factory:swig_factory_if",
"//base/script_options_parser:exception"],
)
1 change: 0 additions & 1 deletion exaudfclient/base/javacontainer/script_options/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <string>
#include <vector>
#include <functional>
#include <set>
#include <memory>

Expand Down
16 changes: 7 additions & 9 deletions exaudfclient/base/javacontainer/script_options/extractor.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "base/javacontainer/script_options/extractor.h"
#include "base/javacontainer/script_options/parser.h"

#include "base/debug_message.h"
#include "base/utils/debug_message.h"
#include <iostream>

#define EXTR_DBG_FUNC_CALL(f) DBG_FUNC_CALL(std::cerr, f)
Expand All @@ -11,24 +11,22 @@ namespace SWIGVMContainers {
namespace JavaScriptOptions {

Extractor::Extractor(ScriptOptionsParser & parser,
SwigFactory& swigFactory,
std::function<void(const std::string&)> throwException)
: m_throwException(throwException)
, m_parser(parser)
SwigFactory& swigFactory)
: m_parser(parser)
, m_swigFactory(swigFactory) {}

void Extractor::extract(std::string & scriptCode) {
m_parser.prepareScriptCode(scriptCode);
EXTR_DBG_FUNC_CALL(m_parser.parseForScriptClass( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertScriptClassName(value));
}, m_throwException));
EXTR_DBG_FUNC_CALL(m_parser.extractImportScripts(m_swigFactory, m_throwException));
}));
EXTR_DBG_FUNC_CALL(m_parser.extractImportScripts(m_swigFactory));
EXTR_DBG_FUNC_CALL(m_parser.parseForJvmOptions( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertJvmOption(value));
}, m_throwException));
}));
EXTR_DBG_FUNC_CALL(m_parser.parseForExternalJars( [&](const std::string& value){
EXTR_DBG_FUNC_CALL(m_converter.convertExternalJar(value));
}, m_throwException));
}));
scriptCode = std::move(m_parser.getScriptCode());
}

Expand Down
5 changes: 1 addition & 4 deletions exaudfclient/base/javacontainer/script_options/extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <string>
#include <vector>
#include <functional>
#include <set>


Expand All @@ -21,8 +20,7 @@ class Extractor {

public:
Extractor(ScriptOptionsParser & parser,
SwigFactory& swigFactory,
std::function<void(const std::string&)> throwException);
SwigFactory& swigFactory);

const std::set<std::string> & getJarPaths() const {
return m_converter.getJarPaths();
Expand All @@ -35,7 +33,6 @@ class Extractor {
void extract(std::string & scriptCode);

private:
std::function<void(const std::string&)> m_throwException;

Converter m_converter;
ScriptOptionsParser & m_parser;
Expand Down
12 changes: 4 additions & 8 deletions exaudfclient/base/javacontainer/script_options/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,26 @@ struct ScriptOptionsParser {
If the option is found, the function removes the option from "scriptCode" and calls "callback" with the option value and position
within "scriptCode".
*/
virtual void parseForScriptClass(std::function<void(const std::string &option)> callback,
std::function<void(const std::string&)> throwException) = 0;
virtual void parseForScriptClass(std::function<void(const std::string &option)> callback) = 0;
/*
Searches for JVM options.
If an option is found, the function removes the option from "scriptCode" and calls "callback" with the option value and position
within "scriptCode".
*/
virtual void parseForJvmOptions(std::function<void(const std::string &option)> callback,
std::function<void(const std::string&)> throwException) = 0;
virtual void parseForJvmOptions(std::function<void(const std::string &option)> callback) = 0;

/*
Searches for External Jar.
If an option is found, the function removes the option from "scriptCode" and calls "callback" with the option value and position
within "scriptCode".
*/
virtual void parseForExternalJars(std::function<void(const std::string &option)> callback,
std::function<void(const std::string&)> throwException) = 0;
virtual void parseForExternalJars(std::function<void(const std::string &option)> callback) = 0;

/*
Searches for the "%import" options and embeds the respective imported script code at the same location as
the option in the script code.
*/
virtual void extractImportScripts(SwigFactory & swigFactory,
std::function<void(const std::string&)> throwException) = 0;
virtual void extractImportScripts(SwigFactory & swigFactory) = 0;

/*
Returns the (eventually modified) script code.
Expand Down
Loading

0 comments on commit 7756307

Please sign in to comment.