ckandeler created this revision.
ckandeler added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is needed for clients that want to highlight virtual functions
differently.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107145

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  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
@@ -642,8 +642,8 @@
     )cpp",
       R"cpp(
       class $Class_decl_abstract[[Abstract]] {
-        virtual void $Method_decl_abstract[[pure]]() = 0;
-        virtual void $Method_decl[[impl]]();
+        virtual void $Method_decl_abstract_virtual[[pure]]() = 0;
+        virtual void $Method_decl_virtual[[impl]]();
       };
       )cpp",
       R"cpp(
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -66,6 +66,7 @@
   Readonly,
   Static,
   Abstract,
+  Virtual,
   DependentName,
   DefaultLibrary,
 
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -240,6 +240,12 @@
   return false;
 }
 
+bool isVirtual(const Decl *D) {
+  if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(D))
+    return CMD->isVirtual();
+  return false;
+}
+
 bool isDependent(const Decl *D) {
   if (isa<UnresolvedUsingValueDecl>(D))
     return true;
@@ -712,6 +718,8 @@
             Tok.addModifier(HighlightingModifier::Static);
           if (isAbstract(Decl))
             Tok.addModifier(HighlightingModifier::Abstract);
+          if (isVirtual(Decl))
+            Tok.addModifier(HighlightingModifier::Virtual);
           if (isDependent(Decl))
             Tok.addModifier(HighlightingModifier::DependentName);
           if (isDefaultLibrary(Decl))
@@ -898,6 +906,8 @@
     return "deduced"; // nonstandard
   case HighlightingModifier::Abstract:
     return "abstract";
+  case HighlightingModifier::Virtual:
+    return "virtual";
   case HighlightingModifier::DependentName:
     return "dependentName"; // nonstandard
   case HighlightingModifier::DefaultLibrary:


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -642,8 +642,8 @@
     )cpp",
       R"cpp(
       class $Class_decl_abstract[[Abstract]] {
-        virtual void $Method_decl_abstract[[pure]]() = 0;
-        virtual void $Method_decl[[impl]]();
+        virtual void $Method_decl_abstract_virtual[[pure]]() = 0;
+        virtual void $Method_decl_virtual[[impl]]();
       };
       )cpp",
       R"cpp(
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -66,6 +66,7 @@
   Readonly,
   Static,
   Abstract,
+  Virtual,
   DependentName,
   DefaultLibrary,
 
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -240,6 +240,12 @@
   return false;
 }
 
+bool isVirtual(const Decl *D) {
+  if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(D))
+    return CMD->isVirtual();
+  return false;
+}
+
 bool isDependent(const Decl *D) {
   if (isa<UnresolvedUsingValueDecl>(D))
     return true;
@@ -712,6 +718,8 @@
             Tok.addModifier(HighlightingModifier::Static);
           if (isAbstract(Decl))
             Tok.addModifier(HighlightingModifier::Abstract);
+          if (isVirtual(Decl))
+            Tok.addModifier(HighlightingModifier::Virtual);
           if (isDependent(Decl))
             Tok.addModifier(HighlightingModifier::DependentName);
           if (isDefaultLibrary(Decl))
@@ -898,6 +906,8 @@
     return "deduced"; // nonstandard
   case HighlightingModifier::Abstract:
     return "abstract";
+  case HighlightingModifier::Virtual:
+    return "virtual";
   case HighlightingModifier::DependentName:
     return "dependentName"; // nonstandard
   case HighlightingModifier::DefaultLibrary:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to