-
Notifications
You must be signed in to change notification settings - Fork 26
/
Index.rb
3814 lines (3616 loc) · 146 KB
/
Index.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Generated by ffi-gen. Please do not change this file by hand.
require 'ffi'
module Clang
extend FFI::Library
ffi_lib 'clang'
def self.attach_function(name, *_)
begin; super; rescue FFI::NotFoundError => e
(class << self; self; end).class_eval { define_method(name) { |*_| raise e } }
end
end
# A single translation unit, which resides in an index.
class TranslationUnitImpl < FFI::Struct
layout :dummy, :char
end
# Provides the contents of a file that has not yet been saved to disk.
#
# Each CXUnsavedFile instance provides the name of a file on the
# system along with the current contents of that file that have not
# yet been saved to disk.
#
# = Fields:
# :filename ::
# (String) The file whose contents have not yet been saved.
#
# This file must already exist in the file system.
# :contents ::
# (String) A buffer containing the unsaved contents of this file.
# :length ::
# (Integer) The length of the unsaved contents of this buffer.
class UnsavedFile < FFI::Struct
layout :filename, :string,
:contents, :string,
:length, :ulong
end
# Describes the availability of a particular entity, which indicates
# whether the use of this entity will result in a warning or error due to
# it being deprecated or unavailable.
#
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:availability_kind).</em>
#
# === Options:
# :available ::
# The entity is available.
# :deprecated ::
# The entity is available, but has been deprecated (and its use is
# not recommended).
# :not_available ::
# The entity is not available; any use of it will be an error.
# :not_accessible ::
# The entity is available, but not accessible; any use of it will be
# an error.
#
# @method _enum_availability_kind_
# @return [Symbol]
# @scope class
enum :availability_kind, [
:available, 0,
:deprecated, 1,
:not_available, 2,
:not_accessible, 3
]
# A character string.
#
# The \c CXString type is used to return strings from the interface when
# the ownership of that string might different from one call to the next.
# Use \c clang_getCString() to retrieve the string data and, once finished
# with the string data, call \c clang_disposeString() to free the string.
#
# = Fields:
# :data ::
# (FFI::Pointer(*Void))
# :private_flags ::
# (Integer)
class String < FFI::Struct
layout :data, :pointer,
:private_flags, :uint
end
# Retrieve the character data associated with the given string.
#
# @method get_c_string(string)
# @param [String] string
# @return [String]
# @scope class
attach_function :get_c_string, :clang_getCString, [String.by_value], :string
# Free the given string,
#
# @method dispose_string(string)
# @param [String] string
# @return [nil]
# @scope class
attach_function :dispose_string, :clang_disposeString, [String.by_value], :void
# clang_createIndex() provides a shared context for creating
# translation units. It provides two options:
#
# - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
# declarations (when loading any new translation units). A "local" declaration
# is one that belongs in the translation unit itself and not in a precompiled
# header that was used by the translation unit. If zero, all declarations
# will be enumerated.
#
# Here is an example:
#
# // excludeDeclsFromPCH = 1, displayDiagnostics=1
# Idx = clang_createIndex(1, 1);
#
# // IndexTest.pch was produced with the following command:
# // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
# TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
#
# // This will load all the symbols from 'IndexTest.pch'
# clang_visitChildren(clang_getTranslationUnitCursor(TU),
# TranslationUnitVisitor, 0);
# clang_disposeTranslationUnit(TU);
#
# // This will load all the symbols from 'IndexTest.c', excluding symbols
# // from 'IndexTest.pch'.
# char *args() = { "-Xclang", "-include-pch=IndexTest.pch" };
# TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
# 0, 0);
# clang_visitChildren(clang_getTranslationUnitCursor(TU),
# TranslationUnitVisitor, 0);
# clang_disposeTranslationUnit(TU);
#
# This process of creating the 'pch', loading it separately, and using it (via
# -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
# (which gives the indexer the same performance benefit as the compiler).
#
# @method create_index(exclude_declarations_from_pch, display_diagnostics)
# @param [Integer] exclude_declarations_from_pch
# @param [Integer] display_diagnostics
# @return [FFI::Pointer(Index)]
# @scope class
attach_function :create_index, :clang_createIndex, [:int, :int], :pointer
# Destroy the given index.
#
# The index must not be destroyed until all of the translation units created
# within that index have been destroyed.
#
# @method dispose_index(index)
# @param [FFI::Pointer(Index)] index
# @return [nil]
# @scope class
attach_function :dispose_index, :clang_disposeIndex, [:pointer], :void
# Retrieve the complete file and path name of the given file.
#
# @method get_file_name(s_file)
# @param [FFI::Pointer(File)] s_file
# @return [String]
# @scope class
attach_function :get_file_name, :clang_getFileName, [:pointer], String.by_value
# Retrieve the last modification time of the given file.
#
# @method get_file_time(s_file)
# @param [FFI::Pointer(File)] s_file
# @return [Integer]
# @scope class
attach_function :get_file_time, :clang_getFileTime, [:pointer], :long
# Determine whether the given header is guarded against
# multiple inclusions, either with the conventional
# #ifndef/#define/#endif macro guards or with #pragma once.
#
# @method is_file_multiple_include_guarded(tu, file)
# @param [TranslationUnitImpl] tu
# @param [FFI::Pointer(File)] file
# @return [Integer]
# @scope class
attach_function :is_file_multiple_include_guarded, :clang_isFileMultipleIncludeGuarded, [TranslationUnitImpl, :pointer], :uint
# Retrieve a file handle within the given translation unit.
#
# @method get_file(tu, file_name)
# @param [TranslationUnitImpl] tu the translation unit
# @param [String] file_name the name of the file.
# @return [FFI::Pointer(File)] the file handle for the named file in the translation unit \p tu,
# or a NULL file handle if the file was not a part of this translation unit.
# @scope class
attach_function :get_file, :clang_getFile, [TranslationUnitImpl, :string], :pointer
# Identifies a specific source location within a translation
# unit.
#
# Use clang_getExpansionLocation() or clang_getSpellingLocation()
# to map a source location to a particular file, line, and column.
#
# = Fields:
# :ptr_data ::
# (Array<FFI::Pointer(*Void)>)
# :int_data ::
# (Integer)
class SourceLocation < FFI::Struct
layout :ptr_data, [:pointer, 2],
:int_data, :uint
end
# Identifies a half-open character range in the source code.
#
# Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
# starting and end locations from a source range, respectively.
#
# = Fields:
# :ptr_data ::
# (Array<FFI::Pointer(*Void)>)
# :begin_int_data ::
# (Integer)
# :end_int_data ::
# (Integer)
class SourceRange < FFI::Struct
layout :ptr_data, [:pointer, 2],
:begin_int_data, :uint,
:end_int_data, :uint
end
# Retrieve a NULL (invalid) source location.
#
# @method get_null_location()
# @return [SourceLocation]
# @scope class
attach_function :get_null_location, :clang_getNullLocation, [], SourceLocation.by_value
# Determine whether two source locations, which must refer into
# the same translation unit, refer to exactly the same point in the source
# code.
#
# @method equal_locations(loc1, loc2)
# @param [SourceLocation] loc1
# @param [SourceLocation] loc2
# @return [Integer] non-zero if the source locations refer to the same location, zero
# if they refer to different locations.
# @scope class
attach_function :equal_locations, :clang_equalLocations, [SourceLocation.by_value, SourceLocation.by_value], :uint
# Retrieves the source location associated with a given file/line/column
# in a particular translation unit.
#
# @method get_location(tu, file, line, column)
# @param [TranslationUnitImpl] tu
# @param [FFI::Pointer(File)] file
# @param [Integer] line
# @param [Integer] column
# @return [SourceLocation]
# @scope class
attach_function :get_location, :clang_getLocation, [TranslationUnitImpl, :pointer, :uint, :uint], SourceLocation.by_value
# Retrieves the source location associated with a given character offset
# in a particular translation unit.
#
# @method get_location_for_offset(tu, file, offset)
# @param [TranslationUnitImpl] tu
# @param [FFI::Pointer(File)] file
# @param [Integer] offset
# @return [SourceLocation]
# @scope class
attach_function :get_location_for_offset, :clang_getLocationForOffset, [TranslationUnitImpl, :pointer, :uint], SourceLocation.by_value
# Retrieve a NULL (invalid) source range.
#
# @method get_null_range()
# @return [SourceRange]
# @scope class
attach_function :get_null_range, :clang_getNullRange, [], SourceRange.by_value
# Retrieve a source range given the beginning and ending source
# locations.
#
# @method get_range(begin_, end_)
# @param [SourceLocation] begin_
# @param [SourceLocation] end_
# @return [SourceRange]
# @scope class
attach_function :get_range, :clang_getRange, [SourceLocation.by_value, SourceLocation.by_value], SourceRange.by_value
# Determine whether two ranges are equivalent.
#
# @method equal_ranges(range1, range2)
# @param [SourceRange] range1
# @param [SourceRange] range2
# @return [Integer] non-zero if the ranges are the same, zero if they differ.
# @scope class
attach_function :equal_ranges, :clang_equalRanges, [SourceRange.by_value, SourceRange.by_value], :uint
# Returns non-zero if \arg range is null.
#
# @method range_is_null(range)
# @param [SourceRange] range
# @return [Integer]
# @scope class
attach_function :range_is_null, :clang_Range_isNull, [SourceRange.by_value], :int
# Retrieve the file, line, column, and offset represented by
# the given source location.
#
# If the location refers into a macro expansion, retrieves the
# location of the macro expansion.
#
# @method get_expansion_location(location, file, line, column, offset)
# @param [SourceLocation] location the location within a source file that will be decomposed
# into its parts.
# @param [FFI::Pointer(*File)] file (out) if non-NULL, will be set to the file to which the given
# source location points.
# @param [FFI::Pointer(*UInt)] line (out) if non-NULL, will be set to the line to which the given
# source location points.
# @param [FFI::Pointer(*UInt)] column (out) if non-NULL, will be set to the column to which the given
# source location points.
# @param [FFI::Pointer(*UInt)] offset (out) if non-NULL, will be set to the offset into the
# buffer to which the given source location points.
# @return [nil]
# @scope class
attach_function :get_expansion_location, :clang_getExpansionLocation, [SourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
# Retrieve the file, line, column, and offset represented by
# the given source location, as specified in a # line directive.
#
# Example: given the following source code in a file somefile.c
#
# #123 "dummy.c" 1
#
# static int func(void)
# {
# return 0;
# }
#
# the location information returned by this function would be
#
# File: dummy.c Line: 124 Column: 12
#
# whereas clang_getExpansionLocation would have returned
#
# File: somefile.c Line: 3 Column: 12
#
# @method get_presumed_location(location, filename, line, column)
# @param [SourceLocation] location the location within a source file that will be decomposed
# into its parts.
# @param [String] filename (out) if non-NULL, will be set to the filename of the
# source location. Note that filenames returned will be for "virtual" files,
# which don't necessarily exist on the machine running clang - e.g. when
# parsing preprocessed output obtained from a different environment. If
# a non-NULL value is passed in, remember to dispose of the returned value
# using \c clang_disposeString() once you've finished with it. For an invalid
# source location, an empty string is returned.
# @param [FFI::Pointer(*UInt)] line (out) if non-NULL, will be set to the line number of the
# source location. For an invalid source location, zero is returned.
# @param [FFI::Pointer(*UInt)] column (out) if non-NULL, will be set to the column number of the
# source location. For an invalid source location, zero is returned.
# @return [nil]
# @scope class
attach_function :get_presumed_location, :clang_getPresumedLocation, [SourceLocation.by_value, String, :pointer, :pointer], :void
# Legacy API to retrieve the file, line, column, and offset represented
# by the given source location.
#
# This interface has been replaced by the newer interface
# \see clang_getExpansionLocation(). See that interface's documentation for
# details.
#
# @method get_instantiation_location(location, file, line, column, offset)
# @param [SourceLocation] location
# @param [FFI::Pointer(*File)] file
# @param [FFI::Pointer(*UInt)] line
# @param [FFI::Pointer(*UInt)] column
# @param [FFI::Pointer(*UInt)] offset
# @return [nil]
# @scope class
attach_function :get_instantiation_location, :clang_getInstantiationLocation, [SourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
# Retrieve the file, line, column, and offset represented by
# the given source location.
#
# If the location refers into a macro instantiation, return where the
# location was originally spelled in the source file.
#
# @method get_spelling_location(location, file, line, column, offset)
# @param [SourceLocation] location the location within a source file that will be decomposed
# into its parts.
# @param [FFI::Pointer(*File)] file (out) if non-NULL, will be set to the file to which the given
# source location points.
# @param [FFI::Pointer(*UInt)] line (out) if non-NULL, will be set to the line to which the given
# source location points.
# @param [FFI::Pointer(*UInt)] column (out) if non-NULL, will be set to the column to which the given
# source location points.
# @param [FFI::Pointer(*UInt)] offset (out) if non-NULL, will be set to the offset into the
# buffer to which the given source location points.
# @return [nil]
# @scope class
attach_function :get_spelling_location, :clang_getSpellingLocation, [SourceLocation.by_value, :pointer, :pointer, :pointer, :pointer], :void
# Retrieve a source location representing the first character within a
# source range.
#
# @method get_range_start(range)
# @param [SourceRange] range
# @return [SourceLocation]
# @scope class
attach_function :get_range_start, :clang_getRangeStart, [SourceRange.by_value], SourceLocation.by_value
# Retrieve a source location representing the last character within a
# source range.
#
# @method get_range_end(range)
# @param [SourceRange] range
# @return [SourceLocation]
# @scope class
attach_function :get_range_end, :clang_getRangeEnd, [SourceRange.by_value], SourceLocation.by_value
# Describes the severity of a particular diagnostic.
#
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:diagnostic_severity).</em>
#
# === Options:
# :ignored ::
# A diagnostic that has been suppressed, e.g., by a command-line
# option.
# :note ::
# This diagnostic is a note that should be attached to the
# previous (non-note) diagnostic.
# :warning ::
# This diagnostic indicates suspicious code that may not be
# wrong.
# :error ::
# This diagnostic indicates that the code is ill-formed.
# :fatal ::
# This diagnostic indicates that the code is ill-formed such
# that future parser recovery is unlikely to produce useful
# results.
#
# @method _enum_diagnostic_severity_
# @return [Symbol]
# @scope class
enum :diagnostic_severity, [
:ignored, 0,
:note, 1,
:warning, 2,
:error, 3,
:fatal, 4
]
# Determine the number of diagnostics produced for the given
# translation unit.
#
# @method get_num_diagnostics(unit)
# @param [TranslationUnitImpl] unit
# @return [Integer]
# @scope class
attach_function :get_num_diagnostics, :clang_getNumDiagnostics, [TranslationUnitImpl], :uint
# Retrieve a diagnostic associated with the given translation unit.
#
# @method get_diagnostic(unit, index)
# @param [TranslationUnitImpl] unit the translation unit to query.
# @param [Integer] index the zero-based diagnostic number to retrieve.
# @return [FFI::Pointer(Diagnostic)] the requested diagnostic. This diagnostic must be freed
# via a call to \c clang_disposeDiagnostic().
# @scope class
attach_function :get_diagnostic, :clang_getDiagnostic, [TranslationUnitImpl, :uint], :pointer
# Destroy a diagnostic.
#
# @method dispose_diagnostic(diagnostic)
# @param [FFI::Pointer(Diagnostic)] diagnostic
# @return [nil]
# @scope class
attach_function :dispose_diagnostic, :clang_disposeDiagnostic, [:pointer], :void
# Options to control the display of diagnostics.
#
# The values in this enum are meant to be combined to customize the
# behavior of \c clang_displayDiagnostic().
#
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:diagnostic_display_options).</em>
#
# === Options:
# :source_location ::
# Display the source-location information where the
# diagnostic was located.
#
# When set, diagnostics will be prefixed by the file, line, and
# (optionally) column to which the diagnostic refers. For example,
#
# \code
# test.c:28: warning: extra tokens at end of #endif directive
# \endcode
#
# This option corresponds to the clang flag \c -fshow-source-location.
# :column ::
# If displaying the source-location information of the
# diagnostic, also include the column number.
#
# This option corresponds to the clang flag \c -fshow-column.
# :source_ranges ::
# If displaying the source-location information of the
# diagnostic, also include information about source ranges in a
# machine-parsable format.
#
# This option corresponds to the clang flag
# \c -fdiagnostics-print-source-range-info.
# :option ::
# Display the option name associated with this diagnostic, if any.
#
# The option name displayed (e.g., -Wconversion) will be placed in brackets
# after the diagnostic text. This option corresponds to the clang flag
# \c -fdiagnostics-show-option.
# :category_id ::
# Display the category number associated with this diagnostic, if any.
#
# The category number is displayed within brackets after the diagnostic text.
# This option corresponds to the clang flag
# \c -fdiagnostics-show-category=id.
# :category_name ::
# Display the category name associated with this diagnostic, if any.
#
# The category name is displayed within brackets after the diagnostic text.
# This option corresponds to the clang flag
# \c -fdiagnostics-show-category=name.
#
# @method _enum_diagnostic_display_options_
# @return [Symbol]
# @scope class
enum :diagnostic_display_options, [
:source_location, 1,
:column, 2,
:source_ranges, 4,
:option, 8,
:category_id, 16,
:category_name, 32
]
# Format the given diagnostic in a manner that is suitable for display.
#
# This routine will format the given diagnostic to a string, rendering
# the diagnostic according to the various options given. The
# \c clang_defaultDiagnosticDisplayOptions() function returns the set of
# options that most closely mimics the behavior of the clang compiler.
#
# @method format_diagnostic(diagnostic, options)
# @param [FFI::Pointer(Diagnostic)] diagnostic The diagnostic to print.
# @param [Integer] options A set of options that control the diagnostic display,
# created by combining \c CXDiagnosticDisplayOptions values.
# @return [String] A new string containing for formatted diagnostic.
# @scope class
attach_function :format_diagnostic, :clang_formatDiagnostic, [:pointer, :uint], String.by_value
# Retrieve the set of display options most similar to the
# default behavior of the clang compiler.
#
# @method default_diagnostic_display_options()
# @return [Integer] A set of display options suitable for use with \c
# clang_displayDiagnostic().
# @scope class
attach_function :default_diagnostic_display_options, :clang_defaultDiagnosticDisplayOptions, [], :uint
# Determine the severity of the given diagnostic.
#
# @method get_diagnostic_severity(diagnostic)
# @param [FFI::Pointer(Diagnostic)] diagnostic
# @return [Symbol from _enum_diagnostic_severity_]
# @scope class
attach_function :get_diagnostic_severity, :clang_getDiagnosticSeverity, [:pointer], :diagnostic_severity
# Retrieve the source location of the given diagnostic.
#
# This location is where Clang would print the caret ('^') when
# displaying the diagnostic on the command line.
#
# @method get_diagnostic_location(diagnostic)
# @param [FFI::Pointer(Diagnostic)] diagnostic
# @return [SourceLocation]
# @scope class
attach_function :get_diagnostic_location, :clang_getDiagnosticLocation, [:pointer], SourceLocation.by_value
# Retrieve the text of the given diagnostic.
#
# @method get_diagnostic_spelling(diagnostic)
# @param [FFI::Pointer(Diagnostic)] diagnostic
# @return [String]
# @scope class
attach_function :get_diagnostic_spelling, :clang_getDiagnosticSpelling, [:pointer], String.by_value
# Retrieve the name of the command-line option that enabled this
# diagnostic.
#
# @method get_diagnostic_option(diag, disable)
# @param [FFI::Pointer(Diagnostic)] diag The diagnostic to be queried.
# @param [String] disable If non-NULL, will be set to the option that disables this
# diagnostic (if any).
# @return [String] A string that contains the command-line option used to enable this
# warning, such as "-Wconversion" or "-pedantic".
# @scope class
attach_function :get_diagnostic_option, :clang_getDiagnosticOption, [:pointer, String], String.by_value
# Retrieve the category number for this diagnostic.
#
# Diagnostics can be categorized into groups along with other, related
# diagnostics (e.g., diagnostics under the same warning flag). This routine
# retrieves the category number for the given diagnostic.
#
# @method get_diagnostic_category(diagnostic)
# @param [FFI::Pointer(Diagnostic)] diagnostic
# @return [Integer] The number of the category that contains this diagnostic, or zero
# if this diagnostic is uncategorized.
# @scope class
attach_function :get_diagnostic_category, :clang_getDiagnosticCategory, [:pointer], :uint
# Retrieve the name of a particular diagnostic category.
#
# @method get_diagnostic_category_name(category)
# @param [Integer] category A diagnostic category number, as returned by
# \c clang_getDiagnosticCategory().
# @return [String] The name of the given diagnostic category.
# @scope class
attach_function :get_diagnostic_category_name, :clang_getDiagnosticCategoryName, [:uint], String.by_value
# Determine the number of source ranges associated with the given
# diagnostic.
#
# @method get_diagnostic_num_ranges(diagnostic)
# @param [FFI::Pointer(Diagnostic)] diagnostic
# @return [Integer]
# @scope class
attach_function :get_diagnostic_num_ranges, :clang_getDiagnosticNumRanges, [:pointer], :uint
# Retrieve a source range associated with the diagnostic.
#
# A diagnostic's source ranges highlight important elements in the source
# code. On the command line, Clang displays source ranges by
# underlining them with '~' characters.
#
# @method get_diagnostic_range(diagnostic, range)
# @param [FFI::Pointer(Diagnostic)] diagnostic the diagnostic whose range is being extracted.
# @param [Integer] range the zero-based index specifying which range to
# @return [SourceRange] the requested source range.
# @scope class
attach_function :get_diagnostic_range, :clang_getDiagnosticRange, [:pointer, :uint], SourceRange.by_value
# Determine the number of fix-it hints associated with the
# given diagnostic.
#
# @method get_diagnostic_num_fix_its(diagnostic)
# @param [FFI::Pointer(Diagnostic)] diagnostic
# @return [Integer]
# @scope class
attach_function :get_diagnostic_num_fix_its, :clang_getDiagnosticNumFixIts, [:pointer], :uint
# Retrieve the replacement information for a given fix-it.
#
# Fix-its are described in terms of a source range whose contents
# should be replaced by a string. This approach generalizes over
# three kinds of operations: removal of source code (the range covers
# the code to be removed and the replacement string is empty),
# replacement of source code (the range covers the code to be
# replaced and the replacement string provides the new code), and
# insertion (both the start and end of the range point at the
# insertion location, and the replacement string provides the text to
# insert).
#
# @method get_diagnostic_fix_it(diagnostic, fix_it, replacement_range)
# @param [FFI::Pointer(Diagnostic)] diagnostic The diagnostic whose fix-its are being queried.
# @param [Integer] fix_it The zero-based index of the fix-it.
# @param [SourceRange] replacement_range The source range whose contents will be
# replaced with the returned replacement string. Note that source
# ranges are half-open ranges (a, b), so the source code should be
# replaced from a and up to (but not including) b.
# @return [String] A string containing text that should be replace the source
# code indicated by the \c ReplacementRange.
# @scope class
attach_function :get_diagnostic_fix_it, :clang_getDiagnosticFixIt, [:pointer, :uint, SourceRange], String.by_value
# Get the original translation unit source file name.
#
# @method get_translation_unit_spelling(ct_unit)
# @param [TranslationUnitImpl] ct_unit
# @return [String]
# @scope class
attach_function :get_translation_unit_spelling, :clang_getTranslationUnitSpelling, [TranslationUnitImpl], String.by_value
# Return the CXTranslationUnit for a given source file and the provided
# command line arguments one would pass to the compiler.
#
# Note: The 'source_filename' argument is optional. If the caller provides a
# NULL pointer, the name of the source file is expected to reside in the
# specified command line arguments.
#
# Note: When encountered in 'clang_command_line_args', the following options
# are ignored:
#
# '-c'
# '-emit-ast'
# '-fsyntax-only'
# '-o <output file>' (both '-o' and '<output file>' are ignored)
#
# @method create_translation_unit_from_source_file(c_idx, source_filename, num_clang_command_line_args, command_line_args, num_unsaved_files, unsaved_files)
# @param [FFI::Pointer(Index)] c_idx The index object with which the translation unit will be
# associated.
# @param [String] source_filename - The name of the source file to load, or NULL if the
# source file is included in \p clang_command_line_args.
# @param [Integer] num_clang_command_line_args The number of command-line arguments in
# \p clang_command_line_args.
# @param [FFI::Pointer(**CharS)] command_line_args The command-line arguments that would be
# passed to the \c clang executable if it were being invoked out-of-process.
# These command-line options will be parsed and will affect how the translation
# unit is parsed. Note that the following options are ignored: '-c',
# '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
# @param [Integer] num_unsaved_files the number of unsaved file entries in \p
# unsaved_files.
# @param [UnsavedFile] unsaved_files the files that have not yet been saved to disk
# but may be required for code completion, including the contents of
# those files. The contents and name of these files (as specified by
# CXUnsavedFile) are copied when necessary, so the client only needs to
# guarantee their validity until the call to this function returns.
# @return [TranslationUnitImpl]
# @scope class
attach_function :create_translation_unit_from_source_file, :clang_createTranslationUnitFromSourceFile, [:pointer, :string, :int, :pointer, :uint, UnsavedFile], TranslationUnitImpl
# Create a translation unit from an AST file (-emit-ast).
#
# @method create_translation_unit(index, ast_filename)
# @param [FFI::Pointer(Index)] index
# @param [String] ast_filename
# @return [TranslationUnitImpl]
# @scope class
attach_function :create_translation_unit, :clang_createTranslationUnit, [:pointer, :string], TranslationUnitImpl
# Flags that control the creation of translation units.
#
# The enumerators in this enumeration type are meant to be bitwise
# ORed together to specify which options should be used when
# constructing the translation unit.
#
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:translation_unit_flags).</em>
#
# === Options:
# :none ::
# Used to indicate that no special translation-unit options are
# needed.
# :detailed_preprocessing_record ::
# Used to indicate that the parser should construct a "detailed"
# preprocessing record, including all macro definitions and instantiations.
#
# Constructing a detailed preprocessing record requires more memory
# and time to parse, since the information contained in the record
# is usually not retained. However, it can be useful for
# applications that require more detailed information about the
# behavior of the preprocessor.
# :incomplete ::
# Used to indicate that the translation unit is incomplete.
#
# When a translation unit is considered "incomplete", semantic
# analysis that is typically performed at the end of the
# translation unit will be suppressed. For example, this suppresses
# the completion of tentative declarations in C and of
# instantiation of implicitly-instantiation function templates in
# C++. This option is typically used when parsing a header with the
# intent of producing a precompiled header.
# :precompiled_preamble ::
# Used to indicate that the translation unit should be built with an
# implicit precompiled header for the preamble.
#
# An implicit precompiled header is used as an optimization when a
# particular translation unit is likely to be reparsed many times
# when the sources aren't changing that often. In this case, an
# implicit precompiled header will be built containing all of the
# initial includes at the top of the main file (what we refer to as
# the "preamble" of the file). In subsequent parses, if the
# preamble or the files in it have not changed, \c
# clang_reparseTranslationUnit() will re-use the implicit
# precompiled header to improve parsing performance.
# :cache_completion_results ::
# Used to indicate that the translation unit should cache some
# code-completion results with each reparse of the source file.
#
# Caching of code-completion results is a performance optimization that
# introduces some overhead to reparsing but improves the performance of
# code-completion operations.
# :cxx_precompiled_preamble ::
# DEPRECATED: Enable precompiled preambles in C++.
#
# Note: this is a *temporary* option that is available only while
# we are testing C++ precompiled preamble support. It is deprecated.
# :cxx_chained_pch ::
# DEPRECATED: Enabled chained precompiled preambles in C++.
#
# Note: this is a *temporary* option that is available only while
# we are testing C++ precompiled preamble support. It is deprecated.
# :nested_macro_expansions ::
# Used to indicate that the "detailed" preprocessing record,
# if requested, should also contain nested macro expansions.
#
# Nested macro expansions (i.e., macro expansions that occur
# inside another macro expansion) can, in some code bases, require
# a large amount of storage to due preprocessor metaprogramming. Moreover,
# its fairly rare that this information is useful for libclang clients.
#
# @method _enum_translation_unit_flags_
# @return [Symbol]
# @scope class
enum :translation_unit_flags, [
:none, 0,
:detailed_preprocessing_record, 1,
:incomplete, 2,
:precompiled_preamble, 4,
:cache_completion_results, 8,
:cxx_precompiled_preamble, 16,
:cxx_chained_pch, 32,
:nested_macro_expansions, 64
]
# Returns the set of flags that is suitable for parsing a translation
# unit that is being edited.
#
# The set of flags returned provide options for \c clang_parseTranslationUnit()
# to indicate that the translation unit is likely to be reparsed many times,
# either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
# (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
# set contains an unspecified set of optimizations (e.g., the precompiled
# preamble) geared toward improving the performance of these routines. The
# set of optimizations enabled may change from one version to the next.
#
# @method default_editing_translation_unit_options()
# @return [Integer]
# @scope class
attach_function :default_editing_translation_unit_options, :clang_defaultEditingTranslationUnitOptions, [], :uint
# Parse the given source file and the translation unit corresponding
# to that file.
#
# This routine is the main entry point for the Clang C API, providing the
# ability to parse a source file into a translation unit that can then be
# queried by other functions in the API. This routine accepts a set of
# command-line arguments so that the compilation can be configured in the same
# way that the compiler is configured on the command line.
#
# @method parse_translation_unit(c_idx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, options)
# @param [FFI::Pointer(Index)] c_idx The index object with which the translation unit will be
# associated.
# @param [String] source_filename The name of the source file to load, or NULL if the
# source file is included in \p command_line_args.
# @param [FFI::Pointer(**CharS)] command_line_args The command-line arguments that would be
# passed to the \c clang executable if it were being invoked out-of-process.
# These command-line options will be parsed and will affect how the translation
# unit is parsed. Note that the following options are ignored: '-c',
# '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
# @param [Integer] num_command_line_args The number of command-line arguments in
# \p command_line_args.
# @param [UnsavedFile] unsaved_files the files that have not yet been saved to disk
# but may be required for parsing, including the contents of
# those files. The contents and name of these files (as specified by
# CXUnsavedFile) are copied when necessary, so the client only needs to
# guarantee their validity until the call to this function returns.
# @param [Integer] num_unsaved_files the number of unsaved file entries in \p
# unsaved_files.
# @param [Integer] options A bitmask of options that affects how the translation unit
# is managed but not its compilation. This should be a bitwise OR of the
# CXTranslationUnit_XXX flags.
# @return [TranslationUnitImpl] A new translation unit describing the parsed code and containing
# any diagnostics produced by the compiler. If there is a failure from which
# the compiler cannot recover, returns NULL.
# @scope class
attach_function :parse_translation_unit, :clang_parseTranslationUnit, [:pointer, :string, :pointer, :int, UnsavedFile, :uint, :uint], TranslationUnitImpl
# Flags that control how translation units are saved.
#
# The enumerators in this enumeration type are meant to be bitwise
# ORed together to specify which options should be used when
# saving the translation unit.
#
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:save_translation_unit_flags).</em>
#
# === Options:
# :save_translation_unit_none ::
# Used to indicate that no special saving options are needed.
#
# @method _enum_save_translation_unit_flags_
# @return [Symbol]
# @scope class
enum :save_translation_unit_flags, [
:save_translation_unit_none, 0
]
# Returns the set of flags that is suitable for saving a translation
# unit.
#
# The set of flags returned provide options for
# \c clang_saveTranslationUnit() by default. The returned flag
# set contains an unspecified set of options that save translation units with
# the most commonly-requested data.
#
# @method default_save_options(tu)
# @param [TranslationUnitImpl] tu
# @return [Integer]
# @scope class
attach_function :default_save_options, :clang_defaultSaveOptions, [TranslationUnitImpl], :uint
# Describes the kind of error that occurred (if any) in a call to
# \c clang_saveTranslationUnit().
#
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:save_error).</em>
#
# === Options:
# :none ::
# Indicates that no error occurred while saving a translation unit.
# :unknown ::
# Indicates that an unknown error occurred while attempting to save
# the file.
#
# This error typically indicates that file I/O failed when attempting to
# write the file.
# :translation_errors ::
# Indicates that errors during translation prevented this attempt
# to save the translation unit.
#
# Errors that prevent the translation unit from being saved can be
# extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
# :invalid_tu ::
# Indicates that the translation unit to be saved was somehow
# invalid (e.g., NULL).
#
# @method _enum_save_error_
# @return [Symbol]
# @scope class
enum :save_error, [
:none, 0,
:unknown, 1,
:translation_errors, 2,
:invalid_tu, 3
]
# Saves a translation unit into a serialized representation of
# that translation unit on disk.
#
# Any translation unit that was parsed without error can be saved
# into a file. The translation unit can then be deserialized into a
# new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
# if it is an incomplete translation unit that corresponds to a
# header, used as a precompiled header when parsing other translation
# units.
#
# @method save_translation_unit(tu, file_name, options)
# @param [TranslationUnitImpl] tu The translation unit to save.
# @param [String] file_name The file to which the translation unit will be saved.
# @param [Integer] options A bitmask of options that affects how the translation unit
# is saved. This should be a bitwise OR of the
# CXSaveTranslationUnit_XXX flags.
# @return [Integer] A value that will match one of the enumerators of the CXSaveError
# enumeration. Zero (CXSaveError_None) indicates that the translation unit was
# saved successfully, while a non-zero value indicates that a problem occurred.
# @scope class
attach_function :save_translation_unit, :clang_saveTranslationUnit, [TranslationUnitImpl, :string, :uint], :int
# Destroy the specified CXTranslationUnit object.
#
# @method dispose_translation_unit(translation_unit_impl)
# @param [TranslationUnitImpl] translation_unit_impl
# @return [nil]
# @scope class
attach_function :dispose_translation_unit, :clang_disposeTranslationUnit, [TranslationUnitImpl], :void
# Flags that control the reparsing of translation units.
#
# The enumerators in this enumeration type are meant to be bitwise
# ORed together to specify which options should be used when
# reparsing the translation unit.
#
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:reparse_flags).</em>
#
# === Options:
# :reparse_none ::
# Used to indicate that no special reparsing options are needed.
#
# @method _enum_reparse_flags_
# @return [Symbol]
# @scope class
enum :reparse_flags, [
:reparse_none, 0
]
# Returns the set of flags that is suitable for reparsing a translation
# unit.
#
# The set of flags returned provide options for
# \c clang_reparseTranslationUnit() by default. The returned flag
# set contains an unspecified set of optimizations geared toward common uses
# of reparsing. The set of optimizations enabled may change from one version
# to the next.
#
# @method default_reparse_options(tu)
# @param [TranslationUnitImpl] tu
# @return [Integer]
# @scope class