ffi-clang 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -35,33 +35,53 @@ module FFI
|
|
35
35
|
end
|
36
36
|
|
37
37
|
typedef :pointer, :CXDiagnostic
|
38
|
+
typedef :pointer, :CXDiagnosticSet
|
39
|
+
|
40
|
+
DiagnosticDisplayOptions = enum [
|
41
|
+
:source_location, 0x01,
|
42
|
+
:column, 0x02,
|
43
|
+
:source_ranges, 0x04,
|
44
|
+
:option, 0x08,
|
45
|
+
:category_id, 0x10,
|
46
|
+
:category_name , 0x20,
|
47
|
+
]
|
48
|
+
|
49
|
+
enum :diagnostic_severity, [:ignored, :note, :warning, :error, :fatal]
|
38
50
|
|
39
51
|
# Source code diagnostics:
|
40
52
|
attach_function :get_num_diagnostics, :clang_getNumDiagnostics, [:CXTranslationUnit], :uint
|
41
|
-
attach_function :get_diagnostic, :clang_getDiagnostic, [:CXTranslationUnit,
|
53
|
+
attach_function :get_diagnostic, :clang_getDiagnostic, [:CXTranslationUnit, :uint], :CXDiagnostic
|
42
54
|
attach_function :dispose_diagnostic, :clang_disposeDiagnostic, [:CXDiagnostic], :void
|
43
55
|
|
44
|
-
|
56
|
+
# DiagnosticSet (not used yet)
|
57
|
+
# attach_function :get_diagnostic_set_from_tu, :clang_getDiagnosticSetFromTU, [:CXTranslationUnit], :CXDiagnosticSet
|
58
|
+
# attach_function :dispose_diagnostic_set, :clang_disposeDiagnosticSet, [:CXDiagnosticSet], :void
|
59
|
+
# attach_function :load_diagnostics, :clang_loadDiagnostics, [:string, :pointer, :pointer], :CXDiagnosticSet
|
45
60
|
|
46
61
|
# Diagnostic details and string representations:
|
47
|
-
|
62
|
+
attach_function :get_diagnostic_spelling, :clang_getDiagnosticSpelling, [:CXDiagnostic], CXString.by_value
|
48
63
|
attach_function :default_diagnostic_display_options, :clang_defaultDiagnosticDisplayOptions, [], :uint
|
49
64
|
attach_function :format_diagnostic, :clang_formatDiagnostic, [:CXDiagnostic, :uint], CXString.by_value
|
50
|
-
|
51
|
-
attach_function :get_diagnostic_spelling, :clang_getDiagnosticSpelling, [:CXDiagnostic], CXString.by_value
|
52
|
-
|
53
|
-
enum :diagnostic_severity, [:ignored, :note, :warning, :error, :fatal]
|
54
65
|
attach_function :get_diagnostic_severity, :clang_getDiagnosticSeverity, [:CXDiagnostic], :diagnostic_severity
|
66
|
+
attach_function :get_diagnostic_option, :clang_getDiagnosticOption, [:CXDiagnostic, :pointer], CXString.by_value
|
55
67
|
|
56
|
-
# Diagnostic source ranges:
|
68
|
+
# Diagnostic source location and source ranges:
|
69
|
+
attach_function :get_diagnostic_location, :clang_getDiagnosticLocation, [:CXDiagnostic], CXSourceLocation.by_value
|
57
70
|
attach_function :get_diagnostic_num_ranges, :clang_getDiagnosticNumRanges, [:CXDiagnostic], :uint
|
58
71
|
attach_function :get_diagnostic_range, :clang_getDiagnosticRange, [:CXDiagnostic, :uint], CXSourceRange.by_value
|
59
72
|
|
60
|
-
#
|
61
|
-
attach_function :
|
62
|
-
attach_function :
|
73
|
+
# Child Diagnostics:
|
74
|
+
attach_function :get_child_diagnostics, :clang_getChildDiagnostics, [:CXDiagnostic], :CXDiagnosticSet
|
75
|
+
attach_function :get_num_diagnostics_in_set, :clang_getNumDiagnosticsInSet, [:CXDiagnosticSet], :uint
|
76
|
+
attach_function :get_diagnostic_in_set, :clang_getDiagnosticInSet, [:CXDiagnosticSet, :uint], :CXDiagnostic
|
77
|
+
|
78
|
+
# Category:
|
79
|
+
attach_function :get_diagnostic_category, :clang_getDiagnosticCategory, [:CXDiagnostic], :uint
|
80
|
+
attach_function :get_diagnostic_category_text, :clang_getDiagnosticCategoryText, [:CXDiagnostic], CXString.by_value
|
63
81
|
|
64
|
-
|
82
|
+
# Fixit:
|
83
|
+
attach_function :get_diagnostic_num_fix_its, :clang_getDiagnosticNumFixIts, [:CXDiagnostic], :uint
|
84
|
+
attach_function :get_diagnostic_fix_it, :clang_getDiagnosticFixIt, [:CXDiagnostic, :uint, :pointer], CXString.by_value
|
65
85
|
end
|
66
86
|
end
|
67
87
|
end
|
data/lib/ffi/clang/lib/file.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
|
@@ -21,6 +22,7 @@
|
|
21
22
|
|
22
23
|
require 'ffi/clang/lib/string'
|
23
24
|
require 'ffi/clang/lib/translation_unit'
|
25
|
+
require 'ffi/clang/utils'
|
24
26
|
|
25
27
|
module FFI
|
26
28
|
module Clang
|
@@ -33,13 +35,23 @@ module FFI
|
|
33
35
|
)
|
34
36
|
end
|
35
37
|
|
38
|
+
class CXFileUniqueID < FFI::Struct
|
39
|
+
layout(
|
40
|
+
:device, :ulong_long,
|
41
|
+
:inode, :ulong_long,
|
42
|
+
:modification, :ulong_long
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
36
46
|
typedef :pointer, :CXFile
|
37
47
|
|
38
|
-
# Retrieve a file handle within the given translation unit.
|
39
48
|
attach_function :get_file, :clang_getFile, [:CXTranslationUnit, :string], :CXFile
|
40
|
-
|
41
|
-
# Retrieve the complete file and path name of the given file.
|
42
49
|
attach_function :get_file_name, :clang_getFileName, [:CXFile], CXString.by_value
|
50
|
+
attach_function :get_file_time, :clang_getFileTime, [:CXFile], :time_t
|
51
|
+
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
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright, 2014, by Greg Hazel
|
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/lib/source_location'
|
23
|
+
|
24
|
+
module FFI
|
25
|
+
module Clang
|
26
|
+
module Lib
|
27
|
+
# Source code inclusions:
|
28
|
+
callback :visit_inclusion_function, [:CXFile, :pointer, :uint, :pointer], :void
|
29
|
+
attach_function :get_inclusions, :clang_getInclusions, [:CXTranslationUnit, :visit_inclusion_function, :pointer], :void
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -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
|
@@ -19,6 +20,8 @@
|
|
19
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
21
|
# THE SOFTWARE.
|
21
22
|
|
23
|
+
require 'ffi/clang/lib/file'
|
24
|
+
|
22
25
|
module FFI
|
23
26
|
module Clang
|
24
27
|
module Lib
|
@@ -29,7 +32,22 @@ module FFI
|
|
29
32
|
)
|
30
33
|
end
|
31
34
|
|
35
|
+
attach_function :get_null_location, :clang_getNullLocation, [], CXSourceLocation.by_value
|
36
|
+
attach_function :equal_locations, :clang_equalLocations, [CXSourceLocation.by_value, CXSourceLocation.by_value], :int
|
37
|
+
|
38
|
+
attach_function :get_location, :clang_getLocation, [:CXTranslationUnit, :CXFile, :uint, :uint], CXSourceLocation.by_value
|
39
|
+
attach_function :get_location_offset, :clang_getLocationForOffset, [:CXTranslationUnit, :CXFile, :uint], CXSourceLocation.by_value
|
32
40
|
attach_function :get_expansion_location, :clang_getExpansionLocation, [CXSourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
|
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
|
45
|
+
attach_function :get_spelling_location, :clang_getSpellingLocation, [CXSourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
|
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
|
33
51
|
end
|
34
52
|
end
|
35
53
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# Copyright, 2010-2012 by Jari Bakken.
|
3
3
|
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
4
|
# Copyright, 2013, by Garry C. Marshall. <http://www.meaningfulname.net>
|
5
|
+
# Copyright, 2014, by Masahiro Sano.
|
5
6
|
#
|
6
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
8
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -34,8 +35,12 @@ module FFI
|
|
34
35
|
)
|
35
36
|
end
|
36
37
|
|
38
|
+
attach_function :get_null_range, :clang_getNullRange, [], CXSourceLocation.by_value
|
39
|
+
attach_function :get_range, :clang_getRange, [CXSourceLocation.by_value, CXSourceLocation.by_value], CXSourceRange.by_value
|
37
40
|
attach_function :get_range_start, :clang_getRangeStart, [CXSourceRange.by_value], CXSourceLocation.by_value
|
38
41
|
attach_function :get_range_end, :clang_getRangeEnd, [CXSourceRange.by_value], CXSourceLocation.by_value
|
42
|
+
attach_function :range_is_null, :clang_Range_isNull, [CXSourceRange.by_value], :int
|
43
|
+
attach_function :equal_range, :clang_equalRanges, [CXSourceRange.by_value, CXSourceRange.by_value], :uint
|
39
44
|
end
|
40
45
|
end
|
41
46
|
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
|
+
class CXToken < FFI::Struct
|
25
|
+
layout(
|
26
|
+
:int_data, [:uint, 4],
|
27
|
+
:ptr_data, :pointer,
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
class TokensPointer < FFI::Pointer
|
32
|
+
attr_reader :token_size
|
33
|
+
attr_reader :translation_unit
|
34
|
+
def initialize(ptr, token_size, translation_unit)
|
35
|
+
super ptr
|
36
|
+
@token_size = token_size
|
37
|
+
@translation_unit = translation_unit
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
enum :token_kind, [
|
42
|
+
:punctuation,
|
43
|
+
:keyword,
|
44
|
+
:identifier,
|
45
|
+
:literal,
|
46
|
+
:comment,
|
47
|
+
]
|
48
|
+
|
49
|
+
attach_function :get_token_kind, :clang_getTokenKind, [CXToken.by_value], :token_kind
|
50
|
+
attach_function :get_token_spelliing, :clang_getTokenSpelling, [:CXTranslationUnit, CXToken.by_value], CXString.by_value
|
51
|
+
attach_function :get_token_location, :clang_getTokenLocation, [:CXTranslationUnit, CXToken.by_value], CXSourceLocation.by_value
|
52
|
+
attach_function :get_token_extent, :clang_getTokenExtent, [:CXTranslationUnit, CXToken.by_value], CXSourceRange.by_value
|
53
|
+
attach_function :tokenize, :clang_tokenize, [:CXTranslationUnit, CXSourceRange.by_value, :pointer, :pointer], :void
|
54
|
+
attach_function :annotate_tokens, :clang_annotateTokens, [:CXTranslationUnit, :pointer, :uint, :pointer], :void
|
55
|
+
attach_function :dispose_tokens, :clang_disposeTokens, [:CXTranslationUnit, :pointer, :uint], :void
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -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
|
@@ -26,11 +27,80 @@ module FFI
|
|
26
27
|
module Lib
|
27
28
|
typedef :pointer, :CXTranslationUnit
|
28
29
|
|
29
|
-
TranslationUnitFlags = enum [
|
30
|
+
TranslationUnitFlags = enum [
|
31
|
+
:none, 0x0,
|
32
|
+
:detailed_preprocessing_record, 0x01,
|
33
|
+
:incomplete, 0x02,
|
34
|
+
:precompiled_preamble, 0x04,
|
35
|
+
:cache_completion_results, 0x08,
|
36
|
+
:for_serialization, 0x10,
|
37
|
+
:cxx_chained_pch, 0x20,
|
38
|
+
:skip_function_bodies, 0x40,
|
39
|
+
:include_brief_comments_in_code_completion, 0x80,
|
40
|
+
]
|
41
|
+
|
42
|
+
SaveTranslationUnitFlags = enum [
|
43
|
+
:save_translation_unit_none, 0x0,
|
44
|
+
]
|
45
|
+
|
46
|
+
SaveError = enum [
|
47
|
+
:none, 0,
|
48
|
+
:unknown, 1,
|
49
|
+
:translation_errors, 2,
|
50
|
+
:invalid_tu, 3
|
51
|
+
]
|
52
|
+
|
53
|
+
ReparseFlags = enum [
|
54
|
+
:none, 0x0,
|
55
|
+
]
|
56
|
+
|
57
|
+
enum :resource_usage_kind, [
|
58
|
+
:ast, 1,
|
59
|
+
:identifiers, 2,
|
60
|
+
:selectors, 3,
|
61
|
+
:global_completion_results, 4,
|
62
|
+
:source_manager_content_cache, 5,
|
63
|
+
:ast_side_tables, 6,
|
64
|
+
:source_manager_membuffer_malloc, 7,
|
65
|
+
:source_manager_membuffer_mmap, 8,
|
66
|
+
:external_ast_source_membuffer_malloc, 9,
|
67
|
+
:external_ast_source_membuffer_mmap, 10,
|
68
|
+
:preprocessor, 11,
|
69
|
+
:preprocessing_record, 12,
|
70
|
+
:sourcemanager_data_structures, 13,
|
71
|
+
:preprocessor_header_search, 14,
|
72
|
+
]
|
73
|
+
|
74
|
+
class CXTUResourceUsage < FFI::Struct
|
75
|
+
layout(
|
76
|
+
:data, :pointer,
|
77
|
+
:numEntries, :uint,
|
78
|
+
:entries, :pointer
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
class CXTUResourceUsageEntry < FFI::Struct
|
83
|
+
layout(
|
84
|
+
:kind, :resource_usage_kind,
|
85
|
+
:amount, :ulong,
|
86
|
+
)
|
87
|
+
end
|
30
88
|
|
31
89
|
# Source code translation units:
|
32
90
|
attach_function :parse_translation_unit, :clang_parseTranslationUnit, [:CXIndex, :string, :pointer, :int, :pointer, :uint, :uint], :CXTranslationUnit
|
91
|
+
attach_function :create_translation_unit, :clang_createTranslationUnit, [:CXIndex, :string], :CXTranslationUnit
|
33
92
|
attach_function :dispose_translation_unit, :clang_disposeTranslationUnit, [:CXTranslationUnit], :void
|
93
|
+
attach_function :get_translation_unit_spelling, :clang_getTranslationUnitSpelling, [:CXTranslationUnit], :string
|
94
|
+
|
95
|
+
attach_function :default_editing_translation_unit_options, :clang_defaultEditingTranslationUnitOptions, [], :uint
|
96
|
+
attach_function :default_save_options, :clang_defaultSaveOptions, [:CXTranslationUnit], :uint
|
97
|
+
attach_function :save_translation_unit, :clang_saveTranslationUnit, [:CXTranslationUnit, :string, :uint], :int
|
98
|
+
attach_function :default_reparse_options, :clang_defaultReparseOptions, [:CXTranslationUnit], :uint
|
99
|
+
attach_function :reparse_translation_unit, :clang_reparseTranslationUnit, [:CXTranslationUnit, :uint, :pointer, :uint], :int
|
100
|
+
|
101
|
+
attach_function :resource_usage, :clang_getCXTUResourceUsage, [:CXTranslationUnit], CXTUResourceUsage.by_value
|
102
|
+
attach_function :dispose_resource_usage, :clang_disposeCXTUResourceUsage, [CXTUResourceUsage.by_value], :void
|
103
|
+
attach_function :resource_usage_name, :clang_getTUResourceUsageName, [:resource_usage_kind], :string
|
34
104
|
end
|
35
105
|
end
|
36
106
|
end
|
data/lib/ffi/clang/lib/type.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
# Copyright, 2014, by Masahiro Sano.
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -72,6 +73,37 @@ module FFI
|
|
72
73
|
:type_member_pointer, 117,
|
73
74
|
]
|
74
75
|
|
76
|
+
enum :calling_conv, [
|
77
|
+
:calling_conv_default, 0,
|
78
|
+
:calling_conv_c, 1,
|
79
|
+
:calling_conv_x86_stdcall, 2,
|
80
|
+
:calling_conv_x86_fastcall, 3,
|
81
|
+
:calling_conv_x86_thiscall, 4,
|
82
|
+
:calling_conv_x86_pascal, 5,
|
83
|
+
:calling_conv_aapcs, 6,
|
84
|
+
:calling_conv_aapcs_vfp, 7,
|
85
|
+
:calling_conv_pnacl_call, 8,
|
86
|
+
:calling_conv_intel_ocl_bicc, 9,
|
87
|
+
:calling_conv_x86_64_win64, 10,
|
88
|
+
:calling_conv_x86_64_sysv, 11,
|
89
|
+
:calling_conv_invalid, 100,
|
90
|
+
:calling_conv_unexposed, 200
|
91
|
+
]
|
92
|
+
|
93
|
+
enum :ref_qualifier_kind, [
|
94
|
+
:ref_qualifier_none, 0,
|
95
|
+
:ref_qualifier_lvalue, 1,
|
96
|
+
:ref_qualifier_rvalue, 2,
|
97
|
+
]
|
98
|
+
|
99
|
+
enum :layout_error, [
|
100
|
+
:layout_error_invalid, -1,
|
101
|
+
:layout_error_incomplete, -2,
|
102
|
+
:layout_error_dependent, -3,
|
103
|
+
:layout_error_not_constant_size, -4,
|
104
|
+
:layout_error_invalid_field_name, -5,
|
105
|
+
]
|
106
|
+
|
75
107
|
class CXType < FFI::Struct
|
76
108
|
layout(
|
77
109
|
:kind, :kind,
|
@@ -79,18 +111,44 @@ module FFI
|
|
79
111
|
)
|
80
112
|
end
|
81
113
|
|
82
|
-
attach_function :get_pointee_type, :clang_getPointeeType, [CXType.by_value], CXType.by_value
|
83
114
|
attach_function :get_type_kind_spelling, :clang_getTypeKindSpelling, [:kind], CXString.by_value
|
84
115
|
if FFI::Clang::Utils.satisfy_version?('3.3')
|
85
116
|
attach_function :get_type_spelling, :clang_getTypeSpelling, [CXType.by_value], CXString.by_value
|
86
117
|
end
|
118
|
+
|
87
119
|
attach_function :is_function_type_variadic, :clang_isFunctionTypeVariadic, [CXType.by_value], :uint
|
88
120
|
attach_function :is_pod_type, :clang_isPODType, [CXType.by_value], :uint
|
89
|
-
|
90
|
-
attach_function :
|
121
|
+
|
122
|
+
attach_function :get_pointee_type, :clang_getPointeeType, [CXType.by_value], CXType.by_value
|
91
123
|
attach_function :get_result_type, :clang_getResultType, [CXType.by_value], CXType.by_value
|
92
124
|
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
|
128
|
+
|
93
129
|
attach_function :is_const_qualified_type, :clang_isConstQualifiedType, [CXType.by_value], :uint
|
130
|
+
attach_function :is_volatile_qualified_type, :clang_isVolatileQualifiedType, [CXType.by_value], :uint
|
131
|
+
attach_function :is_restrict_qualified_type, :clang_isRestrictQualifiedType, [CXType.by_value], :uint
|
132
|
+
|
133
|
+
attach_function :get_num_arg_types, :clang_getNumArgTypes, [CXType.by_value], :int
|
134
|
+
attach_function :get_arg_type, :clang_getArgType, [CXType.by_value, :uint], CXType.by_value
|
135
|
+
attach_function :get_num_elements, :clang_getNumElements, [CXType.by_value], :long_long
|
136
|
+
attach_function :get_element_type, :clang_getElementType, [CXType.by_value], CXType.by_value
|
137
|
+
attach_function :get_array_size, :clang_getArraySize, [CXType.by_value], :long_long
|
138
|
+
attach_function :get_array_element_type ,:clang_getArrayElementType, [CXType.by_value], CXType.by_value
|
139
|
+
|
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
|
145
|
+
|
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
|
149
|
+
attach_function :get_fuction_type_calling_conv, :clang_getFunctionTypeCallingConv, [CXType.by_value], :calling_conv
|
150
|
+
|
151
|
+
attach_function :equal_types, :clang_equalTypes, [CXType.by_value, CXType.by_value], :uint
|
94
152
|
end
|
95
153
|
end
|
96
154
|
end
|
@@ -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
|
@@ -25,8 +26,53 @@ require 'ffi/clang/lib/file'
|
|
25
26
|
module FFI
|
26
27
|
module Clang
|
27
28
|
class SourceLocation
|
29
|
+
def self.null_location
|
30
|
+
ExpansionLocation.new Lib.get_null_location
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :location
|
28
34
|
def initialize(location)
|
29
35
|
@location = location
|
36
|
+
end
|
37
|
+
|
38
|
+
def in_system_header?
|
39
|
+
Lib.location_in_system_header(@location) != 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def from_main_file?
|
43
|
+
Lib.location_is_from_main_file(@location) != 0
|
44
|
+
end
|
45
|
+
|
46
|
+
def expansion_location
|
47
|
+
ExpansionLocation.new(@location)
|
48
|
+
end
|
49
|
+
|
50
|
+
def presumed_location
|
51
|
+
PresumedLocation.new(@location)
|
52
|
+
end
|
53
|
+
|
54
|
+
def spelling_location
|
55
|
+
SpellingLocation.new(@location)
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_location
|
59
|
+
FileLocation.new(@location)
|
60
|
+
end
|
61
|
+
|
62
|
+
def null?
|
63
|
+
Lib.equal_locations(@location, Lib.get_null_location) != 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def ==(other)
|
67
|
+
Lib.equal_locations(@location, other.location) != 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class ExpansionLocation < SourceLocation
|
72
|
+
attr_reader :file, :line, :column, :offset
|
73
|
+
|
74
|
+
def initialize(location)
|
75
|
+
super(location)
|
30
76
|
|
31
77
|
cxfile = MemoryPointer.new :pointer
|
32
78
|
line = MemoryPointer.new :uint
|
@@ -40,8 +86,64 @@ module FFI
|
|
40
86
|
@column = column.get_uint(0)
|
41
87
|
@offset = offset.get_uint(0)
|
42
88
|
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class PresumedLocation < SourceLocation
|
92
|
+
attr_reader :filename, :line, :column, :offset
|
93
|
+
|
94
|
+
def initialize(location)
|
95
|
+
super(location)
|
96
|
+
|
97
|
+
cxstring = MemoryPointer.new Lib::CXString
|
98
|
+
line = MemoryPointer.new :uint
|
99
|
+
column = MemoryPointer.new :uint
|
100
|
+
|
101
|
+
Lib::get_presumed_location(@location, cxstring, line, column)
|
102
|
+
|
103
|
+
@filename = Lib.extract_string cxstring
|
104
|
+
@line = line.get_uint(0)
|
105
|
+
@column = column.get_uint(0)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class SpellingLocation < SourceLocation
|
110
|
+
attr_reader :file, :line, :column, :offset
|
111
|
+
|
112
|
+
def initialize(location)
|
113
|
+
super(location)
|
114
|
+
|
115
|
+
cxfile = MemoryPointer.new :pointer
|
116
|
+
line = MemoryPointer.new :uint
|
117
|
+
column = MemoryPointer.new :uint
|
118
|
+
offset = MemoryPointer.new :uint
|
119
|
+
|
120
|
+
Lib::get_spelling_location(@location, cxfile, line, column, offset)
|
121
|
+
|
122
|
+
@file = Lib.extract_string Lib.get_file_name(cxfile.read_pointer)
|
123
|
+
@line = line.get_uint(0)
|
124
|
+
@column = column.get_uint(0)
|
125
|
+
@offset = offset.get_uint(0)
|
126
|
+
end
|
127
|
+
end
|
43
128
|
|
129
|
+
class FileLocation < SourceLocation
|
44
130
|
attr_reader :file, :line, :column, :offset
|
131
|
+
|
132
|
+
def initialize(location)
|
133
|
+
super(location)
|
134
|
+
|
135
|
+
cxfile = MemoryPointer.new :pointer
|
136
|
+
line = MemoryPointer.new :uint
|
137
|
+
column = MemoryPointer.new :uint
|
138
|
+
offset = MemoryPointer.new :uint
|
139
|
+
|
140
|
+
Lib::get_file_location(@location, cxfile, line, column, offset)
|
141
|
+
|
142
|
+
@file = Lib.extract_string Lib.get_file_name(cxfile.read_pointer)
|
143
|
+
@line = line.get_uint(0)
|
144
|
+
@column = column.get_uint(0)
|
145
|
+
@offset = offset.get_uint(0)
|
146
|
+
end
|
45
147
|
end
|
46
148
|
end
|
47
149
|
end
|