12#ifndef OPENVDB_AX_COMPILER_LOGGER_HAS_BEEN_INCLUDED
13#define OPENVDB_AX_COMPILER_LOGGER_HAS_BEEN_INCLUDED
17#include <openvdb/version.h>
21#include <unordered_map>
60 using Ptr = std::shared_ptr<Logger>;
70 [](
const std::string& msg){
71 std::cerr << msg << std::endl;
73 const OutputFunction& warnings = [](
const std::string&){});
109 inline size_t errors()
const {
return mNumErrors; }
111 inline size_t warnings()
const {
return mNumWarnings; }
114 inline bool hasError()
const {
return this->errors() > 0; }
116 inline bool hasWarning()
const {
return this->warnings() > 0; }
119 return this->getMaxErrors() > 0 && this->errors() >= this->getMaxErrors();
200 friend class ::TestLogger;
208 std::unique_ptr<Settings> mSettings;
212 std::unique_ptr<SourceCode> mCode;
214 std::unordered_map<const ax::ast::Node*, CodeLocation> mNodeToLineColMap;
Provides the definition for every abstract and concrete derived class which represent a particular ab...
Logger for collecting errors and warnings that occur during AX compilation.
Definition Logger.h:58
const char * getWarningPrefix() const
Returns the prefix for each warning message.
size_t warnings() const
Returns the number of warnings that have been encountered.
Definition Logger.h:111
void setWarningPrefix(const char *prefix="warning: ")
Set a prefix for each warning message.
void addNodeLocation(const ax::ast::Node *node, const CodeLocation &location)
Add a node to the code location map.
std::function< void(const std::string &)> OutputFunction
Definition Logger.h:63
bool error(const std::string &message, const CodeLocation &lineCol=CodeLocation(0, 0))
Log a compiler error and its offending code location. If the offending location is (0,...
bool atErrorLimit() const
Returns true if it has errored and the max errors has been hit.
Definition Logger.h:118
void setSourceTree(openvdb::ax::ast::Tree::ConstPtr tree)
Set the AST source tree which will be used as reference for the locations of nodes when resolving lin...
Logger(const OutputFunction &errors=[](const std::string &msg){ std::cerr<< msg<< std::endl;}, const OutputFunction &warnings=[](const std::string &){})
Construct a Logger with optional error and warning output functions, defaults stream errors to std::c...
bool warning(const std::string &message, const CodeLocation &lineCol=CodeLocation(0, 0))
Log a compiler warning and its offending code location. If the offending location is (0,...
size_t getIndent() const
Returns the number of spaces to be printed before every new line.
bool getPrintLines() const
Returns whether the messages will include the line of offending code.
std::shared_ptr< Logger > Ptr
Definition Logger.h:60
const char * getErrorPrefix() const
Returns the prefix for each error message.
size_t errors() const
Returns the number of errors that have been encountered.
Definition Logger.h:109
void setNumberedOutput(const bool numbered=true)
Error/warning formatting options.
bool warning(const std::string &message, const ax::ast::Node *node)
Log a compiler warning using the offending AST node. Used in AST traversal.
bool hasError() const
Returns true if an error has been found, false otherwise.
Definition Logger.h:114
bool error(const std::string &message, const ax::ast::Node *node)
Log a compiler error using the offending AST node. Used in AST traversal.
bool getNumberedOutput() const
Returns whether the messages will be numbered.
void setMaxErrors(const size_t maxErrors=0)
Sets the maximum number of errors that are allowed before compilation should exit.
void setWarningsAsErrors(const bool warnAsError=false)
Set any warnings that are encountered to be promoted to errors.
void setPrintLines(const bool print=true)
Set whether the output should include the offending line of code.
bool hasWarning() const
Returns true if a warning has been found, false otherwise.
Definition Logger.h:116
bool getWarningsAsErrors() const
Returns if warning are promoted to errors.
void setErrorPrefix(const char *prefix="error: ")
Set a prefix for each warning message.
void clear()
Clear the tree-code mapping and reset the number of errors/warnings.
size_t getMaxErrors() const
Returns the number of allowed errors.
void setIndent(const size_t ident=0)
Number of spaces to indent every new line before the message is formatted.
std::pair< size_t, size_t > CodeLocation
Definition Logger.h:62
void setSourceCode(const char *code)
Set the source code that lines can be printed from if an error or warning is raised.
Definition Exceptions.h:13
The base abstract node which determines the interface and required methods for all derived concrete n...
Definition AST.h:102
std::shared_ptr< const Tree > ConstPtr
Definition AST.h:564
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212