mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[AST] Improve JSON representation of various AST nodes.
This commit is contained in:
committed by
Tony Allevato
parent
a57fb4dfa9
commit
52c009a2ec
File diff suppressed because it is too large
Load Diff
@@ -5,9 +5,10 @@
|
||||
// issues are discovered in the future.
|
||||
//
|
||||
// This file should not contain top-level code, since it contains a `@main`
|
||||
// type.
|
||||
// type. It should also not contain code that requires Obj-C; put that in
|
||||
// ast-dump-json-objc-no-crash.swift instead.
|
||||
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -target %target-swift-5.9-abi-triple -swift-version 6 -I %S/Inputs/dependencies -parse-as-library -dump-ast -dump-ast-format json %s -module-name main -o -
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -target %target-swift-5.9-abi-triple -swift-version 6 -I %S/Inputs/dependencies -parse-as-library -dump-ast -dump-ast-format json %s -module-name main -o - >/dev/null
|
||||
|
||||
struct E: Error {}
|
||||
|
||||
@@ -60,7 +61,7 @@ protocol P1 {
|
||||
|
||||
associatedtype A1
|
||||
associatedtype A2 = Int
|
||||
associatedtype A3: BinaryInteger
|
||||
associatedtype A3: BinaryInteger where A3: Codable
|
||||
}
|
||||
protocol P2: AnyObject where Self: C1 {}
|
||||
|
||||
|
||||
30
test/Frontend/ast-dump-json-objc-no-crash.swift
Normal file
30
test/Frontend/ast-dump-json-objc-no-crash.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
// This test is by no means exhaustive, but attempts to catch any places in the
|
||||
// implementation of ASTDumper's JSON where it might do an unprotected call to
|
||||
// some method on AST node that would cause an assertion due to some
|
||||
// unsatisfied precondition. This is a good place to put regression tests if
|
||||
// issues are discovered in the future.
|
||||
//
|
||||
// It is separate from ast-dump-json-no-crash.swift since we don't want that
|
||||
// other test to require Obj-C interop.
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -target %target-swift-5.9-abi-triple -enable-objc-interop -swift-version 6 -parse-as-library -dump-ast -dump-ast-format json %s -module-name main -o -
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc public class NotRenamed: NSObject {
|
||||
@objc public var property: Int = 0
|
||||
}
|
||||
|
||||
@objc(PFXRenamed) @objcMembers public class Renamed: NSObject {
|
||||
@objc(f1) public func f1() {}
|
||||
@objc(f2WithInteger:) public func f2(_ x: Int) {}
|
||||
@objc(f3withInteger:error:) public func f3(_ x: Int) throws {}
|
||||
|
||||
@objc(objcnested) public var nested: NotRenamed = .init()
|
||||
}
|
||||
|
||||
func f() {
|
||||
_ = #selector(Renamed.f1)
|
||||
_ = #keyPath(Renamed.nested.property)
|
||||
}
|
||||
33
test/Frontend/ast-dump-json-output-map.swift
Normal file
33
test/Frontend/ast-dump-json-output-map.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: echo 'public func a() { }' > %t/a.swift
|
||||
// RUN: echo 'public func b() { }' > %t/b.swift
|
||||
// RUN: echo 'public func main() {a(); b()}' > %t/main.swift
|
||||
// RUN: echo "{\"%/t/a.swift\": {\"ast-dump\": \"%/t/a.ast\"}, \"%/t/b.swift\": {\"ast-dump\": \"%/t/b.ast\"}, \"%/t/main.swift\": {\"ast-dump\": \"%/t/main.ast\"}}" > %t/outputs.json
|
||||
|
||||
// RUN: %target-build-swift -dump-ast -dump-ast-format json -output-file-map %t/outputs.json %t/a.swift %t/b.swift %t/main.swift -module-name main
|
||||
// RUN: %FileCheck -check-prefix A-AST %s < %t/a.ast
|
||||
// RUN: %FileCheck -check-prefix B-AST %s < %t/b.ast
|
||||
// RUN: %FileCheck -check-prefix MAIN-AST %s < %t/main.ast
|
||||
|
||||
|
||||
// Check a.swift's AST
|
||||
// A-AST: "filename":"{{[^"]+}}a.swift"
|
||||
// A-AST-SAME: "_kind":"func_decl"
|
||||
// A-AST-SAME: "usr":"s:4main1ayyF"
|
||||
|
||||
|
||||
// Check b.swift's AST
|
||||
// B-AST: "filename":"{{[^"]+}}b.swift"
|
||||
// B-AST-SAME: "_kind":"func_decl"
|
||||
// B-AST-SAME: "usr":"s:4main1byyF"
|
||||
|
||||
|
||||
// Check main.swift's AST
|
||||
// MAIN-AST: "filename":"{{[^"]+}}main.swift"
|
||||
// MAIN-AST-SAME: "_kind":"func_decl"
|
||||
// MAIN-AST-SAME: "usr":"s:4mainAAyyF"
|
||||
|
||||
// MAIN-AST-SAME: "_kind":"call_expr"
|
||||
// MAIN-AST-SAME: "decl_usr":"s:4main1ayyF"
|
||||
// MAIN-AST-SAME: "_kind":"call_expr"
|
||||
// MAIN-AST-SAME: "decl_usr":"s:4main1byyF"
|
||||
13
test/Frontend/ast-dump-json-zlib.swift
Normal file
13
test/Frontend/ast-dump-json-zlib.swift
Normal file
@@ -0,0 +1,13 @@
|
||||
// This test verifies that the zlib-compressed JSON option returns something
|
||||
// that looks like correct JSON once it's been decompressed. Note that the
|
||||
// output is a simple zlib-compressed stream and *not* a gzip archive.
|
||||
|
||||
// Windows does not currently build with zlib support.
|
||||
// UNSUPPORTED: OS=windows-msvc
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -target %target-swift-5.9-abi-triple -swift-version 6 -I %S/Inputs/dependencies -parse-as-library -dump-ast -dump-ast-format json-zlib %S/ast-dump-json-no-crash.swift -module-name main -o - > %t/main.jsonz
|
||||
// RUN: %{python} -c 'import sys, zlib; sys.stdout.write(zlib.decompress(sys.stdin.buffer.read()).decode())' < %t/main.jsonz | %FileCheck %s
|
||||
|
||||
// CHECK: {"_kind":"source_file",
|
||||
// CHECK-SAME: "items":[{
|
||||
30
test/Frontend/ast-dump-json.swift
Normal file
30
test/Frontend/ast-dump-json.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: echo 'public func a() { }' >%t/a.swift
|
||||
// RUN: echo 'public func b() { }' >%t/b.swift
|
||||
// RUN: echo 'public func main() {a(); b()}' >%t/main.swift
|
||||
|
||||
// RUN: %target-swift-frontend -dump-ast -dump-ast-format json -primary-file %t/a.swift %t/b.swift %t/main.swift -module-name main -o - 2>%t/a.swift.stderr | %FileCheck -check-prefix A-AST %s
|
||||
// RUN: %target-swift-frontend -dump-ast -dump-ast-format json %t/a.swift -primary-file %t/b.swift %t/main.swift -module-name main -o - 2>%t/b.swift.stderr | %FileCheck -check-prefix B-AST %s
|
||||
// RUN: %target-swift-frontend -dump-ast -dump-ast-format json %t/a.swift %t/b.swift -primary-file %t/main.swift -module-name main -o - 2>%t/main.swift.stderr | %FileCheck -check-prefix MAIN-AST %s
|
||||
|
||||
// Check a.swift's AST
|
||||
// A-AST: "filename":"{{[^"]+}}/a.swift"
|
||||
// A-AST-SAME: "_kind":"func_decl"
|
||||
// A-AST-SAME: "usr":"s:4main1ayyF"
|
||||
|
||||
|
||||
// Check b.swift's AST
|
||||
// B-AST: "filename":"{{[^"]+}}/b.swift"
|
||||
// B-AST-SAME: "_kind":"func_decl"
|
||||
// B-AST-SAME: "usr":"s:4main1byyF"
|
||||
|
||||
|
||||
// Check main.swift's AST
|
||||
// MAIN-AST: "filename":"{{[^"]+}}/main.swift"
|
||||
// MAIN-AST-SAME: "_kind":"func_decl"
|
||||
// MAIN-AST-SAME: "usr":"s:4mainAAyyF"
|
||||
|
||||
// MAIN-AST-SAME: "_kind":"call_expr"
|
||||
// MAIN-AST-SAME: "decl_usr":"s:4main1ayyF"
|
||||
// MAIN-AST-SAME: "_kind":"call_expr"
|
||||
// MAIN-AST-SAME: "decl_usr":"s:4main1byyF"
|
||||
Reference in New Issue
Block a user