clangc 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clangc/_clangc_functions.c +303 -0
  3. data/ext/clangc/_clangc_functions.h +51 -0
  4. data/ext/clangc/clangc.c +376 -0
  5. data/ext/clangc/class_CodeCompleteResults.c +186 -0
  6. data/ext/clangc/class_CodeCompleteResults.h +51 -0
  7. data/ext/clangc/class_CompletionResult.c +98 -0
  8. data/ext/clangc/class_CompletionResult.h +36 -0
  9. data/ext/clangc/class_CompletionString.c +231 -0
  10. data/ext/clangc/class_CompletionString.h +57 -0
  11. data/ext/clangc/class_Cursor.c +1677 -0
  12. data/ext/clangc/class_Cursor.h +259 -0
  13. data/ext/clangc/class_CursorSet.c +109 -0
  14. data/ext/clangc/class_CursorSet.h +39 -0
  15. data/ext/clangc/class_Diagnostic.c +322 -0
  16. data/ext/clangc/class_Diagnostic.h +66 -0
  17. data/ext/clangc/class_File.c +145 -0
  18. data/ext/clangc/class_File.h +45 -0
  19. data/ext/clangc/class_Index.c +461 -0
  20. data/ext/clangc/class_Index.h +58 -0
  21. data/ext/clangc/class_Module.c +181 -0
  22. data/ext/clangc/class_Module.h +51 -0
  23. data/ext/clangc/class_OverriddenCursor.c +51 -0
  24. data/ext/clangc/class_OverriddenCursor.h +31 -0
  25. data/ext/clangc/class_SourceLocation.c +197 -0
  26. data/ext/clangc/class_SourceLocation.h +45 -0
  27. data/ext/clangc/class_SourceRange.c +123 -0
  28. data/ext/clangc/class_SourceRange.h +42 -0
  29. data/ext/clangc/class_TranslationUnit.c +457 -0
  30. data/ext/clangc/class_TranslationUnit.h +63 -0
  31. data/ext/clangc/class_Type.c +564 -0
  32. data/ext/clangc/class_Type.h +108 -0
  33. data/ext/clangc/constants.c +660 -0
  34. data/ext/clangc/constants.h +21 -0
  35. data/ext/clangc/extconf.rb +34 -0
  36. data/ext/clangc/macros.h +230 -0
  37. data/lib/clangc.rb +397 -0
  38. metadata +95 -0
@@ -0,0 +1,58 @@
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 INDEX_H
19
+ #define INDEX_H
20
+ #include <ruby/ruby.h>
21
+ #include "clang-c/Index.h"
22
+ typedef struct Index_t
23
+ {
24
+ CXIndex data;
25
+ } Index_t;
26
+
27
+ VALUE
28
+ c_Index_struct_alloc(VALUE);
29
+
30
+ VALUE
31
+ c_Index_initialize(VALUE, VALUE, VALUE);
32
+
33
+ VALUE
34
+ c_Index_set_global_options(VALUE, VALUE);
35
+
36
+ VALUE
37
+ c_Index_get_global_options(VALUE);
38
+
39
+ VALUE
40
+ c_Index_create_TU_from_source_file(VALUE, VALUE, VALUE);
41
+
42
+ VALUE
43
+ c_Index_create_TU(VALUE, VALUE);
44
+
45
+ VALUE
46
+ c_Index_create_TU2(VALUE, VALUE);
47
+
48
+ VALUE
49
+ c_Index_parse_TU(VALUE, VALUE, VALUE, VALUE);
50
+
51
+ VALUE
52
+ c_Index_parse_TU2(VALUE, VALUE, VALUE, VALUE);
53
+
54
+ #if (CINDEX_VERSION_MINOR >= 32)
55
+ VALUE
56
+ c_Index_parse_TU2_full_argv(VALUE, VALUE, VALUE, VALUE);
57
+ #endif
58
+ #endif // INDEX_H
@@ -0,0 +1,181 @@
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
+ /*Module ruby class*/
19
+ #include "class_Module.h"
20
+ #include "class_File.h"
21
+ #include "class_TranslationUnit.h"
22
+ #include "macros.h"
23
+
24
+ static void c_Module_struct_free(Module_t *s)
25
+ {
26
+ if (s)
27
+ {
28
+
29
+ ruby_xfree(s);
30
+ }
31
+ }
32
+
33
+ static void c_Module_mark(void *s)
34
+ {
35
+ if (s)
36
+ {
37
+ Module_t *t = (Module_t *) s;
38
+ rb_gc_mark(t->parent);
39
+ }
40
+ }
41
+
42
+ VALUE
43
+ c_Module_struct_alloc(VALUE klass)
44
+ {
45
+
46
+ Module_t *ptr;
47
+ ptr = (Module_t *) ruby_xmalloc(sizeof(Module_t));
48
+ ptr->data = NULL;
49
+ ptr->parent = Qnil;
50
+
51
+ return Data_Wrap_Struct(klass, NULL, c_Module_struct_free, (void *) ptr);
52
+ }
53
+
54
+ /**
55
+ * call-seq:
56
+ * Clangc::Module#ast_file => CLangc::File or nil
57
+ *
58
+ * Get the module file where the provided module object came from.
59
+ */
60
+ VALUE
61
+ c_Module_get_ast_file(VALUE self)
62
+ {
63
+ Module_t *m;
64
+ Data_Get_Struct(self, Module_t, m);
65
+ VALUE ast_file;
66
+ File_t *f;
67
+ R_GET_CLASS_DATA("Clangc", File, ast_file, f);
68
+ f->data = clang_Module_getASTFile(m->data);
69
+ if (f->data)
70
+ return ast_file;
71
+ else
72
+ return Qnil;
73
+ }
74
+
75
+ /**
76
+ * call-seq:
77
+ * Clangc::Module#parent => Clangc::Module
78
+ *
79
+ * the parent of a sub-module or NULL if the given module is top-level,
80
+ * e.g. for 'std.vector' it will return the 'std' module.
81
+ */
82
+ VALUE
83
+ c_Module_get_parent(VALUE self)
84
+ {
85
+ Module_t *m;
86
+ Data_Get_Struct(self, Module_t, m);
87
+ VALUE parent;
88
+ Module_t *p;
89
+ R_GET_CLASS_DATA("Clangc", Module, parent, p);
90
+ p->data = clang_Module_getParent(m->data);
91
+ return parent;
92
+ }
93
+
94
+ /**
95
+ * call-seq:
96
+ * Clangc::Module#name => String
97
+ *
98
+ * Get the name of the module, e.g. for the 'std.vector' sub-module it
99
+ * will return "vector".
100
+ */
101
+ VALUE
102
+ c_Module_get_name(VALUE self)
103
+ {
104
+ Module_t *m;
105
+ Data_Get_Struct(self, Module_t, m);
106
+ return CXSTR_2_RVAL(clang_Module_getName(m->data));
107
+ }
108
+
109
+ /**
110
+ * call-seq:
111
+ * Clangc::Module#full_name => String
112
+ *
113
+ * Returns the full name of the module, e.g. "std.vector".
114
+ */
115
+ VALUE
116
+ c_Module_get_full_name(VALUE self)
117
+ {
118
+ Module_t *m;
119
+ Data_Get_Struct(self, Module_t, m);
120
+ return CXSTR_2_RVAL(clang_Module_getFullName(m->data));
121
+ }
122
+
123
+ /**
124
+ * call-seq:
125
+ * Clangc::Module#is_system => true/false
126
+ *
127
+ * Returns non-zero if the module is a system one.
128
+ */
129
+ VALUE
130
+ c_Module_is_system(VALUE self)
131
+ {
132
+ Module_t *m;
133
+ Data_Get_Struct(self, Module_t, m);
134
+ return NOT_0_2_RVAL(clang_Module_isSystem(m->data));
135
+ }
136
+
137
+ /**
138
+ * call-seq:
139
+ * Clangc::Module#num_top_level_headers(Clangc::TranslationUnit) => Integer
140
+ *
141
+ * The number of top level headers associated with this module.
142
+ */
143
+ VALUE
144
+ c_Module_get_num_top_level_headers(VALUE self, VALUE translation_unit)
145
+ {
146
+ Module_t *m;
147
+ Data_Get_Struct(self, Module_t, m);
148
+ TranslationUnit_t *t;
149
+ CHECK_ARG_TYPE(translation_unit, TranslationUnit);
150
+ Data_Get_Struct(translation_unit, TranslationUnit_t, t);
151
+
152
+ return CUINT_2_NUM(clang_Module_getNumTopLevelHeaders(t->data, m->data));
153
+ }
154
+
155
+ /**
156
+ * call-seq:
157
+ * Clangc::Module#top_level_header(Clangc::TranslationUnit, Integer) =>
158
+ * Clangc::File
159
+ *
160
+ * Index top level header index (zero-based).
161
+ *
162
+ * Returns the specified top level header associated with the module.
163
+ */
164
+ VALUE
165
+ c_Module_get_top_level_header(VALUE self, VALUE translation_unit, VALUE index)
166
+ {
167
+ Module_t *m;
168
+ Data_Get_Struct(self, Module_t, m);
169
+ TranslationUnit_t *t;
170
+ CHECK_ARG_TYPE(translation_unit, TranslationUnit);
171
+ Data_Get_Struct(translation_unit, TranslationUnit_t, t);
172
+ unsigned int c_index = NUM2UINT(index);
173
+ VALUE header;
174
+ File_t *f;
175
+ R_GET_CLASS_DATA("Clangc", File, header, f);
176
+ f->data = clang_Module_getTopLevelHeader(t->data, m->data, c_index);
177
+ if (f->data)
178
+ return header;
179
+ else
180
+ return Qnil;
181
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * ruby-clangc ruby bindings for the C interface of Clang
3
+ * Copyright (C) 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 MODULE_H
19
+ #define MODULE_H
20
+ #include <ruby/ruby.h>
21
+ #include "clang-c/Index.h"
22
+ typedef struct Module_t
23
+ {
24
+ CXModule data;
25
+ VALUE parent;
26
+ } Module_t;
27
+
28
+ VALUE
29
+ c_Module_struct_alloc(VALUE);
30
+
31
+ VALUE
32
+ c_Module_get_ast_file(VALUE);
33
+
34
+ VALUE
35
+ c_Module_get_parent(VALUE);
36
+
37
+ VALUE
38
+ c_Module_get_name(VALUE);
39
+
40
+ VALUE
41
+ c_Module_get_full_name(VALUE);
42
+
43
+ VALUE
44
+ c_Module_is_system(VALUE);
45
+
46
+ VALUE
47
+ c_Module_get_num_top_level_headers(VALUE, VALUE);
48
+
49
+ VALUE
50
+ c_Module_get_top_level_header(VALUE, VALUE, VALUE);
51
+ #endif // MODULE_H
@@ -0,0 +1,51 @@
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
+ /*Cursor ruby class*/
19
+ #include "class_OverriddenCursor.h"
20
+ #include "macros.h"
21
+
22
+ static void c_OverriddenCursor_struct_free(OverriddenCursor_t *s)
23
+ {
24
+ if (s)
25
+ {
26
+ if (s->ptr) clang_disposeOverriddenCursors(s->ptr);
27
+
28
+ ruby_xfree(s);
29
+ }
30
+ }
31
+
32
+ static void c_OverriddenCursor_mark(void *s)
33
+ {
34
+ if (s)
35
+ {
36
+ OverriddenCursor_t *t = (OverriddenCursor_t *) s;
37
+ rb_gc_mark(t->parent);
38
+ }
39
+ }
40
+
41
+ VALUE
42
+ c_OverriddenCursor_struct_alloc(VALUE klass)
43
+ {
44
+
45
+ OverriddenCursor_t *ptr;
46
+ ptr = (OverriddenCursor_t *) ruby_xmalloc(sizeof(OverriddenCursor_t));
47
+ ptr->parent = Qnil;
48
+
49
+ return Data_Wrap_Struct(
50
+ klass, NULL, c_OverriddenCursor_struct_free, (void *) ptr);
51
+ }
@@ -0,0 +1,31 @@
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 OVERRIDDEN_CURSOR_H
19
+ #define OVERRIDDEN_CURSOR_H
20
+ #include <ruby/ruby.h>
21
+ #include "clang-c/Index.h"
22
+ typedef struct OverriddenCursor_t
23
+ {
24
+ CXCursor data;
25
+ CXCursor *ptr;
26
+ VALUE parent;
27
+ } OverriddenCursor_t;
28
+
29
+ VALUE
30
+ c_OverriddenCursor_struct_alloc(VALUE);
31
+ #endif // OVERRIDDEN_CURSOR_H
@@ -0,0 +1,197 @@
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
+ /*SourceLocation ruby class*/
19
+ #include "class_SourceLocation.h"
20
+ #include "class_File.h"
21
+ #include "macros.h"
22
+
23
+ static void c_SourceLocation_struct_free(SourceLocation_t *s)
24
+ {
25
+ if (s)
26
+ {
27
+
28
+ ruby_xfree(s);
29
+ }
30
+ }
31
+
32
+ static void c_SourceLocation_mark(void *s)
33
+ {
34
+ if (s)
35
+ {
36
+ SourceLocation_t *t = (SourceLocation_t *) s;
37
+ rb_gc_mark(t->parent);
38
+ }
39
+ }
40
+
41
+ VALUE
42
+ c_SourceLocation_struct_alloc(VALUE klass)
43
+ {
44
+
45
+ return Data_Wrap_Struct(klass,
46
+ NULL,
47
+ c_SourceLocation_struct_free,
48
+ ruby_xmalloc(sizeof(SourceLocation_t)));
49
+ }
50
+
51
+ /**
52
+ * call-seq:
53
+ * Clangc::SourceLocation#is_in_system_header => true
54
+ *
55
+ * Returns true if the given source location is in a system header.
56
+ */
57
+ VALUE
58
+ c_SourceLocation_is_in_system_header(VALUE self)
59
+ {
60
+ SourceLocation_t *s;
61
+ Data_Get_Struct(self, SourceLocation_t, s);
62
+ return NOT_0_2_RVAL(clang_Location_isInSystemHeader(s->data));
63
+ }
64
+
65
+ /**
66
+ * call-seq:
67
+ * Clangc::SourceLocation#is_from_main_file => true
68
+ *
69
+ * Returns true if the given source location is in the main file of
70
+ * the corresponding translation unit.
71
+ */
72
+ VALUE
73
+ c_SourceLocation_is_from_main_file(VALUE self)
74
+ {
75
+ SourceLocation_t *s;
76
+ Data_Get_Struct(self, SourceLocation_t, s);
77
+ return NOT_0_2_RVAL(clang_Location_isFromMainFile(s->data));
78
+ }
79
+
80
+ /**
81
+ * call-seq:
82
+ * Clangc::SourceLocation#equal(Clangc::SourceLocation) => true /false
83
+ *
84
+ * Determine whether two source locations, which must refer into
85
+ * the same translation unit, refer to exactly the same point in the source
86
+ * code.
87
+ *
88
+ * true if the source locations refer to the same location, false
89
+ * if they refer to different locations.
90
+ */
91
+ VALUE
92
+ c_SourceLocation_is_equal(VALUE self, VALUE source_location)
93
+ {
94
+ SourceLocation_t *s;
95
+ SourceLocation_t *sl;
96
+ Data_Get_Struct(self, SourceLocation_t, s);
97
+ CHECK_ARG_TYPE(source_location, SourceLocation);
98
+ Data_Get_Struct(source_location, SourceLocation_t, sl);
99
+
100
+ return NOT_0_2_RVAL(clang_equalLocations(s->data, sl->data));
101
+ }
102
+
103
+ /**
104
+ * call-seq:
105
+ * Clangc::SourceLocation#spelling => Array
106
+ *
107
+ * Retrieve the file, line, column, and offset represented by
108
+ * the given source location.
109
+ *
110
+ * If the location refers into a macro instantiation, return where the
111
+ * location was originally spelled in the source file.
112
+ *
113
+ * The returned array contains four values:
114
+ *
115
+ * array[0] will be set to the file to which the given
116
+ * source location points.(Clangc::File)
117
+ *
118
+ * array[1] will be set to the line to which the given
119
+ * source location points.
120
+ *
121
+ * array[2] will be set to the column to which the given
122
+ * source location points.
123
+ *
124
+ * array[3] will be set to the offset into the
125
+ * buffer to which the given source location points. (the position
126
+ * in the file)
127
+ */
128
+ VALUE c_SourceLocation_get_spelling(VALUE self)
129
+ {
130
+ VALUE ret = rb_ary_new();
131
+ SourceLocation_t *s;
132
+ Data_Get_Struct(self, SourceLocation_t, s);
133
+ CXFile cxf = NULL;
134
+ unsigned int line = 0;
135
+ unsigned int column = 0;
136
+ unsigned int offset = 0;
137
+ clang_getSpellingLocation(s->data, &cxf, &line, &column, &offset);
138
+ VALUE file;
139
+ File_t *f;
140
+ R_GET_CLASS_DATA("Clangc", File, file, f);
141
+ f->data = cxf;
142
+ f->parent = self;
143
+ rb_ary_push(ret, file);
144
+ rb_ary_push(ret, CUINT_2_NUM(line));
145
+ rb_ary_push(ret, CUINT_2_NUM(column));
146
+ rb_ary_push(ret, CUINT_2_NUM(offset));
147
+
148
+ return ret;
149
+ }
150
+ /**
151
+ * call-seq:
152
+ * Clangc::SourceLocation#file_location => Array
153
+ *
154
+ * Retrieve the file, line, column, and offset represented by
155
+ * the given source location.
156
+ *
157
+ * If the location refers into a macro instantiation, return where the
158
+ * location was originally spelled in the source file.
159
+ *
160
+ * The returned array contains four values:
161
+ *
162
+ * array[0] will be set to the file to which the given
163
+ * source location points.(Clangc::File)
164
+ *
165
+ * array[1] will be set to the line to which the given
166
+ * source location points.
167
+ *
168
+ * array[2] will be set to the column to which the given
169
+ * source location points.
170
+ *
171
+ * array[3] will be set to the offset into the
172
+ * buffer to which the given source location points. (the position
173
+ * in the file)
174
+ */
175
+ VALUE c_SourceLocation_get_file_location(VALUE self)
176
+ {
177
+ VALUE ret = rb_ary_new();
178
+ SourceLocation_t *s;
179
+ Data_Get_Struct(self, SourceLocation_t, s);
180
+ CXFile cxf = NULL;
181
+ unsigned int line;
182
+ unsigned int column;
183
+ unsigned int offset;
184
+ clang_getFileLocation(s->data, &cxf, &line, &column, &offset);
185
+
186
+ VALUE file;
187
+ File_t *f;
188
+ R_GET_CLASS_DATA("Clangc", File, file, f);
189
+ f->data = cxf;
190
+ f->parent = self;
191
+ rb_ary_push(ret, file);
192
+ rb_ary_push(ret, CUINT_2_NUM(line));
193
+ rb_ary_push(ret, CUINT_2_NUM(column));
194
+ rb_ary_push(ret, CUINT_2_NUM(offset));
195
+
196
+ return ret;
197
+ }