forked from OSchip/llvm-project
[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
This commit is contained in:
parent
b3b002b12f
commit
f71404c37c
|
@ -497,7 +497,7 @@ void ClangdServer::prepareRename(PathRef File, Position Pos,
|
|||
// prepareRename is latency-sensitive: we don't query the index, as we
|
||||
// only need main-file references
|
||||
auto Results =
|
||||
clangd::rename({Pos, NewName.getValueOr("__clangd_rename_dummy"),
|
||||
clangd::rename({Pos, NewName.getValueOr("__clangd_rename_placeholder"),
|
||||
InpAST->AST, File, /*FS=*/nullptr,
|
||||
/*Index=*/nullptr, RenameOpts});
|
||||
if (!Results) {
|
||||
|
|
|
@ -96,9 +96,9 @@ std::string detectClangPath() {
|
|||
if (auto PathCC = llvm::sys::findProgramByName(Name))
|
||||
return resolve(std::move(*PathCC));
|
||||
// Fallback: a nonexistent 'clang' binary next to clangd.
|
||||
static int Dummy;
|
||||
static int StaticForMainAddr;
|
||||
std::string ClangdExecutable =
|
||||
llvm::sys::fs::getMainExecutable("clangd", (void *)&Dummy);
|
||||
llvm::sys::fs::getMainExecutable("clangd", (void *)&StaticForMainAddr);
|
||||
SmallString<128> ClangPath;
|
||||
ClangPath = llvm::sys::path::parent_path(ClangdExecutable);
|
||||
llvm::sys::path::append(ClangPath, "clang");
|
||||
|
@ -120,8 +120,9 @@ const llvm::Optional<std::string> detectSysroot() {
|
|||
}
|
||||
|
||||
std::string detectStandardResourceDir() {
|
||||
static int Dummy; // Just an address in this process.
|
||||
return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
|
||||
static int StaticForMainAddr; // Just an address in this process.
|
||||
return CompilerInvocation::GetResourcesPath("clangd",
|
||||
(void *)&StaticForMainAddr);
|
||||
}
|
||||
|
||||
// The path passed to argv[0] is important:
|
||||
|
|
|
@ -376,10 +376,10 @@ public:
|
|||
|
||||
/// Builds the document outline for the generated AST.
|
||||
std::vector<DocumentSymbol> build() {
|
||||
SymBuilder DummyRoot;
|
||||
SymBuilder Root;
|
||||
for (auto &TopLevel : AST.getLocalTopLevelDecls())
|
||||
traverseDecl(TopLevel, DummyRoot);
|
||||
return std::move(std::move(DummyRoot).build().children);
|
||||
traverseDecl(TopLevel, Root);
|
||||
return std::move(std::move(Root).build().children);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace {
|
|||
/// as it isn't sure where the errors are and so can't correct.
|
||||
/// When editing, it's reasonable to assume code before the cursor is complete.
|
||||
void closeBrackets(std::string &Code, const format::FormatStyle &Style) {
|
||||
SourceManagerForFile FileSM("dummy.cpp", Code);
|
||||
SourceManagerForFile FileSM("mock_file.cpp", Code);
|
||||
auto &SM = FileSM.get();
|
||||
FileID FID = SM.getMainFileID();
|
||||
Lexer Lex(FID, SM.getBufferOrFake(FID), SM,
|
||||
|
|
|
@ -294,7 +294,7 @@ public:
|
|||
HighlightingToken &addToken(SourceLocation Loc, HighlightingKind Kind) {
|
||||
Loc = getHighlightableSpellingToken(Loc, SourceMgr);
|
||||
if (Loc.isInvalid())
|
||||
return Dummy;
|
||||
return InvalidHighlightingToken;
|
||||
const auto *Tok = TB.spelledTokenAt(Loc);
|
||||
assert(Tok);
|
||||
return addToken(
|
||||
|
@ -395,7 +395,8 @@ private:
|
|||
const SourceManager &SourceMgr;
|
||||
const LangOptions &LangOpts;
|
||||
std::vector<HighlightingToken> Tokens;
|
||||
HighlightingToken Dummy; // returned from addToken(InvalidLoc)
|
||||
// returned from addToken(InvalidLoc)
|
||||
HighlightingToken InvalidHighlightingToken;
|
||||
};
|
||||
|
||||
llvm::Optional<HighlightingModifier> scopeModifier(const NamedDecl *D) {
|
||||
|
|
|
@ -599,7 +599,7 @@ lex(llvm::StringRef Code, const LangOptions &LangOpts,
|
|||
Action) {
|
||||
// FIXME: InMemoryFileAdapter crashes unless the buffer is null terminated!
|
||||
std::string NullTerminatedCode = Code.str();
|
||||
SourceManagerForFile FileSM("dummy.cpp", NullTerminatedCode);
|
||||
SourceManagerForFile FileSM("mock_file_name.cpp", NullTerminatedCode);
|
||||
auto &SM = FileSM.get();
|
||||
for (const auto &Tok : syntax::tokenize(SM.getMainFileID(), SM, LangOpts))
|
||||
Action(Tok, SM);
|
||||
|
|
|
@ -162,10 +162,10 @@ SymbolLocation toIndexLocation(const Location &Loc, std::string &URIStorage) {
|
|||
SymbolLocation getPreferredLocation(const Location &ASTLoc,
|
||||
const SymbolLocation &IdxLoc,
|
||||
std::string &Scratch) {
|
||||
// Also use a dummy symbol for the index location so that other fields (e.g.
|
||||
// Also use a mock symbol for the index location so that other fields (e.g.
|
||||
// definition) are not factored into the preference.
|
||||
Symbol ASTSym, IdxSym;
|
||||
ASTSym.ID = IdxSym.ID = SymbolID("dummy_id");
|
||||
ASTSym.ID = IdxSym.ID = SymbolID("mock_symbol_id");
|
||||
ASTSym.CanonicalDeclaration = toIndexLocation(ASTLoc, Scratch);
|
||||
IdxSym.CanonicalDeclaration = IdxLoc;
|
||||
auto Merged = mergeSymbol(ASTSym, IdxSym);
|
||||
|
|
|
@ -9,7 +9,7 @@ set(LLVM_LINK_COMPONENTS
|
|||
# This fuzzer runs on oss-fuzz, so keep it around even if it looks unreferenced.
|
||||
add_llvm_fuzzer(clangd-fuzzer
|
||||
clangd-fuzzer.cpp
|
||||
DUMMY_MAIN DummyClangdMain.cpp
|
||||
DUMMY_MAIN FuzzerClangdMain.cpp
|
||||
)
|
||||
|
||||
clang_target_link_libraries(clangd-fuzzer
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===---- DummyClangdMain.cpp - Entry point to sanity check the fuzzer ----===//
|
||||
//===--- FuzzerClangdMain.cpp - Entry point to sanity check the fuzzer ----===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
|
@ -39,6 +39,6 @@ if (CLANGD_ENABLE_REMOTE)
|
|||
add_subdirectory(marshalling)
|
||||
add_subdirectory(server)
|
||||
else()
|
||||
# Provides a dummy implementation of clangdRemoteIndex.
|
||||
# Provides a no-op implementation of clangdRemoteIndex.
|
||||
add_subdirectory(unimplemented)
|
||||
endif()
|
||||
|
|
|
@ -376,7 +376,7 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
|
|||
if (llvm::isa<DeclRefExpr>(E) || llvm::isa<MemberExpr>(E))
|
||||
return false;
|
||||
|
||||
// Extracting Exprs like a = 1 gives dummy = a = 1 which isn't useful.
|
||||
// Extracting Exprs like a = 1 gives placeholder = a = 1 which isn't useful.
|
||||
// FIXME: we could still hoist the assignment, and leave the variable there?
|
||||
ParsedBinaryOperator BinOp;
|
||||
if (BinOp.parse(*N) && BinaryOperator::isAssignmentOp(BinOp.Kind))
|
||||
|
@ -387,7 +387,7 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
|
|||
if (!Parent)
|
||||
return false;
|
||||
// We don't want to extract expressions used as statements, that would leave
|
||||
// a `dummy;` around that has no effect.
|
||||
// a `placeholder;` around that has no effect.
|
||||
// Unfortunately because the AST doesn't have ExprStmt, we have to check in
|
||||
// this roundabout way.
|
||||
if (childExprIsStmt(Parent->ASTNode.get<Stmt>(),
|
||||
|
@ -422,7 +422,7 @@ const SelectionTree::Node *computeExtractedExpr(const SelectionTree::Node *N) {
|
|||
llvm::isa<MemberExpr>(SelectedExpr))
|
||||
if (const SelectionTree::Node *Call = getCallExpr(N))
|
||||
TargetNode = Call;
|
||||
// Extracting Exprs like a = 1 gives dummy = a = 1 which isn't useful.
|
||||
// Extracting Exprs like a = 1 gives placeholder = a = 1 which isn't useful.
|
||||
if (const BinaryOperator *BinOpExpr =
|
||||
dyn_cast_or_null<BinaryOperator>(SelectedExpr)) {
|
||||
if (BinOpExpr->getOpcode() == BinaryOperatorKind::BO_Assign)
|
||||
|
@ -433,13 +433,13 @@ const SelectionTree::Node *computeExtractedExpr(const SelectionTree::Node *N) {
|
|||
return TargetNode;
|
||||
}
|
||||
|
||||
/// Extracts an expression to the variable dummy
|
||||
/// Extracts an expression to the variable placeholder
|
||||
/// Before:
|
||||
/// int x = 5 + 4 * 3;
|
||||
/// ^^^^^
|
||||
/// After:
|
||||
/// auto dummy = 5 + 4;
|
||||
/// int x = dummy * 3;
|
||||
/// auto placeholder = 5 + 4;
|
||||
/// int x = placeholder * 3;
|
||||
class ExtractVariable : public Tweak {
|
||||
public:
|
||||
const char *id() const override final;
|
||||
|
@ -476,7 +476,7 @@ bool ExtractVariable::prepare(const Selection &Inputs) {
|
|||
Expected<Tweak::Effect> ExtractVariable::apply(const Selection &Inputs) {
|
||||
tooling::Replacements Result;
|
||||
// FIXME: get variable name from user or suggest based on type
|
||||
std::string VarName = "dummy";
|
||||
std::string VarName = "placeholder";
|
||||
SourceRange Range = Target->getExtractionChars();
|
||||
// insert new variable declaration
|
||||
if (auto Err = Result.add(Target->insertDeclaration(VarName, Range)))
|
||||
|
|
|
@ -112,14 +112,14 @@ private:
|
|||
"s",
|
||||
llvm::json::Object{{"id", FlowID},
|
||||
{"name", "Context crosses threads"},
|
||||
{"cat", "dummy"}},
|
||||
{"cat", "mock_cat"}},
|
||||
(*Parent)->TID, (*Parent)->StartTime);
|
||||
Tracer->jsonEvent(
|
||||
"f",
|
||||
llvm::json::Object{{"id", FlowID},
|
||||
{"bp", "e"},
|
||||
{"name", "Context crosses threads"},
|
||||
{"cat", "dummy"}},
|
||||
{"cat", "mock_cat"}},
|
||||
TID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -407,9 +407,9 @@ TEST(ClangdServerTest, SearchLibDir) {
|
|||
|
||||
// Put crtbegin.o into LibDir/64 to trick clang into thinking there's a gcc
|
||||
// installation there.
|
||||
SmallString<64> DummyLibFile;
|
||||
llvm::sys::path::append(DummyLibFile, LibDir, "64", "crtbegin.o");
|
||||
FS.Files[DummyLibFile] = "";
|
||||
SmallString<64> MockLibFile;
|
||||
llvm::sys::path::append(MockLibFile, LibDir, "64", "crtbegin.o");
|
||||
FS.Files[MockLibFile] = "";
|
||||
|
||||
SmallString<64> IncludeDir("/randomusr/include/c++");
|
||||
llvm::sys::path::append(IncludeDir, Version);
|
||||
|
|
|
@ -463,7 +463,9 @@ MATCHER_P2(hasFlag, Flag, Path, "") {
|
|||
return true;
|
||||
}
|
||||
|
||||
auto hasFlag(llvm::StringRef Flag) { return hasFlag(Flag, "dummy.cc"); }
|
||||
auto hasFlag(llvm::StringRef Flag) {
|
||||
return hasFlag(Flag, "mock_file_name.cc");
|
||||
}
|
||||
|
||||
TEST_F(DirectoryBasedGlobalCompilationDatabaseCacheTest, Cacheable) {
|
||||
MockFS FS;
|
||||
|
@ -507,15 +509,15 @@ TEST_F(DirectoryBasedGlobalCompilationDatabaseCacheTest, Cacheable) {
|
|||
// compile_commands.json takes precedence over compile_flags.txt.
|
||||
FS.Files["foo/compile_commands.json"] =
|
||||
llvm::formatv(R"json([{
|
||||
"file": "{0}/foo/dummy.cc",
|
||||
"command": "clang -DBAZ dummy.cc",
|
||||
"file": "{0}/foo/mock_file.cc",
|
||||
"command": "clang -DBAZ mock_file.cc",
|
||||
"directory": "{0}/foo",
|
||||
}])json",
|
||||
llvm::sys::path::convert_to_slash(testRoot()));
|
||||
EXPECT_EQ(FooBar, lookupCDB(GDB, testPath("foo/test.cc"), Stale))
|
||||
<< "cache still valid";
|
||||
auto Baz = lookupCDB(GDB, testPath("foo/test.cc"), Fresh);
|
||||
EXPECT_THAT(Baz, hasFlag("-DBAZ", testPath("foo/dummy.cc")))
|
||||
EXPECT_THAT(Baz, hasFlag("-DBAZ", testPath("foo/mock_file.cc")))
|
||||
<< "compile_commands overrides compile_flags";
|
||||
|
||||
// Removing compile_commands.json reveals compile_flags.txt again.
|
||||
|
|
|
@ -844,7 +844,7 @@ TEST(RenameTest, Renameable) {
|
|||
const char *Code;
|
||||
const char* ErrorMessage; // null if no error
|
||||
bool IsHeaderFile;
|
||||
llvm::StringRef NewName = "DummyName";
|
||||
llvm::StringRef NewName = "MockName";
|
||||
};
|
||||
const bool HeaderFile = true;
|
||||
Case Cases[] = {
|
||||
|
|
|
@ -71,7 +71,7 @@ MATCHER_P2(TUState, PreambleActivity, ASTActivity, "") {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Dummy ContextProvider to verify the provider is invoked & contexts are used.
|
||||
// Simple ContextProvider to verify the provider is invoked & contexts are used.
|
||||
static Key<std::string> BoundPath;
|
||||
Context bindPath(PathRef F) {
|
||||
return Context::current().derive(BoundPath, F.str());
|
||||
|
|
|
@ -131,7 +131,7 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
int a = 5 * (4 + (3 [[- 1)]]);
|
||||
})cpp",
|
||||
R"cpp(void varDecl() {
|
||||
auto dummy = (3 - 1); int a = 5 * (4 + dummy);
|
||||
auto placeholder = (3 - 1); int a = 5 * (4 + placeholder);
|
||||
})cpp"},
|
||||
// FIXME: extraction from switch case
|
||||
/*{R"cpp(void f(int a) {
|
||||
|
@ -146,11 +146,11 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
}
|
||||
})cpp",
|
||||
R"cpp(void f(int a) {
|
||||
auto dummy = 1 + 2; if(1)
|
||||
auto placeholder = 1 + 2; if(1)
|
||||
while(a < 1)
|
||||
switch (1) {
|
||||
case 1:
|
||||
a = dummy;
|
||||
a = placeholder;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -164,11 +164,11 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
/*FIXME: It should be extracted like this.
|
||||
R"cpp(#define PLUS(x) x++
|
||||
void f(int a) {
|
||||
auto dummy = 1+a; int y = PLUS(dummy);
|
||||
auto placeholder = 1+a; int y = PLUS(placeholder);
|
||||
})cpp"},*/
|
||||
R"cpp(#define PLUS(x) x++
|
||||
void f(int a) {
|
||||
auto dummy = PLUS(1+a); int y = dummy;
|
||||
auto placeholder = PLUS(1+a); int y = placeholder;
|
||||
})cpp"},
|
||||
// ensure InsertionPoint isn't inside a macro
|
||||
{R"cpp(#define LOOP(x) while (1) {a = x;}
|
||||
|
@ -178,8 +178,8 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
})cpp",
|
||||
R"cpp(#define LOOP(x) while (1) {a = x;}
|
||||
void f(int a) {
|
||||
auto dummy = 3; if(1)
|
||||
LOOP(5 + dummy)
|
||||
auto placeholder = 3; if(1)
|
||||
LOOP(5 + placeholder)
|
||||
})cpp"},
|
||||
{R"cpp(#define LOOP(x) do {x;} while(1);
|
||||
void f(int a) {
|
||||
|
@ -188,15 +188,15 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
})cpp",
|
||||
R"cpp(#define LOOP(x) do {x;} while(1);
|
||||
void f(int a) {
|
||||
auto dummy = 3; if(1)
|
||||
LOOP(5 + dummy)
|
||||
auto placeholder = 3; if(1)
|
||||
LOOP(5 + placeholder)
|
||||
})cpp"},
|
||||
// attribute testing
|
||||
{R"cpp(void f(int a) {
|
||||
[ [gsl::suppress("type")] ] for (;;) a = [[1]] + 1;
|
||||
})cpp",
|
||||
R"cpp(void f(int a) {
|
||||
auto dummy = 1; [ [gsl::suppress("type")] ] for (;;) a = dummy + 1;
|
||||
auto placeholder = 1; [ [gsl::suppress("type")] ] for (;;) a = placeholder + 1;
|
||||
})cpp"},
|
||||
// MemberExpr
|
||||
{R"cpp(class T {
|
||||
|
@ -206,7 +206,7 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
};)cpp",
|
||||
R"cpp(class T {
|
||||
T f() {
|
||||
auto dummy = T().f(); return dummy.f();
|
||||
auto placeholder = T().f(); return placeholder.f();
|
||||
}
|
||||
};)cpp"},
|
||||
// Function DeclRefExpr
|
||||
|
@ -214,7 +214,7 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
return [[f]]();
|
||||
})cpp",
|
||||
R"cpp(int f() {
|
||||
auto dummy = f(); return dummy;
|
||||
auto placeholder = f(); return placeholder;
|
||||
})cpp"},
|
||||
// FIXME: Wrong result for \[\[clang::uninitialized\]\] int b = [[1]];
|
||||
// since the attr is inside the DeclStmt and the bounds of
|
||||
|
@ -225,33 +225,33 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
int x = 1 + [[2 + 3 + 4]] + 5;
|
||||
})cpp",
|
||||
R"cpp(void f() {
|
||||
auto dummy = 2 + 3 + 4; int x = 1 + dummy + 5;
|
||||
auto placeholder = 2 + 3 + 4; int x = 1 + placeholder + 5;
|
||||
})cpp"},
|
||||
{R"cpp(void f() {
|
||||
int x = [[1 + 2 + 3]] + 4 + 5;
|
||||
})cpp",
|
||||
R"cpp(void f() {
|
||||
auto dummy = 1 + 2 + 3; int x = dummy + 4 + 5;
|
||||
auto placeholder = 1 + 2 + 3; int x = placeholder + 4 + 5;
|
||||
})cpp"},
|
||||
{R"cpp(void f() {
|
||||
int x = 1 + 2 + [[3 + 4 + 5]];
|
||||
})cpp",
|
||||
R"cpp(void f() {
|
||||
auto dummy = 3 + 4 + 5; int x = 1 + 2 + dummy;
|
||||
auto placeholder = 3 + 4 + 5; int x = 1 + 2 + placeholder;
|
||||
})cpp"},
|
||||
// Non-associative operations have no special support
|
||||
{R"cpp(void f() {
|
||||
int x = 1 - [[2 - 3 - 4]] - 5;
|
||||
})cpp",
|
||||
R"cpp(void f() {
|
||||
auto dummy = 1 - 2 - 3 - 4; int x = dummy - 5;
|
||||
auto placeholder = 1 - 2 - 3 - 4; int x = placeholder - 5;
|
||||
})cpp"},
|
||||
// A mix of associative operators isn't associative.
|
||||
{R"cpp(void f() {
|
||||
int x = 0 + 1 * [[2 + 3]] * 4 + 5;
|
||||
})cpp",
|
||||
R"cpp(void f() {
|
||||
auto dummy = 1 * 2 + 3 * 4; int x = 0 + dummy + 5;
|
||||
auto placeholder = 1 * 2 + 3 * 4; int x = 0 + placeholder + 5;
|
||||
})cpp"},
|
||||
// Overloaded operators are supported, we assume associativity
|
||||
// as if they were built-in.
|
||||
|
@ -269,7 +269,7 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
S operator+(S, S);
|
||||
|
||||
void f() {
|
||||
auto dummy = S(2) + S(3) + S(4); S x = S(1) + dummy + S(5);
|
||||
auto placeholder = S(2) + S(3) + S(4); S x = S(1) + placeholder + S(5);
|
||||
})cpp"},
|
||||
// Don't try to analyze across macro boundaries
|
||||
// FIXME: it'd be nice to do this someday (in a safe way)
|
||||
|
@ -279,7 +279,7 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
})cpp",
|
||||
R"cpp(#define ECHO(X) X
|
||||
void f() {
|
||||
auto dummy = 1 + ECHO(2 + 3) + 4; int x = dummy + 5;
|
||||
auto placeholder = 1 + ECHO(2 + 3) + 4; int x = placeholder + 5;
|
||||
})cpp"},
|
||||
{R"cpp(#define ECHO(X) X
|
||||
void f() {
|
||||
|
@ -287,7 +287,7 @@ TEST_F(ExtractVariableTest, Test) {
|
|||
})cpp",
|
||||
R"cpp(#define ECHO(X) X
|
||||
void f() {
|
||||
auto dummy = 1 + ECHO(2) + ECHO(3) + 4; int x = dummy + 5;
|
||||
auto placeholder = 1 + ECHO(2) + ECHO(3) + 4; int x = placeholder + 5;
|
||||
})cpp"},
|
||||
};
|
||||
for (const auto &IO : InputOutputs) {
|
||||
|
|
Loading…
Reference in New Issue