1
+ //===--- ASTBridging.h - header for the swift SILBridging module ----------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2022 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ #ifndef SWIFT_C_AST_ASTBRIDGING_H
14
+ #define SWIFT_C_AST_ASTBRIDGING_H
15
+
16
+ // Provide macros to temporarily suppress warning about the use of
17
+ // _Nullable and _Nonnull.
18
+ #define SWIFT_BEGIN_NULLABILITY_ANNOTATIONS \
19
+ _Pragma("clang diagnostic push") \
20
+ _Pragma("clang diagnostic ignored \"-Wnullability-extension\"") \
21
+ _Pragma("clang assume_nonnull begin")
22
+
23
+ #define SWIFT_END_NULLABILITY_ANNOTATIONS \
24
+ _Pragma("clang diagnostic pop") _Pragma("clang assume_nonnull end")
25
+
26
+ //===----------------------------------------------------------------------===//
27
+ // Diagnostic Engine
28
+ //===----------------------------------------------------------------------===//
29
+
30
+ // TODO: Move this to somewhere common header.
31
+ #if __has_attribute (enum_extensibility )
32
+ #define ENUM_EXTENSIBILITY_ATTR (arg ) __attribute__((enum_extensibility(arg)))
33
+ #else
34
+ #define ENUM_EXTENSIBILITY_ATTR (arg )
35
+ #endif
36
+
37
+ // NOTE: This must be the same underlying value as C++ 'swift::DiagID' defined
38
+ // in 'DiagnosticList.cpp'.
39
+ typedef enum ENUM_EXTENSIBILITY_ATTR (open ) BridgedDiagID : unsigned {
40
+ #define DIAG (KIND , ID , Options , Text , Signature ) BridgedDiagID_##ID,
41
+ #include "swift/AST/DiagnosticsAll.def"
42
+ } BridgedDiagID ;
43
+
44
+ SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
45
+
46
+ typedef long SwiftInt ;
47
+ typedef unsigned long SwiftUInt ;
48
+
49
+ typedef struct {
50
+ const void * _Nullable data ;
51
+ long numElements ;
52
+ } BridgedArrayRef ;
53
+
54
+ typedef struct {
55
+ void * start ;
56
+ SwiftInt byteLength ;
57
+ } BridgedCharSourceRange ;
58
+
59
+ // FIXME: Can we bridge InFlightDiagnostic?
60
+ void DiagnosticEngine_diagnose (void * , void * loc , BridgedDiagID diagID ,
61
+ BridgedArrayRef arguments ,
62
+ BridgedCharSourceRange highlight ,
63
+ BridgedArrayRef fixIts );
64
+
65
+ int DiagnosticEngine_hadAnyError (void * );
66
+
67
+ typedef const char * BridgedIdentifier ;
68
+
69
+ #ifdef __cplusplus
70
+ extern "C" {
71
+
72
+ #define _Bool bool
73
+
74
+ #endif
75
+
76
+ BridgedIdentifier
77
+ SwiftASTContext_getIdentifier (void * ctx , const char * _Nullable str , long len );
78
+
79
+ void * SwiftImportDecl_create (void * , void * , void * , char , void * ,
80
+ BridgedArrayRef , BridgedArrayRef );
81
+
82
+ void * SwiftTopLevelCodeDecl_createStmt (void * ctx , void * DC , void * startLoc ,
83
+ void * element , void * endLoc );
84
+ void * SwiftTopLevelCodeDecl_createExpr (void * ctx , void * DC , void * startLoc ,
85
+ void * element , void * endLoc );
86
+
87
+ void * SwiftSequenceExpr_create (void * ctx , BridgedArrayRef exprs );
88
+
89
+ void * SwiftTupleExpr_create (void * ctx , void * lparen , BridgedArrayRef subs ,
90
+ void * rparen );
91
+
92
+ void * SwiftFunctionCallExpr_create (void * ctx , void * fn , void * args );
93
+
94
+ void * SwiftIdentifierExpr_create (void * ctx , const char * base , void * loc );
95
+
96
+ void * SwiftStringLiteralExpr_create (void * ctx , const char * _Nullable string ,
97
+ long len , void * TokenLoc );
98
+
99
+ void * SwiftIntegerLiteralExpr_create (void * ctx , const char * _Nullable string ,
100
+ long len , void * TokenLoc );
101
+
102
+ void * SwiftVarDecl_create (void * ctx , const char * _Nullable name ,
103
+ void * loc , _Bool isStatic , _Bool isLet , void * dc );
104
+
105
+ void * IfStmt_create (void * ctx , void * ifLoc , void * cond , void * _Nullable then , void * _Nullable elseLoc ,
106
+ void * _Nullable elseStmt );
107
+
108
+ void * BraceStmt_create (void * ctx , void * lbloc , BridgedArrayRef elements , void * rbloc );
109
+
110
+ void * BridgedSourceLoc_advanced (void * loc , long len );
111
+
112
+ void * ParamDecl_create (void * ctx , void * loc ,
113
+ void * _Nullable argLoc , void * _Nullable argName ,
114
+ void * _Nullable paramLoc , void * _Nullable paramName ,
115
+ void * declContext );
116
+
117
+ void * FuncDecl_create (void * ctx , void * staticLoc , _Bool isStatic , void * funcLoc ,
118
+ const char * name , void * nameLoc ,
119
+ _Bool isAsync , void * _Nullable asyncLoc ,
120
+ _Bool throws , void * _Nullable throwsLoc ,
121
+ void * paramLLoc , BridgedArrayRef params , void * paramRLoc ,
122
+ void * _Nullable body , void * _Nullable returnType ,
123
+ void * declContext );
124
+
125
+ void * SimpleIdentTypeRepr_create (void * ctx , void * loc , const char * id );
126
+
127
+ void * UnresolvedDotExpr_create (void * ctx , void * base , void * dotLoc , const char * name , void * nameLoc );
128
+
129
+ void TopLevelCodeDecl_dump (void * );
130
+ void Expr_dump (void * );
131
+ void Decl_dump (void * );
132
+ void Stmt_dump (void * );
133
+
134
+ #ifdef __cplusplus
135
+ }
136
+ #endif
137
+
138
+ SWIFT_END_NULLABILITY_ANNOTATIONS
139
+
140
+ #endif // SWIFT_C_AST_ASTBRIDGING_H
0 commit comments