Have the driver return errors on SemanticsIR errors. (#2471)

This does a high level check on diagnostics in order to be minimally invasive on the semantics code.
This commit is contained in:
Jon Ross-Perkins
2022-12-16 15:51:00 -08:00
committed by GitHub
parent 5d123189c3
commit 8e6d48004b
6 changed files with 22 additions and 11 deletions
+8 -4
View File
@@ -162,24 +162,28 @@ auto Driver::RunDumpSubcommand(DiagnosticConsumer& consumer,
return false;
}
bool has_errors = false;
CARBON_VLOG() << "*** TokenizedBuffer::Lex ***\n";
auto tokenized_source = TokenizedBuffer::Lex(*source, consumer);
has_errors |= tokenized_source.has_errors();
CARBON_VLOG() << "*** TokenizedBuffer::Lex done ***\n";
if (dump_mode == DumpMode::TokenizedBuffer) {
CARBON_VLOG() << "Finishing output.";
consumer.Flush();
tokenized_source.Print(output_stream_);
return !tokenized_source.has_errors();
return !has_errors;
}
CARBON_VLOG() << "tokenized_buffer: " << tokenized_source;
CARBON_VLOG() << "*** ParseTree::Parse ***\n";
auto parse_tree = ParseTree::Parse(tokenized_source, consumer, vlog_stream_);
has_errors |= parse_tree.has_errors();
CARBON_VLOG() << "*** ParseTree::Parse done ***\n";
if (dump_mode == DumpMode::ParseTree) {
consumer.Flush();
parse_tree.Print(output_stream_, parse_tree_preorder);
return !tokenized_source.has_errors() && !parse_tree.has_errors();
return !has_errors;
}
CARBON_VLOG() << "parse_tree: " << parse_tree;
@@ -187,12 +191,12 @@ auto Driver::RunDumpSubcommand(DiagnosticConsumer& consumer,
CARBON_VLOG() << "*** SemanticsIR::MakeFromParseTree ***\n";
const SemanticsIR semantics_ir = SemanticsIR::MakeFromParseTree(
builtin_ir, tokenized_source, parse_tree, consumer, vlog_stream_);
has_errors |= semantics_ir.has_errors();
CARBON_VLOG() << "*** SemanticsIR::MakeFromParseTree done ***\n";
if (dump_mode == DumpMode::SemanticsIR) {
consumer.Flush();
semantics_ir.Print(output_stream_);
// TODO: Return false when SemanticsIR has errors (not supported right now).
return !tokenized_source.has_errors() && !parse_tree.has_errors();
return !has_errors;
}
CARBON_VLOG() << "semantics_ir: " << semantics_ir;