[cfe-commits] r150033 - in /cfe/trunk: include/clang/AST/DeclarationName.h lib/Sema/SemaOverload.cpp test/Index/annotate-tokens.cpp test/Index/index-refs.cpp test/Index/recursive-cxx-member-calls.cpp tools/libclang/IndexBody.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Feb 7 17:21:13 PST 2012
Author: akirtzidis
Date: Tue Feb 7 19:21:13 2012
New Revision: 150033
URL: http://llvm.org/viewvc/llvm-project?rev=150033&view=rev
Log:
[libclang] For CXXOperatorCallExprs, give a valid source location to the DeclRefExpr
that is referencing the member function, so we can index the referenced function.
Fixes rdar://10762375&10324915 & http://llvm.org/PR11192
Modified:
cfe/trunk/include/clang/AST/DeclarationName.h
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Index/annotate-tokens.cpp
cfe/trunk/test/Index/index-refs.cpp
cfe/trunk/test/Index/recursive-cxx-member-calls.cpp
cfe/trunk/tools/libclang/IndexBody.cpp
Modified: cfe/trunk/include/clang/AST/DeclarationName.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclarationName.h?rev=150033&r1=150032&r2=150033&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclarationName.h (original)
+++ cfe/trunk/include/clang/AST/DeclarationName.h Tue Feb 7 19:21:13 2012
@@ -511,7 +511,9 @@
SourceLocation getEndLoc() const;
/// getSourceRange - The range of the declaration name.
SourceRange getSourceRange() const {
- return SourceRange(getBeginLoc(), getEndLoc());
+ SourceLocation BeginLoc = getBeginLoc();
+ SourceLocation EndLoc = getEndLoc();
+ return SourceRange(BeginLoc, EndLoc.isValid() ? EndLoc : BeginLoc);
}
};
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=150033&r1=150032&r2=150033&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Feb 7 19:21:13 2012
@@ -9585,7 +9585,7 @@
// Build the actual expression node.
ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl,
- HadMultipleCandidates);
+ HadMultipleCandidates, OpLoc);
if (FnExpr.isInvalid())
return ExprError();
@@ -10011,12 +10011,12 @@
ResultTy = ResultTy.getNonLValueExprType(Context);
// Build the actual expression node.
- DeclarationNameLoc LocInfo;
- LocInfo.CXXOperatorName.BeginOpNameLoc = LLoc.getRawEncoding();
- LocInfo.CXXOperatorName.EndOpNameLoc = RLoc.getRawEncoding();
+ DeclarationNameInfo OpLocInfo(OpName, LLoc);
+ OpLocInfo.setCXXOperatorNameRange(SourceRange(LLoc, RLoc));
ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl,
HadMultipleCandidates,
- LLoc, LocInfo);
+ OpLocInfo.getLoc(),
+ OpLocInfo.getInfo());
if (FnExpr.isInvalid())
return ExprError();
@@ -10521,8 +10521,13 @@
for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx)
MethodArgs[ArgIdx + 1] = Args[ArgIdx];
+ DeclarationNameInfo OpLocInfo(
+ Context.DeclarationNames.getCXXOperatorName(OO_Call), LParenLoc);
+ OpLocInfo.setCXXOperatorNameRange(SourceRange(LParenLoc, RParenLoc));
ExprResult NewFn = CreateFunctionRefExpr(*this, Method,
- HadMultipleCandidates);
+ HadMultipleCandidates,
+ OpLocInfo.getLoc(),
+ OpLocInfo.getInfo());
if (NewFn.isInvalid())
return true;
@@ -10698,7 +10703,7 @@
// Build the operator call.
ExprResult FnExpr = CreateFunctionRefExpr(*this, Method,
- HadMultipleCandidates);
+ HadMultipleCandidates, OpLoc);
if (FnExpr.isInvalid())
return ExprError();
Modified: cfe/trunk/test/Index/annotate-tokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.cpp?rev=150033&r1=150032&r2=150033&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-tokens.cpp (original)
+++ cfe/trunk/test/Index/annotate-tokens.cpp Tue Feb 7 19:21:13 2012
@@ -34,7 +34,7 @@
// CHECK: Punctuation: ")" [2:17 - 2:18] FunctionDecl=test:2:6 (Definition)
// CHECK: Punctuation: "{" [2:19 - 2:20] CompoundStmt=
// CHECK: Identifier: "X" [3:5 - 3:6] DeclRefExpr=X:2:16
-// CHECK: Punctuation: "=" [3:7 - 3:8] CallExpr=operator=:1:8
+// CHECK: Punctuation: "=" [3:7 - 3:8] DeclRefExpr=operator=:1:8
// CHECK: Identifier: "X" [3:9 - 3:10] DeclRefExpr=X:2:16
// CHECK: Punctuation: ";" [3:10 - 3:11] CompoundStmt=
// CHECK: Keyword: "__is_base_of" [4:5 - 4:17] UnexposedExpr=
@@ -78,7 +78,7 @@
// CHECK: Punctuation: "(" [13:3 - 13:4] ParenExpr=
// CHECK: Identifier: "x" [13:4 - 13:5] DeclRefExpr=x:11:14
// CHECK: Punctuation: ")" [13:5 - 13:6] ParenExpr=
-// CHECK: Punctuation: "++" [13:6 - 13:8] CallExpr=operator++:9:5
+// CHECK: Punctuation: "++" [13:6 - 13:8] DeclRefExpr=operator++:9:5
// CHECK: Punctuation: ";" [13:8 - 13:9] CompoundStmt=
// CHECK: Punctuation: "}" [14:1 - 14:2] CompoundStmt=
// CHECK: Keyword: "struct" [16:1 - 16:7] StructDecl=S1:16:8 (Definition)
@@ -111,7 +111,7 @@
// CHECK: Punctuation: ")" [18:17 - 18:18] FunctionDecl=test3:18:6 (Definition)
// CHECK: Punctuation: "{" [18:19 - 18:20] CompoundStmt=
// CHECK: Identifier: "s2" [19:3 - 19:5] DeclRefExpr=s2:18:15
-// CHECK: Punctuation: "->" [19:5 - 19:7] MemberRefExpr=f:16:18
+// CHECK: Punctuation: "->" [19:5 - 19:7] DeclRefExpr=operator->:17:17
// CHECK: Identifier: "f" [19:7 - 19:8] MemberRefExpr=f:16:18
// CHECK: Punctuation: "(" [19:8 - 19:9] CallExpr=f:16:18
// CHECK: Punctuation: ")" [19:9 - 19:10] CallExpr=f:16:18
Modified: cfe/trunk/test/Index/index-refs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-refs.cpp?rev=150033&r1=150032&r2=150033&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-refs.cpp (original)
+++ cfe/trunk/test/Index/index-refs.cpp Tue Feb 7 19:21:13 2012
@@ -18,6 +18,22 @@
SecondVal = EnumVal
};
+struct S {
+ S& operator++();
+ int operator*();
+ S& operator=(int x);
+ S& operator!=(int x);
+ S& operator()(int x);
+};
+
+void foo2(S &s) {
+ (void)++s;
+ (void)*s;
+ s = 3;
+ (void)(s != 3);
+ s(3);
+}
+
// RUN: c-index-test -index-file %s | FileCheck %s
// CHECK: [indexDeclaration]: kind: namespace | name: NS
// CHECK-NEXT: [indexDeclaration]: kind: variable | name: gx
@@ -35,3 +51,10 @@
// CHECK-NEXT: [indexDeclaration]: kind: enum
// CHECK-NEXT: [indexDeclaration]: kind: enumerator | name: SecondVal
// CHECK-NEXT: [indexEntityReference]: kind: enumerator | name: EnumVal
+
+// CHECK: [indexDeclaration]: kind: function | name: foo2
+// CHECK: [indexEntityReference]: kind: c++-instance-method | name: operator++
+// CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator*
+// CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator=
+// CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator!=
+// CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator()
Modified: cfe/trunk/test/Index/recursive-cxx-member-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/recursive-cxx-member-calls.cpp?rev=150033&r1=150032&r2=150033&view=diff
==============================================================================
--- cfe/trunk/test/Index/recursive-cxx-member-calls.cpp (original)
+++ cfe/trunk/test/Index/recursive-cxx-member-calls.cpp Tue Feb 7 19:21:13 2012
@@ -933,7 +933,7 @@
// CHECK-tokens: Punctuation: ")" [102:58 - 102:59] CallExpr=endswith:56:8
// CHECK-tokens: Punctuation: ")" [102:59 - 102:60] IfStmt=
// CHECK-tokens: Identifier: "AttrName" [103:5 - 103:13] DeclRefExpr=AttrName:101:19
-// CHECK-tokens: Punctuation: "=" [103:14 - 103:15] CallExpr=operator=:38:7
+// CHECK-tokens: Punctuation: "=" [103:14 - 103:15] DeclRefExpr=operator=:38:7
// CHECK-tokens: Identifier: "AttrName" [103:16 - 103:24] DeclRefExpr=AttrName:101:19
// CHECK-tokens: Punctuation: "." [103:24 - 103:25] MemberRefExpr=substr:60:13
// CHECK-tokens: Identifier: "substr" [103:25 - 103:31] MemberRefExpr=substr:60:13
Modified: cfe/trunk/tools/libclang/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexBody.cpp?rev=150033&r1=150032&r2=150033&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexBody.cpp (original)
+++ cfe/trunk/tools/libclang/IndexBody.cpp Tue Feb 7 19:21:13 2012
@@ -90,6 +90,12 @@
return true;
}
+ bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+ if (E->getOperatorLoc().isInvalid())
+ return true; // implicit.
+ return base::TraverseCXXOperatorCallExpr(E);
+ }
+
bool VisitDeclStmt(DeclStmt *S) {
if (IndexCtx.indexFunctionLocalSymbols())
IndexCtx.indexDeclGroupRef(S->getDeclGroup());
More information about the cfe-commits
mailing list