Skip to content

Commit 78d7bc1

Browse files
authored
Merge pull request #1284 from DougGregor/remove-pound-assert
Remove parsing, token, and syntax nodes for `#` things subsumed by macros
2 parents 101eaf0 + 5ea331a commit 78d7bc1

39 files changed

+37
-2512
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/DeclNodes.swift

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -213,58 +213,6 @@ public let DECL_NODES: [Node] = [
213213
classification: "BuildConfigId")
214214
]),
215215

216-
Node(name: "PoundErrorDecl",
217-
nameForDiagnostics: "'#error' directive",
218-
kind: "Decl",
219-
traits: [
220-
"Parenthesized"
221-
],
222-
children: [
223-
Child(name: "PoundError",
224-
kind: "PoundErrorToken",
225-
tokenChoices: [
226-
"PoundError"
227-
]),
228-
Child(name: "LeftParen",
229-
kind: "LeftParenToken",
230-
tokenChoices: [
231-
"LeftParen"
232-
]),
233-
Child(name: "Message",
234-
kind: "StringLiteralExpr"),
235-
Child(name: "RightParen",
236-
kind: "RightParenToken",
237-
tokenChoices: [
238-
"RightParen"
239-
])
240-
]),
241-
242-
Node(name: "PoundWarningDecl",
243-
nameForDiagnostics: "'#warning' directive",
244-
kind: "Decl",
245-
traits: [
246-
"Parenthesized"
247-
],
248-
children: [
249-
Child(name: "PoundWarning",
250-
kind: "PoundWarningToken",
251-
tokenChoices: [
252-
"PoundWarning"
253-
]),
254-
Child(name: "LeftParen",
255-
kind: "LeftParenToken",
256-
tokenChoices: [
257-
"LeftParen"
258-
]),
259-
Child(name: "Message",
260-
kind: "StringLiteralExpr"),
261-
Child(name: "RightParen",
262-
kind: "RightParenToken",
263-
tokenChoices: [
264-
"RightParen"
265-
])
266-
]),
267-
268216
Node(name: "PoundSourceLocation",
269217
nameForDiagnostics: "'#sourceLocation' directive",
270218
kind: "Decl",
@@ -1600,7 +1548,7 @@ public let DECL_NODES: [Node] = [
16001548
]),
16011549

16021550
Node(name: "MacroExpansionDecl",
1603-
nameForDiagnostics: "pound literal declaration",
1551+
nameForDiagnostics: "macro expansion",
16041552
kind: "Decl",
16051553
traits: [
16061554
"FreestandingMacroExpansion"

CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ public let EXPR_NODES: [Node] = [
11601160
]),
11611161

11621162
Node(name: "MacroExpansionExpr",
1163-
nameForDiagnostics: "pound literal expression",
1163+
nameForDiagnostics: "macro expansion expression",
11641164
kind: "Expr",
11651165
traits: [
11661166
"FreestandingMacroExpansion"

CodeGeneration/Sources/SyntaxSupport/gyb_generated/StmtNodes.swift

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,7 @@ public let STMT_NODES: [Node] = [
408408
Child(name: "MatchingPattern",
409409
kind: "MatchingPatternCondition"),
410410
Child(name: "OptionalBinding",
411-
kind: "OptionalBindingCondition"),
412-
Child(name: "HasSymbol",
413-
kind: "HasSymbolCondition")
411+
kind: "OptionalBindingCondition")
414412
]),
415413
Child(name: "TrailingComma",
416414
kind: "CommaToken",
@@ -489,26 +487,6 @@ public let STMT_NODES: [Node] = [
489487
isOptional: true)
490488
]),
491489

492-
Node(name: "HasSymbolCondition",
493-
nameForDiagnostics: "'#_hasSymbol' condition",
494-
kind: "Syntax",
495-
children: [
496-
Child(name: "HasSymbolKeyword",
497-
kind: "HasSymbolToken"),
498-
Child(name: "LeftParen",
499-
kind: "LeftParenToken",
500-
tokenChoices: [
501-
"LeftParen"
502-
]),
503-
Child(name: "Expression",
504-
kind: "Expr"),
505-
Child(name: "RightParen",
506-
kind: "RightParenToken",
507-
tokenChoices: [
508-
"RightParen"
509-
])
510-
]),
511-
512490
Node(name: "ConditionElementList",
513491
nameForDiagnostics: nil,
514492
kind: "SyntaxCollection",
@@ -695,39 +673,4 @@ public let STMT_NODES: [Node] = [
695673
kind: "CodeBlock")
696674
]),
697675

698-
Node(name: "PoundAssertStmt",
699-
nameForDiagnostics: "'#assert' directive",
700-
kind: "Stmt",
701-
children: [
702-
Child(name: "PoundAssert",
703-
kind: "PoundAssertToken",
704-
tokenChoices: [
705-
"PoundAssert"
706-
]),
707-
Child(name: "LeftParen",
708-
kind: "LeftParenToken",
709-
tokenChoices: [
710-
"LeftParen"
711-
]),
712-
Child(name: "Condition",
713-
kind: "Expr",
714-
description: "The assertion condition."),
715-
Child(name: "Comma",
716-
kind: "CommaToken",
717-
description: "The comma after the assertion condition.",
718-
isOptional: true,
719-
tokenChoices: [
720-
"Comma"
721-
]),
722-
Child(name: "Message",
723-
kind: "StringLiteralExpr",
724-
description: "The assertion message.",
725-
isOptional: true),
726-
Child(name: "RightParen",
727-
kind: "RightParenToken",
728-
tokenChoices: [
729-
"RightParen"
730-
])
731-
]),
732-
733676
]

CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,13 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
196196
PunctuatorSpec(name: "StringQuote", kind: "string_quote", text: "\"", classification: "StringLiteral"),
197197
PunctuatorSpec(name: "SingleQuote", kind: "single_quote", text: "\'", classification: "StringLiteral"),
198198
PunctuatorSpec(name: "MultilineStringQuote", kind: "multiline_string_quote", text: "\"\"\"", classification: "StringLiteral"),
199-
PoundKeywordSpec(name: "PoundAssert", kind: "pound_assert", text: "#assert"),
200199
PoundDirectiveKeywordSpec(name: "PoundSourceLocation", kind: "pound_sourceLocation", text: "#sourceLocation"),
201-
PoundDirectiveKeywordSpec(name: "PoundWarning", kind: "pound_warning", text: "#warning"),
202-
PoundDirectiveKeywordSpec(name: "PoundError", kind: "pound_error", text: "#error"),
203200
PoundConditionalDirectiveKeywordSpec(name: "PoundIf", kind: "pound_if", text: "#if"),
204201
PoundConditionalDirectiveKeywordSpec(name: "PoundElse", kind: "pound_else", text: "#else"),
205202
PoundConditionalDirectiveKeywordSpec(name: "PoundElseif", kind: "pound_elseif", text: "#elseif"),
206203
PoundConditionalDirectiveKeywordSpec(name: "PoundEndif", kind: "pound_endif", text: "#endif"),
207204
PoundConfigSpec(name: "PoundAvailable", kind: "pound_available", text: "#available"),
208205
PoundConfigSpec(name: "PoundUnavailable", kind: "pound_unavailable", text: "#unavailable"),
209-
PoundObjectLiteralSpec(name: "PoundFileLiteral", kind: "pound_fileLiteral", text: "#fileLiteral", nameForDiagnostics: "file reference", protocol: "ExpressibleByFileReferenceLiteral"),
210-
PoundObjectLiteralSpec(name: "PoundImageLiteral", kind: "pound_imageLiteral", text: "#imageLiteral", nameForDiagnostics: "image", protocol: "ExpressibleByImageLiteral"),
211-
PoundObjectLiteralSpec(name: "PoundColorLiteral", kind: "pound_colorLiteral", text: "#colorLiteral", nameForDiagnostics: "color", protocol: "ExpressibleByColorLiteral"),
212-
PoundConfigSpec(name: "PoundHasSymbol", kind: "pound__hasSymbol", text: "#_hasSymbol"),
213206
LiteralSpec(name: "IntegerLiteral", kind: "integer_literal", nameForDiagnostics: "integer literal", classification: "IntegerLiteral"),
214207
LiteralSpec(name: "FloatingLiteral", kind: "floating_literal", nameForDiagnostics: "floating literal", classification: "FloatingLiteral"),
215208
LiteralSpec(name: "RegexLiteral", kind: "regex_literal", nameForDiagnostics: "regex literal"),

Sources/IDEUtils/generated/SyntaxClassification.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,8 @@ extension RawTokenKind {
192192
return .stringLiteral
193193
case .multilineStringQuote:
194194
return .stringLiteral
195-
case .poundAssertKeyword:
196-
return .keyword
197195
case .poundSourceLocationKeyword:
198196
return .poundDirectiveKeyword
199-
case .poundWarningKeyword:
200-
return .poundDirectiveKeyword
201-
case .poundErrorKeyword:
202-
return .poundDirectiveKeyword
203197
case .poundIfKeyword:
204198
return .poundDirectiveKeyword
205199
case .poundElseKeyword:
@@ -212,14 +206,6 @@ extension RawTokenKind {
212206
return .keyword
213207
case .poundUnavailableKeyword:
214208
return .keyword
215-
case .poundFileLiteralKeyword:
216-
return .objectLiteral
217-
case .poundImageLiteralKeyword:
218-
return .objectLiteral
219-
case .poundColorLiteralKeyword:
220-
return .objectLiteral
221-
case .poundHasSymbolKeyword:
222-
return .keyword
223209
case .integerLiteral:
224210
return .integerLiteral
225211
case .floatingLiteral:

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,8 @@ open class BasicFormat: SyntaxRewriter {
198198
return true
199199
case .arrow:
200200
return true
201-
case .poundAssertKeyword:
202-
return true
203201
case .poundSourceLocationKeyword:
204202
return true
205-
case .poundWarningKeyword:
206-
return true
207-
case .poundErrorKeyword:
208-
return true
209203
case .poundIfKeyword:
210204
return true
211205
case .poundElseKeyword:
@@ -218,14 +212,6 @@ open class BasicFormat: SyntaxRewriter {
218212
return true
219213
case .poundUnavailableKeyword:
220214
return true
221-
case .poundFileLiteralKeyword:
222-
return true
223-
case .poundImageLiteralKeyword:
224-
return true
225-
case .poundColorLiteralKeyword:
226-
return true
227-
case .poundHasSymbolKeyword:
228-
return true
229215
case .binaryOperator:
230216
return true
231217
case .keyword(.`Any`):

Sources/SwiftParser/Declarations.swift

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ extension Parser {
202202
return .decls(RawMemberDeclListSyntax(elements: elements, arena: parser.arena))
203203
}
204204
return RawDeclSyntax(directive)
205-
case (.poundWarningKeyword, _)?, (.poundErrorKeyword, _)?:
206-
return self.parsePoundDiagnosticDeclaration()
207205
case (.pound, _)?:
208206
// FIXME: If we can have attributes for macro expansions, handle this
209207
// via DeclarationStart.
@@ -2062,76 +2060,6 @@ extension Parser {
20622060
}
20632061

20642062
extension Parser {
2065-
enum PoundDiagnosticKind {
2066-
case error(poundError: RawTokenSyntax)
2067-
case warning(poundWarning: RawTokenSyntax)
2068-
}
2069-
2070-
@_spi(RawSyntax)
2071-
public mutating func parsePoundDiagnosticDeclaration() -> RawDeclSyntax {
2072-
enum ExpectedTokenKind: RawTokenKindSubset {
2073-
case poundErrorKeyword
2074-
case poundWarningKeyword
2075-
2076-
init?(lexeme: Lexer.Lexeme) {
2077-
switch lexeme.rawTokenKind {
2078-
case .poundErrorKeyword: self = .poundErrorKeyword
2079-
case .poundWarningKeyword: self = .poundWarningKeyword
2080-
default: return nil
2081-
}
2082-
}
2083-
2084-
var rawTokenKind: RawTokenKind {
2085-
switch self {
2086-
case .poundErrorKeyword: return .poundErrorKeyword
2087-
case .poundWarningKeyword: return .poundWarningKeyword
2088-
}
2089-
}
2090-
}
2091-
2092-
let directive: PoundDiagnosticKind
2093-
2094-
switch self.at(anyIn: ExpectedTokenKind.self) {
2095-
case (.poundErrorKeyword, let handle)?:
2096-
directive = .error(poundError: self.eat(handle))
2097-
case (.poundWarningKeyword, let handle)?:
2098-
directive = .warning(poundWarning: self.eat(handle))
2099-
case nil:
2100-
directive = .error(poundError: RawTokenSyntax(missing: .poundErrorKeyword, arena: self.arena))
2101-
}
2102-
2103-
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
2104-
let stringLiteral = self.parseStringLiteral()
2105-
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
2106-
2107-
switch directive {
2108-
case .error(let tok):
2109-
return RawDeclSyntax(
2110-
RawPoundErrorDeclSyntax(
2111-
poundError: tok,
2112-
unexpectedBeforeLeftParen,
2113-
leftParen: leftParen,
2114-
message: stringLiteral,
2115-
unexpectedBeforeRightParen,
2116-
rightParen: rightParen,
2117-
arena: self.arena
2118-
)
2119-
)
2120-
case .warning(let tok):
2121-
return RawDeclSyntax(
2122-
RawPoundWarningDeclSyntax(
2123-
poundWarning: tok,
2124-
unexpectedBeforeLeftParen,
2125-
leftParen: leftParen,
2126-
message: stringLiteral,
2127-
unexpectedBeforeRightParen,
2128-
rightParen: rightParen,
2129-
arena: self.arena
2130-
)
2131-
)
2132-
}
2133-
}
2134-
21352063
/// Parse a macro declaration.
21362064
mutating func parseMacroDeclaration(
21372065
attrs: DeclAttributes,

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,17 +1458,13 @@ extension Lexer.Cursor {
14581458

14591459
let kind: RawTokenKind
14601460
switch literal {
1461-
case "assert": kind = .poundAssertKeyword
14621461
case "sourceLocation": kind = .poundSourceLocationKeyword
1463-
case "warning": kind = .poundWarningKeyword
1464-
case "error": kind = .poundErrorKeyword
14651462
case "if": kind = .poundIfKeyword
14661463
case "else": kind = .poundElseKeyword
14671464
case "elseif": kind = .poundElseifKeyword
14681465
case "endif": kind = .poundEndifKeyword
14691466
case "available": kind = .poundAvailableKeyword
14701467
case "unavailable": kind = .poundUnavailableKeyword
1471-
case "_hasSymbol": kind = .poundHasSymbolKeyword
14721468
default:
14731469
// If we didn't find a match, then just return `.pound`. This is highly
14741470
// dubious in terms of error recovery, but is useful for code completion and

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
104104
case forKeyword
105105
case guardKeyword
106106
case ifKeyword
107-
case poundAssertKeyword
108107
case repeatKeyword
109108
case returnKeyword
110109
case switchKeyword
@@ -122,7 +121,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
122121
case RawTokenKindMatch(.for): self = .forKeyword
123122
case RawTokenKindMatch(.guard): self = .guardKeyword
124123
case RawTokenKindMatch(.if): self = .ifKeyword
125-
case RawTokenKindMatch(.poundAssertKeyword): self = .poundAssertKeyword
126124
case RawTokenKindMatch(.repeat): self = .repeatKeyword
127125
case RawTokenKindMatch(.return): self = .returnKeyword
128126
case RawTokenKindMatch(.switch): self = .switchKeyword
@@ -143,7 +141,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
143141
case .forKeyword: return .keyword(.for)
144142
case .guardKeyword: return .keyword(.guard)
145143
case .ifKeyword: return .keyword(.if)
146-
case .poundAssertKeyword: return .poundAssertKeyword
147144
case .repeatKeyword: return .keyword(.repeat)
148145
case .returnKeyword: return .keyword(.return)
149146
case .switchKeyword: return .keyword(.switch)
@@ -474,15 +471,11 @@ enum OperatorLike: RawTokenKindSubset {
474471

475472
enum PoundDeclarationStart: RawTokenKindSubset {
476473
case poundIfKeyword
477-
case poundWarningKeyword
478-
case poundErrorKeyword
479474
case pound
480475

481476
init?(lexeme: Lexer.Lexeme) {
482477
switch lexeme.rawTokenKind {
483478
case .poundIfKeyword: self = .poundIfKeyword
484-
case .poundWarningKeyword: self = .poundWarningKeyword
485-
case .poundErrorKeyword: self = .poundErrorKeyword
486479
case .pound: self = .pound
487480
default: return nil
488481
}
@@ -491,8 +484,6 @@ enum PoundDeclarationStart: RawTokenKindSubset {
491484
var rawTokenKind: RawTokenKind {
492485
switch self {
493486
case .poundIfKeyword: return .poundIfKeyword
494-
case .poundWarningKeyword: return .poundWarningKeyword
495-
case .poundErrorKeyword: return .poundErrorKeyword
496487
case .pound: return .pound
497488
}
498489
}

0 commit comments

Comments
 (0)