Skip to content

Commit 9b312b7

Browse files
committed
Use formatter
1 parent ac06077 commit 9b312b7

16 files changed

+443
-350
lines changed

.clang-format

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ColumnLimit: 80
2+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
3+
ConstructorInitializerIndentWidth: 2
4+
ContinuationIndentWidth: 1
5+
IndentWidth: 2
6+
NamespaceIndentation: Inner
7+
TabWidth: 2
8+
BreakConstructorInitializers: BeforeComma

CMakeLists.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.5.1)
2-
project(clangql VERSION 0.1.0
2+
project(clangql VERSION 0.2.0
33
DESCRIPTION "ClangQL"
44
LANGUAGES C CXX)
55

@@ -11,13 +11,15 @@ add_library(clangql
1111
SHARED
1212
src/clangql.cc
1313
src/ClangQLModule.cc
14-
src/Index.grpc.pb.cc
15-
src/Index.pb.cc
16-
src/Service.grpc.pb.cc
17-
src/Service.pb.cc
14+
src/Module.cc
1815
src/RefsTable.cc
1916
src/RelationsTable.cc
2017
src/SymbolsTable.cc
21-
src/Module.cc)
18+
19+
# Autogenerated files
20+
src/Index.grpc.pb.cc
21+
src/Index.pb.cc
22+
src/Service.grpc.pb.cc
23+
src/Service.pb.cc)
2224

2325
target_link_libraries(clangql PRIVATE protobuf::libprotobuf gRPC::grpc++)

src/ClangQLModule.cc

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
#include "ClangQLModule.hpp"
22
SQLITE_EXTENSION_INIT3
3-
#include "SymbolsTable.hpp"
4-
#include "RelationsTable.hpp"
53
#include "RefsTable.hpp"
4+
#include "RelationsTable.hpp"
5+
#include "SymbolsTable.hpp"
66
#include <grpcpp/grpcpp.h>
77

88
#include <string>
99

1010
using namespace clang::clangd::remote;
1111
using clang::clangd::remote::v1::SymbolIndex;
1212

13-
static std::unique_ptr<VirtualTable> InitTable(sqlite3* db, int argc, const char *const*argv) {
13+
static std::unique_ptr<VirtualTable> InitTable(sqlite3 *db, int argc,
14+
const char *const *argv) {
1415
auto table_type = std::string{argv[3]};
1516
auto server_addr = std::string{argv[4]};
1617

17-
auto channel = grpc::CreateChannel(server_addr, grpc::InsecureChannelCredentials());
18-
if(table_type == "symbols") {
18+
auto channel =
19+
grpc::CreateChannel(server_addr, grpc::InsecureChannelCredentials());
20+
if (table_type == "symbols") {
1921
return std::make_unique<SymbolsTable>(db, SymbolIndex::NewStub(channel));
20-
} else if(table_type == "base_of") {
21-
return std::make_unique<RelationsTable>(db, SymbolIndex::NewStub(channel), BaseOf);
22-
} else if(table_type == "overridden_by") {
23-
return std::make_unique<RelationsTable>(db, SymbolIndex::NewStub(channel), OverriddenBy);
24-
} else if(table_type == "refs") {
22+
} else if (table_type == "base_of") {
23+
return std::make_unique<RelationsTable>(db, SymbolIndex::NewStub(channel),
24+
BaseOf);
25+
} else if (table_type == "overridden_by") {
26+
return std::make_unique<RelationsTable>(db, SymbolIndex::NewStub(channel),
27+
OverriddenBy);
28+
} else if (table_type == "refs") {
2529
return std::make_unique<RefsTable>(db, SymbolIndex::NewStub(channel));
2630
} else {
2731
return nullptr;
2832
}
2933
}
3034

31-
std::unique_ptr<VirtualTable> ClangQLModule::Create(sqlite3* db, int argc, const char *const*argv) {
35+
std::unique_ptr<VirtualTable> ClangQLModule::Create(sqlite3 *db, int argc,
36+
const char *const *argv) {
3237
return InitTable(db, argc, argv);
3338
}
3439

35-
std::unique_ptr<VirtualTable> ClangQLModule::Connect(sqlite3* db, int argc, const char *const*argv) {
40+
std::unique_ptr<VirtualTable> ClangQLModule::Connect(sqlite3 *db, int argc,
41+
const char *const *argv) {
3642
return InitTable(db, argc, argv);
3743
}

src/ClangQLModule.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
class ClangQLModule : public Module {
66
public:
7-
virtual std::unique_ptr<VirtualTable> Create(sqlite3* db, int argc, const char *const*argv) override;
8-
virtual std::unique_ptr<VirtualTable> Connect(sqlite3* db, int argc, const char *const*argv) override;
7+
virtual std::unique_ptr<VirtualTable>
8+
Create(sqlite3 *db, int argc, const char *const *argv) override;
9+
virtual std::unique_ptr<VirtualTable>
10+
Connect(sqlite3 *db, int argc, const char *const *argv) override;
911
};
1012

1113
#endif

src/IResultStream.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#ifndef IRESULTSTREAM_HPP
22
#define IRESULTSTREAM_HPP
33

4-
template<typename T>
5-
class IResultStream {
4+
template <typename T> class IResultStream {
65
public:
76
virtual ~IResultStream() = default;
87

9-
virtual const T& Current() = 0;
8+
virtual const T &Current() = 0;
109
virtual bool Next() = 0;
1110
};
1211

src/Module.cc

+64-92
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,25 @@ struct module_vtab_cur {
1616
};
1717

1818
static int module_destroy(sqlite3_vtab *pVtab) {
19-
auto vtab = (module_vtab*)pVtab;
19+
auto vtab = (module_vtab *)pVtab;
2020
vtab->tab->Destroy();
2121
delete vtab;
2222
return SQLITE_OK;
2323
}
2424

2525
static int module_disconnect(sqlite3_vtab *pVtab) {
26-
auto vtab = (module_vtab*)pVtab;
26+
auto vtab = (module_vtab *)pVtab;
2727
vtab->tab->Disconnect();
2828
delete vtab;
2929
return SQLITE_OK;
3030
}
3131

32-
static int module_create(
33-
sqlite3 *db, void *pAux,
34-
int argc, const char *const*argv,
35-
sqlite3_vtab **ppVTab,
36-
char **pzErr
37-
){
38-
auto mod = (Module*)pAux;
32+
static int module_create(sqlite3 *db, void *pAux, int argc,
33+
const char *const *argv, sqlite3_vtab **ppVTab,
34+
char **pzErr) {
35+
auto mod = (Module *)pAux;
3936
auto vtab = new module_vtab();
40-
if(vtab == nullptr) {
37+
if (vtab == nullptr) {
4138
return SQLITE_NOMEM;
4239
}
4340

@@ -47,15 +44,12 @@ static int module_create(
4744
return SQLITE_OK;
4845
}
4946

50-
static int module_connect(
51-
sqlite3 *db, void *pAux,
52-
int argc, const char *const*argv,
53-
sqlite3_vtab **ppVTab,
54-
char **pzErr
55-
){
56-
auto mod = (Module*)pAux;
47+
static int module_connect(sqlite3 *db, void *pAux, int argc,
48+
const char *const *argv, sqlite3_vtab **ppVTab,
49+
char **pzErr) {
50+
auto mod = (Module *)pAux;
5751
auto vtab = new module_vtab();
58-
if(vtab == nullptr) {
52+
if (vtab == nullptr) {
5953
return SQLITE_NOMEM;
6054
}
6155

@@ -65,13 +59,10 @@ static int module_connect(
6559
return SQLITE_OK;
6660
}
6761

68-
static int module_open(
69-
sqlite3_vtab *pVTab,
70-
sqlite3_vtab_cursor **pp_cursor
71-
){
72-
auto table = (module_vtab*)pVTab;
62+
static int module_open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **pp_cursor) {
63+
auto table = (module_vtab *)pVTab;
7364
auto cur = new module_vtab_cur();
74-
if(cur == nullptr) {
65+
if (cur == nullptr) {
7566
return SQLITE_NOMEM;
7667
} else {
7768
cur->cur = table->tab->Open();
@@ -80,108 +71,89 @@ static int module_open(
8071
}
8172
}
8273

83-
static int module_close(
84-
sqlite3_vtab_cursor *pVCur
85-
){
86-
auto cur = (module_vtab_cur*)pVCur;
74+
static int module_close(sqlite3_vtab_cursor *pVCur) {
75+
auto cur = (module_vtab_cur *)pVCur;
8776
cur->cur->Close();
8877
delete cur;
8978
return SQLITE_OK;
9079
}
9180

92-
static int module_eof(
93-
sqlite3_vtab_cursor *base
94-
){
95-
auto cur = (module_vtab_cur*)base;
81+
static int module_eof(sqlite3_vtab_cursor *base) {
82+
auto cur = (module_vtab_cur *)base;
9683
return cur->cur->Eof();
9784
}
9885

99-
static int module_next(
100-
sqlite3_vtab_cursor *base
101-
){
102-
auto cur = (module_vtab_cur*)base;
86+
static int module_next(sqlite3_vtab_cursor *base) {
87+
auto cur = (module_vtab_cur *)base;
10388
return cur->cur->Next();
10489
}
10590

106-
static int module_column(
107-
sqlite3_vtab_cursor *base,
108-
sqlite3_context *ctx,
109-
int idxCol
110-
){
111-
auto cur = (module_vtab_cur*)base;
91+
static int module_column(sqlite3_vtab_cursor *base, sqlite3_context *ctx,
92+
int idxCol) {
93+
auto cur = (module_vtab_cur *)base;
11294
return cur->cur->Column(ctx, idxCol);
11395
}
11496

115-
static int module_rowid(
116-
sqlite3_vtab_cursor *base,
117-
sqlite3_int64* rowid
118-
){
119-
auto cur = (module_vtab_cur*)base;
97+
static int module_rowid(sqlite3_vtab_cursor *base, sqlite3_int64 *rowid) {
98+
auto cur = (module_vtab_cur *)base;
12099
*rowid = cur->cur->RowId();
121100
return SQLITE_OK;
122101
}
123102

124-
static int module_filter(
125-
sqlite3_vtab_cursor *base,
126-
int idxNum, const char *idxStr,
127-
int argc, sqlite3_value **argv
128-
) {
129-
auto cur = (module_vtab_cur*)base;
103+
static int module_filter(sqlite3_vtab_cursor *base, int idxNum,
104+
const char *idxStr, int argc, sqlite3_value **argv) {
105+
auto cur = (module_vtab_cur *)base;
130106
return cur->cur->Filter(idxNum, idxStr, argc, argv);
131107
}
132108

133-
static int module_best_index(
134-
sqlite3_vtab *base,
135-
sqlite3_index_info *pIdxInfo
136-
){
137-
auto tab = (module_vtab*)base;
109+
static int module_best_index(sqlite3_vtab *base, sqlite3_index_info *pIdxInfo) {
110+
auto tab = (module_vtab *)base;
138111
return tab->tab->BestIndex(pIdxInfo);
139112
}
140113

141-
static int module_find_function(
142-
sqlite3_vtab *base,
143-
int nArg,
144-
const char *zName,
145-
void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
146-
void **ppArg
147-
) {
148-
auto tab = (module_vtab*)base;
114+
static int module_find_function(sqlite3_vtab *base, int nArg, const char *zName,
115+
void (**pxFunc)(sqlite3_context *, int,
116+
sqlite3_value **),
117+
void **ppArg) {
118+
auto tab = (module_vtab *)base;
149119
return tab->tab->FindFunction(nArg, zName, pxFunc, ppArg);
150120
}
151121

152122
static sqlite3_module module_vtbl = {
153-
0, /* iVersion */
154-
module_create, /* xCreate */
155-
module_create, /* xConnect */
156-
module_best_index, /* xBestIndex */
157-
module_disconnect, /* xDisconnect */
158-
module_destroy, /* xDestroy */
159-
module_open, /* xOpen */
160-
module_close, /* xClose */
161-
module_filter, /* xFilter */
162-
module_next, /* xNext */
163-
module_eof, /* xEof */
164-
module_column, /* xColumn */
165-
module_rowid, /* xRowid */
166-
nullptr, /* xUpdate */
167-
nullptr, /* xBegin */
168-
nullptr, /* xSync */
169-
nullptr, /* xCommit */
170-
nullptr, /* xRollback */
171-
module_find_function, /* xFindFunction */
172-
nullptr, /* xRename */
173-
nullptr, /* xSavepoint */
174-
nullptr, /* xRelease */
175-
nullptr /* xRollbackto */
123+
0, /* iVersion */
124+
module_create, /* xCreate */
125+
module_create, /* xConnect */
126+
module_best_index, /* xBestIndex */
127+
module_disconnect, /* xDisconnect */
128+
module_destroy, /* xDestroy */
129+
module_open, /* xOpen */
130+
module_close, /* xClose */
131+
module_filter, /* xFilter */
132+
module_next, /* xNext */
133+
module_eof, /* xEof */
134+
module_column, /* xColumn */
135+
module_rowid, /* xRowid */
136+
nullptr, /* xUpdate */
137+
nullptr, /* xBegin */
138+
nullptr, /* xSync */
139+
nullptr, /* xCommit */
140+
nullptr, /* xRollback */
141+
module_find_function, /* xFindFunction */
142+
nullptr, /* xRename */
143+
nullptr, /* xSavepoint */
144+
nullptr, /* xRelease */
145+
nullptr /* xRollbackto */
176146
};
177147

178-
#define CHECK_ERR(e) if((err = (e)) != SQLITE_OK) return err;
148+
#define CHECK_ERR(e) \
149+
if ((err = (e)) != SQLITE_OK) \
150+
return err;
179151

180-
static void dummy_func(sqlite3_context* ctx,int,sqlite3_value**) {
152+
static void dummy_func(sqlite3_context *ctx, int, sqlite3_value **) {
181153
sqlite3_result_error(ctx, "Invalid call to function", -1);
182154
}
183155

184-
int Module::Register(sqlite3* db, const char* name) {
156+
int Module::Register(sqlite3 *db, const char *name) {
185157
int err;
186158
CHECK_ERR(sqlite3_create_module(db, name, &module_vtbl, this));
187159
return SQLITE_OK;

src/Module.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ class VirtualTable;
77

88
class Module {
99
public:
10-
virtual std::unique_ptr<VirtualTable> Create(sqlite3* db, int argc, const char *const*argv) = 0;
11-
virtual std::unique_ptr<VirtualTable> Connect(sqlite3* db, int argc, const char *const*argv) = 0;
10+
virtual std::unique_ptr<VirtualTable> Create(sqlite3 *db, int argc,
11+
const char *const *argv) = 0;
12+
virtual std::unique_ptr<VirtualTable> Connect(sqlite3 *db, int argc,
13+
const char *const *argv) = 0;
1214
virtual ~Module() = default;
1315

14-
int Register(sqlite3* db, const char* name);
16+
int Register(sqlite3 *db, const char *name);
1517
};
1618

1719
#endif

0 commit comments

Comments
 (0)