11import * as ast from './python-parser' ;
22import { ControlFlowGraph } from './control-flow' ;
33import { Set } from './set' ;
4- import { JsonSpecs , PythonType } from './specs' ;
5- declare class DefUse {
4+ import { Spec } from './specs' ;
5+ import { SymbolTable } from './symbol-table' ;
6+ export interface Dataflow {
7+ fromNode : ast . SyntaxNode ;
8+ toNode : ast . SyntaxNode ;
9+ fromRef ?: Ref ;
10+ toRef ?: Ref ;
11+ }
12+ export declare enum ReferenceType {
13+ DEFINITION = "DEFINITION" ,
14+ UPDATE = "UPDATE" ,
15+ USE = "USE"
16+ }
17+ export interface Ref {
18+ level : ReferenceType ;
19+ name : string ;
20+ location : ast . Location ;
21+ node : ast . SyntaxNode ;
22+ }
23+ export declare class RefSet extends Set < Ref > {
24+ constructor ( ...items : Ref [ ] ) ;
25+ }
26+ declare class DefUseDelta {
627 DEFINITION : RefSet ;
728 UPDATE : RefSet ;
829 USE : RefSet ;
9- constructor ( DEFINITION ?: RefSet , UPDATE ?: RefSet , USE ?: RefSet ) ;
10- readonly defs : Set < Ref > ;
11- readonly uses : Set < Ref > ;
30+ leaks : LeakInfo [ ] ;
31+ constructor ( DEFINITION ?: RefSet , UPDATE ?: RefSet , USE ?: RefSet , leaks ?: LeakInfo [ ] ) ;
32+ get uses ( ) : Set < Ref > ;
33+ createFlowsFrom ( fromSet : DefUse ) : [ Set < Dataflow > , Set < Ref > ] ;
34+ }
35+ declare class DefUse {
36+ private DEFINITION ;
37+ private UPDATE ;
38+ private USE ;
39+ leaks : LeakInfo [ ] ;
40+ constructor ( DEFINITION ?: RefSet , UPDATE ?: RefSet , USE ?: RefSet , leaks ?: LeakInfo [ ] ) ;
41+ get defs ( ) : Set < Ref > ;
1242 union ( that : DefUse ) : DefUse ;
13- update ( newRefs : DefUse ) : void ;
43+ update ( newRefs : DefUseDelta ) : void ;
1444 equals ( that : DefUse ) : boolean ;
15- createFlowsFrom ( fromSet : DefUse ) : [ Set < Dataflow > , Set < Ref > ] ;
1645}
1746/**
1847 * Use a shared dataflow analyzer object for all dataflow analysis / querying for defs and uses.
1948 * It caches defs and uses for each statement, which can save time.
2049 * For caching to work, statements must be annotated with a cell's ID and execution count.
2150 */
2251export declare class DataflowAnalyzer {
23- constructor ( moduleMap ?: JsonSpecs ) ;
24- getDefUseForStatement ( statement : ast . SyntaxNode , defsForMethodResolution : RefSet ) : DefUse ;
52+ constructor ( moduleMap ?: Spec , symbolTable ?: SymbolTable ) ;
53+ getDefUseForStatement ( statement : ast . SyntaxNode , incomingDefs : RefSet , incomingLeaks : LeakInfo [ ] ) : DefUseDelta ;
2554 analyze ( cfg : ControlFlowGraph , refSet ?: RefSet ) : DataflowAnalysisResult ;
26- getDefs ( statement : ast . SyntaxNode , defsForMethodResolution : RefSet ) : RefSet ;
55+ getDefs ( statement : ast . SyntaxNode , stateLeaks : LeakInfo [ ] ) : {
56+ defs : RefSet ;
57+ leaks : LeakInfo [ ] ;
58+ } ;
2759 private getClassDefs ;
2860 private getFuncDefs ;
2961 private getAssignDefs ;
@@ -35,41 +67,15 @@ export declare class DataflowAnalyzer {
3567 private getClassDeclUses ;
3668 private getFuncDeclUses ;
3769 private getAssignUses ;
38- private _symbolTable ;
70+ private symbolTable ;
3971 private _defUsesCache ;
4072}
41- export interface Dataflow {
42- fromNode : ast . SyntaxNode ;
43- toNode : ast . SyntaxNode ;
44- fromRef ?: Ref ;
45- toRef ?: Ref ;
46- }
47- export declare enum ReferenceType {
48- DEFINITION = "DEFINITION" ,
49- UPDATE = "UPDATE" ,
50- USE = "USE"
51- }
52- export declare enum SymbolType {
53- VARIABLE = 0 ,
54- CLASS = 1 ,
55- FUNCTION = 2 ,
56- IMPORT = 3 ,
57- MUTATION = 4 ,
58- MAGIC = 5
59- }
60- export interface Ref {
61- type : SymbolType ;
62- level : ReferenceType ;
63- name : string ;
64- inferredType ?: PythonType ;
65- location : ast . Location ;
66- node : ast . SyntaxNode ;
67- }
68- export declare class RefSet extends Set < Ref > {
69- constructor ( ...items : Ref [ ] ) ;
70- }
7173export declare function sameLocation ( loc1 : ast . Location , loc2 : ast . Location ) : boolean ;
7274export declare const GlobalSyntheticVariable = "$global" ;
75+ interface LeakInfo {
76+ innerName : string ;
77+ outerName : string ;
78+ }
7379export declare type DataflowAnalysisResult = {
7480 dataflows : Set < Dataflow > ;
7581 undefinedRefs : RefSet ;
0 commit comments