Go to the documentation of this file.
12 #ifndef OPENVDB_AX_COMPILER_LOGGER_HAS_BEEN_INCLUDED
13 #define OPENVDB_AX_COMPILER_LOGGER_HAS_BEEN_INCLUDED
15 #include "../ast/AST.h"
21 #include <unordered_map>
57 using Ptr = std::shared_ptr<Logger>;
67 [](
const std::string& msg){
68 std::cerr << msg << std::endl;
70 const OutputFunction& warnings = [](
const std::string&){});
103 inline size_t errors()
const {
return mNumErrors; }
105 inline size_t warnings()
const {
return mNumWarnings; }
108 inline bool hasError()
const {
return this->errors() > 0; }
110 inline bool hasWarning()
const {
return this->warnings() > 0; }
113 return this->getMaxErrors() > 0 && this->errors() >= this->getMaxErrors();
188 friend class ::TestLogger;
190 std::function<void(
const std::string&)> mErrorOutput;
191 std::function<void(
const std::string&)> mWarningOutput;
196 std::unique_ptr<Settings> mSettings;
200 std::unique_ptr<SourceCode> mCode;
202 std::unordered_map<const ax::ast::Node*, CodeLocation> mNodeToLineColMap;
209 #endif // OPENVDB_AX_COMPILER_LOGGER_HAS_BEEN_INCLUDED
void addNodeLocation(const ax::ast::Node *node, const CodeLocation &location)
Add a node to the code location map.
void setWarningPrefix(const char *prefix="warning: ")
Set a prefix for each warning message.
size_t getMaxErrors() const
Returns the number of allowed errors.
bool error(const std::string &message, const CodeLocation &lineCol)
Log a compiler error and its offending code location.
bool hasWarning() const
Returns true if a warning has been found, false otherwise.
Definition: Logger.h:110
bool getWarningsAsErrors() const
Returns if warning are promoted to errors.
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:103
std::pair< size_t, size_t > CodeLocation
Definition: Logger.h:59
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 getNumberedOutput() const
Returns whether the messages will be numbered.
size_t warnings() const
Returns the number of warnings that have been encountered.
Definition: Logger.h:105
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...
Library and file format version numbers.
void setNumberedOutput(const bool numbered=true)
Error/warning formatting options.
bool atErrorLimit() const
Returns true if it has errored and the max errors has been hit.
Definition: Logger.h:112
std::function< void(const std::string &)> OutputFunction
Definition: Logger.h:60
std::shared_ptr< const Tree > ConstPtr
Definition: AST.h:564
void setPrintLines(const bool print=true)
Set whether the output should include the offending line of code.
bool warning(const std::string &message, const CodeLocation &lineCol)
Log a compiler warning and its offending code location.
The base abstract node which determines the interface and required methods for all derived concrete n...
Definition: AST.h:102
const char * getWarningPrefix() const
Returns the prefix for each warning message.
std::shared_ptr< Logger > Ptr
Definition: Logger.h:57
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153
void setWarningsAsErrors(const bool warnAsError=false)
Set any warnings that are encountered to be promoted to errors.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
void setSourceCode(const char *code)
Set the source code that lines can be printed from if an error or warning is raised.
bool hasError() const
Returns true if an error has been found, false otherwise.
Definition: Logger.h:108
Logger for collecting errors and warnings that occur during AX compilation.
Definition: Logger.h:55
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...
Definition: openvdb/Exceptions.h:13
bool getPrintLines() const
Returns whether the messages will include the line of offending code.
void clear()
Clear the tree-code mapping and reset the number of errors/warnings.
void setMaxErrors(const size_t maxErrors=0)
Sets the maximum number of errors that are allowed before compilation should exit.
void setErrorPrefix(const char *prefix="error: ")
Set a prefix for each error message.
bool error(const std::string &message, const ax::ast::Node *node)
Log a compiler error using the offending AST node. Used in AST traversal.
void print(const ast::Node &node, const bool numberStatements=true, std::ostream &os=std::cout, const char *indent=" ")
Writes a descriptive printout of a Node hierarchy into a target stream.