Skip to content

Commit

Permalink
Add missing info and message reporting methods to ASTNode and OSLComp…
Browse files Browse the repository at this point in the history
…ileImp. (#854)
  • Loading branch information
lgritz committed Feb 5, 2018
1 parent e410f16 commit 5a5766f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
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

0 comments on commit 5a5766f

Please sign in to comment.