Skip to content

Revert "Add Double and Int Convenience Properties (#239)" #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Note: This is in reverse chronological order, so newer entries are added to the

## Swift 5.3

* Introduced `integerValue` and `floatingValue` properties to `IntegerLiteralExprSyntax` and `FloatLiteralExprSyntax`, respectively. Converted their `digits` and `floatingDigits` setters, respectively, into throwing functions.

* Introduced `FunctionCallExprSyntax.additionalTrailingClosures` property with type `MultipleTrailingClosureElementListSyntax?` for supporting [SE-0279 Multiple Trailing Closures](https://github.com/apple/swift-evolution/blob/master/proposals/0279-multiple-trailing-closures.md).

* Introduced `syntaxNodeType` property for all types conforming to `SyntaxProtocol`, which returns the underlying syntax node type. It is primarily intended as a debugging aid during development.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ swift/utils/build-script --swiftsyntax --swiftpm --llbuild -t --skip-test-cmark
```
This command will build SwiftSyntax and all its dependencies, tell the build script to run tests, but skip all tests but the SwiftSyntax tests.

Note that it is not currently supported to build SwiftSyntax while building the Swift compiler using Xcode.
Note that it is not currently supported to SwiftSyntax while building the Swift compiler using Xcode.

### CI Testing

Expand Down
4 changes: 0 additions & 4 deletions Sources/SwiftSyntax/SyntaxBuilders.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ extension ${node.name} {
/// incrementally build the structure of the node.
/// - Returns: A `${node.name}` with all the fields populated in the builder
/// closure.
% if node.must_uphold_invariant:
public init?(_ build: (inout ${Builder}) -> Void) {
% else:
public init(_ build: (inout ${Builder}) -> Void) {
% end
var builder = ${Builder}()
build(&builder)
let data = builder.buildData()
Expand Down
80 changes: 0 additions & 80 deletions Sources/SwiftSyntax/SyntaxConvenienceMethods.swift

This file was deleted.

6 changes: 1 addition & 5 deletions Sources/SwiftSyntax/SyntaxFactory.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public enum SyntaxFactory {
% param_type = param_type + "?"
% child_params.append("%s: %s" % (child.swift_name, param_type))
% child_params = ', '.join(child_params)
% if node.must_uphold_invariant:
public static func make${node.syntax_kind}(${child_params}) -> ${node.name}? {
% else:
public static func make${node.syntax_kind}(${child_params}) -> ${node.name} {
% end
let layout: [RawSyntax?] = [
% for child in node.children:
% if child.is_optional:
Expand All @@ -86,7 +82,7 @@ public enum SyntaxFactory {
}
% end

% if not node.is_base() and not node.must_uphold_invariant:
% if not node.is_base():
public static func makeBlank${node.syntax_kind}() -> ${node.name} {
let data = SyntaxData.forRoot(RawSyntax.create(kind: .${node.swift_syntax_kind},
layout: [
Expand Down
42 changes: 0 additions & 42 deletions Sources/SwiftSyntax/SyntaxNodes.swift.gyb.template
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,14 @@ public struct ${node.name}: ${base_type}Protocol, SyntaxHashable {
public init?(_ syntax: Syntax) {
guard syntax.raw.kind == .${node.swift_syntax_kind} else { return nil }
self._syntaxNode = syntax
% if node.must_uphold_invariant:
if !isValid {
fatalError("Instance of ${node.name} is invalid.")
}
% end
}

/// Creates a `${node.name}` node from the given `SyntaxData`. This assumes
/// that the `SyntaxData` is of the correct kind. If it is not, the behaviour
/// is undefined.
% if node.must_uphold_invariant:
/// This initializer returns nil if the invariant is not satisfied.
internal init?(_ data: SyntaxData) {
% else:
internal init(_ data: SyntaxData) {
% end
assert(data.raw.kind == .${node.swift_syntax_kind})
self._syntaxNode = Syntax(data)
% if node.must_uphold_invariant:
if !isValid {
return nil
}
% end
}

public var syntaxNodeType: SyntaxProtocol.Type {
Expand Down Expand Up @@ -122,33 +107,10 @@ public struct ${node.name}: ${base_type}Protocol, SyntaxHashable {
% end
return ${child.type_name}(childData!)
}
% if not node.must_uphold_invariant:
set(value) {
self = with${child.name}(value)
}
% end
}
% if node.must_uphold_invariant:

public enum ${child.name}Error: Error, CustomStringConvertible {
case invalid(${child.swift_name}: ${ret_type})

public var description: String {
switch self {
case .invalid(let ${child.swift_name}):
return "attempted to use setter with invalid ${child.name} \"\(${child.swift_name})\""
}
}
}

mutating public func set${child.name}(_ ${child.swift_name}: ${ret_type}) throws {
if let childSyntax = with${child.name}(${child.swift_name}) {
self = childSyntax
} else {
throw ${child.name}Error.invalid(${child.swift_name}: ${child.swift_name})
}
}
% end
%
% # ===============
% # Adding children
Expand Down Expand Up @@ -187,11 +149,7 @@ public struct ${node.name}: ${base_type}Protocol, SyntaxHashable {
/// - param newChild: The new `${child.swift_name}` to replace the node's
/// current `${child.swift_name}`, if present.
public func with${child.name}(
% if node.must_uphold_invariant:
_ newChild: ${child.type_name}?) -> ${node.name}? {
% else:
_ newChild: ${child.type_name}?) -> ${node.name} {
% end
% if child.is_optional:
let raw = newChild?.raw
% else:
Expand Down
5 changes: 0 additions & 5 deletions Sources/SwiftSyntax/SyntaxRewriter.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ open class SyntaxRewriter {
if let newNode = visitAny(node._syntaxNode) { return newNode }
return Syntax(visit(node))
% else:
% if node.must_uphold_invariant:
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
let node = ${node.name}(data)!
% else:
let node = ${node.name}(data)
% end
// Accessing _syntaxNode directly is faster than calling Syntax(node)
visitPre(node._syntaxNode)
defer { visitPost(node._syntaxNode) }
Expand Down
5 changes: 0 additions & 5 deletions Sources/SwiftSyntax/SyntaxVisitor.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ open class SyntaxVisitor {
}
visitPost(node)
% else:
% if node.must_uphold_invariant:
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
let node = ${node.name}(data)!
% else:
let node = ${node.name}(data)
% end
let needsChildren = (visit(node) == .visitChildren)
// Avoid calling into visitChildren if possible.
if needsChildren && node.raw.numberOfChildren > 0 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ extension FloatLiteralExprSyntax {
/// incrementally build the structure of the node.
/// - Returns: A `FloatLiteralExprSyntax` with all the fields populated in the builder
/// closure.
public init?(_ build: (inout FloatLiteralExprSyntaxBuilder) -> Void) {
public init(_ build: (inout FloatLiteralExprSyntaxBuilder) -> Void) {
var builder = FloatLiteralExprSyntaxBuilder()
build(&builder)
let data = builder.buildData()
Expand Down Expand Up @@ -1444,7 +1444,7 @@ extension IntegerLiteralExprSyntax {
/// incrementally build the structure of the node.
/// - Returns: A `IntegerLiteralExprSyntax` with all the fields populated in the builder
/// closure.
public init?(_ build: (inout IntegerLiteralExprSyntaxBuilder) -> Void) {
public init(_ build: (inout IntegerLiteralExprSyntaxBuilder) -> Void) {
var builder = IntegerLiteralExprSyntaxBuilder()
build(&builder)
let data = builder.buildData()
Expand Down
18 changes: 16 additions & 2 deletions Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public enum SyntaxFactory {
], length: .zero, presence: .present))
return ArrowExprSyntax(data)
}
public static func makeFloatLiteralExpr(floatingDigits: TokenSyntax) -> FloatLiteralExprSyntax? {
public static func makeFloatLiteralExpr(floatingDigits: TokenSyntax) -> FloatLiteralExprSyntax {
let layout: [RawSyntax?] = [
floatingDigits.raw,
]
Expand All @@ -629,6 +629,13 @@ public enum SyntaxFactory {
return FloatLiteralExprSyntax(data)
}

public static func makeBlankFloatLiteralExpr() -> FloatLiteralExprSyntax {
let data = SyntaxData.forRoot(RawSyntax.create(kind: .floatLiteralExpr,
layout: [
RawSyntax.missingToken(TokenKind.floatingLiteral("")),
], length: .zero, presence: .present))
return FloatLiteralExprSyntax(data)
}
public static func makeTupleExpr(leftParen: TokenSyntax, elementList: TupleExprElementListSyntax, rightParen: TokenSyntax) -> TupleExprSyntax {
let layout: [RawSyntax?] = [
leftParen.raw,
Expand Down Expand Up @@ -757,7 +764,7 @@ public enum SyntaxFactory {
], length: .zero, presence: .present))
return DictionaryElementSyntax(data)
}
public static func makeIntegerLiteralExpr(digits: TokenSyntax) -> IntegerLiteralExprSyntax? {
public static func makeIntegerLiteralExpr(digits: TokenSyntax) -> IntegerLiteralExprSyntax {
let layout: [RawSyntax?] = [
digits.raw,
]
Expand All @@ -767,6 +774,13 @@ public enum SyntaxFactory {
return IntegerLiteralExprSyntax(data)
}

public static func makeBlankIntegerLiteralExpr() -> IntegerLiteralExprSyntax {
let data = SyntaxData.forRoot(RawSyntax.create(kind: .integerLiteralExpr,
layout: [
RawSyntax.missingToken(TokenKind.integerLiteral("")),
], length: .zero, presence: .present))
return IntegerLiteralExprSyntax(data)
}
public static func makeBooleanLiteralExpr(booleanLiteral: TokenSyntax) -> BooleanLiteralExprSyntax {
let layout: [RawSyntax?] = [
booleanLiteral.raw,
Expand Down
6 changes: 2 additions & 4 deletions Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2135,8 +2135,7 @@ open class SyntaxRewriter {

/// Implementation detail of visit(_:). Do not call directly.
private func visitImplFloatLiteralExprSyntax(_ data: SyntaxData) -> Syntax {
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
let node = FloatLiteralExprSyntax(data)!
let node = FloatLiteralExprSyntax(data)
// Accessing _syntaxNode directly is faster than calling Syntax(node)
visitPre(node._syntaxNode)
defer { visitPost(node._syntaxNode) }
Expand Down Expand Up @@ -2206,8 +2205,7 @@ open class SyntaxRewriter {

/// Implementation detail of visit(_:). Do not call directly.
private func visitImplIntegerLiteralExprSyntax(_ data: SyntaxData) -> Syntax {
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
let node = IntegerLiteralExprSyntax(data)!
let node = IntegerLiteralExprSyntax(data)
// Accessing _syntaxNode directly is faster than calling Syntax(node)
visitPre(node._syntaxNode)
defer { visitPost(node._syntaxNode) }
Expand Down
6 changes: 2 additions & 4 deletions Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2878,8 +2878,7 @@ open class SyntaxVisitor {

/// Implementation detail of doVisit(_:_:). Do not call directly.
private func visitImplFloatLiteralExprSyntax(_ data: SyntaxData) {
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
let node = FloatLiteralExprSyntax(data)!
let node = FloatLiteralExprSyntax(data)
let needsChildren = (visit(node) == .visitChildren)
// Avoid calling into visitChildren if possible.
if needsChildren && node.raw.numberOfChildren > 0 {
Expand Down Expand Up @@ -2956,8 +2955,7 @@ open class SyntaxVisitor {

/// Implementation detail of doVisit(_:_:). Do not call directly.
private func visitImplIntegerLiteralExprSyntax(_ data: SyntaxData) {
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
let node = IntegerLiteralExprSyntax(data)!
let node = IntegerLiteralExprSyntax(data)
let needsChildren = (visit(node) == .visitChildren)
// Avoid calling into visitChildren if possible.
if needsChildren && node.raw.numberOfChildren > 0 {
Expand Down
Loading