Skip to content

Commit 83aad7a

Browse files
committed
Merge from 'master' to 'sycl-web' (#35)
CONFLICT (content): Merge conflict in clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
2 parents 582b321 + 60a99f4 commit 83aad7a

File tree

600 files changed

+2804
-924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

600 files changed

+2804
-924
lines changed

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ class HighlightingTokenCollector
225225
addToken(Loc, HighlightingKind::Parameter);
226226
return;
227227
}
228-
if (isa<VarDecl>(D)) {
229-
addToken(Loc, HighlightingKind::Variable);
228+
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
229+
addToken(Loc, VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
230+
: HighlightingKind::Variable);
230231
return;
231232
}
232233
if (isa<FunctionDecl>(D)) {
@@ -256,7 +257,7 @@ class HighlightingTokenCollector
256257
}
257258

258259
void addToken(SourceLocation Loc, HighlightingKind Kind) {
259-
if(Loc.isMacroID()) {
260+
if (Loc.isMacroID()) {
260261
// Only intereseted in highlighting arguments in macros (DEF_X(arg)).
261262
if (!SM.isMacroArgExpansion(Loc))
262263
return;
@@ -266,8 +267,8 @@ class HighlightingTokenCollector
266267
// Non top level decls that are included from a header are not filtered by
267268
// topLevelDecls. (example: method declarations being included from another
268269
// file for a class from another file)
269-
// There are also cases with macros where the spelling loc will not be in the
270-
// main file and the highlighting would be incorrect.
270+
// There are also cases with macros where the spelling loc will not be in
271+
// the main file and the highlighting would be incorrect.
271272
if (!isInsideMainFile(Loc, SM))
272273
return;
273274

@@ -367,9 +368,9 @@ diffHighlightings(ArrayRef<HighlightingToken> New,
367368
auto OldEnd = Old.end();
368369
auto NextLineNumber = [&]() {
369370
int NextNew = NewLine.end() != NewEnd ? NewLine.end()->R.start.line
370-
: std::numeric_limits<int>::max();
371+
: std::numeric_limits<int>::max();
371372
int NextOld = OldLine.end() != OldEnd ? OldLine.end()->R.start.line
372-
: std::numeric_limits<int>::max();
373+
: std::numeric_limits<int>::max();
373374
return std::min(NextNew, NextOld);
374375
};
375376

@@ -436,6 +437,8 @@ llvm::StringRef toTextMateScope(HighlightingKind Kind) {
436437
return "entity.name.function.method.cpp";
437438
case HighlightingKind::Variable:
438439
return "variable.other.cpp";
440+
case HighlightingKind::LocalVariable:
441+
return "variable.other.local.cpp";
439442
case HighlightingKind::Parameter:
440443
return "variable.parameter.cpp";
441444
case HighlightingKind::Field:

clang-tools-extra/clangd/SemanticHighlighting.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace clangd {
2525

2626
enum class HighlightingKind {
2727
Variable = 0,
28+
LocalVariable,
2829
Parameter,
2930
Function,
3031
Method,

clang-tools-extra/clangd/test/semantic-highlighting.test

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
# CHECK-NEXT: "variable.other.cpp"
99
# CHECK-NEXT: ],
1010
# CHECK-NEXT: [
11+
# CHECK-NEXT: "variable.other.local.cpp"
12+
# CHECK-NEXT: ],
13+
# CHECK-NEXT: [
1114
# CHECK-NEXT: "variable.parameter.cpp"
1215
# CHECK-NEXT: ],
1316
# CHECK-NEXT: [
@@ -46,7 +49,7 @@
4649
# CHECK-NEXT: "lines": [
4750
# CHECK-NEXT: {
4851
# CHECK-NEXT: "line": 0,
49-
# CHECK-NEXT: "tokens": "AAAAAAADAAoAAAAEAAEAAA=="
52+
# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
5053
# CHECK-NEXT: }
5154
# CHECK-NEXT: ],
5255
# CHECK-NEXT: "textDocument": {
@@ -61,11 +64,11 @@
6164
# CHECK-NEXT: "lines": [
6265
# CHECK-NEXT: {
6366
# CHECK-NEXT: "line": 0,
64-
# CHECK-NEXT: "tokens": "AAAAAAADAAoAAAAEAAEAAA=="
67+
# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
6568
# CHECK-NEXT: }
6669
# CHECK-NEXT: {
6770
# CHECK-NEXT: "line": 1,
68-
# CHECK-NEXT: "tokens": "AAAAAAADAAoAAAAEAAEAAA=="
71+
# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
6972
# CHECK-NEXT: }
7073
# CHECK-NEXT: ],
7174
# CHECK-NEXT: "textDocument": {
@@ -80,7 +83,7 @@
8083
# CHECK-NEXT: "lines": [
8184
# CHECK-NEXT: {
8285
# CHECK-NEXT: "line": 1,
83-
# CHECK-NEXT: "tokens": "AAAAAAADAAoAAAAEAAEAAA=="
86+
# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
8487
# CHECK-NEXT: }
8588
# CHECK-NEXT: ],
8689
# CHECK-NEXT: "textDocument": {

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ std::vector<HighlightingToken> getExpectedTokens(Annotations &Test) {
4444
{HighlightingKind::Field, "Field"},
4545
{HighlightingKind::Method, "Method"},
4646
{HighlightingKind::TemplateParameter, "TemplateParameter"},
47-
{HighlightingKind::Primitive, "Primitive"}};
47+
{HighlightingKind::Primitive, "Primitive"},
48+
{HighlightingKind::LocalVariable, "LocalVariable"}};
4849
std::vector<HighlightingToken> ExpectedTokens;
4950
for (const auto &KindString : KindToString) {
5051
std::vector<HighlightingToken> Toks = makeHighlightingTokens(
@@ -103,31 +104,31 @@ void checkDiffedHighlights(llvm::StringRef OldCode, llvm::StringRef NewCode) {
103104

104105
TEST(SemanticHighlighting, GetsCorrectTokens) {
105106
const char *TestCases[] = {
106-
R"cpp(
107+
R"cpp(
107108
struct $Class[[AS]] {
108109
$Primitive[[double]] $Field[[SomeMember]];
109110
};
110111
struct {
111112
} $Variable[[S]];
112113
$Primitive[[void]] $Function[[foo]]($Primitive[[int]] $Parameter[[A]], $Class[[AS]] $Parameter[[As]]) {
113-
$Primitive[[auto]] $Variable[[VeryLongVariableName]] = 12312;
114-
$Class[[AS]] $Variable[[AA]];
115-
$Primitive[[auto]] $Variable[[L]] = $Variable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
116-
auto $Variable[[FN]] = [ $Variable[[AA]]]($Primitive[[int]] $Parameter[[A]]) -> $Primitive[[void]] {};
117-
$Variable[[FN]](12312);
114+
$Primitive[[auto]] $LocalVariable[[VeryLongVariableName]] = 12312;
115+
$Class[[AS]] $LocalVariable[[AA]];
116+
$Primitive[[auto]] $LocalVariable[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
117+
auto $LocalVariable[[FN]] = [ $LocalVariable[[AA]]]($Primitive[[int]] $Parameter[[A]]) -> $Primitive[[void]] {};
118+
$LocalVariable[[FN]](12312);
118119
}
119120
)cpp",
120-
R"cpp(
121+
R"cpp(
121122
$Primitive[[void]] $Function[[foo]]($Primitive[[int]]);
122123
$Primitive[[void]] $Function[[Gah]]();
123124
$Primitive[[void]] $Function[[foo]]() {
124-
auto $Variable[[Bou]] = $Function[[Gah]];
125+
auto $LocalVariable[[Bou]] = $Function[[Gah]];
125126
}
126127
struct $Class[[A]] {
127128
$Primitive[[void]] $Method[[abc]]();
128129
};
129130
)cpp",
130-
R"cpp(
131+
R"cpp(
131132
namespace $Namespace[[abc]] {
132133
template<typename $TemplateParameter[[T]]>
133134
struct $Class[[A]] {
@@ -149,12 +150,12 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
149150
$Class[[B]]::$Class[[B]]() {}
150151
$Class[[B]]::~$Class[[B]]() {}
151152
$Primitive[[void]] $Function[[f]] () {
152-
$Class[[B]] $Variable[[BB]] = $Class[[B]]();
153-
$Variable[[BB]].~$Class[[B]]();
153+
$Class[[B]] $LocalVariable[[BB]] = $Class[[B]]();
154+
$LocalVariable[[BB]].~$Class[[B]]();
154155
$Class[[B]]();
155156
}
156157
)cpp",
157-
R"cpp(
158+
R"cpp(
158159
enum class $Enum[[E]] {
159160
$EnumConstant[[A]],
160161
$EnumConstant[[B]],
@@ -169,7 +170,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
169170
$Primitive[[int]] $Variable[[I]] = $EnumConstant[[Hi]];
170171
$Enum[[E]] $Variable[[L]] = $Enum[[E]]::$EnumConstant[[B]];
171172
)cpp",
172-
R"cpp(
173+
R"cpp(
173174
namespace $Namespace[[abc]] {
174175
namespace {}
175176
namespace $Namespace[[bcd]] {
@@ -192,7 +193,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
192193
::$Namespace[[vwz]]::$Class[[A]] $Variable[[B]];
193194
::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[BB]];
194195
)cpp",
195-
R"cpp(
196+
R"cpp(
196197
struct $Class[[D]] {
197198
$Primitive[[double]] $Field[[C]];
198199
};
@@ -209,21 +210,21 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
209210
}
210211
};
211212
$Primitive[[void]] $Function[[foo]]() {
212-
$Class[[A]] $Variable[[AA]];
213-
$Variable[[AA]].$Field[[B]] += 2;
214-
$Variable[[AA]].$Method[[foo]]();
215-
$Variable[[AA]].$Field[[E]].$Field[[C]];
213+
$Class[[A]] $LocalVariable[[AA]];
214+
$LocalVariable[[AA]].$Field[[B]] += 2;
215+
$LocalVariable[[AA]].$Method[[foo]]();
216+
$LocalVariable[[AA]].$Field[[E]].$Field[[C]];
216217
$Class[[A]]::$Variable[[S]] = 90;
217218
}
218219
)cpp",
219-
R"cpp(
220+
R"cpp(
220221
struct $Class[[AA]] {
221222
$Primitive[[int]] $Field[[A]];
222223
}
223224
$Primitive[[int]] $Variable[[B]];
224225
$Class[[AA]] $Variable[[A]]{$Variable[[B]]};
225226
)cpp",
226-
R"cpp(
227+
R"cpp(
227228
namespace $Namespace[[a]] {
228229
struct $Class[[A]] {};
229230
typedef $Primitive[[char]] $Primitive[[C]];
@@ -239,7 +240,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
239240
typedef $Namespace[[a]]::$Primitive[[C]] $Primitive[[PC]];
240241
typedef $Primitive[[float]] $Primitive[[F]];
241242
)cpp",
242-
R"cpp(
243+
R"cpp(
243244
template<typename $TemplateParameter[[T]], typename = $Primitive[[void]]>
244245
class $Class[[A]] {
245246
$TemplateParameter[[T]] $Field[[AA]];
@@ -265,30 +266,30 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
265266
template<typename $TemplateParameter[[T]]>
266267
$Primitive[[void]] $Function[[foo]]($TemplateParameter[[T]] ...);
267268
)cpp",
268-
R"cpp(
269+
R"cpp(
269270
template <class $TemplateParameter[[T]]>
270271
struct $Class[[Tmpl]] {$TemplateParameter[[T]] $Field[[x]] = 0;};
271272
extern template struct $Class[[Tmpl]]<$Primitive[[float]]>;
272273
template struct $Class[[Tmpl]]<$Primitive[[double]]>;
273274
)cpp",
274-
// This test is to guard against highlightings disappearing when using
275-
// conversion operators as their behaviour in the clang AST differ from
276-
// other CXXMethodDecls.
277-
R"cpp(
275+
// This test is to guard against highlightings disappearing when using
276+
// conversion operators as their behaviour in the clang AST differ from
277+
// other CXXMethodDecls.
278+
R"cpp(
278279
class $Class[[Foo]] {};
279280
struct $Class[[Bar]] {
280281
explicit operator $Class[[Foo]]*() const;
281282
explicit operator $Primitive[[int]]() const;
282283
operator $Class[[Foo]]();
283284
};
284285
$Primitive[[void]] $Function[[f]]() {
285-
$Class[[Bar]] $Variable[[B]];
286-
$Class[[Foo]] $Variable[[F]] = $Variable[[B]];
287-
$Class[[Foo]] *$Variable[[FP]] = ($Class[[Foo]]*)$Variable[[B]];
288-
$Primitive[[int]] $Variable[[I]] = ($Primitive[[int]])$Variable[[B]];
286+
$Class[[Bar]] $LocalVariable[[B]];
287+
$Class[[Foo]] $LocalVariable[[F]] = $LocalVariable[[B]];
288+
$Class[[Foo]] *$LocalVariable[[FP]] = ($Class[[Foo]]*)$LocalVariable[[B]];
289+
$Primitive[[int]] $LocalVariable[[I]] = ($Primitive[[int]])$LocalVariable[[B]];
289290
}
290291
)cpp"
291-
R"cpp(
292+
R"cpp(
292293
struct $Class[[B]] {};
293294
struct $Class[[A]] {
294295
$Class[[B]] $Field[[BB]];
@@ -297,7 +298,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
297298
298299
$Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Parameter[[O]]) = default;
299300
)cpp",
300-
R"cpp(
301+
R"cpp(
301302
enum $Enum[[En]] {
302303
$EnumConstant[[EC]],
303304
};
@@ -315,7 +316,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
315316
$Class[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant[[EC]]) {}
316317
};
317318
)cpp",
318-
R"cpp(
319+
R"cpp(
319320
enum $Enum[[E]] {
320321
$EnumConstant[[E]],
321322
};
@@ -329,7 +330,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
329330
$Primitive[[decltype]]($Variable[[Form]]) $Variable[[F]] = 10;
330331
auto $Variable[[Fun]] = []()->$Primitive[[void]]{};
331332
)cpp",
332-
R"cpp(
333+
R"cpp(
333334
class $Class[[G]] {};
334335
template<$Class[[G]] *$TemplateParameter[[U]]>
335336
class $Class[[GP]] {};
@@ -344,19 +345,19 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
344345
template<$Primitive[[unsigned]] $TemplateParameter[[U]] = 2>
345346
class $Class[[Foo]] {
346347
$Primitive[[void]] $Method[[f]]() {
347-
for($Primitive[[int]] $Variable[[I]] = 0;
348-
$Variable[[I]] < $TemplateParameter[[U]];) {}
348+
for($Primitive[[int]] $LocalVariable[[I]] = 0;
349+
$LocalVariable[[I]] < $TemplateParameter[[U]];) {}
349350
}
350351
};
351352
352353
$Class[[G]] $Variable[[L]];
353354
$Primitive[[void]] $Function[[f]]() {
354-
$Class[[Foo]]<123> $Variable[[F]];
355-
$Class[[GP]]<&$Variable[[L]]> $Variable[[LL]];
356-
$Class[[GR]]<$Variable[[L]]> $Variable[[LLL]];
355+
$Class[[Foo]]<123> $LocalVariable[[F]];
356+
$Class[[GP]]<&$Variable[[L]]> $LocalVariable[[LL]];
357+
$Class[[GR]]<$Variable[[L]]> $LocalVariable[[LLL]];
357358
}
358359
)cpp",
359-
R"cpp(
360+
R"cpp(
360361
template<typename $TemplateParameter[[T]],
361362
$Primitive[[void]] (T::*$TemplateParameter[[method]])($Primitive[[int]])>
362363
struct $Class[[G]] {
@@ -376,14 +377,14 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
376377
};
377378
378379
$Primitive[[void]] $Function[[foo]]() {
379-
$Class[[F]] $Variable[[FF]];
380-
$Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $Variable[[GG]];
381-
$Variable[[GG]].$Method[[foo]](&$Variable[[FF]]);
382-
$Class[[A]]<$Function[[foo]]> $Variable[[AA]];
380+
$Class[[F]] $LocalVariable[[FF]];
381+
$Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $LocalVariable[[GG]];
382+
$LocalVariable[[GG]].$Method[[foo]](&$LocalVariable[[FF]]);
383+
$Class[[A]]<$Function[[foo]]> $LocalVariable[[AA]];
383384
)cpp",
384-
// Tokens that share a source range but have conflicting Kinds are not
385-
// highlighted.
386-
R"cpp(
385+
// Tokens that share a source range but have conflicting Kinds are not
386+
// highlighted.
387+
R"cpp(
387388
#define DEF_MULTIPLE(X) namespace X { class X { int X; }; }
388389
#define DEF_CLASS(T) class T {};
389390
DEF_MULTIPLE(XYZ);
@@ -399,17 +400,17 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
399400
#define SOME_NAME_SET variable2 = 123
400401
#define INC_VAR(X) X += 2
401402
$Primitive[[void]] $Function[[foo]]() {
402-
DEF_VAR($Variable[[X]], 123);
403-
DEF_VAR_REV(908, $Variable[[XY]]);
404-
$Primitive[[int]] CPY( $Variable[[XX]] );
405-
DEF_VAR_TYPE($Class[[A]], $Variable[[AA]]);
403+
DEF_VAR($LocalVariable[[X]], 123);
404+
DEF_VAR_REV(908, $LocalVariable[[XY]]);
405+
$Primitive[[int]] CPY( $LocalVariable[[XX]] );
406+
DEF_VAR_TYPE($Class[[A]], $LocalVariable[[AA]]);
406407
$Primitive[[double]] SOME_NAME;
407408
$Primitive[[int]] SOME_NAME_SET;
408-
$Variable[[variable]] = 20.1;
409+
$LocalVariable[[variable]] = 20.1;
409410
MACRO_CONCAT(var, 2, $Primitive[[float]]);
410-
DEF_VAR_T($Class[[A]], CPY(CPY($Variable[[Nested]])),
411+
DEF_VAR_T($Class[[A]], CPY(CPY($LocalVariable[[Nested]])),
411412
CPY($Class[[A]]()));
412-
INC_VAR($Variable[[variable]]);
413+
INC_VAR($LocalVariable[[variable]]);
413414
}
414415
$Primitive[[void]] SOME_NAME();
415416
DEF_VAR($Variable[[XYZ]], 567);
@@ -421,7 +422,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
421422
CALL_FN($Function[[foo]]);
422423
}
423424
)cpp",
424-
R"cpp(
425+
R"cpp(
425426
#define fail(expr) expr
426427
#define assert(COND) if (!(COND)) { fail("assertion failed" #COND); }
427428
$Primitive[[int]] $Variable[[x]];
@@ -505,7 +506,7 @@ TEST(SemanticHighlighting, toSemanticHighlightingInformation) {
505506
std::vector<SemanticHighlightingInformation> ActualResults =
506507
toSemanticHighlightingInformation(Tokens);
507508
std::vector<SemanticHighlightingInformation> ExpectedResults = {
508-
{3, "AAAACAAEAAAAAAAEAAMAAg=="}, {1, "AAAAAQAEAAA="}};
509+
{3, "AAAACAAEAAAAAAAEAAMAAw=="}, {1, "AAAAAQAEAAA="}};
509510
EXPECT_EQ(ActualResults, ExpectedResults);
510511
}
511512

clang/.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Windows line ending tests
2+
test/Lexer/minimize_source_to_dependency_directives_invalid_error.c text eol=crlf
3+
test/FixIt/fixit-newline-style.c text eol=crlf
4+
test/Frontend/system-header-line-directive-ms-lineendings.c text eol=crlf

0 commit comments

Comments
 (0)