Skip to content

Commit

Permalink
fix clang-tidy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
sekiguchi-nagisa committed Dec 7, 2023
1 parent 72f910a commit f118bc6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/cmd_shctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int printBacktrace(const DSState &state, const ArrayObject &argvObj) {
}

static int printFuncName(const DSState &state, const ArrayObject &argvObj) {
auto *code = state.getCallStack().getFrame().code;
const auto *code = state.getCallStack().getFrame().code;
const char *name = nullptr;
if (!code->is(CodeKind::NATIVE) && !code->is(CodeKind::TOPLEVEL)) {
name = cast<CompiledCode>(code)->getName();
Expand Down
13 changes: 7 additions & 6 deletions tools/analyzer/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ void SymbolIndexes::remove(ModId id) {
bool findDeclaration(const SymbolIndexes &indexes, SymbolRequest request,
const std::function<void(const FindDeclResult &)> &consumer) {
if (auto index = indexes.find(request.modId)) {
if (auto *symbol = index->findSymbol(request.pos)) {
auto *decl = indexes.findDecl({.modId = symbol->getDeclModId(), .pos = symbol->getDeclPos()});
if (const auto *symbol = index->findSymbol(request.pos)) {
const auto *decl =
indexes.findDecl({.modId = symbol->getDeclModId(), .pos = symbol->getDeclPos()});
if (!decl) {
return false;
}
Expand Down Expand Up @@ -284,7 +285,7 @@ unsigned int findAllReferences(const SymbolIndexes &indexes, const DeclSymbol &d
}

// search local ref
for (auto &e : decl.getRefs()) {
for (const auto &e : decl.getRefs()) {
count++;
if (consumer) {
FindRefsResult ret = {
Expand All @@ -300,12 +301,12 @@ unsigned int findAllReferences(const SymbolIndexes &indexes, const DeclSymbol &d
.modId = decl.getModId(),
.pos = decl.getPos(),
};
for (auto &index : indexes) {
for (const auto &index : indexes) {
if (index->getModId() == request.modId) {
continue;
}
if (auto *foreign = index->findForeignDecl(request)) {
for (auto &e : foreign->getRefs()) {
if (const auto *foreign = index->findForeignDecl(request)) {
for (const auto &e : foreign->getRefs()) {
count++;
if (consumer) {
FindRefsResult ret = {
Expand Down
37 changes: 18 additions & 19 deletions tools/analyzer/rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ namespace ydsh::lsp {

static std::unordered_set<StringRef, StrRefHash> initStatementKeywordSet() {
std::unordered_set<StringRef, StrRefHash> set;
TokenKind table[] = {
constexpr TokenKind table[] = {
#define GEN_ITEM(T) TokenKind::T,
EACH_LA_statement(GEN_ITEM)
#undef GEN_ITEM
};
for (auto &e : table) {
for (const auto &e : table) {
StringRef keyword = toString(e);
if (isValidIdentifier(keyword)) {
set.emplace(keyword);
Expand Down Expand Up @@ -63,17 +63,16 @@ static void
resolveInlinedImportedIndexes(const SymbolIndexes &indexes, const SymbolIndexPtr &thisIndex,
const SymbolRef ref, std::unordered_set<ModId> &foundModSet,
std::vector<std::pair<SymbolRef, SymbolIndexPtr>> &results) {
for (auto &pair : thisIndex->getLinks()) {
for (const auto &pair : thisIndex->getLinks()) {
const auto attr = pair.second.getImportAttr();
if (!hasFlag(attr, IndexLink::ImportAttr::INLINED)) {
continue;
}
const auto modId = pair.second.getModId();
if (foundModSet.find(modId) != foundModSet.end()) { // already found
continue;
} else {
foundModSet.emplace(modId);
}
foundModSet.emplace(modId);
auto index = indexes.find(modId);
results.emplace_back(ref, index);
resolveInlinedImportedIndexes(indexes, index, ref, foundModSet, results);
Expand All @@ -84,7 +83,7 @@ static std::vector<std::pair<SymbolRef, SymbolIndexPtr>>
resolveGlobalImportedIndexes(const SymbolIndexes &indexes, const SymbolIndexPtr &thisIndex) {
std::vector<std::pair<SymbolRef, SymbolIndexPtr>> results;
results.emplace_back(SymbolRef(0, 0, BUILTIN_MOD_ID), indexes.find(BUILTIN_MOD_ID));
for (auto &pair : thisIndex->getLinks()) {
for (const auto &pair : thisIndex->getLinks()) {
const auto attr = pair.second.getImportAttr();
if (!hasFlag(attr, IndexLink::ImportAttr::GLOBAL)) {
continue;
Expand All @@ -99,7 +98,7 @@ resolveGlobalImportedIndexes(const SymbolIndexes &indexes, const SymbolIndexPtr

static bool isInlinedImportingIndex(const SymbolIndexes &indexes, const ModId targetModId,
const SymbolIndexPtr &index) {
for (auto &e : index->getLinks()) {
for (const auto &e : index->getLinks()) {
if (!hasFlag(e.second.getImportAttr(), IndexLink::ImportAttr::INLINED)) {
continue;
}
Expand Down Expand Up @@ -151,7 +150,7 @@ static bool equalsName(const DeclSymbol &decl, const std::string &mangledNewDecl
static bool checkMangledNames(const DeclSymbol &decl, const DeclSymbol &target,
const std::vector<std::string> &mangledNewNames,
const std::function<void(const RenameResult &)> &consumer) {
for (auto &mangledNewName : mangledNewNames) {
for (const auto &mangledNewName : mangledNewNames) {
if (equalsName(decl, mangledNewName, target)) {
if (consumer) {
consumer(Err(RenameConflict(target.toRef())));
Expand Down Expand Up @@ -241,8 +240,8 @@ static bool checkNameConflict(const SymbolIndexes &indexes, const DeclSymbol &de
auto importedIndexes = resolveGlobalImportedIndexes(indexes, declIndex);
for (auto &[ref, importedIndex] : importedIndexes) {
if (!isBuiltinMod(importedIndex->getModId())) {
auto &declScope = declIndex->getScopes()[decl.getScopeId()];
auto &targetScope = declIndex->getScopes()[0]; // always global scope
const auto &declScope = declIndex->getScopes()[decl.getScopeId()];
const auto &targetScope = declIndex->getScopes()[0]; // always global scope
if (!mayBeConflict(declScope, decl.toRef(), targetScope, ref)) {
continue;
}
Expand All @@ -269,9 +268,9 @@ static bool checkNameConflict(const SymbolIndexes &indexes, const DeclSymbol &de
return false;
}
}
for (auto &target : declIndex->getDecls()) { // FIXME: check constructor field
auto &declScope = declIndex->getScopes()[decl.getScopeId()];
auto &targetScope = declIndex->getScopes()[target.getScopeId()];
for (const auto &target : declIndex->getDecls()) { // FIXME: check constructor field
const auto &declScope = declIndex->getScopes()[decl.getScopeId()];
const auto &targetScope = declIndex->getScopes()[target.getScopeId()];
if (!mayBeConflict(declScope, decl.toRef(), targetScope, target.toRef())) {
continue;
}
Expand All @@ -284,17 +283,17 @@ static bool checkNameConflict(const SymbolIndexes &indexes, const DeclSymbol &de
if (!hasFlag(decl.getAttr(), DeclSymbol::Attr::GLOBAL)) {
return true;
}
for (auto &index : indexes) {
for (const auto &index : indexes) {
if (index->getModId() == decl.getModId()) {
continue; // ignore this index
}
for (auto &e : index->getLinks()) {
for (const auto &e : index->getLinks()) {
if (!isImportingIndex(indexes, decl.getModId(), e.second)) {
continue;
}
for (auto &target : index->getDecls()) {
auto &declScope = index->getScopes()[0]; // always global scope
auto &targetScope = index->getScopes()[target.getScopeId()];
for (const auto &target : index->getDecls()) {
const auto &declScope = index->getScopes()[0]; // always global scope
const auto &targetScope = index->getScopes()[target.getScopeId()];
if (!mayBeConflict(declScope, e.first, targetScope, target.toRef())) {
continue;
}
Expand Down Expand Up @@ -364,7 +363,7 @@ Optional<FindDeclResult> resolveRenameLocation(const SymbolIndexes &indexes,
decl = &r.decl;
symbol = &r.request;
});
if (!decl || decl->getKind() == DeclSymbol::Kind::HERE_START) {
if ((decl == nullptr) || decl->getKind() == DeclSymbol::Kind::HERE_START) {
return {};
}
return FindDeclResult{
Expand Down

0 comments on commit f118bc6

Please sign in to comment.