Skip to content

Commit 24aaf6e

Browse files
committed
Move the details of C99 identifier mangling out of ProjectModel and down into Utility. It looks as if at some point this was meant to be able to fail because it might remove all the characters and end up with an empty string, but now that it replaces characters it doesn't seem possible for it to end up with an empty string assuming it was given a non-empty string. Instead we just define it to never generate an empty string if given a non-empty string. It will continue to be the caller's responsibility to check separately for non-empty strings, for which it is likely to want different errors anyway (e.g. reporting a missing module name as different from a malformed module name or whatever).
1 parent e756c96 commit 24aaf6e

File tree

8 files changed

+289
-273
lines changed

8 files changed

+289
-273
lines changed

Sources/Commands/init.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ final class InitPackage {
5555

5656
init(mode: InitMode) throws {
5757
self.mode = mode
58-
pkgname = rootd.basename
59-
// Also validates that the name is valid.
60-
moduleName = try c99name(name: rootd.basename)
58+
let dirname = rootd.basename
59+
assert(!dirname.isEmpty) // a base name is never empty
60+
self.pkgname = dirname
61+
self.moduleName = dirname.mangledToC99ExtendedIdentifier()
6162
}
6263

6364
func writePackageStructure() throws {

Sources/PackageModel/Module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class Module: ModuleProtocol {
6363
self.type = type
6464
self.sources = sources
6565
self.dependencies = []
66-
self.c99name = try PackageModel.c99name(name: self.name)
66+
self.c99name = self.name.mangledToC99ExtendedIdentifier()
6767
self.isTest = isTest
6868
}
6969

Sources/PackageModel/c99name().swift

Lines changed: 0 additions & 222 deletions
This file was deleted.

0 commit comments

Comments
 (0)