Commit d418e6e2 authored by Martin Marinov's avatar Martin Marinov Committed by GitHub Enterprise
Browse files

MTBR-691 Add Scheme support (#4)

* Refactor Journal::Stream::Impl
* Add Scheme journal implementation
* Apply SMI class naming conventions for Scheme
* Remove Base::Command as this is breaking ENDL output during static initialization
* Clang reformat for JournalStream.cc
* Improve the naming API
* Various fixes for the Scheme journal
* Replace define() overloads with template<> define() specializations
parent 68f08e89
...@@ -35,11 +35,11 @@ void File::print(const char _c, const bool _cnsl) ...@@ -35,11 +35,11 @@ void File::print(const char _c, const bool _cnsl)
(*bffr_) += ' '; (*bffr_) += ' ';
} }
bffr_->append(&_c, 1); bffr_->append(&_c, 1);
if (_c == '\n') if (_c == ENDL)
line_strt_ = true; line_strt_ = true;
} }
void File::line_break(const bool _cnsl) { print('\n', _cnsl); } void File::line_break(const bool _cnsl) { print(ENDL, _cnsl); }
void File::print(const std::string& _s) void File::print(const std::string& _s)
{ {
...@@ -84,19 +84,6 @@ void File::print(double _d) ...@@ -84,19 +84,6 @@ void File::print(double _d)
print(strm.str); print(strm.str);
} }
void File::print(const Base::Command& _co)
{
switch (_co.cmd)
{
case Base::Command::END:
break;
case Base::Command::END_ERR:
case Base::Command::END_LF:
line_break();
break;
}
}
// Append current asctime to given string // Append current asctime to given string
void File::print_time() void File::print_time()
{ {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace Debug { namespace Debug {
typedef unsigned int uint; typedef unsigned int uint;
using Base::ENDL;
class Enter; class Enter;
//! Debug file. //! Debug file.
...@@ -38,7 +38,6 @@ public: ...@@ -38,7 +38,6 @@ public:
void print(const int _i); void print(const int _i);
void print(float _f); void print(float _f);
void print(double _d); void print(double _d);
void print(const Base::Command& _co);
private: private:
int flush_nmbr_ = 0; int flush_nmbr_ = 0;
......
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
namespace Debug { namespace Debug {
typedef unsigned int uint; typedef unsigned int uint;
const int INVALID_LEVEL = -1; const int INVALID_LEVEL = -1;
const char* const ERROR = "ERROR"; const char* const ERROR = "ERROR";
const char* const WARNING = "WARNING"; const char* const WARNING = "WARNING";
...@@ -68,7 +67,6 @@ public: ...@@ -68,7 +67,6 @@ public:
Base::IOutputStream& print(const double) override; Base::IOutputStream& print(const double) override;
Base::IOutputStream& print(const char* const) override; Base::IOutputStream& print(const char* const) override;
Base::IOutputStream& print(const char) override; Base::IOutputStream& print(const char) override;
Base::IOutputStream& print(const Base::Command&) override;
private: private:
File& file_; File& file_;
...@@ -158,11 +156,11 @@ std::string to_string(const T& _t) ...@@ -158,11 +156,11 @@ std::string to_string(const T& _t)
#define DEB_out(LL, AA) DEB_out_if(true, LL, AA) #define DEB_out(LL, AA) DEB_out_if(true, LL, AA)
#define DEB_out_if(CC, LL, AA) \ #define DEB_out_if(CC, LL, AA) \
DEB_if(CC, LL, deb.stream() << AA << ::Base::Command::END) DEB_if(CC, LL, deb.stream() << AA << Base::ENDL)
#define DEB_line(LL, AA) DEB_line_if(true, LL, AA) #define DEB_line(LL, AA) DEB_line_if(true, LL, AA)
#define DEB_line_if(CC, LL, AA) \ #define DEB_line_if(CC, LL, AA) \
DEB_if(CC, LL, deb.stream() << AA << ::Base::LF) DEB_if(CC, LL, deb.stream() << AA << Base::ENDL)
#define DEB_warning(LL, AA) DEB_warning_if(true, LL, AA) #define DEB_warning(LL, AA) DEB_warning_if(true, LL, AA)
#define DEB_warning_if(CC, LL, AA) \ #define DEB_warning_if(CC, LL, AA) \
......
...@@ -15,14 +15,14 @@ void warning(const std::string& _wrng, const Base::CodeLink& _lnk) ...@@ -15,14 +15,14 @@ void warning(const std::string& _wrng, const Base::CodeLink& _lnk)
{ {
TEST(Test::Checksum::Debug::warning, record(_wrng, _lnk)); TEST(Test::Checksum::Debug::warning, record(_wrng, _lnk));
Stream strm(File::modify()); Stream strm(File::modify());
strm << WARNING << ": " << _wrng << ' ' << _lnk << Base::LF; strm << WARNING << ": " << _wrng << ' ' << _lnk << Base::ENDL;
} }
void error(const std::string& _err, const Base::CodeLink& _lnk) void error(const std::string& _err, const Base::CodeLink& _lnk)
{ {
TEST(Test::Checksum::Debug::error, record(_err, _lnk)); TEST(Test::Checksum::Debug::error, record(_err, _lnk));
Stream strm(File::modify()); Stream strm(File::modify());
strm << ERROR << ": " << _err << ' ' << _lnk << Base::Command::END_ERR; strm << ERROR << ": " << _err << ' ' << _lnk << Base::ENDL;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
...@@ -98,12 +98,6 @@ Base::IOutputStream& Stream::print(const char _c) ...@@ -98,12 +98,6 @@ Base::IOutputStream& Stream::print(const char _c)
return *this; return *this;
}; };
Base::IOutputStream& Stream::print(const Base::Command& _co)
{
file_.print(_co);
return *this;
};
}//namespace Debug }//namespace Debug
#endif // DEB_ON #endif // DEB_ON
set(my_headers set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/JournalCpp.hh ${CMAKE_CURRENT_SOURCE_DIR}/JournalCppDefs.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalCppImpl.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalFileSystem.hh ${CMAKE_CURRENT_SOURCE_DIR}/JournalFileSystem.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalSchemeDefs.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalSchemeImpl.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalStream.hh ${CMAKE_CURRENT_SOURCE_DIR}/JournalStream.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalStreamImpl.hh ${CMAKE_CURRENT_SOURCE_DIR}/JournalStreamImpl.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalString.hh ${CMAKE_CURRENT_SOURCE_DIR}/JournalString.hh
...@@ -8,8 +11,11 @@ set(my_headers ...@@ -8,8 +11,11 @@ set(my_headers
) )
set(my_sources set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/JournalCpp.cc ${CMAKE_CURRENT_SOURCE_DIR}/JournalCppDefs.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalCppImpl.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalFileSystem.cc ${CMAKE_CURRENT_SOURCE_DIR}/JournalFileSystem.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalSchemeDefs.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalSchemeImpl.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalStream.cc ${CMAKE_CURRENT_SOURCE_DIR}/JournalStream.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalStreamImpl.cc ${CMAKE_CURRENT_SOURCE_DIR}/JournalStreamImpl.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalString.cc ${CMAKE_CURRENT_SOURCE_DIR}/JournalString.cc
......
...@@ -42,6 +42,10 @@ namespace Journal ...@@ -42,6 +42,10 @@ namespace Journal
#error Please define the component name string when including this #error Please define the component name string when including this
#endif//COMPONENT_NAME_STRING #endif//COMPONENT_NAME_STRING
#ifndef JOURNAL_LANGUAGE
#error Please define the component journal language, see Journal::Language
#endif // COMPONENT_NAME_STRING
std::string& base_path_string() std::string& base_path_string()
{// make sure this constructor is called when the base_path_str is accessed {// make sure this constructor is called when the base_path_str is accessed
static std::string base_path_str = "."; static std::string base_path_str = ".";
...@@ -60,6 +64,7 @@ const char* base_path() ...@@ -60,6 +64,7 @@ const char* base_path()
#ifdef JOURNAL_ON #ifdef JOURNAL_ON
#ifdef JOURNAL_STARTUP
struct Setup struct Setup
{ {
Setup() Setup()
...@@ -73,13 +78,14 @@ struct Setup ...@@ -73,13 +78,14 @@ struct Setup
}; };
static Setup setup__; static Setup setup__;
#endif // JOURNAL_STARTUP
void set_on(const bool _on) void set_on(const bool _on)
{ {
if (on() == _on) if (on() == _on)
return; return;
::Journal::set_on(_on, COMPONENT_NAME_STRING, base_path()); ::Journal::set_on(JOURNAL_LANGUAGE, _on, COMPONENT_NAME_STRING, base_path());
if (!on()) if (!on())
return; return;
......
// Copyright 2020 Autodesk, Inc. All rights reserved.
//
// This computer source code and related instructions and comments are the
// unpublished confidential and proprietary information of Autodesk, Inc.
// and are protected under applicable copyright and trade secret law. They
// may not be disclosed to, copied or used by any third party without the
// prior written consent of Autodesk, Inc.
#ifdef JOURNAL_ON
#include "Base/Security/Mandatory.hh"
#include "Base/Code/Quality.hh"
#include "JournalCppDefs.hh"
#include "JournalFileSystem.hh"
#include "Base/Journal/JournalString.hh"
namespace Journal
{
namespace Cpp
{
template <> Data define(Stream&, const std::nullptr_t&)
{
return Data("nullptr");
}
template <> Data define(Stream&, const bool& _b)
{
return Data(_b ? "true" : "false");
}
template <> Data define(Stream&, const short& _i)
{
return Data(to_string(_i));
}
template <> Data define(Stream&, const unsigned short& _u)
{
return Data(to_string(_u));
}
template <> Data define(Stream&, const int& _i)
{
return Data(to_string(_i));
}
template <> Data define(Stream&, const unsigned int& _u)
{
return Data(to_string(_u));
}
template <> Data define(Stream&, const float& _f)
{
Base::OStringStream os;
os << _f << "f";
return Data(os.str);
}
template <> Data define(Stream&, const double& _d)
{
return Data(to_string(_d));
}
template <> Data define(Stream& _strm, const Filename& _flnm)
{
auto flnm = extract_filename(_flnm.str);
_strm.transform_path(flnm);
return Data(flnm);
}
template <> Data define(Stream&, const char* const& _str)
{
return Data(String("\"") + _str + String("\""));
}
template <> Data define(Stream& _strm, const String& _str)
{
return define(_strm, _str.c_str());
}
} // namespace Cpp
} // namespace Journal
#endif // JOURNAL_ON
// Copyright 2020 Autodesk, Inc. All rights reserved.
//
// This computer source code and related instructions and comments are the
// unpublished confidential and proprietary information of Autodesk, Inc.
// and are protected under applicable copyright and trade secret law. They
// may not be disclosed to, copied or used by any third party without the
// prior written consent of Autodesk, Inc.
#ifndef BASE_JOURNALCPPDEFS_HH_INCLUDED
#define BASE_JOURNALCPPDEFS_HH_INCLUDED
#include <Base/Journal/JournalStream.hh>
#ifdef JOURNAL_ON
namespace Journal
{
namespace Cpp
{
template <typename ArgT> Data define(Stream&, const ArgT&);
template <const size_t _bffr_size>
Data define(Stream& _strm, const Base::FormatT<_bffr_size>& _frmt)
{
return define(_strm, _frmt.buffer());
}
template <typename T> Data define(Stream& _strm, const CArrayT<T>& _c_arr)
{
if (_c_arr.pntr == nullptr) // nullptr if the argument is optional
return define(_strm, nullptr);
std::vector<Data> dfns;
dfns.reserve(_c_arr.size);
for (size_t i = 0; i < _c_arr.size; ++i)
dfns.push_back(define(_strm, _c_arr.pntr[i]));
// Make a unique name for this array variable and skip the leading _
const auto name = _strm.make_unique_name(_c_arr.name + 1);
auto& os = _strm.os();
os << "const " << type_name<T>() << " " << name << "[" << _c_arr.size
<< "] = {";
for (size_t i = 0; i < _c_arr.size; ++i)
{
if (i > 0)
os << ", ";
os << dfns[i].str;
}
os << "}";
_strm.end_line();
return Data(name);
}
template <class T> Data define(Stream& _strm, const OutputT<T>& _otpt)
{
_strm.os() << type_name<T>() << " " << _otpt.name /*<< " = " << _otpt.vrbl*/;
_strm.end_line();
return Data(_otpt.name);
}
} // namespace Scheme
template <typename ArgT>
Data define_in_language(Stream& _strm, const ArgT& _arg)
{
return Cpp::define(_strm, _arg);
}
} // namespace Journal
#endif // JOURNAL_ON
#endif // BASE_JOURNALCPPDEFS_HH_INCLUDED
...@@ -11,14 +11,16 @@ ...@@ -11,14 +11,16 @@
#include "Base/Security/Mandatory.hh" #include "Base/Security/Mandatory.hh"
#include "Base/Code/Quality.hh" #include "Base/Code/Quality.hh"
#include "JournalCpp.hh" #include "JournalCppImpl.hh"
#include "JournalString.hh" #include "JournalString.hh"
#include "Base/Utils/Environment.hh" #include "Base/Utils/Environment.hh"
#include <cstring>
namespace Journal namespace Journal
{ {
Stream::Cpp::Cpp(const char* const _cmpn_name, const char* const _base_path) Stream::CppImpl::CppImpl(const char* const _cmpn_name, const char* const _base_path)
: Stream::Impl(_cmpn_name, _base_path) : Stream::Impl(_cmpn_name, _base_path)
{ {
// jrnl_path_ should be set by make_directory() above // jrnl_path_ should be set by make_directory() above
...@@ -29,13 +31,13 @@ Stream::Cpp::Cpp(const char* const _cmpn_name, const char* const _base_path) ...@@ -29,13 +31,13 @@ Stream::Cpp::Cpp(const char* const _cmpn_name, const char* const _base_path)
} }
} }
Stream::Cpp::~Cpp() Stream::CppImpl::~CppImpl()
{ {
os() << "return 0;" << ENDL; os() << "return 0;" << ENDL;
close_scope(); close_scope();
} }
void Stream::Cpp::line(const String& _str) void Stream::CppImpl::line(const String& _str)
{ {
for (int i = 0; i < indt_; ++i) // add indent spaces for (int i = 0; i < indt_; ++i) // add indent spaces
cc_fs_ << ' '; cc_fs_ << ' ';
...@@ -44,31 +46,31 @@ void Stream::Cpp::line(const String& _str) ...@@ -44,31 +46,31 @@ void Stream::Cpp::line(const String& _str)
cc_fs_.flush(); cc_fs_.flush();
} }
void Stream::Cpp::set_path_transform(const char* const _trns) void Stream::CppImpl::set_path_transform(const char* const _trns)
{ {
path_trns_ = _trns; path_trns_ = _trns;
os() << "#define PATH(FLNM) " << _trns << ENDL; os() << "#define PATH(FLNM) " << _trns << ENDL;
} }
void Stream::Cpp::transform_path(String& _path) const void Stream::CppImpl::transform_path(String& _path) const
{ {
if (!path_trns_.empty()) if (!path_trns_.empty())
_path = String("PATH(\"") + _path + String("\")"); _path = String("PATH(\"") + _path + String("\")");
} }
void Stream::Cpp::open_scope() void Stream::CppImpl::open_scope()
{ {
os() << "{" << ENDL; os() << "{" << ENDL;
indt_ += SCOPE_INDENT_SPACE_NMBR; indt_ += SCOPE_INDENT_SPACE_NMBR;
} }
void Stream::Cpp::close_scope() void Stream::CppImpl::close_scope()
{ {
indt_ -= SCOPE_INDENT_SPACE_NMBR; indt_ -= SCOPE_INDENT_SPACE_NMBR;
os() << "}" << ENDL; os() << "}" << ENDL;
} }
void Stream::Cpp::include(const char* const _flnm) void Stream::CppImpl::include(const char* const _flnm)
{ {
const auto cmnt_name_lgnt = cmpn_name_.length(); const auto cmnt_name_lgnt = cmpn_name_.length();
...@@ -114,7 +116,7 @@ void Stream::Cpp::include(const char* const _flnm) ...@@ -114,7 +116,7 @@ void Stream::Cpp::include(const char* const _flnm)
emit_include(flnm.c_str()); emit_include(flnm.c_str());
} }
void Stream::Cpp::main(const char* const _main_fnct) void Stream::CppImpl::main(const char* const _main_fnct)
{ {
blank_line(); blank_line();
add_includes(); add_includes();
...@@ -123,31 +125,31 @@ void Stream::Cpp::main(const char* const _main_fnct) ...@@ -123,31 +125,31 @@ void Stream::Cpp::main(const char* const _main_fnct)
open_scope(); open_scope();
} }
void Stream::Cpp::code_line(const char* const _line) void Stream::CppImpl::code_line(const char* const _line)
{ {
os() << _line; os() << _line;
end_line(); end_line();
} }
void Stream::Cpp::end_line() void Stream::CppImpl::end_line()
{ {
os() << ';' << ENDL; os() << ';' << ENDL;
} }
IOutputStream& Stream::Cpp::comment_os() IOutputStream& Stream::CppImpl::comment_os()
{ {
os() << "// "; os() << "// ";
return *this; return *this;
} }
void Stream::Cpp::add_includes() void Stream::CppImpl::add_includes()
{ {
os() << "#include \"" << hh_flnm_.c_str() + output_path().size() + 1 os() << "#include \"" << hh_flnm_.c_str() + output_path().size() + 1
<< "\"" << ENDL; // include the header, skipping the sub-folder path << "\"" << ENDL; // include the header, skipping the sub-folder path
} }
void Stream::Cpp::emit_arguments(const DataVector& _args) void Stream::CppImpl::emit_arguments(const DataVector& _args)
{ {
os() << "("; os() << "(";
bool frst = true; bool frst = true;
...@@ -162,7 +164,7 @@ void Stream::Cpp::emit_arguments(const DataVector& _args) ...@@ -162,7 +164,7 @@ void Stream::Cpp::emit_arguments(const DataVector& _args)
os() << ")"; os() << ")";
}; };
void Stream::Cpp::emit_constructor( void Stream::CppImpl::emit_constructor(
const char* const _fnct, const Key& _obj, const DataVector& _args) const char* const _fnct, const Key& _obj, const DataVector& _args)
{ {
// Unlike other output pointers, constructor journaling does not require // Unlike other output pointers, constructor journaling does not require
...@@ -178,20 +180,20 @@ void Stream::Cpp::emit_constructor( ...@@ -178,20 +180,20 @@ void Stream::Cpp::emit_constructor(
end_line(); end_line();
} }
void Stream::Cpp::emit_destructor(const char* const /*_fnct*/, const Key& _obj) void Stream::CppImpl::emit_destructor(const char* const /*_fnct*/, const Key& _obj)
{ {
os() << "delete " << find_unique_name(_obj); os() << "delete " << retrieve_unique_name(_obj);
end_line(); end_line();
} }
void Stream::Cpp::emit_method_call(