Skip to content

Commit 841eeb0

Browse files
authored
Merge pull request swiftlang#30403 from MForster/forster/string-fixes
Cherry-pick StringRef->std::string conversion fixes into `master`
2 parents 2af51be + 345a914 commit 841eeb0

File tree

107 files changed

+364
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+364
-345
lines changed

include/swift/ABI/TypeIdentity.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ class TypeImportInfo {
129129
value = value.drop_front(1);
130130

131131
switch (component) {
132-
#define case_setIfNonEmpty(FIELD) \
133-
case TypeImportComponent::FIELD: \
134-
check(!value.empty(), "incoming value of " #FIELD " was empty"); \
135-
check(FIELD.empty(), #FIELD " was already set"); \
136-
FIELD = value; \
137-
return true; \
138-
139-
case_setIfNonEmpty(ABIName)
140-
case_setIfNonEmpty(SymbolNamespace)
141-
case_setIfNonEmpty(RelatedEntityName)
132+
#define case_setIfNonEmpty(FIELD) \
133+
case TypeImportComponent::FIELD: \
134+
check(!value.empty(), "incoming value of " #FIELD " was empty"); \
135+
check(FIELD.empty(), #FIELD " was already set"); \
136+
FIELD = StringType(value); \
137+
return true;
138+
139+
case_setIfNonEmpty(ABIName)
140+
case_setIfNonEmpty(SymbolNamespace)
141+
case_setIfNonEmpty(RelatedEntityName)
142142

143143
#undef case_setIfNonEmpty
144144
#undef check

include/swift/AST/Identifier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ class Identifier {
8383
const char *get() const { return Pointer; }
8484

8585
StringRef str() const { return Pointer; }
86-
86+
87+
explicit operator std::string() const { return std::string(Pointer); }
88+
8789
unsigned getLength() const {
8890
assert(Pointer != nullptr && "Tried getting length of empty identifier");
8991
return ::strlen(Pointer);

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ namespace swift {
369369
/// compiler flag.
370370
void addCustomConditionalCompilationFlag(StringRef Name) {
371371
assert(!Name.empty());
372-
CustomConditionalCompilationFlags.push_back(Name);
372+
CustomConditionalCompilationFlags.push_back(Name.str());
373373
}
374374

375375
/// Determines if a given conditional compilation flag has been set.

include/swift/Demangling/TypeDecoder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class TypeDecoder {
384384
}
385385
case NodeKind::BuiltinTypeName: {
386386
auto mangledName = Demangle::mangleNode(Node);
387-
return Builder.createBuiltinType(Node->getText(), mangledName);
387+
return Builder.createBuiltinType(Node->getText().str(), mangledName);
388388
}
389389
case NodeKind::Metatype:
390390
case NodeKind::ExistentialMetatype: {
@@ -683,12 +683,12 @@ class TypeDecoder {
683683
auto assocTypeChild = Node->getChild(1);
684684
auto member = assocTypeChild->getFirstChild()->getText();
685685
if (assocTypeChild->getNumChildren() < 2)
686-
return Builder.createDependentMemberType(member, base);
686+
return Builder.createDependentMemberType(member.str(), base);
687687

688688
auto protocol = decodeMangledProtocolType(assocTypeChild->getChild(1));
689689
if (!protocol)
690690
return BuiltType();
691-
return Builder.createDependentMemberType(member, base, protocol);
691+
return Builder.createDependentMemberType(member.str(), base, protocol);
692692
}
693693
case NodeKind::DependentAssociatedTypeRef: {
694694
if (Node->getNumChildren() < 2)

include/swift/Remote/MetadataReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ class MetadataReader {
823823

824824
#if SWIFT_OBJC_INTEROP
825825
BuiltProtocolDecl objcProtocol(StringRef name) {
826-
return builder.createObjCProtocolDecl(name);
826+
return builder.createObjCProtocolDecl(name.str());
827827
}
828828
#endif
829829
} resolver{Builder};

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ class SILFunction
692692
void addSemanticsAttr(StringRef Ref) {
693693
if (hasSemanticsAttr(Ref))
694694
return;
695-
SemanticsAttrSet.push_back(Ref);
695+
SemanticsAttrSet.push_back(Ref.str());
696696
std::sort(SemanticsAttrSet.begin(), SemanticsAttrSet.end());
697697
}
698698

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ void ASTContext::addSearchPath(StringRef searchPath, bool isFramework,
14311431
if (isFramework)
14321432
SearchPathOpts.FrameworkSearchPaths.push_back({searchPath, isSystem});
14331433
else
1434-
SearchPathOpts.ImportSearchPaths.push_back(searchPath);
1434+
SearchPathOpts.ImportSearchPaths.push_back(searchPath.str());
14351435

14361436
if (auto *clangLoader = getClangModuleLoader())
14371437
clangLoader->addSearchPath(searchPath, isFramework, isSystem);

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ std::string ASTPrinter::sanitizeUtf8(StringRef Text) {
272272
}
273273
Data += Step;
274274
}
275-
return Builder.str();
275+
return std::string(Builder.str());
276276
}
277277

278278
void ASTPrinter::anchor() {}
@@ -4543,7 +4543,7 @@ AnyFunctionType::getParamListAsString(ArrayRef<AnyFunctionType::Param> Params,
45434543
SmallString<16> Scratch;
45444544
llvm::raw_svector_ostream OS(Scratch);
45454545
AnyFunctionType::printParams(Params, OS);
4546-
return OS.str();
4546+
return std::string(OS.str());
45474547
}
45484548

45494549
void LayoutConstraintInfo::print(raw_ostream &OS,

lib/AST/DiagnosticEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
989989
while (associatedNotes && *associatedNotes) {
990990
SmallString<128> notePath(getDiagnosticDocumentationPath());
991991
llvm::sys::path::append(notePath, *associatedNotes);
992-
educationalNotePaths.push_back(notePath.str());
992+
educationalNotePaths.push_back(notePath.str().str());
993993
associatedNotes++;
994994
}
995995
info->EducationalNotePaths = educationalNotePaths;

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,7 @@ StringRef ModuleEntity::getName() const {
24092409
std::string ModuleEntity::getFullName() const {
24102410
assert(!Mod.isNull());
24112411
if (auto SwiftMod = Mod.dyn_cast<const ModuleDecl*>())
2412-
return SwiftMod->getName().str();
2412+
return std::string(SwiftMod->getName());
24132413
return getClangModule(Mod)->getFullModuleName();
24142414
}
24152415

0 commit comments

Comments
 (0)