diff --git a/clang-tools-extra/clangd/SemanticHighlighting.h b/clang-tools-extra/clangd/SemanticHighlighting.h --- a/clang-tools-extra/clangd/SemanticHighlighting.h +++ b/clang-tools-extra/clangd/SemanticHighlighting.h @@ -61,7 +61,7 @@ enum class HighlightingModifier { Declaration, - // FIXME: Definition (needs findExplicitReferences support) + Definition, Deprecated, Deduced, Readonly, diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -66,6 +66,20 @@ llvm_unreachable("invalid name kind"); } +bool isUniqueDefinition(const NamedDecl *Decl) { + if (auto *Func = dyn_cast(Decl)) + return Func->isThisDeclarationADefinition(); + if (auto *Klass = dyn_cast(Decl)) + return Klass->isThisDeclarationADefinition(); + if (auto *Iface = dyn_cast(Decl)) + return Iface->isThisDeclarationADefinition(); + if (auto *Proto = dyn_cast(Decl)) + return Proto->isThisDeclarationADefinition(); + if (auto *Var = dyn_cast(Decl)) + return Var->isThisDeclarationADefinition(); + return isa(Decl) || isa(Decl); +} + llvm::Optional kindForType(const Type *TP, const HeuristicResolver *Resolver); llvm::Optional @@ -660,7 +674,7 @@ // We handle objective-C selectors specially, because one reference can // cover several non-contiguous tokens. void highlightObjCSelector(const ArrayRef &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 +682,8 @@ 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 +694,9 @@ bool VisitObjCMethodDecl(ObjCMethodDecl *OMD) { llvm::SmallVector 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 +706,8 @@ 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 +876,15 @@ 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(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(Decl)) + Tok.addModifier(HighlightingModifier::Declaration); + if (isUniqueDefinition(Decl)) + Tok.addModifier(HighlightingModifier::Definition); + } } }, AST.getHeuristicResolver()); @@ -934,6 +955,8 @@ 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 +1088,8 @@ 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/test/initialize-params.test b/clang-tools-extra/clangd/test/initialize-params.test --- 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 --- 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 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -48,12 +48,21 @@ 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(HighlightingModifier::LastModifier); ++I) { - if (T.Modifiers & (1 << I)) - OS << '_' << static_cast(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(I); + } } OS << "[[" << Input.substr(StartOffset, EndOffset - StartOffset) << "]]"; NextChar = EndOffset; @@ -96,52 +105,52 @@ 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 - struct $Class_decl[[A]] { + struct $Class_def[[A]] { $TemplateParameter[[T]] $Field_decl[[t]]; }; } template - struct $Class_decl[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> { + struct $Class_def[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> { typename $TemplateParameter[[T]]::$Type_dependentName[[A]]* $Field_decl[[D]]; }; - $Namespace[[abc]]::$Class[[A]] $Variable_decl[[AA]]; + $Namespace[[abc]]::$Class[[A]] $Variable_def[[AA]]; typedef $Namespace[[abc]]::$Class[[A]] $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 @@ 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 @@ 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 @@ $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 @@ } )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]]; @@ -235,146 +244,146 @@ )cpp", R"cpp( template - class $Class_decl[[A]] { + class $Class_def[[A]] { $TemplateParameter[[T]] $Field_decl[[AA]]; $TemplateParameter[[T]] $Method_decl[[foo]](); }; template - class $Class_decl[[B]] { + class $Class_def[[B]] { $Class[[A]]<$TemplateParameter[[TT]]> $Field_decl[[AA]]; }; template - class $Class_decl[[BB]] {}; + class $Class_def[[BB]] {}; template - class $Class_decl[[BB]]<$TemplateParameter[[T]], int> {}; + class $Class_def[[BB]]<$TemplateParameter[[T]], int> {}; template - class $Class_decl[[BB]]<$TemplateParameter[[T]], $TemplateParameter[[T]]*> {}; + class $Class_def[[BB]]<$TemplateParameter[[T]], $TemplateParameter[[T]]*> {}; template class $TemplateParameter_decl[[T]], class $TemplateParameter_decl[[C]]> $TemplateParameter[[T]]<$TemplateParameter[[C]]> $Function_decl[[f]](); template - class $Class_decl[[Foo]] {}; + class $Class_def[[Foo]] {}; template void $Function_decl[[foo]]($TemplateParameter[[T]] ...); )cpp", R"cpp( template - struct $Class_decl[[Tmpl]] {$TemplateParameter[[T]] $Field_decl[[x]] = 0;}; - extern template struct $Class_decl[[Tmpl]]; - template struct $Class_decl[[Tmpl]]; + struct $Class_def[[Tmpl]] {$TemplateParameter[[T]] $Field_decl[[x]] = 0;}; + extern template struct $Class_def[[Tmpl]]; + template struct $Class_def[[Tmpl]]; )cpp", // This test is to guard against highlightings disappearing when using // conversion operators as their behaviour in the clang AST differ 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]] {}; + class $Class_def[[G]] {}; template<$Class[[G]] *$TemplateParameter_decl_readonly[[U]]> - class $Class_decl[[GP]] {}; + class $Class_def[[GP]] {}; template<$Class[[G]] &$TemplateParameter_decl_readonly[[U]]> - class $Class_decl[[GR]] {}; + class $Class_def[[GR]] {}; template - class $Class_decl[[IP]] { - void $Method_decl[[f]]() { + class $Class_def[[IP]] { + void $Method_def[[f]]() { *$TemplateParameter_readonly[[U]] += 5; } }; template - class $Class_decl[[Foo]] { - void $Method_decl[[f]]() { - for(int $LocalVariable_decl[[I]] = 0; + 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 - struct $Class_decl[[G]] { - void $Method_decl[[foo]]( - $TemplateParameter[[T]] *$Parameter_decl[[O]]) { + 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 - struct $Class_decl[[A]] { - void $Method_decl[[f]]() { + 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 @@ // 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 @@ #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 @@ #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 @@ $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]]; @@ -463,7 +472,7 @@ )cpp", R"cpp( template - class $Class_decl[[A]] { + class $Class_def[[A]] { using $TemplateParameter_decl[[TemplateParam1]] = $TemplateParameter[[T]]; typedef $TemplateParameter[[T]] $TemplateParameter_decl[[TemplateParam2]]; using $Primitive_decl[[IntType]] = int; @@ -484,31 +493,31 @@ template void $Function_decl[[phase1]]($TemplateParameter[[T]]); template - void $Function_decl[[foo]]($TemplateParameter[[T]] $Parameter_decl[[P]]) { + 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]] { + class $Class_def[[A]] { template void $Method_decl[[bar]]($TemplateParameter[[T]]); }; template - void $Function_decl[[foo]]($TemplateParameter[[U]] $Parameter_decl[[P]]) { + void $Function_def[[foo]]($TemplateParameter[[U]] $Parameter_def[[P]]) { $Class[[A]]().$Method[[bar]]($Parameter[[P]]); } )cpp", R"cpp( - struct $Class_decl[[A]] { + struct $Class_def[[A]] { template static void $StaticMethod_decl_static[[foo]]($TemplateParameter[[T]]); }; template - struct $Class_decl[[B]] { - void $Method_decl[[bar]]() { + struct $Class_def[[B]] { + void $Method_def[[bar]]() { $Class[[A]]::$StaticMethod_static[[foo]]($TemplateParameter[[T]]()); } }; @@ -520,14 +529,14 @@ )cpp", R"cpp( template - void $Function_decl[[foo]]($TemplateParameter[[T]] $Parameter_decl[[P]]) { + void $Function_def[[foo]]($TemplateParameter[[T]] $Parameter_def[[P]]) { $Parameter[[P]].$Unknown_dependentName[[Field]]; } )cpp", R"cpp( template - class $Class_decl[[A]] { - int $Method_decl[[foo]]() { + class $Class_def[[A]] { + int $Method_def[[foo]]() { return $TemplateParameter[[T]]::$Unknown_dependentName[[Field]]; } }; @@ -541,7 +550,7 @@ R"cpp( template