diff --git a/src/lib/symbol-impl.cpp b/src/lib/symbol-impl.cpp index d4852cad8..232dba4ac 100644 --- a/src/lib/symbol-impl.cpp +++ b/src/lib/symbol-impl.cpp @@ -59,6 +59,33 @@ namespace lib { const size_t STRING_MAX_RELEVANT = LUMIERA_IDSTRING_MAX_RELEVANT; + namespace { // symbol table implementation + + /** @warning grows eternally, never shrinks */ + std::unordered_set symbolTable; + } + + + /** + * create Symbol by symbol table lookup. + * @note identical strings will be mapped to + * the same Symbol (embedded pointer) + */ + Symbol::Symbol (string&& definition) + : Literal{symbolTable.insert(forward (definition)).first->c_str()} + { } + + + /* == predefined marker Symbols == */ + Symbol Symbol::BOTTOM = "⟂"; + Symbol Symbol::FAILURE = "↯"; + + // see also: lib/format-obj.cpp + // We can not share these definitions due to undefined static init order + + + + /** equality on Literal and Symbol values is defined * based on the content, not the address. */ bool @@ -90,20 +117,4 @@ namespace lib { - namespace { // quick-n-dirty symbol table implementation - - /** @warning grows eternally, never shrinks */ - std::unordered_set symbolTable; ////////////////////////////////TICKET #158 replace by symbol table class - } - - /** create Symbol by symbol table lookup. - * @note identical strings will be mapped to - * the same Symbol (embedded pointer) - */ - Symbol::Symbol (string&& definition) - : Literal{symbolTable.insert(forward (definition)).first->c_str()} - { } - - - } // namespace lib diff --git a/src/lib/symbol.hpp b/src/lib/symbol.hpp index 681ee99f4..8cb615345 100644 --- a/src/lib/symbol.hpp +++ b/src/lib/symbol.hpp @@ -96,25 +96,28 @@ namespace lib { : public Literal { public: - explicit - Symbol (std::string&& definition); + static Symbol BOTTOM; + static Symbol FAILURE; + + Symbol (const char* lit =NULL) + : Symbol{std::string(lit? lit : BOTTOM.c())} + { } + + explicit + Symbol (std::string&& definition); + + Symbol (std::string const& str) + : Symbol{std::string(str)} + { } + + Symbol (Literal const& base, std::string ext) + : Symbol{std::string(base)+"."+ext} + { } + + Symbol (Literal const& base, const char* ext) + : Symbol{base, std::string(ext)} + { } - Symbol() - : Symbol{""} - { } - - Symbol (const char* lit) - : Symbol{std::string(lit)} - { } - - Symbol (Literal const& base, std::string ext) - : Symbol{std::string(base)+"."+ext} - { } - - Symbol (Literal const& base, const char* ext) - : Symbol{base, std::string(ext)} - { } - Symbol (Symbol const&) = default; Symbol (Symbol &&) = default; diff --git a/tests/library/symbol-test.cpp b/tests/library/symbol-test.cpp index 8392a72cc..2258d1c18 100644 --- a/tests/library/symbol-test.cpp +++ b/tests/library/symbol-test.cpp @@ -113,7 +113,7 @@ namespace test{ CHECK (sy1 == sy2); CHECK (not isSameObject (l1,sy1)); CHECK (not isSameObject (sy1,sy2)); - CHECK (l1.c() == sy1.c()); + CHECK (l1.c() != sy1.c()); CHECK (sy1.c() == sy2.c()); Symbol sy3;