ckandeler created this revision. ckandeler added a reviewer: sammccall. Herald added subscribers: kadircet, arphaman. Herald added a project: All. ckandeler requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
This is useful for clients that want to highlight constructors and/or destructors different from classes, e.g. like functions. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134728 Files: 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
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -133,16 +133,16 @@ $Namespace[[abc]]::$Class[[A]]<int> $Variable_decl[[AA]]; typedef $Namespace[[abc]]::$Class[[A]]<int> $Class_decl[[AAA]]; struct $Class_decl[[B]] { - $Class_decl[[B]](); - ~$Class[[B]](); // FIXME: inconsistent with constructor + $Class_decl_constructor[[B]](); + ~$Class_decl_destructor[[B]](); void operator<<($Class[[B]]); $Class[[AAA]] $Field_decl[[AA]]; }; - $Class[[B]]::$Class_decl[[B]]() {} - $Class[[B]]::~$Class[[B]]() {} // FIXME: inconsistent with constructor + $Class[[B]]::$Class_decl_constructor[[B]]() {} + $Class[[B]]::~$Class_decl_destructor[[B]]() {} void $Function_decl[[f]] () { $Class[[B]] $LocalVariable_decl[[BB]] = $Class[[B]](); - $LocalVariable[[BB]].~$Class[[B]](); + $LocalVariable[[BB]].~$Class_destructor[[B]](); $Class[[B]](); } )cpp", @@ -301,13 +301,13 @@ $Class[[Foo]] $Field_decl[[Fo]]; $Enum[[En]] $Field_decl[[E]]; int $Field_decl[[I]]; - $Class_decl[[Bar]] ($Class[[Foo]] $Parameter_decl[[F]], + $Class_decl_constructor[[Bar]] ($Class[[Foo]] $Parameter_decl[[F]], $Enum[[En]] $Parameter_decl[[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_decl_constructor[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant_readonly[[EC]]) {} }; )cpp", R"cpp( @@ -748,7 +748,7 @@ static inline int $StaticField_decl_static[[j]] = 0; }; struct $Class_decl[[ClassWithRefMembers]] { - $Class_decl[[ClassWithRefMembers]](int $Parameter_decl[[i]]) + $Class_decl_constructor[[ClassWithRefMembers]](int $Parameter_decl[[i]]) : $Field[[i1]]($Parameter[[i]]), $Field_readonly[[i2]]($Parameter[[i]]), $Field[[i3]]($Parameter_usedAsMutableReference[[i]]), @@ -794,7 +794,7 @@ $LocalVariable_readonly[[c2]][$LocalVariable[[val]]]; } struct $Class_decl[[S]] { - $Class_decl[[S]](int&) { + $Class_decl_constructor[[S]](int&) { $Class[[S]] $LocalVariable_decl[[s1]]($Field_usedAsMutableReference[[field]]); $Class[[S]] $LocalVariable_decl[[s2]]($LocalVariable[[s1]].$Field_usedAsMutableReference[[field]]); Index: clang-tools-extra/clangd/test/semantic-tokens.test =================================================================== --- clang-tools-extra/clangd/test/semantic-tokens.test +++ 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: 32769 # 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: 32769 # 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: 32769, # CHECK-NEXT: 1, # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 8193 +# CHECK-NEXT: 32769 # CHECK-NEXT: ], # CHECK-NEXT: "resultId": "3" # CHECK-NEXT: } Index: clang-tools-extra/clangd/test/initialize-params.test =================================================================== --- clang-tools-extra/clangd/test/initialize-params.test +++ clang-tools-extra/clangd/test/initialize-params.test @@ -67,6 +67,8 @@ # CHECK-NEXT: "dependentName", # CHECK-NEXT: "defaultLibrary", # CHECK-NEXT: "usedAsMutableReference", +# CHECK-NEXT: "constructor", +# CHECK-NEXT: "destructor", # CHECK-NEXT: "functionScope", # CHECK-NEXT: "classScope", # CHECK-NEXT: "fileScope", Index: clang-tools-extra/clangd/SemanticHighlighting.h =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.h +++ clang-tools-extra/clangd/SemanticHighlighting.h @@ -71,6 +71,8 @@ DependentName, DefaultLibrary, UsedAsMutableReference, + Constructor, + Destructor, FunctionScope, ClassScope, Index: clang-tools-extra/clangd/SemanticHighlighting.cpp =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.cpp +++ clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -632,6 +632,27 @@ return true; } + bool VisitCXXDestructorDecl(CXXDestructorDecl *D) { + if (auto *TI = D->getNameInfo().getNamedTypeInfo()) { + SourceLocation Loc = TI->getTypeLoc().getBeginLoc(); + H.addExtraModifier(Loc, HighlightingModifier::Destructor); + H.addExtraModifier(Loc, HighlightingModifier::Declaration); + } + return true; + } + + bool VisitCXXMemberCallExpr(CXXMemberCallExpr *CE) { + if (isa<CXXDestructorDecl>(CE->getMethodDecl())) { + if (auto *ME = dyn_cast<MemberExpr>(CE->getCallee())) { + if (auto *TI = ME->getMemberNameInfo().getNamedTypeInfo()) { + H.addExtraModifier(TI->getTypeLoc().getBeginLoc(), + HighlightingModifier::Destructor); + } + } + } + return true; + } + bool VisitDeclaratorDecl(DeclaratorDecl *D) { auto *AT = D->getType()->getContainedAutoType(); if (!AT) @@ -859,6 +880,8 @@ Tok.addModifier(HighlightingModifier::DefaultLibrary); if (Decl->isDeprecated()) Tok.addModifier(HighlightingModifier::Deprecated); + if (isa<CXXConstructorDecl>(Decl)) + Tok.addModifier(HighlightingModifier::Constructor); // Do not treat an UnresolvedUsingValueDecl as a declaration. // It's more common to think of it as a reference to the // underlying declaration. @@ -1083,6 +1106,10 @@ return "defaultLibrary"; case HighlightingModifier::UsedAsMutableReference: return "usedAsMutableReference"; // nonstandard + case HighlightingModifier::Constructor: + return "constructor"; // nonstandard + case HighlightingModifier::Destructor: + return "destructor"; // nonstandard case HighlightingModifier::FunctionScope: return "functionScope"; // nonstandard case HighlightingModifier::ClassScope:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits