Skip to content

Commit df2c197

Browse files
committed
Swift: Add CFG trees for local declarations and accept test changes.
1 parent b715a6b commit df2c197

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,14 @@ module Decls {
884884
)
885885
}
886886
}
887+
888+
private class AbstractFunctionDeclTree extends AstLeafTree {
889+
override AbstractFunctionDecl ast;
890+
}
891+
892+
private class TypeDeclTree extends AstLeafTree {
893+
override TypeDecl ast;
894+
}
887895
}
888896

889897
module Exprs {

swift/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ cfg.swift:
357357
# 46| ClosureExpr
358358
#-----| -> ReturnStmt
359359

360+
# 51| enter ConcreteFuncDecl
361+
#-----| -> ConcreteFuncDecl
362+
363+
# 51| exit ConcreteFuncDecl
364+
365+
# 51| exit ConcreteFuncDecl (normal)
366+
#-----| -> exit ConcreteFuncDecl
367+
368+
# 52| ConcreteFuncDecl
369+
#-----| -> DeclRefExpr
370+
360371
# 52| enter ConcreteFuncDecl
361372
#-----| -> DeclRefExpr
362373

@@ -387,6 +398,12 @@ cfg.swift:
387398
# 53| DeclRefExpr
388399
#-----| -> BinaryExpr
389400

401+
# 55| ReturnStmt
402+
#-----| return -> exit ConcreteFuncDecl (normal)
403+
404+
# 55| DeclRefExpr
405+
#-----| -> ReturnStmt
406+
390407
# 58| enter ConcreteFuncDecl
391408
#-----| -> ClosureExpr
392409

@@ -611,17 +628,26 @@ cfg.swift:
611628
# 81| enter ConcreteFuncDecl
612629
#-----| -> NamedPattern
613630

631+
# 81| exit ConcreteFuncDecl
632+
633+
# 81| exit ConcreteFuncDecl (normal)
634+
#-----| -> exit ConcreteFuncDecl
635+
614636
# 82| PatternBindingDecl
615637
#-----| -> ConcreteVarDecl
616638

617639
# 82| ConcreteVarDecl
640+
#-----| -> ConcreteFuncDecl
618641

619642
# 82| NamedPattern
620643
#-----| -> IntegerLiteralExpr
621644

622645
# 82| IntegerLiteralExpr
623646
#-----| -> PatternBindingDecl
624647

648+
# 84| ConcreteFuncDecl
649+
#-----| -> ConcreteFuncDecl
650+
625651
# 84| enter ConcreteFuncDecl
626652
#-----| -> DeclRefExpr
627653

@@ -658,6 +684,9 @@ cfg.swift:
658684
# 85| IntegerLiteralExpr
659685
#-----| -> BinaryExpr
660686

687+
# 88| ConcreteFuncDecl
688+
#-----| -> DeclRefExpr
689+
661690
# 88| enter ConcreteFuncDecl
662691
#-----| -> DeclRefExpr
663692

@@ -675,6 +704,81 @@ cfg.swift:
675704
# 89| NilLiteralExpr
676705
#-----| -> AssignExpr
677706

707+
# 92| DeclRefExpr
708+
#-----| -> DeclRefExpr
709+
710+
# 92| CallExpr
711+
#-----| exception -> exit ConcreteFuncDecl (normal)
712+
#-----| -> NamedPattern
713+
714+
# 92| InOutExpr
715+
#-----| -> CallExpr
716+
717+
# 92| DeclRefExpr
718+
#-----| -> InOutExpr
719+
720+
# 93| PatternBindingDecl
721+
#-----| -> ConcreteVarDecl
722+
723+
# 93| ConcreteVarDecl
724+
#-----| -> DeclRefExpr
725+
726+
# 93| NamedPattern
727+
#-----| -> TypedPattern
728+
729+
# 93| TypedPattern
730+
#-----| -> IntegerLiteralExpr
731+
732+
# 93| InjectIntoOptionalExpr
733+
#-----| -> PatternBindingDecl
734+
735+
# 93| IntegerLiteralExpr
736+
#-----| -> InjectIntoOptionalExpr
737+
738+
# 94| DeclRefExpr
739+
#-----| -> DeclRefExpr
740+
741+
# 94| CallExpr
742+
#-----| exception -> exit ConcreteFuncDecl (normal)
743+
#-----| -> DeclRefExpr
744+
745+
# 94| InOutExpr
746+
#-----| -> CallExpr
747+
748+
# 94| DeclRefExpr
749+
#-----| -> InOutExpr
750+
751+
# 95| ReturnStmt
752+
#-----| return -> exit ConcreteFuncDecl (normal)
753+
754+
# 95| DeclRefExpr
755+
#-----| -> LoadExpr
756+
757+
# 95| LoadExpr
758+
#-----| -> DeclRefExpr
759+
760+
# 95| BinaryExpr
761+
#-----| -> ReturnStmt
762+
763+
# 95| DeclRefExpr
764+
#-----| -> TypeExpr
765+
766+
# 95| DotSyntaxCallExpr
767+
#-----| exception -> exit ConcreteFuncDecl (normal)
768+
#-----| -> DeclRefExpr
769+
770+
# 95| TypeExpr
771+
#-----| -> DotSyntaxCallExpr
772+
773+
# 95| DeclRefExpr
774+
#-----| -> LoadExpr
775+
776+
# 95| LoadExpr
777+
#-----| -> ForceValueExpr
778+
779+
# 95| ForceValueExpr
780+
#-----| -> BinaryExpr
781+
678782
# 99| enter AccessorDecl
679783

680784
# 99| exit AccessorDecl
@@ -4786,6 +4890,17 @@ cfg.swift:
47864890
# 405| DeclRefExpr
47874891
#-----| -> TupleExpr
47884892

4893+
# 408| enter ConcreteFuncDecl
4894+
#-----| -> ClassDecl
4895+
4896+
# 408| exit ConcreteFuncDecl
4897+
4898+
# 408| exit ConcreteFuncDecl (normal)
4899+
#-----| -> exit ConcreteFuncDecl
4900+
4901+
# 409| ClassDecl
4902+
#-----| -> StructDecl
4903+
47894904
# 410| TBD (YieldStmt)
47904905
#-----| -> exit AccessorDecl (normal)
47914906

@@ -4834,6 +4949,9 @@ cfg.swift:
48344949
# 413| ReturnStmt
48354950
#-----| return -> exit ConstructorDecl (normal)
48364951

4952+
# 416| StructDecl
4953+
#-----| -> EnumDecl
4954+
48374955
# 417| TBD (YieldStmt)
48384956
#-----| -> exit AccessorDecl (normal)
48394957

@@ -4881,3 +4999,24 @@ cfg.swift:
48814999

48825000
# 420| ReturnStmt
48835001
#-----| return -> exit ConstructorDecl (normal)
5002+
5003+
# 423| EnumDecl
5004+
#-----| -> NamedPattern
5005+
5006+
# 428| PatternBindingDecl
5007+
#-----| -> ConcreteVarDecl
5008+
5009+
# 428| ConcreteVarDecl
5010+
#-----| -> IntegerLiteralExpr
5011+
5012+
# 428| NamedPattern
5013+
#-----| -> TypedPattern
5014+
5015+
# 428| TypedPattern
5016+
#-----| -> PatternBindingDecl
5017+
5018+
# 442| ReturnStmt
5019+
#-----| return -> exit ConcreteFuncDecl (normal)
5020+
5021+
# 442| IntegerLiteralExpr
5022+
#-----| -> ReturnStmt

0 commit comments

Comments
 (0)