Add location information to diagnostics. (#385)

Add simple mocking and testing of diagnostic emission to ensure this
works.
This commit is contained in:
Richard Smith
2021-03-18 21:05:54 -07:00
committed by GitHub
parent b2455d8dba
commit d1757d9979
26 changed files with 621 additions and 172 deletions
+3 -5
View File
@@ -7,6 +7,7 @@
#include <cstring>
#include "diagnostics/diagnostic_emitter.h"
#include "diagnostics/null_diagnostics.h"
#include "lexer/tokenized_buffer.h"
#include "llvm/ADT/StringRef.h"
#include "parser/parse_tree.h"
@@ -39,18 +40,15 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
auto source = SourceBuffer::CreateFromText(
llvm::StringRef(reinterpret_cast<const char*>(data), size), filename);
// Use a real diagnostic emitter to get lazy codepaths to execute.
DiagnosticEmitter emitter = NullDiagnosticEmitter();
// Lex the input.
auto tokens = TokenizedBuffer::Lex(source, emitter);
auto tokens = TokenizedBuffer::Lex(source, NullDiagnosticConsumer());
if (tokens.HasErrors()) {
return 0;
}
// Now parse it into a tree. Note that parsing will (when asserts are enabled)
// walk the entire tree to verify it so we don't have to do that here.
ParseTree tree = ParseTree::Parse(tokens, emitter);
ParseTree tree = ParseTree::Parse(tokens, NullDiagnosticConsumer());
if (tree.HasErrors()) {
return 0;
}