[mlir][AsmParser] Improve parse{Attribute,Type} error handling

Currently these functions report errors directly to stderr, this updates
them to use diagnostics instead. This also makes partially-consumed
strings an error if the `numRead` parameter isn't provided (the
docstrings already claimed this happened, but it didn't.)

While here I also tried to reduce the number of overloads by switching
to using default parameters.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D144804
This commit is contained in:
Rahul Kayaith
2023-02-25 02:30:46 -05:00
parent bd6eb1423c
commit f5f8a46bb0
7 changed files with 85 additions and 72 deletions

View File

@@ -1031,9 +1031,9 @@ LogicalResult AttrTypeReader::parseAsmEntry(T &result, EncodingReader &reader,
size_t numRead = 0;
MLIRContext *context = fileLoc->getContext();
if constexpr (std::is_same_v<T, Type>)
result = ::parseType(asmStr, context, numRead);
result = ::parseType(asmStr, context, &numRead);
else
result = ::parseAttribute(asmStr, context, numRead);
result = ::parseAttribute(asmStr, context, Type(), &numRead);
if (!result)
return failure();