12#ifndef OPENVDB_AX_COMPILER_LOGGER_HAS_BEEN_INCLUDED
13#define OPENVDB_AX_COMPILER_LOGGER_HAS_BEEN_INCLUDED
15#include "../ast/AST.h"
17#include <openvdb/version.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&){});
106 inline size_t errors()
const {
return mNumErrors; }
108 inline size_t warnings()
const {
return mNumWarnings; }
111 inline bool hasError()
const {
return this->errors() > 0; }
113 inline bool hasWarning()
const {
return this->warnings() > 0; }
116 return this->getMaxErrors() > 0 && this->errors() >= this->getMaxErrors();
195 friend class ::TestLogger;
197 std::function<void(
const std::string&)> mErrorOutput;
198 std::function<void(
const std::string&)> mWarningOutput;
203 std::unique_ptr<Settings> mSettings;
207 std::unique_ptr<SourceCode> mCode;
209 std::unordered_map<const ax::ast::Node*, CodeLocation> mNodeToLineColMap;
Logger for collecting errors and warnings that occur during AX compilation.
Definition: Logger.h:55
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:108
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:60
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:115
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:57
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:106
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:111
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:113
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:59
void setSourceCode(const char *code)
Set the source code that lines can be printed from if an error or warning is raised.
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.
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:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202