@@ -388,14 +388,13 @@ module API {
388
388
// The `builtins` module should always be implicitly available
389
389
name = "builtins"
390
390
} or
391
- MkModuleExport ( Module mod ) or
392
391
/** A use of an API member at the node `nd`. */
393
392
MkUse ( DataFlow:: Node nd ) { use ( _, _, nd ) } or
394
393
MkDef ( DataFlow:: Node nd ) { rhs ( _, _, nd ) }
395
394
396
395
class TUse = MkModuleImport or MkUse ;
397
396
398
- class TDef = MkDef or MkModuleExport ;
397
+ class TDef = MkDef ;
399
398
400
399
/**
401
400
* Holds if the dotted module name `sub` refers to the `member` member of `base`.
@@ -455,12 +454,6 @@ module API {
455
454
*/
456
455
cached
457
456
predicate rhs ( TApiNode base , Label:: ApiLabel lbl , DataFlow:: Node rhs ) {
458
- exists ( Module mod , string prop |
459
- base = MkModuleExport ( mod ) and
460
- exports ( mod , prop , rhs ) and
461
- lbl = Label:: member ( prop )
462
- )
463
- or
464
457
exists ( DataFlow:: Node def , DataFlow:: LocalSourceNode pred |
465
458
rhs ( base , def ) and pred = trackDefNode ( def )
466
459
|
@@ -649,12 +642,7 @@ module API {
649
642
* Holds if `rhs` is the right-hand side of a definition of node `nd`.
650
643
*/
651
644
cached
652
- predicate rhs ( TApiNode nd , DataFlow:: Node rhs ) {
653
- // TODO: There are no "default" exports in python, right? E.g. in `import foo`, `foo` cannot be a function.
654
- // exists(string m | nd = MkModuleExport(m) | exports(m, rhs))
655
- // or
656
- nd = MkDef ( rhs )
657
- }
645
+ predicate rhs ( TApiNode nd , DataFlow:: Node rhs ) { nd = MkDef ( rhs ) }
658
646
659
647
/**
660
648
* Holds if there is an edge from `pred` to `succ` in the API graph that is labeled with `lbl`.
@@ -665,12 +653,9 @@ module API {
665
653
exists ( string m |
666
654
pred = MkRoot ( ) and
667
655
lbl = Label:: mod ( m ) and
656
+ succ = MkModuleImport ( m ) and
668
657
// Only allow undotted names to count as base modules.
669
658
not m .matches ( "%.%" )
670
- |
671
- succ = MkModuleImport ( m )
672
- or
673
- succ = MkModuleExport ( any ( Module mod | mod .getName ( ) = m and mod .isPackage ( ) ) )
674
659
)
675
660
or
676
661
/* Step from the dotted module name `foo.bar` to `foo.bar.baz` along an edge labeled `baz` */
@@ -685,14 +670,6 @@ module API {
685
670
succ = MkUse ( ref )
686
671
)
687
672
or
688
- exists ( Module parentMod , Module childMod , string edge |
689
- pred = MkModuleExport ( parentMod ) and
690
- succ = MkModuleExport ( childMod ) and
691
- // TODO: __init__.py shows up here, maybe add some shortcut. Example code: https://stackoverflow.com/questions/38927979/default-export-in-python-3
692
- parentMod .getSubModule ( edge ) = childMod and
693
- lbl = Label:: member ( edge )
694
- )
695
- or
696
673
exists ( DataFlow:: Node rhs |
697
674
rhs ( pred , lbl , rhs ) and
698
675
succ = MkDef ( rhs )
@@ -725,20 +702,14 @@ module API {
725
702
726
703
newtype TLabel =
727
704
MkLabelModule ( string mod ) {
728
- (
729
- exists ( Impl:: MkModuleImport ( mod ) )
730
- or
731
- exists ( Module m | exists ( Impl:: MkModuleExport ( m ) ) | mod = m .getName ( ) )
732
- ) and
705
+ exists ( Impl:: MkModuleImport ( mod ) ) and
733
706
not mod .matches ( "%.%" ) // only top level modules count as base modules
734
707
} or
735
708
MkLabelMember ( string member ) {
736
709
member = any ( DataFlow:: AttrRef pr ) .getAttributeName ( ) or
737
710
exists ( Builtins:: likelyBuiltin ( member ) ) or
738
711
ImportStar:: namePossiblyDefinedInImportStar ( _, member , _) or
739
712
Impl:: prefix_member ( _, member , _) or
740
- exists ( any ( Module mod ) .getSubModule ( member ) ) or
741
- exports ( _, member , _) or
742
713
member = any ( Dict d ) .getAnItem ( ) .( KeyValuePair ) .getKey ( ) .( StrConst ) .getS ( )
743
714
} or
744
715
MkLabelUnknownMember ( ) or
@@ -866,22 +837,3 @@ module API {
866
837
LabelAwait await ( ) { any ( ) }
867
838
}
868
839
}
869
-
870
- /** Holds if module `mod` exports `rhs` under the name `prop`. */
871
- private predicate exports ( Module mod , string prop , DataFlow:: Node rhs ) {
872
- exists ( Assign assign |
873
- assign = mod .getAStmt ( ) and
874
- rhs .asExpr ( ) = assign .getValue ( ) and
875
- exists ( Variable v | assign .defines ( v ) and prop = v .getId ( ) )
876
- )
877
- or
878
- // `from foo import *`, just forward directly.
879
- exists ( ImportStar star , Module subMod |
880
- star .getEnclosingModule ( ) = mod and
881
- mod .getPackage ( ) .getName ( ) + "." + star .getImportedModuleName ( ) = subMod .getName ( ) and
882
- exports ( subMod , prop , rhs )
883
- )
884
- // TODO: There should be a better way to do this, I'm just missing it.
885
- // TODO: named imports, which should probably be an edge, unless there is some way imports are just magically "handled".
886
- // TODO: use this predicate with __init__.py?
887
- }
0 commit comments