@@ -176,6 +176,10 @@ class DeclAttribute : public AttributeBase {
176
176
kind : NumExposureKindBits
177
177
);
178
178
179
+ SWIFT_INLINE_BITFIELD (ExternAttr, DeclAttribute, NumExternKindBits,
180
+ kind : NumExternKindBits
181
+ );
182
+
179
183
SWIFT_INLINE_BITFIELD (SynthesizedProtocolAttr, DeclAttribute, 1 ,
180
184
isUnchecked : 1
181
185
);
@@ -2335,22 +2339,48 @@ class ExposeAttr : public DeclAttribute {
2335
2339
}
2336
2340
};
2337
2341
2338
- // / Define the `@_extern ` attribute, used to import external declarations in
2342
+ // / Define the `@extern ` attribute, used to import external declarations in
2339
2343
// / the specified way to interoperate with Swift.
2340
2344
class ExternAttr : public DeclAttribute {
2345
+ SourceLoc LParenLoc, RParenLoc;
2346
+
2341
2347
public:
2342
- ExternAttr (StringRef ModuleName, StringRef Name, SourceLoc AtLoc, SourceRange Range, bool Implicit)
2343
- : DeclAttribute(DAK_Extern, AtLoc, Range, Implicit),
2344
- ModuleName (ModuleName), Name(Name) {}
2348
+ ExternAttr (llvm::Optional<StringRef> ModuleName,
2349
+ llvm::Optional<StringRef> Name, SourceLoc AtLoc,
2350
+ SourceLoc LParenLoc, SourceLoc RParenLoc, SourceRange Range,
2351
+ ExternKind Kind, bool Implicit)
2352
+ : DeclAttribute(DAK_Extern, AtLoc, Range, Implicit), LParenLoc(LParenLoc),
2353
+ RParenLoc (RParenLoc), ModuleName(ModuleName), Name(Name) {
2354
+ Bits.ExternAttr .kind = static_cast <unsigned >(Kind);
2355
+ }
2345
2356
2346
- ExternAttr (StringRef ModuleName, StringRef Name, bool Implicit)
2347
- : ExternAttr(ModuleName, Name, SourceLoc(), SourceRange(), Implicit) {}
2357
+ ExternAttr (llvm::Optional<StringRef> ModuleName,
2358
+ llvm::Optional<StringRef> Name, ExternKind Kind, bool Implicit)
2359
+ : ExternAttr(ModuleName, Name, SourceLoc(), SourceLoc(), SourceLoc(),
2360
+ SourceRange(), Kind, Implicit) {}
2348
2361
2349
2362
// / The module name to import the named declaration in it
2350
- const StringRef ModuleName;
2363
+ // / Used for Wasm import declaration.
2364
+ const llvm::Optional<StringRef> ModuleName;
2351
2365
2352
2366
// / The declaration name to import
2353
- const StringRef Name;
2367
+ // / std::nullopt if the declaration name is not specified with @extern(c)
2368
+ const llvm::Optional<StringRef> Name;
2369
+
2370
+ SourceLoc getLParenLoc () const { return LParenLoc; }
2371
+ SourceLoc getRParenLoc () const { return RParenLoc; }
2372
+
2373
+ // / Returns the kind of extern.
2374
+ ExternKind getExternKind () const {
2375
+ return static_cast <ExternKind>(Bits.ExternAttr .kind );
2376
+ }
2377
+
2378
+ // / Returns the C name of the given declaration.
2379
+ // / \p forDecl is the func decl that the attribute belongs to.
2380
+ StringRef getCName (const FuncDecl *forDecl) const ;
2381
+
2382
+ // / Find an ExternAttr with the given kind in the given DeclAttributes.
2383
+ static ExternAttr *find (DeclAttributes &attrs, ExternKind kind);
2354
2384
2355
2385
static bool classof (const DeclAttribute *DA) {
2356
2386
return DA->getKind () == DAK_Extern;
0 commit comments