Skip to content

Commit 4880857

Browse files
committed
Reformat C++ code
1 parent 11e5a76 commit 4880857

32 files changed

+413
-426
lines changed

CycleDetection.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,46 @@
22

33
#include "TypeTranslator.h"
44

5-
#include <string>
65
#include <map>
76
#include <set>
7+
#include <string>
88

99
class CycleDetection {
10-
private:
11-
TypeTranslator& tpeTransl;
10+
private:
11+
TypeTranslator &tpeTransl;
1212

13-
bool contains(std::string& k){
14-
return !!dependencies.count(k);
15-
}
13+
bool contains(std::string &k) { return !!dependencies.count(k); }
1614

17-
public:
18-
std::map<std::string, std::set<std::string> > dependencies;
19-
CycleDetection(TypeTranslator& tpeTransl_) : tpeTransl(tpeTransl_), dependencies{} {}
15+
public:
16+
std::map<std::string, std::set<std::string>> dependencies;
17+
CycleDetection(TypeTranslator &tpeTransl_)
18+
: tpeTransl(tpeTransl_), dependencies{} {}
2019

20+
void AddDependcy(std::string name, const clang::QualType &qtpe) {
2121

22-
void AddDependcy(std::string name, const clang::QualType& qtpe){
22+
// TODO: function pointer
2323

24-
//TODO: function pointer
25-
26-
if(qtpe->isPointerType()){
27-
const clang::PointerType* ptr = qtpe.getTypePtr()->getAs<clang::PointerType>();
24+
if (qtpe->isPointerType()) {
25+
const clang::PointerType *ptr =
26+
qtpe.getTypePtr()->getAs<clang::PointerType>();
2827
AddDependcy(name, ptr->getPointeeType());
2928
return;
3029
}
3130

3231
std::string qtpeString = tpeTransl.Translate(qtpe);
3332

34-
//Add the dependence of qtpe
35-
if(contains(qtpeString)){
36-
dependencies[name].insert(dependencies[qtpeString].begin(), dependencies[qtpeString].end());
33+
// Add the dependence of qtpe
34+
if (contains(qtpeString)) {
35+
dependencies[name].insert(dependencies[qtpeString].begin(),
36+
dependencies[qtpeString].end());
3737
}
3838

3939
dependencies[name].insert(qtpeString);
4040
}
4141

42-
43-
bool isCyclic(std::string& name){
44-
if(contains(name)){
45-
if(dependencies[name].count(name) != 0){
42+
bool isCyclic(std::string &name) {
43+
if (contains(name)) {
44+
if (dependencies[name].count(name) != 0) {
4645
return true;
4746
}
4847
}

HeaderManager.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,30 @@
33

44
#include <clang/Tooling/Tooling.h>
55

6-
#include <iostream>
76
#include <fstream>
7+
#include <iostream>
88

9-
HeaderManager::HeaderManager(): headers() {
10-
11-
}
9+
HeaderManager::HeaderManager() : headers() {}
1210

13-
void HeaderManager::LoadConfig(std::string path){
11+
void HeaderManager::LoadConfig(std::string path) {
1412
trim(path);
1513
std::ifstream input(path);
1614

17-
for(std::string line; getline( input, line );){
15+
for (std::string line; getline(input, line);) {
1816
size_t f = line.find("=");
19-
if(f != line.npos){
17+
if (f != line.npos) {
2018
std::string header = line.substr(0, f);
21-
std::string import = line.substr(f+1, line.npos);
19+
std::string import = line.substr(f + 1, line.npos);
2220
headers[header] = import;
2321
}
2422
}
25-
2623
}
2724

28-
bool HeaderManager::IsStandard(std::string path){
25+
bool HeaderManager::IsStandard(std::string path) {
2926
trim(path);
3027
return !!headers.count(path);
3128
}
3229

33-
34-
std::string* HeaderManager::GetImport(const std::string& include){
30+
std::string *HeaderManager::GetImport(const std::string &include) {
3531
return nullptr;
3632
}

HeaderManager.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#pragma once
22

3-
#include <string>
43
#include <map>
4+
#include <string>
55

66
class HeaderManager {
7-
private:
7+
private:
88
std::map<std::string, std::string> headers;
99

10-
public:
10+
public:
1111
HeaderManager();
1212
void LoadConfig(std::string path);
1313
bool IsStandard(std::string path);
14-
std::string* GetImport(const std::string& include);
15-
14+
std::string *GetImport(const std::string &include);
1615
};

Main.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
#include "visitor/ScalaFrontendActionFactory.h"
22
#include <clang/Tooling/CommonOptionsParser.h>
33

4-
54
int main(int argc, char *argv[]) {
65
llvm::cl::OptionCategory Category("Binding Generator");
7-
llvm::cl::extrahelp CommonHelp(clang::tooling::CommonOptionsParser::HelpMessage);
8-
llvm::cl::extrahelp MoreHelp("\nProduce Bindings for scala native. Please specify lib name with parameter name\n");
6+
llvm::cl::extrahelp CommonHelp(
7+
clang::tooling::CommonOptionsParser::HelpMessage);
8+
llvm::cl::extrahelp MoreHelp("\nProduce Bindings for scala native. Please "
9+
"specify lib name with parameter name\n");
910

1011
llvm::cl::opt<std::string> LibName("name", llvm::cl::cat(Category));
11-
llvm::cl::opt<std::string> StdHeaders("std-headers", llvm::cl::cat(Category));
12-
llvm::cl::opt<bool> PrintHeadersLocation("location", llvm::cl::cat(Category));
13-
llvm::cl::opt<std::string> ExcludePrefix("exclude-prefix", llvm::cl::cat(Category));
14-
15-
clang::tooling::CommonOptionsParser op(argc, (const char**)argv, Category);
16-
clang::tooling::ClangTool Tool(op.getCompilations(), op.getSourcePathList());
12+
llvm::cl::opt<std::string> StdHeaders("std-headers",
13+
llvm::cl::cat(Category));
14+
llvm::cl::opt<bool> PrintHeadersLocation("location",
15+
llvm::cl::cat(Category));
16+
llvm::cl::opt<std::string> ExcludePrefix("exclude-prefix",
17+
llvm::cl::cat(Category));
18+
19+
clang::tooling::CommonOptionsParser op(argc, (const char **)argv, Category);
20+
clang::tooling::ClangTool Tool(op.getCompilations(),
21+
op.getSourcePathList());
1722

1823
auto libName = LibName.getValue();
19-
if(libName.empty()){
20-
llvm::errs() << "Error: Please specify the lib name using -name parameter\n";
24+
if (libName.empty()) {
25+
llvm::errs()
26+
<< "Error: Please specify the lib name using -name parameter\n";
2127
llvm::errs().flush();
2228
return -1;
2329
}
2430

2531
auto stdhead = StdHeaders.getValue();
26-
if(!stdhead.empty()){
32+
if (!stdhead.empty()) {
2733
headerMan.LoadConfig(stdhead);
2834
}
2935

@@ -37,7 +43,7 @@ int main(int argc, char *argv[]) {
3743

3844
auto printLoc = PrintHeadersLocation.getValue();
3945
if (printLoc) {
40-
for (const auto &location: locations) {
46+
for (const auto &location : locations) {
4147
llvm::outs() << location.c_str();
4248
}
4349
} else {

0 commit comments

Comments
 (0)