<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I am trying to understand the Swift AST by looking at output produced from swiftc -dump-ast &lt;file&gt;.</div><div class="">Most of it makes sense to me, but there are some things that I don’t understand. For example, consider</div><div class="">the following code:</div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">var x = 42</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class="">This produces the following output:</div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(source_file</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; (top_level_code_decl</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; (brace_stmt</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; (pattern_binding_decl</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">pattern_named</span><span style="font-variant-ligatures: no-common-ligatures" class=""> type='Int' 'x')</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; (call_expr implicit type='Int' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] nothrow</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (constructor_ref_call_expr implicit type='(_builtinIntegerLiteral: Int2048) -&gt; Int' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] nothrow</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (declref_expr implicit type='Int.Type -&gt; (_builtinIntegerLiteral: Int2048) -&gt; Int' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] decl=Swift.(file).Int.init(_builtinIntegerLiteral:) specialized=no)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (type_expr implicit type='Int.Type' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] typerepr='Int'))</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (tuple_expr implicit type='(_builtinIntegerLiteral: Int2048)' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] names=_builtinIntegerLiteral</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (integer_literal_expr type='Int2048' location=test.swift:1:9 range=[test.swift:1:9 - line:1:9] value=42))))</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; (var_decl "x" type='Int' access=internal storage_kind=stored))</span></div></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">Intuitively, I would have expected that the initializer is part of the var_decl. Also, why is there a brace_stmt involved?</div><div style="margin: 0px; line-height: normal;" class="">As far as I have seen, the term brace statement doesn’t appear anywhere in the Swift Language Reference. Is it the</div><div style="margin: 0px; line-height: normal;" class="">same as&nbsp;<a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/swift/grammar/code-block" class="">code-block</a>?</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Thanks in advance!</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Best regards,</div><div style="margin: 0px; line-height: normal;" class="">Toni</div></body></html>