@@ -5,6 +5,7 @@ private import codeql_ql.ast.internal.Predicate
5
5
import codeql_ql.ast.internal.Type
6
6
private import codeql_ql.ast.internal.Variable
7
7
private import codeql_ql.ast.internal.Builtins
8
+ private import internal.AstMocks as Mocks
8
9
9
10
bindingset [ name]
10
11
private string directMember ( string name ) { result = name + "()" }
@@ -501,11 +502,11 @@ class PredicateExpr extends TPredicateExpr, AstNode {
501
502
* A classless predicate.
502
503
*/
503
504
class ClasslessPredicate extends TClasslessPredicate , Predicate , ModuleDeclaration {
504
- QL :: ClasslessPredicate pred ;
505
+ Mocks :: ClasslessPredicateOrMock pred ;
505
506
506
507
ClasslessPredicate ( ) { this = TClasslessPredicate ( pred ) }
507
508
508
- override Location getLocation ( ) { result = pred .getName ( ) .getLocation ( ) }
509
+ override Location getLocation ( ) { result = pred .asLeft ( ) . getName ( ) .getLocation ( ) }
509
510
510
511
/**
511
512
* Gets the aliased value if this predicate is an alias
@@ -514,25 +515,39 @@ class ClasslessPredicate extends TClasslessPredicate, Predicate, ModuleDeclarati
514
515
*/
515
516
final AstNode getAlias ( ) {
516
517
exists ( QL:: PredicateAliasBody alias |
517
- alias .getParent ( ) = pred and
518
+ alias .getParent ( ) = pred . asLeft ( ) and
518
519
toQL ( result ) .getParent ( ) = alias
519
520
)
520
521
or
521
- toQL ( result ) = pred .getChild ( _) .( QL:: HigherOrderTerm )
522
+ toQL ( result ) = pred .asLeft ( ) . getChild ( _) .( QL:: HigherOrderTerm )
522
523
}
523
524
524
525
override string getAPrimaryQlClass ( ) { result = "ClasslessPredicate" }
525
526
526
- override Formula getBody ( ) { toQL ( result ) = pred .getChild ( _) .( QL:: Body ) .getChild ( ) }
527
+ override Formula getBody ( ) { toQL ( result ) = pred .asLeft ( ) . getChild ( _) .( QL:: Body ) .getChild ( ) }
527
528
528
- override string getName ( ) { result = pred .getName ( ) .getValue ( ) }
529
+ override string getName ( ) {
530
+ result = pred .asLeft ( ) .getName ( ) .getValue ( )
531
+ or
532
+ result = pred .asRight ( ) .getName ( )
533
+ }
529
534
530
535
override VarDecl getParameter ( int i ) {
531
536
toQL ( result ) =
532
- rank [ i + 1 ] ( QL:: VarDecl decl , int index | decl = pred .getChild ( index ) | decl order by index )
537
+ rank [ i + 1 ] ( QL:: VarDecl decl , int index |
538
+ decl = pred .asLeft ( ) .getChild ( index )
539
+ |
540
+ decl order by index
541
+ )
542
+ or
543
+ toMock ( result ) = pred .asRight ( ) .getParameter ( i )
533
544
}
534
545
535
- override TypeExpr getReturnTypeExpr ( ) { toQL ( result ) = pred .getReturnType ( ) }
546
+ override TypeExpr getReturnTypeExpr ( ) {
547
+ toQL ( result ) = pred .asLeft ( ) .getReturnType ( )
548
+ or
549
+ toMock ( result ) = pred .asRight ( ) .getReturnTypeExpr ( )
550
+ }
536
551
537
552
override AstNode getAChild ( string pred_name ) {
538
553
result = Predicate .super .getAChild ( pred_name )
@@ -651,11 +666,15 @@ class VarDef extends TVarDef, AstNode {
651
666
* A variable declaration, with a type and a name.
652
667
*/
653
668
class VarDecl extends TVarDecl , VarDef , Declaration {
654
- QL :: VarDecl var ;
669
+ Mocks :: VarDeclOrMock var ;
655
670
656
671
VarDecl ( ) { this = TVarDecl ( var ) }
657
672
658
- override string getName ( ) { result = var .getChild ( 1 ) .( QL:: VarName ) .getChild ( ) .getValue ( ) }
673
+ override string getName ( ) {
674
+ result = var .asLeft ( ) .getChild ( 1 ) .( QL:: VarName ) .getChild ( ) .getValue ( )
675
+ or
676
+ result = var .asRight ( ) .getName ( )
677
+ }
659
678
660
679
override Type getType ( ) { result = this .getTypeExpr ( ) .getResolvedType ( ) }
661
680
@@ -664,14 +683,18 @@ class VarDecl extends TVarDecl, VarDef, Declaration {
664
683
/**
665
684
* Gets the type part of this variable declaration.
666
685
*/
667
- TypeExpr getTypeExpr ( ) { toQL ( result ) = var .getChild ( 0 ) }
686
+ TypeExpr getTypeExpr ( ) {
687
+ toQL ( result ) = var .asLeft ( ) .getChild ( 0 )
688
+ or
689
+ toMock ( result ) = var .asRight ( ) .getType ( )
690
+ }
668
691
669
692
/**
670
693
* Holds if this variable declaration is a private field on a class.
671
694
*/
672
695
predicate isPrivate ( ) {
673
696
exists ( QL:: ClassMember member |
674
- var = member .getChild ( _) .( QL:: Field ) .getChild ( ) and
697
+ var . asLeft ( ) = member .getChild ( _) .( QL:: Field ) .getChild ( ) and
675
698
member .getAFieldOrChild ( ) .( QL:: Annotation ) .getName ( ) .getValue ( ) = "private"
676
699
)
677
700
}
@@ -725,7 +748,7 @@ class FieldDecl extends TFieldDecl, AstNode {
725
748
* A type reference, such as `DataFlow::Node`.
726
749
*/
727
750
class TypeExpr extends TType , TypeRef {
728
- QL :: TypeExpr type ;
751
+ Mocks :: TypeExprOrMock type ;
729
752
730
753
TypeExpr ( ) { this = TType ( type ) }
731
754
@@ -738,28 +761,30 @@ class TypeExpr extends TType, TypeRef {
738
761
* or db-types such as `@locateable`.
739
762
*/
740
763
string getClassName ( ) {
741
- result = type .getName ( ) .getValue ( )
764
+ result = type .asLeft ( ) . getName ( ) .getValue ( )
742
765
or
743
- result = type .getChild ( ) .( QL:: PrimitiveType ) .getValue ( )
766
+ result = type .asLeft ( ) . getChild ( ) .( QL:: PrimitiveType ) .getValue ( )
744
767
or
745
- result = type .getChild ( ) .( QL:: Dbtype ) .getValue ( )
768
+ result = type .asLeft ( ) .getChild ( ) .( QL:: Dbtype ) .getValue ( )
769
+ or
770
+ result = type .asRight ( ) .getClassName ( )
746
771
}
747
772
748
773
/**
749
774
* Holds if this type is a primitive such as `string` or `int`.
750
775
*/
751
- predicate isPrimitive ( ) { type .getChild ( ) instanceof QL:: PrimitiveType }
776
+ predicate isPrimitive ( ) { type .asLeft ( ) . getChild ( ) instanceof QL:: PrimitiveType }
752
777
753
778
/**
754
779
* Holds if this type is a db-type.
755
780
*/
756
- predicate isDBType ( ) { type .getChild ( ) instanceof QL:: Dbtype }
781
+ predicate isDBType ( ) { type .asLeft ( ) . getChild ( ) instanceof QL:: Dbtype }
757
782
758
783
/**
759
784
* Gets the module of the type, if it exists.
760
785
* E.g. `DataFlow` in `DataFlow::Node`.
761
786
*/
762
- ModuleExpr getModule ( ) { toQL ( result ) = type .getQualifier ( ) }
787
+ ModuleExpr getModule ( ) { toQL ( result ) = type .asLeft ( ) . getQualifier ( ) }
763
788
764
789
/** Gets the type that this type reference refers to. */
765
790
override Type getResolvedType ( ) {
@@ -781,34 +806,44 @@ class TypeExpr extends TType, TypeRef {
781
806
* A QL module.
782
807
*/
783
808
class Module extends TModule , ModuleDeclaration {
784
- QL :: Module mod ;
809
+ Mocks :: ModuleOrMock mod ;
785
810
786
811
Module ( ) { this = TModule ( mod ) }
787
812
788
- override Location getLocation ( ) { result = mod .getName ( ) .getLocation ( ) }
813
+ override Location getLocation ( ) { result = mod .asLeft ( ) . getName ( ) .getLocation ( ) }
789
814
790
815
override string getAPrimaryQlClass ( ) { result = "Module" }
791
816
792
- override string getName ( ) { result = mod .getName ( ) .getChild ( ) .getValue ( ) }
817
+ override string getName ( ) {
818
+ result = mod .asLeft ( ) .getName ( ) .getChild ( ) .getValue ( )
819
+ or
820
+ result = mod .asRight ( ) .getName ( )
821
+ }
793
822
794
823
/**
795
824
* Gets a member of the module.
796
825
*/
797
- AstNode getAMember ( ) { toQL ( result ) = mod . getChild ( _ ) . ( QL :: ModuleMember ) . getChild ( _) }
826
+ AstNode getAMember ( ) { result = this . getMember ( _) }
798
827
799
- AstNode getMember ( int i ) { toQL ( result ) = mod .getChild ( i ) .( QL:: ModuleMember ) .getChild ( _) }
828
+ AstNode getMember ( int i ) {
829
+ toQL ( result ) = mod .asLeft ( ) .getChild ( i ) .( QL:: ModuleMember ) .getChild ( _)
830
+ or
831
+ toMock ( result ) = mod .asRight ( ) .getMember ( i )
832
+ }
800
833
801
834
QLDoc getQLDocFor ( AstNode m ) {
802
835
exists ( int i | result = this .getMember ( i ) and m = this .getMember ( i + 1 ) )
803
836
}
804
837
805
838
/** Gets a ref to the module that this module implements. */
806
839
TypeRef getImplements ( int i ) {
807
- exists ( SignatureExpr sig | sig .toQL ( ) = mod .getImplements ( i ) | result = sig .asType ( ) )
840
+ exists ( SignatureExpr sig | sig .toQL ( ) = mod .asLeft ( ) . getImplements ( i ) | result = sig .asType ( ) )
808
841
}
809
842
810
843
/** Gets the module expression that this module is an alias for, if any. */
811
- ModuleExpr getAlias ( ) { toQL ( result ) = mod .getAFieldOrChild ( ) .( QL:: ModuleAliasBody ) .getChild ( ) }
844
+ ModuleExpr getAlias ( ) {
845
+ toQL ( result ) = mod .asLeft ( ) .getAFieldOrChild ( ) .( QL:: ModuleAliasBody ) .getChild ( )
846
+ }
812
847
813
848
override AstNode getAChild ( string pred ) {
814
849
result = super .getAChild ( pred )
@@ -825,10 +860,12 @@ class Module extends TModule, ModuleDeclaration {
825
860
/** Holds if the `i`th parameter of this module has `name` and type `sig`. */
826
861
predicate hasParameter ( int i , string name , SignatureExpr sig ) {
827
862
exists ( QL:: ModuleParam param |
828
- param = mod .getParameter ( i ) and
863
+ param = mod .asLeft ( ) . getParameter ( i ) and
829
864
name = param .getParameter ( ) .getValue ( ) and
830
865
sig .toQL ( ) = param .getSignature ( )
831
866
)
867
+ or
868
+ mod .asRight ( ) .hasTypeParam ( i , toMock ( sig ) , name )
832
869
}
833
870
}
834
871
@@ -866,22 +903,26 @@ class TypeDeclaration extends TTypeDeclaration, Declaration { }
866
903
* A QL class.
867
904
*/
868
905
class Class extends TClass , TypeDeclaration , ModuleDeclaration {
869
- QL :: Dataclass cls ;
906
+ Mocks :: ClassOrMock cls ;
870
907
871
908
Class ( ) { this = TClass ( cls ) }
872
909
873
- override Location getLocation ( ) { result = cls .getName ( ) .getLocation ( ) }
910
+ override Location getLocation ( ) { result = cls .asLeft ( ) . getName ( ) .getLocation ( ) }
874
911
875
912
override string getAPrimaryQlClass ( ) { result = "Class" }
876
913
877
- override string getName ( ) { result = cls .getName ( ) .getValue ( ) }
914
+ override string getName ( ) {
915
+ result = cls .asLeft ( ) .getName ( ) .getValue ( )
916
+ or
917
+ result = cls .asRight ( ) .getName ( )
918
+ }
878
919
879
920
/**
880
921
* Gets the characteristic predicate for this class.
881
922
*/
882
- CharPred getCharPred ( ) { toQL ( result ) = cls .getChild ( _) .( QL:: ClassMember ) .getChild ( _) }
923
+ CharPred getCharPred ( ) { toQL ( result ) = cls .asLeft ( ) . getChild ( _) .( QL:: ClassMember ) .getChild ( _) }
883
924
884
- AstNode getMember ( int i ) { toQL ( result ) = cls .getChild ( i ) .( QL:: ClassMember ) .getChild ( _) }
925
+ AstNode getMember ( int i ) { toQL ( result ) = cls .asLeft ( ) . getChild ( i ) .( QL:: ClassMember ) .getChild ( _) }
885
926
886
927
QLDoc getQLDocFor ( AstNode m ) {
887
928
exists ( int i | result = this .getMember ( i ) and m = this .getMember ( i + 1 ) )
@@ -891,7 +932,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
891
932
* Gets a predicate in this class.
892
933
*/
893
934
ClassPredicate getAClassPredicate ( ) {
894
- toQL ( result ) = cls .getChild ( _) .( QL:: ClassMember ) .getChild ( _)
935
+ toQL ( result ) = cls .asLeft ( ) . getChild ( _) .( QL:: ClassMember ) .getChild ( _)
895
936
}
896
937
897
938
/**
@@ -910,18 +951,20 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
910
951
/**
911
952
* Gets a super-type referenced in the `extends` part of the class declaration.
912
953
*/
913
- TypeExpr getASuperType ( ) { toQL ( result ) = cls .getExtends ( _) }
954
+ TypeExpr getASuperType ( ) { toQL ( result ) = cls .asLeft ( ) . getExtends ( _) }
914
955
915
956
/**
916
957
* Gets a type referenced in the `instanceof` part of the class declaration.
917
958
*/
918
- TypeExpr getAnInstanceofType ( ) { toQL ( result ) = cls .getInstanceof ( _) }
959
+ TypeExpr getAnInstanceofType ( ) { toQL ( result ) = cls .asLeft ( ) . getInstanceof ( _) }
919
960
920
961
/** Gets the type that this class is defined to be an alias of. */
921
- TypeExpr getAliasType ( ) { toQL ( result ) = cls .getChild ( _) .( QL:: TypeAliasBody ) .getChild ( ) }
962
+ TypeExpr getAliasType ( ) { toQL ( result ) = cls .asLeft ( ) . getChild ( _) .( QL:: TypeAliasBody ) .getChild ( ) }
922
963
923
964
/** Gets the type of one of the members that this class is defined to be a union of. */
924
- TypeExpr getUnionMember ( ) { toQL ( result ) = cls .getChild ( _) .( QL:: TypeUnionBody ) .getChild ( _) }
965
+ TypeExpr getUnionMember ( ) {
966
+ toQL ( result ) = cls .asLeft ( ) .getChild ( _) .( QL:: TypeUnionBody ) .getChild ( _)
967
+ }
925
968
926
969
/** Gets the class type defined by this class declaration. */
927
970
Type getType ( ) { result .getDeclaration ( ) = this }
@@ -2383,18 +2426,20 @@ class ModuleExpr extends TModuleExpr, TypeRef {
2383
2426
2384
2427
/** A signature expression, either a `PredicateExpr`, a `TypeExpr`, or a `ModuleExpr`. */
2385
2428
class SignatureExpr extends TSignatureExpr , AstNode {
2386
- QL :: SignatureExpr sig ;
2429
+ Mocks :: SignatureExprOrMock sig ;
2387
2430
2388
2431
SignatureExpr ( ) {
2389
- toQL ( this ) = sig .getPredicate ( )
2432
+ toQL ( this ) = sig .asLeft ( ) .getPredicate ( )
2433
+ or
2434
+ toQL ( this ) = sig .asLeft ( ) .getTypeExpr ( )
2390
2435
or
2391
- toQL ( this ) = sig .getTypeExpr ( )
2436
+ toMock ( this ) = sig .asRight ( )
2392
2437
or
2393
- toQL ( this ) = sig .getModExpr ( )
2438
+ toQL ( this ) = sig .asLeft ( ) . getModExpr ( )
2394
2439
}
2395
2440
2396
2441
/** Gets the generated AST node that contains this signature expression. */
2397
- QL:: SignatureExpr toQL ( ) { result = sig }
2442
+ QL:: SignatureExpr toQL ( ) { result = sig . asLeft ( ) }
2398
2443
2399
2444
/** Gets this signature expression if it represents a predicate expression. */
2400
2445
PredicateExpr asPredicate ( ) { result = this }
0 commit comments