Skip to content

Commit 048a381

Browse files
committed
[cxx-interop] Add back identifier validation; traffic 'isCxxClassTemplateSpec' through 'formDeclName'.
1 parent ab15240 commit 048a381

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

include/swift/Parse/Parser.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,10 +2001,12 @@ struct ParsedDeclName {
20012001
}
20022002

20032003
/// Form a declaration name from this parsed declaration name.
2004-
DeclName formDeclName(ASTContext &ctx, bool isSubscript = false) const;
2004+
DeclName formDeclName(ASTContext &ctx, bool isSubscript = false,
2005+
bool isCxxClassTemplateSpec = false) const;
20052006

20062007
/// Form a declaration name from this parsed declaration name.
2007-
DeclNameRef formDeclNameRef(ASTContext &ctx, bool isSubscript = false) const;
2008+
DeclNameRef formDeclNameRef(ASTContext &ctx, bool isSubscript = false,
2009+
bool isCxxClassTemplateSpec = false) const;
20082010
};
20092011

20102012
/// To assist debugging parser crashes, tell us the location of the
@@ -2026,15 +2028,17 @@ DeclName formDeclName(ASTContext &ctx,
20262028
ArrayRef<StringRef> argumentLabels,
20272029
bool isFunctionName,
20282030
bool isInitializer,
2029-
bool isSubscript = false);
2031+
bool isSubscript = false,
2032+
bool isCxxClassTemplateSpec = false);
20302033

20312034
/// Form a Swift declaration name reference from its constituent parts.
20322035
DeclNameRef formDeclNameRef(ASTContext &ctx,
20332036
StringRef baseName,
20342037
ArrayRef<StringRef> argumentLabels,
20352038
bool isFunctionName,
20362039
bool isInitializer,
2037-
bool isSubscript = false);
2040+
bool isSubscript = false,
2041+
bool isCxxClassTemplateSpec = false);
20382042

20392043
/// Whether a given token can be the start of a decl.
20402044
bool isKeywordPossibleDeclStart(const Token &Tok);

lib/ClangImporter/ImportName.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,9 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
16581658

16591659
if (!skipCustomName) {
16601660
result.info.hasCustomName = true;
1661-
result.declName = parsedName.formDeclName(swiftCtx);
1661+
result.declName = parsedName.formDeclName(
1662+
swiftCtx, /*isSubscript=*/false,
1663+
isa<clang::ClassTemplateSpecializationDecl>(D));
16621664

16631665
// Handle globals treated as members.
16641666
if (parsedName.isMember()) {
@@ -1713,7 +1715,8 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
17131715
// Update the name to reflect the new parameter labels.
17141716
result.declName = formDeclName(
17151717
swiftCtx, parsedName.BaseName, parsedName.ArgumentLabels,
1716-
/*isFunction=*/true, isInitializer);
1718+
/*isFunction=*/true, isInitializer, /*isSubscript=*/false,
1719+
isa<clang::ClassTemplateSpecializationDecl>(D));
17171720
} else if (nameAttr->isAsync) {
17181721
// The custom name was for an async import, but we didn't in fact
17191722
// import as async for some reason. Ignore this import.
@@ -2356,7 +2359,8 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
23562359
baseName = renameUnsafeMethod(swiftCtx, D, baseName);
23572360

23582361
result.declName = formDeclName(swiftCtx, baseName, argumentNames, isFunction,
2359-
isInitializer);
2362+
isInitializer, /*isSubscript=*/false,
2363+
isa<clang::ClassTemplateSpecializationDecl>(D));
23602364
return result;
23612365
}
23622366

lib/Parse/Parser.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,36 +1331,46 @@ ParsedDeclName swift::parseDeclName(StringRef name) {
13311331
return result;
13321332
}
13331333

1334-
DeclName ParsedDeclName::formDeclName(ASTContext &ctx, bool isSubscript) const {
1335-
return formDeclNameRef(ctx, isSubscript).getFullName();
1334+
DeclName ParsedDeclName::formDeclName(ASTContext &ctx, bool isSubscript,
1335+
bool isCxxClassTemplateSpec) const {
1336+
return formDeclNameRef(ctx, isSubscript, isCxxClassTemplateSpec).getFullName();
13361337
}
13371338

13381339
DeclNameRef ParsedDeclName::formDeclNameRef(ASTContext &ctx,
1339-
bool isSubscript) const {
1340+
bool isSubscript,
1341+
bool isCxxClassTemplateSpec) const {
13401342
return swift::formDeclNameRef(ctx, BaseName, ArgumentLabels, IsFunctionName,
1341-
/*IsInitializer=*/true, isSubscript);
1343+
/*IsInitializer=*/true, isSubscript,
1344+
isCxxClassTemplateSpec);
13421345
}
13431346

13441347
DeclName swift::formDeclName(ASTContext &ctx,
13451348
StringRef baseName,
13461349
ArrayRef<StringRef> argumentLabels,
13471350
bool isFunctionName,
13481351
bool isInitializer,
1349-
bool isSubscript) {
1352+
bool isSubscript,
1353+
bool isCxxClassTemplateSpec) {
13501354
return formDeclNameRef(ctx, baseName, argumentLabels, isFunctionName,
1351-
isInitializer, isSubscript).getFullName();
1355+
isInitializer, isSubscript,
1356+
isCxxClassTemplateSpec).getFullName();
13521357
}
13531358

13541359
DeclNameRef swift::formDeclNameRef(ASTContext &ctx,
13551360
StringRef baseName,
13561361
ArrayRef<StringRef> argumentLabels,
13571362
bool isFunctionName,
13581363
bool isInitializer,
1359-
bool isSubscript) {
1364+
bool isSubscript,
1365+
bool isCxxClassTemplateSpec) {
13601366
// We cannot import when the base name is not an identifier.
13611367
if (baseName.empty())
13621368
return DeclNameRef();
13631369

1370+
if (!Lexer::isIdentifier(baseName) && !Lexer::isOperator(baseName) &&
1371+
!isCxxClassTemplateSpec)
1372+
return DeclNameRef();
1373+
13641374
// Get the identifier for the base name. Special-case `init`.
13651375
DeclBaseName baseNameId;
13661376
if (isInitializer && baseName == "init")

0 commit comments

Comments
 (0)