Skip to content

Commit 76db1c5

Browse files
committed
Swift: Add the same code to the AST test as well.
1 parent b0c7964 commit 76db1c5

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

swift/ql/test/library-tests/ast/PrintAst.expected

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7148,3 +7148,95 @@ statements.swift:
71487148
# 92| getExpr(): [DefaultArgumentExpr] default separator
71497149
# 92| getArgument(2): [Argument] terminator: default terminator
71507150
# 92| getExpr(): [DefaultArgumentExpr] default terminator
7151+
# 95| [Comment] // ---
7152+
# 95|
7153+
# 97| [ProtocolDecl] MyProtocol
7154+
#-----| getGenericTypeParam(0): [GenericTypeParamDecl] Self
7155+
# 98| getMember(0): [NamedFunction] source()
7156+
# 98| InterfaceType = <Self where Self : MyProtocol> (Self) -> () -> Int
7157+
# 98| getSelfParam(): [ParamDecl] self
7158+
# 98| Type = Self
7159+
# 101| [ClassDecl] MyProcotolImpl
7160+
# 102| getMember(0): [NamedFunction] source()
7161+
# 102| InterfaceType = (MyProcotolImpl) -> () -> Int
7162+
# 102| getSelfParam(): [ParamDecl] self
7163+
# 102| Type = MyProcotolImpl
7164+
# 102| getBody(): [BraceStmt] { ... }
7165+
# 102| getElement(0): [ReturnStmt] return ...
7166+
# 102| getResult(): [IntegerLiteralExpr] 0
7167+
# 101| getMember(1): [Deinitializer] MyProcotolImpl.deinit()
7168+
# 101| InterfaceType = (MyProcotolImpl) -> () -> ()
7169+
# 101| getSelfParam(): [ParamDecl] self
7170+
# 101| Type = MyProcotolImpl
7171+
# 101| getBody(): [BraceStmt] { ... }
7172+
# 101| getMember(2): [Initializer] MyProcotolImpl.init()
7173+
# 101| InterfaceType = (MyProcotolImpl.Type) -> () -> MyProcotolImpl
7174+
# 101| getSelfParam(): [ParamDecl] self
7175+
# 101| Type = MyProcotolImpl
7176+
# 101| getBody(): [BraceStmt] { ... }
7177+
# 101| getElement(0): [ReturnStmt] return
7178+
# 105| [NamedFunction] getMyProtocol()
7179+
# 105| InterfaceType = () -> MyProtocol
7180+
# 105| getBody(): [BraceStmt] { ... }
7181+
# 105| getElement(0): [ReturnStmt] return ...
7182+
# 105| getResult(): [CallExpr] call to MyProcotolImpl.init()
7183+
# 105| getFunction(): [MethodLookupExpr] MyProcotolImpl.init()
7184+
# 105| getBase(): [TypeExpr] MyProcotolImpl.Type
7185+
# 105| getTypeRepr(): [TypeRepr] MyProcotolImpl
7186+
# 105| getMethodRef(): [DeclRefExpr] MyProcotolImpl.init()
7187+
# 105| getResult().getFullyConverted(): [ErasureExpr] (MyProtocol) ...
7188+
# 106| [NamedFunction] getMyProtocolImpl()
7189+
# 106| InterfaceType = () -> MyProcotolImpl
7190+
# 106| getBody(): [BraceStmt] { ... }
7191+
# 106| getElement(0): [ReturnStmt] return ...
7192+
# 106| getResult(): [CallExpr] call to MyProcotolImpl.init()
7193+
# 106| getFunction(): [MethodLookupExpr] MyProcotolImpl.init()
7194+
# 106| getBase(): [TypeExpr] MyProcotolImpl.Type
7195+
# 106| getTypeRepr(): [TypeRepr] MyProcotolImpl
7196+
# 106| getMethodRef(): [DeclRefExpr] MyProcotolImpl.init()
7197+
# 108| [NamedFunction] sink(arg:)
7198+
# 108| InterfaceType = (Int) -> ()
7199+
# 108| getParam(0): [ParamDecl] arg
7200+
# 108| Type = Int
7201+
# 108| getBody(): [BraceStmt] { ... }
7202+
# 110| [NamedFunction] testOpenExistentialExpr(x:y:)
7203+
# 110| InterfaceType = (MyProtocol, MyProcotolImpl) -> ()
7204+
# 110| getParam(0): [ParamDecl] x
7205+
# 110| Type = MyProtocol
7206+
# 110| getParam(1): [ParamDecl] y
7207+
# 110| Type = MyProcotolImpl
7208+
# 110| getBody(): [BraceStmt] { ... }
7209+
# 111| getElement(0): [CallExpr] call to sink(arg:)
7210+
# 111| getFunction(): [DeclRefExpr] sink(arg:)
7211+
# 111| getArgument(0): [Argument] arg: OpenExistentialExpr
7212+
# 111| getExpr(): [OpenExistentialExpr] OpenExistentialExpr
7213+
# 111| getSubExpr(): [CallExpr] call to source()
7214+
# 111| getFunction(): [MethodLookupExpr] .source()
7215+
# 111| getBase(): [OpaqueValueExpr] OpaqueValueExpr
7216+
# 111| getMethodRef(): [DeclRefExpr] source()
7217+
# 111| getExistential(): [DeclRefExpr] x
7218+
# 112| getElement(1): [CallExpr] call to sink(arg:)
7219+
# 112| getFunction(): [DeclRefExpr] sink(arg:)
7220+
# 112| getArgument(0): [Argument] arg: call to source()
7221+
# 112| getExpr(): [CallExpr] call to source()
7222+
# 112| getFunction(): [MethodLookupExpr] .source()
7223+
# 112| getBase(): [DeclRefExpr] y
7224+
# 112| getMethodRef(): [DeclRefExpr] source()
7225+
# 113| getElement(2): [CallExpr] call to sink(arg:)
7226+
# 113| getFunction(): [DeclRefExpr] sink(arg:)
7227+
# 113| getArgument(0): [Argument] arg: OpenExistentialExpr
7228+
# 113| getExpr(): [OpenExistentialExpr] OpenExistentialExpr
7229+
# 113| getSubExpr(): [CallExpr] call to source()
7230+
# 113| getFunction(): [MethodLookupExpr] .source()
7231+
# 113| getBase(): [OpaqueValueExpr] OpaqueValueExpr
7232+
# 113| getMethodRef(): [DeclRefExpr] source()
7233+
# 113| getExistential(): [CallExpr] call to getMyProtocol()
7234+
# 113| getFunction(): [DeclRefExpr] getMyProtocol()
7235+
# 114| getElement(3): [CallExpr] call to sink(arg:)
7236+
# 114| getFunction(): [DeclRefExpr] sink(arg:)
7237+
# 114| getArgument(0): [Argument] arg: call to source()
7238+
# 114| getExpr(): [CallExpr] call to source()
7239+
# 114| getFunction(): [MethodLookupExpr] .source()
7240+
# 114| getBase(): [CallExpr] call to getMyProtocolImpl()
7241+
# 114| getFunction(): [DeclRefExpr] getMyProtocolImpl()
7242+
# 114| getMethodRef(): [DeclRefExpr] source()

swift/ql/test/library-tests/ast/statements.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,24 @@ if #unavailable(macOS 42) {
9292
print(42)
9393
}
9494

95+
// ---
9596

97+
protocol MyProtocol {
98+
func source() -> Int
99+
}
100+
101+
class MyProcotolImpl : MyProtocol {
102+
func source() -> Int { return 0 }
103+
}
104+
105+
func getMyProtocol() -> MyProtocol { return MyProcotolImpl() }
106+
func getMyProtocolImpl() -> MyProcotolImpl { return MyProcotolImpl() }
107+
108+
func sink(arg: Int) { }
109+
110+
func testOpenExistentialExpr(x: MyProtocol, y: MyProcotolImpl) {
111+
sink(arg: x.source())
112+
sink(arg: y.source())
113+
sink(arg: getMyProtocol().source())
114+
sink(arg: getMyProtocolImpl().source())
115+
}

0 commit comments

Comments
 (0)