Skip to content

Commit 86011c6

Browse files
committed
merge several libclang
1 parent a76fb1d commit 86011c6

File tree

17 files changed

+73
-303
lines changed

17 files changed

+73
-303
lines changed

libclang/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
set(LIBCLANG_TOOLS
22
cc_lookup
33
clang_test_it
4-
clang_visit
4+
match_symbol
55
CodeComplete
6-
compilation_db
7-
diagnose
86
diagnosis
97
func_sig
10-
inclusion_visitor
118
libclang_wrapper
129
token
13-
visit_test
1410
)
1511

1612
list(APPEND FULL_LLVM_LIBS -lclang)

libclang/cc_lookup/cc_lookup.cc

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
/**
2-
* @file cc_lookup.cpp
3-
* @brief a simple program to lookup the definition of the cursorbol given its
4-
* (line, column)
5-
*
6-
* @author Hongxu Chen
7-
* @date 2013-05-01
8-
*/
91
#include <stdio.h>
102
#include <stdlib.h>
113
#include <string.h>
124
#include <assert.h>
135
#include <clang-c/Index.h>
146

15-
const int ARG_NUM = 4; /// *test
7+
const int ARG_NUM = 4; /// *test
168

17-
/**
18-
* \brief a wrapper to print CXString and release the malloc space
19-
* \c Note that it has not so much functionality
20-
* @param cx_str the CXString to be printed and disposed
21-
*/
229
static inline void printCXString(CXString cx_str) {
2310
const char* c_str = clang_getCString(cx_str);
2411
if (c_str) {
@@ -93,12 +80,6 @@ static void printCursor(CXTranslationUnit TU, CXSourceLocation location) {
9380
}
9481
CXCursor realCursor = clang_getCanonicalCursor(cursor);
9582
clang_disposeString(fileName);
96-
printf("\n[kind]:");
97-
printCXString(clang_getCursorKindSpelling(clang_getCursorKind(cursor)));
98-
printf("\n[name]:");
99-
printCXString(clang_getCursorDisplayName(cursor));
100-
printf("\n[USR]");
101-
printCXString(clang_getCursorUSR(cursor));
10283
printf("\n[doc]");
10384
printCXString(clang_Cursor_getBriefCommentText(cursor));
10485
printf("\n[rawdoc]");
@@ -156,7 +137,7 @@ int main(int argc, char* argv[]) {
156137
}
157138

158139
CXIndex index = clang_createIndex(0, 0);
159-
const char* const* clang_args = (const char* const*)(argv + ARG_NUM);
140+
const char* const* clang_args = (const char * const*)(argv + ARG_NUM);
160141
CXTranslationUnit TU = clang_parseTranslationUnit(
161142
index,
162143
org_file_name, // source_filename, 0 if included in command_line_args

libclang/compilation_db/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

libclang/compilation_db/CompilationDatabase.cc

Lines changed: 0 additions & 51 deletions
This file was deleted.

libclang/diagnose/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

libclang/diagnose/diagnose.cc

Lines changed: 0 additions & 75 deletions
This file was deleted.

libclang/inclusion_visitor/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

libclang/inclusion_visitor/includeVisitor.cc

Lines changed: 0 additions & 22 deletions
This file was deleted.

libclang/libclang_wrapper/Common.cc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,62 @@
11
#include "Common.hpp"
22

3+
#include <clang-c/Index.h>
4+
#include <clang-c/CXCompilationDatabase.h>
5+
#include <llvm/Support/raw_ostream.h>
6+
#include <llvm/Support/Format.h>
7+
8+
#define WITH_COLOR(color, x) \
9+
{ \
10+
llvm::errs().changeColor(color); \
11+
x; \
12+
llvm::errs().resetColor(); \
13+
}
14+
15+
using namespace llvm;
16+
317
std::string getStrFromCXString(CXString const &cxstring) {
418
std::string str;
519
char const *cstr = clang_getCString(cxstring);
620
if (cstr != nullptr) str = cstr;
721
clang_disposeString(cxstring);
822
return str;
923
}
24+
25+
int DBParser(int argc, char **argv) {
26+
if (argc != 2) {
27+
errs() << format("%s database_dir\n", argv[0]);
28+
exit(1);
29+
}
30+
31+
CXCompilationDatabase_Error error;
32+
CXCompilationDatabase db =
33+
clang_CompilationDatabase_fromDirectory(argv[1], &error);
34+
switch (error) {
35+
case CXCompilationDatabase_NoError:
36+
break;
37+
case CXCompilationDatabase_CanNotLoadDatabase:
38+
errs() << "Cannot load database\n";
39+
exit(1);
40+
default:
41+
errs() << "unknown return\n";
42+
exit(1);
43+
}
44+
45+
auto cmds = clang_CompilationDatabase_getAllCompileCommands(db);
46+
auto numCmds = clang_CompileCommands_getSize(cmds);
47+
WITH_COLOR(raw_ostream::BLUE, errs() << numCmds << '\n';);
48+
for (auto i = 0U; i < numCmds; i++) {
49+
CXCompileCommands cmd = clang_CompileCommands_getCommand(cmds, i);
50+
auto numArgs = clang_CompileCommand_getNumArgs(cmd);
51+
WITH_COLOR(raw_ostream::YELLOW, errs() << numArgs << '\n');
52+
for (auto j = 0U; j < numArgs; j++) {
53+
CXString arg = clang_CompileCommand_getArg(cmd, j);
54+
errs() << clang_getCString(arg) << '\n';
55+
clang_disposeString(arg);
56+
}
57+
}
58+
59+
clang_CompileCommands_dispose(cmds);
60+
clang_CompilationDatabase_dispose(db);
61+
return 0;
62+
}

libclang/libclang_wrapper/CursorInfo.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ void CursorInfo::dump() {
6969

7070
errs() << "cursor String: "
7171
<< getStrFromCXString(clang_getCursorSpelling(cursor_)) << '\n';
72+
errs() << "cursor DisplayName: "
73+
<< getStrFromCXString(clang_getCursorDisplayName(cursor_)) << '\n';
7274
dumpIfNotNullCXStr("cursor USR", clang_getCursorUSR(cursor_));
7375
if (clang_isPreprocessing(kind_)) {
7476
if (expand_.filename_.empty()) {

libclang/libclang_wrapper/CursorInfo.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,20 @@ struct LocPoint {
2626
LocPoint &operator=(LocPoint const &) = delete;
2727
};
2828

29+
struct Comment {
30+
std::string comment;
31+
};
32+
33+
struct XMLComment : Comment {
34+
void parser();
35+
};
36+
37+
struct HTMLComment : Comment {
38+
void parser();
39+
};
40+
2941
class CursorInfo {
3042
CXCursor cursor_;
31-
std::string cursorStr_;
3243
LocPoint presumed_, expand_, spelling_;
3344
CXFile included_;
3445
CXCursor lexParent_, semaParent_, parent_;

libclang/libclang_wrapper/tests/sample.c

Lines changed: 0 additions & 14 deletions
This file was deleted.

libclang/clang_visit/clang_visit.cc renamed to libclang/match_symbol/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ enum CXChildVisitResult visitor_f(CXCursor cursor, CXCursor parent,
5757
}
5858

5959
int main(int argc, char* argv[]) {
60-
if (argc < 2) {
61-
fprintf(stderr, "Usage:\n\t <-s symbol> <-f file1>[,file2]...\n");
60+
if (argc < 5) {
61+
fprintf(stderr, "Usage:\n%s <-s symbol> <-f file1>[,file2]...\n", argv[0]);
6262
return 1;
6363
}
6464

libclang/visit_test/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)