Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing info and message reporting methods to ASTNode and OSLCompilerImpl #854

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/liboslcomp/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,32 @@ ASTNode::warning_impl (string_view msg) const



void
ASTNode::info_impl (string_view msg) const
{
#if OIIO_VERSION >= 10803
m_compiler->info (sourcefile(), sourceline(), "%s", msg);
#else
// DEPRECATED -- delete when minimum OIIO is at least 1.8
m_compiler->info (sourcefile(), sourceline(), "%s", msg.c_str());
#endif
}



void
ASTNode::message_impl (string_view msg) const
{
#if OIIO_VERSION >= 10803
m_compiler->message (sourcefile(), sourceline(), "%s", msg);
#else
// DEPRECATED -- delete when minimum OIIO is at least 1.8
m_compiler->message (sourcefile(), sourceline(), "%s", msg.c_str());
#endif
}



void
ASTNode::print (std::ostream &out, int indentlevel) const
{
Expand Down
26 changes: 26 additions & 0 deletions src/liboslcomp/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@ class ASTNode : public OIIO::RefCnt {
#endif
}

/// info reporting
template<typename... Args>
void info (string_view format, const Args&... args) const
{
DASSERT (format.size());
#if OIIO_VERSION >= 10803
info_impl (OIIO::Strutil::format (format, args...));
#else /* DEPRECATE when OIIO minimum is at least 1.8 */
info_impl (OIIO::Strutil::format (format.c_str(), args...));
#endif
}

/// message reporting
template<typename... Args>
void message (string_view format, const Args&... args) const
{
DASSERT (format.size());
#if OIIO_VERSION >= 10803
message_impl (OIIO::Strutil::format (format, args...));
#else /* DEPRECATE when OIIO minimum is at least 1.8 */
message_impl (OIIO::Strutil::format (format.c_str(), args...));
#endif
}

bool is_lvalue () const { return m_is_lvalue; }

/// Return a reference-counted pointer to the next node in the sequence.
Expand Down Expand Up @@ -367,6 +391,8 @@ class ASTNode : public OIIO::RefCnt {

void error_impl (string_view msg) const;
void warning_impl (string_view msg) const;
void info_impl (string_view msg) const;
void message_impl (string_view msg) const;

protected:
NodeType m_nodetype; ///< Type of node this is
Expand Down
42 changes: 42 additions & 0 deletions src/liboslcomp/oslcomp_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,48 @@ class OSLCompilerImpl {
#endif
}

/// Info reporting
template<typename... Args>
void info (string_view filename, int line,
string_view format, const Args&... args) const
{
ASSERT (format.size());
#if OIIO_VERSION >= 10804
std::string msg = OIIO::Strutil::format (format, args...);
if (filename.size())
m_errhandler->info ("%s:%d: info: %s", filename, line, msg);
else
m_errhandler->info ("info: %s", msg);
#else /* Deprecate when the OIIO minimum is 1.8 */
std::string msg = OIIO::Strutil::format (format.c_str(), args...);
if (filename.size())
m_errhandler->info ("%s:%d: info: %s", filename.c_str(), line, msg.c_str());
else
m_errhandler->info ("info: %s", msg.c_str());
#endif
}

/// message reporting
template<typename... Args>
void message (string_view filename, int line,
string_view format, const Args&... args) const
{
ASSERT (format.size());
#if OIIO_VERSION >= 10804
std::string msg = OIIO::Strutil::format (format, args...);
if (filename.size())
m_errhandler->message ("%s:%d: %s", filename, line, msg);
else
m_errhandler->message ("%s", msg);
#else /* Deprecate when the OIIO minimum is 1.8 */
std::string msg = OIIO::Strutil::format (format.c_str(), args...);
if (filename.size())
m_errhandler->message ("%s:%d: %s", filename.c_str(), line, msg.c_str());
else
m_errhandler->message ("%s", msg.c_str());
#endif
}

/// Have we hit an error?
///
bool error_encountered () const { return m_err; }
Expand Down