From ff87ea9045a6e0979311ae7b25055d6b53b0a13d Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 5 Aug 2016 11:09:53 +0200 Subject: o Dropping the native library code, we're all Python now! --- core/CMakeLists.txt | 2 +- core/include-priv/trygvis/antlr.h | 67 -------------------------------- core/include-priv/trygvis/string_utils.h | 23 ----------- core/trygvis/antlr.h | 67 ++++++++++++++++++++++++++++++++ core/trygvis/string_utils.h | 25 ++++++++++++ 5 files changed, 93 insertions(+), 91 deletions(-) delete mode 100644 core/include-priv/trygvis/antlr.h delete mode 100644 core/include-priv/trygvis/string_utils.h create mode 100644 core/trygvis/antlr.h create mode 100644 core/trygvis/string_utils.h (limited to 'core') diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index cbf8e78..75d2383 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -16,7 +16,7 @@ get_target_property(KicadNet_includes KicadNet INCLUDE_DIRECTORIES) target_include_directories(kicad-utils-core PUBLIC include - PRIVATE include-priv ${KicadNet_includes}) + PRIVATE ${KicadNet_includes}) target_link_libraries(kicad-utils-core Antlr4::antlr4_shared) diff --git a/core/include-priv/trygvis/antlr.h b/core/include-priv/trygvis/antlr.h deleted file mode 100644 index f5656ea..0000000 --- a/core/include-priv/trygvis/antlr.h +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -#include "antlr4-runtime.h" - -namespace trygvis { -namespace antlr { - -// This namespace is shared copied code - -using ParseTree = antlr4::tree::ParseTree; - -class MissingParseTreeProperty : public std::out_of_range { -public: - explicit MissingParseTreeProperty(const std::string &what) : out_of_range(what) { } -}; - -template -class ParseTreeProperty { -public: - virtual V get(Ref node) { - return get(node.get()); - } - - virtual V get(ParseTree *const node) { - if (!debug) { - return _annotations.at(node); - } - - try { -// cerr << "node = " << node->getText() << endl; - return _annotations.at(node); - } catch (std::out_of_range &e) { - std::cerr << "get(" << node << "), text=" << node->getText() << std::endl; - std::stringstream buf; - buf << "out of range: " << node << ", text=" << node->getText(); - auto msg = buf.str(); - std::cerr << msg << std::endl; - throw MissingParseTreeProperty(msg); - } - } - - virtual void put(ParseTree *const node, V value) { - if (debug) { - std::cerr << "put(" << node << ", " << value << "), text: " << node->getText() << std::endl; - } - _annotations[node] = value; - } - - virtual V removeFrom(ParseTree *const node) { - auto it = _annotations.find(node); - - if (it == _annotations.end()) { - throw MissingParseTreeProperty(node->getText()); - } - - return it->second; - } - -protected: - std::map _annotations; - -private: -}; - -} // namespace antlr - -} diff --git a/core/include-priv/trygvis/string_utils.h b/core/include-priv/trygvis/string_utils.h deleted file mode 100644 index 9902a3f..0000000 --- a/core/include-priv/trygvis/string_utils.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include - -namespace trygvis { -namespace string_utils { - -/** - * Check if a starts with b. - */ -static bool startsWith(const std::string &a, const std::string &b) { - return b.length() <= a.length() && a.compare(0, b.length(), b) == 0; -} - -/** - * Check if a ends with b. - */ -static bool endsWith(const std::string &a, const std::string &b) { - return b.length() <= a.length() && a.compare(a.length() - b.length(), b.length(), b) == 0; -} - -} // namespace string_utils -} // namespace trygvis diff --git a/core/trygvis/antlr.h b/core/trygvis/antlr.h new file mode 100644 index 0000000..f5656ea --- /dev/null +++ b/core/trygvis/antlr.h @@ -0,0 +1,67 @@ +#pragma once + +#include "antlr4-runtime.h" + +namespace trygvis { +namespace antlr { + +// This namespace is shared copied code + +using ParseTree = antlr4::tree::ParseTree; + +class MissingParseTreeProperty : public std::out_of_range { +public: + explicit MissingParseTreeProperty(const std::string &what) : out_of_range(what) { } +}; + +template +class ParseTreeProperty { +public: + virtual V get(Ref node) { + return get(node.get()); + } + + virtual V get(ParseTree *const node) { + if (!debug) { + return _annotations.at(node); + } + + try { +// cerr << "node = " << node->getText() << endl; + return _annotations.at(node); + } catch (std::out_of_range &e) { + std::cerr << "get(" << node << "), text=" << node->getText() << std::endl; + std::stringstream buf; + buf << "out of range: " << node << ", text=" << node->getText(); + auto msg = buf.str(); + std::cerr << msg << std::endl; + throw MissingParseTreeProperty(msg); + } + } + + virtual void put(ParseTree *const node, V value) { + if (debug) { + std::cerr << "put(" << node << ", " << value << "), text: " << node->getText() << std::endl; + } + _annotations[node] = value; + } + + virtual V removeFrom(ParseTree *const node) { + auto it = _annotations.find(node); + + if (it == _annotations.end()) { + throw MissingParseTreeProperty(node->getText()); + } + + return it->second; + } + +protected: + std::map _annotations; + +private: +}; + +} // namespace antlr + +} diff --git a/core/trygvis/string_utils.h b/core/trygvis/string_utils.h new file mode 100644 index 0000000..2f2a7a5 --- /dev/null +++ b/core/trygvis/string_utils.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +namespace trygvis { +namespace string_utils { + +/** + * Check if a starts with b. + */ +__attribute__((unused)) +static bool startsWith(const std::string &a, const std::string &b) { + return b.length() <= a.length() && a.compare(0, b.length(), b) == 0; +} + +/** + * Check if a ends with b. + */ +__attribute__((unused)) +static bool endsWith(const std::string &a, const std::string &b) { + return b.length() <= a.length() && a.compare(a.length() - b.length(), b.length(), b) == 0; +} + +} // namespace string_utils +} // namespace trygvis -- cgit v1.2.3