ffi_gen 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/ffi_gen/clang.rb +75 -75
- data/lib/ffi_gen.rb +152 -144
- metadata +4 -4
data/README.md
CHANGED
data/lib/ffi_gen/clang.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'ffi'
|
4
4
|
|
5
|
-
module Clang
|
5
|
+
module FFIGen::Clang
|
6
6
|
extend FFI::Library
|
7
7
|
ffi_lib 'clang'
|
8
8
|
|
@@ -167,21 +167,21 @@ module Clang
|
|
167
167
|
# #ifndef/#define/#endif macro guards or with #pragma once.
|
168
168
|
#
|
169
169
|
# @method is_file_multiple_include_guarded(tu, file)
|
170
|
-
# @param [
|
170
|
+
# @param [TranslationUnitImpl] tu
|
171
171
|
# @param [FFI::Pointer(File)] file
|
172
172
|
# @return [Integer]
|
173
173
|
# @scope class
|
174
|
-
attach_function :is_file_multiple_include_guarded, :clang_isFileMultipleIncludeGuarded, [
|
174
|
+
attach_function :is_file_multiple_include_guarded, :clang_isFileMultipleIncludeGuarded, [TranslationUnitImpl, :pointer], :uint
|
175
175
|
|
176
176
|
# Retrieve a file handle within the given translation unit.
|
177
177
|
#
|
178
178
|
# @method get_file(tu, file_name)
|
179
|
-
# @param [
|
179
|
+
# @param [TranslationUnitImpl] tu the translation unit
|
180
180
|
# @param [String] file_name the name of the file.
|
181
181
|
# @return [FFI::Pointer(File)] the file handle for the named file in the translation unit \p tu,
|
182
182
|
# or a NULL file handle if the file was not a part of this translation unit.
|
183
183
|
# @scope class
|
184
|
-
attach_function :get_file, :clang_getFile, [
|
184
|
+
attach_function :get_file, :clang_getFile, [TranslationUnitImpl, :string], :pointer
|
185
185
|
|
186
186
|
# Identifies a specific source location within a translation
|
187
187
|
# unit.
|
@@ -240,24 +240,24 @@ module Clang
|
|
240
240
|
# in a particular translation unit.
|
241
241
|
#
|
242
242
|
# @method get_location(tu, file, line, column)
|
243
|
-
# @param [
|
243
|
+
# @param [TranslationUnitImpl] tu
|
244
244
|
# @param [FFI::Pointer(File)] file
|
245
245
|
# @param [Integer] line
|
246
246
|
# @param [Integer] column
|
247
247
|
# @return [SourceLocation]
|
248
248
|
# @scope class
|
249
|
-
attach_function :get_location, :clang_getLocation, [
|
249
|
+
attach_function :get_location, :clang_getLocation, [TranslationUnitImpl, :pointer, :uint, :uint], SourceLocation.by_value
|
250
250
|
|
251
251
|
# Retrieves the source location associated with a given character offset
|
252
252
|
# in a particular translation unit.
|
253
253
|
#
|
254
254
|
# @method get_location_for_offset(tu, file, offset)
|
255
|
-
# @param [
|
255
|
+
# @param [TranslationUnitImpl] tu
|
256
256
|
# @param [FFI::Pointer(File)] file
|
257
257
|
# @param [Integer] offset
|
258
258
|
# @return [SourceLocation]
|
259
259
|
# @scope class
|
260
|
-
attach_function :get_location_for_offset, :clang_getLocationForOffset, [
|
260
|
+
attach_function :get_location_for_offset, :clang_getLocationForOffset, [TranslationUnitImpl, :pointer, :uint], SourceLocation.by_value
|
261
261
|
|
262
262
|
# Retrieve a NULL (invalid) source range.
|
263
263
|
#
|
@@ -423,20 +423,20 @@ module Clang
|
|
423
423
|
# translation unit.
|
424
424
|
#
|
425
425
|
# @method get_num_diagnostics(unit)
|
426
|
-
# @param [
|
426
|
+
# @param [TranslationUnitImpl] unit
|
427
427
|
# @return [Integer]
|
428
428
|
# @scope class
|
429
|
-
attach_function :get_num_diagnostics, :clang_getNumDiagnostics, [
|
429
|
+
attach_function :get_num_diagnostics, :clang_getNumDiagnostics, [TranslationUnitImpl], :uint
|
430
430
|
|
431
431
|
# Retrieve a diagnostic associated with the given translation unit.
|
432
432
|
#
|
433
433
|
# @method get_diagnostic(unit, index)
|
434
|
-
# @param [
|
434
|
+
# @param [TranslationUnitImpl] unit the translation unit to query.
|
435
435
|
# @param [Integer] index the zero-based diagnostic number to retrieve.
|
436
436
|
# @return [FFI::Pointer(Diagnostic)] the requested diagnostic. This diagnostic must be freed
|
437
437
|
# via a call to \c clang_disposeDiagnostic().
|
438
438
|
# @scope class
|
439
|
-
attach_function :get_diagnostic, :clang_getDiagnostic, [
|
439
|
+
attach_function :get_diagnostic, :clang_getDiagnostic, [TranslationUnitImpl, :uint], :pointer
|
440
440
|
|
441
441
|
# Destroy a diagnostic.
|
442
442
|
#
|
@@ -652,10 +652,10 @@ module Clang
|
|
652
652
|
# Get the original translation unit source file name.
|
653
653
|
#
|
654
654
|
# @method get_translation_unit_spelling(ct_unit)
|
655
|
-
# @param [
|
655
|
+
# @param [TranslationUnitImpl] ct_unit
|
656
656
|
# @return [String]
|
657
657
|
# @scope class
|
658
|
-
attach_function :get_translation_unit_spelling, :clang_getTranslationUnitSpelling, [
|
658
|
+
attach_function :get_translation_unit_spelling, :clang_getTranslationUnitSpelling, [TranslationUnitImpl], String.by_value
|
659
659
|
|
660
660
|
# Return the CXTranslationUnit for a given source file and the provided
|
661
661
|
# command line arguments one would pass to the compiler.
|
@@ -686,23 +686,23 @@ module Clang
|
|
686
686
|
# '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
|
687
687
|
# @param [Integer] num_unsaved_files the number of unsaved file entries in \p
|
688
688
|
# unsaved_files.
|
689
|
-
# @param [
|
689
|
+
# @param [UnsavedFile] unsaved_files the files that have not yet been saved to disk
|
690
690
|
# but may be required for code completion, including the contents of
|
691
691
|
# those files. The contents and name of these files (as specified by
|
692
692
|
# CXUnsavedFile) are copied when necessary, so the client only needs to
|
693
693
|
# guarantee their validity until the call to this function returns.
|
694
|
-
# @return [
|
694
|
+
# @return [TranslationUnitImpl]
|
695
695
|
# @scope class
|
696
|
-
attach_function :create_translation_unit_from_source_file, :clang_createTranslationUnitFromSourceFile, [:pointer, :string, :int, :pointer, :uint,
|
696
|
+
attach_function :create_translation_unit_from_source_file, :clang_createTranslationUnitFromSourceFile, [:pointer, :string, :int, :pointer, :uint, UnsavedFile], TranslationUnitImpl
|
697
697
|
|
698
698
|
# Create a translation unit from an AST file (-emit-ast).
|
699
699
|
#
|
700
700
|
# @method create_translation_unit(index, ast_filename)
|
701
701
|
# @param [FFI::Pointer(Index)] index
|
702
702
|
# @param [String] ast_filename
|
703
|
-
# @return [
|
703
|
+
# @return [TranslationUnitImpl]
|
704
704
|
# @scope class
|
705
|
-
attach_function :create_translation_unit, :clang_createTranslationUnit, [:pointer, :string],
|
705
|
+
attach_function :create_translation_unit, :clang_createTranslationUnit, [:pointer, :string], TranslationUnitImpl
|
706
706
|
|
707
707
|
# Flags that control the creation of translation units.
|
708
708
|
#
|
@@ -825,7 +825,7 @@ module Clang
|
|
825
825
|
# '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
|
826
826
|
# @param [Integer] num_command_line_args The number of command-line arguments in
|
827
827
|
# \p command_line_args.
|
828
|
-
# @param [
|
828
|
+
# @param [UnsavedFile] unsaved_files the files that have not yet been saved to disk
|
829
829
|
# but may be required for parsing, including the contents of
|
830
830
|
# those files. The contents and name of these files (as specified by
|
831
831
|
# CXUnsavedFile) are copied when necessary, so the client only needs to
|
@@ -835,11 +835,11 @@ module Clang
|
|
835
835
|
# @param [Integer] options A bitmask of options that affects how the translation unit
|
836
836
|
# is managed but not its compilation. This should be a bitwise OR of the
|
837
837
|
# CXTranslationUnit_XXX flags.
|
838
|
-
# @return [
|
838
|
+
# @return [TranslationUnitImpl] A new translation unit describing the parsed code and containing
|
839
839
|
# any diagnostics produced by the compiler. If there is a failure from which
|
840
840
|
# the compiler cannot recover, returns NULL.
|
841
841
|
# @scope class
|
842
|
-
attach_function :parse_translation_unit, :clang_parseTranslationUnit, [:pointer, :string, :pointer, :int,
|
842
|
+
attach_function :parse_translation_unit, :clang_parseTranslationUnit, [:pointer, :string, :pointer, :int, UnsavedFile, :uint, :uint], TranslationUnitImpl
|
843
843
|
|
844
844
|
# Flags that control how translation units are saved.
|
845
845
|
#
|
@@ -869,10 +869,10 @@ module Clang
|
|
869
869
|
# the most commonly-requested data.
|
870
870
|
#
|
871
871
|
# @method default_save_options(tu)
|
872
|
-
# @param [
|
872
|
+
# @param [TranslationUnitImpl] tu
|
873
873
|
# @return [Integer]
|
874
874
|
# @scope class
|
875
|
-
attach_function :default_save_options, :clang_defaultSaveOptions, [
|
875
|
+
attach_function :default_save_options, :clang_defaultSaveOptions, [TranslationUnitImpl], :uint
|
876
876
|
|
877
877
|
# Describes the kind of error that occurred (if any) in a call to
|
878
878
|
# \c clang_saveTranslationUnit().
|
@@ -919,7 +919,7 @@ module Clang
|
|
919
919
|
# units.
|
920
920
|
#
|
921
921
|
# @method save_translation_unit(tu, file_name, options)
|
922
|
-
# @param [
|
922
|
+
# @param [TranslationUnitImpl] tu The translation unit to save.
|
923
923
|
# @param [String] file_name The file to which the translation unit will be saved.
|
924
924
|
# @param [Integer] options A bitmask of options that affects how the translation unit
|
925
925
|
# is saved. This should be a bitwise OR of the
|
@@ -928,15 +928,15 @@ module Clang
|
|
928
928
|
# enumeration. Zero (CXSaveError_None) indicates that the translation unit was
|
929
929
|
# saved successfully, while a non-zero value indicates that a problem occurred.
|
930
930
|
# @scope class
|
931
|
-
attach_function :save_translation_unit, :clang_saveTranslationUnit, [
|
931
|
+
attach_function :save_translation_unit, :clang_saveTranslationUnit, [TranslationUnitImpl, :string, :uint], :int
|
932
932
|
|
933
933
|
# Destroy the specified CXTranslationUnit object.
|
934
934
|
#
|
935
|
-
# @method dispose_translation_unit(
|
936
|
-
# @param [
|
935
|
+
# @method dispose_translation_unit(translation_unit_impl)
|
936
|
+
# @param [TranslationUnitImpl] translation_unit_impl
|
937
937
|
# @return [nil]
|
938
938
|
# @scope class
|
939
|
-
attach_function :dispose_translation_unit, :clang_disposeTranslationUnit, [
|
939
|
+
attach_function :dispose_translation_unit, :clang_disposeTranslationUnit, [TranslationUnitImpl], :void
|
940
940
|
|
941
941
|
# Flags that control the reparsing of translation units.
|
942
942
|
#
|
@@ -967,10 +967,10 @@ module Clang
|
|
967
967
|
# to the next.
|
968
968
|
#
|
969
969
|
# @method default_reparse_options(tu)
|
970
|
-
# @param [
|
970
|
+
# @param [TranslationUnitImpl] tu
|
971
971
|
# @return [Integer]
|
972
972
|
# @scope class
|
973
|
-
attach_function :default_reparse_options, :clang_defaultReparseOptions, [
|
973
|
+
attach_function :default_reparse_options, :clang_defaultReparseOptions, [TranslationUnitImpl], :uint
|
974
974
|
|
975
975
|
# Reparse the source files that produced this translation unit.
|
976
976
|
#
|
@@ -988,12 +988,12 @@ module Clang
|
|
988
988
|
# unit using this routine.
|
989
989
|
#
|
990
990
|
# @method reparse_translation_unit(tu, num_unsaved_files, unsaved_files, options)
|
991
|
-
# @param [
|
991
|
+
# @param [TranslationUnitImpl] tu The translation unit whose contents will be re-parsed. The
|
992
992
|
# translation unit must originally have been built with
|
993
993
|
# \c clang_createTranslationUnitFromSourceFile().
|
994
994
|
# @param [Integer] num_unsaved_files The number of unsaved file entries in \p
|
995
995
|
# unsaved_files.
|
996
|
-
# @param [
|
996
|
+
# @param [UnsavedFile] unsaved_files The files that have not yet been saved to disk
|
997
997
|
# but may be required for parsing, including the contents of
|
998
998
|
# those files. The contents and name of these files (as specified by
|
999
999
|
# CXUnsavedFile) are copied when necessary, so the client only needs to
|
@@ -1006,7 +1006,7 @@ module Clang
|
|
1006
1006
|
# invalid. In such cases, the only valid call for \p TU is
|
1007
1007
|
# \c clang_disposeTranslationUnit(TU).
|
1008
1008
|
# @scope class
|
1009
|
-
attach_function :reparse_translation_unit, :clang_reparseTranslationUnit, [
|
1009
|
+
attach_function :reparse_translation_unit, :clang_reparseTranslationUnit, [TranslationUnitImpl, :uint, UnsavedFile, :uint], :int
|
1010
1010
|
|
1011
1011
|
# Categorizes how memory is being used by a translation unit.
|
1012
1012
|
#
|
@@ -1092,22 +1092,22 @@ module Clang
|
|
1092
1092
|
# :num_entries ::
|
1093
1093
|
# (Integer) The number of entries in the 'entries' array.
|
1094
1094
|
# :entries ::
|
1095
|
-
# (
|
1095
|
+
# (TUResourceUsageEntry) An array of key-value pairs, representing the breakdown of memory
|
1096
1096
|
# usage.
|
1097
1097
|
class TUResourceUsage < FFI::Struct
|
1098
1098
|
layout :data, :pointer,
|
1099
1099
|
:num_entries, :uint,
|
1100
|
-
:entries,
|
1100
|
+
:entries, TUResourceUsageEntry
|
1101
1101
|
end
|
1102
1102
|
|
1103
1103
|
# Return the memory usage of a translation unit. This object
|
1104
1104
|
# should be released with clang_disposeCXTUResourceUsage().
|
1105
1105
|
#
|
1106
1106
|
# @method get_cxtu_resource_usage(tu)
|
1107
|
-
# @param [
|
1107
|
+
# @param [TranslationUnitImpl] tu
|
1108
1108
|
# @return [TUResourceUsage]
|
1109
1109
|
# @scope class
|
1110
|
-
attach_function :get_cxtu_resource_usage, :clang_getCXTUResourceUsage, [
|
1110
|
+
attach_function :get_cxtu_resource_usage, :clang_getCXTUResourceUsage, [TranslationUnitImpl], TUResourceUsage.by_value
|
1111
1111
|
|
1112
1112
|
# (Not documented)
|
1113
1113
|
#
|
@@ -1753,11 +1753,11 @@ module Clang
|
|
1753
1753
|
# The translation unit cursor can be used to start traversing the
|
1754
1754
|
# various declarations within the given translation unit.
|
1755
1755
|
#
|
1756
|
-
# @method get_translation_unit_cursor(
|
1757
|
-
# @param [
|
1756
|
+
# @method get_translation_unit_cursor(translation_unit_impl)
|
1757
|
+
# @param [TranslationUnitImpl] translation_unit_impl
|
1758
1758
|
# @return [Cursor]
|
1759
1759
|
# @scope class
|
1760
|
-
attach_function :get_translation_unit_cursor, :clang_getTranslationUnitCursor, [
|
1760
|
+
attach_function :get_translation_unit_cursor, :clang_getTranslationUnitCursor, [TranslationUnitImpl], Cursor.by_value
|
1761
1761
|
|
1762
1762
|
# Determine whether two cursors are equivalent.
|
1763
1763
|
#
|
@@ -1955,9 +1955,9 @@ module Clang
|
|
1955
1955
|
#
|
1956
1956
|
# @method cursor_get_translation_unit(cursor)
|
1957
1957
|
# @param [Cursor] cursor
|
1958
|
-
# @return [
|
1958
|
+
# @return [TranslationUnitImpl]
|
1959
1959
|
# @scope class
|
1960
|
-
attach_function :cursor_get_translation_unit, :clang_Cursor_getTranslationUnit, [Cursor.by_value],
|
1960
|
+
attach_function :cursor_get_translation_unit, :clang_Cursor_getTranslationUnit, [Cursor.by_value], TranslationUnitImpl
|
1961
1961
|
|
1962
1962
|
# A fast container representing a set of CXCursors.
|
1963
1963
|
class CursorSetImpl < FFI::Struct
|
@@ -1966,35 +1966,35 @@ module Clang
|
|
1966
1966
|
# Creates an empty CXCursorSet.
|
1967
1967
|
#
|
1968
1968
|
# @method create_cx_cursor_set()
|
1969
|
-
# @return [
|
1969
|
+
# @return [CursorSetImpl]
|
1970
1970
|
# @scope class
|
1971
|
-
attach_function :create_cx_cursor_set, :clang_createCXCursorSet, [],
|
1971
|
+
attach_function :create_cx_cursor_set, :clang_createCXCursorSet, [], CursorSetImpl
|
1972
1972
|
|
1973
1973
|
# Disposes a CXCursorSet and releases its associated memory.
|
1974
1974
|
#
|
1975
1975
|
# @method dispose_cx_cursor_set(cset)
|
1976
|
-
# @param [
|
1976
|
+
# @param [CursorSetImpl] cset
|
1977
1977
|
# @return [nil]
|
1978
1978
|
# @scope class
|
1979
|
-
attach_function :dispose_cx_cursor_set, :clang_disposeCXCursorSet, [
|
1979
|
+
attach_function :dispose_cx_cursor_set, :clang_disposeCXCursorSet, [CursorSetImpl], :void
|
1980
1980
|
|
1981
1981
|
# Queries a CXCursorSet to see if it contains a specific CXCursor.
|
1982
1982
|
#
|
1983
1983
|
# @method cx_cursor_set_contains(cset, cursor)
|
1984
|
-
# @param [
|
1984
|
+
# @param [CursorSetImpl] cset
|
1985
1985
|
# @param [Cursor] cursor
|
1986
1986
|
# @return [Integer] non-zero if the set contains the specified cursor.
|
1987
1987
|
# @scope class
|
1988
|
-
attach_function :cx_cursor_set_contains, :clang_CXCursorSet_contains, [
|
1988
|
+
attach_function :cx_cursor_set_contains, :clang_CXCursorSet_contains, [CursorSetImpl, Cursor.by_value], :uint
|
1989
1989
|
|
1990
1990
|
# Inserts a CXCursor into a CXCursorSet.
|
1991
1991
|
#
|
1992
1992
|
# @method cx_cursor_set_insert(cset, cursor)
|
1993
|
-
# @param [
|
1993
|
+
# @param [CursorSetImpl] cset
|
1994
1994
|
# @param [Cursor] cursor
|
1995
1995
|
# @return [Integer] zero if the CXCursor was already in the set, and non-zero otherwise.
|
1996
1996
|
# @scope class
|
1997
|
-
attach_function :cx_cursor_set_insert, :clang_CXCursorSet_insert, [
|
1997
|
+
attach_function :cx_cursor_set_insert, :clang_CXCursorSet_insert, [CursorSetImpl, Cursor.by_value], :uint
|
1998
1998
|
|
1999
1999
|
# Determine the semantic parent of the given cursor.
|
2000
2000
|
#
|
@@ -2145,13 +2145,13 @@ module Clang
|
|
2145
2145
|
# "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
|
2146
2146
|
# will return a cursor referring to the "+" expression.
|
2147
2147
|
#
|
2148
|
-
# @method get_cursor(
|
2149
|
-
# @param [
|
2148
|
+
# @method get_cursor(translation_unit_impl, source_location)
|
2149
|
+
# @param [TranslationUnitImpl] translation_unit_impl
|
2150
2150
|
# @param [SourceLocation] source_location
|
2151
2151
|
# @return [Cursor] a cursor representing the entity at the given source location, or
|
2152
2152
|
# a NULL cursor if no such entity can be found.
|
2153
2153
|
# @scope class
|
2154
|
-
attach_function :get_cursor, :clang_getCursor, [
|
2154
|
+
attach_function :get_cursor, :clang_getCursor, [TranslationUnitImpl, SourceLocation.by_value], Cursor.by_value
|
2155
2155
|
|
2156
2156
|
# Retrieve the physical location of the source constructor referenced
|
2157
2157
|
# by the given cursor.
|
@@ -2962,36 +2962,36 @@ module Clang
|
|
2962
2962
|
# The spelling of a token is the textual representation of that token, e.g.,
|
2963
2963
|
# the text of an identifier or keyword.
|
2964
2964
|
#
|
2965
|
-
# @method get_token_spelling(
|
2966
|
-
# @param [
|
2965
|
+
# @method get_token_spelling(translation_unit_impl, token)
|
2966
|
+
# @param [TranslationUnitImpl] translation_unit_impl
|
2967
2967
|
# @param [Token] token
|
2968
2968
|
# @return [String]
|
2969
2969
|
# @scope class
|
2970
|
-
attach_function :get_token_spelling, :clang_getTokenSpelling, [
|
2970
|
+
attach_function :get_token_spelling, :clang_getTokenSpelling, [TranslationUnitImpl, Token.by_value], String.by_value
|
2971
2971
|
|
2972
2972
|
# Retrieve the source location of the given token.
|
2973
2973
|
#
|
2974
|
-
# @method get_token_location(
|
2975
|
-
# @param [
|
2974
|
+
# @method get_token_location(translation_unit_impl, token)
|
2975
|
+
# @param [TranslationUnitImpl] translation_unit_impl
|
2976
2976
|
# @param [Token] token
|
2977
2977
|
# @return [SourceLocation]
|
2978
2978
|
# @scope class
|
2979
|
-
attach_function :get_token_location, :clang_getTokenLocation, [
|
2979
|
+
attach_function :get_token_location, :clang_getTokenLocation, [TranslationUnitImpl, Token.by_value], SourceLocation.by_value
|
2980
2980
|
|
2981
2981
|
# Retrieve a source range that covers the given token.
|
2982
2982
|
#
|
2983
|
-
# @method get_token_extent(
|
2984
|
-
# @param [
|
2983
|
+
# @method get_token_extent(translation_unit_impl, token)
|
2984
|
+
# @param [TranslationUnitImpl] translation_unit_impl
|
2985
2985
|
# @param [Token] token
|
2986
2986
|
# @return [SourceRange]
|
2987
2987
|
# @scope class
|
2988
|
-
attach_function :get_token_extent, :clang_getTokenExtent, [
|
2988
|
+
attach_function :get_token_extent, :clang_getTokenExtent, [TranslationUnitImpl, Token.by_value], SourceRange.by_value
|
2989
2989
|
|
2990
2990
|
# Tokenize the source code described by the given range into raw
|
2991
2991
|
# lexical tokens.
|
2992
2992
|
#
|
2993
2993
|
# @method tokenize(tu, range, tokens, num_tokens)
|
2994
|
-
# @param [
|
2994
|
+
# @param [TranslationUnitImpl] tu the translation unit whose text is being tokenized.
|
2995
2995
|
# @param [SourceRange] range the source range in which text should be tokenized. All of the
|
2996
2996
|
# tokens produced by tokenization will fall within this source range,
|
2997
2997
|
# @param [FFI::Pointer(**Token)] tokens this pointer will be set to point to the array of tokens
|
@@ -3001,7 +3001,7 @@ module Clang
|
|
3001
3001
|
# array.
|
3002
3002
|
# @return [nil]
|
3003
3003
|
# @scope class
|
3004
|
-
attach_function :tokenize, :clang_tokenize, [
|
3004
|
+
attach_function :tokenize, :clang_tokenize, [TranslationUnitImpl, SourceRange.by_value, :pointer, :pointer], :void
|
3005
3005
|
|
3006
3006
|
# Annotate the given set of tokens by providing cursors for each token
|
3007
3007
|
# that can be mapped to a specific entity within the abstract syntax tree.
|
@@ -3024,24 +3024,24 @@ module Clang
|
|
3024
3024
|
# not provided as an annotation.
|
3025
3025
|
#
|
3026
3026
|
# @method annotate_tokens(tu, tokens, num_tokens, cursors)
|
3027
|
-
# @param [
|
3027
|
+
# @param [TranslationUnitImpl] tu the translation unit that owns the given tokens.
|
3028
3028
|
# @param [FFI::Pointer(*Token)] tokens the set of tokens to annotate.
|
3029
3029
|
# @param [Integer] num_tokens the number of tokens in \p Tokens.
|
3030
3030
|
# @param [FFI::Pointer(*Cursor)] cursors an array of \p NumTokens cursors, whose contents will be
|
3031
3031
|
# replaced with the cursors corresponding to each token.
|
3032
3032
|
# @return [nil]
|
3033
3033
|
# @scope class
|
3034
|
-
attach_function :annotate_tokens, :clang_annotateTokens, [
|
3034
|
+
attach_function :annotate_tokens, :clang_annotateTokens, [TranslationUnitImpl, :pointer, :uint, :pointer], :void
|
3035
3035
|
|
3036
3036
|
# Free the given set of tokens.
|
3037
3037
|
#
|
3038
3038
|
# @method dispose_tokens(tu, tokens, num_tokens)
|
3039
|
-
# @param [
|
3039
|
+
# @param [TranslationUnitImpl] tu
|
3040
3040
|
# @param [FFI::Pointer(*Token)] tokens
|
3041
3041
|
# @param [Integer] num_tokens
|
3042
3042
|
# @return [nil]
|
3043
3043
|
# @scope class
|
3044
|
-
attach_function :dispose_tokens, :clang_disposeTokens, [
|
3044
|
+
attach_function :dispose_tokens, :clang_disposeTokens, [TranslationUnitImpl, :pointer, :uint], :void
|
3045
3045
|
|
3046
3046
|
# for debug/testing
|
3047
3047
|
#
|
@@ -3448,7 +3448,7 @@ module Clang
|
|
3448
3448
|
# have a lower latency.
|
3449
3449
|
#
|
3450
3450
|
# @method code_complete_at(tu, complete_filename, complete_line, complete_column, unsaved_files, num_unsaved_files, options)
|
3451
|
-
# @param [
|
3451
|
+
# @param [TranslationUnitImpl] tu The translation unit in which code-completion should
|
3452
3452
|
# occur. The source files for this translation unit need not be
|
3453
3453
|
# completely up-to-date (and the contents of those source files may
|
3454
3454
|
# be overridden via \p unsaved_files). Cursors referring into the
|
@@ -3460,7 +3460,7 @@ module Clang
|
|
3460
3460
|
# @param [Integer] complete_column The column at which code-completion should occur.
|
3461
3461
|
# Note that the column should point just after the syntactic construct that
|
3462
3462
|
# initiated code completion, and not in the middle of a lexical token.
|
3463
|
-
# @param [
|
3463
|
+
# @param [UnsavedFile] unsaved_files the Tiles that have not yet been saved to disk
|
3464
3464
|
# but may be required for parsing or code completion, including the
|
3465
3465
|
# contents of those files. The contents and name of these files (as
|
3466
3466
|
# specified by CXUnsavedFile) are copied when necessary, so the
|
@@ -3478,7 +3478,7 @@ module Clang
|
|
3478
3478
|
# freed with \c clang_disposeCodeCompleteResults(). If code
|
3479
3479
|
# completion fails, returns NULL.
|
3480
3480
|
# @scope class
|
3481
|
-
attach_function :code_complete_at, :clang_codeCompleteAt, [
|
3481
|
+
attach_function :code_complete_at, :clang_codeCompleteAt, [TranslationUnitImpl, :string, :uint, :uint, UnsavedFile, :uint, :uint], :pointer
|
3482
3482
|
|
3483
3483
|
# Sort the code-completion results in case-insensitive alphabetical
|
3484
3484
|
# order.
|
@@ -3614,12 +3614,12 @@ module Clang
|
|
3614
3614
|
# is inspecting the inclusions in the PCH file itself).
|
3615
3615
|
#
|
3616
3616
|
# @method get_inclusions(tu, visitor, client_data)
|
3617
|
-
# @param [
|
3617
|
+
# @param [TranslationUnitImpl] tu
|
3618
3618
|
# @param [Proc(_callback_inclusion_visitor_)] visitor
|
3619
3619
|
# @param [FFI::Pointer(ClientData)] client_data
|
3620
3620
|
# @return [nil]
|
3621
3621
|
# @scope class
|
3622
|
-
attach_function :get_inclusions, :clang_getInclusions, [
|
3622
|
+
attach_function :get_inclusions, :clang_getInclusions, [TranslationUnitImpl, :inclusion_visitor, :pointer], :void
|
3623
3623
|
|
3624
3624
|
# Retrieve a remapping.
|
3625
3625
|
#
|
data/lib/ffi_gen.rb
CHANGED
@@ -1,33 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
class FFIGen
|
2
|
+
RUBY_KEYWORDS = %w{alias allocate and begin break case class def defined do else elsif end ensure false for if in initialize module next nil not or redo rescue retry return self super then true undef unless until when while yield}
|
3
|
+
|
4
|
+
require "ffi_gen/clang"
|
5
|
+
|
6
|
+
class << Clang
|
7
|
+
def get_children(declaration)
|
8
|
+
children = []
|
9
|
+
visit_children declaration, lambda { |child, child_parent, child_client_data|
|
10
|
+
children << child
|
11
|
+
:continue
|
12
|
+
}, nil
|
13
|
+
children
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_spelling_location_data(location)
|
17
|
+
file_ptr = FFI::MemoryPointer.new :pointer
|
18
|
+
line_ptr = FFI::MemoryPointer.new :uint
|
19
|
+
column_ptr = FFI::MemoryPointer.new :uint
|
20
|
+
offset_ptr = FFI::MemoryPointer.new :uint
|
21
|
+
get_spelling_location location, file_ptr, line_ptr, column_ptr, offset_ptr
|
22
|
+
{ file: file_ptr.read_pointer, line: line_ptr.read_uint, column: column_ptr.read_uint, offset: offset_ptr.read_uint }
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
class Clang::String
|
27
|
+
def to_s
|
28
|
+
Clang.get_c_string self
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s_and_dispose
|
32
|
+
str = to_s
|
33
|
+
Clang.dispose_string self
|
34
|
+
str
|
35
|
+
end
|
23
36
|
end
|
24
|
-
|
25
|
-
|
26
|
-
class FFIGen
|
27
|
-
RUBY_KEYWORDS = %w{alias allocate and begin break case class def defined do else elsif end ensure false for if in initialize module next nil not or redo rescue retry return self super then true undef unless until when while yield}
|
28
|
-
|
37
|
+
|
29
38
|
class Enum
|
30
|
-
attr_reader :constants
|
39
|
+
attr_reader :constants, :comment
|
31
40
|
|
32
41
|
def initialize(generator, name, comment)
|
33
42
|
@generator = generator
|
@@ -86,29 +95,23 @@ class FFIGen
|
|
86
95
|
def ruby_name
|
87
96
|
@ruby_name ||= @generator.to_ruby_lowercase @name
|
88
97
|
end
|
89
|
-
|
90
|
-
def type_name(short)
|
91
|
-
short ? @name : "Symbol from _enum_#{ruby_name}_"
|
92
|
-
end
|
93
|
-
|
94
|
-
def reference
|
95
|
-
":#{ruby_name}"
|
96
|
-
end
|
97
98
|
end
|
98
99
|
|
99
100
|
class Struct
|
100
|
-
attr_reader :fields
|
101
|
+
attr_reader :fields, :comment, :written
|
101
102
|
|
102
103
|
def initialize(generator, name, comment)
|
103
104
|
@generator = generator
|
104
105
|
@name = name
|
105
106
|
@comment = comment
|
106
107
|
@fields = []
|
108
|
+
@written = false
|
107
109
|
end
|
108
110
|
|
109
111
|
def write(writer)
|
110
112
|
@fields.each do |field|
|
111
113
|
field[:symbol] = ":#{@generator.to_ruby_lowercase field[:name]}"
|
114
|
+
field[:type_data] = @generator.map_type field[:type]
|
112
115
|
end
|
113
116
|
|
114
117
|
writer.comment do
|
@@ -117,7 +120,7 @@ class FFIGen
|
|
117
120
|
writer.puts "", "= Fields:"
|
118
121
|
@fields.each do |field|
|
119
122
|
writer.puts "#{field[:symbol]} ::"
|
120
|
-
writer.write_description field[:comment], false, " (#{
|
123
|
+
writer.write_description field[:comment], false, " (#{field[:type_data][:description]}) ", " "
|
121
124
|
end
|
122
125
|
end
|
123
126
|
end
|
@@ -125,27 +128,21 @@ class FFIGen
|
|
125
128
|
writer.puts "class #{ruby_name} < FFI::Struct"
|
126
129
|
writer.indent do
|
127
130
|
writer.write_array @fields, ",", "layout ", " " do |field|
|
128
|
-
"#{field[:symbol]}, #{
|
131
|
+
"#{field[:symbol]}, #{field[:type_data][:ffi_type]}"
|
129
132
|
end
|
130
133
|
end
|
131
134
|
writer.puts "end", ""
|
135
|
+
|
136
|
+
@written = true
|
132
137
|
end
|
133
138
|
|
134
139
|
def ruby_name
|
135
140
|
@ruby_name ||= @generator.to_ruby_camelcase @name
|
136
141
|
end
|
137
|
-
|
138
|
-
def type_name(short)
|
139
|
-
ruby_name
|
140
|
-
end
|
141
|
-
|
142
|
-
def reference
|
143
|
-
"#{ruby_name}.by_value"
|
144
|
-
end
|
145
142
|
end
|
146
143
|
|
147
144
|
class Function
|
148
|
-
attr_reader :name, :parameters
|
145
|
+
attr_reader :name, :parameters, :comment
|
149
146
|
attr_accessor :return_type
|
150
147
|
|
151
148
|
def initialize(generator, name, is_callback, comment)
|
@@ -158,10 +155,11 @@ class FFIGen
|
|
158
155
|
|
159
156
|
def write(writer)
|
160
157
|
@parameters.each do |parameter|
|
161
|
-
parameter[:
|
162
|
-
parameter[:ruby_name] =
|
158
|
+
parameter[:type_data] = @generator.map_type parameter[:type]
|
159
|
+
parameter[:ruby_name] = !parameter[:name].empty? ? @generator.to_ruby_lowercase(parameter[:name]) : parameter[:type_data][:parameter_name]
|
163
160
|
parameter[:description] = []
|
164
161
|
end
|
162
|
+
return_type_data = @generator.map_type @return_type
|
165
163
|
|
166
164
|
function_description = []
|
167
165
|
return_value_description = []
|
@@ -185,13 +183,13 @@ class FFIGen
|
|
185
183
|
writer.puts "", "<em>This entry is only for documentation and no real method.</em>" if @is_callback
|
186
184
|
writer.puts "", "@method #{@is_callback ? "_callback_#{ruby_name}_" : ruby_name}(#{@parameters.map{ |parameter| parameter[:ruby_name] }.join(', ')})"
|
187
185
|
@parameters.each do |parameter|
|
188
|
-
writer.write_description parameter[:description], false, "@param [#{parameter[:
|
186
|
+
writer.write_description parameter[:description], false, "@param [#{parameter[:type_data][:description]}] #{parameter[:ruby_name]} ", " "
|
189
187
|
end
|
190
|
-
writer.write_description return_value_description, false, "@return [#{
|
188
|
+
writer.write_description return_value_description, false, "@return [#{return_type_data[:description]}] ", " "
|
191
189
|
writer.puts "@scope class"
|
192
190
|
end
|
193
191
|
|
194
|
-
ffi_signature = "[#{@parameters.map{ |parameter|
|
192
|
+
ffi_signature = "[#{@parameters.map{ |parameter| parameter[:type_data][:ffi_type] }.join(', ')}], #{return_type_data[:ffi_type]}"
|
195
193
|
if @is_callback
|
196
194
|
writer.puts "callback :#{ruby_name}, #{ffi_signature}", ""
|
197
195
|
else
|
@@ -202,14 +200,6 @@ class FFIGen
|
|
202
200
|
def ruby_name
|
203
201
|
@ruby_name ||= @generator.to_ruby_lowercase @name, true
|
204
202
|
end
|
205
|
-
|
206
|
-
def type_name(short)
|
207
|
-
"Proc(_callback_#{ruby_name}_)"
|
208
|
-
end
|
209
|
-
|
210
|
-
def reference
|
211
|
-
":#{ruby_name}"
|
212
|
-
end
|
213
203
|
end
|
214
204
|
|
215
205
|
class Constant
|
@@ -297,6 +287,24 @@ class FFIGen
|
|
297
287
|
@declarations = nil
|
298
288
|
end
|
299
289
|
|
290
|
+
def generate
|
291
|
+
writer = Writer.new
|
292
|
+
writer.puts "# Generated by ffi_gen. Please do not change this file by hand.", "", "require 'ffi'", "", "module #{@ruby_module}"
|
293
|
+
writer.indent do
|
294
|
+
writer.puts "extend FFI::Library", "ffi_lib '#{@ffi_lib}'", ""
|
295
|
+
declarations.each do |name, declaration|
|
296
|
+
declaration.write writer
|
297
|
+
end
|
298
|
+
end
|
299
|
+
writer.puts "end"
|
300
|
+
if @output.is_a? String
|
301
|
+
File.open(@output, "w") { |file| file.write writer.output }
|
302
|
+
puts "ffi_gen: #{@output}"
|
303
|
+
else
|
304
|
+
@output.write writer.output
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
300
308
|
def translation_unit
|
301
309
|
return @translation_unit unless @translation_unit.nil?
|
302
310
|
|
@@ -333,9 +341,7 @@ class FFIGen
|
|
333
341
|
unit_cursor = Clang.get_translation_unit_cursor translation_unit
|
334
342
|
previous_declaration_end = Clang.get_cursor_location unit_cursor
|
335
343
|
Clang.get_children(unit_cursor).each do |declaration|
|
336
|
-
|
337
|
-
Clang.get_spelling_location Clang.get_cursor_location(declaration), file_ptr, nil, nil, nil
|
338
|
-
file = file_ptr.read_pointer
|
344
|
+
file = Clang.get_spelling_location_data(Clang.get_cursor_location(declaration))[:file]
|
339
345
|
|
340
346
|
extent = Clang.get_cursor_extent declaration
|
341
347
|
comment_range = Clang.get_range previous_declaration_end, Clang.get_range_start(extent)
|
@@ -397,32 +403,17 @@ class FFIGen
|
|
397
403
|
@declarations[name] = Constant.new self, name, value
|
398
404
|
end
|
399
405
|
end
|
400
|
-
|
406
|
+
|
401
407
|
end
|
402
408
|
end
|
403
409
|
|
404
410
|
@declarations
|
405
411
|
end
|
406
412
|
|
407
|
-
def generate
|
408
|
-
writer = Writer.new
|
409
|
-
writer.puts "# Generated by ffi_gen. Please do not change this file by hand.", "", "require 'ffi'", "", "module #{@ruby_module}"
|
410
|
-
writer.indent do
|
411
|
-
writer.puts "extend FFI::Library", "ffi_lib '#{@ffi_lib}'", ""
|
412
|
-
declarations.each do |name, declaration|
|
413
|
-
declaration.write writer
|
414
|
-
end
|
415
|
-
end
|
416
|
-
writer.puts "end"
|
417
|
-
if @output.is_a? String
|
418
|
-
File.open(@output, "w") { |file| file.write writer.output }
|
419
|
-
puts "ffi_gen: #{@output}"
|
420
|
-
else
|
421
|
-
@output.write writer.output
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
413
|
def read_named_declaration(declaration, name, comment)
|
414
|
+
old_declaration = @declarations.delete name
|
415
|
+
comment = "#{old_declaration.comment}\n#{comment}" if old_declaration
|
416
|
+
|
426
417
|
case declaration[:kind]
|
427
418
|
when :enum_decl
|
428
419
|
enum = Enum.new self, name, comment
|
@@ -457,85 +448,93 @@ class FFIGen
|
|
457
448
|
|
458
449
|
when :struct_decl
|
459
450
|
struct = Struct.new self, name, comment
|
460
|
-
@declarations[name] = struct
|
461
451
|
|
462
|
-
|
463
|
-
Clang.
|
464
|
-
|
465
|
-
|
452
|
+
struct_children = Clang.get_children declaration
|
453
|
+
previous_child_end = Clang.get_cursor_location declaration
|
454
|
+
struct_children.each_with_index do |struct_child, index|
|
455
|
+
child_name = Clang.get_cursor_spelling(struct_child).to_s_and_dispose
|
456
|
+
child_extent = Clang.get_cursor_extent struct_child
|
466
457
|
|
467
|
-
|
468
|
-
|
469
|
-
field_comment = extract_comment translation_unit, field_comment_range
|
470
|
-
previous_field_location = field_location
|
458
|
+
child_comment_range = Clang.get_range previous_child_end, Clang.get_range_start(child_extent)
|
459
|
+
child_comment = extract_comment translation_unit, child_comment_range
|
471
460
|
|
472
|
-
|
461
|
+
# check for comment starting on same line
|
462
|
+
next_child_start = index < struct_children.size - 1 ? Clang.get_cursor_location(struct_children[index + 1]) : Clang.get_range_end(Clang.get_cursor_extent(declaration))
|
463
|
+
following_comment_range = Clang.get_range Clang.get_range_end(child_extent), next_child_start
|
464
|
+
following_comment_token = extract_comment translation_unit, following_comment_range, false, false
|
465
|
+
if following_comment_token and Clang.get_spelling_location_data(Clang.get_token_location(translation_unit, following_comment_token))[:line] == Clang.get_spelling_location_data(Clang.get_range_end(child_extent))[:line]
|
466
|
+
child_comment = Clang.get_token_spelling(translation_unit, following_comment_token).to_s_and_dispose
|
467
|
+
previous_child_end = Clang.get_range_end Clang.get_token_extent(translation_unit, following_comment_token)
|
468
|
+
else
|
469
|
+
previous_child_end = Clang.get_range_end child_extent
|
470
|
+
end
|
471
|
+
|
472
|
+
case struct_child[:kind]
|
473
|
+
when :field_decl
|
474
|
+
field_type = Clang.get_cursor_type struct_child
|
475
|
+
|
476
|
+
struct.fields << { name: child_name, type: field_type, comment: child_comment }
|
477
|
+
when :struct_decl
|
478
|
+
read_named_declaration struct_child, child_name, child_comment
|
479
|
+
end
|
473
480
|
end
|
481
|
+
|
482
|
+
@declarations[name] = struct
|
483
|
+
|
474
484
|
end
|
475
485
|
end
|
476
486
|
|
477
|
-
def extract_comment(translation_unit, range)
|
487
|
+
def extract_comment(translation_unit, range, search_backwards = true, return_spelling = true)
|
478
488
|
tokens_ptr_ptr = FFI::MemoryPointer.new :pointer
|
479
489
|
num_tokens_ptr = FFI::MemoryPointer.new :uint
|
480
490
|
Clang.tokenize translation_unit, range, tokens_ptr_ptr, num_tokens_ptr
|
481
491
|
num_tokens = num_tokens_ptr.read_uint
|
482
492
|
tokens_ptr = FFI::Pointer.new Clang::Token, tokens_ptr_ptr.read_pointer
|
483
|
-
(num_tokens - 1).downto(0)
|
493
|
+
indices = search_backwards ? (num_tokens - 1).downto(0) : 0.upto(num_tokens - 1)
|
494
|
+
indices.each do |i|
|
484
495
|
token = Clang::Token.new tokens_ptr[i]
|
485
|
-
|
496
|
+
if Clang.get_token_kind(token) == :comment
|
497
|
+
return return_spelling ? Clang.get_token_spelling(translation_unit, token).to_s_and_dispose : token
|
498
|
+
end
|
486
499
|
end
|
487
500
|
""
|
488
501
|
end
|
489
502
|
|
490
|
-
def
|
491
|
-
|
492
|
-
|
493
|
-
return @declarations[name].reference if @declarations.has_key? name
|
503
|
+
def map_type(full_type)
|
504
|
+
name = Clang.get_cursor_spelling(Clang.get_type_declaration(full_type)).to_s_and_dispose
|
505
|
+
declaration = !name.empty? && @declarations[name]
|
494
506
|
|
495
507
|
canonical_type = Clang.get_canonical_type full_type
|
496
|
-
case canonical_type[:kind]
|
497
|
-
when :void
|
498
|
-
when :bool
|
499
|
-
when :u_char
|
500
|
-
when :u_short
|
501
|
-
when :u_int
|
502
|
-
when :u_long
|
503
|
-
when :u_long_long
|
504
|
-
when :char_s, :s_char then ":char"
|
505
|
-
when :short
|
506
|
-
when :int
|
507
|
-
when :long
|
508
|
-
when :long_long
|
509
|
-
when :float
|
510
|
-
when :double
|
508
|
+
data_array = case canonical_type[:kind]
|
509
|
+
when :void then [":void", "nil"]
|
510
|
+
when :bool then [":bool", "Boolean"]
|
511
|
+
when :u_char then [":uchar", "Integer"]
|
512
|
+
when :u_short then [":ushort", "Integer"]
|
513
|
+
when :u_int then [":uint", "Integer"]
|
514
|
+
when :u_long then [":ulong", "Integer"]
|
515
|
+
when :u_long_long then [":ulong_long", "Integer"]
|
516
|
+
when :char_s, :s_char then [":char", "Integer"]
|
517
|
+
when :short then [":short", "Integer"]
|
518
|
+
when :int then [":int", "Integer"]
|
519
|
+
when :long then [":long", "Integer"]
|
520
|
+
when :long_long then [":long_long", "Integer"]
|
521
|
+
when :float then [":float", "Float"]
|
522
|
+
when :double then [":double", "Float"]
|
511
523
|
when :pointer
|
512
524
|
pointee_type = Clang.get_pointee_type canonical_type
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
return @declarations[name].type_name(short) if @declarations.has_key? name
|
527
|
-
|
528
|
-
canonical_type = Clang.get_canonical_type full_type
|
529
|
-
case canonical_type[:kind]
|
530
|
-
when :void then "nil"
|
531
|
-
when :bool then "Boolean"
|
532
|
-
when :u_char, :u_short, :u_int, :u_long, :u_long_long, :char_s, :s_char, :short, :int, :long, :long_long then "Integer"
|
533
|
-
when :float, :double then "Float"
|
534
|
-
when :pointer
|
535
|
-
pointee_type = Clang.get_pointee_type canonical_type
|
536
|
-
if pointee_type[:kind] == :char_s
|
537
|
-
"String"
|
538
|
-
else
|
525
|
+
result = nil
|
526
|
+
case pointee_type[:kind]
|
527
|
+
when :char_s
|
528
|
+
result = [":string", "String"]
|
529
|
+
when :record
|
530
|
+
pointee_name = Clang.get_cursor_spelling(Clang.get_type_declaration(pointee_type)).to_s_and_dispose
|
531
|
+
pointee_declaration = !pointee_name.empty? && @declarations[pointee_name]
|
532
|
+
result = [pointee_declaration.ruby_name, pointee_declaration.ruby_name] if pointee_declaration and pointee_declaration.written
|
533
|
+
when :function_proto
|
534
|
+
result = [":#{declaration.ruby_name}", "Proc(_callback_#{declaration.ruby_name}_)"] if declaration
|
535
|
+
end
|
536
|
+
|
537
|
+
if result.nil?
|
539
538
|
pointer_depth = 0
|
540
539
|
pointer_target_name = ""
|
541
540
|
current_type = full_type
|
@@ -555,14 +554,23 @@ class FFIGen
|
|
555
554
|
break
|
556
555
|
end
|
557
556
|
end
|
558
|
-
|
557
|
+
result = [":pointer", "FFI::Pointer(#{'*' * pointer_depth}#{pointer_target_name})", pointer_target_name]
|
559
558
|
end
|
559
|
+
|
560
|
+
result
|
561
|
+
when :record
|
562
|
+
["#{declaration.ruby_name}.by_value", declaration.ruby_name]
|
563
|
+
when :enum
|
564
|
+
[":#{declaration.ruby_name}", "Symbol from _enum_#{declaration.ruby_name}_", declaration.ruby_name]
|
560
565
|
when :constant_array
|
561
|
-
|
562
|
-
|
566
|
+
element_type_data = map_type Clang.get_array_element_type(canonical_type)
|
567
|
+
size = Clang.get_array_size canonical_type
|
568
|
+
["[#{element_type_data[:ffi_type]}, #{size}]", "Array<#{element_type_data[:description]}>"]
|
563
569
|
else
|
564
|
-
raise NotImplementedError, "No
|
570
|
+
raise NotImplementedError, "No translation for values of type #{canonical_type[:kind]}"
|
565
571
|
end
|
572
|
+
|
573
|
+
{ ffi_type: data_array[0], description: data_array[1], parameter_name: to_ruby_lowercase(data_array[2] || data_array[1]) }
|
566
574
|
end
|
567
575
|
|
568
576
|
def to_ruby_lowercase(str, avoid_keywords = false)
|
@@ -594,7 +602,7 @@ end
|
|
594
602
|
|
595
603
|
if __FILE__ == $0
|
596
604
|
FFIGen.generate(
|
597
|
-
ruby_module: "Clang",
|
605
|
+
ruby_module: "FFIGen::Clang",
|
598
606
|
ffi_lib: "clang",
|
599
607
|
headers: ["clang-c/Index.h"],
|
600
608
|
cflags: `llvm-config --cflags`.split(" "),
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement: &
|
16
|
+
requirement: &18320080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *18320080
|
25
25
|
description: A generator for Ruby FFI bindings, directly from header files via LLVM's
|
26
26
|
Clang compiler
|
27
27
|
email: mail@richard-musiol.de
|