[swift-dev] Role of Brace-Stmt in Swift AST
Toni Suter
tonisuter at me.com
Wed Mar 23 07:58:20 CDT 2016
Hi,
I am trying to understand the Swift AST by looking at output produced from swiftc -dump-ast <file>.
Most of it makes sense to me, but there are some things that I don’t understand. For example, consider
the following code:
var x = 42
This produces the following output:
(source_file
(top_level_code_decl
(brace_stmt
(pattern_binding_decl
(pattern_named type='Int' 'x')
(call_expr implicit type='Int' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] nothrow
(constructor_ref_call_expr implicit type='(_builtinIntegerLiteral: Int2048) -> Int' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] nothrow
(declref_expr implicit type='Int.Type -> (_builtinIntegerLiteral: Int2048) -> Int' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] decl=Swift.(file).Int.init(_builtinIntegerLiteral:) specialized=no)
(type_expr implicit type='Int.Type' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] typerepr='Int'))
(tuple_expr implicit type='(_builtinIntegerLiteral: Int2048)' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] names=_builtinIntegerLiteral
(integer_literal_expr type='Int2048' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] value=42))))
))
(var_decl "x" type='Int' access=internal storage_kind=stored))
Intuitively, I would have expected that the initializer is part of the var_decl. Also, why is there a brace_stmt involved?
As far as I have seen, the term brace statement doesn’t appear anywhere in the Swift Language Reference. Is it the
same as code-block <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block>?
Thanks in advance!
Best regards,
Toni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160323/f3b2107e/attachment.html>
More information about the swift-dev
mailing list