ffi-clang 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.travis.yml +20 -9
  4. data/Gemfile +10 -1
  5. data/README.md +1 -1
  6. data/Rakefile +9 -9
  7. data/examples/docs.cpp +25 -0
  8. data/examples/docs.rb +31 -0
  9. data/ffi-clang.gemspec +1 -1
  10. data/lib/ffi/clang.rb +16 -13
  11. data/lib/ffi/clang/clang_version.rb +29 -0
  12. data/lib/ffi/clang/code_completion.rb +1 -1
  13. data/lib/ffi/clang/comment.rb +8 -4
  14. data/lib/ffi/clang/compilation_database.rb +1 -1
  15. data/lib/ffi/clang/cursor.rb +42 -15
  16. data/lib/ffi/clang/diagnostic.rb +6 -2
  17. data/lib/ffi/clang/file.rb +6 -9
  18. data/lib/ffi/clang/index.rb +4 -4
  19. data/lib/ffi/clang/lib.rb +1 -1
  20. data/lib/ffi/clang/lib/{utils.rb → clang_version.rb} +1 -1
  21. data/lib/ffi/clang/lib/code_completion.rb +2 -3
  22. data/lib/ffi/clang/lib/comment.rb +0 -2
  23. data/lib/ffi/clang/lib/compilation_database.rb +6 -9
  24. data/lib/ffi/clang/lib/cursor.rb +10 -18
  25. data/lib/ffi/clang/lib/diagnostic.rb +4 -4
  26. data/lib/ffi/clang/lib/file.rb +4 -6
  27. data/lib/ffi/clang/lib/inclusions.rb +2 -2
  28. data/lib/ffi/clang/lib/index.rb +0 -2
  29. data/lib/ffi/clang/lib/source_location.rb +6 -8
  30. data/lib/ffi/clang/lib/source_range.rb +1 -1
  31. data/lib/ffi/clang/lib/string.rb +0 -2
  32. data/lib/ffi/clang/lib/translation_unit.rb +2 -2
  33. data/lib/ffi/clang/lib/type.rb +8 -17
  34. data/lib/ffi/clang/source_location.rb +2 -2
  35. data/lib/ffi/clang/source_range.rb +16 -3
  36. data/lib/ffi/clang/token.rb +4 -4
  37. data/lib/ffi/clang/translation_unit.rb +5 -5
  38. data/lib/ffi/clang/type.rb +0 -14
  39. data/lib/ffi/clang/version.rb +2 -2
  40. data/spec/{clang → ffi/clang}/code_completion_spec.rb +6 -6
  41. data/spec/{clang → ffi/clang}/comment_spec.rb +22 -39
  42. data/spec/{clang → ffi/clang}/compilation_database_spec.rb +8 -10
  43. data/spec/{clang → ffi/clang}/cursor_spec.rb +89 -97
  44. data/spec/{clang → ffi/clang}/diagnostic_spec.rb +9 -10
  45. data/spec/{clang → ffi/clang}/file_spec.rb +3 -5
  46. data/spec/{fixtures → ffi/clang/fixtures}/a.c +0 -0
  47. data/spec/{fixtures → ffi/clang/fixtures}/canonical.c +0 -0
  48. data/spec/ffi/clang/fixtures/class.cpp +8 -0
  49. data/spec/{fixtures → ffi/clang/fixtures}/compile_commands.json +0 -0
  50. data/spec/{fixtures → ffi/clang/fixtures}/completion.cxx +0 -0
  51. data/spec/{fixtures → ffi/clang/fixtures}/docs.c +0 -0
  52. data/spec/{fixtures → ffi/clang/fixtures}/docs.cc +0 -0
  53. data/spec/{fixtures → ffi/clang/fixtures}/docs.h +0 -0
  54. data/spec/{fixtures → ffi/clang/fixtures}/list.c +0 -0
  55. data/spec/{fixtures → ffi/clang/fixtures}/location1.c +0 -0
  56. data/spec/ffi/clang/fixtures/simple.ast +0 -0
  57. data/spec/{fixtures → ffi/clang/fixtures}/simple.c +0 -0
  58. data/spec/{fixtures → ffi/clang/fixtures}/test.cxx +0 -0
  59. data/spec/{clang → ffi/clang}/index_spec.rb +17 -14
  60. data/spec/{clang → ffi/clang}/source_location_spec.rb +12 -14
  61. data/spec/{clang → ffi/clang}/source_range_spec.rb +12 -14
  62. data/spec/{clang → ffi/clang}/token_spec.rb +6 -8
  63. data/spec/{clang → ffi/clang}/translation_unit_spec.rb +28 -30
  64. data/spec/{clang → ffi/clang}/type_spec.rb +17 -33
  65. data/spec/ffi/clang/version_spec.rb +28 -0
  66. data/spec/spec_helper.rb +11 -37
  67. metadata +61 -55
  68. data/lib/ffi/clang/utils.rb +0 -89
  69. data/spec/clang/utils_spec.rb +0 -60
@@ -38,7 +38,7 @@ module FFI
38
38
  begin
39
39
  xcode_dir = `xcode-select -p`.chomp
40
40
  libs << "#{xcode_dir}/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib"
41
- rescue Errno::ENOENT => e
41
+ rescue Errno::ENOENT
42
42
  # Ignore
43
43
  end
44
44
 
@@ -18,7 +18,7 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'ffi/clang/lib/string'
21
+ require_relative 'string'
22
22
 
23
23
  module FFI
24
24
  module Clang
@@ -18,9 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'ffi/clang/lib/translation_unit'
22
- require 'ffi/clang/lib/cursor'
23
- require 'ffi/clang/lib/diagnostic'
21
+ require_relative 'cursor'
22
+ require_relative 'diagnostic'
24
23
 
25
24
  module FFI
26
25
  module Clang
@@ -19,8 +19,6 @@
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
21
 
22
- require 'ffi/clang/lib/index'
23
-
24
22
  module FFI
25
23
  module Clang
26
24
  module Lib
@@ -34,9 +34,7 @@ module FFI
34
34
  attach_function :compilation_database_from_directory, :clang_CompilationDatabase_fromDirectory, [:string, :pointer], :CXCompilationDatabase
35
35
  attach_function :compilation_database_dispose, :clang_CompilationDatabase_dispose, [:CXCompilationDatabase], :uint
36
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
37
+ attach_function :compilation_database_get_all_compile_commands, :clang_CompilationDatabase_getAllCompileCommands, [:CXCompilationDatabase], :CXCompileCommands
40
38
 
41
39
  # CompilationDatabase::CompileCommands
42
40
  attach_function :compile_commands_dispose, :clang_CompileCommands_dispose, [:CXCompileCommands], :void
@@ -47,12 +45,11 @@ module FFI
47
45
  attach_function :compile_command_get_directory, :clang_CompileCommand_getDirectory, [:CXCompileCommand], CXString.by_value
48
46
  attach_function :compile_command_get_num_args, :clang_CompileCommand_getNumArgs, [:CXCompileCommand], :uint
49
47
  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
48
+
49
+ # Thease functions are not exposed by libclang.so privided by packages.
50
+ # attach_function :compile_command_get_num_mapped_sources, :clang_CompileCommand_getNumMappedSources, [:CXCompileCommand], :uint
51
+ # attach_function :compile_command_get_mapped_source_path, :clang_CompileCommand_getMappedSourcePath, [:CXCompileCommand, :uint], CXString.by_value
52
+ # attach_function :compile_command_get_mapped_source_content, :clang_CompileCommand_getMappedSourceContent, [:CXCompileCommand, :uint], CXString.by_value
56
53
  end
57
54
  end
58
55
  end
@@ -21,11 +21,10 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
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'
24
+ require_relative 'translation_unit'
25
+ require_relative 'diagnostic'
26
+ require_relative 'comment'
27
+ require_relative 'type'
29
28
 
30
29
  module FFI
31
30
  module Clang
@@ -259,16 +258,14 @@ module FFI
259
258
 
260
259
  attach_function :is_virtual_base, :clang_isVirtualBase, [CXCursor.by_value], :uint
261
260
  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
261
+ attach_function :is_variadic, :clang_Cursor_isVariadic, [CXCursor.by_value], :uint
262
+
265
263
  attach_function :is_definition, :clang_isCursorDefinition, [CXCursor.by_value], :uint
266
264
  attach_function :cxx_method_is_static, :clang_CXXMethod_isStatic, [CXCursor.by_value], :uint
267
265
  attach_function :cxx_method_is_virtual, :clang_CXXMethod_isVirtual, [CXCursor.by_value], :uint
268
266
 
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
267
+ attach_function :cxx_method_is_pure_virtual, :clang_CXXMethod_isPureVirtual, [CXCursor.by_value], :uint
268
+
272
269
  attach_function :cxx_get_access_specifier, :clang_getCXXAccessSpecifier, [CXCursor.by_value], :access_specifier
273
270
 
274
271
  enum :language_kind, [:invalid, :c, :obj_c, :c_plus_plus]
@@ -330,10 +327,8 @@ module FFI
330
327
  attach_function :get_included_file, :clang_getIncludedFile, [CXCursor.by_value], :CXFile
331
328
  attach_function :get_cursor_hash, :clang_hashCursor, [CXCursor.by_value], :uint
332
329
 
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
330
+ attach_function :is_bit_field,:clang_Cursor_isBitField, [CXCursor.by_value], :uint
331
+ attach_function :get_field_decl_bit_width, :clang_getFieldDeclBitWidth, [CXCursor.by_value], :int
337
332
 
338
333
  attach_function :get_overloaded_decl, :clang_getOverloadedDecl, [CXCursor.by_value, :uint], CXCursor.by_value
339
334
  attach_function :get_num_overloaded_decls, :clang_getNumOverloadedDecls, [CXCursor.by_value], :uint
@@ -350,13 +345,10 @@ module FFI
350
345
  attach_function :dispose_overridden_cursors, :clang_disposeOverriddenCursors, [:pointer], :void
351
346
 
352
347
  attach_function :get_typedef_decl_unerlying_type, :clang_getTypedefDeclUnderlyingType, [CXCursor.by_value], CXType.by_value
353
- attach_function :get_type_declaration, :clang_getTypeDeclaration, [CXType.by_value], CXCursor.by_value
354
348
 
355
349
  attach_function :get_enum_type, :clang_getEnumDeclIntegerType, [CXCursor.by_value], CXType.by_value
356
350
 
357
351
  attach_function :get_num_args, :clang_Cursor_getNumArguments, [CXCursor.by_value], :int
358
-
359
- attach_function :is_variadic, :clang_Cursor_isVariadic, [CXCursor.by_value], :uint
360
352
  end
361
353
  end
362
354
  end
@@ -19,9 +19,9 @@
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
21
 
22
- require 'ffi/clang/lib/translation_unit'
23
- require 'ffi/clang/lib/source_location'
24
- require 'ffi/clang/lib/string'
22
+ require_relative 'translation_unit'
23
+ require_relative 'source_location'
24
+ require_relative 'string'
25
25
 
26
26
  module FFI
27
27
  module Clang
@@ -54,7 +54,7 @@ module FFI
54
54
  attach_function :dispose_diagnostic, :clang_disposeDiagnostic, [:CXDiagnostic], :void
55
55
 
56
56
  # DiagnosticSet (not used yet)
57
- # attach_function :get_diagnostic_set_from_tu, :clang_getDiagnosticSetFromTU, [:CXTranslationUnit], :CXDiagnosticSet
57
+ # attach_function :get_diagnostic_set_from_translation_unit, :clang_getDiagnosticSetFromTU, [:CXTranslationUnit], :CXDiagnosticSet
58
58
  # attach_function :dispose_diagnostic_set, :clang_disposeDiagnosticSet, [:CXDiagnosticSet], :void
59
59
  # attach_function :load_diagnostics, :clang_loadDiagnostics, [:string, :pointer, :pointer], :CXDiagnosticSet
60
60
 
@@ -20,9 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'ffi/clang/lib/string'
24
- require 'ffi/clang/lib/translation_unit'
25
- require 'ffi/clang/utils'
23
+ require_relative 'string'
24
+ require_relative 'translation_unit'
26
25
 
27
26
  module FFI
28
27
  module Clang
@@ -49,9 +48,8 @@ module FFI
49
48
  attach_function :get_file_name, :clang_getFileName, [:CXFile], CXString.by_value
50
49
  attach_function :get_file_time, :clang_getFileTime, [:CXFile], :time_t
51
50
  attach_function :is_file_multiple_include_guarded, :clang_isFileMultipleIncludeGuarded, [:CXTranslationUnit, :CXFile], :int
52
- if FFI::Clang::Utils.satisfy_version?('3.3')
53
- attach_function :get_file_unique_id, :clang_getFileUniqueID, [:CXFile, :pointer], :int
54
- end
51
+
52
+ attach_function :get_file_unique_id, :clang_getFileUniqueID, [:CXFile, :pointer], :int
55
53
  end
56
54
  end
57
55
  end
@@ -18,8 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'ffi/clang/lib/file'
22
- require 'ffi/clang/lib/source_location'
21
+ require_relative 'file'
22
+ require_relative 'source_location'
23
23
 
24
24
  module FFI
25
25
  module Clang
@@ -19,8 +19,6 @@
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
21
 
22
- require 'ffi/clang/lib'
23
-
24
22
  module FFI
25
23
  module Clang
26
24
  module Lib
@@ -20,7 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'ffi/clang/lib/file'
23
+ require_relative 'file'
24
24
 
25
25
  module FFI
26
26
  module Clang
@@ -39,15 +39,13 @@ module FFI
39
39
  attach_function :get_location_offset, :clang_getLocationForOffset, [:CXTranslationUnit, :CXFile, :uint], CXSourceLocation.by_value
40
40
  attach_function :get_expansion_location, :clang_getExpansionLocation, [CXSourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
41
41
  attach_function :get_presumed_location, :clang_getPresumedLocation, [CXSourceLocation.by_value, :pointer, :pointer, :pointer], :void
42
- if FFI::Clang::Utils.satisfy_version?('3.3')
43
- attach_function :get_file_location, :clang_getFileLocation, [CXSourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
44
- end
42
+
43
+ attach_function :get_file_location, :clang_getFileLocation, [CXSourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
44
+
45
45
  attach_function :get_spelling_location, :clang_getSpellingLocation, [CXSourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
46
46
 
47
- if FFI::Clang::Utils.satisfy_version?('3.4')
48
- attach_function :location_in_system_header, :clang_Location_isInSystemHeader, [CXSourceLocation.by_value], :int
49
- attach_function :location_is_from_main_file, :clang_Location_isFromMainFile, [CXSourceLocation.by_value], :int
50
- end
47
+ attach_function :location_in_system_header, :clang_Location_isInSystemHeader, [CXSourceLocation.by_value], :int
48
+ attach_function :location_is_from_main_file, :clang_Location_isFromMainFile, [CXSourceLocation.by_value], :int
51
49
  end
52
50
  end
53
51
  end
@@ -22,7 +22,7 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
23
  # THE SOFTWARE.
24
24
 
25
- require 'ffi/clang/lib/source_location'
25
+ require_relative 'source_location'
26
26
 
27
27
  module FFI
28
28
  module Clang
@@ -19,8 +19,6 @@
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
21
 
22
- require 'ffi/clang/lib'
23
-
24
22
  module FFI
25
23
  module Clang
26
24
  module Lib
@@ -20,7 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'ffi/clang/lib/index'
23
+ require_relative 'index'
24
24
 
25
25
  module FFI
26
26
  module Clang
@@ -47,7 +47,7 @@ module FFI
47
47
  :none, 0,
48
48
  :unknown, 1,
49
49
  :translation_errors, 2,
50
- :invalid_tu, 3
50
+ :invalid_translation_unit, 3
51
51
  ]
52
52
 
53
53
  ReparseFlags = enum [
@@ -112,9 +112,7 @@ module FFI
112
112
  end
113
113
 
114
114
  attach_function :get_type_kind_spelling, :clang_getTypeKindSpelling, [:kind], CXString.by_value
115
- if FFI::Clang::Utils.satisfy_version?('3.3')
116
- attach_function :get_type_spelling, :clang_getTypeSpelling, [CXType.by_value], CXString.by_value
117
- end
115
+ attach_function :get_type_spelling, :clang_getTypeSpelling, [CXType.by_value], CXString.by_value
118
116
 
119
117
  attach_function :is_function_type_variadic, :clang_isFunctionTypeVariadic, [CXType.by_value], :uint
120
118
  attach_function :is_pod_type, :clang_isPODType, [CXType.by_value], :uint
@@ -122,9 +120,8 @@ module FFI
122
120
  attach_function :get_pointee_type, :clang_getPointeeType, [CXType.by_value], CXType.by_value
123
121
  attach_function :get_result_type, :clang_getResultType, [CXType.by_value], CXType.by_value
124
122
  attach_function :get_canonical_type, :clang_getCanonicalType, [CXType.by_value], CXType.by_value
125
- if FFI::Clang::Utils.satisfy_version?('3.4')
126
- attach_function :type_get_class_type, :clang_Type_getClassType, [CXType.by_value], CXType.by_value
127
- end
123
+
124
+ attach_function :type_get_class_type, :clang_Type_getClassType, [CXType.by_value], CXType.by_value
128
125
 
129
126
  attach_function :is_const_qualified_type, :clang_isConstQualifiedType, [CXType.by_value], :uint
130
127
  attach_function :is_volatile_qualified_type, :clang_isVolatileQualifiedType, [CXType.by_value], :uint
@@ -137,21 +134,15 @@ module FFI
137
134
  attach_function :get_array_size, :clang_getArraySize, [CXType.by_value], :long_long
138
135
  attach_function :get_array_element_type ,:clang_getArrayElementType, [CXType.by_value], CXType.by_value
139
136
 
140
- if FFI::Clang::Utils.satisfy_version?('3.3')
141
- attach_function :type_get_align_of, :clang_Type_getAlignOf, [CXType.by_value], :long_long
142
- attach_function :type_get_size_of, :clang_Type_getSizeOf, [CXType.by_value], :long_long
143
- attach_function :type_get_offset_of, :clang_Type_getOffsetOf, [CXType.by_value, :string], :long_long
144
- end
137
+ attach_function :type_get_align_of, :clang_Type_getAlignOf, [CXType.by_value], :long_long
138
+ attach_function :type_get_size_of, :clang_Type_getSizeOf, [CXType.by_value], :long_long
139
+ attach_function :type_get_offset_of, :clang_Type_getOffsetOf, [CXType.by_value, :string], :long_long
145
140
 
146
- if FFI::Clang::Utils.satisfy_version?('3.4')
147
- attach_function :type_get_cxx_ref_qualifier, :clang_Type_getCXXRefQualifier, [CXType.by_value], :ref_qualifier_kind
148
- end
141
+ attach_function :type_get_cxx_ref_qualifier, :clang_Type_getCXXRefQualifier, [CXType.by_value], :ref_qualifier_kind
142
+
149
143
  attach_function :get_fuction_type_calling_conv, :clang_getFunctionTypeCallingConv, [CXType.by_value], :calling_conv
150
144
 
151
145
  attach_function :equal_types, :clang_equalTypes, [CXType.by_value, CXType.by_value], :uint
152
-
153
- attach_function :get_array_element_type, :clang_getArrayElementType, [CXType.by_value], CXType.by_value
154
- attach_function :get_array_size, :clang_getArraySize, [CXType.by_value], :int
155
146
  end
156
147
  end
157
148
  end
@@ -20,8 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'ffi/clang/lib/source_location'
24
- require 'ffi/clang/lib/file'
23
+ require_relative 'lib/source_location'
24
+ require_relative 'lib/file'
25
25
 
26
26
  module FFI
27
27
  module Clang
@@ -22,7 +22,7 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
23
  # THE SOFTWARE.
24
24
 
25
- require 'ffi/clang/lib/source_range'
25
+ require_relative 'lib/source_range'
26
26
 
27
27
  module FFI
28
28
  module Clang
@@ -40,11 +40,24 @@ module FFI
40
40
  end
41
41
 
42
42
  def start
43
- ExpansionLocation.new(Lib.get_range_start @range)
43
+ @start ||= ExpansionLocation.new(Lib.get_range_start @range)
44
44
  end
45
45
 
46
46
  def end
47
- ExpansionLocation.new(Lib.get_range_end @range)
47
+ @end ||= ExpansionLocation.new(Lib.get_range_end @range)
48
+ end
49
+
50
+ # The size, in bytes, of the source range.
51
+ def bytesize
52
+ self.end.offset - self.start.offset
53
+ end
54
+
55
+ # Read the part of the source file referred to by this source range.
56
+ def text
57
+ ::File.open(self.start.file, "r") do |file|
58
+ file.seek(self.start.offset)
59
+ return file.read(self.bytesize)
60
+ end
48
61
  end
49
62
 
50
63
  def null?
@@ -18,9 +18,9 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'ffi/clang/lib/token'
22
- require 'ffi/clang/lib/cursor'
23
- require 'ffi/clang/source_location'
21
+ require_relative 'lib/token'
22
+ require_relative 'lib/cursor'
23
+ require_relative 'source_location'
24
24
 
25
25
  module FFI
26
26
  module Clang
@@ -46,7 +46,7 @@ module FFI
46
46
  end
47
47
 
48
48
  def self.release(pointer)
49
- Lib.dispose_tokens(pointer, pointer.token_size, pointer.translation_unit)
49
+ Lib.dispose_tokens(pointer.translation_unit, pointer, pointer.token_size)
50
50
  end
51
51
 
52
52
  def each(&block)
@@ -20,11 +20,11 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'ffi/clang/lib/translation_unit'
24
- require 'ffi/clang/lib/inclusions'
25
- require 'ffi/clang/cursor'
26
- require 'ffi/clang/file'
27
- require 'ffi/clang/token'
23
+ require_relative 'lib/translation_unit'
24
+ require_relative 'lib/inclusions'
25
+ require_relative 'cursor'
26
+ require_relative 'file'
27
+ require_relative 'token'
28
28
 
29
29
  module FFI
30
30
  module Clang
@@ -19,8 +19,6 @@
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
21
 
22
- require 'ffi/clang/cursor'
23
-
24
22
  module FFI
25
23
  module Clang
26
24
  class Type
@@ -130,18 +128,6 @@ module FFI
130
128
  def ==(other)
131
129
  Lib.equal_types(@type, other.type) != 0
132
130
  end
133
-
134
- def declaration
135
- Cursor.new Lib.get_type_declaration(@type), @translation_unit
136
- end
137
-
138
- def element_type
139
- Type.new Lib.get_array_element_type(@type), @translation_unit
140
- end
141
-
142
- def array_size
143
- Lib.get_array_size(@type)
144
- end
145
131
  end
146
132
  end
147
133
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright, 2010-2012 by Jari Bakken.
2
- # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,6 @@
21
21
 
22
22
  module FFI
23
23
  module Clang
24
- VERSION = "0.3.0"
24
+ VERSION = "0.5.0"
25
25
  end
26
26
  end