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,45 @@
|
|
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
|
+
#ifndef SOURCELOCATION_H
|
19
|
+
#define SOURCELOCATION_H
|
20
|
+
#include <ruby/ruby.h>
|
21
|
+
#include "clang-c/Index.h"
|
22
|
+
typedef struct SourceLocation_t
|
23
|
+
{
|
24
|
+
CXSourceLocation data;
|
25
|
+
VALUE parent;
|
26
|
+
} SourceLocation_t;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
c_SourceLocation_struct_alloc(VALUE);
|
30
|
+
|
31
|
+
VALUE
|
32
|
+
c_SourceLocation_is_in_system_header(VALUE);
|
33
|
+
|
34
|
+
VALUE
|
35
|
+
c_SourceLocation_is_from_main_file(VALUE);
|
36
|
+
|
37
|
+
VALUE
|
38
|
+
c_SourceLocation_is_equal(VALUE, VALUE);
|
39
|
+
|
40
|
+
VALUE
|
41
|
+
c_SourceLocation_get_spelling(VALUE);
|
42
|
+
|
43
|
+
VALUE
|
44
|
+
c_SourceLocation_get_file_location(VALUE);
|
45
|
+
#endif // SOURCELOCATION_H
|
@@ -0,0 +1,123 @@
|
|
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
|
+
/*SourceRange ruby class*/
|
19
|
+
#include "class_SourceRange.h"
|
20
|
+
#include "macros.h"
|
21
|
+
#include "class_SourceLocation.h"
|
22
|
+
|
23
|
+
static void c_SourceRange_struct_free(SourceRange_t *s)
|
24
|
+
{
|
25
|
+
if (s)
|
26
|
+
{
|
27
|
+
ruby_xfree(s);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
static void c_SourceRange_mark(void *s)
|
32
|
+
{
|
33
|
+
if (s)
|
34
|
+
{
|
35
|
+
SourceRange_t *t = (SourceRange_t *) s;
|
36
|
+
rb_gc_mark(t->parent);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
VALUE
|
40
|
+
c_SourceRange_struct_alloc(VALUE klass)
|
41
|
+
{
|
42
|
+
|
43
|
+
SourceRange_t *ptr;
|
44
|
+
ptr = (SourceRange_t *) ruby_xmalloc(sizeof(SourceRange_t));
|
45
|
+
ptr->parent = Qnil;
|
46
|
+
|
47
|
+
return Data_Wrap_Struct(
|
48
|
+
klass, NULL, c_SourceRange_struct_free, (void *) ptr);
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* call-seq:
|
53
|
+
* Clangc::SourceRange#is_null => true or false
|
54
|
+
*
|
55
|
+
* Returns true is the underlying CXSourceRange is NULL or false otherwise
|
56
|
+
*/
|
57
|
+
VALUE
|
58
|
+
c_SourceRange_is_null(VALUE self)
|
59
|
+
{
|
60
|
+
SourceRange_t *s;
|
61
|
+
Data_Get_Struct(self, SourceRange_t, s);
|
62
|
+
return NOT_0_2_RVAL(clang_Range_isNull(s->data));
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* call-seq:
|
67
|
+
* clangc::SourceRange#is_equal
|
68
|
+
*
|
69
|
+
* Determine whether two ranges are equivalent.
|
70
|
+
* Returns true if the ranges are the same, false if they differ.
|
71
|
+
*/
|
72
|
+
VALUE
|
73
|
+
c_SourceRange_is_equal(VALUE self, VALUE source_range)
|
74
|
+
{
|
75
|
+
SourceRange_t *sr1;
|
76
|
+
SourceRange_t *sr2;
|
77
|
+
Data_Get_Struct(self, SourceRange_t, sr1);
|
78
|
+
CHECK_ARG_TYPE(source_range, SourceRange);
|
79
|
+
Data_Get_Struct(source_range, SourceRange_t, sr2);
|
80
|
+
return NOT_0_2_RVAL(clang_equalRanges(sr1->data, sr2->data));
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* call-seq:
|
85
|
+
* Clangc::SourceRange#start => clangc::SourceLocation
|
86
|
+
*
|
87
|
+
* Retrieve a source location representing the first character within a
|
88
|
+
* source range.
|
89
|
+
*/
|
90
|
+
VALUE
|
91
|
+
c_SourceRange_get_start(VALUE self)
|
92
|
+
{
|
93
|
+
SourceRange_t *sr;
|
94
|
+
SourceLocation_t *sl;
|
95
|
+
VALUE a_source_location;
|
96
|
+
Data_Get_Struct(self, SourceRange_t, sr);
|
97
|
+
|
98
|
+
R_GET_CLASS_DATA("Clangc", SourceLocation, a_source_location, sl);
|
99
|
+
sl->data = clang_getRangeStart(sr->data);
|
100
|
+
sl->parent = self;
|
101
|
+
return a_source_location;
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* call-seq:
|
106
|
+
* Clangc::SourceRange#end => clangc::SourceLocation
|
107
|
+
*
|
108
|
+
* Retrieve a source location representing the last character within a
|
109
|
+
* source range.
|
110
|
+
*/
|
111
|
+
VALUE
|
112
|
+
c_SourceRange_get_end(VALUE self)
|
113
|
+
{
|
114
|
+
SourceRange_t *sr;
|
115
|
+
SourceLocation_t *sl;
|
116
|
+
VALUE a_source_location;
|
117
|
+
Data_Get_Struct(self, SourceRange_t, sr);
|
118
|
+
|
119
|
+
R_GET_CLASS_DATA("Clangc", SourceLocation, a_source_location, sl);
|
120
|
+
sl->data = clang_getRangeEnd(sr->data);
|
121
|
+
sl->parent = self;
|
122
|
+
return a_source_location;
|
123
|
+
}
|
@@ -0,0 +1,42 @@
|
|
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
|
+
#ifndef SOURCERANGE_H
|
19
|
+
#define SOURCERANGE_H
|
20
|
+
#include <ruby/ruby.h>
|
21
|
+
#include "clang-c/Index.h"
|
22
|
+
typedef struct SourceRange_t
|
23
|
+
{
|
24
|
+
CXSourceRange data;
|
25
|
+
VALUE parent;
|
26
|
+
} SourceRange_t;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
c_SourceRange_struct_alloc(VALUE);
|
30
|
+
|
31
|
+
VALUE
|
32
|
+
c_SourceRange_is_null(VALUE);
|
33
|
+
|
34
|
+
VALUE
|
35
|
+
c_SourceRange_is_equal(VALUE, VALUE);
|
36
|
+
|
37
|
+
VALUE
|
38
|
+
c_SourceRange_get_start(VALUE);
|
39
|
+
|
40
|
+
VALUE
|
41
|
+
c_SourceRange_get_end(VALUE);
|
42
|
+
#endif // SOURCERANGE_H
|
@@ -0,0 +1,457 @@
|
|
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
|
+
/*TranslationUnit ruby class*/
|
19
|
+
#include "class_TranslationUnit.h"
|
20
|
+
#include "class_Diagnostic.h"
|
21
|
+
#include "class_File.h"
|
22
|
+
#include "class_Cursor.h"
|
23
|
+
#include "class_Module.h"
|
24
|
+
#include "class_CodeCompleteResults.h"
|
25
|
+
#include "class_SourceRange.h"
|
26
|
+
#include "macros.h"
|
27
|
+
|
28
|
+
static void c_TranslationUnit_struct_free(TranslationUnit_t *s)
|
29
|
+
{
|
30
|
+
if (s)
|
31
|
+
{
|
32
|
+
|
33
|
+
if (s->data) clang_disposeTranslationUnit(s->data);
|
34
|
+
|
35
|
+
ruby_xfree(s);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
static void c_TranslationUnit_mark(void *s)
|
39
|
+
{
|
40
|
+
if (s)
|
41
|
+
{
|
42
|
+
TranslationUnit_t *t = (TranslationUnit_t *) s;
|
43
|
+
rb_gc_mark(t->parent);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
VALUE
|
48
|
+
c_TranslationUnit_struct_alloc(VALUE klass)
|
49
|
+
{
|
50
|
+
|
51
|
+
TranslationUnit_t *ptr;
|
52
|
+
ptr = (TranslationUnit_t *) ruby_xmalloc(sizeof(TranslationUnit_t));
|
53
|
+
ptr->data = NULL;
|
54
|
+
ptr->parent = Qnil;
|
55
|
+
return Data_Wrap_Struct(klass,
|
56
|
+
c_TranslationUnit_mark,
|
57
|
+
c_TranslationUnit_struct_free,
|
58
|
+
(void *) ptr);
|
59
|
+
}
|
60
|
+
|
61
|
+
/*
|
62
|
+
* call-seq:
|
63
|
+
* Clangc::TranslationUnit#diagnostics_num => num
|
64
|
+
*
|
65
|
+
* Determine the number of diagnostics produced for the given
|
66
|
+
* translation unit.
|
67
|
+
*/
|
68
|
+
VALUE
|
69
|
+
c_TranslationUnit_get_diagnostics_num(VALUE self)
|
70
|
+
{
|
71
|
+
TranslationUnit_t *t;
|
72
|
+
unsigned int num;
|
73
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
74
|
+
|
75
|
+
num = clang_getNumDiagnostics(t->data);
|
76
|
+
return CUINT_2_NUM(num);
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* call-seq:
|
81
|
+
* Clangc::TranslationUnit#default_save_options => num
|
82
|
+
*
|
83
|
+
* Returns the set of flags that is suitable for saving a translation
|
84
|
+
* unit. Those flags should be Clangc::SaveTranslationUnit_Flags constant
|
85
|
+
*
|
86
|
+
* The set of flags returned provide options for Clangc::TranslationUnit#save by
|
87
|
+
* default.
|
88
|
+
* The returned flags set contains an unspecified set of options that save
|
89
|
+
* translation units with
|
90
|
+
* the most commonly-requested data.
|
91
|
+
*/
|
92
|
+
VALUE
|
93
|
+
c_TranslationUnit_get_default_save_options(VALUE self)
|
94
|
+
{
|
95
|
+
TranslationUnit_t *t;
|
96
|
+
unsigned int num;
|
97
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
98
|
+
|
99
|
+
num = clang_defaultSaveOptions(t->data);
|
100
|
+
return CUINT_2_NUM(num);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* call-seq:
|
105
|
+
* Clangc::TranslationUnit#spelling => string
|
106
|
+
*
|
107
|
+
* Get the original translation unit source file name.
|
108
|
+
*/
|
109
|
+
VALUE
|
110
|
+
c_TranslationUnit_get_spelling(VALUE self)
|
111
|
+
{
|
112
|
+
TranslationUnit_t *t;
|
113
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
114
|
+
return CXSTR_2_RVAL(clang_getTranslationUnitSpelling(t->data));
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* call-seq:
|
119
|
+
* Clangc::TranslationUnit#default_reparse_options => num
|
120
|
+
*
|
121
|
+
* Returns the set of flags that is suitable for reparsing a translation
|
122
|
+
* unit.
|
123
|
+
*
|
124
|
+
* The set of flags returned provide options for Clangc::TranslationUnit.reparse
|
125
|
+
* by default. The returned flag set contains an unspecified set of
|
126
|
+
* optimizations
|
127
|
+
* geared toward common uses of reparsing. The set of optimizations enabled may
|
128
|
+
* change from one version to the next. Clangc::ReparseF_Flags constants.
|
129
|
+
*/
|
130
|
+
|
131
|
+
VALUE
|
132
|
+
c_TranslationUnit_get_default_reparse_options(VALUE self)
|
133
|
+
{
|
134
|
+
TranslationUnit_t *t;
|
135
|
+
unsigned int num;
|
136
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
137
|
+
|
138
|
+
num = clang_defaultReparseOptions(t->data);
|
139
|
+
return CUINT_2_NUM(num);
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* call-seq:
|
144
|
+
* Clangc::TranslationUnit#diagnostic(index) => Clangc::Diagnostic
|
145
|
+
*
|
146
|
+
* Retrieve a diagnostic associated with the given translation unit.
|
147
|
+
*
|
148
|
+
* index the zero-based diagnostic number to retrieve.
|
149
|
+
*
|
150
|
+
* returns the requested diagnostic.
|
151
|
+
*/
|
152
|
+
VALUE
|
153
|
+
c_TranslationUnit_get_diagnostic(VALUE self, VALUE num)
|
154
|
+
{
|
155
|
+
TranslationUnit_t *t;
|
156
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
157
|
+
unsigned int max;
|
158
|
+
unsigned int c_num;
|
159
|
+
VALUE diagnostic;
|
160
|
+
|
161
|
+
max = clang_getNumDiagnostics(t->data);
|
162
|
+
c_num = NUM2UINT(num);
|
163
|
+
CHECK_IN_RANGE(c_num, 0, max);
|
164
|
+
Diagnostic_t *d;
|
165
|
+
R_GET_CLASS_DATA("Clangc", Diagnostic, diagnostic, d);
|
166
|
+
d->data = clang_getDiagnostic(t->data, c_num);
|
167
|
+
d->parent = self;
|
168
|
+
return diagnostic;
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* call-seq:
|
173
|
+
* Clangc::TranslationUnit#file(file_name) => clangc::File or nil
|
174
|
+
*
|
175
|
+
* Retrieve a file handle within the given translation unit.
|
176
|
+
* file_name a String for the name of the file.
|
177
|
+
*
|
178
|
+
* it returns the file handle for the named file in the translation unit ,
|
179
|
+
* a nil if the file was not a part of this translation unit.
|
180
|
+
*/
|
181
|
+
VALUE
|
182
|
+
c_TranslationUnit_get_file(VALUE self, VALUE file_name)
|
183
|
+
{
|
184
|
+
TranslationUnit_t *t;
|
185
|
+
CXFile cxfile;
|
186
|
+
char *c_file_name;
|
187
|
+
|
188
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
189
|
+
c_file_name = RSTRING_2_CHAR(file_name);
|
190
|
+
cxfile = clang_getFile(t->data, c_file_name);
|
191
|
+
|
192
|
+
if (cxfile)
|
193
|
+
{
|
194
|
+
VALUE file;
|
195
|
+
File_t *f;
|
196
|
+
R_GET_CLASS_DATA("Clangc", File, file, f);
|
197
|
+
f->data = cxfile;
|
198
|
+
f->parent = self;
|
199
|
+
return file;
|
200
|
+
}
|
201
|
+
else
|
202
|
+
return Qnil;
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* call-seq:
|
207
|
+
* Clangc::TranslationUnit#cursor => Clangc::Cursor
|
208
|
+
*
|
209
|
+
* Retrieve the cursor that represents the given translation unit.
|
210
|
+
*
|
211
|
+
* The translation unit cursor can be used to start traversing the
|
212
|
+
* various declarations within the given translation unit.
|
213
|
+
*/
|
214
|
+
VALUE
|
215
|
+
c_TranslationUnit_get_cursor(VALUE self)
|
216
|
+
{
|
217
|
+
TranslationUnit_t *t;
|
218
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
219
|
+
Cursor_t *c;
|
220
|
+
VALUE a_cursor;
|
221
|
+
R_GET_CLASS_DATA("Clangc", Cursor, a_cursor, c);
|
222
|
+
c->data = clang_getTranslationUnitCursor(t->data);
|
223
|
+
c->parent = self;
|
224
|
+
return a_cursor;
|
225
|
+
}
|
226
|
+
|
227
|
+
/**
|
228
|
+
* call-seq:
|
229
|
+
* Clangc::TranslationUnit#module(Clangc::File) => Clangc::Module
|
230
|
+
*
|
231
|
+
* Given a Clangc::File header file, return the module that contains it, if one
|
232
|
+
* exists.
|
233
|
+
*/
|
234
|
+
VALUE
|
235
|
+
c_TranslationUnit_get_module(VALUE self, VALUE file)
|
236
|
+
{
|
237
|
+
TranslationUnit_t *t;
|
238
|
+
File_t *f;
|
239
|
+
Module_t *m;
|
240
|
+
VALUE module;
|
241
|
+
|
242
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
243
|
+
CHECK_ARG_TYPE(file, File);
|
244
|
+
Data_Get_Struct(file, File_t, f);
|
245
|
+
|
246
|
+
R_GET_CLASS_DATA("Clangc", Module, module, m);
|
247
|
+
m->data = clang_getModuleForFile(t->data, f->data);
|
248
|
+
m->parent = self;
|
249
|
+
|
250
|
+
if (m->data)
|
251
|
+
return module;
|
252
|
+
else
|
253
|
+
return Qnil;
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* call-seq:
|
258
|
+
* Clangc::TranslationUnit#code_complete_at(filename, line, column, options) =>
|
259
|
+
* Clangc::CodeCompleteResults or nil
|
260
|
+
*
|
261
|
+
* Perform code completion at a given location in a translation unit.
|
262
|
+
*
|
263
|
+
* This function performs code completion at a particular file, line, and
|
264
|
+
* column within source code, providing results that suggest potential
|
265
|
+
* code snippets based on the context of the completion. The basic model
|
266
|
+
* for code completion is that Clang will parse a complete source file,
|
267
|
+
* performing syntax checking up to the location where code-completion has
|
268
|
+
* been requested. At that point, a special code-completion token is passed
|
269
|
+
* to the parser, which recognizes this token and determines, based on the
|
270
|
+
* current location in the C/Objective-C/C++ grammar and the state of
|
271
|
+
* semantic analysis, what completions to provide. These completions are
|
272
|
+
* returned via a new Clangc::CodeCompleteResults instantce.
|
273
|
+
*
|
274
|
+
* Code completion itself is meant to be triggered by the client when the
|
275
|
+
* user types punctuation characters or whitespace, at which point the
|
276
|
+
* code-completion location will coincide with the cursor. For example, if \c p
|
277
|
+
* is a pointer, code-completion might be triggered after the "-" and then
|
278
|
+
* after the ">" in \c p->. When the code-completion location is afer the ">",
|
279
|
+
* the completion results will provide, e.g., the members of the struct that
|
280
|
+
* "p" points to. The client is responsible for placing the cursor at the
|
281
|
+
* beginning of the token currently being typed, then filtering the results
|
282
|
+
* based on the contents of the token. For example, when code-completing for
|
283
|
+
* the expression \c p->get, the client should provide the location just after
|
284
|
+
* the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
|
285
|
+
* client can filter the results based on the current token text ("get"), only
|
286
|
+
* showing those results that start with "get". The intent of this interface
|
287
|
+
* is to separate the relatively high-latency acquisition of code-completion
|
288
|
+
* results from the filtering of results on a per-character basis, which must
|
289
|
+
* have a lower latency.
|
290
|
+
*
|
291
|
+
* Self is The translation unit in which code-completion should
|
292
|
+
* occur. The source files for this translation unit need not be
|
293
|
+
* completely up-to-date (and the contents of those source files may
|
294
|
+
* be overridden via \p unsaved_files). Cursors referring into the
|
295
|
+
* translation unit may be invalidated by this invocation.
|
296
|
+
*
|
297
|
+
* The name of the source file where code
|
298
|
+
* completion should be performed. This filename may be any file
|
299
|
+
* included in the translation unit.
|
300
|
+
*
|
301
|
+
* The line at which code-completion should occur.
|
302
|
+
*
|
303
|
+
* The column at which code-completion should occur.
|
304
|
+
* Note that the column should point just after the syntactic construct that
|
305
|
+
* initiated code completion, and not in the middle of a lexical token.
|
306
|
+
*
|
307
|
+
* # TODO unsaved_files (not managed yet) the Tiles that have not yet been saved
|
308
|
+
* to disk
|
309
|
+
* but may be required for parsing or code completion, including the
|
310
|
+
* contents of those files. The contents and name of these files (as
|
311
|
+
* specified by CXUnsavedFile) are copied when necessary, so the
|
312
|
+
* client only needs to guarantee their validity until the call to
|
313
|
+
* this function returns.
|
314
|
+
*
|
315
|
+
* # TODO num_unsaved_files The number of unsaved file entries in \p
|
316
|
+
* unsaved_files.
|
317
|
+
*
|
318
|
+
* Extra options that control the behavior of code
|
319
|
+
* completion, expressed as a bitwise OR of the constants of the
|
320
|
+
* Clangc::CodeComplete_Flags. The
|
321
|
+
* Clangc_default_code_complete_options function returns a default set
|
322
|
+
* of code-completion options.
|
323
|
+
*
|
324
|
+
* \returns If successful, a new \c CXCodeCompleteResults structure
|
325
|
+
* containing code-completion results, which should eventually be
|
326
|
+
* freed with \c clang_disposeCodeCompleteResults(). If code
|
327
|
+
* completion fails, returns NULL.
|
328
|
+
*/
|
329
|
+
VALUE
|
330
|
+
c_TranslationUnit_code_complete_at(
|
331
|
+
VALUE self, VALUE filename, VALUE line, VALUE column, VALUE options)
|
332
|
+
{
|
333
|
+
TranslationUnit_t *t;
|
334
|
+
CodeCompleteResults_t *c;
|
335
|
+
VALUE code_complete_results;
|
336
|
+
char *c_filename;
|
337
|
+
unsigned int c_line;
|
338
|
+
unsigned int c_column;
|
339
|
+
unsigned int c_options;
|
340
|
+
|
341
|
+
c_filename = RSTRING_2_CHAR(filename);
|
342
|
+
c_line = NUM2UINT(line);
|
343
|
+
c_column = NUM2UINT(column);
|
344
|
+
c_options = CLANGC_CONSTANT_TO_UINT("CodeComplete_Flags", options);
|
345
|
+
|
346
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
347
|
+
R_GET_CLASS_DATA("Clangc", CodeCompleteResults, code_complete_results, c);
|
348
|
+
c->data = clang_codeCompleteAt(t->data,
|
349
|
+
c_filename,
|
350
|
+
c_line,
|
351
|
+
c_column,
|
352
|
+
NULL, // TODO Manage unsaved files
|
353
|
+
0,
|
354
|
+
c_options);
|
355
|
+
c->parent = self;
|
356
|
+
|
357
|
+
if (c->data)
|
358
|
+
return code_complete_results;
|
359
|
+
else
|
360
|
+
return Qnil;
|
361
|
+
}
|
362
|
+
|
363
|
+
/**
|
364
|
+
* call-seq:
|
365
|
+
* Clangc::TranslationUnit#reparse(options) => Clangc::ErrorCode
|
366
|
+
*
|
367
|
+
* Reparse the source files that produced this translation unit.
|
368
|
+
*
|
369
|
+
* This routine can be used to re-parse the source files that originally
|
370
|
+
* created the given translation unit, for example because those source files
|
371
|
+
* have changed (either on disk or as passed via \p unsaved_files). The
|
372
|
+
* source code will be reparsed with the same command-line options as it
|
373
|
+
* was originally parsed.
|
374
|
+
*
|
375
|
+
* Reparsing a translation unit invalidates all cursors and source locations
|
376
|
+
* that refer into that translation unit. This makes reparsing a translation
|
377
|
+
* unit semantically equivalent to destroying the translation unit and then
|
378
|
+
* creating a new translation unit with the same command-line arguments.
|
379
|
+
* However, it may be more efficient to reparse a translation
|
380
|
+
* unit using this routine.
|
381
|
+
*
|
382
|
+
* The translation unit whose contents will be re-parsed. The
|
383
|
+
* translation unit must originally have been built with
|
384
|
+
* \c clang_createTranslationUnitFromSourceFile().
|
385
|
+
*
|
386
|
+
* TODO num_unsaved_files The number of unsaved file entries in \p
|
387
|
+
* unsaved_files.
|
388
|
+
*
|
389
|
+
* TODO unsaved_files The files that have not yet been saved to disk
|
390
|
+
* but may be required for parsing, including the contents of
|
391
|
+
* those files. The contents and name of these files (as specified by
|
392
|
+
* CXUnsavedFile) are copied when necessary, so the client only needs to
|
393
|
+
* guarantee their validity until the call to this function returns.
|
394
|
+
*
|
395
|
+
* options A bitset of options composed of the flags in Clangc::Reparse_Flags.
|
396
|
+
* The function Clangc::TranslationUnit.defaultReparseOptions() produces a
|
397
|
+
* default set of
|
398
|
+
* options recommended for most uses, based on the translation unit.
|
399
|
+
*
|
400
|
+
* \returns 0 if the sources could be reparsed. A non-zero error code will be
|
401
|
+
* returned if reparsing was impossible, such that the translation unit is
|
402
|
+
* invalid. The error codes returned by this
|
403
|
+
* routine are described by the Clangc::ErrorCode.
|
404
|
+
*/
|
405
|
+
VALUE
|
406
|
+
c_TranslationUnit_reparse(VALUE self, VALUE options)
|
407
|
+
{
|
408
|
+
TranslationUnit_t *t;
|
409
|
+
int error;
|
410
|
+
unsigned int c_options;
|
411
|
+
|
412
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
413
|
+
c_options = CLANGC_CONSTANT_TO_UINT("Reparse_Flags", options);
|
414
|
+
error = clang_reparseTranslationUnit(t->data,
|
415
|
+
0,
|
416
|
+
NULL, // TODO Manage unsaved files
|
417
|
+
c_options);
|
418
|
+
return CINT_2_NUM(error);
|
419
|
+
}
|
420
|
+
|
421
|
+
/**
|
422
|
+
* call-seq:
|
423
|
+
* Clangc::TranslationUnit#skipped_ranges(cxfile) => Array
|
424
|
+
*
|
425
|
+
* Retrieve all ranges that were skipped by the preprocessor for the Clangc::File
|
426
|
+
* instance.
|
427
|
+
*
|
428
|
+
* The preprocessor will skip lines when they are surrounded by an
|
429
|
+
* if/ifdef/ifndef directive whose condition does not evaluate to true.
|
430
|
+
* It returns an Array of SourceRange.
|
431
|
+
*/
|
432
|
+
VALUE
|
433
|
+
c_TranslationUnit_get_skipped_ranges(VALUE self, VALUE file)
|
434
|
+
{
|
435
|
+
TranslationUnit_t *t;
|
436
|
+
File_t *f;
|
437
|
+
VALUE ret = rb_ary_new();
|
438
|
+
CXSourceRangeList * skipped_ranges_list;
|
439
|
+
int i = 0;
|
440
|
+
|
441
|
+
Data_Get_Struct(self, TranslationUnit_t, t);
|
442
|
+
CHECK_ARG_TYPE(file, File);
|
443
|
+
Data_Get_Struct(file, File_t, f);
|
444
|
+
skipped_ranges_list = clang_getSkippedRanges(t->data, f->data);
|
445
|
+
|
446
|
+
for(i = 0; i < skipped_ranges_list->count; i++)
|
447
|
+
{
|
448
|
+
SourceRange_t * s;
|
449
|
+
VALUE source_range;
|
450
|
+
R_GET_CLASS_DATA("Clangc", SourceRange, source_range, s);
|
451
|
+
s->data = skipped_ranges_list->ranges[i];
|
452
|
+
s->parent = t->data;
|
453
|
+
rb_ary_push(ret, source_range);
|
454
|
+
}
|
455
|
+
clang_disposeSourceRangeList(skipped_ranges_list);
|
456
|
+
return ret;
|
457
|
+
}
|