[PATCH] D86719: [SyntaxTree][NFC] Refactor function templates into functions taking base class
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 27 09:03:43 PDT 2020
eduucaldas updated this revision to Diff 288362.
eduucaldas added a comment.
Fix macro
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86719/new/
https://reviews.llvm.org/D86719
Files:
clang/lib/Tooling/Syntax/BuildTree.cpp
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -378,11 +378,9 @@
/// Returns true if \p D is the last declarator in a chain and is thus
/// reponsible for creating SimpleDeclaration for the whole chain.
- template <class T>
- bool isResponsibleForCreatingDeclaration(const T *D) const {
- static_assert((std::is_base_of<DeclaratorDecl, T>::value ||
- std::is_base_of<TypedefNameDecl, T>::value),
- "only DeclaratorDecl and TypedefNameDecl are supported.");
+ bool isResponsibleForCreatingDeclaration(const Decl *D) const {
+ assert((isa<DeclaratorDecl, TypedefNameDecl>(D)) &&
+ "only DeclaratorDecl and TypedefNameDecl are supported.");
const Decl *Next = D->getNextDeclInContext();
@@ -390,15 +388,14 @@
if (Next == nullptr) {
return true;
}
- const auto *NextT = dyn_cast<T>(Next);
// Next sibling is not the same type, this one is responsible.
- if (NextT == nullptr) {
+ if (D->getKind() != Next->getKind()) {
return true;
}
// Next sibling doesn't begin at the same loc, it must be a different
// declaration, so this declarator is responsible.
- if (NextT->getBeginLoc() != D->getBeginLoc()) {
+ if (Next->getBeginLoc() != D->getBeginLoc()) {
return true;
}
@@ -1405,10 +1402,9 @@
}
private:
- template <class T> SourceLocation getQualifiedNameStart(T *D) {
- static_assert((std::is_base_of<DeclaratorDecl, T>::value ||
- std::is_base_of<TypedefNameDecl, T>::value),
- "only DeclaratorDecl and TypedefNameDecl are supported.");
+ SourceLocation getQualifiedNameStart(NamedDecl *D) {
+ assert((isa<DeclaratorDecl, TypedefNameDecl>(D)) &&
+ "only DeclaratorDecl and TypedefNameDecl are supported.");
auto DN = D->getDeclName();
bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
@@ -1438,10 +1434,9 @@
/// Folds SimpleDeclarator node (if present) and in case this is the last
/// declarator in the chain it also folds SimpleDeclaration node.
template <class T> bool processDeclaratorAndDeclaration(T *D) {
- SourceRange Initializer = getInitializerRange(D);
- auto Range = getDeclaratorRange(Builder.sourceManager(),
- D->getTypeSourceInfo()->getTypeLoc(),
- getQualifiedNameStart(D), Initializer);
+ auto Range = getDeclaratorRange(
+ Builder.sourceManager(), D->getTypeSourceInfo()->getTypeLoc(),
+ getQualifiedNameStart(D), getInitializerRange(D));
// There doesn't have to be a declarator (e.g. `void foo(int)` only has
// declaration, but no declarator).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86719.288362.patch
Type: text/x-patch
Size: 2868 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200827/97583a68/attachment-0001.bin>
More information about the cfe-commits
mailing list