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,66 @@
|
|
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 DIAGNOSTIC_H
|
19
|
+
#define DIAGNOSTIC_H
|
20
|
+
#include <ruby/ruby.h>
|
21
|
+
#include "clang-c/Index.h"
|
22
|
+
typedef struct Diagnostic_t
|
23
|
+
{
|
24
|
+
CXDiagnostic data;
|
25
|
+
VALUE parent;
|
26
|
+
} Diagnostic_t;
|
27
|
+
|
28
|
+
VALUE
|
29
|
+
c_Diagnostic_struct_alloc(VALUE);
|
30
|
+
|
31
|
+
VALUE
|
32
|
+
c_Diagnostic_get_severity(VALUE);
|
33
|
+
|
34
|
+
VALUE
|
35
|
+
c_Diagnostic_get_spelling(VALUE);
|
36
|
+
|
37
|
+
VALUE
|
38
|
+
c_Diagnostic_get_category(VALUE);
|
39
|
+
|
40
|
+
VALUE
|
41
|
+
c_Diagnostic_get_category_name(VALUE);
|
42
|
+
|
43
|
+
VALUE
|
44
|
+
c_Diagnostic_get_category_text(VALUE);
|
45
|
+
|
46
|
+
VALUE
|
47
|
+
c_Diagnostic_get_num_ranges(VALUE);
|
48
|
+
|
49
|
+
VALUE
|
50
|
+
c_Diagnostic_get_num_fixits(VALUE);
|
51
|
+
|
52
|
+
VALUE
|
53
|
+
c_Diagnostic_format(VALUE, VALUE);
|
54
|
+
|
55
|
+
VALUE
|
56
|
+
c_Diagnostic_get_option(VALUE);
|
57
|
+
|
58
|
+
VALUE
|
59
|
+
c_Diagnostic_get_source_range(VALUE, VALUE);
|
60
|
+
|
61
|
+
VALUE
|
62
|
+
c_Diagnostic_get_source_location(VALUE);
|
63
|
+
|
64
|
+
VALUE
|
65
|
+
c_Diagnostic_get_fixit(VALUE, VALUE);
|
66
|
+
#endif // DIAGNOSTIC_H
|
@@ -0,0 +1,145 @@
|
|
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
|
+
/*File ruby class*/
|
19
|
+
#include "class_File.h"
|
20
|
+
#include "macros.h"
|
21
|
+
#include "class_TranslationUnit.h"
|
22
|
+
|
23
|
+
static void c_File_struct_free(File_t *s)
|
24
|
+
{
|
25
|
+
if (s)
|
26
|
+
{
|
27
|
+
|
28
|
+
ruby_xfree(s);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
static void c_File_mark(void *s)
|
33
|
+
{
|
34
|
+
if (s)
|
35
|
+
{
|
36
|
+
File_t *t = (File_t *) s;
|
37
|
+
rb_gc_mark(t->parent);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE
|
42
|
+
c_File_struct_alloc(VALUE klass)
|
43
|
+
{
|
44
|
+
|
45
|
+
File_t *ptr;
|
46
|
+
ptr = (File_t *) ruby_xmalloc(sizeof(File_t));
|
47
|
+
ptr->data = NULL;
|
48
|
+
ptr->parent = Qnil;
|
49
|
+
return Data_Wrap_Struct(
|
50
|
+
klass, c_File_mark, c_File_struct_free, (void *) ptr);
|
51
|
+
}
|
52
|
+
|
53
|
+
VALUE
|
54
|
+
generate_File_under(VALUE module, VALUE superclass)
|
55
|
+
{
|
56
|
+
VALUE klass = rb_define_class_under(module, "File", superclass);
|
57
|
+
rb_define_alloc_func(klass, c_File_struct_alloc);
|
58
|
+
return klass;
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* call-seq:
|
63
|
+
* Clangc::File#name => String
|
64
|
+
*
|
65
|
+
* Retrieve the complete file and path name of the given file.
|
66
|
+
* Returns Qnil if the CXFile pointer is NULL (this can happen)
|
67
|
+
*/
|
68
|
+
VALUE
|
69
|
+
c_File_get_name(VALUE self)
|
70
|
+
{
|
71
|
+
File_t *f;
|
72
|
+
VALUE name = Qnil;
|
73
|
+
Data_Get_Struct(self, File_t, f);
|
74
|
+
if (f->data != NULL)
|
75
|
+
{
|
76
|
+
name = CXSTR_2_RVAL(clang_getFileName(f->data));
|
77
|
+
}
|
78
|
+
else
|
79
|
+
name = Qnil;
|
80
|
+
return name;
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* call-seq:
|
85
|
+
* Clangc::File#mtime => Time
|
86
|
+
*
|
87
|
+
* Retrieve the last modification time of the given file.
|
88
|
+
*/
|
89
|
+
|
90
|
+
VALUE
|
91
|
+
c_File_get_mtime(VALUE self)
|
92
|
+
{
|
93
|
+
File_t *f;
|
94
|
+
VALUE mtime = Qnil;
|
95
|
+
Data_Get_Struct(self, File_t, f);
|
96
|
+
mtime = rb_time_new(clang_getFileTime(f->data), 0);
|
97
|
+
return mtime;
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* call-seq:
|
102
|
+
* Clangc::File#is_multiple_include_guarded => true or false
|
103
|
+
*
|
104
|
+
* Determine whether the given header is guarded against
|
105
|
+
* multiple inclusions, either with the conventional
|
106
|
+
* \#ifndef/\#define/\#endif macro guards or with \#pragma once.
|
107
|
+
*/
|
108
|
+
|
109
|
+
VALUE
|
110
|
+
c_File_is_multiple_include_guarded(VALUE self)
|
111
|
+
{
|
112
|
+
File_t *f;
|
113
|
+
Data_Get_Struct(self, File_t, f);
|
114
|
+
TranslationUnit_t *t;
|
115
|
+
Data_Get_Struct(f->parent, TranslationUnit_t, t);
|
116
|
+
unsigned int ret = clang_isFileMultipleIncludeGuarded(t->data, f->data);
|
117
|
+
return NOT_0_2_RVAL(ret);
|
118
|
+
}
|
119
|
+
|
120
|
+
#if (CINDEX_VERSION_MINOR >= 29)
|
121
|
+
/**
|
122
|
+
* call-seq:
|
123
|
+
* clangc::File#is_equal(file) => true or false
|
124
|
+
*
|
125
|
+
* Returns true if the file1 and file2 point to the same file,
|
126
|
+
* or both null.
|
127
|
+
* Two ruby objects Clangc::File can be different but can hold the
|
128
|
+
* same File_t data.
|
129
|
+
*/
|
130
|
+
|
131
|
+
VALUE
|
132
|
+
c_File_is_equal(VALUE self, VALUE file)
|
133
|
+
{
|
134
|
+
File_t *f1;
|
135
|
+
File_t *f2;
|
136
|
+
Data_Get_Struct(self, File_t, f1);
|
137
|
+
CHECK_ARG_TYPE(file, File);
|
138
|
+
Data_Get_Struct(file, File_t, f2);
|
139
|
+
return NOT_0_2_RVAL(clang_File_isEqual(f1->data, f2->data));
|
140
|
+
}
|
141
|
+
#endif
|
142
|
+
|
143
|
+
/*
|
144
|
+
* skipped :
|
145
|
+
* clang_getFileUniqueID*/
|
@@ -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 FILE_H
|
19
|
+
#define FILE_H
|
20
|
+
#include <ruby/ruby.h>
|
21
|
+
#include "clang-c/Index.h"
|
22
|
+
typedef struct File_t
|
23
|
+
{
|
24
|
+
CXFile data;
|
25
|
+
VALUE parent; // A translation unit ( a CXFile is a file related to a
|
26
|
+
// translation unit)
|
27
|
+
} File_t;
|
28
|
+
|
29
|
+
VALUE
|
30
|
+
c_File_struct_alloc(VALUE);
|
31
|
+
|
32
|
+
VALUE
|
33
|
+
c_File_get_name(VALUE);
|
34
|
+
|
35
|
+
VALUE
|
36
|
+
c_File_get_mtime(VALUE);
|
37
|
+
|
38
|
+
VALUE
|
39
|
+
c_File_is_multiple_include_guarded(VALUE);
|
40
|
+
|
41
|
+
#if (CINDEX_VERSION_MINOR >= 29)
|
42
|
+
VALUE
|
43
|
+
c_File_is_equal(VALUE, VALUE);
|
44
|
+
#endif
|
45
|
+
#endif // FILE_H
|
@@ -0,0 +1,461 @@
|
|
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
|
+
/*Index ruby class*/
|
19
|
+
#include "class_Index.h"
|
20
|
+
#include "class_TranslationUnit.h"
|
21
|
+
#include "stdio.h"
|
22
|
+
#include "macros.h"
|
23
|
+
|
24
|
+
static void c_Index_struct_free(Index_t *s)
|
25
|
+
{
|
26
|
+
if (s)
|
27
|
+
{
|
28
|
+
if (s->data) clang_disposeIndex(s->data);
|
29
|
+
|
30
|
+
ruby_xfree(s);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE
|
35
|
+
c_Index_struct_alloc(VALUE klass)
|
36
|
+
{
|
37
|
+
Index_t *i;
|
38
|
+
i = (Index_t *) ruby_xmalloc(sizeof(Index_t));
|
39
|
+
i->data = NULL;
|
40
|
+
return Data_Wrap_Struct(klass, NULL, c_Index_struct_free, (void *) i);
|
41
|
+
}
|
42
|
+
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* Clangc::Index.new(exclude_decl_from_pch, display_diagnostics) =>
|
46
|
+
* Clangc::Index
|
47
|
+
*
|
48
|
+
* Provides a shared context for creating translation units.
|
49
|
+
*
|
50
|
+
* It provides two options:
|
51
|
+
*
|
52
|
+
* - excludeDeclarationsFromPCH:
|
53
|
+
* When true, allows enumeration of "local"
|
54
|
+
* declarations (when loading any new translation units). A "local" declaration
|
55
|
+
* is one that belongs in the translation unit itself and not in a precompiled
|
56
|
+
* header that was used by the translation unit. If false, all declarations
|
57
|
+
* will be enumerated.
|
58
|
+
* The process of creating the 'pch', loading it separately, and using it (via
|
59
|
+
* -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
|
60
|
+
* (which gives the indexer the same performance benefit as the compiler).
|
61
|
+
*
|
62
|
+
* - displayDiagnostics:
|
63
|
+
* When true, default diagnostics are displayed, when false, it is up to the user
|
64
|
+
* to display them.
|
65
|
+
*/
|
66
|
+
VALUE
|
67
|
+
c_Index_initialize(VALUE self,
|
68
|
+
VALUE excl_decls_from_PCH,
|
69
|
+
VALUE display_diagnostics)
|
70
|
+
{
|
71
|
+
Index_t *i;
|
72
|
+
int c_excl_decls_from_PCH;
|
73
|
+
int c_display_diagnostics;
|
74
|
+
|
75
|
+
c_excl_decls_from_PCH = RBOOL_2_INT(excl_decls_from_PCH);
|
76
|
+
c_display_diagnostics = RBOOL_2_INT(display_diagnostics);
|
77
|
+
Data_Get_Struct(self, Index_t, i);
|
78
|
+
|
79
|
+
i->data = clang_createIndex(c_excl_decls_from_PCH, c_display_diagnostics);
|
80
|
+
return self;
|
81
|
+
}
|
82
|
+
|
83
|
+
/*
|
84
|
+
* call-seq:
|
85
|
+
* Clangc::Index#global_options=(options) => nil
|
86
|
+
*
|
87
|
+
* Sets general options associated with an Index instance.
|
88
|
+
* - options:
|
89
|
+
* A bitmask of options, a bitwise OR of the Clangc::GlobalOptFlags constants.
|
90
|
+
*/
|
91
|
+
VALUE
|
92
|
+
c_Index_set_global_options(VALUE self, VALUE options)
|
93
|
+
{
|
94
|
+
Index_t *i;
|
95
|
+
unsigned int c_options;
|
96
|
+
|
97
|
+
Data_Get_Struct(self, Index_t, i);
|
98
|
+
c_options = CLANGC_CONSTANT_TO_UINT("GlobalOptFlags", options);
|
99
|
+
clang_CXIndex_setGlobalOptions(i->data, c_options);
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* call-seq:
|
105
|
+
* Clangc::Index#global_options() => num
|
106
|
+
*
|
107
|
+
* Gets the general options associated with an Index.
|
108
|
+
* A bitmask of options, a bitwise OR of the Clangc::GlobalOptFlags constants.
|
109
|
+
*/
|
110
|
+
VALUE
|
111
|
+
c_Index_get_global_options(VALUE self)
|
112
|
+
{
|
113
|
+
Index_t *i;
|
114
|
+
Data_Get_Struct(self, Index_t, i);
|
115
|
+
return CUINT_2_NUM(clang_CXIndex_getGlobalOptions(i->data));
|
116
|
+
}
|
117
|
+
/*
|
118
|
+
* call-seq:
|
119
|
+
* Clangc::Index#create_translation_unit_from_source_file(source, args) =>
|
120
|
+
* Clangc::TranslationUnit
|
121
|
+
*
|
122
|
+
* Return a TranslationUnit instance for a given source file and the provided
|
123
|
+
* command line arguments one would pass to the compiler.
|
124
|
+
*
|
125
|
+
* - source:
|
126
|
+
* The source filename argument must be a string but is optional. If the caller
|
127
|
+
* provides a nil value, the name of the source file is expected to reside in the
|
128
|
+
* specified command line arguments.
|
129
|
+
* - args:
|
130
|
+
* Must be an array of strings or empty.
|
131
|
+
* The command-line arguments that would be passed to the clang executable if it
|
132
|
+
* were being invoked out-of-process.
|
133
|
+
* These command-line options will be parsed and will affect how the translation
|
134
|
+
* unit is parsed. Note that the following options are ignored: '-c',
|
135
|
+
* '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
|
136
|
+
*
|
137
|
+
* TODO : (not implemented yet)
|
138
|
+
* - num_unsaved_files
|
139
|
+
* the number of unsaved file entries in unsaved_files.
|
140
|
+
*
|
141
|
+
* - unsaved_files
|
142
|
+
* the files that have not yet been saved to disk but may be required
|
143
|
+
* for code completion, including the contents of those files. The contents and
|
144
|
+
* name
|
145
|
+
* of these files (as specified by CXUnsavedFile) are copied when necessary, so
|
146
|
+
* the
|
147
|
+
* client only needs to guarantee their validity until the call to this function
|
148
|
+
* returns.
|
149
|
+
*/
|
150
|
+
|
151
|
+
VALUE
|
152
|
+
c_Index_create_TU_from_source_file(VALUE self, VALUE source_file, VALUE args)
|
153
|
+
{
|
154
|
+
char *c_source_file = NULL;
|
155
|
+
Index_t *i;
|
156
|
+
VALUE tu;
|
157
|
+
TranslationUnit_t *c_tu;
|
158
|
+
|
159
|
+
c_source_file = RSTRING_2_CHAR(source_file);
|
160
|
+
RARRAY_OF_STRINGS_2_C(args);
|
161
|
+
Data_Get_Struct(self, Index_t, i);
|
162
|
+
R_GET_CLASS_DATA("Clangc", TranslationUnit, tu, c_tu);
|
163
|
+
|
164
|
+
c_tu->data = clang_createTranslationUnitFromSourceFile(
|
165
|
+
i->data, c_source_file, len, c_args, 0, 0); // TODO manage unsaved files
|
166
|
+
c_tu->parent = self;
|
167
|
+
|
168
|
+
if (c_tu->data != NULL)
|
169
|
+
return tu;
|
170
|
+
else
|
171
|
+
return Qnil;
|
172
|
+
}
|
173
|
+
/*
|
174
|
+
* call-seq:
|
175
|
+
* Clangc::Index#create_translation_unit(ast_file) => Clangc::TranslationUnit
|
176
|
+
*
|
177
|
+
* Create a translation unit from an AST file name. If the creation fail, it
|
178
|
+
* returns
|
179
|
+
* nil.
|
180
|
+
* The AST file is created by clang with the option -emit-ast
|
181
|
+
*/
|
182
|
+
VALUE
|
183
|
+
c_Index_create_TU(VALUE self, VALUE ast_file)
|
184
|
+
{
|
185
|
+
Index_t *i;
|
186
|
+
Data_Get_Struct(self, Index_t, i);
|
187
|
+
VALUE tu;
|
188
|
+
TranslationUnit_t *c_tu;
|
189
|
+
R_GET_CLASS_DATA("Clangc", TranslationUnit, tu, c_tu);
|
190
|
+
char *c_ast_file = NULL;
|
191
|
+
c_ast_file = RSTRING_2_CHAR(ast_file);
|
192
|
+
c_tu->data = clang_createTranslationUnit(i->data, c_ast_file);
|
193
|
+
|
194
|
+
c_tu->parent = self;
|
195
|
+
|
196
|
+
if (c_tu->data)
|
197
|
+
return tu;
|
198
|
+
else
|
199
|
+
return Qnil;
|
200
|
+
}
|
201
|
+
/*
|
202
|
+
* call-seq:
|
203
|
+
* Clangc::Index#create_translation_unit2(ast_file) => Clangc::TranslationUnit
|
204
|
+
* or an error code
|
205
|
+
*
|
206
|
+
* Create a translation unit from an AST file name. If the creation fail, it
|
207
|
+
* returns
|
208
|
+
* an error code Clangc::ErrorCode. With this implementation,
|
209
|
+
* Clangc::ErrorCode::Success is not
|
210
|
+
* used.
|
211
|
+
* The AST file is created by clang with the option -emit-ast
|
212
|
+
*/
|
213
|
+
VALUE
|
214
|
+
c_Index_create_TU2(VALUE self, VALUE ast_file)
|
215
|
+
{
|
216
|
+
Index_t *i;
|
217
|
+
Data_Get_Struct(self, Index_t, i);
|
218
|
+
VALUE tu;
|
219
|
+
TranslationUnit_t *c_tu;
|
220
|
+
R_GET_CLASS_DATA("Clangc", TranslationUnit, tu, c_tu);
|
221
|
+
char *c_ast_file = NULL;
|
222
|
+
c_ast_file = RSTRING_2_CHAR(ast_file);
|
223
|
+
unsigned int er =
|
224
|
+
clang_createTranslationUnit2(i->data, c_ast_file, &(c_tu->data));
|
225
|
+
|
226
|
+
c_tu->parent = self;
|
227
|
+
|
228
|
+
if (er != 0)
|
229
|
+
return CUINT_2_NUM(er);
|
230
|
+
else
|
231
|
+
return tu;
|
232
|
+
}
|
233
|
+
/*
|
234
|
+
* call-seq:
|
235
|
+
* Clangc::Index#parse_translation_unit(source_file, args, options) =>
|
236
|
+
* Clangc::TranslationUnit
|
237
|
+
*
|
238
|
+
* Parse the given source file and generate the translation unit corresponding
|
239
|
+
* to that file.
|
240
|
+
*
|
241
|
+
* This routine is the main entry point for the Clang C API, providing the
|
242
|
+
* ability to parse a source file into a translation unit that can then be
|
243
|
+
* queried by other functions in the API. This routine accepts a set of
|
244
|
+
* command-line arguments so that the compilation can be configured in the same
|
245
|
+
* way that the compiler is configured on the command line.
|
246
|
+
*
|
247
|
+
* - source_file:
|
248
|
+
* The name of the source file to load, or nil if the source file is included in
|
249
|
+
* the command line arguments.
|
250
|
+
*
|
251
|
+
* - args:
|
252
|
+
* The command-line arguments that would be passed to the clang executable if it
|
253
|
+
* were being invoked out-of-process.
|
254
|
+
* These command-line options will be parsed and will affect how the translation
|
255
|
+
* unit is parsed. Note that the following options are ignored: '-c',
|
256
|
+
* '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
|
257
|
+
*
|
258
|
+
* - options:
|
259
|
+
* A bitmask of options that affects how the translation unit is managed but not
|
260
|
+
* its compilation. This should be a bitwise OR of the TranslationUnit_Flags
|
261
|
+
* constants.
|
262
|
+
*
|
263
|
+
* TODO:
|
264
|
+
* - unsaved_files:
|
265
|
+
* The files that have not yet been saved to disk but may be required for
|
266
|
+
* parsing,
|
267
|
+
* including the contents of those files. The contents and name of these files
|
268
|
+
* (as specified by CXUnsavedFile) are copied when necessary, so the client only
|
269
|
+
* needs to guarantee their validity until the call to this function returns.
|
270
|
+
*
|
271
|
+
* - num_unsaved_files:
|
272
|
+
* The number of unsaved file entries in unsaved_files.
|
273
|
+
*/
|
274
|
+
VALUE
|
275
|
+
c_Index_parse_TU(VALUE self, VALUE source_file, VALUE args, VALUE options)
|
276
|
+
{
|
277
|
+
char *c_source_file = NULL;
|
278
|
+
c_source_file = RSTRING_2_CHAR(source_file);
|
279
|
+
|
280
|
+
unsigned int c_options = CLANGC_CONSTANT_TO_UINT("TranslationUnit_Flags",
|
281
|
+
options);
|
282
|
+
|
283
|
+
RARRAY_OF_STRINGS_2_C(args);
|
284
|
+
Index_t *i;
|
285
|
+
Data_Get_Struct(self, Index_t, i);
|
286
|
+
VALUE tu;
|
287
|
+
TranslationUnit_t *c_tu;
|
288
|
+
R_GET_CLASS_DATA("Clangc", TranslationUnit, tu, c_tu);
|
289
|
+
|
290
|
+
c_tu->data =
|
291
|
+
clang_parseTranslationUnit(i->data,
|
292
|
+
c_source_file,
|
293
|
+
c_args,
|
294
|
+
len,
|
295
|
+
0,
|
296
|
+
0,
|
297
|
+
c_options); // TODO manage unsaved files
|
298
|
+
|
299
|
+
c_tu->parent = self;
|
300
|
+
|
301
|
+
if (c_tu->data)
|
302
|
+
return tu;
|
303
|
+
else
|
304
|
+
return Qnil;
|
305
|
+
}
|
306
|
+
/*
|
307
|
+
* call-seq:
|
308
|
+
* Clangc::Index#parse_translation_unit2(source_file, args, options) =>
|
309
|
+
* Clangc::TranslationUnit
|
310
|
+
*
|
311
|
+
* Parse the given source file and generate the translation unit corresponding
|
312
|
+
* to that file. If its fails, it returns an Integer corresponding to the
|
313
|
+
* error code a Clangc::ErrorCode constant.
|
314
|
+
*
|
315
|
+
* This routine is the main entry point for the Clang C API, providing the
|
316
|
+
* ability to parse a source file into a translation unit that can then be
|
317
|
+
* queried by other functions in the API. This routine accepts a set of
|
318
|
+
* command-line arguments so that the compilation can be configured in the same
|
319
|
+
* way that the compiler is configured on the command line.
|
320
|
+
*
|
321
|
+
* - source_file:
|
322
|
+
* The name of the source file to load, or nil if the source file is included in
|
323
|
+
* the command line arguments.
|
324
|
+
*
|
325
|
+
* - args:
|
326
|
+
* The command-line arguments that would be passed to the clang executable if it
|
327
|
+
* were being invoked out-of-process.
|
328
|
+
* These command-line options will be parsed and will affect how the translation
|
329
|
+
* unit is parsed. Note that the following options are ignored: '-c',
|
330
|
+
* '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
|
331
|
+
*
|
332
|
+
* - options:
|
333
|
+
* A bitmask of options that affects how the translation unit is managed but not
|
334
|
+
* its compilation. This should be a bitwise OR of the TranslationUnit_Flags
|
335
|
+
* constants.
|
336
|
+
*
|
337
|
+
* TODO:
|
338
|
+
* - unsaved_files:
|
339
|
+
* The files that have not yet been saved to disk but may be required for
|
340
|
+
* parsing,
|
341
|
+
* including the contents of those files. The contents and name of these files
|
342
|
+
* (as specified by CXUnsavedFile) are copied when necessary, so the client only
|
343
|
+
* needs to guarantee their validity until the call to this function returns.
|
344
|
+
*
|
345
|
+
* - num_unsaved_files:
|
346
|
+
* The number of unsaved file entries in unsaved_files.
|
347
|
+
*/
|
348
|
+
VALUE
|
349
|
+
c_Index_parse_TU2(VALUE self, VALUE source_file, VALUE args, VALUE options)
|
350
|
+
{
|
351
|
+
char *c_source_file = NULL;
|
352
|
+
c_source_file = RSTRING_2_CHAR(source_file);
|
353
|
+
|
354
|
+
unsigned int c_options = CLANGC_CONSTANT_TO_UINT("TranslationUnit_Flags",
|
355
|
+
options);
|
356
|
+
|
357
|
+
RARRAY_OF_STRINGS_2_C(args);
|
358
|
+
Index_t *i;
|
359
|
+
Data_Get_Struct(self, Index_t, i);
|
360
|
+
VALUE tu;
|
361
|
+
TranslationUnit_t *c_tu;
|
362
|
+
R_GET_CLASS_DATA("Clangc", TranslationUnit, tu, c_tu);
|
363
|
+
|
364
|
+
unsigned int er =
|
365
|
+
clang_parseTranslationUnit2(i->data,
|
366
|
+
c_source_file,
|
367
|
+
c_args,
|
368
|
+
len,
|
369
|
+
0,
|
370
|
+
0,
|
371
|
+
c_options, // TODO manage unsaved files
|
372
|
+
&(c_tu->data));
|
373
|
+
|
374
|
+
c_tu->parent = self;
|
375
|
+
|
376
|
+
if (er != 0)
|
377
|
+
return CUINT_2_NUM(er);
|
378
|
+
else
|
379
|
+
return tu;
|
380
|
+
}
|
381
|
+
|
382
|
+
#if (CINDEX_VERSION_MINOR >= 32)
|
383
|
+
/*
|
384
|
+
* call-seq:
|
385
|
+
* Clangc::Index#parse_translation_unit2_full_argv(source_file, args, options) =>
|
386
|
+
* Clangc::TranslationUnit
|
387
|
+
*
|
388
|
+
* Parse the given source file and generate the translation unit corresponding
|
389
|
+
* to that file. If its fails, it returns an Integer corresponding to the
|
390
|
+
* error code a Clangc::ErrorCode constant.
|
391
|
+
*
|
392
|
+
* This routine is the main entry point for the Clang C API, providing the
|
393
|
+
* ability to parse a source file into a translation unit that can then be
|
394
|
+
* queried by other functions in the API. This routine accepts a set of
|
395
|
+
* command-line arguments so that the compilation can be configured in the same
|
396
|
+
* way that the compiler is configured on the command line.
|
397
|
+
*
|
398
|
+
* - source_file:
|
399
|
+
* The name of the source file to load, or nil if the source file is included in
|
400
|
+
* the command line arguments.
|
401
|
+
*
|
402
|
+
* - args:
|
403
|
+
* The command-line arguments that would be passed to the clang executable if it
|
404
|
+
* were being invoked out-of-process.
|
405
|
+
* These command-line options will be parsed and will affect how the translation
|
406
|
+
* unit is parsed. Note that the following options are ignored: '-c',
|
407
|
+
* '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
|
408
|
+
*
|
409
|
+
* - options:
|
410
|
+
* A bitmask of options that affects how the translation unit is managed but not
|
411
|
+
* its compilation. This should be a bitwise OR of the TranslationUnit_Flags
|
412
|
+
* constants.
|
413
|
+
*
|
414
|
+
* TODO:
|
415
|
+
* - unsaved_files:
|
416
|
+
* The files that have not yet been saved to disk but may be required for
|
417
|
+
* parsing,
|
418
|
+
* including the contents of those files. The contents and name of these files
|
419
|
+
* (as specified by CXUnsavedFile) are copied when necessary, so the client only
|
420
|
+
* needs to guarantee their validity until the call to this function returns.
|
421
|
+
*
|
422
|
+
* - num_unsaved_files:
|
423
|
+
* The number of unsaved file entries in unsaved_files.
|
424
|
+
* Same as clang_parseTranslationUnit2 but requires a full command line
|
425
|
+
* for \c command_line_args including argv[0]. This is useful if the standard
|
426
|
+
* library paths are relative to the binary.
|
427
|
+
*/
|
428
|
+
VALUE
|
429
|
+
c_Index_parse_TU2_full_argv(VALUE self, VALUE source_file, VALUE args, VALUE options)
|
430
|
+
{
|
431
|
+
char *c_source_file = NULL;
|
432
|
+
c_source_file = RSTRING_2_CHAR(source_file);
|
433
|
+
|
434
|
+
unsigned int c_options = CLANGC_CONSTANT_TO_UINT("TranslationUnit_Flags",
|
435
|
+
options);
|
436
|
+
|
437
|
+
RARRAY_OF_STRINGS_2_C(args);
|
438
|
+
Index_t *i;
|
439
|
+
Data_Get_Struct(self, Index_t, i);
|
440
|
+
VALUE tu;
|
441
|
+
TranslationUnit_t *c_tu;
|
442
|
+
R_GET_CLASS_DATA("Clangc", TranslationUnit, tu, c_tu);
|
443
|
+
|
444
|
+
unsigned int er =
|
445
|
+
clang_parseTranslationUnit2FullArgv(i->data,
|
446
|
+
c_source_file,
|
447
|
+
c_args,
|
448
|
+
len,
|
449
|
+
0,
|
450
|
+
0,
|
451
|
+
c_options, // TODO manage unsaved files
|
452
|
+
&(c_tu->data));
|
453
|
+
|
454
|
+
c_tu->parent = self;
|
455
|
+
|
456
|
+
if (er != 0)
|
457
|
+
return CUINT_2_NUM(er);
|
458
|
+
else
|
459
|
+
return tu;
|
460
|
+
}
|
461
|
+
#endif
|