[clang-tools-extra] 4abc910 - [clangd] Implement semantic token modifier "definition"

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 17 14:13:01 PDT 2022


Author: Christian Kandeler
Date: 2022-10-17T17:12:41-04:00
New Revision: 4abc910a42e50d278f64558acc20b346bf3013f4

URL: https://github.com/llvm/llvm-project/commit/4abc910a42e50d278f64558acc20b346bf3013f4
DIFF: https://github.com/llvm/llvm-project/commit/4abc910a42e50d278f64558acc20b346bf3013f4.diff

LOG: [clangd] Implement semantic token modifier "definition"

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D127403

Added: 
    

Modified: 
    clang-tools-extra/clangd/SemanticHighlighting.cpp
    clang-tools-extra/clangd/SemanticHighlighting.h
    clang-tools-extra/clangd/test/initialize-params.test
    clang-tools-extra/clangd/test/semantic-tokens.test
    clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
    clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 2375d6f7dd355..1a6fa528acced 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -66,6 +66,23 @@ bool canHighlightName(DeclarationName Name) {
   llvm_unreachable("invalid name kind");
 }
 
+bool isUniqueDefinition(const NamedDecl *Decl) {
+  if (auto *Func = dyn_cast<FunctionDecl>(Decl))
+    return Func->isThisDeclarationADefinition();
+  if (auto *Klass = dyn_cast<CXXRecordDecl>(Decl))
+    return Klass->isThisDeclarationADefinition();
+  if (auto *Iface = dyn_cast<ObjCInterfaceDecl>(Decl))
+    return Iface->isThisDeclarationADefinition();
+  if (auto *Proto = dyn_cast<ObjCProtocolDecl>(Decl))
+    return Proto->isThisDeclarationADefinition();
+  if (auto *Var = dyn_cast<VarDecl>(Decl))
+    return Var->isThisDeclarationADefinition();
+  return isa<TemplateTypeParmDecl>(Decl) ||
+         isa<NonTypeTemplateParmDecl>(Decl) ||
+         isa<TemplateTemplateParmDecl>(Decl) || isa<ObjCCategoryDecl>(Decl) ||
+         isa<ObjCImplDecl>(Decl);
+}
+
 llvm::Optional<HighlightingKind> kindForType(const Type *TP,
                                              const HeuristicResolver *Resolver);
 llvm::Optional<HighlightingKind>
@@ -660,7 +677,7 @@ class CollectExtraHighlightings
   // We handle objective-C selectors specially, because one reference can
   // cover several non-contiguous tokens.
   void highlightObjCSelector(const ArrayRef<SourceLocation> &Locs, bool Decl,
-                             bool Class, bool DefaultLibrary) {
+                             bool Def, bool Class, bool DefaultLibrary) {
     HighlightingKind Kind =
         Class ? HighlightingKind::StaticMethod : HighlightingKind::Method;
     for (SourceLocation Part : Locs) {
@@ -668,6 +685,8 @@ class CollectExtraHighlightings
           H.addToken(Part, Kind).addModifier(HighlightingModifier::ClassScope);
       if (Decl)
         Tok.addModifier(HighlightingModifier::Declaration);
+      if (Def)
+        Tok.addModifier(HighlightingModifier::Definition);
       if (Class)
         Tok.addModifier(HighlightingModifier::Static);
       if (DefaultLibrary)
@@ -678,8 +697,9 @@ class CollectExtraHighlightings
   bool VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
     llvm::SmallVector<SourceLocation> Locs;
     OMD->getSelectorLocs(Locs);
-    highlightObjCSelector(Locs, /*Decl=*/true, OMD->isClassMethod(),
-                          isDefaultLibrary(OMD));
+    highlightObjCSelector(Locs, /*Decl=*/true,
+                          OMD->isThisDeclarationADefinition(),
+                          OMD->isClassMethod(), isDefaultLibrary(OMD));
     return true;
   }
 
@@ -689,8 +709,8 @@ class CollectExtraHighlightings
     bool DefaultLibrary = false;
     if (ObjCMethodDecl *OMD = OME->getMethodDecl())
       DefaultLibrary = isDefaultLibrary(OMD);
-    highlightObjCSelector(Locs, /*Decl=*/false, OME->isClassMessage(),
-                          DefaultLibrary);
+    highlightObjCSelector(Locs, /*Decl=*/false, /*Def=*/false,
+                          OME->isClassMessage(), DefaultLibrary);
     return true;
   }
 
@@ -859,11 +879,15 @@ std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST) {
             Tok.addModifier(HighlightingModifier::DefaultLibrary);
           if (Decl->isDeprecated())
             Tok.addModifier(HighlightingModifier::Deprecated);
-          // Do not treat an UnresolvedUsingValueDecl as a declaration.
-          // It's more common to think of it as a reference to the
-          // underlying declaration.
-          if (R.IsDecl && !isa<UnresolvedUsingValueDecl>(Decl))
-            Tok.addModifier(HighlightingModifier::Declaration);
+          if (R.IsDecl) {
+            // Do not treat an UnresolvedUsingValueDecl as a declaration.
+            // It's more common to think of it as a reference to the
+            // underlying declaration.
+            if (!isa<UnresolvedUsingValueDecl>(Decl))
+              Tok.addModifier(HighlightingModifier::Declaration);
+            if (isUniqueDefinition(Decl))
+              Tok.addModifier(HighlightingModifier::Definition);
+          }
         }
       },
       AST.getHeuristicResolver());
@@ -934,6 +958,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, HighlightingModifier K) {
   switch (K) {
   case HighlightingModifier::Declaration:
     return OS << "decl"; // abbreviation for common case
+  case HighlightingModifier::Definition:
+    return OS << "def"; // abbrevation for common case
   default:
     return OS << toSemanticTokenModifier(K);
   }
@@ -1065,6 +1091,8 @@ llvm::StringRef toSemanticTokenModifier(HighlightingModifier Modifier) {
   switch (Modifier) {
   case HighlightingModifier::Declaration:
     return "declaration";
+  case HighlightingModifier::Definition:
+    return "definition";
   case HighlightingModifier::Deprecated:
     return "deprecated";
   case HighlightingModifier::Readonly:

diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.h b/clang-tools-extra/clangd/SemanticHighlighting.h
index 17863fce5ae87..4fe2fc7aee54d 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.h
+++ b/clang-tools-extra/clangd/SemanticHighlighting.h
@@ -61,7 +61,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, HighlightingKind K);
 
 enum class HighlightingModifier {
   Declaration,
-  // FIXME: Definition (needs findExplicitReferences support)
+  Definition,
   Deprecated,
   Deduced,
   Readonly,

diff  --git a/clang-tools-extra/clangd/test/initialize-params.test b/clang-tools-extra/clangd/test/initialize-params.test
index e7810c66f44a2..031be9e147f74 100644
--- a/clang-tools-extra/clangd/test/initialize-params.test
+++ b/clang-tools-extra/clangd/test/initialize-params.test
@@ -58,6 +58,7 @@
 # CHECK-NEXT:        "legend": {
 # CHECK-NEXT:          "tokenModifiers": [
 # CHECK-NEXT:            "declaration",
+# CHECK-NEXT:            "definition",
 # CHECK-NEXT:            "deprecated",
 # CHECK-NEXT:            "deduced",
 # CHECK-NEXT:            "readonly",

diff  --git a/clang-tools-extra/clangd/test/semantic-tokens.test b/clang-tools-extra/clangd/test/semantic-tokens.test
index a29993bc9ba28..b85d720ff5137 100644
--- a/clang-tools-extra/clangd/test/semantic-tokens.test
+++ b/clang-tools-extra/clangd/test/semantic-tokens.test
@@ -23,7 +23,7 @@
 # CHECK-NEXT:      4,
 # CHECK-NEXT:      1,
 # CHECK-NEXT:      0,
-# CHECK-NEXT:      8193
+# CHECK-NEXT:      16387
 # CHECK-NEXT:    ],
 # CHECK-NEXT:    "resultId": "1"
 # CHECK-NEXT:  }
@@ -49,7 +49,7 @@
 # CHECK-NEXT:          4,
 # CHECK-NEXT:          1,
 # CHECK-NEXT:          0,
-# CHECK-NEXT:          8193
+# CHECK-NEXT:          16387
 # CHECK-NEXT:        ],
 #                    Inserted at position 1
 # CHECK-NEXT:        "deleteCount": 0,
@@ -72,12 +72,12 @@
 # CHECK-NEXT:      4,
 # CHECK-NEXT:      1,
 # CHECK-NEXT:      0,
-# CHECK-NEXT:      8193,
+# CHECK-NEXT:      16387,
 # CHECK-NEXT:      1,
 # CHECK-NEXT:      4,
 # CHECK-NEXT:      1,
 # CHECK-NEXT:      0,
-# CHECK-NEXT:      8193
+# CHECK-NEXT:      16387
 # CHECK-NEXT:    ],
 # CHECK-NEXT:    "resultId": "3"
 # CHECK-NEXT:  }

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 6011aca7fa393..d3219617d4000 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -48,12 +48,21 @@ std::string annotate(llvm::StringRef Input,
     assert(StartOffset <= EndOffset);
     assert(NextChar <= StartOffset);
 
+    bool hasDef =
+        T.Modifiers & (1 << uint32_t(HighlightingModifier::Definition));
+    bool hasDecl =
+        T.Modifiers & (1 << uint32_t(HighlightingModifier::Declaration));
+    EXPECT_TRUE(!hasDef || hasDecl);
+
     OS << Input.substr(NextChar, StartOffset - NextChar);
     OS << '$' << T.Kind;
     for (unsigned I = 0;
          I <= static_cast<uint32_t>(HighlightingModifier::LastModifier); ++I) {
-      if (T.Modifiers & (1 << I))
-        OS << '_' << static_cast<HighlightingModifier>(I);
+      if (T.Modifiers & (1 << I)) {
+        // _decl_def is common and redundant, just print _def instead.
+        if (I != uint32_t(HighlightingModifier::Declaration) || !hasDef)
+          OS << '_' << static_cast<HighlightingModifier>(I);
+      }
     }
     OS << "[[" << Input.substr(StartOffset, EndOffset - StartOffset) << "]]";
     NextChar = EndOffset;
@@ -96,52 +105,52 @@ constexpr static uint32_t ScopeModifierMask =
 TEST(SemanticHighlighting, GetsCorrectTokens) {
   const char *TestCases[] = {
       R"cpp(
-      struct $Class_decl[[AS]] {
+      struct $Class_def[[AS]] {
         double $Field_decl[[SomeMember]];
       };
       struct {
-      } $Variable_decl[[S]];
-      void $Function_decl[[foo]](int $Parameter_decl[[A]], $Class[[AS]] $Parameter_decl[[As]]) {
-        $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[VeryLongVariableName]] = 12312;
-        $Class[[AS]]     $LocalVariable_decl[[AA]];
-        $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
-        auto $LocalVariable_decl[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_decl[[A]]) -> void {};
+      } $Variable_def[[S]];
+      void $Function_def[[foo]](int $Parameter_def[[A]], $Class[[AS]] $Parameter_def[[As]]) {
+        $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[VeryLongVariableName]] = 12312;
+        $Class[[AS]]     $LocalVariable_def[[AA]];
+        $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
+        auto $LocalVariable_def[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_def[[A]]) -> void {};
         $LocalVariable[[FN]](12312);
       }
     )cpp",
       R"cpp(
       void $Function_decl[[foo]](int);
       void $Function_decl[[Gah]]();
-      void $Function_decl[[foo]]() {
-        auto $LocalVariable_decl[[Bou]] = $Function[[Gah]];
+      void $Function_def[[foo]]() {
+        auto $LocalVariable_def[[Bou]] = $Function[[Gah]];
       }
-      struct $Class_decl[[A]] {
+      struct $Class_def[[A]] {
         void $Method_decl[[abc]]();
       };
     )cpp",
       R"cpp(
       namespace $Namespace_decl[[abc]] {
-        template<typename $TemplateParameter_decl[[T]]>
-        struct $Class_decl[[A]] {
+        template<typename $TemplateParameter_def[[T]]>
+        struct $Class_def[[A]] {
           $TemplateParameter[[T]] $Field_decl[[t]];
         };
       }
-      template<typename $TemplateParameter_decl[[T]]>
-      struct $Class_decl[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> {
+      template<typename $TemplateParameter_def[[T]]>
+      struct $Class_def[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> {
         typename $TemplateParameter[[T]]::$Type_dependentName[[A]]* $Field_decl[[D]];
       };
-      $Namespace[[abc]]::$Class[[A]]<int> $Variable_decl[[AA]];
+      $Namespace[[abc]]::$Class[[A]]<int> $Variable_def[[AA]];
       typedef $Namespace[[abc]]::$Class[[A]]<int> $Class_decl[[AAA]];
-      struct $Class_decl[[B]] {
+      struct $Class_def[[B]] {
         $Class_decl[[B]]();
         ~$Class[[B]](); // FIXME: inconsistent with constructor
         void operator<<($Class[[B]]);
         $Class[[AAA]] $Field_decl[[AA]];
       };
-      $Class[[B]]::$Class_decl[[B]]() {}
+      $Class[[B]]::$Class_def[[B]]() {}
       $Class[[B]]::~$Class[[B]]() {} // FIXME: inconsistent with constructor
-      void $Function_decl[[f]] () {
-        $Class[[B]] $LocalVariable_decl[[BB]] = $Class[[B]]();
+      void $Function_def[[f]] () {
+        $Class[[B]] $LocalVariable_def[[BB]] = $Class[[B]]();
         $LocalVariable[[BB]].~$Class[[B]]();
         $Class[[B]]();
       }
@@ -154,20 +163,20 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       enum $Enum_decl[[EE]] {
         $EnumConstant_decl_readonly[[Hi]],
       };
-      struct $Class_decl[[A]] {
+      struct $Class_def[[A]] {
         $Enum[[E]] $Field_decl[[EEE]];
         $Enum[[EE]] $Field_decl[[EEEE]];
       };
-      int $Variable_decl[[I]] = $EnumConstant_readonly[[Hi]];
-      $Enum[[E]] $Variable_decl[[L]] = $Enum[[E]]::$EnumConstant_readonly[[B]];
+      int $Variable_def[[I]] = $EnumConstant_readonly[[Hi]];
+      $Enum[[E]] $Variable_def[[L]] = $Enum[[E]]::$EnumConstant_readonly[[B]];
     )cpp",
       R"cpp(
       namespace $Namespace_decl[[abc]] {
         namespace {}
         namespace $Namespace_decl[[bcd]] {
-          struct $Class_decl[[A]] {};
+          struct $Class_def[[A]] {};
           namespace $Namespace_decl[[cde]] {
-            struct $Class_decl[[A]] {
+            struct $Class_def[[A]] {
               enum class $Enum_decl[[B]] {
                 $EnumConstant_decl_readonly[[Hi]],
               };
@@ -178,22 +187,22 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       using namespace $Namespace[[abc]]::$Namespace[[bcd]];
       namespace $Namespace_decl[[vwz]] =
             $Namespace[[abc]]::$Namespace[[bcd]]::$Namespace[[cde]];
-      $Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable_decl[[AA]];
-      $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]] $Variable_decl[[AAA]] =
+      $Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable_def[[AA]];
+      $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]] $Variable_def[[AAA]] =
             $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::$EnumConstant_readonly[[Hi]];
-      ::$Namespace[[vwz]]::$Class[[A]] $Variable_decl[[B]];
-      ::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable_decl[[BB]];
+      ::$Namespace[[vwz]]::$Class[[A]] $Variable_def[[B]];
+      ::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable_def[[BB]];
     )cpp",
       R"cpp(
-      struct $Class_decl[[D]] {
+      struct $Class_def[[D]] {
         double $Field_decl[[C]];
       };
-      struct $Class_decl[[A]] {
+      struct $Class_def[[A]] {
         double $Field_decl[[B]];
         $Class[[D]] $Field_decl[[E]];
         static double $StaticField_decl_static[[S]];
-        static void $StaticMethod_decl_static[[bar]]() {}
-        void $Method_decl[[foo]]() {
+        static void $StaticMethod_def_static[[bar]]() {}
+        void $Method_def[[foo]]() {
           $Field[[B]] = 123;
           this->$Field[[B]] = 156;
           this->$Method[[foo]]();
@@ -202,8 +211,8 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
           $StaticField_static[[S]] = 90.1;
         }
       };
-      void $Function_decl[[foo]]() {
-        $Class[[A]] $LocalVariable_decl[[AA]];
+      void $Function_def[[foo]]() {
+        $Class[[A]] $LocalVariable_def[[AA]];
         $LocalVariable[[AA]].$Field[[B]] += 2;
         $LocalVariable[[AA]].$Method[[foo]]();
         $LocalVariable[[AA]].$Field[[E]].$Field[[C]];
@@ -211,15 +220,15 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       }
     )cpp",
       R"cpp(
-      struct $Class_decl[[AA]] {
+      struct $Class_def[[AA]] {
         int $Field_decl[[A]];
       };
-      int $Variable_decl[[B]];
-      $Class[[AA]] $Variable_decl[[A]]{$Variable[[B]]};
+      int $Variable_def[[B]];
+      $Class[[AA]] $Variable_def[[A]]{$Variable[[B]]};
     )cpp",
       R"cpp(
       namespace $Namespace_decl[[a]] {
-        struct $Class_decl[[A]] {};
+        struct $Class_def[[A]] {};
         typedef char $Primitive_decl[[C]];
       }
       typedef $Namespace[[a]]::$Class[[A]] $Class_decl[[B]];
@@ -234,147 +243,147 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       typedef float $Primitive_decl[[F]];
     )cpp",
       R"cpp(
-      template<typename $TemplateParameter_decl[[T]], typename = void>
-      class $Class_decl[[A]] {
+      template<typename $TemplateParameter_def[[T]], typename = void>
+      class $Class_def[[A]] {
         $TemplateParameter[[T]] $Field_decl[[AA]];
         $TemplateParameter[[T]] $Method_decl[[foo]]();
       };
-      template<class $TemplateParameter_decl[[TT]]>
-      class $Class_decl[[B]] {
+      template<class $TemplateParameter_def[[TT]]>
+      class $Class_def[[B]] {
         $Class[[A]]<$TemplateParameter[[TT]]> $Field_decl[[AA]];
       };
-      template<class $TemplateParameter_decl[[TT]], class $TemplateParameter_decl[[GG]]>
-      class $Class_decl[[BB]] {};
-      template<class $TemplateParameter_decl[[T]]>
-      class $Class_decl[[BB]]<$TemplateParameter[[T]], int> {};
-      template<class $TemplateParameter_decl[[T]]>
-      class $Class_decl[[BB]]<$TemplateParameter[[T]], $TemplateParameter[[T]]*> {};
+      template<class $TemplateParameter_def[[TT]], class $TemplateParameter_def[[GG]]>
+      class $Class_def[[BB]] {};
+      template<class $TemplateParameter_def[[T]]>
+      class $Class_def[[BB]]<$TemplateParameter[[T]], int> {};
+      template<class $TemplateParameter_def[[T]]>
+      class $Class_def[[BB]]<$TemplateParameter[[T]], $TemplateParameter[[T]]*> {};
 
-      template<template<class> class $TemplateParameter_decl[[T]], class $TemplateParameter_decl[[C]]>
+      template<template<class> class $TemplateParameter_def[[T]], class $TemplateParameter_def[[C]]>
       $TemplateParameter[[T]]<$TemplateParameter[[C]]> $Function_decl[[f]]();
 
       template<typename>
-      class $Class_decl[[Foo]] {};
+      class $Class_def[[Foo]] {};
 
-      template<typename $TemplateParameter_decl[[T]]>
+      template<typename $TemplateParameter_def[[T]]>
       void $Function_decl[[foo]]($TemplateParameter[[T]] ...);
     )cpp",
       R"cpp(
-      template <class $TemplateParameter_decl[[T]]>
-      struct $Class_decl[[Tmpl]] {$TemplateParameter[[T]] $Field_decl[[x]] = 0;};
-      extern template struct $Class_decl[[Tmpl]]<float>;
-      template struct $Class_decl[[Tmpl]]<double>;
+      template <class $TemplateParameter_def[[T]]>
+      struct $Class_def[[Tmpl]] {$TemplateParameter[[T]] $Field_decl[[x]] = 0;};
+      extern template struct $Class_def[[Tmpl]]<float>;
+      template struct $Class_def[[Tmpl]]<double>;
     )cpp",
       // This test is to guard against highlightings disappearing when using
       // conversion operators as their behaviour in the clang AST 
diff er from
       // other CXXMethodDecls.
       R"cpp(
-      class $Class_decl[[Foo]] {};
-      struct $Class_decl[[Bar]] {
+      class $Class_def[[Foo]] {};
+      struct $Class_def[[Bar]] {
         explicit operator $Class[[Foo]]*() const;
         explicit operator int() const;
         operator $Class[[Foo]]();
       };
-      void $Function_decl[[f]]() {
-        $Class[[Bar]] $LocalVariable_decl[[B]];
-        $Class[[Foo]] $LocalVariable_decl[[F]] = $LocalVariable[[B]];
-        $Class[[Foo]] *$LocalVariable_decl[[FP]] = ($Class[[Foo]]*)$LocalVariable[[B]];
-        int $LocalVariable_decl[[I]] = (int)$LocalVariable[[B]];
+      void $Function_def[[f]]() {
+        $Class[[Bar]] $LocalVariable_def[[B]];
+        $Class[[Foo]] $LocalVariable_def[[F]] = $LocalVariable[[B]];
+        $Class[[Foo]] *$LocalVariable_def[[FP]] = ($Class[[Foo]]*)$LocalVariable[[B]];
+        int $LocalVariable_def[[I]] = (int)$LocalVariable[[B]];
       }
     )cpp",
       R"cpp(
-      struct $Class_decl[[B]] {};
-      struct $Class_decl[[A]] {
+      struct $Class_def[[B]] {};
+      struct $Class_def[[A]] {
         $Class[[B]] $Field_decl[[BB]];
-        $Class[[A]] &operator=($Class[[A]] &&$Parameter_decl[[O]]);
+        $Class[[A]] &operator=($Class[[A]] &&$Parameter_def[[O]]);
       };
 
-      $Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Parameter_decl[[O]]) = default;
+      $Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Parameter_def[[O]]) = default;
     )cpp",
       R"cpp(
       enum $Enum_decl[[En]] {
         $EnumConstant_decl_readonly[[EC]],
       };
-      class $Class_decl[[Foo]] {};
-      class $Class_decl[[Bar]] {
+      class $Class_def[[Foo]] {};
+      class $Class_def[[Bar]] {
       public:
         $Class[[Foo]] $Field_decl[[Fo]];
         $Enum[[En]] $Field_decl[[E]];
         int $Field_decl[[I]];
-        $Class_decl[[Bar]] ($Class[[Foo]] $Parameter_decl[[F]],
-                $Enum[[En]] $Parameter_decl[[E]])
+        $Class_def[[Bar]] ($Class[[Foo]] $Parameter_def[[F]],
+                $Enum[[En]] $Parameter_def[[E]])
         : $Field[[Fo]] ($Parameter[[F]]), $Field[[E]] ($Parameter[[E]]),
           $Field[[I]] (123) {}
       };
-      class $Class_decl[[Bar2]] : public $Class[[Bar]] {
-        $Class_decl[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant_readonly[[EC]]) {}
+      class $Class_def[[Bar2]] : public $Class[[Bar]] {
+        $Class_def[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant_readonly[[EC]]) {}
       };
     )cpp",
       R"cpp(
       enum $Enum_decl[[E]] {
         $EnumConstant_decl_readonly[[E]],
       };
-      class $Class_decl[[Foo]] {};
-      $Enum_deduced[[auto]] $Variable_decl[[AE]] = $Enum[[E]]::$EnumConstant_readonly[[E]];
-      $Class_deduced[[auto]] $Variable_decl[[AF]] = $Class[[Foo]]();
-      $Class_deduced[[decltype]](auto) $Variable_decl[[AF2]] = $Class[[Foo]]();
-      $Class_deduced[[auto]] *$Variable_decl[[AFP]] = &$Variable[[AF]];
-      $Enum_deduced[[auto]] &$Variable_decl[[AER]] = $Variable[[AE]];
-      $Primitive_deduced_defaultLibrary[[auto]] $Variable_decl[[Form]] = 10.2 + 2 * 4;
-      $Primitive_deduced_defaultLibrary[[decltype]]($Variable[[Form]]) $Variable_decl[[F]] = 10;
-      auto $Variable_decl[[Fun]] = []()->void{};
+      class $Class_def[[Foo]] {};
+      $Enum_deduced[[auto]] $Variable_def[[AE]] = $Enum[[E]]::$EnumConstant_readonly[[E]];
+      $Class_deduced[[auto]] $Variable_def[[AF]] = $Class[[Foo]]();
+      $Class_deduced[[decltype]](auto) $Variable_def[[AF2]] = $Class[[Foo]]();
+      $Class_deduced[[auto]] *$Variable_def[[AFP]] = &$Variable[[AF]];
+      $Enum_deduced[[auto]] &$Variable_def[[AER]] = $Variable[[AE]];
+      $Primitive_deduced_defaultLibrary[[auto]] $Variable_def[[Form]] = 10.2 + 2 * 4;
+      $Primitive_deduced_defaultLibrary[[decltype]]($Variable[[Form]]) $Variable_def[[F]] = 10;
+      auto $Variable_def[[Fun]] = []()->void{};
     )cpp",
       R"cpp(
-      class $Class_decl[[G]] {};
-      template<$Class[[G]] *$TemplateParameter_decl_readonly[[U]]>
-      class $Class_decl[[GP]] {};
-      template<$Class[[G]] &$TemplateParameter_decl_readonly[[U]]>
-      class $Class_decl[[GR]] {};
-      template<int *$TemplateParameter_decl_readonly[[U]]>
-      class $Class_decl[[IP]] {
-        void $Method_decl[[f]]() {
+      class $Class_def[[G]] {};
+      template<$Class[[G]] *$TemplateParameter_def_readonly[[U]]>
+      class $Class_def[[GP]] {};
+      template<$Class[[G]] &$TemplateParameter_def_readonly[[U]]>
+      class $Class_def[[GR]] {};
+      template<int *$TemplateParameter_def_readonly[[U]]>
+      class $Class_def[[IP]] {
+        void $Method_def[[f]]() {
           *$TemplateParameter_readonly[[U]] += 5;
         }
       };
-      template<unsigned $TemplateParameter_decl_readonly[[U]] = 2>
-      class $Class_decl[[Foo]] {
-        void $Method_decl[[f]]() {
-          for(int $LocalVariable_decl[[I]] = 0;
+      template<unsigned $TemplateParameter_def_readonly[[U]] = 2>
+      class $Class_def[[Foo]] {
+        void $Method_def[[f]]() {
+          for(int $LocalVariable_def[[I]] = 0;
             $LocalVariable[[I]] < $TemplateParameter_readonly[[U]];) {}
         }
       };
 
-      $Class[[G]] $Variable_decl[[L]];
-      void $Function_decl[[f]]() {
-        $Class[[Foo]]<123> $LocalVariable_decl[[F]];
-        $Class[[GP]]<&$Variable[[L]]> $LocalVariable_decl[[LL]];
-        $Class[[GR]]<$Variable[[L]]> $LocalVariable_decl[[LLL]];
+      $Class[[G]] $Variable_def[[L]];
+      void $Function_def[[f]]() {
+        $Class[[Foo]]<123> $LocalVariable_def[[F]];
+        $Class[[GP]]<&$Variable[[L]]> $LocalVariable_def[[LL]];
+        $Class[[GR]]<$Variable[[L]]> $LocalVariable_def[[LLL]];
       }
     )cpp",
       R"cpp(
-      template<typename $TemplateParameter_decl[[T]],
-        void ($TemplateParameter[[T]]::*$TemplateParameter_decl_readonly[[method]])(int)>
-      struct $Class_decl[[G]] {
-        void $Method_decl[[foo]](
-            $TemplateParameter[[T]] *$Parameter_decl[[O]]) {
+      template<typename $TemplateParameter_def[[T]],
+        void ($TemplateParameter[[T]]::*$TemplateParameter_def_readonly[[method]])(int)>
+      struct $Class_def[[G]] {
+        void $Method_def[[foo]](
+            $TemplateParameter[[T]] *$Parameter_def[[O]]) {
           ($Parameter[[O]]->*$TemplateParameter_readonly[[method]])(10);
         }
       };
-      struct $Class_decl[[F]] {
+      struct $Class_def[[F]] {
         void $Method_decl[[f]](int);
       };
-      template<void (*$TemplateParameter_decl_readonly[[Func]])()>
-      struct $Class_decl[[A]] {
-        void $Method_decl[[f]]() {
+      template<void (*$TemplateParameter_def_readonly[[Func]])()>
+      struct $Class_def[[A]] {
+        void $Method_def[[f]]() {
           (*$TemplateParameter_readonly[[Func]])();
         }
       };
 
-      void $Function_decl[[foo]]() {
-        $Class[[F]] $LocalVariable_decl[[FF]];
-        $Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $LocalVariable_decl[[GG]];
+      void $Function_def[[foo]]() {
+        $Class[[F]] $LocalVariable_def[[FF]];
+        $Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $LocalVariable_def[[GG]];
         $LocalVariable[[GG]].$Method[[foo]](&$LocalVariable[[FF]]);
-        $Class[[A]]<$Function[[foo]]> $LocalVariable_decl[[AA]];
+        $Class[[A]]<$Function[[foo]]> $LocalVariable_def[[AA]];
       }
     )cpp",
       // Tokens that share a source range but have conflicting Kinds are not
@@ -385,7 +394,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       // Preamble ends.
       $Macro[[DEF_MULTIPLE]](XYZ);
       $Macro[[DEF_MULTIPLE]](XYZW);
-      $Macro[[DEF_CLASS]]($Class_decl[[A]])
+      $Macro[[DEF_CLASS]]($Class_def[[A]])
       #define $Macro_decl[[MACRO_CONCAT]](X, V, T) T foo##X = V
       #define $Macro_decl[[DEF_VAR]](X, V) int X = V
       #define $Macro_decl[[DEF_VAR_T]](T, X, V) T X = V
@@ -395,27 +404,27 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       #define $Macro_decl[[SOME_NAME]] variable
       #define $Macro_decl[[SOME_NAME_SET]] variable2 = 123
       #define $Macro_decl[[INC_VAR]](X) X += 2
-      void $Function_decl[[foo]]() {
-        $Macro[[DEF_VAR]]($LocalVariable_decl[[X]],  123);
-        $Macro[[DEF_VAR_REV]](908, $LocalVariable_decl[[XY]]);
-        int $Macro[[CPY]]( $LocalVariable_decl[[XX]] );
-        $Macro[[DEF_VAR_TYPE]]($Class[[A]], $LocalVariable_decl[[AA]]);
+      void $Function_def[[foo]]() {
+        $Macro[[DEF_VAR]]($LocalVariable_def[[X]],  123);
+        $Macro[[DEF_VAR_REV]](908, $LocalVariable_def[[XY]]);
+        int $Macro[[CPY]]( $LocalVariable_def[[XX]] );
+        $Macro[[DEF_VAR_TYPE]]($Class[[A]], $LocalVariable_def[[AA]]);
         double $Macro[[SOME_NAME]];
         int $Macro[[SOME_NAME_SET]];
         $LocalVariable[[variable]] = 20.1;
         $Macro[[MACRO_CONCAT]](var, 2, float);
         $Macro[[DEF_VAR_T]]($Class[[A]], $Macro[[CPY]](
-              $Macro[[CPY]]($LocalVariable_decl[[Nested]])),
+              $Macro[[CPY]]($LocalVariable_def[[Nested]])),
             $Macro[[CPY]]($Class[[A]]()));
         $Macro[[INC_VAR]]($LocalVariable[[variable]]);
       }
       void $Macro[[SOME_NAME]]();
-      $Macro[[DEF_VAR]]($Variable_decl[[MMMMM]], 567);
-      $Macro[[DEF_VAR_REV]](756, $Variable_decl[[AB]]);
+      $Macro[[DEF_VAR]]($Variable_def[[MMMMM]], 567);
+      $Macro[[DEF_VAR_REV]](756, $Variable_def[[AB]]);
 
       #define $Macro_decl[[CALL_FN]](F) F();
       #define $Macro_decl[[DEF_FN]](F) void F ()
-      $Macro[[DEF_FN]]($Function_decl[[g]]) {
+      $Macro[[DEF_FN]]($Function_def[[g]]) {
         $Macro[[CALL_FN]]($Function[[foo]]);
       }
     )cpp",
@@ -423,10 +432,10 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       #define $Macro_decl[[fail]](expr) expr
       #define $Macro_decl[[assert]](COND) if (!(COND)) { fail("assertion failed" #COND); }
       // Preamble ends.
-      int $Variable_decl[[x]];
-      int $Variable_decl[[y]];
+      int $Variable_def[[x]];
+      int $Variable_def[[y]];
       int $Function_decl[[f]]();
-      void $Function_decl[[foo]]() {
+      void $Function_def[[foo]]() {
         $Macro[[assert]]($Variable[[x]] != $Variable[[y]]);
         $Macro[[assert]]($Variable[[x]] != $Function[[f]]());
       }
@@ -446,14 +455,14 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
 $InactiveCode[[#endif]]
     )cpp",
       R"cpp(
-      struct $Class_decl[[S]] {
+      struct $Class_def[[S]] {
         float $Field_decl[[Value]];
         $Class[[S]] *$Field_decl[[Next]];
       };
-      $Class[[S]] $Variable_decl[[Global]][2] = {$Class[[S]](), $Class[[S]]()};
+      $Class[[S]] $Variable_def[[Global]][2] = {$Class[[S]](), $Class[[S]]()};
       auto [$Variable_decl[[G1]], $Variable_decl[[G2]]] = $Variable[[Global]];
-      void $Function_decl[[f]]($Class[[S]] $Parameter_decl[[P]]) {
-        int $LocalVariable_decl[[A]][2] = {1,2};
+      void $Function_def[[f]]($Class[[S]] $Parameter_def[[P]]) {
+        int $LocalVariable_def[[A]][2] = {1,2};
         auto [$LocalVariable_decl[[B1]], $LocalVariable_decl[[B2]]] = $LocalVariable[[A]];
         auto [$LocalVariable_decl[[G1]], $LocalVariable_decl[[G2]]] = $Variable[[Global]];
         $Class_deduced[[auto]] [$LocalVariable_decl[[P1]], $LocalVariable_decl[[P2]]] = $Parameter[[P]];
@@ -462,8 +471,8 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       }
     )cpp",
       R"cpp(
-      template<class $TemplateParameter_decl[[T]]>
-      class $Class_decl[[A]] {
+      template<class $TemplateParameter_def[[T]]>
+      class $Class_def[[A]] {
         using $TemplateParameter_decl[[TemplateParam1]] = $TemplateParameter[[T]];
         typedef $TemplateParameter[[T]] $TemplateParameter_decl[[TemplateParam2]];
         using $Primitive_decl[[IntType]] = int;
@@ -481,53 +490,53 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       };
     )cpp",
       R"cpp(
-      template <class $TemplateParameter_decl[[T]]>
+      template <class $TemplateParameter_def[[T]]>
       void $Function_decl[[phase1]]($TemplateParameter[[T]]);
-      template <class $TemplateParameter_decl[[T]]>
-      void $Function_decl[[foo]]($TemplateParameter[[T]] $Parameter_decl[[P]]) {
+      template <class $TemplateParameter_def[[T]]>
+      void $Function_def[[foo]]($TemplateParameter[[T]] $Parameter_def[[P]]) {
         $Function[[phase1]]($Parameter[[P]]);
         $Unknown_dependentName[[phase2]]($Parameter[[P]]);
       }
     )cpp",
       R"cpp(
-      class $Class_decl[[A]] {
-        template <class $TemplateParameter_decl[[T]]>
+      class $Class_def[[A]] {
+        template <class $TemplateParameter_def[[T]]>
         void $Method_decl[[bar]]($TemplateParameter[[T]]);
       };
 
-      template <class $TemplateParameter_decl[[U]]>
-      void $Function_decl[[foo]]($TemplateParameter[[U]] $Parameter_decl[[P]]) {
+      template <class $TemplateParameter_def[[U]]>
+      void $Function_def[[foo]]($TemplateParameter[[U]] $Parameter_def[[P]]) {
         $Class[[A]]().$Method[[bar]]($Parameter[[P]]);
       }
     )cpp",
       R"cpp(
-      struct $Class_decl[[A]] {
-        template <class $TemplateParameter_decl[[T]]>
+      struct $Class_def[[A]] {
+        template <class $TemplateParameter_def[[T]]>
         static void $StaticMethod_decl_static[[foo]]($TemplateParameter[[T]]);
       };
 
-      template <class $TemplateParameter_decl[[T]]>
-      struct $Class_decl[[B]] {
-        void $Method_decl[[bar]]() {
+      template <class $TemplateParameter_def[[T]]>
+      struct $Class_def[[B]] {
+        void $Method_def[[bar]]() {
           $Class[[A]]::$StaticMethod_static[[foo]]($TemplateParameter[[T]]());
         }
       };
     )cpp",
       R"cpp(
-      template <class $TemplateParameter_decl[[T]]>
+      template <class $TemplateParameter_def[[T]]>
       void $Function_decl[[foo]](typename $TemplateParameter[[T]]::$Type_dependentName[[Type]]
                                             = $TemplateParameter[[T]]::$Unknown_dependentName[[val]]);
     )cpp",
       R"cpp(
-      template <class $TemplateParameter_decl[[T]]>
-      void $Function_decl[[foo]]($TemplateParameter[[T]] $Parameter_decl[[P]]) {
+      template <class $TemplateParameter_def[[T]]>
+      void $Function_def[[foo]]($TemplateParameter[[T]] $Parameter_def[[P]]) {
         $Parameter[[P]].$Unknown_dependentName[[Field]];
       }
     )cpp",
       R"cpp(
-      template <class $TemplateParameter_decl[[T]]>
-      class $Class_decl[[A]] {
-        int $Method_decl[[foo]]() {
+      template <class $TemplateParameter_def[[T]]>
+      class $Class_def[[A]] {
+        int $Method_def[[foo]]() {
           return $TemplateParameter[[T]]::$Unknown_dependentName[[Field]];
         }
       };
@@ -539,9 +548,9 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
     )cpp",
       // Highlighting of template template arguments.
       R"cpp(
-      template <template <class> class $TemplateParameter_decl[[TT]],
-                template <class> class ...$TemplateParameter_decl[[TTs]]>
-      struct $Class_decl[[Foo]] {
+      template <template <class> class $TemplateParameter_def[[TT]],
+                template <class> class ...$TemplateParameter_def[[TTs]]>
+      struct $Class_def[[Foo]] {
         $Class[[Foo]]<$TemplateParameter[[TT]], $TemplateParameter[[TTs]]...>
           *$Field_decl[[t]];
       };
@@ -554,7 +563,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
 $InactiveCode[[#endif]]
 
       // A declaration to cause the preamble to end.
-      int $Variable_decl[[EndPreamble]];
+      int $Variable_def[[EndPreamble]];
 
       // Code after the preamble.
       // Code inside inactive blocks does not get regular highlightings
@@ -563,33 +572,33 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
 $InactiveCode[[#if defined(test)]]
 $InactiveCode[[int Inactive2;]]
 $InactiveCode[[#elif defined(test2)]]
-      int $Variable_decl[[Active1]];
+      int $Variable_def[[Active1]];
 $InactiveCode[[#else]]
 $InactiveCode[[int Inactive3;]]
 $InactiveCode[[#endif]]
 
       #ifndef $Macro[[test]]
-      int $Variable_decl[[Active2]];
+      int $Variable_def[[Active2]];
       #endif
 
 $InactiveCode[[#ifdef test]]
 $InactiveCode[[int Inactive4;]]
 $InactiveCode[[#else]]
-      int $Variable_decl[[Active3]];
+      int $Variable_def[[Active3]];
       #endif
     )cpp",
       // Argument to 'sizeof...'
       R"cpp(
-      template <typename... $TemplateParameter_decl[[Elements]]>
-      struct $Class_decl[[TupleSize]] {
+      template <typename... $TemplateParameter_def[[Elements]]>
+      struct $Class_def[[TupleSize]] {
         static const int $StaticField_decl_readonly_static[[size]] =
 sizeof...($TemplateParameter[[Elements]]);
       };
     )cpp",
       // More dependent types
       R"cpp(
-      template <typename $TemplateParameter_decl[[T]]>
-      struct $Class_decl[[Waldo]] {
+      template <typename $TemplateParameter_def[[T]]>
+      struct $Class_def[[Waldo]] {
         using $Typedef_decl[[Location1]] = typename $TemplateParameter[[T]]
             ::$Type_dependentName[[Resolver]]::$Type_dependentName[[Location]];
         using $Typedef_decl[[Location2]] = typename $TemplateParameter[[T]]
@@ -605,116 +614,116 @@ sizeof...($TemplateParameter[[Elements]]);
       // Dependent name with heuristic target
       R"cpp(
       template <typename>
-      struct $Class_decl[[Foo]] {
+      struct $Class_def[[Foo]] {
         int $Field_decl[[Waldo]];
-        void $Method_decl[[bar]]() {
+        void $Method_def[[bar]]() {
           $Class[[Foo]]().$Field_dependentName[[Waldo]];
         }
-        template <typename $TemplateParameter_decl[[U]]>
-        void $Method_decl[[bar1]]() {
+        template <typename $TemplateParameter_def[[U]]>
+        void $Method_def[[bar1]]() {
           $Class[[Foo]]<$TemplateParameter[[U]]>().$Field_dependentName[[Waldo]];
         }
 
         void $Method_decl[[Overload]]();
         void $Method_decl_readonly[[Overload]]() const;
       };
-      template <typename $TemplateParameter_decl[[T]]>
-      void $Function_decl[[baz]]($Class[[Foo]]<$TemplateParameter[[T]]> $Parameter_decl[[o]]) {
+      template <typename $TemplateParameter_def[[T]]>
+      void $Function_def[[baz]]($Class[[Foo]]<$TemplateParameter[[T]]> $Parameter_def[[o]]) {
         $Parameter[[o]].$Method_readonly_dependentName[[Overload]]();
       }
     )cpp",
       // Concepts
       R"cpp(
-      template <typename $TemplateParameter_decl[[T]]>
-      concept $Concept_decl[[Fooable]] = 
-          requires($TemplateParameter[[T]] $Parameter_decl[[F]]) {
+      template <typename $TemplateParameter_def[[T]]>
+      concept $Concept_decl[[Fooable]] =
+          requires($TemplateParameter[[T]] $Parameter_def[[F]]) {
             $Parameter[[F]].$Unknown_dependentName[[foo]]();
           };
-      template <typename $TemplateParameter_decl[[T]]>
+      template <typename $TemplateParameter_def[[T]]>
           requires $Concept[[Fooable]]<$TemplateParameter[[T]]>
-      void $Function_decl[[bar]]($TemplateParameter[[T]] $Parameter_decl[[F]]) {
+      void $Function_def[[bar]]($TemplateParameter[[T]] $Parameter_def[[F]]) {
         $Parameter[[F]].$Unknown_dependentName[[foo]]();
       }
     )cpp",
       // Dependent template name
       R"cpp(
-      template <template <typename> class> struct $Class_decl[[A]] {};
-      template <typename $TemplateParameter_decl[[T]]>
+      template <template <typename> class> struct $Class_def[[A]] {};
+      template <typename $TemplateParameter_def[[T]]>
       using $Typedef_decl[[W]] = $Class[[A]]<
         $TemplateParameter[[T]]::template $Class_dependentName[[Waldo]]
       >;
     )cpp",
       R"cpp(
-      class $Class_decl_abstract[[Abstract]] {
+      class $Class_def_abstract[[Abstract]] {
       public:
         virtual void $Method_decl_abstract_virtual[[pure]]() = 0;
         virtual void $Method_decl_virtual[[impl]]();
       };
-      void $Function_decl[[foo]]($Class_abstract[[Abstract]]* $Parameter_decl[[A]]) {
+      void $Function_def[[foo]]($Class_abstract[[Abstract]]* $Parameter_def[[A]]) {
           $Parameter[[A]]->$Method_abstract_virtual[[pure]]();
           $Parameter[[A]]->$Method_virtual[[impl]]();
       }
       )cpp",
       R"cpp(
-      <:[deprecated]:> int $Variable_decl_deprecated[[x]];
+      <:[deprecated]:> int $Variable_def_deprecated[[x]];
       )cpp",
       R"cpp(
         // ObjC: Classes and methods
         @class $Class_decl[[Forward]];
 
-        @interface $Class_decl[[Foo]]
+        @interface $Class_def[[Foo]]
         @end
-        @interface $Class_decl[[Bar]] : $Class[[Foo]]
-        -(id) $Method_decl[[x]]:(int)$Parameter_decl[[a]] $Method_decl[[y]]:(int)$Parameter_decl[[b]];
+        @interface $Class_def[[Bar]] : $Class[[Foo]]
+        -(id) $Method_decl[[x]]:(int)$Parameter_def[[a]] $Method_decl[[y]]:(int)$Parameter_def[[b]];
         +(instancetype)$StaticMethod_decl_static[[sharedInstance]];
         +(void) $StaticMethod_decl_static[[explode]];
         @end
-        @implementation $Class_decl[[Bar]]
-        -(id) $Method_decl[[x]]:(int)$Parameter_decl[[a]] $Method_decl[[y]]:(int)$Parameter_decl[[b]] {
+        @implementation $Class_def[[Bar]]
+        -(id) $Method_def[[x]]:(int)$Parameter_def[[a]] $Method_def[[y]]:(int)$Parameter_def[[b]] {
           return self;
         }
-        +(instancetype)$StaticMethod_decl_static[[sharedInstance]] { return 0; }
-        +(void) $StaticMethod_decl_static[[explode]] {}
+        +(instancetype)$StaticMethod_def_static[[sharedInstance]] { return 0; }
+        +(void) $StaticMethod_def_static[[explode]] {}
         @end
 
-        void $Function_decl[[m]]($Class[[Bar]] *$Parameter_decl[[b]]) {
+        void $Function_def[[m]]($Class[[Bar]] *$Parameter_def[[b]]) {
           [$Parameter[[b]] $Method[[x]]:1 $Method[[y]]:2];
           [$Class[[Bar]] $StaticMethod_static[[explode]]];
         }
       )cpp",
       R"cpp(
         // ObjC: Protocols
-        @protocol $Interface_decl[[Protocol]]
+        @protocol $Interface_def[[Protocol]]
         @end
-        @protocol $Interface_decl[[Protocol2]] <$Interface[[Protocol]]>
+        @protocol $Interface_def[[Protocol2]] <$Interface[[Protocol]]>
         @end
-        @interface $Class_decl[[Klass]] <$Interface[[Protocol]]>
+        @interface $Class_def[[Klass]] <$Interface[[Protocol]]>
         @end
-        id<$Interface[[Protocol]]> $Variable_decl[[x]];
+        id<$Interface[[Protocol]]> $Variable_def[[x]];
       )cpp",
       R"cpp(
         // ObjC: Categories
-        @interface $Class_decl[[Foo]]
+        @interface $Class_def[[Foo]]
         @end
-        @interface $Class[[Foo]]($Namespace_decl[[Bar]])
+        @interface $Class[[Foo]]($Namespace_def[[Bar]])
         @end
-        @implementation $Class[[Foo]]($Namespace_decl[[Bar]])
+        @implementation $Class[[Foo]]($Namespace_def[[Bar]])
         @end
       )cpp",
       R"cpp(
         // ObjC: Properties and Ivars.
-        @interface $Class_decl[[Foo]] {
+        @interface $Class_def[[Foo]] {
           int $Field_decl[[_someProperty]];
         }
         @property(nonatomic, assign) int $Field_decl[[someProperty]];
         @property(readonly, class) $Class[[Foo]] *$Field_decl_readonly_static[[sharedInstance]];
         @end
-        @implementation $Class_decl[[Foo]]
+        @implementation $Class_def[[Foo]]
         @synthesize someProperty = _someProperty;
-        - (int)$Method_decl[[otherMethod]] {
+        - (int)$Method_def[[otherMethod]] {
           return 0;
         }
-        - (int)$Method_decl[[doSomething]] {
+        - (int)$Method_def[[doSomething]] {
           $Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] = 1;
           self.$Field[[someProperty]] = self.$Field[[someProperty]] + self.$Field[[otherMethod]] + 1;
           self->$Field[[_someProperty]] = $Field[[_someProperty]] + 1;
@@ -723,32 +732,32 @@ sizeof...($TemplateParameter[[Elements]]);
       )cpp",
       // Member imported from dependent base
       R"cpp(
-        template <typename> struct $Class_decl[[Base]] {
+        template <typename> struct $Class_def[[Base]] {
           int $Field_decl[[member]];
         };
-        template <typename $TemplateParameter_decl[[T]]>
-        struct $Class_decl[[Derived]] : $Class[[Base]]<$TemplateParameter[[T]]> {
+        template <typename $TemplateParameter_def[[T]]>
+        struct $Class_def[[Derived]] : $Class[[Base]]<$TemplateParameter[[T]]> {
           using $Class[[Base]]<$TemplateParameter[[T]]>::$Field_dependentName[[member]];
 
-          void $Method_decl[[method]]() {
+          void $Method_def[[method]]() {
             (void)$Field_dependentName[[member]];
           }
         };
       )cpp",
       // Modifier for variables passed as non-const references
       R"cpp(
-        struct $Class_decl[[ClassWithOp]] {
+        struct $Class_def[[ClassWithOp]] {
             void operator()(int);
             void operator()(int, int &);
             void operator()(int, int, const int &);
             int &operator[](int &);
             int operator[](int) const;
         };
-        struct $Class_decl[[ClassWithStaticMember]] {
-            static inline int $StaticField_decl_static[[j]] = 0;
+        struct $Class_def[[ClassWithStaticMember]] {
+            static inline int $StaticField_def_static[[j]] = 0;
         };
-        struct $Class_decl[[ClassWithRefMembers]] {
-          $Class_decl[[ClassWithRefMembers]](int $Parameter_decl[[i]])
+        struct $Class_def[[ClassWithRefMembers]] {
+          $Class_def[[ClassWithRefMembers]](int $Parameter_def[[i]])
             : $Field[[i1]]($Parameter[[i]]),
               $Field_readonly[[i2]]($Parameter[[i]]),
               $Field[[i3]]($Parameter_usedAsMutableReference[[i]]),
@@ -761,61 +770,61 @@ sizeof...($TemplateParameter[[Elements]]);
           const int &$Field_decl_readonly[[i4]];
           int &$Field_decl[[i5]];
         };
-        void $Function_decl[[fun]](int, const int,
+        void $Function_def[[fun]](int, const int,
                                    int*, const int*,
                                    int&, const int&,
                                    int*&, const int*&, const int* const &,
                                    int**, int**&, int** const &,
                                    int = 123) {
-          int $LocalVariable_decl[[val]];
-          int* $LocalVariable_decl[[ptr]];
-          const int* $LocalVariable_decl_readonly[[constPtr]];
-          int** $LocalVariable_decl[[array]];
-          $Function[[fun]]($LocalVariable[[val]], $LocalVariable[[val]], 
-                           $LocalVariable[[ptr]], $LocalVariable_readonly[[constPtr]], 
-                           $LocalVariable_usedAsMutableReference[[val]], $LocalVariable[[val]], 
+          int $LocalVariable_def[[val]];
+          int* $LocalVariable_def[[ptr]];
+          const int* $LocalVariable_def_readonly[[constPtr]];
+          int** $LocalVariable_def[[array]];
+          $Function[[fun]]($LocalVariable[[val]], $LocalVariable[[val]],
+                           $LocalVariable[[ptr]], $LocalVariable_readonly[[constPtr]],
+                           $LocalVariable_usedAsMutableReference[[val]], $LocalVariable[[val]],
 
                            $LocalVariable_usedAsMutableReference[[ptr]],
                            $LocalVariable_readonly_usedAsMutableReference[[constPtr]],
                            $LocalVariable_readonly[[constPtr]],
 
-                           $LocalVariable[[array]], $LocalVariable_usedAsMutableReference[[array]], 
+                           $LocalVariable[[array]], $LocalVariable_usedAsMutableReference[[array]],
                            $LocalVariable[[array]]
                            );
           [](int){}($LocalVariable[[val]]);
           [](int&){}($LocalVariable_usedAsMutableReference[[val]]);
           [](const int&){}($LocalVariable[[val]]);
-          $Class[[ClassWithOp]] $LocalVariable_decl[[c]];
-          const $Class[[ClassWithOp]] $LocalVariable_decl_readonly[[c2]];
+          $Class[[ClassWithOp]] $LocalVariable_def[[c]];
+          const $Class[[ClassWithOp]] $LocalVariable_def_readonly[[c2]];
           $LocalVariable[[c]]($LocalVariable[[val]]);
           $LocalVariable[[c]](0, $LocalVariable_usedAsMutableReference[[val]]);
           $LocalVariable[[c]](0, 0, $LocalVariable[[val]]);
           $LocalVariable[[c]][$LocalVariable_usedAsMutableReference[[val]]];
           $LocalVariable_readonly[[c2]][$LocalVariable[[val]]];
         }
-        struct $Class_decl[[S]] {
-          $Class_decl[[S]](int&) {
-            $Class[[S]] $LocalVariable_decl[[s1]]($Field_usedAsMutableReference[[field]]);
-            $Class[[S]] $LocalVariable_decl[[s2]]($LocalVariable[[s1]].$Field_usedAsMutableReference[[field]]);
+        struct $Class_def[[S]] {
+          $Class_def[[S]](int&) {
+            $Class[[S]] $LocalVariable_def[[s1]]($Field_usedAsMutableReference[[field]]);
+            $Class[[S]] $LocalVariable_def[[s2]]($LocalVariable[[s1]].$Field_usedAsMutableReference[[field]]);
 
-            $Class[[S]] $LocalVariable_decl[[s3]]($StaticField_static_usedAsMutableReference[[staticField]]);
-            $Class[[S]] $LocalVariable_decl[[s4]]($Class[[S]]::$StaticField_static_usedAsMutableReference[[staticField]]);
+            $Class[[S]] $LocalVariable_def[[s3]]($StaticField_static_usedAsMutableReference[[staticField]]);
+            $Class[[S]] $LocalVariable_def[[s4]]($Class[[S]]::$StaticField_static_usedAsMutableReference[[staticField]]);
           }
           int $Field_decl[[field]];
           static int $StaticField_decl_static[[staticField]];
         };
-        template <typename $TemplateParameter_decl[[X]]>
-        void $Function_decl[[foo]]($TemplateParameter[[X]]& $Parameter_decl[[x]]) {
+        template <typename $TemplateParameter_def[[X]]>
+        void $Function_def[[foo]]($TemplateParameter[[X]]& $Parameter_def[[x]]) {
           // We do not support dependent types, so this one should *not* get the modifier.
-          $Function[[foo]]($Parameter[[x]]); 
+          $Function[[foo]]($Parameter[[x]]);
         }
       )cpp",
       // init-captures
       R"cpp(
-        void $Function_decl[[foo]]() {
-          int $LocalVariable_decl[[a]], $LocalVariable_decl[[b]];
-          [ $LocalVariable_decl[[c]] = $LocalVariable[[a]],
-            $LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}();
+        void $Function_def[[foo]]() {
+          int $LocalVariable_def[[a]], $LocalVariable_def[[b]];
+          [ $LocalVariable_def[[c]] = $LocalVariable[[a]],
+            $LocalVariable_def[[d]]($LocalVariable[[b]]) ]() {}();
         }
       )cpp",
       // Enum base specifier
@@ -840,19 +849,19 @@ sizeof...($TemplateParameter[[Elements]]);
       R"cpp(
         void $Function_decl[[Foo]]();
         // Use <: :> digraphs for deprecated attribute to avoid conflict with annotation syntax
-        <:<:deprecated:>:> void $Function_decl_deprecated[[Foo]](int* $Parameter_decl[[x]]);
-        void $Function_decl[[Foo]](int $Parameter_decl[[x]]);
-        template <typename $TemplateParameter_decl[[T]]>
-        void $Function_decl[[Bar]]($TemplateParameter[[T]] $Parameter_decl[[x]]) {
-            $Function_deprecated[[Foo]]($Parameter[[x]]); 
-            $Function_deprecated[[Foo]]($Parameter[[x]]); 
-            $Function_deprecated[[Foo]]($Parameter[[x]]); 
+        <:<:deprecated:>:> void $Function_decl_deprecated[[Foo]](int* $Parameter_def[[x]]);
+        void $Function_decl[[Foo]](int $Parameter_def[[x]]);
+        template <typename $TemplateParameter_def[[T]]>
+        void $Function_def[[Bar]]($TemplateParameter[[T]] $Parameter_def[[x]]) {
+            $Function_deprecated[[Foo]]($Parameter[[x]]);
+            $Function_deprecated[[Foo]]($Parameter[[x]]);
+            $Function_deprecated[[Foo]]($Parameter[[x]]);
         }
       )cpp",
       // Predefined identifiers
       R"cpp(
-        void $Function_decl[[Foo]]() {
-            const char *$LocalVariable_decl_readonly[[s]] = $LocalVariable_readonly_static[[__func__]];
+        void $Function_def[[Foo]]() {
+            const char *$LocalVariable_def_readonly[[s]] = $LocalVariable_readonly_static[[__func__]];
         }
       )cpp",
       // Issue 1022: readonly modifier for generic parameter
@@ -868,16 +877,16 @@ sizeof...($TemplateParameter[[Elements]]);
       )cpp",
       // Explicit template specialization
       R"cpp(
-        struct $Class_decl[[Base]]{};
-        template <typename $TemplateParameter_decl[[T]]>
-        struct $Class_decl[[S]] : public $Class[[Base]] {};
-        template <> 
-        struct $Class_decl[[S]]<void> : public $Class[[Base]] {};
+        struct $Class_def[[Base]]{};
+        template <typename $TemplateParameter_def[[T]]>
+        struct $Class_def[[S]] : public $Class[[Base]] {};
+        template <>
+        struct $Class_def[[S]]<void> : public $Class[[Base]] {};
 
-        template <typename $TemplateParameter_decl[[T]]>
-        $TemplateParameter[[T]] $Variable_decl[[x]] = {};
+        template <typename $TemplateParameter_def[[T]]>
+        $TemplateParameter[[T]] $Variable_def[[x]] = {};
         template <>
-        int $Variable_decl[[x]]<int> = (int)sizeof($Class[[Base]]);
+        int $Variable_def[[x]]<int> = (int)sizeof($Class[[Base]]);
       )cpp"};
   for (const auto &TestCase : TestCases)
     // Mask off scope modifiers to keep the tests manageable.
@@ -885,7 +894,7 @@ sizeof...($TemplateParameter[[Elements]]);
     checkHighlightings(TestCase, {}, ~ScopeModifierMask);
 
   checkHighlightings(R"cpp(
-    class $Class_decl[[A]] {
+    class $Class_def[[A]] {
       #include "imp.h"
     };
   )cpp",
@@ -911,11 +920,11 @@ sizeof...($TemplateParameter[[Elements]]);
 
   checkHighlightings(R"cpp(
     #include "SYSObject.h"
-    @interface $Class_defaultLibrary[[SYSObject]] ($Namespace_decl[[UserCategory]])
+    @interface $Class_defaultLibrary[[SYSObject]] ($Namespace_def[[UserCategory]])
     @property(nonatomic, readonly) int $Field_decl_readonly[[user_property]];
     @end
-    int $Function_decl[[somethingUsingSystemSymbols]]() {
-      $Class_defaultLibrary[[SYSObject]] *$LocalVariable_decl[[obj]] = [$Class_defaultLibrary[[SYSObject]] $StaticMethod_static_defaultLibrary[[new]]];
+    int $Function_def[[somethingUsingSystemSymbols]]() {
+      $Class_defaultLibrary[[SYSObject]] *$LocalVariable_def[[obj]] = [$Class_defaultLibrary[[SYSObject]] $StaticMethod_static_defaultLibrary[[new]]];
       return $LocalVariable[[obj]].$Field_defaultLibrary[[value]] + $LocalVariable[[obj]].$Field_readonly[[user_property]];
     }
   )cpp",

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp
index e8ccef9947fef..359491e9ddb95 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp
@@ -18,18 +18,18 @@ TWEAK_TEST(AnnotateHighlightings);
 TEST_F(AnnotateHighlightingsTest, Test) {
   EXPECT_AVAILABLE("^vo^id^ ^f(^) {^}^"); // available everywhere.
   EXPECT_AVAILABLE("[[int a; int b;]]");
-  EXPECT_EQ("void /* Function [decl] [globalScope] */f() {}",
+  EXPECT_EQ("void /* Function [decl] [def] [globalScope] */f() {}",
             apply("void ^f() {}"));
 
   EXPECT_EQ(apply("[[int f1(); const int x = f1();]]"),
             "int /* Function [decl] [globalScope] */f1(); "
-            "const int /* Variable [decl] [readonly] [fileScope] */x = "
+            "const int /* Variable [decl] [def] [readonly] [fileScope] */x = "
             "/* Function [globalScope] */f1();");
 
   // Only the targeted range is annotated.
   EXPECT_EQ(apply("void f1(); void f2() {^}"),
             "void f1(); "
-            "void /* Function [decl] [globalScope] */f2() {}");
+            "void /* Function [decl] [def] [globalScope] */f2() {}");
 }
 
 } // namespace


        


More information about the cfe-commits mailing list