-
Notifications
You must be signed in to change notification settings - Fork 68
/
LibClang.jl
6932 lines (5617 loc) · 640 KB
/
LibClang.jl
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
module LibClang
using Clang_jll
export Clang_jll
using CEnum
const Ctime_t = Int
"""
CXString
A character string.
The [`CXString`](@ref) type is used to return strings from the interface when the ownership of that string might differ from one call to the next. Use [`clang_getCString`](@ref)() to retrieve the string data and, once finished with the string data, call [`clang_disposeString`](@ref)() to free the string.
"""
struct CXString
data::Ptr{Cvoid}
private_flags::Cuint
end
struct CXStringSet
Strings::Ptr{CXString}
Count::Cuint
end
"""
clang_getCString(string)
Retrieve the character data associated with the given string.
"""
function clang_getCString(string)
@ccall libclang.clang_getCString(string::CXString)::Cstring
end
"""
clang_disposeString(string)
Free the given string.
"""
function clang_disposeString(string)
@ccall libclang.clang_disposeString(string::CXString)::Cvoid
end
"""
clang_disposeStringSet(set)
Free the given string set.
"""
function clang_disposeStringSet(set)
@ccall libclang.clang_disposeStringSet(set::Ptr{CXStringSet})::Cvoid
end
"""
A compilation database holds all information used to compile files in a project. For each file in the database, it can be queried for the working directory or the command line used for the compiler invocation.
Must be freed by [`clang_CompilationDatabase_dispose`](@ref)
"""
const CXCompilationDatabase = Ptr{Cvoid}
"""
Contains the results of a search in the compilation database
When searching for the compile command for a file, the compilation db can return several commands, as the file may have been compiled with different options in different places of the project. This choice of compile commands is wrapped in this opaque data structure. It must be freed by [`clang_CompileCommands_dispose`](@ref).
"""
const CXCompileCommands = Ptr{Cvoid}
"""
Represents the command line invocation to compile a specific file.
"""
const CXCompileCommand = Ptr{Cvoid}
"""
CXCompilationDatabase_Error
Error codes for Compilation Database
"""
@cenum CXCompilationDatabase_Error::UInt32 begin
CXCompilationDatabase_NoError = 0
CXCompilationDatabase_CanNotLoadDatabase = 1
end
"""
clang_CompilationDatabase_fromDirectory(BuildDir, ErrorCode)
Creates a compilation database from the database found in directory buildDir. For example, CMake can output a compile\\_commands.json which can be used to build the database.
It must be freed by [`clang_CompilationDatabase_dispose`](@ref).
"""
function clang_CompilationDatabase_fromDirectory(BuildDir, ErrorCode)
@ccall libclang.clang_CompilationDatabase_fromDirectory(BuildDir::Cstring, ErrorCode::Ptr{CXCompilationDatabase_Error})::CXCompilationDatabase
end
"""
clang_CompilationDatabase_dispose(arg1)
Free the given compilation database
"""
function clang_CompilationDatabase_dispose(arg1)
@ccall libclang.clang_CompilationDatabase_dispose(arg1::CXCompilationDatabase)::Cvoid
end
"""
clang_CompilationDatabase_getCompileCommands(arg1, CompleteFileName)
Find the compile commands used for a file. The compile commands must be freed by [`clang_CompileCommands_dispose`](@ref).
"""
function clang_CompilationDatabase_getCompileCommands(arg1, CompleteFileName)
@ccall libclang.clang_CompilationDatabase_getCompileCommands(arg1::CXCompilationDatabase, CompleteFileName::Cstring)::CXCompileCommands
end
"""
clang_CompilationDatabase_getAllCompileCommands(arg1)
Get all the compile commands in the given compilation database.
"""
function clang_CompilationDatabase_getAllCompileCommands(arg1)
@ccall libclang.clang_CompilationDatabase_getAllCompileCommands(arg1::CXCompilationDatabase)::CXCompileCommands
end
"""
clang_CompileCommands_dispose(arg1)
Free the given CompileCommands
"""
function clang_CompileCommands_dispose(arg1)
@ccall libclang.clang_CompileCommands_dispose(arg1::CXCompileCommands)::Cvoid
end
"""
clang_CompileCommands_getSize(arg1)
Get the number of CompileCommand we have for a file
"""
function clang_CompileCommands_getSize(arg1)
@ccall libclang.clang_CompileCommands_getSize(arg1::CXCompileCommands)::Cuint
end
"""
clang_CompileCommands_getCommand(arg1, I)
Get the I'th CompileCommand for a file
Note : 0 <= i < [`clang_CompileCommands_getSize`](@ref)([`CXCompileCommands`](@ref))
"""
function clang_CompileCommands_getCommand(arg1, I)
@ccall libclang.clang_CompileCommands_getCommand(arg1::CXCompileCommands, I::Cuint)::CXCompileCommand
end
"""
clang_CompileCommand_getDirectory(arg1)
Get the working directory where the CompileCommand was executed from
"""
function clang_CompileCommand_getDirectory(arg1)
@ccall libclang.clang_CompileCommand_getDirectory(arg1::CXCompileCommand)::CXString
end
"""
clang_CompileCommand_getFilename(arg1)
Get the filename associated with the CompileCommand.
"""
function clang_CompileCommand_getFilename(arg1)
@ccall libclang.clang_CompileCommand_getFilename(arg1::CXCompileCommand)::CXString
end
"""
clang_CompileCommand_getNumArgs(arg1)
Get the number of arguments in the compiler invocation.
"""
function clang_CompileCommand_getNumArgs(arg1)
@ccall libclang.clang_CompileCommand_getNumArgs(arg1::CXCompileCommand)::Cuint
end
"""
clang_CompileCommand_getArg(arg1, I)
Get the I'th argument value in the compiler invocations
Invariant : - argument 0 is the compiler executable
"""
function clang_CompileCommand_getArg(arg1, I)
@ccall libclang.clang_CompileCommand_getArg(arg1::CXCompileCommand, I::Cuint)::CXString
end
"""
clang_CompileCommand_getNumMappedSources(arg1)
Get the number of source mappings for the compiler invocation.
"""
function clang_CompileCommand_getNumMappedSources(arg1)
@ccall libclang.clang_CompileCommand_getNumMappedSources(arg1::CXCompileCommand)::Cuint
end
"""
clang_CompileCommand_getMappedSourcePath(arg1, I)
Get the I'th mapped source path for the compiler invocation.
"""
function clang_CompileCommand_getMappedSourcePath(arg1, I)
@warn "`clang_CompileCommand_getMappedSourcePath` Left here for backward compatibility.\nNo mapped sources exists in the C++ backend anymore.\nThis function just return Null `CXString`.\nSee:\n- [Remove unused CompilationDatabase::MappedSources](https://reviews.llvm.org/D32351)\n"
@ccall libclang.clang_CompileCommand_getMappedSourcePath(arg1::CXCompileCommand, I::Cuint)::CXString
end
"""
clang_CompileCommand_getMappedSourceContent(arg1, I)
Get the I'th mapped source content for the compiler invocation.
"""
function clang_CompileCommand_getMappedSourceContent(arg1, I)
@warn "`clang_CompileCommand_getMappedSourceContent` Left here for backward compatibility.\nNo mapped sources exists in the C++ backend anymore.\nThis function just return Null `CXString`.\nSee:\n- [Remove unused CompilationDatabase::MappedSources](https://reviews.llvm.org/D32351)\n"
@ccall libclang.clang_CompileCommand_getMappedSourceContent(arg1::CXCompileCommand, I::Cuint)::CXString
end
"""
CXErrorCode
Error codes returned by libclang routines.
Zero (`CXError_Success`) is the only error code indicating success. Other error codes, including not yet assigned non-zero values, indicate errors.
| Enumerator | Note |
| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------ |
| CXError\\_Success | No error. |
| CXError\\_Failure | A generic error code, no further details are available. Errors of this kind can get their own specific error codes in future libclang versions. |
| CXError\\_Crashed | libclang crashed while performing the requested operation. |
| CXError\\_InvalidArguments | The function detected that the arguments violate the function contract. |
| CXError\\_ASTReadError | An AST deserialization error has occurred. |
"""
@cenum CXErrorCode::UInt32 begin
CXError_Success = 0
CXError_Failure = 1
CXError_Crashed = 2
CXError_InvalidArguments = 3
CXError_ASTReadError = 4
end
"""
clang_getBuildSessionTimestamp()
Return the timestamp for use with Clang's `-fbuild-session-timestamp=` option.
"""
function clang_getBuildSessionTimestamp()
@ccall libclang.clang_getBuildSessionTimestamp()::Culonglong
end
mutable struct CXVirtualFileOverlayImpl end
"""
Object encapsulating information about overlaying virtual file/directories over the real file system.
"""
const CXVirtualFileOverlay = Ptr{CXVirtualFileOverlayImpl}
"""
clang_VirtualFileOverlay_create(options)
Create a [`CXVirtualFileOverlay`](@ref) object. Must be disposed with [`clang_VirtualFileOverlay_dispose`](@ref)().
### Parameters
* `options`: is reserved, always pass 0.
"""
function clang_VirtualFileOverlay_create(options)
@ccall libclang.clang_VirtualFileOverlay_create(options::Cuint)::CXVirtualFileOverlay
end
"""
clang_VirtualFileOverlay_addFileMapping(arg1, virtualPath, realPath)
Map an absolute virtual file path to an absolute real one. The virtual path must be canonicalized (not contain "."/"..").
### Returns
0 for success, non-zero to indicate an error.
"""
function clang_VirtualFileOverlay_addFileMapping(arg1, virtualPath, realPath)
@ccall libclang.clang_VirtualFileOverlay_addFileMapping(arg1::CXVirtualFileOverlay, virtualPath::Cstring, realPath::Cstring)::CXErrorCode
end
"""
clang_VirtualFileOverlay_setCaseSensitivity(arg1, caseSensitive)
Set the case sensitivity for the [`CXVirtualFileOverlay`](@ref) object. The [`CXVirtualFileOverlay`](@ref) object is case-sensitive by default, this option can be used to override the default.
### Returns
0 for success, non-zero to indicate an error.
"""
function clang_VirtualFileOverlay_setCaseSensitivity(arg1, caseSensitive)
@ccall libclang.clang_VirtualFileOverlay_setCaseSensitivity(arg1::CXVirtualFileOverlay, caseSensitive::Cint)::CXErrorCode
end
"""
clang_VirtualFileOverlay_writeToBuffer(arg1, options, out_buffer_ptr, out_buffer_size)
Write out the [`CXVirtualFileOverlay`](@ref) object to a char buffer.
### Parameters
* `options`: is reserved, always pass 0.
* `out_buffer_ptr`: pointer to receive the buffer pointer, which should be disposed using [`clang_free`](@ref)().
* `out_buffer_size`: pointer to receive the buffer size.
### Returns
0 for success, non-zero to indicate an error.
"""
function clang_VirtualFileOverlay_writeToBuffer(arg1, options, out_buffer_ptr, out_buffer_size)
@ccall libclang.clang_VirtualFileOverlay_writeToBuffer(arg1::CXVirtualFileOverlay, options::Cuint, out_buffer_ptr::Ptr{Cstring}, out_buffer_size::Ptr{Cuint})::CXErrorCode
end
"""
clang_free(buffer)
free memory allocated by libclang, such as the buffer returned by [`CXVirtualFileOverlay`](@ref)() or [`clang_ModuleMapDescriptor_writeToBuffer`](@ref)().
### Parameters
* `buffer`: memory pointer to free.
"""
function clang_free(buffer)
@ccall libclang.clang_free(buffer::Ptr{Cvoid})::Cvoid
end
"""
clang_VirtualFileOverlay_dispose(arg1)
Dispose a [`CXVirtualFileOverlay`](@ref) object.
"""
function clang_VirtualFileOverlay_dispose(arg1)
@ccall libclang.clang_VirtualFileOverlay_dispose(arg1::CXVirtualFileOverlay)::Cvoid
end
mutable struct CXModuleMapDescriptorImpl end
"""
Object encapsulating information about a module.map file.
"""
const CXModuleMapDescriptor = Ptr{CXModuleMapDescriptorImpl}
"""
clang_ModuleMapDescriptor_create(options)
Create a [`CXModuleMapDescriptor`](@ref) object. Must be disposed with [`clang_ModuleMapDescriptor_dispose`](@ref)().
### Parameters
* `options`: is reserved, always pass 0.
"""
function clang_ModuleMapDescriptor_create(options)
@ccall libclang.clang_ModuleMapDescriptor_create(options::Cuint)::CXModuleMapDescriptor
end
"""
clang_ModuleMapDescriptor_setFrameworkModuleName(arg1, name)
Sets the framework module name that the module.map describes.
### Returns
0 for success, non-zero to indicate an error.
"""
function clang_ModuleMapDescriptor_setFrameworkModuleName(arg1, name)
@ccall libclang.clang_ModuleMapDescriptor_setFrameworkModuleName(arg1::CXModuleMapDescriptor, name::Cstring)::CXErrorCode
end
"""
clang_ModuleMapDescriptor_setUmbrellaHeader(arg1, name)
Sets the umbrella header name that the module.map describes.
### Returns
0 for success, non-zero to indicate an error.
"""
function clang_ModuleMapDescriptor_setUmbrellaHeader(arg1, name)
@ccall libclang.clang_ModuleMapDescriptor_setUmbrellaHeader(arg1::CXModuleMapDescriptor, name::Cstring)::CXErrorCode
end
"""
clang_ModuleMapDescriptor_writeToBuffer(arg1, options, out_buffer_ptr, out_buffer_size)
Write out the [`CXModuleMapDescriptor`](@ref) object to a char buffer.
### Parameters
* `options`: is reserved, always pass 0.
* `out_buffer_ptr`: pointer to receive the buffer pointer, which should be disposed using [`clang_free`](@ref)().
* `out_buffer_size`: pointer to receive the buffer size.
### Returns
0 for success, non-zero to indicate an error.
"""
function clang_ModuleMapDescriptor_writeToBuffer(arg1, options, out_buffer_ptr, out_buffer_size)
@ccall libclang.clang_ModuleMapDescriptor_writeToBuffer(arg1::CXModuleMapDescriptor, options::Cuint, out_buffer_ptr::Ptr{Cstring}, out_buffer_size::Ptr{Cuint})::CXErrorCode
end
"""
clang_ModuleMapDescriptor_dispose(arg1)
Dispose a [`CXModuleMapDescriptor`](@ref) object.
"""
function clang_ModuleMapDescriptor_dispose(arg1)
@ccall libclang.clang_ModuleMapDescriptor_dispose(arg1::CXModuleMapDescriptor)::Cvoid
end
"""
An "index" that consists of a set of translation units that would typically be linked together into an executable or library.
"""
const CXIndex = Ptr{Cvoid}
mutable struct CXTargetInfoImpl end
"""
An opaque type representing target information for a given translation unit.
"""
const CXTargetInfo = Ptr{CXTargetInfoImpl}
mutable struct CXTranslationUnitImpl end
"""
A single translation unit, which resides in an index.
"""
const CXTranslationUnit = Ptr{CXTranslationUnitImpl}
"""
Opaque pointer representing client data that will be passed through to various callbacks and visitors.
"""
const CXClientData = Ptr{Cvoid}
"""
CXUnsavedFile
Provides the contents of a file that has not yet been saved to disk.
Each [`CXUnsavedFile`](@ref) 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.
| Field | Note |
| :------- | :-------------------------------------------------------------------------------------------------- |
| Filename | The file whose contents have not yet been saved. This file must already exist in the file system. |
| Contents | A buffer containing the unsaved contents of this file. |
| Length | The length of the unsaved contents of this buffer. |
"""
struct CXUnsavedFile
Filename::Cstring
Contents::Cstring
Length::Culong
end
"""
CXAvailabilityKind
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.
| Enumerator | Note |
| :----------------------------- | :---------------------------------------------------------------------------------- |
| CXAvailability\\_Available | The entity is available. |
| CXAvailability\\_Deprecated | The entity is available, but has been deprecated (and its use is not recommended). |
| CXAvailability\\_NotAvailable | The entity is not available; any use of it will be an error. |
| CXAvailability\\_NotAccessible | The entity is available, but not accessible; any use of it will be an error. |
"""
@cenum CXAvailabilityKind::UInt32 begin
CXAvailability_Available = 0
CXAvailability_Deprecated = 1
CXAvailability_NotAvailable = 2
CXAvailability_NotAccessible = 3
end
"""
CXVersion
Describes a version number of the form major.minor.subminor.
| Field | Note |
| :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Major | The major version number, e.g., the '10' in '10.7.3'. A negative value indicates that there is no version number at all. |
| Minor | The minor version number, e.g., the '7' in '10.7.3'. This value will be negative if no minor version number was provided, e.g., for version '10'. |
| Subminor | The subminor version number, e.g., the '3' in '10.7.3'. This value will be negative if no minor or subminor version number was provided, e.g., in version '10' or '10.7'. |
"""
struct CXVersion
Major::Cint
Minor::Cint
Subminor::Cint
end
"""
CXCursor_ExceptionSpecificationKind
Describes the exception specification of a cursor.
A negative value indicates that the cursor is not a function declaration.
| Enumerator | Note |
| :------------------------------------------------------- | :----------------------------------------------------------------- |
| CXCursor\\_ExceptionSpecificationKind\\_None | The cursor has no exception specification. |
| CXCursor\\_ExceptionSpecificationKind\\_DynamicNone | The cursor has exception specification throw() |
| CXCursor\\_ExceptionSpecificationKind\\_Dynamic | The cursor has exception specification throw(T1, T2) |
| CXCursor\\_ExceptionSpecificationKind\\_MSAny | The cursor has exception specification throw(...). |
| CXCursor\\_ExceptionSpecificationKind\\_BasicNoexcept | The cursor has exception specification basic noexcept. |
| CXCursor\\_ExceptionSpecificationKind\\_ComputedNoexcept | The cursor has exception specification computed noexcept. |
| CXCursor\\_ExceptionSpecificationKind\\_Unevaluated | The exception specification has not yet been evaluated. |
| CXCursor\\_ExceptionSpecificationKind\\_Uninstantiated | The exception specification has not yet been instantiated. |
| CXCursor\\_ExceptionSpecificationKind\\_Unparsed | The exception specification has not been parsed yet. |
| CXCursor\\_ExceptionSpecificationKind\\_NoThrow | The cursor has a \\_\\_declspec(nothrow) exception specification. |
"""
@cenum CXCursor_ExceptionSpecificationKind::UInt32 begin
CXCursor_ExceptionSpecificationKind_None = 0
CXCursor_ExceptionSpecificationKind_DynamicNone = 1
CXCursor_ExceptionSpecificationKind_Dynamic = 2
CXCursor_ExceptionSpecificationKind_MSAny = 3
CXCursor_ExceptionSpecificationKind_BasicNoexcept = 4
CXCursor_ExceptionSpecificationKind_ComputedNoexcept = 5
CXCursor_ExceptionSpecificationKind_Unevaluated = 6
CXCursor_ExceptionSpecificationKind_Uninstantiated = 7
CXCursor_ExceptionSpecificationKind_Unparsed = 8
CXCursor_ExceptionSpecificationKind_NoThrow = 9
end
"""
clang_createIndex(excludeDeclarationsFromPCH, displayDiagnostics)
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:
```c++
// 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).
"""
function clang_createIndex(excludeDeclarationsFromPCH, displayDiagnostics)
@ccall libclang.clang_createIndex(excludeDeclarationsFromPCH::Cint, displayDiagnostics::Cint)::CXIndex
end
"""
clang_disposeIndex(index)
Destroy the given index.
The index must not be destroyed until all of the translation units created within that index have been destroyed.
"""
function clang_disposeIndex(index)
@ccall libclang.clang_disposeIndex(index::CXIndex)::Cvoid
end
"""
CXGlobalOptFlags
| Enumerator | Note |
| :------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| CXGlobalOpt\\_None | Used to indicate that no special [`CXIndex`](@ref) options are needed. |
| CXGlobalOpt\\_ThreadBackgroundPriorityForIndexing | Used to indicate that threads that libclang creates for indexing purposes should use background priority. Affects #[`clang_indexSourceFile`](@ref), #[`clang_indexTranslationUnit`](@ref), #[`clang_parseTranslationUnit`](@ref), #[`clang_saveTranslationUnit`](@ref). |
| CXGlobalOpt\\_ThreadBackgroundPriorityForEditing | Used to indicate that threads that libclang creates for editing purposes should use background priority. Affects #[`clang_reparseTranslationUnit`](@ref), #[`clang_codeCompleteAt`](@ref), #[`clang_annotateTokens`](@ref) |
| CXGlobalOpt\\_ThreadBackgroundPriorityForAll | Used to indicate that all threads that libclang creates should use background priority. |
"""
@cenum CXGlobalOptFlags::UInt32 begin
CXGlobalOpt_None = 0
CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 1
CXGlobalOpt_ThreadBackgroundPriorityForEditing = 2
CXGlobalOpt_ThreadBackgroundPriorityForAll = 3
end
"""
clang_CXIndex_setGlobalOptions(arg1, options)
Sets general options associated with a [`CXIndex`](@ref).
For example:
```c++
CXIndex idx = ...;
clang_CXIndex_setGlobalOptions(idx,
clang_CXIndex_getGlobalOptions(idx) |
CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
```
### Parameters
* `options`: A bitmask of options, a bitwise OR of CXGlobalOpt\\_XXX flags.
"""
function clang_CXIndex_setGlobalOptions(arg1, options)
@ccall libclang.clang_CXIndex_setGlobalOptions(arg1::CXIndex, options::Cuint)::Cvoid
end
"""
clang_CXIndex_getGlobalOptions(arg1)
Gets the general options associated with a [`CXIndex`](@ref).
### Returns
A bitmask of options, a bitwise OR of CXGlobalOpt\\_XXX flags that are associated with the given [`CXIndex`](@ref) object.
"""
function clang_CXIndex_getGlobalOptions(arg1)
@ccall libclang.clang_CXIndex_getGlobalOptions(arg1::CXIndex)::Cuint
end
"""
clang_CXIndex_setInvocationEmissionPathOption(arg1, Path)
Sets the invocation emission path option in a [`CXIndex`](@ref).
The invocation emission path specifies a path which will contain log files for certain libclang invocations. A null value (default) implies that libclang invocations are not logged..
"""
function clang_CXIndex_setInvocationEmissionPathOption(arg1, Path)
@ccall libclang.clang_CXIndex_setInvocationEmissionPathOption(arg1::CXIndex, Path::Cstring)::Cvoid
end
"""
A particular source file that is part of a translation unit.
"""
const CXFile = Ptr{Cvoid}
"""
clang_getFileName(SFile)
Retrieve the complete file and path name of the given file.
"""
function clang_getFileName(SFile)
@ccall libclang.clang_getFileName(SFile::CXFile)::CXString
end
"""
clang_getFileTime(SFile)
Retrieve the last modification time of the given file.
"""
function clang_getFileTime(SFile)
@ccall libclang.clang_getFileTime(SFile::CXFile)::Ctime_t
end
"""
CXFileUniqueID
Uniquely identifies a [`CXFile`](@ref), that refers to the same underlying file, across an indexing session.
"""
struct CXFileUniqueID
data::NTuple{3, Culonglong}
end
"""
clang_getFileUniqueID(file, outID)
Retrieve the unique ID for the given `file`.
### Parameters
* `file`: the file to get the ID for.
* `outID`: stores the returned [`CXFileUniqueID`](@ref).
### Returns
If there was a failure getting the unique ID, returns non-zero, otherwise returns 0.
"""
function clang_getFileUniqueID(file, outID)
@ccall libclang.clang_getFileUniqueID(file::CXFile, outID::Ptr{CXFileUniqueID})::Cint
end
"""
clang_isFileMultipleIncludeGuarded(tu, file)
Determine whether the given header is guarded against multiple inclusions, either with the conventional #ifndef/#define/#endif macro guards or with #pragma once.
"""
function clang_isFileMultipleIncludeGuarded(tu, file)
@ccall libclang.clang_isFileMultipleIncludeGuarded(tu::CXTranslationUnit, file::CXFile)::Cuint
end
"""
clang_getFile(tu, file_name)
Retrieve a file handle within the given translation unit.
### Parameters
* `tu`: the translation unit
* `file_name`: the name of the file.
### Returns
the file handle for the named file in the translation unit `tu`, or a NULL file handle if the file was not a part of this translation unit.
"""
function clang_getFile(tu, file_name)
@ccall libclang.clang_getFile(tu::CXTranslationUnit, file_name::Cstring)::CXFile
end
"""
clang_getFileContents(tu, file, size)
Retrieve the buffer associated with the given file.
### Parameters
* `tu`: the translation unit
* `file`: the file for which to retrieve the buffer.
* `size`: [out] if non-NULL, will be set to the size of the buffer.
### Returns
a pointer to the buffer in memory that holds the contents of `file`, or a NULL pointer when the file is not loaded.
"""
function clang_getFileContents(tu, file, size)
@ccall libclang.clang_getFileContents(tu::CXTranslationUnit, file::CXFile, size::Ptr{Csize_t})::Cstring
end
"""
clang_File_isEqual(file1, file2)
Returns non-zero if the `file1` and `file2` point to the same file, or they are both NULL.
"""
function clang_File_isEqual(file1, file2)
@ccall libclang.clang_File_isEqual(file1::CXFile, file2::CXFile)::Cint
end
"""
clang_File_tryGetRealPathName(file)
Returns the real path name of `file`.
An empty string may be returned. Use [`clang_getFileName`](@ref)() in that case.
"""
function clang_File_tryGetRealPathName(file)
@ccall libclang.clang_File_tryGetRealPathName(file::CXFile)::CXString
end
"""
CXSourceLocation
Identifies a specific source location within a translation unit.
Use [`clang_getExpansionLocation`](@ref)() or [`clang_getSpellingLocation`](@ref)() to map a source location to a particular file, line, and column.
"""
struct CXSourceLocation
ptr_data::NTuple{2, Ptr{Cvoid}}
int_data::Cuint
end
"""
CXSourceRange
Identifies a half-open character range in the source code.
Use [`clang_getRangeStart`](@ref)() and [`clang_getRangeEnd`](@ref)() to retrieve the starting and end locations from a source range, respectively.
"""
struct CXSourceRange
ptr_data::NTuple{2, Ptr{Cvoid}}
begin_int_data::Cuint
end_int_data::Cuint
end
"""
clang_getNullLocation()
Retrieve a NULL (invalid) source location.
"""
function clang_getNullLocation()
@ccall libclang.clang_getNullLocation()::CXSourceLocation
end
"""
clang_equalLocations(loc1, loc2)
Determine whether two source locations, which must refer into the same translation unit, refer to exactly the same point in the source code.
### Returns
non-zero if the source locations refer to the same location, zero if they refer to different locations.
"""
function clang_equalLocations(loc1, loc2)
@ccall libclang.clang_equalLocations(loc1::CXSourceLocation, loc2::CXSourceLocation)::Cuint
end
"""
clang_getLocation(tu, file, line, column)
Retrieves the source location associated with a given file/line/column in a particular translation unit.
"""
function clang_getLocation(tu, file, line, column)
@ccall libclang.clang_getLocation(tu::CXTranslationUnit, file::CXFile, line::Cuint, column::Cuint)::CXSourceLocation
end
"""
clang_getLocationForOffset(tu, file, offset)
Retrieves the source location associated with a given character offset in a particular translation unit.
"""
function clang_getLocationForOffset(tu, file, offset)
@ccall libclang.clang_getLocationForOffset(tu::CXTranslationUnit, file::CXFile, offset::Cuint)::CXSourceLocation
end
"""
clang_Location_isInSystemHeader(location)
Returns non-zero if the given source location is in a system header.
"""
function clang_Location_isInSystemHeader(location)
@ccall libclang.clang_Location_isInSystemHeader(location::CXSourceLocation)::Cint
end
"""
clang_Location_isFromMainFile(location)
Returns non-zero if the given source location is in the main file of the corresponding translation unit.
"""
function clang_Location_isFromMainFile(location)
@ccall libclang.clang_Location_isFromMainFile(location::CXSourceLocation)::Cint
end
"""
clang_getNullRange()
Retrieve a NULL (invalid) source range.
"""
function clang_getNullRange()
@ccall libclang.clang_getNullRange()::CXSourceRange
end
"""
clang_getRange(_begin, _end)
Retrieve a source range given the beginning and ending source locations.
"""
function clang_getRange(_begin, _end)
@ccall libclang.clang_getRange(_begin::CXSourceLocation, _end::CXSourceLocation)::CXSourceRange
end
"""
clang_equalRanges(range1, range2)
Determine whether two ranges are equivalent.
### Returns
non-zero if the ranges are the same, zero if they differ.
"""
function clang_equalRanges(range1, range2)
@ccall libclang.clang_equalRanges(range1::CXSourceRange, range2::CXSourceRange)::Cuint
end
"""
clang_Range_isNull(range)
Returns non-zero if `range` is null.
"""
function clang_Range_isNull(range)
@ccall libclang.clang_Range_isNull(range::CXSourceRange)::Cint
end
"""
clang_getExpansionLocation(location, file, line, column, offset)
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.
### Parameters
* `location`: the location within a source file that will be decomposed into its parts.
* `file`: [out] if non-NULL, will be set to the file to which the given source location points.
* `line`: [out] if non-NULL, will be set to the line to which the given source location points.
* `column`: [out] if non-NULL, will be set to the column to which the given source location points.
* `offset`: [out] if non-NULL, will be set to the offset into the buffer to which the given source location points.
"""
function clang_getExpansionLocation(location, file, line, column, offset)
@ccall libclang.clang_getExpansionLocation(location::CXSourceLocation, file::Ptr{CXFile}, line::Ptr{Cuint}, column::Ptr{Cuint}, offset::Ptr{Cuint})::Cvoid
end
"""
clang_getPresumedLocation(location, filename, line, column)
Retrieve the file, line and column represented by the given source location, as specified in a # line directive.
Example: given the following source code in a file somefile.c
```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`](@ref) would have returned
File: somefile.c Line: 3 Column: 12
### Parameters
* `location`: the location within a source file that will be decomposed into its parts.
* `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 [`clang_disposeString`](@ref)() once you've finished with it. For an invalid source location, an empty string is returned.
* `line`: [out] if non-NULL, will be set to the line number of the source location. For an invalid source location, zero is returned.
* `column`: [out] if non-NULL, will be set to the column number of the source location. For an invalid source location, zero is returned.
"""
function clang_getPresumedLocation(location, filename, line, column)
@ccall libclang.clang_getPresumedLocation(location::CXSourceLocation, filename::Ptr{CXString}, line::Ptr{Cuint}, column::Ptr{Cuint})::Cvoid
end
"""
clang_getInstantiationLocation(location, file, line, column, offset)
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 #[`clang_getExpansionLocation`](@ref)(). See that interface's documentation for details.
"""
function clang_getInstantiationLocation(location, file, line, column, offset)
@ccall libclang.clang_getInstantiationLocation(location::CXSourceLocation, file::Ptr{CXFile}, line::Ptr{Cuint}, column::Ptr{Cuint}, offset::Ptr{Cuint})::Cvoid
end
"""
clang_getSpellingLocation(location, file, line, column, offset)
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.
### Parameters
* `location`: the location within a source file that will be decomposed into its parts.
* `file`: [out] if non-NULL, will be set to the file to which the given source location points.
* `line`: [out] if non-NULL, will be set to the line to which the given source location points.
* `column`: [out] if non-NULL, will be set to the column to which the given source location points.
* `offset`: [out] if non-NULL, will be set to the offset into the buffer to which the given source location points.
"""
function clang_getSpellingLocation(location, file, line, column, offset)
@ccall libclang.clang_getSpellingLocation(location::CXSourceLocation, file::Ptr{CXFile}, line::Ptr{Cuint}, column::Ptr{Cuint}, offset::Ptr{Cuint})::Cvoid
end
"""
clang_getFileLocation(location, file, line, column, offset)
Retrieve the file, line, column, and offset represented by the given source location.
If the location refers into a macro expansion, return where the macro was expanded or where the macro argument was written, if the location points at a macro argument.
### Parameters
* `location`: the location within a source file that will be decomposed into its parts.
* `file`: [out] if non-NULL, will be set to the file to which the given source location points.
* `line`: [out] if non-NULL, will be set to the line to which the given source location points.
* `column`: [out] if non-NULL, will be set to the column to which the given source location points.
* `offset`: [out] if non-NULL, will be set to the offset into the buffer to which the given source location points.
"""
function clang_getFileLocation(location, file, line, column, offset)
@ccall libclang.clang_getFileLocation(location::CXSourceLocation, file::Ptr{CXFile}, line::Ptr{Cuint}, column::Ptr{Cuint}, offset::Ptr{Cuint})::Cvoid
end
"""
clang_getRangeStart(range)
Retrieve a source location representing the first character within a source range.
"""
function clang_getRangeStart(range)
@ccall libclang.clang_getRangeStart(range::CXSourceRange)::CXSourceLocation
end
"""
clang_getRangeEnd(range)
Retrieve a source location representing the last character within a source range.
"""
function clang_getRangeEnd(range)
@ccall libclang.clang_getRangeEnd(range::CXSourceRange)::CXSourceLocation
end
"""
CXSourceRangeList
Identifies an array of ranges.
| Field | Note |
| :----- | :------------------------------------------- |
| count | The number of ranges in the `ranges` array. |
| ranges | An array of `CXSourceRanges`. |
"""
struct CXSourceRangeList
count::Cuint
ranges::Ptr{CXSourceRange}
end
"""
clang_getSkippedRanges(tu, file)
Retrieve all ranges that were skipped by the preprocessor.
The preprocessor will skip lines when they are surrounded by an if/ifdef/ifndef directive whose condition does not evaluate to true.
"""
function clang_getSkippedRanges(tu, file)
@ccall libclang.clang_getSkippedRanges(tu::CXTranslationUnit, file::CXFile)::Ptr{CXSourceRangeList}
end
"""
clang_getAllSkippedRanges(tu)
Retrieve all ranges from all files that were skipped by the preprocessor.
The preprocessor will skip lines when they are surrounded by an if/ifdef/ifndef directive whose condition does not evaluate to true.
"""
function clang_getAllSkippedRanges(tu)
@ccall libclang.clang_getAllSkippedRanges(tu::CXTranslationUnit)::Ptr{CXSourceRangeList}
end
"""