[PATCH] D50672: [ASTImporter] Change the return result of Decl import to Optional

Aleksei Sidorin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 13 15:52:28 PDT 2018


a_sidorin created this revision.
a_sidorin added reviewers: martong, balazske, xazax.hun, jingham.
Herald added a subscriber: rnkovacs.
Herald added a reviewer: a.sidorin.

This is a small step to simplify ASTImporter internals and make them more robust. As it was discussed in the mailing lists, the following changes are included:

- Introduced helper methods `importNonNull()` and `importNullable()` with `LLVM_NODISCARD` attribute. These methods are used to avoid redundant casting and to simplify checks for import return result. `LLVM_NODISCARD` will also print a warning every time a return result of import is unchecked.
- The return result of `Import*Decl()` methods is changed to `Optional<Decl *>`. The value of `nullptr` doesn't signal an error anymore (as it should be); `None` object are used instead in case of import failure. I hope that the need for dereferencing the result will remind about the need to check it first.
- ASTimporter and its clients are changed to use the new API. The patch for LLDB is coming soon. Some unchecked imports were found and fixed.

Unfortunately, the patch became very big. However, most changes are same. The code became a bit smaller and, as it looks to me, a bit more readable.


Repository:
  rC Clang

https://reviews.llvm.org/D50672

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp
  lib/AST/ExternalASTMerger.cpp
  lib/CrossTU/CrossTranslationUnit.cpp
  lib/Frontend/ASTMerge.cpp
  unittests/AST/ASTImporterTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50672.160468.patch
Type: text/x-patch
Size: 136355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180813/14afc0e4/attachment-0001.bin>


More information about the cfe-commits mailing list