clangc 1.0.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/clangc/_clangc_functions.c +303 -0
- data/ext/clangc/_clangc_functions.h +51 -0
- data/ext/clangc/clangc.c +376 -0
- data/ext/clangc/class_CodeCompleteResults.c +186 -0
- data/ext/clangc/class_CodeCompleteResults.h +51 -0
- data/ext/clangc/class_CompletionResult.c +98 -0
- data/ext/clangc/class_CompletionResult.h +36 -0
- data/ext/clangc/class_CompletionString.c +231 -0
- data/ext/clangc/class_CompletionString.h +57 -0
- data/ext/clangc/class_Cursor.c +1677 -0
- data/ext/clangc/class_Cursor.h +259 -0
- data/ext/clangc/class_CursorSet.c +109 -0
- data/ext/clangc/class_CursorSet.h +39 -0
- data/ext/clangc/class_Diagnostic.c +322 -0
- data/ext/clangc/class_Diagnostic.h +66 -0
- data/ext/clangc/class_File.c +145 -0
- data/ext/clangc/class_File.h +45 -0
- data/ext/clangc/class_Index.c +461 -0
- data/ext/clangc/class_Index.h +58 -0
- data/ext/clangc/class_Module.c +181 -0
- data/ext/clangc/class_Module.h +51 -0
- data/ext/clangc/class_OverriddenCursor.c +51 -0
- data/ext/clangc/class_OverriddenCursor.h +31 -0
- data/ext/clangc/class_SourceLocation.c +197 -0
- data/ext/clangc/class_SourceLocation.h +45 -0
- data/ext/clangc/class_SourceRange.c +123 -0
- data/ext/clangc/class_SourceRange.h +42 -0
- data/ext/clangc/class_TranslationUnit.c +457 -0
- data/ext/clangc/class_TranslationUnit.h +63 -0
- data/ext/clangc/class_Type.c +564 -0
- data/ext/clangc/class_Type.h +108 -0
- data/ext/clangc/constants.c +660 -0
- data/ext/clangc/constants.h +21 -0
- data/ext/clangc/extconf.rb +34 -0
- data/ext/clangc/macros.h +230 -0
- data/lib/clangc.rb +397 -0
- metadata +95 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
* ruby-clangc ruby bindings for the C interface of Clang
|
4
|
+
* Copyright (C) 2015 cedlemo <cedlemo@gmx.com>
|
5
|
+
*
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
9
|
+
* (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
* GNU General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public License
|
17
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
19
|
+
#include <ruby/ruby.h>
|
20
|
+
void init_clang_enums_to_constants(VALUE);
|
21
|
+
void init_clang_errors_enums_to_constants(VALUE);
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
$CFLAGS += " -I#{`llvm-config --prefix`.chomp}/include"
|
4
|
+
#$CFLAGS += " -std=c89 -pedantic -Wall"
|
5
|
+
#$CFLAGS += " -Wno-missing-braces -Wextra -Wno-missing-field-initializers -Wformat=2"
|
6
|
+
#$CFLAGS += " -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith"
|
7
|
+
#$CFLAGS += " -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline"
|
8
|
+
#$CFLAGS += " -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code"
|
9
|
+
#$CFLAGS += " -Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls"
|
10
|
+
#$CFLAGS += " -Wold-style-definition -Werror"
|
11
|
+
#$CFLAGS += " -ggdb3"
|
12
|
+
#$CFLAGS += " -O0"
|
13
|
+
#$CFLAGS += " -fno-omit-frame-pointer -ffloat-store -fno-common -fstrict-aliasing"
|
14
|
+
#$CFLAGS += " -lm"
|
15
|
+
#$LIBS += " #{`llvm-config --libs`.chomp}"
|
16
|
+
# When the libclang.so is in a custom directory:
|
17
|
+
# llvm-config --libdir => /usr/lib64/llvm in Fedora
|
18
|
+
# llvm-config --libdir => /usr/lib in Archlinux so not needed
|
19
|
+
$LDFLAGS << " -L#{`llvm-config --libdir`.chomp}"
|
20
|
+
# override normal build configuration to build debug friendly library
|
21
|
+
# if installed via 'gem install clangc -- --enable-debug'
|
22
|
+
if enable_config('debug')
|
23
|
+
puts '[INFO] enabling debug library build configuration.'
|
24
|
+
if RUBY_VERSION < '1.9'
|
25
|
+
$CFLAGS = CONFIG['CFLAGS'].gsub(/\s\-O\d?\s/, ' -O0 ')
|
26
|
+
$CFLAGS.gsub!(/\s?\-g\w*\s/, ' -ggdb3 ')
|
27
|
+
CONFIG['LDSHARED'] = CONFIG['LDSHARED'].gsub(/\s\-s(\s|\z)/, ' ')
|
28
|
+
else
|
29
|
+
CONFIG['debugflags'] << ' -ggdb3 -O0 -std=c89 -pedantic -Wall'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
have_library("clang", "clang_createIndex")
|
33
|
+
|
34
|
+
create_makefile("clangc/clangc")
|
data/ext/clangc/macros.h
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
/*
|
2
|
+
* ruby-clangc ruby bindings for the C interface of Clang
|
3
|
+
* Copyright (C) 2015-2016 Cedric Le Moigne cedlemo <cedlemo@gmx.com>
|
4
|
+
*
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU General Public License
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef MACROS_H
|
20
|
+
#define MACROS_H
|
21
|
+
/*****************/
|
22
|
+
/*Debugging tools*/
|
23
|
+
/*****************/
|
24
|
+
#include <stdio.h>
|
25
|
+
#include <errno.h>
|
26
|
+
#include <string.h>
|
27
|
+
#include <ruby/ruby.h>
|
28
|
+
#include "clang-c/Index.h"
|
29
|
+
|
30
|
+
#define clean_errno() (errno == 0 ? "None" : strerror(errno))
|
31
|
+
#define SENTINEL(M, ...) \
|
32
|
+
printf("[SENTINEL] (%s:%s:%d: errno: %s) " M "\n", \
|
33
|
+
__FILE__, \
|
34
|
+
__FUNCTION__, \
|
35
|
+
__LINE__, \
|
36
|
+
clean_errno(), \
|
37
|
+
##__VA_ARGS__)
|
38
|
+
#define LOG_ERR(M, ...) \
|
39
|
+
fprintf(stderr, \
|
40
|
+
"[ERROR] (%s:%s:%d: errno: %s) " M "\n", \
|
41
|
+
__FILE__, \
|
42
|
+
__FUNCTION__, \
|
43
|
+
__LINE__, \
|
44
|
+
clean_errno(), \
|
45
|
+
##__VA_ARGS__)
|
46
|
+
#define LOG_WARN(M, ...) \
|
47
|
+
fprintf(stderr, \
|
48
|
+
"[WARN] (%s:%s:%d: errno: %s) " M "\n", \
|
49
|
+
__FILE__, \
|
50
|
+
__FUNCTION__, \
|
51
|
+
__LINE__, \
|
52
|
+
clean_errno(), \
|
53
|
+
##__VA_ARGS__)
|
54
|
+
#define LOG_INFO(M, ...) \
|
55
|
+
fprintf(stderr, \
|
56
|
+
"[INFO] (%s:%s:%d) " M "\n", \
|
57
|
+
__FILE__, \
|
58
|
+
__FUNCTION__, \
|
59
|
+
__LINE__, \
|
60
|
+
##__VA_ARGS__)
|
61
|
+
#define check(A, M, ...) \
|
62
|
+
if (!(A)) \
|
63
|
+
{ \
|
64
|
+
log_err(M, ##__VA_ARGS__); \
|
65
|
+
errno = 0; \
|
66
|
+
}
|
67
|
+
#define check_mem(A) check((A), "Out of memory.")
|
68
|
+
#define check_debug(A, M, ...) \
|
69
|
+
if (!(A)) \
|
70
|
+
{ \
|
71
|
+
debug(M, ##__VA_ARGS__); \
|
72
|
+
errno = 0; \
|
73
|
+
goto error; \
|
74
|
+
}
|
75
|
+
/*****************/
|
76
|
+
/*Common C macros*/
|
77
|
+
/*****************/
|
78
|
+
#define CARRAY_LEN(A) (sizeof(A) / sizeof((A)[0]));
|
79
|
+
#define CHECK_IN_RANGE(A, MIN, MAX) \
|
80
|
+
if (A < MIN) A = MIN; \
|
81
|
+
if (A > MAX) A = MAX;
|
82
|
+
|
83
|
+
/***************************/
|
84
|
+
/*Ruby arguments to C value*/
|
85
|
+
/***************************/
|
86
|
+
// ruby array of string to C array
|
87
|
+
#define RARRAY_OF_STRINGS_2_C(args) \
|
88
|
+
Check_Type(args, T_ARRAY); \
|
89
|
+
int len = RARRAY_LEN(args); \
|
90
|
+
const char *c_args[len]; \
|
91
|
+
if (len > 0) \
|
92
|
+
{ \
|
93
|
+
int j = 0; \
|
94
|
+
for (j = 0; j < len; j++) \
|
95
|
+
{ \
|
96
|
+
VALUE arg = rb_ary_entry(args, j); \
|
97
|
+
c_args[j] = StringValueCStr(arg); \
|
98
|
+
} \
|
99
|
+
}
|
100
|
+
// ruby boolean value to C int
|
101
|
+
static inline int rbool_2_int(VALUE rval)
|
102
|
+
{
|
103
|
+
return (int) ((rval == Qtrue) ? 1 : 0);
|
104
|
+
}
|
105
|
+
#define RBOOL_2_INT(a) rbool_2_int(a)
|
106
|
+
|
107
|
+
// Ruby string to C char
|
108
|
+
static inline char *rstring_2_char(VALUE rval)
|
109
|
+
{
|
110
|
+
return StringValueCStr(rval);
|
111
|
+
}
|
112
|
+
#define RSTRING_2_CHAR(rval) rstring_2_char(rval)
|
113
|
+
|
114
|
+
static int symbol_2_const(char *module_name, char *enum_name, VALUE sym)
|
115
|
+
{
|
116
|
+
VALUE main_module, enum_module, constant_name;
|
117
|
+
main_module = rb_const_get(rb_cObject, rb_intern(module_name));
|
118
|
+
enum_module = rb_const_get(main_module, rb_intern(enum_name));
|
119
|
+
constant_name = rb_funcall(sym, rb_intern("to_s"), 0, NULL);
|
120
|
+
constant_name = rb_funcall(constant_name, rb_intern("upcase"), 0, NULL);
|
121
|
+
VALUE num = rb_const_get(enum_module, rb_intern_str(constant_name));
|
122
|
+
|
123
|
+
return NUM2UINT(num);
|
124
|
+
}
|
125
|
+
|
126
|
+
static int bitmask_or_array(char *module_name, char *enum_name, VALUE array)
|
127
|
+
{
|
128
|
+
int or_sum = 0;
|
129
|
+
int i = 0;
|
130
|
+
int len = RARRAY_LEN(array);
|
131
|
+
|
132
|
+
for(i = 0; i < len; i++)
|
133
|
+
{
|
134
|
+
VALUE sym = rb_ary_entry(array, i);
|
135
|
+
or_sum = or_sum | symbol_2_const(module_name, enum_name, sym);
|
136
|
+
}
|
137
|
+
return or_sum;
|
138
|
+
}
|
139
|
+
|
140
|
+
static unsigned int rb_constant_argument_to_uint(char *module_name, char *enum_name, VALUE argument)
|
141
|
+
{
|
142
|
+
if(TYPE(argument) == T_SYMBOL)
|
143
|
+
return symbol_2_const(module_name, enum_name, argument);
|
144
|
+
else if(TYPE(argument) == T_ARRAY)
|
145
|
+
return bitmask_or_array(module_name, enum_name, argument);
|
146
|
+
else
|
147
|
+
return NUM2UINT(argument);
|
148
|
+
}
|
149
|
+
#define CLANGC_CONSTANT_TO_UINT(enum_name, argument) \
|
150
|
+
rb_constant_argument_to_uint("Clangc", enum_name, argument)
|
151
|
+
|
152
|
+
/****************/
|
153
|
+
/*Classes Macros*/
|
154
|
+
/****************/
|
155
|
+
// Check argument
|
156
|
+
static inline void check_arg_type(VALUE arg, char *class_name)
|
157
|
+
{
|
158
|
+
VALUE mModule;
|
159
|
+
VALUE cKlass;
|
160
|
+
char *message;
|
161
|
+
int len;
|
162
|
+
|
163
|
+
Check_Type(arg, T_DATA);
|
164
|
+
mModule = rb_const_get(rb_cObject, rb_intern("Clangc"));
|
165
|
+
cKlass = rb_const_get(mModule, rb_intern(class_name));
|
166
|
+
|
167
|
+
len = asprintf(&message, "Clangc::%s Object was expected", class_name);
|
168
|
+
|
169
|
+
if (cKlass != rb_funcall(arg, rb_intern("class"), 0))
|
170
|
+
{
|
171
|
+
if (len != -1)
|
172
|
+
{
|
173
|
+
rb_raise(rb_eTypeError, "%s", message);
|
174
|
+
free(message);
|
175
|
+
}
|
176
|
+
else
|
177
|
+
rb_raise(rb_eTypeError, "Not the object type expected");
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
#define CHECK_ARG_TYPE(arg, classname) check_arg_type(arg, #classname)
|
182
|
+
|
183
|
+
// Create a new instance without args and get its data
|
184
|
+
#define R_GET_CLASS_DATA(module_name, class_name, instance, data_ptr) \
|
185
|
+
VALUE mModule = rb_const_get(rb_cObject, rb_intern(module_name)); \
|
186
|
+
VALUE cKlass = rb_const_get(mModule, rb_intern(#class_name)); \
|
187
|
+
instance = rb_class_new_instance(0, NULL, cKlass); \
|
188
|
+
Data_Get_Struct(instance, class_name##_t, data_ptr);
|
189
|
+
|
190
|
+
// Create a new instance with args and get its data
|
191
|
+
#define R_GET_CLASS_WITH_ARGS_DATA( \
|
192
|
+
module_name, class_name, instance, args, data_type, data_ptr) \
|
193
|
+
VALUE mModule = rb_const_get(rb_cObject, rb_intern(module_name)); \
|
194
|
+
VALUE cKlass = rb_const_get(mModule, rb_intern(class_name)); \
|
195
|
+
int args_n = CARRAY_LEN(args) instance = \
|
196
|
+
rb_class_new_instance(args_len, args, cKlass); \
|
197
|
+
Data_Get_Struct(instance, data_type, data_ptr);
|
198
|
+
|
199
|
+
/* For later.
|
200
|
+
#define NEW_CLASS_INSTANCE(class_name)\
|
201
|
+
static inline VALUE new_##class_name##_inst(class_name##_t *data)\
|
202
|
+
{\
|
203
|
+
VALUE instance;\
|
204
|
+
R_GET_CLASS_DATA("clangc", class_name, instance, data);\
|
205
|
+
return instance;\
|
206
|
+
}
|
207
|
+
NEW_CLASS_INSTANCE(TranslationUnit)
|
208
|
+
#undef NEW_CLASS_INSTANCE*/
|
209
|
+
|
210
|
+
/************************/
|
211
|
+
/*C values to Ruby value*/
|
212
|
+
/************************/
|
213
|
+
static inline VALUE cxstring_2_rval(CXString str)
|
214
|
+
{
|
215
|
+
VALUE r_string;
|
216
|
+
const char *c_string =
|
217
|
+
(clang_getCString(str) != NULL) ? clang_getCString(str) : "";
|
218
|
+
r_string = rb_str_new2(c_string);
|
219
|
+
clang_disposeString(str);
|
220
|
+
return r_string;
|
221
|
+
}
|
222
|
+
#define CUINT_2_NUM(c_val) UINT2NUM(c_val)
|
223
|
+
#define CINT_2_NUM(c_val) INT2NUM(c_val)
|
224
|
+
#define CLLONG_2_NUM(c_val) LL2NUM(c_val)
|
225
|
+
#define CULLONG_2_NUM(c_val) ULL2NUM(c_val)
|
226
|
+
#define NOT_0_2_RVAL(c_val) ((c_val == 0) ? Qfalse : Qtrue)
|
227
|
+
#define EQ_1_2_RVAL(c_val) ((c_val == 1) ? Qtrue : Qfalse)
|
228
|
+
#define CXSTR_2_RVAL(str) (cxstring_2_rval(str))
|
229
|
+
|
230
|
+
#endif // MACROS_H
|
data/lib/clangc.rb
ADDED
@@ -0,0 +1,397 @@
|
|
1
|
+
require "clangc/clangc"
|
2
|
+
|
3
|
+
module Clangc
|
4
|
+
##
|
5
|
+
# :call-seq:
|
6
|
+
# Clangc.visit_children(Hash)
|
7
|
+
#
|
8
|
+
# This is a convenient method that call Clangc.visit_children_with_proc or
|
9
|
+
# Clangc.visit_children_with_block.
|
10
|
+
# the Hash arguments can accept two keys:
|
11
|
+
# * cursor
|
12
|
+
# * visitor
|
13
|
+
#
|
14
|
+
# Clangc.visit_children(cursor: acursor, visitor: aproc)
|
15
|
+
#
|
16
|
+
# Clangc.visit_children(cursor: acursor) do |cursor, parent|
|
17
|
+
# #do your stuf
|
18
|
+
# return Clangc::ChildVisitResult::Recurse
|
19
|
+
# #return Clangc::ChildVisitResult::Break
|
20
|
+
# end
|
21
|
+
def self.visit_children(args)
|
22
|
+
cursor = args[:cursor]
|
23
|
+
callback = args[:visitor] || nil
|
24
|
+
if(callback)
|
25
|
+
visit_children_with_proc(cursor, callback)
|
26
|
+
else
|
27
|
+
visit_children_with_block(cursor) do |cursor, parent|
|
28
|
+
yield(cursor, parent)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
class TranslationUnit
|
33
|
+
##
|
34
|
+
# :call-seq:
|
35
|
+
# Clangc::TranslationUnit#diagnostics => Array
|
36
|
+
#
|
37
|
+
# Returns an array of Clangc::Diagnostic for the current Clangc::TranslationUnit.
|
38
|
+
# The array is empty if no Clangc::Diagnostic can be found.
|
39
|
+
def diagnostics
|
40
|
+
ds = []
|
41
|
+
for i in 0..(diagnostics_num - 1) do
|
42
|
+
ds << diagnostic(i)
|
43
|
+
end
|
44
|
+
ds
|
45
|
+
end
|
46
|
+
end
|
47
|
+
class Diagnostic
|
48
|
+
##
|
49
|
+
# :call-seq:
|
50
|
+
# Clangc::Diagnostic#source_ranges => Array
|
51
|
+
#
|
52
|
+
# Returns an array of Clangc::SourceRange for the current Clangc::Diagnostic.
|
53
|
+
# The array is empty if there is no Clangc::SourceRange
|
54
|
+
def source_ranges
|
55
|
+
num = num_ranges
|
56
|
+
sr = []
|
57
|
+
return sr if num == 0
|
58
|
+
|
59
|
+
for i in 0..(num - 1) do
|
60
|
+
sr << source_range(i)
|
61
|
+
end
|
62
|
+
sr
|
63
|
+
end
|
64
|
+
end
|
65
|
+
class Type
|
66
|
+
##
|
67
|
+
# :call-seq:
|
68
|
+
# Clangc::Type#arg_types -> Array
|
69
|
+
#
|
70
|
+
# Return an array that contains all the
|
71
|
+
# types for the argument of the function that
|
72
|
+
# is related to the current type.
|
73
|
+
# If the current type is not a function, it returns
|
74
|
+
# an empty array.
|
75
|
+
def arg_types
|
76
|
+
num = num_arg_types
|
77
|
+
return [] if num == -1
|
78
|
+
|
79
|
+
types = []
|
80
|
+
for i in 0..(num - 1) do
|
81
|
+
types << arg_type(i)
|
82
|
+
end
|
83
|
+
types
|
84
|
+
end
|
85
|
+
##
|
86
|
+
# :call-seq:
|
87
|
+
# Clangc::Type#template_arguments_as_type -> Array
|
88
|
+
#
|
89
|
+
# Return an array that contains all the
|
90
|
+
# types for the arguments of the current Class Type template that
|
91
|
+
# is related to the current cursor.
|
92
|
+
# If the Cursor is not a Class Declaration, it returns
|
93
|
+
# an empty array.
|
94
|
+
def template_arguments_as_type
|
95
|
+
num = num_template_arguments
|
96
|
+
types = []
|
97
|
+
return types if num == -1
|
98
|
+
|
99
|
+
for i in 0..(num - 1) do
|
100
|
+
types << template_argument_as_type(i)
|
101
|
+
end
|
102
|
+
types
|
103
|
+
end
|
104
|
+
end
|
105
|
+
class Cursor
|
106
|
+
##
|
107
|
+
# :call-seq:
|
108
|
+
# Clangc::Cursor#arguments -> Array
|
109
|
+
#
|
110
|
+
# Return an array that contains all the
|
111
|
+
# cursors for the arguments of the function that
|
112
|
+
# is related to the current cursor.
|
113
|
+
# If the current cursor is not a function, it returns
|
114
|
+
# an empty array.
|
115
|
+
def arguments
|
116
|
+
num = num_arguments
|
117
|
+
cursors = []
|
118
|
+
return cursors if num == -1
|
119
|
+
|
120
|
+
for i in 0..(num - 1) do
|
121
|
+
cursors << argument(i)
|
122
|
+
end
|
123
|
+
cursors
|
124
|
+
end
|
125
|
+
##
|
126
|
+
# :call-seq:
|
127
|
+
# Clangc::Cursor#overloaded_decls -> Array
|
128
|
+
#
|
129
|
+
# Return an array that contains all the
|
130
|
+
# cursors for the overloaded declarations that
|
131
|
+
# are related to the current cursor.
|
132
|
+
# If the current cursor is not an overloaded declaration, it returns
|
133
|
+
# an empty array.
|
134
|
+
def overloaded_decls
|
135
|
+
num = num_overloaded_decls
|
136
|
+
cursors = []
|
137
|
+
return cursors if num == 0
|
138
|
+
|
139
|
+
for i in 0..(num - 1) do
|
140
|
+
cursors << overloaded_decl(i)
|
141
|
+
end
|
142
|
+
cursors
|
143
|
+
end
|
144
|
+
##
|
145
|
+
# :call-seq:
|
146
|
+
# Clangc::Cursor#template_arguments_kinds -> Array
|
147
|
+
#
|
148
|
+
# Return an array that contains all the
|
149
|
+
# kinds for the arguments of the function template that
|
150
|
+
# is related to the current cursor.
|
151
|
+
# If the current cursor is not a function declaration, it returns
|
152
|
+
# an empty array.
|
153
|
+
def template_arguments_kinds
|
154
|
+
num = num_template_arguments
|
155
|
+
kinds = []
|
156
|
+
return kinds if num == -1
|
157
|
+
|
158
|
+
for i in 0..(num - 1) do
|
159
|
+
kinds << template_argument_kind(i)
|
160
|
+
end
|
161
|
+
kinds
|
162
|
+
end
|
163
|
+
##
|
164
|
+
# :call-seq:
|
165
|
+
# Clangc::Cursor#template_arguments_types -> Array
|
166
|
+
#
|
167
|
+
# Return an array that contains all the
|
168
|
+
# types for the arguments of the function template that
|
169
|
+
# is related to the current cursor.
|
170
|
+
# If the current cursor is not a function declaration, it returns
|
171
|
+
# an empty array.
|
172
|
+
def template_arguments_types
|
173
|
+
num = num_template_arguments
|
174
|
+
types = []
|
175
|
+
return types if num == -1
|
176
|
+
|
177
|
+
for i in 0..(num - 1) do
|
178
|
+
types << template_argument_type(i)
|
179
|
+
end
|
180
|
+
types
|
181
|
+
end
|
182
|
+
##
|
183
|
+
# :call-seq:
|
184
|
+
# Clangc::Cursor#template_arguments_values -> Array
|
185
|
+
#
|
186
|
+
# Return an array that contains all the
|
187
|
+
# values for the arguments of the function template that
|
188
|
+
# is related to the current cursor.
|
189
|
+
# If the current cursor is not a function declaration, it returns
|
190
|
+
# an empty array.
|
191
|
+
def template_arguments_values
|
192
|
+
num = num_template_arguments
|
193
|
+
values = []
|
194
|
+
return values if num == -1
|
195
|
+
|
196
|
+
for i in 0..(num - 1) do
|
197
|
+
values << template_argument_value(i)
|
198
|
+
end
|
199
|
+
values
|
200
|
+
end
|
201
|
+
##
|
202
|
+
# :call-seq:
|
203
|
+
# Clangc::Cursor#template_arguments_unsigned_values -> Array
|
204
|
+
#
|
205
|
+
# Return an array that contains all the
|
206
|
+
# values for the arguments of the function template that
|
207
|
+
# is related to the current cursor.
|
208
|
+
# If the current cursor is not a function declaration, it returns
|
209
|
+
# an empty array.
|
210
|
+
def template_arguments_unsigned_values
|
211
|
+
num = num_template_arguments
|
212
|
+
values = []
|
213
|
+
return values if num == -1
|
214
|
+
|
215
|
+
for i in 0..(num - 1) do
|
216
|
+
values << template_argument_unsigned_value(i)
|
217
|
+
end
|
218
|
+
values
|
219
|
+
end
|
220
|
+
end
|
221
|
+
class Module
|
222
|
+
##
|
223
|
+
# :call-seq:
|
224
|
+
# Clangc::Module#top_level_headers(Clangc::TranslationUnit) -> Array
|
225
|
+
#
|
226
|
+
# Return an array that contains all the
|
227
|
+
# Clangc::File corresponding to the related
|
228
|
+
# toplevel headers.
|
229
|
+
# If the current cursor is not a module, it returns
|
230
|
+
# an empty array.
|
231
|
+
def top_level_headers(tu)
|
232
|
+
num = num_top_level_headers(tu)
|
233
|
+
headers = []
|
234
|
+
return headers if num < 1
|
235
|
+
|
236
|
+
for i in 0..(num - 1) do
|
237
|
+
headers << top_level_header(tu, i)
|
238
|
+
end
|
239
|
+
headers
|
240
|
+
end
|
241
|
+
end
|
242
|
+
class CompletionString
|
243
|
+
##
|
244
|
+
# :call-seq:
|
245
|
+
# Clangc::CompletionString#chunk_kinds -> Array
|
246
|
+
#
|
247
|
+
# Return an array that contains all the
|
248
|
+
# kinds of the chunk completions for a
|
249
|
+
# completion string.
|
250
|
+
def chunk_kinds
|
251
|
+
num = num_chunks
|
252
|
+
return [] if num == -1
|
253
|
+
|
254
|
+
kinds = []
|
255
|
+
for i in 0..(num - 1) do
|
256
|
+
kinds << chunk_kind(i)
|
257
|
+
end
|
258
|
+
kinds
|
259
|
+
end
|
260
|
+
##
|
261
|
+
# :call-seq:
|
262
|
+
# Clangc::CompletionString#chunk_texts -> Array
|
263
|
+
#
|
264
|
+
# Return an array that contains all the
|
265
|
+
# texts of the chunk completions for a
|
266
|
+
# completion string.
|
267
|
+
def chunk_texts
|
268
|
+
num = num_chunks
|
269
|
+
return [] if num == -1
|
270
|
+
|
271
|
+
texts = []
|
272
|
+
for i in 0..(num - 1) do
|
273
|
+
texts << chunk_text(i)
|
274
|
+
end
|
275
|
+
texts
|
276
|
+
end
|
277
|
+
##
|
278
|
+
# :call-seq:
|
279
|
+
# Clangc::CompletionString#num_annotations -> Array
|
280
|
+
#
|
281
|
+
# Return an array that contains all the
|
282
|
+
# annotations for a completion string.
|
283
|
+
def annotations
|
284
|
+
num = num_annotations
|
285
|
+
return [] if num == -1
|
286
|
+
|
287
|
+
annotations = []
|
288
|
+
for i in 0..(num - 1) do
|
289
|
+
annotations << annotation(i)
|
290
|
+
end
|
291
|
+
annotations
|
292
|
+
end
|
293
|
+
##
|
294
|
+
# :call-seq:
|
295
|
+
# Clangc::CompletionString#chunk_text_completion_strings -> Array
|
296
|
+
#
|
297
|
+
# Return an array that contains all the
|
298
|
+
# completion strings for a
|
299
|
+
# completion string.
|
300
|
+
def chunk_completion_strings
|
301
|
+
num = num_chunks
|
302
|
+
return [] if num == -1
|
303
|
+
|
304
|
+
completion_strings = []
|
305
|
+
for i in 0..(num - 1) do
|
306
|
+
completion_strings << chunk_completion_string(i)
|
307
|
+
end
|
308
|
+
completion_strings
|
309
|
+
end
|
310
|
+
end
|
311
|
+
class CodeCompleteResults
|
312
|
+
##
|
313
|
+
# :call-seq:
|
314
|
+
# Clangc::CodeCompleteResults#results => Array
|
315
|
+
#
|
316
|
+
# Returns an Array of Clangc::CompletionResult
|
317
|
+
def results
|
318
|
+
num = num_results
|
319
|
+
return [] if num < 0
|
320
|
+
|
321
|
+
res = []
|
322
|
+
for i in 0..(num - 1) do
|
323
|
+
res << result(i)
|
324
|
+
end
|
325
|
+
res
|
326
|
+
end
|
327
|
+
##
|
328
|
+
# :call-seq:
|
329
|
+
# Clangc::CodeCompleteResults#diagnostics => Array
|
330
|
+
#
|
331
|
+
# Returns an Array of Clangc::Diagnostics
|
332
|
+
def diagnostics
|
333
|
+
num = num_diagnostics
|
334
|
+
return [] if num < 0
|
335
|
+
|
336
|
+
diags = []
|
337
|
+
for i in 0..(num - 1) do
|
338
|
+
diags << diagnostic(i)
|
339
|
+
end
|
340
|
+
diags
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
class Index
|
345
|
+
##
|
346
|
+
# :call-seq:
|
347
|
+
# Clangc::Index#translation_unit(options) => Clangc::TranslationUnit
|
348
|
+
#
|
349
|
+
# Convenient method that easily allow to create a translation unit
|
350
|
+
# through different ways based on the options you use:
|
351
|
+
# :source => source file
|
352
|
+
# :args => command line arguments
|
353
|
+
# :error => true or false or nil
|
354
|
+
# :ast => String an ast file
|
355
|
+
alias_method :create_translation_unit_raw, :create_translation_unit
|
356
|
+
|
357
|
+
def create_translation_unit(options)
|
358
|
+
source = options[:source] || ""
|
359
|
+
args = options[:args] || []
|
360
|
+
error = options[:error] || nil
|
361
|
+
ast = options[:ast] || nil
|
362
|
+
if ast
|
363
|
+
error ? create_translation_unit2(ast) : create_translation_unit_raw(ast)
|
364
|
+
else
|
365
|
+
create_translation_unit_from_source_file(source, args)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
##
|
370
|
+
# :call-seq:
|
371
|
+
# Clangc::Index#parse_translation_unit(options) => Clangc::TranslationUnit
|
372
|
+
#
|
373
|
+
# Convenient method that easily allow to parse a file to a translation
|
374
|
+
# unit through different ways based on the options you use:
|
375
|
+
# :source => source file
|
376
|
+
# :args => command line arguments
|
377
|
+
# :error => true or false or nil
|
378
|
+
# :flags => bitwise OR of the TranslationUnit_Flags constants
|
379
|
+
# :argv => true or false in order to use argv form
|
380
|
+
alias_method :parse_translation_unit_raw, :parse_translation_unit
|
381
|
+
|
382
|
+
def parse_translation_unit(options)
|
383
|
+
source = options[:source] || ""
|
384
|
+
args = options[:args] || []
|
385
|
+
error = options[:error] || nil
|
386
|
+
flags = options[:flags] || Clangc::TranslationUnit_Flags::NONE
|
387
|
+
argv = options[:argv] || false
|
388
|
+
if error && argv
|
389
|
+
parse_translation_unit2_full_argv(source, args, flags)
|
390
|
+
elsif error
|
391
|
+
parse_translation_unit2(source, args, flags)
|
392
|
+
else
|
393
|
+
parse_translation_unit_raw(source, args, flags)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|