@@ -176,6 +176,10 @@ class DeclAttribute : public AttributeBase {
176176 kind : NumExposureKindBits
177177 );
178178
179+ SWIFT_INLINE_BITFIELD (ExternAttr, DeclAttribute, NumExternKindBits,
180+ kind : NumExternKindBits
181+ );
182+
179183 SWIFT_INLINE_BITFIELD (SynthesizedProtocolAttr, DeclAttribute, 1 ,
180184 isUnchecked : 1
181185 );
@@ -2335,22 +2339,48 @@ class ExposeAttr : public DeclAttribute {
23352339 }
23362340};
23372341
2338- // / Define the `@_extern ` attribute, used to import external declarations in
2342+ // / Define the `@extern ` attribute, used to import external declarations in
23392343// / the specified way to interoperate with Swift.
23402344class ExternAttr : public DeclAttribute {
2345+ SourceLoc LParenLoc, RParenLoc;
2346+
23412347public:
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+ }
23452356
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) {}
23482361
23492362 // / 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;
23512365
23522366 // / 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);
23542384
23552385 static bool classof (const DeclAttribute *DA) {
23562386 return DA->getKind () == DAK_Extern;
0 commit comments