@@ -94,7 +94,7 @@ TypeDecl *ASTBuilder::createTypeDecl(NodePointer node) {
94
94
if (proto == nullptr )
95
95
return nullptr ;
96
96
97
- auto name = Ctx. getIdentifier (node->getChild (1 )->getText ());
97
+ auto name = getIdentifier (node->getChild (1 )->getText ());
98
98
return proto->getAssociatedType (name);
99
99
}
100
100
@@ -110,10 +110,9 @@ ASTBuilder::createBuiltinType(StringRef builtinName,
110
110
111
111
StringRef strippedName =
112
112
builtinName.drop_front (BUILTIN_TYPE_NAME_PREFIX.size ());
113
- Ctx.TheBuiltinModule ->lookupValue (Ctx.getIdentifier (strippedName),
114
- NLKind::QualifiedLookup,
115
- decls);
116
-
113
+ Ctx.TheBuiltinModule ->lookupValue (getIdentifier (strippedName),
114
+ NLKind::QualifiedLookup, decls);
115
+
117
116
if (decls.size () == 1 && isa<TypeDecl>(decls[0 ]))
118
117
return cast<TypeDecl>(decls[0 ])->getDeclaredInterfaceType ();
119
118
}
@@ -348,7 +347,7 @@ Type ASTBuilder::createTupleType(ArrayRef<Type> eltTypes, ArrayRef<StringRef> la
348
347
for (unsigned i : indices (eltTypes)) {
349
348
Identifier label;
350
349
if (!labels[i].empty ())
351
- label = Ctx. getIdentifier (labels[i]);
350
+ label = getIdentifier (labels[i]);
352
351
elements.emplace_back (eltTypes[i], label);
353
352
}
354
353
@@ -408,7 +407,7 @@ Type ASTBuilder::createFunctionType(
408
407
if (!type->isMaterializable ())
409
408
return Type ();
410
409
411
- auto label = Ctx. getIdentifier (param.getLabel ());
410
+ auto label = getIdentifier (param.getLabel ());
412
411
auto flags = param.getFlags ();
413
412
auto ownership =
414
413
ParamDecl::getParameterSpecifierForValueOwnership (asValueOwnership (flags.getOwnership ()));
@@ -884,7 +883,7 @@ Type ASTBuilder::createGenericTypeParameterType(unsigned depth,
884
883
885
884
Type ASTBuilder::createDependentMemberType (StringRef member,
886
885
Type base) {
887
- auto identifier = Ctx. getIdentifier (member);
886
+ auto identifier = getIdentifier (member);
888
887
889
888
if (auto *archetype = base->getAs <ArchetypeType>()) {
890
889
if (Type memberType = archetype->getNestedTypeByName (identifier))
@@ -901,7 +900,7 @@ Type ASTBuilder::createDependentMemberType(StringRef member,
901
900
Type ASTBuilder::createDependentMemberType (StringRef member,
902
901
Type base,
903
902
ProtocolDecl *protocol) {
904
- auto identifier = Ctx. getIdentifier (member);
903
+ auto identifier = getIdentifier (member);
905
904
906
905
if (auto *archetype = base->getAs <ArchetypeType>()) {
907
906
if (auto assocType = protocol->getAssociatedType (identifier))
@@ -1141,7 +1140,7 @@ ASTBuilder::getAcceptableTypeDeclCandidate(ValueDecl *decl,
1141
1140
1142
1141
DeclContext *ASTBuilder::getNotionalDC () {
1143
1142
if (!NotionalDC) {
1144
- NotionalDC = ModuleDecl::createEmpty (Ctx. getIdentifier (" .RemoteAST" ), Ctx);
1143
+ NotionalDC = ModuleDecl::createEmpty (getIdentifier (" .RemoteAST" ), Ctx);
1145
1144
NotionalDC = new (Ctx) TopLevelCodeDecl (NotionalDC);
1146
1145
}
1147
1146
return NotionalDC;
@@ -1314,7 +1313,7 @@ ASTBuilder::findDeclContext(NodePointer node) {
1314
1313
Demangle::Node::Kind::PrivateDeclName) {
1315
1314
name = declNameNode->getChild (1 )->getText ();
1316
1315
privateDiscriminator =
1317
- Ctx. getIdentifier (declNameNode->getChild (0 )->getText ());
1316
+ getIdentifier (declNameNode->getChild (0 )->getText ());
1318
1317
1319
1318
} else if (declNameNode->getKind () ==
1320
1319
Demangle::Node::Kind::RelatedEntityDeclName) {
@@ -1342,14 +1341,14 @@ ASTBuilder::findDeclContext(NodePointer node) {
1342
1341
return nullptr ;
1343
1342
1344
1343
for (auto *module : potentialModules)
1345
- if (auto typeDecl = findTypeDecl (module, Ctx. getIdentifier (name),
1344
+ if (auto typeDecl = findTypeDecl (module, getIdentifier (name),
1346
1345
privateDiscriminator, node->getKind ()))
1347
1346
return typeDecl;
1348
1347
return nullptr ;
1349
1348
}
1350
1349
1351
1350
if (auto *dc = findDeclContext (child))
1352
- if (auto typeDecl = findTypeDecl (dc, Ctx. getIdentifier (name),
1351
+ if (auto typeDecl = findTypeDecl (dc, getIdentifier (name),
1353
1352
privateDiscriminator, node->getKind ()))
1354
1353
return typeDecl;
1355
1354
@@ -1548,7 +1547,7 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
1548
1547
found);
1549
1548
break ;
1550
1549
}
1551
- importer->lookupValue (Ctx. getIdentifier (name), consumer);
1550
+ importer->lookupValue (getIdentifier (name), consumer);
1552
1551
if (consumer.Result )
1553
1552
consumer.Result = getAcceptableTypeDeclCandidate (consumer.Result , kind);
1554
1553
break ;
@@ -1558,3 +1557,28 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
1558
1557
1559
1558
return consumer.Result ;
1560
1559
}
1560
+
1561
+ Identifier ASTBuilder::getIdentifier (StringRef name) {
1562
+ if (name.size () > 1 && name.front () == ' `' && name.back () == ' `' ) {
1563
+ // Raw identifiers have backticks affixed before mangling. We need to
1564
+ // remove those before creating the Identifier for the AST, which doesn't
1565
+ // encode the backticks.
1566
+ std::string fixedName;
1567
+ for (size_t i = 1 ; i < name.size () - 1 ; ++i) {
1568
+ unsigned char ch = name[i];
1569
+ // Raw identifiers have the space (U+0020) replaced with a non-breaking
1570
+ // space (U+00A0, UTF-8: 0xC2 0xA0) in their mangling so that parts of
1571
+ // the runtime that use space as a delimiter remain compatible with
1572
+ // these identifiers. Flip it back.
1573
+ if (ch == 0xc2 && i < name.size () - 2 &&
1574
+ (unsigned char )name[i + 1 ] == 0xa0 ) {
1575
+ fixedName.push_back (' ' );
1576
+ ++i;
1577
+ } else {
1578
+ fixedName.push_back (ch);
1579
+ }
1580
+ }
1581
+ return Ctx.getIdentifier (fixedName);
1582
+ }
1583
+ return Ctx.getIdentifier (name);
1584
+ }
0 commit comments