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

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)
(*bffr_) += ' ';
}
bffr_->append(&_c, 1);
if (_c == '\n')
if (_c == ENDL)
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)
{
......@@ -84,19 +84,6 @@ void File::print(double _d)
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
void File::print_time()
{
......
......@@ -11,7 +11,7 @@
namespace Debug {
typedef unsigned int uint;
using Base::ENDL;
class Enter;
//! Debug file.
......@@ -38,7 +38,6 @@ public:
void print(const int _i);
void print(float _f);
void print(double _d);
void print(const Base::Command& _co);
private:
int flush_nmbr_ = 0;
......
......@@ -43,7 +43,6 @@
namespace Debug {
typedef unsigned int uint;
const int INVALID_LEVEL = -1;
const char* const ERROR = "ERROR";
const char* const WARNING = "WARNING";
......@@ -68,7 +67,6 @@ public:
Base::IOutputStream& print(const double) override;
Base::IOutputStream& print(const char* const) override;
Base::IOutputStream& print(const char) override;
Base::IOutputStream& print(const Base::Command&) override;
private:
File& file_;
......@@ -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_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_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_if(CC, LL, AA) \
......
......@@ -15,14 +15,14 @@ void warning(const std::string& _wrng, const Base::CodeLink& _lnk)
{
TEST(Test::Checksum::Debug::warning, record(_wrng, _lnk));
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)
{
TEST(Test::Checksum::Debug::error, record(_err, _lnk));
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)
return *this;
};
Base::IOutputStream& Stream::print(const Base::Command& _co)
{
file_.print(_co);
return *this;
};
}//namespace Debug
#endif // DEB_ON
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}/JournalSchemeDefs.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalSchemeImpl.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalStream.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalStreamImpl.hh
${CMAKE_CURRENT_SOURCE_DIR}/JournalString.hh
......@@ -8,8 +11,11 @@ set(my_headers
)
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}/JournalSchemeDefs.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalSchemeImpl.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalStream.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalStreamImpl.cc
${CMAKE_CURRENT_SOURCE_DIR}/JournalString.cc
......
......@@ -42,6 +42,10 @@ namespace Journal
#error Please define the component name string when including this
#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()
{// make sure this constructor is called when the base_path_str is accessed
static std::string base_path_str = ".";
......@@ -60,6 +64,7 @@ const char* base_path()
#ifdef JOURNAL_ON
#ifdef JOURNAL_STARTUP
struct Setup
{
Setup()
......@@ -73,13 +78,14 @@ struct Setup
};
static Setup setup__;
#endif // JOURNAL_STARTUP
void set_on(const bool _on)
{
if (on() == _on)
return;
::Journal::set_on(_on, COMPONENT_NAME_STRING, base_path());
::Journal::set_on(JOURNAL_LANGUAGE, _on, COMPONENT_NAME_STRING, base_path());
if (!on())
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 @@
#include "Base/Security/Mandatory.hh"
#include "Base/Code/Quality.hh"
#include "JournalCpp.hh"
#include "JournalCppImpl.hh"
#include "JournalString.hh"
#include "Base/Utils/Environment.hh"
#include <cstring>
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)
{
// 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)
}
}
Stream::Cpp::~Cpp()
Stream::CppImpl::~CppImpl()
{
os() << "return 0;" << ENDL;
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
cc_fs_ << ' ';
......@@ -44,31 +46,31 @@ void Stream::Cpp::line(const String& _str)
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;
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())
_path = String("PATH(\"") + _path + String("\")");
}
void Stream::Cpp::open_scope()
void Stream::CppImpl::open_scope()
{
os() << "{" << ENDL;
indt_ += SCOPE_INDENT_SPACE_NMBR;
}
void Stream::Cpp::close_scope()
void Stream::CppImpl::close_scope()
{
indt_ -= SCOPE_INDENT_SPACE_NMBR;
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();
......@@ -114,7 +116,7 @@ void Stream::Cpp::include(const char* const _flnm)
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();
add_includes();
......@@ -123,31 +125,31 @@ void Stream::Cpp::main(const char* const _main_fnct)
open_scope();
}
void Stream::Cpp::code_line(const char* const _line)
void Stream::CppImpl::code_line(const char* const _line)
{
os() << _line;
end_line();
}
void Stream::Cpp::end_line()
void Stream::CppImpl::end_line()
{
os() << ';' << ENDL;
}
IOutputStream& Stream::Cpp::comment_os()
IOutputStream& Stream::CppImpl::comment_os()
{
os() << "// ";
return *this;
}
void Stream::Cpp::add_includes()
void Stream::CppImpl::add_includes()
{
os() << "#include \"" << hh_flnm_.c_str() + output_path().size() + 1
<< "\"" << 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() << "(";
bool frst = true;
......@@ -162,7 +164,7 @@ void Stream::Cpp::emit_arguments(const DataVector& _args)
os() << ")";
};
void Stream::Cpp::emit_constructor(
void Stream::CppImpl::emit_constructor(
const char* const _fnct, const Key& _obj, const DataVector& _args)
{
// Unlike other output pointers, constructor journaling does not require
......@@ -178,20 +180,20 @@ void Stream::Cpp::emit_constructor(
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();
}
void Stream::Cpp::emit_method_call(
void Stream::CppImpl::emit_method_call(
const char* const _fnct, const Key& _obj, const DataVector& _args)
{
os() << find_unique_name(_obj) << "->" << method_name(_fnct);
os() << retrieve_unique_name(_obj) << "->" << method_name(_fnct);
emit_arguments(_args);
}
void Stream::Cpp::emit_method_outcome(
void Stream::CppImpl::emit_method_outcome(
const char* const _fnct, const Key& _obj, const DataVector& _args)
{
os() << "CHECK_OUTCOME(";
......@@ -200,14 +202,14 @@ void Stream::Cpp::emit_method_outcome(
end_line();
}
void Stream::Cpp::emit_method_void(
void Stream::CppImpl::emit_method_void(
const char* const _fnct, const Key& _obj, const DataVector& _args)
{
emit_method_call(_fnct, _obj, _args);
end_line();
}
void Stream::Cpp::emit_method(const char* const _fnct, const Data& _rtrn,
void Stream::CppImpl::emit_method(const char* const _fnct, const Data& _rtrn,
const Key& _obj, const DataVector& _args)
{
// return variable should be pre-declared for now
......@@ -216,13 +218,13 @@ void Stream::Cpp::emit_method(const char* const _fnct, const Data& _rtrn,
end_line();
}
void Stream::Cpp::emit_function_call(const char* const _fnct, const DataVector& _args)
void Stream::CppImpl::emit_function_call(const char* const _fnct, const DataVector& _args)
{
os() << function_name(_fnct);
emit_arguments(_args);
}
void Stream::Cpp::emit_function_outcome(
void Stream::CppImpl::emit_function_outcome(
const char* const _fnct, const DataVector& _args)
{
os() << "CHECK_OUTCOME(";
......@@ -231,14 +233,14 @@ void Stream::Cpp::emit_function_outcome(
end_line();
}
void Stream::Cpp::emit_function_void(
void Stream::CppImpl::emit_function_void(
const char* const _fnct, const DataVector& _args)
{
emit_function_call(_fnct, _args);
end_line();
}
void Stream::Cpp::emit_function(
void Stream::CppImpl::emit_function(
const char* const _fnct, const Data& _rtrn, const DataVector& _args)
{
// return variable should be pre-declared for now
......
......@@ -6,6 +6,8 @@
// may not be disclosed to, copied or used by any third party without the
// prior written consent of Autodesk, Inc.
#ifndef BASE_JOURNALCPPIMPL_HH_INCLUDED
#define BASE_JOURNALCPPIMPL_HH_INCLUDED
#ifdef JOURNAL_ON
#include <Base/Journal/JournalStreamImpl.hh>
......@@ -15,13 +17,13 @@
namespace Journal
{
class Stream::Cpp : public Stream::Impl
class Stream::CppImpl : public Stream::Impl
{
public:
public:
Cpp(const char* const _cmpn_name, const char* const _base_path);
~Cpp() override;
CppImpl(const char* const _cmpn_name, const char* const _base_path);
~CppImpl() override;
// Language-specific API
Base::IOutputStream& comment_os() override;
......@@ -79,4 +81,5 @@ private:
}//namespace Journal
#endif//JOURNAL_ON
#endif // JOURNAL_ON
#endif // BASE_JOURNALCPPIMPL_HH_INCLUDED
......@@ -42,14 +42,7 @@ namespace Journal {
bool environment_base_path(const char* const _cmpn_name, String& _base_path)
{
String envr_vrbl(_cmpn_name);
const auto to_upper = [](const char _c)
{
return static_cast<char>(::toupper(_c));
};
std::transform(
envr_vrbl.begin(), envr_vrbl.end(), envr_vrbl.begin(), to_upper);
to_upper(envr_vrbl);
envr_vrbl += "_JOURNAL_BASE";
return System::Environment::variable(envr_vrbl.c_str(), _base_path);
}
......
// 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 "JournalSchemeDefs.hh"
#include "JournalFileSystem.hh"
#include "Base/Journal/JournalString.hh"
namespace Journal
{
namespace Scheme
{
template <> Data define(Stream&, const std::nullptr_t&)
{
return Data("'()");
}
template <> Data define(Stream&, const bool& _b)
{
return Data(_b ? "#t" : "#f");
}
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)
{
return Data(to_string(_f));
}
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 Scheme
} // 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_JOURNAL_SCHEME_DEFS_HH_INCLUDED
#define BASE_JOURNAL_SCHEME_DEFS_HH_INCLUDED
#include <Base/Journal/JournalStream.hh>
#ifdef JOURNAL_ON
#define JSCOPE(EXPR) "(" << EXPR << ")"
#define JDEFINE(VAR, DFNT) JSCOPE("define " << VAR << " " << DFNT)
#define JSTRING(STR) '\"' << STR << '\"'
#define JFILENAME(FLNM) JSTRING(extract_filename(FLNM))
namespace Journal
{
namespace Scheme
{
template <typename ArgT> Data define(Stream&, const ArgT&);
<