Skip to content

Commit f71404c

Browse files
committed
[clangd] Replace usages of dummy with more descriptive words
Dummy is a word with inappropriate associations. This patch updates the references to it in clangd code base with more precise ones. The only user-visible change is the default variable name used when extracting a variable. It will be named as `placeholder` from now on. Differential Revision: https://reviews.llvm.org/D99065
1 parent b3b002b commit f71404c

17 files changed

+59
-55
lines changed

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ void ClangdServer::prepareRename(PathRef File, Position Pos,
497497
// prepareRename is latency-sensitive: we don't query the index, as we
498498
// only need main-file references
499499
auto Results =
500-
clangd::rename({Pos, NewName.getValueOr("__clangd_rename_dummy"),
500+
clangd::rename({Pos, NewName.getValueOr("__clangd_rename_placeholder"),
501501
InpAST->AST, File, /*FS=*/nullptr,
502502
/*Index=*/nullptr, RenameOpts});
503503
if (!Results) {

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ std::string detectClangPath() {
9696
if (auto PathCC = llvm::sys::findProgramByName(Name))
9797
return resolve(std::move(*PathCC));
9898
// Fallback: a nonexistent 'clang' binary next to clangd.
99-
static int Dummy;
99+
static int StaticForMainAddr;
100100
std::string ClangdExecutable =
101-
llvm::sys::fs::getMainExecutable("clangd", (void *)&Dummy);
101+
llvm::sys::fs::getMainExecutable("clangd", (void *)&StaticForMainAddr);
102102
SmallString<128> ClangPath;
103103
ClangPath = llvm::sys::path::parent_path(ClangdExecutable);
104104
llvm::sys::path::append(ClangPath, "clang");
@@ -120,8 +120,9 @@ const llvm::Optional<std::string> detectSysroot() {
120120
}
121121

122122
std::string detectStandardResourceDir() {
123-
static int Dummy; // Just an address in this process.
124-
return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
123+
static int StaticForMainAddr; // Just an address in this process.
124+
return CompilerInvocation::GetResourcesPath("clangd",
125+
(void *)&StaticForMainAddr);
125126
}
126127

127128
// The path passed to argv[0] is important:

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,10 @@ class DocumentOutline {
376376

377377
/// Builds the document outline for the generated AST.
378378
std::vector<DocumentSymbol> build() {
379-
SymBuilder DummyRoot;
379+
SymBuilder Root;
380380
for (auto &TopLevel : AST.getLocalTopLevelDecls())
381-
traverseDecl(TopLevel, DummyRoot);
382-
return std::move(std::move(DummyRoot).build().children);
381+
traverseDecl(TopLevel, Root);
382+
return std::move(std::move(Root).build().children);
383383
}
384384

385385
private:

clang-tools-extra/clangd/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace {
2323
/// as it isn't sure where the errors are and so can't correct.
2424
/// When editing, it's reasonable to assume code before the cursor is complete.
2525
void closeBrackets(std::string &Code, const format::FormatStyle &Style) {
26-
SourceManagerForFile FileSM("dummy.cpp", Code);
26+
SourceManagerForFile FileSM("mock_file.cpp", Code);
2727
auto &SM = FileSM.get();
2828
FileID FID = SM.getMainFileID();
2929
Lexer Lex(FID, SM.getBufferOrFake(FID), SM,

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class HighlightingsBuilder {
294294
HighlightingToken &addToken(SourceLocation Loc, HighlightingKind Kind) {
295295
Loc = getHighlightableSpellingToken(Loc, SourceMgr);
296296
if (Loc.isInvalid())
297-
return Dummy;
297+
return InvalidHighlightingToken;
298298
const auto *Tok = TB.spelledTokenAt(Loc);
299299
assert(Tok);
300300
return addToken(
@@ -395,7 +395,8 @@ class HighlightingsBuilder {
395395
const SourceManager &SourceMgr;
396396
const LangOptions &LangOpts;
397397
std::vector<HighlightingToken> Tokens;
398-
HighlightingToken Dummy; // returned from addToken(InvalidLoc)
398+
// returned from addToken(InvalidLoc)
399+
HighlightingToken InvalidHighlightingToken;
399400
};
400401

401402
llvm::Optional<HighlightingModifier> scopeModifier(const NamedDecl *D) {

clang-tools-extra/clangd/SourceCode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ lex(llvm::StringRef Code, const LangOptions &LangOpts,
599599
Action) {
600600
// FIXME: InMemoryFileAdapter crashes unless the buffer is null terminated!
601601
std::string NullTerminatedCode = Code.str();
602-
SourceManagerForFile FileSM("dummy.cpp", NullTerminatedCode);
602+
SourceManagerForFile FileSM("mock_file_name.cpp", NullTerminatedCode);
603603
auto &SM = FileSM.get();
604604
for (const auto &Tok : syntax::tokenize(SM.getMainFileID(), SM, LangOpts))
605605
Action(Tok, SM);

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ SymbolLocation toIndexLocation(const Location &Loc, std::string &URIStorage) {
162162
SymbolLocation getPreferredLocation(const Location &ASTLoc,
163163
const SymbolLocation &IdxLoc,
164164
std::string &Scratch) {
165-
// Also use a dummy symbol for the index location so that other fields (e.g.
165+
// Also use a mock symbol for the index location so that other fields (e.g.
166166
// definition) are not factored into the preference.
167167
Symbol ASTSym, IdxSym;
168-
ASTSym.ID = IdxSym.ID = SymbolID("dummy_id");
168+
ASTSym.ID = IdxSym.ID = SymbolID("mock_symbol_id");
169169
ASTSym.CanonicalDeclaration = toIndexLocation(ASTLoc, Scratch);
170170
IdxSym.CanonicalDeclaration = IdxLoc;
171171
auto Merged = mergeSymbol(ASTSym, IdxSym);

clang-tools-extra/clangd/fuzzer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(LLVM_LINK_COMPONENTS
99
# This fuzzer runs on oss-fuzz, so keep it around even if it looks unreferenced.
1010
add_llvm_fuzzer(clangd-fuzzer
1111
clangd-fuzzer.cpp
12-
DUMMY_MAIN DummyClangdMain.cpp
12+
DUMMY_MAIN FuzzerClangdMain.cpp
1313
)
1414

1515
clang_target_link_libraries(clangd-fuzzer

clang-tools-extra/clangd/fuzzer/DummyClangdMain.cpp renamed to clang-tools-extra/clangd/fuzzer/FuzzerClangdMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===---- DummyClangdMain.cpp - Entry point to sanity check the fuzzer ----===//
1+
//===--- FuzzerClangdMain.cpp - Entry point to sanity check the fuzzer ----===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang-tools-extra/clangd/index/remote/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ if (CLANGD_ENABLE_REMOTE)
3939
add_subdirectory(marshalling)
4040
add_subdirectory(server)
4141
else()
42-
# Provides a dummy implementation of clangdRemoteIndex.
42+
# Provides a no-op implementation of clangdRemoteIndex.
4343
add_subdirectory(unimplemented)
4444
endif()

clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
376376
if (llvm::isa<DeclRefExpr>(E) || llvm::isa<MemberExpr>(E))
377377
return false;
378378

379-
// Extracting Exprs like a = 1 gives dummy = a = 1 which isn't useful.
379+
// Extracting Exprs like a = 1 gives placeholder = a = 1 which isn't useful.
380380
// FIXME: we could still hoist the assignment, and leave the variable there?
381381
ParsedBinaryOperator BinOp;
382382
if (BinOp.parse(*N) && BinaryOperator::isAssignmentOp(BinOp.Kind))
@@ -387,7 +387,7 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
387387
if (!Parent)
388388
return false;
389389
// We don't want to extract expressions used as statements, that would leave
390-
// a `dummy;` around that has no effect.
390+
// a `placeholder;` around that has no effect.
391391
// Unfortunately because the AST doesn't have ExprStmt, we have to check in
392392
// this roundabout way.
393393
if (childExprIsStmt(Parent->ASTNode.get<Stmt>(),
@@ -422,7 +422,7 @@ const SelectionTree::Node *computeExtractedExpr(const SelectionTree::Node *N) {
422422
llvm::isa<MemberExpr>(SelectedExpr))
423423
if (const SelectionTree::Node *Call = getCallExpr(N))
424424
TargetNode = Call;
425-
// Extracting Exprs like a = 1 gives dummy = a = 1 which isn't useful.
425+
// Extracting Exprs like a = 1 gives placeholder = a = 1 which isn't useful.
426426
if (const BinaryOperator *BinOpExpr =
427427
dyn_cast_or_null<BinaryOperator>(SelectedExpr)) {
428428
if (BinOpExpr->getOpcode() == BinaryOperatorKind::BO_Assign)
@@ -433,13 +433,13 @@ const SelectionTree::Node *computeExtractedExpr(const SelectionTree::Node *N) {
433433
return TargetNode;
434434
}
435435

436-
/// Extracts an expression to the variable dummy
436+
/// Extracts an expression to the variable placeholder
437437
/// Before:
438438
/// int x = 5 + 4 * 3;
439439
/// ^^^^^
440440
/// After:
441-
/// auto dummy = 5 + 4;
442-
/// int x = dummy * 3;
441+
/// auto placeholder = 5 + 4;
442+
/// int x = placeholder * 3;
443443
class ExtractVariable : public Tweak {
444444
public:
445445
const char *id() const override final;
@@ -476,7 +476,7 @@ bool ExtractVariable::prepare(const Selection &Inputs) {
476476
Expected<Tweak::Effect> ExtractVariable::apply(const Selection &Inputs) {
477477
tooling::Replacements Result;
478478
// FIXME: get variable name from user or suggest based on type
479-
std::string VarName = "dummy";
479+
std::string VarName = "placeholder";
480480
SourceRange Range = Target->getExtractionChars();
481481
// insert new variable declaration
482482
if (auto Err = Result.add(Target->insertDeclaration(VarName, Range)))

clang-tools-extra/clangd/support/Trace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ class JSONTracer : public EventTracer {
112112
"s",
113113
llvm::json::Object{{"id", FlowID},
114114
{"name", "Context crosses threads"},
115-
{"cat", "dummy"}},
115+
{"cat", "mock_cat"}},
116116
(*Parent)->TID, (*Parent)->StartTime);
117117
Tracer->jsonEvent(
118118
"f",
119119
llvm::json::Object{{"id", FlowID},
120120
{"bp", "e"},
121121
{"name", "Context crosses threads"},
122-
{"cat", "dummy"}},
122+
{"cat", "mock_cat"}},
123123
TID);
124124
}
125125
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ TEST(ClangdServerTest, SearchLibDir) {
407407

408408
// Put crtbegin.o into LibDir/64 to trick clang into thinking there's a gcc
409409
// installation there.
410-
SmallString<64> DummyLibFile;
411-
llvm::sys::path::append(DummyLibFile, LibDir, "64", "crtbegin.o");
412-
FS.Files[DummyLibFile] = "";
410+
SmallString<64> MockLibFile;
411+
llvm::sys::path::append(MockLibFile, LibDir, "64", "crtbegin.o");
412+
FS.Files[MockLibFile] = "";
413413

414414
SmallString<64> IncludeDir("/randomusr/include/c++");
415415
llvm::sys::path::append(IncludeDir, Version);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ MATCHER_P2(hasFlag, Flag, Path, "") {
463463
return true;
464464
}
465465

466-
auto hasFlag(llvm::StringRef Flag) { return hasFlag(Flag, "dummy.cc"); }
466+
auto hasFlag(llvm::StringRef Flag) {
467+
return hasFlag(Flag, "mock_file_name.cc");
468+
}
467469

468470
TEST_F(DirectoryBasedGlobalCompilationDatabaseCacheTest, Cacheable) {
469471
MockFS FS;
@@ -507,15 +509,15 @@ TEST_F(DirectoryBasedGlobalCompilationDatabaseCacheTest, Cacheable) {
507509
// compile_commands.json takes precedence over compile_flags.txt.
508510
FS.Files["foo/compile_commands.json"] =
509511
llvm::formatv(R"json([{
510-
"file": "{0}/foo/dummy.cc",
511-
"command": "clang -DBAZ dummy.cc",
512+
"file": "{0}/foo/mock_file.cc",
513+
"command": "clang -DBAZ mock_file.cc",
512514
"directory": "{0}/foo",
513515
}])json",
514516
llvm::sys::path::convert_to_slash(testRoot()));
515517
EXPECT_EQ(FooBar, lookupCDB(GDB, testPath("foo/test.cc"), Stale))
516518
<< "cache still valid";
517519
auto Baz = lookupCDB(GDB, testPath("foo/test.cc"), Fresh);
518-
EXPECT_THAT(Baz, hasFlag("-DBAZ", testPath("foo/dummy.cc")))
520+
EXPECT_THAT(Baz, hasFlag("-DBAZ", testPath("foo/mock_file.cc")))
519521
<< "compile_commands overrides compile_flags";
520522

521523
// Removing compile_commands.json reveals compile_flags.txt again.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ TEST(RenameTest, Renameable) {
844844
const char *Code;
845845
const char* ErrorMessage; // null if no error
846846
bool IsHeaderFile;
847-
llvm::StringRef NewName = "DummyName";
847+
llvm::StringRef NewName = "MockName";
848848
};
849849
const bool HeaderFile = true;
850850
Case Cases[] = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ MATCHER_P2(TUState, PreambleActivity, ASTActivity, "") {
7171
return true;
7272
}
7373

74-
// Dummy ContextProvider to verify the provider is invoked & contexts are used.
74+
// Simple ContextProvider to verify the provider is invoked & contexts are used.
7575
static Key<std::string> BoundPath;
7676
Context bindPath(PathRef F) {
7777
return Context::current().derive(BoundPath, F.str());

0 commit comments

Comments
 (0)