jvikstrom updated this revision to Diff 214346.
jvikstrom added a comment.

Fixed case where initializer was base class initializer which would cause crash.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66001/new/

https://reviews.llvm.org/D66001

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -285,6 +285,24 @@
       };
 
       $Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Variable[[O]]) = 
default;
+    )cpp",
+    R"cpp(
+      enum $Enum[[En]] {
+        $EnumConstant[[EC]],
+      };
+      class $Class[[Foo]] {};
+      class $Class[[Bar]] {
+        $Class[[Foo]] $Field[[Fo]];
+        $Enum[[En]] $Field[[E]];
+        $Primitive[[int]] $Field[[I]];
+        $Class[[Bar]] ($Class[[Foo]] $Variable[[F]],
+                $Enum[[En]] $Variable[[E]])
+        : $Field[[Fo]] ($Variable[[F]]), $Field[[E]] ($Variable[[E]]),
+          $Field[[I]] (123) {}
+      };
+      class $Class[[Bar2]] : public $Class[[Bar]] {
+        $Class[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant[[EC]]) 
{}
+      };
     )cpp"};
   for (const auto &TestCase : TestCases) {
     checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -11,6 +11,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include <algorithm>
 
@@ -136,6 +137,13 @@
         HighlightingTokenCollector>::TraverseNestedNameSpecifierLoc(NNSLoc);
   }
 
+  bool TraverseConstructorInitializer(CXXCtorInitializer *CI) {
+    if (const FieldDecl *FD = CI->getMember())
+      addToken(CI->getSourceLocation(), FD);
+    return RecursiveASTVisitor<
+        HighlightingTokenCollector>::TraverseConstructorInitializer(CI);
+  }
+
 private:
   void addTypeLoc(SourceLocation Loc, const TypeLoc &TL) {
     if (const Type *TP = TL.getTypePtr()) {


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -285,6 +285,24 @@
       };
 
       $Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Variable[[O]]) = default;
+    )cpp",
+    R"cpp(
+      enum $Enum[[En]] {
+        $EnumConstant[[EC]],
+      };
+      class $Class[[Foo]] {};
+      class $Class[[Bar]] {
+        $Class[[Foo]] $Field[[Fo]];
+        $Enum[[En]] $Field[[E]];
+        $Primitive[[int]] $Field[[I]];
+        $Class[[Bar]] ($Class[[Foo]] $Variable[[F]],
+                $Enum[[En]] $Variable[[E]])
+        : $Field[[Fo]] ($Variable[[F]]), $Field[[E]] ($Variable[[E]]),
+          $Field[[I]] (123) {}
+      };
+      class $Class[[Bar2]] : public $Class[[Bar]] {
+        $Class[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant[[EC]]) {}
+      };
     )cpp"};
   for (const auto &TestCase : TestCases) {
     checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -11,6 +11,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include <algorithm>
 
@@ -136,6 +137,13 @@
         HighlightingTokenCollector>::TraverseNestedNameSpecifierLoc(NNSLoc);
   }
 
+  bool TraverseConstructorInitializer(CXXCtorInitializer *CI) {
+    if (const FieldDecl *FD = CI->getMember())
+      addToken(CI->getSourceLocation(), FD);
+    return RecursiveASTVisitor<
+        HighlightingTokenCollector>::TraverseConstructorInitializer(CI);
+  }
+
 private:
   void addTypeLoc(SourceLocation Loc, const TypeLoc &TL) {
     if (const Type *TP = TL.getTypePtr()) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to