Add error handling to the DataExtractor class

Authored by labath on Aug 27 2019, 4:24 AM.


Add error handling to the DataExtractor class

This is motivated by D63591, where we realized that there isn't a really
good way of telling whether a DataExtractor is reading actual data, or
is it just returning default values because it reached the end of the

This patch resolves that by providing a new "Cursor" class. A Cursor
object encapsulates two things:

  • the current position/offset in the DataExtractor
  • an error object

Storing the error object inside the Cursor enables one to use the same
pattern as the std::{io}stream API, where one can blindly perform a
sequence of reads and only check for errors once at the end of the
operation. Similarly to the stream API, as soon as we encounter one
error, all of the subsequent operations are skipped (return default
values) too, even if the would suceed with clear error state. Unlike the
std::stream API (but in line with other llvm APIs), we force the error
state to be checked through usage of llvm::Error.

Reviewers: probinson, dblaikie, JDevlieghere, aprantl, echristo

Subscribers: kristina, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63713

llvm-svn: 370042


labathAug 27 2019, 4:24 AM
Differential Revision
D63713: Add error handling to the DataExtractor class
rG2535f04338c6: [clang] Ensure that comment classes are trivially destructible