[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    [PATCH] Fix source range of destructor name
From:       Olivier Goffart <ogoffart () kde ! org>
Date:       2014-01-15 21:25:29
Message-ID: 8036718.2TsDpZGWcL () finn
[Download RAW message or body]

Hi,

This fixes http://llvm.org/bugs/show_bug.cgi?id=15125
The problem is that destructor->getNameInfo().getSourceRange() only contains 
the '~' and not the class name after it.

This is why for example the destructor name is not highlighted in my code 
browser, only the '~' has a tooltip.
http://code.woboq.org/userspace/llvm/tools/clang/include/clang/AST/DeclarationName.h.html#_ZN5clang20DeclarationNameTableD1Ev


-- 
Olivier


["0001-Fix-source-range-of-the-destructor-name.patch" (0001-Fix-source-range-of-the-destructor-name.patch)]

From d131af55d2dc2cb6b2f7242697eb44d2e5d042da Mon Sep 17 00:00:00 2001
From: Olivier Goffart <ogoffart@woboq.com>
Date: Wed, 15 Jan 2014 19:45:12 +0100
Subject: [PATCH] Fix source range of the destructor name.

The problem is that the destructor's DeclarationNameInfo do not have
a TypeSourceInfo because Sema::GetNameForDeclarator requires the
ParsedType to be a LocInfoType.

Setting a proper TypeSourceInfo to the destructor changes the way it
it printed (from '~Foo' to '~struct Foo'.  Hence the change in
DeclarationName.cpp which also fix a bug when printing operator names.

http://llvm.org/bugs/show_bug.cgi?id=15125
---
 lib/AST/DeclarationName.cpp       | 5 ++++-
 lib/Sema/SemaExprCXX.cpp          | 5 ++++-
 unittests/AST/DeclPrinterTest.cpp | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp
index e064e23..3811bbf 100644
--- a/lib/AST/DeclarationName.cpp
+++ b/lib/AST/DeclarationName.cpp
@@ -537,7 +537,10 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const {
         OS << '~';
       else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
         OS << "operator ";
-      OS << TInfo->getType().getAsString();
+      LangOptions LO;
+      PrintingPolicy SubPolicy(LO);
+      SubPolicy.SuppressTagKeyword = true;
+      OS << TInfo->getType().getAsString(SubPolicy);
     } else
       OS << Name;
     return;
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index a0c123f..7e4f5f3 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -209,7 +209,8 @@ ParsedType Sema::getDestructorName(SourceLocation TildeLoc,
           Context.hasSameUnqualifiedType(T, SearchType)) {
         // We found our type!
 
-        return ParsedType::make(T);
+        return CreateParsedType(T, Context.getTrivialTypeSourceInfo(T,
+                                                                    NameLoc));
       }
 
       if (!SearchType.isNull())
@@ -245,6 +246,8 @@ ParsedType Sema::getDestructorName(SourceLocation TildeLoc,
               = dyn_cast<ClassTemplateSpecializationDecl>(Record->getDecl())) {
           if (Spec->getSpecializedTemplate()->getCanonicalDecl() ==
                 Template->getCanonicalDecl())
+            return CreateParsedType(MemberOfType,
+                    Context.getTrivialTypeSourceInfo(MemberOfType, NameLoc));
             return ParsedType::make(MemberOfType);
         }
 
diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp
index 44fa742..2e335e3 100644
--- a/unittests/AST/DeclPrinterTest.cpp
+++ b/unittests/AST/DeclPrinterTest.cpp
@@ -558,7 +558,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) {
     "  operator Z();"
     "};",
     methodDecl(ofClass(hasName("A"))).bind("id"),
-    "Z operator struct Z()"));
+    "Z operator Z()"));
     // WRONG; Should be: "operator Z();"
 }
 
-- 
1.8.5.2



_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic