ghazel-ffi-clang 0.2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +4 -0
  6. data/README.md +74 -0
  7. data/Rakefile +12 -0
  8. data/ext/rakefile.rb +12 -0
  9. data/ext/teapot.rb +16 -0
  10. data/ffi-clang.gemspec +26 -0
  11. data/lib/ffi/clang.rb +54 -0
  12. data/lib/ffi/clang/comment.rb +278 -0
  13. data/lib/ffi/clang/cursor.rb +378 -0
  14. data/lib/ffi/clang/diagnostic.rb +113 -0
  15. data/lib/ffi/clang/file.rb +69 -0
  16. data/lib/ffi/clang/index.rb +71 -0
  17. data/lib/ffi/clang/lib.rb +73 -0
  18. data/lib/ffi/clang/lib/comment.rb +117 -0
  19. data/lib/ffi/clang/lib/cursor.rb +353 -0
  20. data/lib/ffi/clang/lib/diagnostic.rb +87 -0
  21. data/lib/ffi/clang/lib/file.rb +57 -0
  22. data/lib/ffi/clang/lib/index.rb +34 -0
  23. data/lib/ffi/clang/lib/source_location.rb +53 -0
  24. data/lib/ffi/clang/lib/source_range.rb +46 -0
  25. data/lib/ffi/clang/lib/string.rb +45 -0
  26. data/lib/ffi/clang/lib/token.rb +58 -0
  27. data/lib/ffi/clang/lib/translation_unit.rb +106 -0
  28. data/lib/ffi/clang/lib/type.rb +154 -0
  29. data/lib/ffi/clang/lib/utils.rb +29 -0
  30. data/lib/ffi/clang/source_location.rb +149 -0
  31. data/lib/ffi/clang/source_range.rb +61 -0
  32. data/lib/ffi/clang/token.rb +95 -0
  33. data/lib/ffi/clang/translation_unit.rb +142 -0
  34. data/lib/ffi/clang/type.rb +135 -0
  35. data/lib/ffi/clang/unsaved_file.rb +49 -0
  36. data/lib/ffi/clang/utils.rb +58 -0
  37. data/lib/ffi/clang/version.rb +26 -0
  38. data/spec/clang/comment_spec.rb +470 -0
  39. data/spec/clang/cursor_spec.rb +709 -0
  40. data/spec/clang/diagnostic_spec.rb +89 -0
  41. data/spec/clang/file_spec.rb +84 -0
  42. data/spec/clang/index_spec.rb +70 -0
  43. data/spec/clang/source_location_spec.rb +140 -0
  44. data/spec/clang/source_range_spec.rb +76 -0
  45. data/spec/clang/token_spec.rb +83 -0
  46. data/spec/clang/translation_unit_spec.rb +214 -0
  47. data/spec/clang/type_spec.rb +289 -0
  48. data/spec/clang/utils_spec.rb +61 -0
  49. data/spec/fixtures/a.c +7 -0
  50. data/spec/fixtures/canonical.c +5 -0
  51. data/spec/fixtures/docs.c +1 -0
  52. data/spec/fixtures/docs.cc +1 -0
  53. data/spec/fixtures/docs.h +54 -0
  54. data/spec/fixtures/list.c +11 -0
  55. data/spec/fixtures/location1.c +7 -0
  56. data/spec/fixtures/simple.c +3 -0
  57. data/spec/fixtures/test.cxx +62 -0
  58. data/spec/spec_helper.rb +64 -0
  59. metadata +180 -0
@@ -0,0 +1,69 @@
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/file'
22
+ require 'ffi/clang/utils'
23
+
24
+ module FFI
25
+ module Clang
26
+ class File < Pointer
27
+ attr_reader :translation_unit
28
+
29
+ def initialize(pointer, tu)
30
+ super pointer
31
+ @translation_unit = tu
32
+
33
+ if FFI::Clang::Utils.satisfy_version?('3.3')
34
+ pointer = MemoryPointer.new(Lib::CXFileUniqueID)
35
+ Lib.get_file_unique_id(self, pointer)
36
+ @unique_id = Lib::CXFileUniqueID.new(pointer)
37
+ end
38
+ end
39
+
40
+ def to_s
41
+ name
42
+ end
43
+
44
+ def name
45
+ Lib.extract_string Lib.get_file_name(self)
46
+ end
47
+
48
+ def time
49
+ Time.at(Lib.get_file_time(self))
50
+ end
51
+
52
+ def include_guarded?
53
+ Lib.is_file_multiple_include_guarded(@translation_unit, self) != 0
54
+ end
55
+
56
+ def device
57
+ @unique_id[:device]
58
+ end
59
+
60
+ def inode
61
+ @unique_id[:inode]
62
+ end
63
+
64
+ def modification
65
+ Time.at(@unique_id[:modification])
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,71 @@
1
+ # Copyright, 2010-2012 by Jari Bakken.
2
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ # Copyright, 2014, by Masahiro Sano.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'ffi/clang/lib/index'
24
+
25
+ module FFI
26
+ module Clang
27
+ class Index < AutoPointer
28
+ def initialize(exclude_declarations = true, display_diagnostics = false)
29
+ super Lib.create_index(exclude_declarations ? 1 : 0, display_diagnostics ? 1 : 0)
30
+ end
31
+
32
+ def self.release(pointer)
33
+ Lib.dispose_index(pointer)
34
+ end
35
+
36
+ def parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {})
37
+ command_line_args = Array(command_line_args)
38
+ unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved)
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))
41
+
42
+ raise Error, "error parsing #{source_file.inspect}" if translation_unit_pointer.null?
43
+
44
+ TranslationUnit.new translation_unit_pointer, self
45
+ end
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
+
53
+ private
54
+
55
+ def args_pointer_from(command_line_args)
56
+ args_pointer = MemoryPointer.new(:pointer, command_line_args.length)
57
+
58
+ strings = command_line_args.map do |arg|
59
+ MemoryPointer.from_string(arg.to_s)
60
+ end
61
+
62
+ args_pointer.put_array_of_pointer(0, strings) unless strings.empty?
63
+ args_pointer
64
+ end
65
+
66
+ def options_bitmask_from(opts)
67
+ Lib.bitmask_from Lib::TranslationUnitFlags, opts
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,73 @@
1
+ # Copyright, 2010-2012 by Jari Bakken.
2
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ module FFI
23
+ module Clang
24
+ module Lib
25
+ extend FFI::Library
26
+
27
+ libs = ["clang"]
28
+
29
+ if ENV['LIBCLANG']
30
+ libs << ENV['LIBCLANG']
31
+ elsif ENV['LLVM_CONFIG']
32
+ llvm_library_dir = `#{ENV['LLVM_CONFIG']} --libdir`.chomp
33
+
34
+ libs << llvm_library_dir + '/libclang.dylib'
35
+ end
36
+
37
+ ffi_lib libs
38
+
39
+ def self.bitmask_from(enum, opts)
40
+ bitmask = 0
41
+
42
+ opts.each do |key, val|
43
+ next unless val
44
+
45
+ if int = enum[key]
46
+ bitmask |= int
47
+ else
48
+ raise Error, "unknown option: #{key.inspect}, expected one of #{enum.symbols}"
49
+ end
50
+ end
51
+
52
+ bitmask
53
+ end
54
+
55
+ def self.opts_from(enum, bitmask)
56
+ bit = 1
57
+ opts = {}
58
+ while bitmask != 0
59
+ if bitmask & 1
60
+ if sym = enum[bit]
61
+ opts[sym] = true
62
+ else
63
+ raise Error, "unknown values: #{bit}, expected one of #{enum.symbols}"
64
+ end
65
+ end
66
+ bitmask >>= 1
67
+ bit <<= 1
68
+ end
69
+ opts
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,117 @@
1
+ # Copyright, 2010-2012 by Jari Bakken.
2
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ require 'ffi/clang/lib/index'
23
+
24
+ module FFI
25
+ module Clang
26
+ module Lib
27
+ class CXComment < FFI::Struct
28
+ layout(
29
+ :ast_node, :pointer,
30
+ :translation_unit, :pointer
31
+ )
32
+ end
33
+
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
+ ]
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
64
+ attach_function :comment_get_kind, :clang_Comment_getKind, [CXComment.by_value], :kind
65
+ attach_function :comment_get_num_children, :clang_Comment_getNumChildren, [CXComment.by_value], :uint
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
70
+ attach_function :text_comment_get_text, :clang_TextComment_getText, [CXComment.by_value], CXString.by_value
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
90
+ attach_function :param_command_comment_get_param_name, :clang_ParamCommandComment_getParamName, [CXComment.by_value], CXString.by_value
91
+ attach_function :param_command_comment_is_param_index_valid, :clang_ParamCommandComment_isParamIndexValid, [CXComment.by_value], :uint
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
102
+ attach_function :block_command_comment_get_command_name, :clang_BlockCommandComment_getCommandName, [CXComment.by_value], CXString.by_value
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
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,353 @@
1
+ # Copyright, 2010-2012 by Jari Bakken.
2
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ # Copyright, 2013, by Garry C. Marshall. <http://www.meaningfulname.net>
4
+ # Copyright, 2014, by Masahiro Sano.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ require 'ffi/clang/lib/translation_unit'
25
+ require 'ffi/clang/lib/diagnostic'
26
+ require 'ffi/clang/lib/comment'
27
+ require 'ffi/clang/lib/type'
28
+ require 'ffi/clang/utils'
29
+
30
+ module FFI
31
+ module Clang
32
+ module Lib
33
+ enum :kind, [
34
+ :cursor_unexposed_decl, 1,
35
+ :cursor_struct, 2,
36
+ :cursor_union, 3,
37
+ :cursor_class_decl, 4,
38
+ :cursor_enum_decl, 5,
39
+ :cursor_field_decl, 6,
40
+ :cursor_enum_constant_decl, 7,
41
+ :cursor_function, 8,
42
+ :cursor_variable, 9,
43
+ :cursor_parm_decl, 10,
44
+ :cursor_obj_c_interface_decl, 11,
45
+ :cursor_obj_c_category_decl, 12,
46
+ :cursor_obj_c_protocol_decl, 13,
47
+ :cursor_obj_c_property_decl, 14,
48
+ :cursor_obj_c_instance_var_decl, 15,
49
+ :cursor_obj_c_instance_method_decl, 16,
50
+ :cursor_obj_c_class_method_decl, 17,
51
+ :cursor_obj_c_implementation_decl, 18,
52
+ :cursor_obj_c_category_impl_decl, 19,
53
+ :cursor_typedef_decl, 20,
54
+ :cursor_cxx_method, 21,
55
+ :cursor_namespace, 22,
56
+ :cursor_linkage_spec, 23,
57
+ :cursor_constructor, 24,
58
+ :cursor_destructor, 25,
59
+ :cursor_conversion_function, 26,
60
+ :cursor_template_type_parameter, 27,
61
+ :cursor_non_type_template_parameter, 28,
62
+ :cursor_template_template_parameter, 29,
63
+ :cursor_function_template, 30,
64
+ :cursor_class_template, 31,
65
+ :cursor_class_template_partial_specialization, 32,
66
+ :cursor_namespace_alias, 33,
67
+ :cursor_using_directive, 34,
68
+ :cursor_using_declaration, 35,
69
+ :cursor_type_alias_decl, 36,
70
+ :cursor_obj_c_synthesize_decl, 37,
71
+ :cursor_obj_c_dynamic_decl, 38,
72
+ :cursor_cxx_access_specifier, 39,
73
+ :cursor_obj_c_super_class_ref, 40,
74
+ :cursor_obj_c_protocol_ref, 41,
75
+ :cursor_obj_c_class_ref, 42,
76
+ :cursor_type_ref, 43,
77
+ :cursor_cxx_base_specifier, 44,
78
+ :cursor_template_ref, 45,
79
+ :cursor_namespace_ref, 46,
80
+ :cursor_member_ref, 47,
81
+ :cursor_label_ref, 48,
82
+ :cursor_overloaded_decl_ref, 49,
83
+ :cursor_variable_ref, 50,
84
+ :cursor_invalid_file, 70,
85
+ :cursor_no_decl_found, 71,
86
+ :cursor_not_implemented, 72,
87
+ :cursor_invalid_code, 73,
88
+ :cursor_unexposed_expr, 100,
89
+ :cursor_decl_ref_expr, 101,
90
+ :cursor_member_ref_expr, 102,
91
+ :cursor_call_expr, 103,
92
+ :cursor_obj_c_message_expr, 104,
93
+ :cursor_block_expr, 105,
94
+ :cursor_integer_literal, 106,
95
+ :cursor_floating_literal, 107,
96
+ :cursor_imaginary_literal, 108,
97
+ :cursor_string_literal, 109,
98
+ :cursor_character_literal, 110,
99
+ :cursor_paren_expr, 111,
100
+ :cursor_unary_operator, 112,
101
+ :cursor_array_subscript_expr, 113,
102
+ :cursor_binary_operator, 114,
103
+ :cursor_compound_assign_operator, 115,
104
+ :cursor_conditional_operator, 116,
105
+ :cursor_c_style_cast_expr, 117,
106
+ :cursor_compound_literal_expr, 118,
107
+ :cursor_init_list_expr, 119,
108
+ :cursor_addr_label_expr, 120,
109
+ :cursor_stmt_expr, 121,
110
+ :cursor_generic_selection_expr, 122,
111
+ :cursor_gnu_null_expr, 123,
112
+ :cursor_cxx_static_cast_expr, 124,
113
+ :cursor_cxx_dynamic_cast_expr, 125,
114
+ :cursor_cxx_reinterpret_cast_expr, 126,
115
+ :cursor_cxx_const_cast_expr, 127,
116
+ :cursor_cxx_functional_cast_expr, 128,
117
+ :cursor_cxx_typeid_expr, 129,
118
+ :cursor_cxx_bool_literal_expr, 130,
119
+ :cursor_cxx_null_ptr_literal_expr, 131,
120
+ :cursor_cxx_this_expr, 132,
121
+ :cursor_cxx_throw_expr, 133,
122
+ :cursor_cxx_new_expr, 134,
123
+ :cursor_cxx_delete_expr, 135,
124
+ :cursor_unary_expr, 136,
125
+ :cursor_obj_c_string_literal, 137,
126
+ :cursor_obj_c_encode_expr, 138,
127
+ :cursor_obj_c_selector_expr, 139,
128
+ :cursor_obj_c_protocol_expr, 140,
129
+ :cursor_obj_c_bridged_cast_expr, 141,
130
+ :cursor_pack_expansion_expr, 142,
131
+ :cursor_size_of_pack_expr, 143,
132
+ :cursor_lambda_expr, 144,
133
+ :cursor_obj_c_bool_literal_expr, 145,
134
+ :cursor_obj_c_self_expr, 146,
135
+ :cursor_unexposed_stmt, 200,
136
+ :cursor_label_stmt, 201,
137
+ :cursor_compound_stmt, 202,
138
+ :cursor_case_stmt, 203,
139
+ :cursor_default_stmt, 204,
140
+ :cursor_if_stmt, 205,
141
+ :cursor_switch_stmt, 206,
142
+ :cursor_while_stmt, 207,
143
+ :cursor_do_stmt, 208,
144
+ :cursor_for_stmt, 209,
145
+ :cursor_goto_stmt, 210,
146
+ :cursor_indirect_goto_stmt, 211,
147
+ :cursor_continue_stmt, 212,
148
+ :cursor_break_stmt, 213,
149
+ :cursor_return_stmt, 214,
150
+ :cursor_gcc_asm_stmt, 215,
151
+ :cursor_obj_c_at_try_stmt, 216,
152
+ :cursor_obj_c_at_catch_stmt, 217,
153
+ :cursor_obj_c_at_finally_stmt, 218,
154
+ :cursor_obj_c_at_throw_stmt, 219,
155
+ :cursor_obj_c_at_synchronized_stmt, 220,
156
+ :cursor_obj_c_autorelease_pool_stmt, 221,
157
+ :cursor_obj_c_for_collection_stmt, 222,
158
+ :cursor_cxx_catch_stmt, 223,
159
+ :cursor_cxx_try_stmt, 224,
160
+ :cursor_cxx_for_range_stmt, 225,
161
+ :cursor_seh_try_stmt, 226,
162
+ :cursor_seh_except_stmt, 227,
163
+ :cursor_seh_finally_stmt, 228,
164
+ :cursor_ms_asm_stmt, 229,
165
+ :cursor_null_stmt, 230,
166
+ :cursor_decl_stmt, 231,
167
+ :cursor_omp_parallel_directive, 232,
168
+ :cursor_translation_unit, 300,
169
+ :cursor_unexposed_attr, 400,
170
+ :cursor_ibaction_attr, 401,
171
+ :cursor_iboutlet_attr, 402,
172
+ :cursor_iboutlet_collection_attr, 403,
173
+ :cursor_cxx_final_attr, 404,
174
+ :cursor_cxx_override_attr, 405,
175
+ :cursor_annotate_attr, 406,
176
+ :cursor_asm_label_attr, 407,
177
+ :cursor_packed_attr, 408,
178
+ :cursor_preprocessing_directive, 500,
179
+ :cursor_macro_definition, 501,
180
+ :cursor_macro_expansion, 502,
181
+ :cursor_inclusion_directive, 503,
182
+ :cursor_module_import_decl, 600,
183
+ ]
184
+
185
+ enum :access_specifier, [
186
+ :invalid, 0,
187
+ :public, 1,
188
+ :protected, 2,
189
+ :private, 3
190
+ ]
191
+
192
+ enum :availability, [
193
+ :available, 0,
194
+ :deprecated, 1,
195
+ :not_available, 2,
196
+ :not_accesible, 3
197
+ ]
198
+
199
+ enum :linkage_kind, [
200
+ :invalid, 0,
201
+ :no_linkage, 1,
202
+ :internal, 2,
203
+ :unique_external, 3,
204
+ :external, 4,
205
+ ]
206
+
207
+ class CXCursor < FFI::Struct
208
+ layout(
209
+ :kind, :kind,
210
+ :xdata, :int,
211
+ :data, [:pointer, 3]
212
+ )
213
+ end
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
+
254
+ enum :cxx_access_specifier, [:invalid, :public, :protected, :private]
255
+ attach_function :get_cxx_access_specifier, :clang_getCXXAccessSpecifier, [CXCursor.by_value], :cxx_access_specifier
256
+
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
259
+
260
+ attach_function :is_virtual_base, :clang_isVirtualBase, [CXCursor.by_value], :uint
261
+ attach_function :is_dynamic_call, :clang_Cursor_isDynamicCall, [CXCursor.by_value], :uint
262
+ if FFI::Clang::Utils.satisfy_version?('3.3')
263
+ attach_function :is_variadic, :clang_Cursor_isVariadic, [CXCursor.by_value], :uint
264
+ end
265
+ attach_function :is_definition, :clang_isCursorDefinition, [CXCursor.by_value], :uint
266
+ attach_function :cxx_method_is_static, :clang_CXXMethod_isStatic, [CXCursor.by_value], :uint
267
+ attach_function :cxx_method_is_virtual, :clang_CXXMethod_isVirtual, [CXCursor.by_value], :uint
268
+
269
+ if FFI::Clang::Utils.satisfy_version?('3.4')
270
+ attach_function :cxx_method_is_pure_virtual, :clang_CXXMethod_isPureVirtual, [CXCursor.by_value], :uint
271
+ end
272
+ attach_function :cxx_get_access_specifier, :clang_getCXXAccessSpecifier, [CXCursor.by_value], :access_specifier
273
+
274
+ enum :language_kind, [:invalid, :c, :obj_c, :c_plus_plus]
275
+ attach_function :get_language, :clang_getCursorLanguage, [CXCursor.by_value], :language_kind
276
+
277
+ attach_function :get_canonical_cursor, :clang_getCanonicalCursor, [CXCursor.by_value], CXCursor.by_value
278
+ attach_function :get_cursor_definition, :clang_getCursorDefinition, [CXCursor.by_value], CXCursor.by_value
279
+ attach_function :get_specialized_cursor_template, :clang_getSpecializedCursorTemplate, [CXCursor.by_value], CXCursor.by_value
280
+ attach_function :get_template_cursor_kind, :clang_getTemplateCursorKind, [CXCursor.by_value], :kind
281
+
282
+ attach_function :get_translation_unit_cursor, :clang_getTranslationUnitCursor, [:CXTranslationUnit], CXCursor.by_value
283
+ attach_function :cursor_get_translation_unit, :clang_Cursor_getTranslationUnit, [CXCursor.by_value], :CXTranslationUnit
284
+
285
+ attach_function :get_null_cursor, :clang_getNullCursor, [], CXCursor.by_value
286
+
287
+ attach_function :cursor_is_null, :clang_Cursor_isNull, [CXCursor.by_value], :int
288
+
289
+ attach_function :cursor_get_comment_range, :clang_Cursor_getCommentRange, [CXCursor.by_value], CXSourceRange.by_value
290
+ attach_function :cursor_get_raw_comment_text, :clang_Cursor_getRawCommentText, [CXCursor.by_value], CXString.by_value
291
+ attach_function :cursor_get_parsed_comment, :clang_Cursor_getParsedComment, [CXCursor.by_value], CXComment.by_value
292
+
293
+ attach_function :get_cursor, :clang_getCursor, [:CXTranslationUnit, CXSourceLocation.by_value], CXCursor.by_value
294
+ attach_function :get_cursor_location, :clang_getCursorLocation, [CXCursor.by_value], CXSourceLocation.by_value
295
+ attach_function :get_cursor_extent, :clang_getCursorExtent, [CXCursor.by_value], CXSourceRange.by_value
296
+ attach_function :get_cursor_display_name, :clang_getCursorDisplayName, [CXCursor.by_value], CXString.by_value
297
+ attach_function :get_cursor_spelling, :clang_getCursorSpelling, [CXCursor.by_value], CXString.by_value
298
+ attach_function :get_cursor_usr, :clang_getCursorUSR, [CXCursor.by_value], CXString.by_value
299
+ attach_function :get_cursor_kind_spelling, :clang_getCursorKindSpelling, [:kind], CXString.by_value
300
+
301
+ attach_function :are_equal, :clang_equalCursors, [CXCursor.by_value, CXCursor.by_value], :uint
302
+
303
+ attach_function :is_declaration, :clang_isDeclaration, [:kind], :uint
304
+ attach_function :is_reference, :clang_isReference, [:kind], :uint
305
+ attach_function :is_expression, :clang_isExpression, [:kind], :uint
306
+ attach_function :is_statement, :clang_isStatement, [:kind], :uint
307
+ attach_function :is_attribute, :clang_isAttribute, [:kind], :uint
308
+ attach_function :is_invalid, :clang_isInvalid, [:kind], :uint
309
+ attach_function :is_translation_unit, :clang_isTranslationUnit, [:kind], :uint
310
+ attach_function :is_preprocessing, :clang_isPreprocessing, [:kind], :uint
311
+ attach_function :is_unexposed, :clang_isUnexposed, [:kind], :uint
312
+
313
+ enum :child_visit_result, [:break, :continue, :recurse]
314
+
315
+ callback :visit_children_function, [CXCursor.by_value, CXCursor.by_value, :pointer], :child_visit_result
316
+ attach_function :visit_children, :clang_visitChildren, [CXCursor.by_value, :visit_children_function, :pointer], :uint
317
+
318
+ attach_function :get_cursor_type, :clang_getCursorType, [CXCursor.by_value], CXType.by_value
319
+ attach_function :get_cursor_result_type, :clang_getCursorResultType, [CXCursor.by_value], CXType.by_value
320
+ attach_function :get_typedef_decl_underlying_type, :clang_getTypedefDeclUnderlyingType, [CXCursor.by_value], CXType.by_value
321
+ attach_function :get_enum_decl_integer_type, :clang_getEnumDeclIntegerType, [CXCursor.by_value], CXType.by_value
322
+ attach_function :get_type_declaration, :clang_getTypeDeclaration, [CXType.by_value], FFI::Clang::Lib::CXCursor.by_value
323
+
324
+ attach_function :get_cursor_referenced, :clang_getCursorReferenced, [CXCursor.by_value], CXCursor.by_value
325
+ attach_function :get_cursor_semantic_parent, :clang_getCursorSemanticParent, [CXCursor.by_value], CXCursor.by_value
326
+ attach_function :get_cursor_lexical_parent, :clang_getCursorLexicalParent, [CXCursor.by_value], CXCursor.by_value
327
+
328
+ attach_function :get_cursor_availability, :clang_getCursorAvailability, [CXCursor.by_value], :availability
329
+ attach_function :get_cursor_linkage, :clang_getCursorLinkage, [CXCursor.by_value], :linkage_kind
330
+ attach_function :get_included_file, :clang_getIncludedFile, [CXCursor.by_value], :CXFile
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
351
+ end
352
+ end
353
+ end