Skip to content

Commit

Permalink
Merge pull request #4 from rhodiumdb/chessai/clang-format
Browse files Browse the repository at this point in the history
format with clang-format
  • Loading branch information
chessai authored Jun 23, 2021
2 parents e63a24b + c844ef8 commit ca4bf36
Show file tree
Hide file tree
Showing 35 changed files with 2,422 additions and 2,584 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IndentWidth: 4
4 changes: 2 additions & 2 deletions .nix/rdss.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, lib, cmake
{ stdenv, lib, cmake, clang-tools
, abseil-cpp, gtest, z3, highway, rapidcheck
}:

Expand All @@ -13,5 +13,5 @@ stdenv.mkDerivation {

buildInputs = [ abseil-cpp gtest highway rapidcheck z3 ];

nativeBuildInputs = [ cmake ];
nativeBuildInputs = [ cmake clang-tools ];
}
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ target_link_libraries(

include(GoogleTest)
gtest_discover_tests(fhd_tests)

file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.hpp)
add_custom_target(
clangformat
COMMAND clang-format -style=LLVM -i ${ALL_SOURCE_FILES}
)
71 changes: 34 additions & 37 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,48 @@

namespace rdss {

std::string Member::ToCpp(FreshVariableSource* source) const {
return absl::StrFormat("%s %s;\n", this->type->ToCpp(), this->name.ToCpp());
std::string Member::ToCpp(FreshVariableSource *source) const {
return absl::StrFormat("%s %s;\n", this->type->ToCpp(), this->name.ToCpp());
}

// <type> <name>(<arg1>, <arg2>, ..., <argN>)
std::string Method::ToCpp(FreshVariableSource* source) const {
std::vector<std::string> args_vec;
for (int32_t i = 0; i < this->arguments.size(); i++) {
args_vec.push_back(absl::StrCat(
this->arguments[i].second->ToCpp(),
" ",
this->arguments[i].first.ToCpp()));
}
std::string Method::ToCpp(FreshVariableSource *source) const {
std::vector<std::string> args_vec;
for (int32_t i = 0; i < this->arguments.size(); i++) {
args_vec.push_back(absl::StrCat(this->arguments[i].second->ToCpp(), " ",
this->arguments[i].first.ToCpp()));
}

auto args = absl::StrJoin(args_vec, ", ");
auto args = absl::StrJoin(args_vec, ", ");

std::string body;
for (int32_t i = 0; i < this->body.size(); i++) {
absl::StrAppend(&body, Indent(this->body[i]->ToCpp(source), 1), "\n");
}
std::string body;
for (int32_t i = 0; i < this->body.size(); i++) {
absl::StrAppend(&body, Indent(this->body[i]->ToCpp(source), 1), "\n");
}

return absl::StrFormat("void %s(%s) {\n%s}",
this->name.ToCpp(), args, body);
return absl::StrFormat("void %s(%s) {\n%s}", this->name.ToCpp(), args, body);
}

std::string DataStructure::ToCpp(FreshVariableSource* source) const {
std::stringstream ss;
if (!this->type_parameters.empty()) {
ss << "template<";
std::vector<std::string> params;
for (const auto& ty_param : this->type_parameters) {
params.push_back("typename " + ty_param.ToCpp());
}
ss << absl::StrJoin(params, ", ");
ss << ">\n";
}
ss << "struct " << this->name << " {\n";
for (const auto& member : this->members) {
ss << Indent(member.ToCpp(source), 1);
}
for (const auto& method : this->methods) {
ss << Indent(method.ToCpp(source), 1);
std::string DataStructure::ToCpp(FreshVariableSource *source) const {
std::stringstream ss;
if (!this->type_parameters.empty()) {
ss << "template<";
std::vector<std::string> params;
for (const auto &ty_param : this->type_parameters) {
params.push_back("typename " + ty_param.ToCpp());
}
ss << "}\n";
return ss.str();
ss << absl::StrJoin(params, ", ");
ss << ">\n";
}
ss << "struct " << this->name << " {\n";
for (const auto &member : this->members) {
ss << Indent(member.ToCpp(source), 1);
}
for (const auto &method : this->methods) {
ss << Indent(method.ToCpp(source), 1);
}
ss << "}\n";
return ss.str();
}

} // namespace rdss
} // namespace rdss
Loading

0 comments on commit ca4bf36

Please sign in to comment.