ffi-clang 0.2.0 → 0.2.1
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 +4 -4
- data/.travis.yml +12 -8
- data/README.md +3 -1
- data/ffi-clang.gemspec +1 -1
- data/lib/ffi/clang.rb +3 -1
- data/lib/ffi/clang/code_completion.rb +193 -0
- data/lib/ffi/clang/comment.rb +154 -11
- data/lib/ffi/clang/compilation_database.rb +125 -0
- data/lib/ffi/clang/cursor.rb +145 -9
- data/lib/ffi/clang/diagnostic.rb +36 -10
- data/lib/ffi/clang/file.rb +69 -0
- data/lib/ffi/clang/index.rb +9 -17
- data/lib/ffi/clang/lib.rb +25 -2
- data/lib/ffi/clang/lib/code_completion.rb +130 -0
- data/lib/ffi/clang/lib/comment.rb +73 -12
- data/lib/ffi/clang/lib/compilation_database.rb +58 -0
- data/lib/ffi/clang/lib/cursor.rb +78 -14
- data/lib/ffi/clang/lib/diagnostic.rb +32 -12
- data/lib/ffi/clang/lib/file.rb +15 -3
- data/lib/ffi/clang/lib/inclusions.rb +32 -0
- data/lib/ffi/clang/lib/source_location.rb +18 -0
- data/lib/ffi/clang/lib/source_range.rb +5 -0
- data/lib/ffi/clang/lib/token.rb +58 -0
- data/lib/ffi/clang/lib/translation_unit.rb +71 -1
- data/lib/ffi/clang/lib/type.rb +61 -3
- data/lib/ffi/clang/source_location.rb +102 -0
- data/lib/ffi/clang/source_range.rb +25 -4
- data/lib/ffi/clang/token.rb +95 -0
- data/lib/ffi/clang/translation_unit.rb +118 -2
- data/lib/ffi/clang/type.rb +61 -0
- data/lib/ffi/clang/unsaved_file.rb +16 -0
- data/lib/ffi/clang/utils.rb +38 -12
- data/lib/ffi/clang/version.rb +1 -1
- data/spec/clang/code_completion_spec.rb +181 -0
- data/spec/clang/comment_spec.rb +385 -12
- data/spec/clang/compilation_database_spec.rb +178 -0
- data/spec/clang/cursor_spec.rb +335 -12
- data/spec/clang/diagnostic_spec.rb +63 -4
- data/spec/clang/file_spec.rb +84 -0
- data/spec/clang/index_spec.rb +62 -5
- data/spec/clang/source_location_spec.rb +104 -4
- data/spec/clang/source_range_spec.rb +76 -0
- data/spec/clang/token_spec.rb +84 -0
- data/spec/clang/translation_unit_spec.rb +202 -5
- data/spec/clang/type_spec.rb +191 -0
- data/spec/clang/utils_spec.rb +2 -3
- data/spec/fixtures/a.c +3 -0
- data/spec/fixtures/compile_commands.json +17 -0
- data/spec/fixtures/completion.cxx +8 -0
- data/spec/fixtures/docs.c +1 -0
- data/spec/fixtures/docs.cc +1 -0
- data/spec/fixtures/docs.h +46 -3
- data/spec/fixtures/list.c +1 -0
- data/spec/fixtures/location1.c +7 -0
- data/spec/fixtures/simple.c +3 -0
- data/spec/fixtures/test.cxx +36 -0
- data/spec/spec_helper.rb +11 -0
- metadata +50 -21
data/lib/ffi/clang/index.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Copyright, 2010-2012 by Jari Bakken.
|
2
2
|
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
|
+
# Copyright, 2014, by Masahiro Sano.
|
3
4
|
#
|
4
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
6
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -29,12 +30,12 @@ module FFI
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def self.release(pointer)
|
32
|
-
Lib.
|
33
|
+
Lib.dispose_index(pointer)
|
33
34
|
end
|
34
35
|
|
35
36
|
def parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {})
|
36
37
|
command_line_args = Array(command_line_args)
|
37
|
-
unsaved_files = unsaved_pointer_from(unsaved)
|
38
|
+
unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved)
|
38
39
|
|
39
40
|
translation_unit_pointer = Lib.parse_translation_unit(self, source_file, args_pointer_from(command_line_args), command_line_args.size, unsaved_files, unsaved.length, options_bitmask_from(opts))
|
40
41
|
|
@@ -43,6 +44,12 @@ module FFI
|
|
43
44
|
TranslationUnit.new translation_unit_pointer, self
|
44
45
|
end
|
45
46
|
|
47
|
+
def create_translation_unit(ast_filename)
|
48
|
+
tu_pointer = Lib.create_translation_unit(self, ast_filename)
|
49
|
+
raise Error, "error parsing #{ast_filename.inspect}" if tu_pointer.null?
|
50
|
+
TranslationUnit.new tu_pointer, self
|
51
|
+
end
|
52
|
+
|
46
53
|
private
|
47
54
|
|
48
55
|
def args_pointer_from(command_line_args)
|
@@ -59,21 +66,6 @@ module FFI
|
|
59
66
|
def options_bitmask_from(opts)
|
60
67
|
Lib.bitmask_from Lib::TranslationUnitFlags, opts
|
61
68
|
end
|
62
|
-
|
63
|
-
def unsaved_pointer_from(unsaved)
|
64
|
-
return nil if unsaved.length == 0
|
65
|
-
|
66
|
-
vec = MemoryPointer.new(Lib::CXUnsavedFile, unsaved.length)
|
67
|
-
|
68
|
-
unsaved.each_with_index do |file, i|
|
69
|
-
uf = Lib::CXUnsavedFile.new(vec + i * Lib::CXUnsavedFile.size)
|
70
|
-
uf[:filename] = MemoryPointer.from_string(file.filename)
|
71
|
-
uf[:contents] = MemoryPointer.from_string(file.contents)
|
72
|
-
uf[:length] = file.contents.length
|
73
|
-
end
|
74
|
-
|
75
|
-
vec
|
76
|
-
end
|
77
69
|
end
|
78
70
|
end
|
79
71
|
end
|
data/lib/ffi/clang/lib.rb
CHANGED
@@ -26,10 +26,16 @@ module FFI
|
|
26
26
|
|
27
27
|
libs = ["clang"]
|
28
28
|
|
29
|
-
if ENV['
|
29
|
+
if ENV['LIBCLANG']
|
30
|
+
libs << ENV['LIBCLANG']
|
31
|
+
elsif ENV['LLVM_CONFIG']
|
30
32
|
llvm_library_dir = `#{ENV['LLVM_CONFIG']} --libdir`.chomp
|
31
33
|
|
32
|
-
|
34
|
+
if FFI::Clang.platform == :darwin
|
35
|
+
libs << llvm_library_dir + '/libclang.dylib'
|
36
|
+
else
|
37
|
+
libs << llvm_library_dir + '/libclang.so'
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
ffi_lib libs
|
@@ -49,6 +55,23 @@ module FFI
|
|
49
55
|
|
50
56
|
bitmask
|
51
57
|
end
|
58
|
+
|
59
|
+
def self.opts_from(enum, bitmask)
|
60
|
+
bit = 1
|
61
|
+
opts = {}
|
62
|
+
while bitmask != 0
|
63
|
+
if bitmask & 1
|
64
|
+
if sym = enum[bit]
|
65
|
+
opts[sym] = true
|
66
|
+
else
|
67
|
+
raise Error, "unknown values: #{bit}, expected one of #{enum.symbols}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
bitmask >>= 1
|
71
|
+
bit <<= 1
|
72
|
+
end
|
73
|
+
opts
|
74
|
+
end
|
52
75
|
end
|
53
76
|
end
|
54
77
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# Copyright, 2014, by Masahiro Sano.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'ffi/clang/lib/translation_unit'
|
22
|
+
require 'ffi/clang/lib/cursor'
|
23
|
+
require 'ffi/clang/lib/diagnostic'
|
24
|
+
|
25
|
+
module FFI
|
26
|
+
module Clang
|
27
|
+
module Lib
|
28
|
+
typedef :pointer, :CXCompletionString
|
29
|
+
|
30
|
+
class CXCompletionResult < FFI::Struct
|
31
|
+
layout(
|
32
|
+
:kind, :cursor_kind,
|
33
|
+
:string, :CXCompletionString,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
class CXCodeCompleteResults < FFI::Struct
|
38
|
+
layout(
|
39
|
+
:results, :pointer,
|
40
|
+
:num, :uint,
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
enum :completion_chunk_kind, [
|
45
|
+
:optional,
|
46
|
+
:typed_text,
|
47
|
+
:text,
|
48
|
+
:placeholder,
|
49
|
+
:informative,
|
50
|
+
:current_parameter,
|
51
|
+
:left_paren,
|
52
|
+
:right_paren,
|
53
|
+
:left_bracket,
|
54
|
+
:right_bracket,
|
55
|
+
:left_brace,
|
56
|
+
:right_brace,
|
57
|
+
:left_angle,
|
58
|
+
:right_angle,
|
59
|
+
:comma,
|
60
|
+
:result_type,
|
61
|
+
:colon,
|
62
|
+
:semi_colon,
|
63
|
+
:equal,
|
64
|
+
:horizontal_space,
|
65
|
+
:vertical_space
|
66
|
+
]
|
67
|
+
|
68
|
+
CodeCompleteFlags = enum :code_complete_flags, [
|
69
|
+
:include_macros, 0x01,
|
70
|
+
:include_code_patterns, 0x02,
|
71
|
+
:include_brief_comments, 0x04
|
72
|
+
]
|
73
|
+
|
74
|
+
CompletionContext = enum :completion_context, [
|
75
|
+
:unexposed, 0,
|
76
|
+
:any_type, 1 << 0,
|
77
|
+
:any_value, 1 << 1,
|
78
|
+
:objc_object_value, 1 << 2,
|
79
|
+
:objc_selector_value, 1 << 3,
|
80
|
+
:cxx_class_type_value, 1 << 4,
|
81
|
+
:dot_member_access, 1 << 5,
|
82
|
+
:arrow_member_access, 1 << 6,
|
83
|
+
:objc_property_access, 1 << 7,
|
84
|
+
:enum_tag, 1 << 8,
|
85
|
+
:union_tag, 1 << 9,
|
86
|
+
:struct_tag, 1 << 10,
|
87
|
+
:class_tag, 1 << 11,
|
88
|
+
:namespace, 1 << 12,
|
89
|
+
:nested_name_specifier, 1 << 13,
|
90
|
+
:objc_interface, 1 << 14,
|
91
|
+
:objc_protocol, 1 << 15,
|
92
|
+
:objc_category, 1 << 16,
|
93
|
+
:objc_instance_message, 1 << 17,
|
94
|
+
:objc_class_message, 1 << 18,
|
95
|
+
:objc_selector_name, 1 << 19,
|
96
|
+
:macro_name, 1 << 20,
|
97
|
+
:natural_language, 1 << 21,
|
98
|
+
:unknown, ((1 << 22) - 1),
|
99
|
+
]
|
100
|
+
|
101
|
+
# CXCompletionString functions
|
102
|
+
attach_function :get_completion_chunk_kind, :clang_getCompletionChunkKind, [:CXCompletionString, :uint], :completion_chunk_kind
|
103
|
+
attach_function :get_completion_text, :clang_getCompletionChunkText, [:CXCompletionString, :uint], CXString.by_value
|
104
|
+
attach_function :get_completion_chunk_completion_string, :clang_getCompletionChunkCompletionString, [:CXCompletionString, :uint], :CXCompletionString
|
105
|
+
attach_function :get_num_completion_chunks, :clang_getNumCompletionChunks, [:CXCompletionString], :uint
|
106
|
+
attach_function :get_completion_priority, :clang_getCompletionPriority, [:CXCompletionString], :uint
|
107
|
+
attach_function :get_completion_availability, :clang_getCompletionAvailability, [:CXCompletionString], :availability
|
108
|
+
attach_function :get_completion_num_annotations, :clang_getCompletionNumAnnotations, [:CXCompletionString], :uint
|
109
|
+
attach_function :get_completion_annotation, :clang_getCompletionAnnotation, [:CXCompletionString, :uint], CXString.by_value
|
110
|
+
attach_function :get_completion_parent, :clang_getCompletionParent, [:CXCompletionString, :pointer], CXString.by_value
|
111
|
+
attach_function :get_completion_brief_comment, :clang_getCompletionBriefComment, [:CXCompletionString], CXString.by_value
|
112
|
+
|
113
|
+
# CXCodeCompleteResults functions
|
114
|
+
attach_function :get_code_complete_get_num_diagnostics, :clang_codeCompleteGetNumDiagnostics, [CXCodeCompleteResults.ptr], :uint
|
115
|
+
attach_function :get_code_complete_get_diagnostic, :clang_codeCompleteGetDiagnostic, [CXCodeCompleteResults.ptr, :uint], :CXDiagnostic
|
116
|
+
attach_function :get_code_complete_get_contexts, :clang_codeCompleteGetContexts, [CXCodeCompleteResults.ptr], :ulong_long
|
117
|
+
attach_function :get_code_complete_get_container_kind, :clang_codeCompleteGetContainerKind, [CXCodeCompleteResults.ptr, :pointer], :cursor_kind
|
118
|
+
attach_function :get_code_complete_get_container_usr, :clang_codeCompleteGetContainerUSR, [CXCodeCompleteResults.ptr], CXString.by_value
|
119
|
+
attach_function :get_code_complete_get_objc_selector, :clang_codeCompleteGetObjCSelector, [CXCodeCompleteResults.ptr], CXString.by_value
|
120
|
+
|
121
|
+
# Other functions
|
122
|
+
attach_function :code_complete_at, :clang_codeCompleteAt, [:CXTranslationUnit, :string, :uint, :uint, :pointer, :uint, :uint], CXCodeCompleteResults.ptr
|
123
|
+
attach_function :dispose_code_complete_results, :clang_disposeCodeCompleteResults, [CXCodeCompleteResults.ptr], :void
|
124
|
+
attach_function :get_cursor_completion_string, :clang_getCursorCompletionString, [CXCursor.by_value], :CXCompletionString
|
125
|
+
attach_function :default_code_completion_options, :clang_defaultCodeCompleteOptions, [], :uint
|
126
|
+
attach_function :sort_code_completion_results, :clang_sortCodeCompletionResults, [:pointer, :uint], :void
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
@@ -26,31 +26,92 @@ module FFI
|
|
26
26
|
module Lib
|
27
27
|
class CXComment < FFI::Struct
|
28
28
|
layout(
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
:ast_node, :pointer,
|
30
|
+
:translation_unit, :pointer
|
31
|
+
)
|
32
32
|
end
|
33
33
|
|
34
|
-
enum :kind, [
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
enum :kind, [
|
35
|
+
:comment_null, 0,
|
36
|
+
:comment_text, 1,
|
37
|
+
:comment_inline_command, 2,
|
38
|
+
:comment_html_start_tag, 3,
|
39
|
+
:comment_html_end_tag, 4,
|
40
|
+
:comment_paragraph, 5,
|
41
|
+
:comment_block_command, 6,
|
42
|
+
:comment_param_command, 7,
|
43
|
+
:comment_tparam_command, 8,
|
44
|
+
:comment_verbatim_block_command, 9,
|
45
|
+
:comment_verbatim_block_line, 10,
|
46
|
+
:comment_verbatim_line, 11,
|
47
|
+
:comment_full, 12,
|
48
|
+
]
|
40
49
|
|
50
|
+
enum :render_kind, [
|
51
|
+
:normal,
|
52
|
+
:bold,
|
53
|
+
:monospaced,
|
54
|
+
:emphasized
|
55
|
+
]
|
56
|
+
|
57
|
+
enum :pass_direction, [
|
58
|
+
:pass_direction_in, 0,
|
59
|
+
:pass_direction_out, 1,
|
60
|
+
:pass_direction_inout, 2
|
61
|
+
]
|
62
|
+
|
63
|
+
# common functions
|
41
64
|
attach_function :comment_get_kind, :clang_Comment_getKind, [CXComment.by_value], :kind
|
42
65
|
attach_function :comment_get_num_children, :clang_Comment_getNumChildren, [CXComment.by_value], :uint
|
43
66
|
attach_function :comment_get_child, :clang_Comment_getChild, [CXComment.by_value, :uint], CXComment.by_value
|
67
|
+
attach_function :comment_is_whitespace, :clang_Comment_isWhitespace, [CXComment.by_value], :uint
|
68
|
+
|
69
|
+
# TextComment functions
|
44
70
|
attach_function :text_comment_get_text, :clang_TextComment_getText, [CXComment.by_value], CXString.by_value
|
45
|
-
attach_function :block_command_comment_get_paragraph, :clang_BlockCommandComment_getParagraph, [CXComment.by_value], CXComment.by_value
|
46
|
-
attach_function :full_comment_get_as_html, :clang_FullComment_getAsHTML, [CXComment.by_value], CXString.by_value
|
47
|
-
attach_function :full_comment_get_as_xml, :clang_FullComment_getAsXML, [CXComment.by_value], CXString.by_value
|
48
71
|
|
72
|
+
# InlineCommandComment functions
|
73
|
+
attach_function :inline_command_comment_get_command_name, :clang_InlineCommandComment_getCommandName, [CXComment.by_value], CXString.by_value
|
74
|
+
attach_function :inline_command_comment_get_num_args, :clang_InlineCommandComment_getNumArgs, [CXComment.by_value], :uint
|
75
|
+
attach_function :inline_content_comment_has_trailing_newline, :clang_InlineContentComment_hasTrailingNewline, [CXComment.by_value], :uint
|
76
|
+
attach_function :inline_command_comment_get_render_kind, :clang_InlineCommandComment_getRenderKind, [CXComment.by_value], :render_kind
|
77
|
+
attach_function :inline_command_comment_get_arg_text, :clang_InlineCommandComment_getArgText, [CXComment.by_value, :uint], CXString.by_value
|
78
|
+
|
79
|
+
# HTMLTagComment functions
|
80
|
+
attach_function :html_tag_comment_get_as_string, :clang_HTMLTagComment_getAsString, [CXComment.by_value], CXString.by_value
|
81
|
+
attach_function :html_tag_comment_get_tag_name, :clang_HTMLTagComment_getTagName, [CXComment.by_value], CXString.by_value
|
82
|
+
attach_function :html_start_tag_comment_is_self_closing, :clang_HTMLStartTagComment_isSelfClosing, [CXComment.by_value], :uint
|
83
|
+
attach_function :html_start_tag_comment_get_num_attrs, :clang_HTMLStartTag_getNumAttrs, [CXComment.by_value], :uint
|
84
|
+
attach_function :html_start_tag_comment_get_attr_name, :clang_HTMLStartTag_getAttrName, [CXComment.by_value, :uint], CXString.by_value
|
85
|
+
attach_function :html_start_tag_comment_get_attr_value, :clang_HTMLStartTag_getAttrValue,[CXComment.by_value, :uint], CXString.by_value
|
86
|
+
|
87
|
+
# ParamCommandComment functions
|
88
|
+
attach_function :param_command_comment_is_direction_explicit, :clang_ParamCommandComment_isDirectionExplicit, [CXComment.by_value], :uint
|
89
|
+
attach_function :param_command_comment_get_direction, :clang_ParamCommandComment_getDirection, [CXComment.by_value], :pass_direction
|
49
90
|
attach_function :param_command_comment_get_param_name, :clang_ParamCommandComment_getParamName, [CXComment.by_value], CXString.by_value
|
50
91
|
attach_function :param_command_comment_is_param_index_valid, :clang_ParamCommandComment_isParamIndexValid, [CXComment.by_value], :uint
|
51
92
|
attach_function :param_command_comment_get_param_index, :clang_ParamCommandComment_getParamIndex, [CXComment.by_value], :uint
|
93
|
+
|
94
|
+
# TParamCommandComment functions
|
95
|
+
attach_function :tparam_command_comment_get_param_name, :clang_TParamCommandComment_getParamName, [CXComment.by_value], CXString.by_value
|
96
|
+
attach_function :tparam_command_comment_is_param_position_valid, :clang_TParamCommandComment_isParamPositionValid, [CXComment.by_value], :uint
|
97
|
+
attach_function :tparam_command_comment_get_depth, :clang_TParamCommandComment_getDepth, [CXComment.by_value], :uint
|
98
|
+
attach_function :tparam_command_comment_get_index, :clang_TParamCommandComment_getIndex, [CXComment.by_value, :uint], :uint
|
99
|
+
|
100
|
+
# BlockCommandComment functions
|
101
|
+
attach_function :block_command_comment_get_paragraph, :clang_BlockCommandComment_getParagraph, [CXComment.by_value], CXComment.by_value
|
52
102
|
attach_function :block_command_comment_get_command_name, :clang_BlockCommandComment_getCommandName, [CXComment.by_value], CXString.by_value
|
53
103
|
attach_function :block_command_comment_get_num_args, :clang_BlockCommandComment_getNumArgs, [CXComment.by_value], :uint
|
104
|
+
attach_function :block_command_comment_get_arg_text, :clang_BlockCommandComment_getArgText, [CXComment.by_value, :uint], CXString.by_value
|
105
|
+
|
106
|
+
# VerbatimBlockLineComment functions
|
107
|
+
attach_function :verbatim_block_line_comment_get_text, :clang_VerbatimBlockLineComment_getText, [CXComment.by_value], CXString.by_value
|
108
|
+
|
109
|
+
# VerbatimLineComment functions
|
110
|
+
attach_function :verbatim_line_comment_get_text, :clang_VerbatimLineComment_getText, [CXComment.by_value], CXString.by_value
|
111
|
+
|
112
|
+
# FullComment functions
|
113
|
+
attach_function :full_comment_get_as_html, :clang_FullComment_getAsHTML, [CXComment.by_value], CXString.by_value
|
114
|
+
attach_function :full_comment_get_as_xml, :clang_FullComment_getAsXML, [CXComment.by_value], CXString.by_value
|
54
115
|
end
|
55
116
|
end
|
56
117
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright, 2014, by Masahiro Sano.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module FFI
|
22
|
+
module Clang
|
23
|
+
module Lib
|
24
|
+
typedef :pointer, :CXCompilationDatabase
|
25
|
+
typedef :pointer, :CXCompileCommands
|
26
|
+
typedef :pointer, :CXCompileCommand
|
27
|
+
|
28
|
+
CompilationDatabaseError = enum [
|
29
|
+
:no_error, 0,
|
30
|
+
:can_not_load_database, 1,
|
31
|
+
]
|
32
|
+
|
33
|
+
# CompilationDatabase
|
34
|
+
attach_function :compilation_database_from_directory, :clang_CompilationDatabase_fromDirectory, [:string, :pointer], :CXCompilationDatabase
|
35
|
+
attach_function :compilation_database_dispose, :clang_CompilationDatabase_dispose, [:CXCompilationDatabase], :uint
|
36
|
+
attach_function :compilation_database_get_compile_commands, :clang_CompilationDatabase_getCompileCommands, [:CXCompilationDatabase, :string], :CXCompileCommands
|
37
|
+
if FFI::Clang::Utils.satisfy_version?('3.3')
|
38
|
+
attach_function :compilation_database_get_all_compile_commands, :clang_CompilationDatabase_getAllCompileCommands, [:CXCompilationDatabase], :CXCompileCommands
|
39
|
+
end
|
40
|
+
|
41
|
+
# CompilationDatabase::CompileCommands
|
42
|
+
attach_function :compile_commands_dispose, :clang_CompileCommands_dispose, [:CXCompileCommands], :void
|
43
|
+
attach_function :compile_commands_get_size, :clang_CompileCommands_getSize, [:CXCompileCommands], :uint
|
44
|
+
attach_function :compile_commands_get_command, :clang_CompileCommands_getCommand, [:CXCompileCommands, :uint], :CXCompileCommand
|
45
|
+
|
46
|
+
# CompilationDatabase::CompileCommand
|
47
|
+
attach_function :compile_command_get_directory, :clang_CompileCommand_getDirectory, [:CXCompileCommand], CXString.by_value
|
48
|
+
attach_function :compile_command_get_num_args, :clang_CompileCommand_getNumArgs, [:CXCompileCommand], :uint
|
49
|
+
attach_function :compile_command_get_arg, :clang_CompileCommand_getArg, [:CXCompileCommand, :uint], CXString.by_value
|
50
|
+
if FFI::Clang::Utils.satisfy_version?('3.4')
|
51
|
+
# Thease functions are not exposed by libclang.so privided by packages.
|
52
|
+
# attach_function :compile_command_get_num_mapped_sources, :clang_CompileCommand_getNumMappedSources, [:CXCompileCommand], :uint
|
53
|
+
# attach_function :compile_command_get_mapped_source_path, :clang_CompileCommand_getMappedSourcePath, [:CXCompileCommand, :uint], CXString.by_value
|
54
|
+
# attach_function :compile_command_get_mapped_source_content, :clang_CompileCommand_getMappedSourceContent, [:CXCompileCommand, :uint], CXString.by_value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/ffi/clang/lib/cursor.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Copyright, 2010-2012 by Jari Bakken.
|
2
2
|
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
3
|
# Copyright, 2013, by Garry C. Marshall. <http://www.meaningfulname.net>
|
4
|
+
# Copyright, 2014, by Masahiro Sano.
|
4
5
|
#
|
5
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
7
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -24,11 +25,12 @@ require 'ffi/clang/lib/translation_unit'
|
|
24
25
|
require 'ffi/clang/lib/diagnostic'
|
25
26
|
require 'ffi/clang/lib/comment'
|
26
27
|
require 'ffi/clang/lib/type'
|
28
|
+
require 'ffi/clang/utils'
|
27
29
|
|
28
30
|
module FFI
|
29
31
|
module Clang
|
30
32
|
module Lib
|
31
|
-
enum :
|
33
|
+
enum :cursor_kind, [
|
32
34
|
:cursor_unexposed_decl, 1,
|
33
35
|
:cursor_struct, 2,
|
34
36
|
:cursor_union, 3,
|
@@ -83,7 +85,7 @@ module FFI
|
|
83
85
|
:cursor_no_decl_found, 71,
|
84
86
|
:cursor_not_implemented, 72,
|
85
87
|
:cursor_invalid_code, 73,
|
86
|
-
:
|
88
|
+
:cursor_unexposed_expr, 100,
|
87
89
|
:cursor_decl_ref_expr, 101,
|
88
90
|
:cursor_member_ref_expr, 102,
|
89
91
|
:cursor_call_expr, 103,
|
@@ -204,16 +206,56 @@ module FFI
|
|
204
206
|
|
205
207
|
class CXCursor < FFI::Struct
|
206
208
|
layout(
|
207
|
-
:kind, :
|
209
|
+
:kind, :cursor_kind,
|
208
210
|
:xdata, :int,
|
209
211
|
:data, [:pointer, 3]
|
210
212
|
)
|
211
213
|
end
|
212
214
|
|
215
|
+
class CXVersion < FFI::Struct
|
216
|
+
layout(
|
217
|
+
:major, :int,
|
218
|
+
:minor, :int,
|
219
|
+
:subminor, :int,
|
220
|
+
)
|
221
|
+
|
222
|
+
def major
|
223
|
+
self[:major]
|
224
|
+
end
|
225
|
+
|
226
|
+
def minor
|
227
|
+
self[:minor]
|
228
|
+
end
|
229
|
+
|
230
|
+
def subminor
|
231
|
+
self[:subminor]
|
232
|
+
end
|
233
|
+
|
234
|
+
def version_string
|
235
|
+
[major, minor, subminor].reject{|v| v < 0}.map(&:to_s).join(".")
|
236
|
+
end
|
237
|
+
|
238
|
+
def to_s
|
239
|
+
version_string
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class CXPlatformAvailability < FFI::Struct
|
244
|
+
layout(
|
245
|
+
:platform, CXString,
|
246
|
+
:introduced, CXVersion,
|
247
|
+
:deprecated, CXVersion,
|
248
|
+
:obsoleted, CXVersion,
|
249
|
+
:unavailable, :int,
|
250
|
+
:message, CXString,
|
251
|
+
)
|
252
|
+
end
|
253
|
+
|
213
254
|
enum :cxx_access_specifier, [:invalid, :public, :protected, :private]
|
214
255
|
attach_function :get_cxx_access_specifier, :clang_getCXXAccessSpecifier, [CXCursor.by_value], :cxx_access_specifier
|
215
256
|
|
216
257
|
attach_function :get_enum_value, :clang_getEnumConstantDeclValue, [CXCursor.by_value], :long_long
|
258
|
+
attach_function :get_enum_unsigned_value, :clang_getEnumConstantDeclUnsignedValue, [CXCursor.by_value], :ulong_long
|
217
259
|
|
218
260
|
attach_function :is_virtual_base, :clang_isVirtualBase, [CXCursor.by_value], :uint
|
219
261
|
attach_function :is_dynamic_call, :clang_Cursor_isDynamicCall, [CXCursor.by_value], :uint
|
@@ -223,6 +265,7 @@ module FFI
|
|
223
265
|
attach_function :is_definition, :clang_isCursorDefinition, [CXCursor.by_value], :uint
|
224
266
|
attach_function :cxx_method_is_static, :clang_CXXMethod_isStatic, [CXCursor.by_value], :uint
|
225
267
|
attach_function :cxx_method_is_virtual, :clang_CXXMethod_isVirtual, [CXCursor.by_value], :uint
|
268
|
+
|
226
269
|
if FFI::Clang::Utils.satisfy_version?('3.4')
|
227
270
|
attach_function :cxx_method_is_pure_virtual, :clang_CXXMethod_isPureVirtual, [CXCursor.by_value], :uint
|
228
271
|
end
|
@@ -234,7 +277,7 @@ module FFI
|
|
234
277
|
attach_function :get_canonical_cursor, :clang_getCanonicalCursor, [CXCursor.by_value], CXCursor.by_value
|
235
278
|
attach_function :get_cursor_definition, :clang_getCursorDefinition, [CXCursor.by_value], CXCursor.by_value
|
236
279
|
attach_function :get_specialized_cursor_template, :clang_getSpecializedCursorTemplate, [CXCursor.by_value], CXCursor.by_value
|
237
|
-
attach_function :get_template_cursor_kind, :clang_getTemplateCursorKind, [CXCursor.by_value], :
|
280
|
+
attach_function :get_template_cursor_kind, :clang_getTemplateCursorKind, [CXCursor.by_value], :cursor_kind
|
238
281
|
|
239
282
|
attach_function :get_translation_unit_cursor, :clang_getTranslationUnitCursor, [:CXTranslationUnit], CXCursor.by_value
|
240
283
|
attach_function :cursor_get_translation_unit, :clang_Cursor_getTranslationUnit, [CXCursor.by_value], :CXTranslationUnit
|
@@ -243,6 +286,7 @@ module FFI
|
|
243
286
|
|
244
287
|
attach_function :cursor_is_null, :clang_Cursor_isNull, [CXCursor.by_value], :int
|
245
288
|
|
289
|
+
attach_function :cursor_get_comment_range, :clang_Cursor_getCommentRange, [CXCursor.by_value], CXSourceRange.by_value
|
246
290
|
attach_function :cursor_get_raw_comment_text, :clang_Cursor_getRawCommentText, [CXCursor.by_value], CXString.by_value
|
247
291
|
attach_function :cursor_get_parsed_comment, :clang_Cursor_getParsedComment, [CXCursor.by_value], CXComment.by_value
|
248
292
|
|
@@ -252,18 +296,19 @@ module FFI
|
|
252
296
|
attach_function :get_cursor_display_name, :clang_getCursorDisplayName, [CXCursor.by_value], CXString.by_value
|
253
297
|
attach_function :get_cursor_spelling, :clang_getCursorSpelling, [CXCursor.by_value], CXString.by_value
|
254
298
|
attach_function :get_cursor_usr, :clang_getCursorUSR, [CXCursor.by_value], CXString.by_value
|
299
|
+
attach_function :get_cursor_kind_spelling, :clang_getCursorKindSpelling, [:cursor_kind], CXString.by_value
|
255
300
|
|
256
301
|
attach_function :are_equal, :clang_equalCursors, [CXCursor.by_value, CXCursor.by_value], :uint
|
257
302
|
|
258
|
-
attach_function :is_declaration, :clang_isDeclaration, [:
|
259
|
-
attach_function :is_reference, :clang_isReference, [:
|
260
|
-
attach_function :is_expression, :clang_isExpression, [:
|
261
|
-
attach_function :is_statement, :clang_isStatement, [:
|
262
|
-
attach_function :is_attribute, :clang_isAttribute, [:
|
263
|
-
attach_function :is_invalid, :clang_isInvalid, [:
|
264
|
-
attach_function :is_translation_unit, :clang_isTranslationUnit, [:
|
265
|
-
attach_function :is_preprocessing, :clang_isPreprocessing, [:
|
266
|
-
attach_function :is_unexposed, :clang_isUnexposed, [:
|
303
|
+
attach_function :is_declaration, :clang_isDeclaration, [:cursor_kind], :uint
|
304
|
+
attach_function :is_reference, :clang_isReference, [:cursor_kind], :uint
|
305
|
+
attach_function :is_expression, :clang_isExpression, [:cursor_kind], :uint
|
306
|
+
attach_function :is_statement, :clang_isStatement, [:cursor_kind], :uint
|
307
|
+
attach_function :is_attribute, :clang_isAttribute, [:cursor_kind], :uint
|
308
|
+
attach_function :is_invalid, :clang_isInvalid, [:cursor_kind], :uint
|
309
|
+
attach_function :is_translation_unit, :clang_isTranslationUnit, [:cursor_kind], :uint
|
310
|
+
attach_function :is_preprocessing, :clang_isPreprocessing, [:cursor_kind], :uint
|
311
|
+
attach_function :is_unexposed, :clang_isUnexposed, [:cursor_kind], :uint
|
267
312
|
|
268
313
|
enum :child_visit_result, [:break, :continue, :recurse]
|
269
314
|
|
@@ -282,8 +327,27 @@ module FFI
|
|
282
327
|
|
283
328
|
attach_function :get_cursor_availability, :clang_getCursorAvailability, [CXCursor.by_value], :availability
|
284
329
|
attach_function :get_cursor_linkage, :clang_getCursorLinkage, [CXCursor.by_value], :linkage_kind
|
285
|
-
|
330
|
+
attach_function :get_included_file, :clang_getIncludedFile, [CXCursor.by_value], :CXFile
|
286
331
|
attach_function :get_cursor_hash, :clang_hashCursor, [CXCursor.by_value], :uint
|
332
|
+
|
333
|
+
if FFI::Clang::Utils.satisfy_version?('3.3')
|
334
|
+
attach_function :is_bit_field,:clang_Cursor_isBitField, [CXCursor.by_value], :uint
|
335
|
+
attach_function :get_field_decl_bit_width, :clang_getFieldDeclBitWidth, [CXCursor.by_value], :int
|
336
|
+
end
|
337
|
+
|
338
|
+
attach_function :get_overloaded_decl, :clang_getOverloadedDecl, [CXCursor.by_value, :uint], CXCursor.by_value
|
339
|
+
attach_function :get_num_overloaded_decls, :clang_getNumOverloadedDecls, [CXCursor.by_value], :uint
|
340
|
+
|
341
|
+
attach_function :cursor_get_argument, :clang_Cursor_getArgument, [CXCursor.by_value, :uint], CXCursor.by_value
|
342
|
+
attach_function :cursor_get_num_arguments, :clang_Cursor_getNumArguments, [CXCursor.by_value], :int
|
343
|
+
|
344
|
+
attach_function :get_decl_objc_type_encoding, :clang_getDeclObjCTypeEncoding, [CXCursor.by_value], CXString.by_value
|
345
|
+
|
346
|
+
attach_function :get_cursor_platform_availability, :clang_getCursorPlatformAvailability, [CXCursor.by_value, :pointer, :pointer, :pointer, :pointer, :pointer, :int], :int
|
347
|
+
attach_function :dispose_platform_availability, :clang_disposeCXPlatformAvailability, [:pointer], :void
|
348
|
+
|
349
|
+
attach_function :get_overridden_cursors, :clang_getOverriddenCursors, [CXCursor.by_value, :pointer, :pointer], :void
|
350
|
+
attach_function :dispose_overridden_cursors, :clang_disposeOverriddenCursors, [:pointer], :void
|
287
351
|
end
|
288
352
|
end
|
289
353
|
end
|