Skip to content

Commit 39afec7

Browse files
committed
[Clang importer] Replace explicit parser calls with the request-based parsing
This cleanup makes sure that we're parsing swift_attr attributes through the normal requests, once, rather than directly calling into the parser.
1 parent 0bcd251 commit 39afec7

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

lib/ClangImporter/ImportDecl.cpp

+5-31
Original file line numberDiff line numberDiff line change
@@ -8273,7 +8273,6 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
82738273

82748274
std::optional<const clang::SwiftAttrAttr *> seenMainActorAttr;
82758275
const clang::SwiftAttrAttr *seenMutabilityAttr = nullptr;
8276-
PatternBindingInitializer *initContext = nullptr;
82778276

82788277
auto importAttrsFromDecl = [&](const clang::NamedDecl *ClangDecl) {
82798278
//
@@ -8401,36 +8400,11 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
84018400
auto &sourceFile = getClangSwiftAttrSourceFile(
84028401
*MappedDecl->getDeclContext()->getParentModule(), bufferID);
84038402

8404-
// Spin up a parser.
8405-
swift::Parser parser(
8406-
bufferID, sourceFile, &SwiftContext.Diags, nullptr, nullptr);
8407-
// Prime the lexer.
8408-
parser.consumeTokenWithoutFeedingReceiver();
8409-
8410-
bool hadError = false;
8411-
if (parser.Tok.is(tok::at_sign)) {
8412-
SourceLoc atEndLoc = parser.Tok.getRange().getEnd();
8413-
SourceLoc atLoc = parser.consumeToken(tok::at_sign);
8414-
hadError = parser
8415-
.parseDeclAttribute(MappedDecl->getAttrs(), atLoc,
8416-
atEndLoc, initContext,
8417-
/*isFromClangAttribute=*/true)
8418-
.isError();
8419-
} else {
8420-
SourceLoc staticLoc;
8421-
StaticSpellingKind staticSpelling;
8422-
hadError = parser
8423-
.parseDeclModifierList(MappedDecl->getAttrs(), staticLoc,
8424-
staticSpelling,
8425-
/*isFromClangAttribute=*/true)
8426-
.isError();
8427-
}
8428-
8429-
if (hadError) {
8430-
// Complain about the unhandled attribute or modifier.
8431-
HeaderLoc attrLoc(swiftAttr->getLocation());
8432-
diagnose(attrLoc, diag::clang_swift_attr_unhandled,
8433-
swiftAttr->getAttribute());
8403+
// Collect the attributes from the synthesized top-level declaration in
8404+
// the source file.
8405+
auto topLevelDecls = sourceFile.getTopLevelDecls();
8406+
for (auto decl : topLevelDecls) {
8407+
MappedDecl->getAttrs().add(decl->getAttrs());
84348408
}
84358409
}
84368410

0 commit comments

Comments
 (0)