Skip to content

Commit

Permalink
clang-format: use SpacesBeforeTrailingComments=2 and AlignTrailingCom…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
ken-matsui committed Nov 16, 2024
1 parent 1dfe872 commit c3f7123
Show file tree
Hide file tree
Showing 49 changed files with 137 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ BasedOnStyle: LLVM
AlignAfterOpenBracket: BlockIndent
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortEnumsOnASingleLine: false
Expand All @@ -20,4 +19,5 @@ IndentPPDirectives: AfterHash
NamespaceIndentation: Inner
PointerAlignment: Left
QualifierAlignment: Left
SpacesBeforeTrailingComments: 2
UseTab: Never
14 changes: 7 additions & 7 deletions src/Algos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ replaceAll(
std::string str, const std::string_view from, const std::string_view to
) {
if (from.empty()) {
return str; // If the substring to replace is empty, return the original
// string
return str; // If the substring to replace is empty, return the original
// string
}

std::size_t startPos = 0;
while ((startPos = str.find(from, startPos)) != std::string::npos) {
str.replace(startPos, from.length(), to);
startPos += to.length(); // Move past the last replaced substring
startPos += to.length(); // Move past the last replaced substring
}
return str;
}
Expand Down Expand Up @@ -122,9 +122,9 @@ levDistance(const std::string_view lhs, const std::string_view rhs) {
for (size_t j = 1; j <= rhsSize; ++j) {
const size_t substCost = lhs[i - 1] == rhs[j - 1] ? 0 : 1;
dist[i][j] = std::min({
dist[i - 1][j] + 1, // deletion
dist[i][j - 1] + 1, // insertion
dist[i - 1][j - 1] + substCost // substitution
dist[i - 1][j] + 1, // deletion
dist[i][j - 1] + 1, // insertion
dist[i - 1][j - 1] + substCost // substitution
});
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ testFindSimilarStr2() {
pass();
}

} // namespace tests
} // namespace tests

int
main() {
Expand Down
34 changes: 17 additions & 17 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ getEnvFlags(const char* name) {
static void
emitDep(std::ostream& os, size_t& offset, const std::string_view dep) {
constexpr size_t maxLineLen = 80;
if (offset + dep.size() + 2 > maxLineLen) { // 2 for space and \.
if (offset + dep.size() + 2 > maxLineLen) { // 2 for space and \.
// \ for line continuation. \ is the 80th character.
os << std::setw(static_cast<int>(maxLineLen + 3 - offset)) << " \\\n ";
offset = 2;
}
os << ' ' << dep;
offset += dep.size() + 1; // space
offset += dep.size() + 1; // space
}

static void
Expand All @@ -181,7 +181,7 @@ emitTarget(
size_t offset = 0;

os << target << ':';
offset += target.size() + 2; // : and space
offset += target.size() + 2; // : and space

if (sourceFile.has_value()) {
emitDep(os, offset, sourceFile.value());
Expand All @@ -203,18 +203,18 @@ emitTarget(

void
BuildConfig::emitVariable(std::ostream& os, const std::string& varName) const {
std::ostringstream oss; // TODO: implement an elegant way to get type size.
std::ostringstream oss; // TODO: implement an elegant way to get type size.
oss << varName << ' ' << variables.at(varName).type;
const std::string left = oss.str();
os << left << ' ';

constexpr size_t maxLineLen = 80; // TODO: share across sources?
size_t offset = left.size() + 1; // space
constexpr size_t maxLineLen = 80; // TODO: share across sources?
size_t offset = left.size() + 1; // space
std::string value;
for (const char c : variables.at(varName).value) {
if (c == ' ') {
// Emit value
if (offset + value.size() + 2 > maxLineLen) { // 2 for space and '\'
if (offset + value.size() + 2 > maxLineLen) { // 2 for space and '\'
os << std::setw(static_cast<int>(maxLineLen + 3 - offset)) << "\\\n ";
offset = 2;
}
Expand All @@ -227,7 +227,7 @@ BuildConfig::emitVariable(std::ostream& os, const std::string& varName) const {
}

if (!value.empty()) {
if (offset + value.size() + 2 > maxLineLen) { // 2 for space and '\'
if (offset + value.size() + 2 > maxLineLen) { // 2 for space and '\'
os << std::setw(static_cast<int>(maxLineLen + 3 - offset)) << "\\\n ";
}
os << value;
Expand All @@ -247,7 +247,7 @@ topoSort(
}
for (const auto& edge : adjList) {
if (!list.contains(edge.first)) {
continue; // Ignore nodes not in list
continue; // Ignore nodes not in list
}
if (!inDegree.contains(edge.first)) {
inDegree[edge.first] = 0;
Expand Down Expand Up @@ -370,8 +370,8 @@ BuildConfig::emitCompdb(std::ostream& os) const {
std::string output = oss.str();
if (!output.empty()) {
// Remove the last comma.
output.pop_back(); // \n
output.pop_back(); // ,
output.pop_back(); // \n
output.pop_back(); // ,
}

os << "[\n";
Expand Down Expand Up @@ -519,7 +519,7 @@ mapHeaderToObj(const fs::path& headerPath, const fs::path& buildOutPath) {
// for each source file. So, we need objTargetDeps, which is the
// depending header files for the source file.
void
BuildConfig::collectBinDepObjs( // NOLINT(misc-no-recursion)
BuildConfig::collectBinDepObjs( // NOLINT(misc-no-recursion)
std::unordered_set<std::string>& deps,
const std::string_view sourceFileName,
const std::unordered_set<std::string>& objTargetDeps,
Expand Down Expand Up @@ -552,7 +552,7 @@ BuildConfig::collectBinDepObjs( // NOLINT(misc-no-recursion)
deps.insert(objTarget);
collectBinDepObjs(
deps, sourceFileName,
targets.at(objTarget).remDeps, // we don't need sourceFile
targets.at(objTarget).remDeps, // we don't need sourceFile
buildObjTargets
);
}
Expand Down Expand Up @@ -672,7 +672,7 @@ BuildConfig::processSrc(
const fs::path& sourceFilePath,
std::unordered_set<std::string>& buildObjTargets, tbb::spin_mutex* mtx
) {
std::string objTarget; // source.o
std::string objTarget; // source.o
const std::unordered_set<std::string> objTargetDeps =
parseMMOutput(runMM(sourceFilePath), objTarget);

Expand Down Expand Up @@ -728,7 +728,7 @@ BuildConfig::processUnittestSrc(
return;
}

std::string objTarget; // source.o
std::string objTarget; // source.o
const std::unordered_set<std::string> objTargetDeps =
parseMMOutput(runMM(sourceFilePath, /*isTest=*/true), objTarget);

Expand Down Expand Up @@ -847,7 +847,7 @@ BuildConfig::configureBuild() {
std::unordered_set<std::string> projTargetDeps = { mainObjTarget };
collectBinDepObjs(
projTargetDeps, "",
targets.at(mainObjTarget).remDeps, // we don't need sourceFile
targets.at(mainObjTarget).remDeps, // we don't need sourceFile
buildObjTargets
);

Expand Down Expand Up @@ -1112,7 +1112,7 @@ testParseEnvFlags() {
pass();
}

} // namespace tests
} // namespace tests

int
main() {
Expand Down
12 changes: 6 additions & 6 deletions src/BuildConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ inline const std::unordered_set<std::string> HEADER_FILE_EXTS{
// clang-format on

enum class VarType : uint8_t {
Recursive, // =
Simple, // :=
Cond, // ?=
Append, // +=
Shell, // !=
Recursive, // =
Simple, // :=
Cond, // ?=
Append, // +=
Shell, // !=
};

struct Variable {
Expand Down Expand Up @@ -146,7 +146,7 @@ struct BuildConfig {
const std::string& binTarget, const std::unordered_set<std::string>& deps
);

void collectBinDepObjs( // NOLINT(misc-no-recursion)
void collectBinDepObjs( // NOLINT(misc-no-recursion)
std::unordered_set<std::string>& deps, std::string_view sourceFileName,
const std::unordered_set<std::string>& objTargetDeps,
const std::unordered_set<std::string>& buildObjTargets
Expand Down
16 changes: 8 additions & 8 deletions src/Cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Opt::print(const size_t maxShortSize, size_t maxOffset) const noexcept {
} else {
// This coloring is for the alignment with std::setw later.
option += bold(cyan(std::string(maxShortSize, ' ')));
option += " "; // ", "
option += " "; // ", "
}
option += bold(cyan(name));
option += ' ';
Expand Down Expand Up @@ -390,7 +390,7 @@ Cli::transformOptions(
&& !args[argIdx + 1].starts_with("-")) {
// Handle space-separated value (like -j 1)
transformed.push_back(args[++argIdx]
); // Consume the next argument as the option's value
); // Consume the next argument as the option's value
}
}
handled = true;
Expand Down Expand Up @@ -439,10 +439,10 @@ Cli::calcMaxOffset(const size_t maxShortSize) const noexcept {
continue;
}

size_t offset = name.size(); // "build"
size_t offset = name.size(); // "build"
if (!cmd.shortName.empty()) {
offset += 2; // ", "
offset += cmd.shortName.size(); // "b"
offset += 2; // ", "
offset += cmd.shortName.size(); // "b"
}
maxOffset = std::max(maxOffset, offset);
}
Expand All @@ -457,10 +457,10 @@ Cli::printAllSubcmds(const bool showHidden, size_t maxOffset) const noexcept {
continue;
}

size_t offset = name.size(); // "build"
size_t offset = name.size(); // "build"
if (!cmd.shortName.empty()) {
offset += 2; // ", "
offset += cmd.shortName.size(); // "b"
offset += 2; // ", "
offset += cmd.shortName.size(); // "b"
}
maxOffset = std::max(maxOffset, offset);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Add.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ addMain(const std::span<const std::string_view> args) {
std::unordered_set<std::string_view> newDeps = {};

bool isSystemDependency = false;
std::string version; // Only used with system-dependencies
std::string version; // Only used with system-dependencies

std::string tag;
std::string rev;
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Clean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

static int cleanMain(std::span<const std::string_view> args) noexcept;

const Subcmd CLEAN_CMD = //
const Subcmd CLEAN_CMD = //
Subcmd{ "clean" }
.setDesc("Remove the built directory")
.addOpt(Opt{ "--profile" }
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Help.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

static int helpMain(std::span<const std::string_view> args) noexcept;

const Subcmd HELP_CMD = //
const Subcmd HELP_CMD = //
Subcmd{ "help" }
.setDesc("Displays help for a poac subcommand")
.setArg(Arg{ "COMMAND" }.setRequired(false))
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/New.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

static int newMain(std::span<const std::string_view> args);

const Subcmd NEW_CMD = //
const Subcmd NEW_CMD = //
Subcmd{ "new" }
.setDesc("Create a new poac project")
.addOpt(OPT_BIN)
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ searchPackages(const SearchArgs& args) {
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resStr);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, reqStr.c_str());
curl_easy_perform(curl); // TODO: Handle CURLCode
curl_easy_perform(curl); // TODO: Handle CURLCode

curl_easy_cleanup(curl);

Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

static int testMain(std::span<const std::string_view> args);

const Subcmd TEST_CMD = //
const Subcmd TEST_CMD = //
Subcmd{ "test" }
.setShort("t")
.setDesc("Run the tests of a local package")
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# error "POAC_POAC_COMMIT_DATE is not defined"
#endif

const Subcmd VERSION_CMD = //
const Subcmd VERSION_CMD = //
Subcmd{ "version" }
.setDesc("Show version information")
.setMainFn(versionMain);
Expand Down
8 changes: 4 additions & 4 deletions src/Command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Command::spawn() const {

// Redirect stdout
if (stdoutConfig == IOConfig::Piped) {
close(stdoutPipe[0]); // Child doesn't read from stdout pipe
close(stdoutPipe[0]); // Child doesn't read from stdout pipe
dup2(stdoutPipe[1], STDOUT_FILENO);
close(stdoutPipe[1]);
} else if (stdoutConfig == IOConfig::Null) {
Expand All @@ -164,7 +164,7 @@ Command::spawn() const {

// Redirect stderr
if (stderrConfig == IOConfig::Piped) {
close(stderrPipe[0]); // Child doesn't read from stderr pipe
close(stderrPipe[0]); // Child doesn't read from stderr pipe
dup2(stderrPipe[1], STDERR_FILENO);
close(stderrPipe[1]);
} else if (stderrConfig == IOConfig::Null) {
Expand Down Expand Up @@ -209,10 +209,10 @@ Command::spawn() const {

// Close unused pipe ends
if (stdoutConfig == IOConfig::Piped) {
close(stdoutPipe[1]); // Parent doesn't write to stdout pipe
close(stdoutPipe[1]); // Parent doesn't write to stdout pipe
}
if (stderrConfig == IOConfig::Piped) {
close(stderrPipe[1]); // Parent doesn't write to stderr pipe
close(stderrPipe[1]); // Parent doesn't write to stderr pipe
}

// Return the Child object with appropriate file descriptors
Expand Down
2 changes: 1 addition & 1 deletion src/CurlVersion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ operator<<(std::ostream& os, const Version& version) {
return os;
}

}; // namespace curl
}; // namespace curl
2 changes: 1 addition & 1 deletion src/CurlVersion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ struct Version {

std::ostream& operator<<(std::ostream& os, const Version& version);

}; // namespace curl
}; // namespace curl
2 changes: 1 addition & 1 deletion src/Exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

struct PoacError : public std::runtime_error {
explicit PoacError(Display auto&&... args)
: std::runtime_error( //
: std::runtime_error( //
(std::ostringstream{} << ... << std::forward<decltype(args)>(args))
.str()
) {}
Expand Down
2 changes: 1 addition & 1 deletion src/Git2/Commit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Commit::time() const {
return { git_commit_time(this->raw) };
}

} // namespace git2
} // namespace git2
2 changes: 1 addition & 1 deletion src/Git2/Commit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ struct Commit : public GlobalState {
Time time() const;
};

} // namespace git2
} // namespace git2
2 changes: 1 addition & 1 deletion src/Git2/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Config::getString(const std::string& name) {
return { ret.ptr, ret.size };
}

} // end namespace git2
} // end namespace git2
2 changes: 1 addition & 1 deletion src/Git2/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ struct Config : public GlobalState {
std::string getString(const std::string& name);
};

} // end namespace git2
} // end namespace git2
Loading

0 comments on commit c3f7123

Please sign in to comment.