import { ClassNode , ExecutionScopeNode , FunctionNode , LambdaNode , ListComprehensionNode , ModuleNode , ParseNode , ParseNodeType , StringNode , } from '../parser/parseNodes' ; import { AnalyzerFileInfo } from './analyzerFileInfo' ; import { FlowFlags , FlowNode } from './codeFlowTypes' ; import { Declaration } from './declaration' ; import { ImportResult } from './importResult' ; import { Scope } from './scope' ; export interface DunderAllInfo { names : string [ ] ; stringNodes : StringNode [ ] ; usesUnsupportedDunderAllForm : boolean ; } interface AnalyzerNodeInfo { importInfo ? : ImportResult ; scope ? : Scope ; declaration ? : Declaration ; flowNode ? : FlowNode ; afterFlowNode ? : FlowNode ; fileInfo ? : AnalyzerFileInfo ; codeFlowExpressions ? : Set < string > ; codeFlowComplexity ? : number ; dunderAllInfo ? : DunderAllInfo | undefined ; } export type ScopedNode = ModuleNode | ClassNode | FunctionNode | LambdaNode | ListComprehensionNode ; export function cleanNodeAnalysisInfo ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; delete analyzerNode . scope ; delete analyzerNode . declaration ; delete analyzerNode . flowNode ; delete analyzerNode . afterFlowNode ; delete analyzerNode . fileInfo ; delete analyzerNode . codeFlowExpressions ; delete analyzerNode . codeFlowComplexity ; delete analyzerNode . dunderAllInfo ; } export function getImportInfo ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . importInfo ; } export function setImportInfo ( node , importInfo ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . importInfo = importInfo ; } export function getScope ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . scope ; } export function setScope ( node , scope ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . scope = scope ; } export function getDeclaration ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . declaration ; } export function setDeclaration ( node , decl ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . declaration = decl ; } export function getFlowNode ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . flowNode ; } export function setFlowNode ( node , flowNode ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . flowNode = flowNode ; } export function getAfterFlowNode ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . afterFlowNode ; } export function setAfterFlowNode ( node , flowNode ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . afterFlowNode = flowNode ; } export function getFileInfo ( node ) { while ( node . nodeType !== ParseNodeType . Module ) { node = node . parent ! ; } const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . fileInfo ! ; } export function setFileInfo ( node , fileInfo ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . fileInfo = fileInfo ; } export function getCodeFlowExpressions ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . codeFlowExpressions ; } export function setCodeFlowExpressions ( node , expressions ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . codeFlowExpressions = expressions ; } export function getCodeFlowComplexity ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . codeFlowComplexity ?? 0 ; } export function setCodeFlowComplexity ( node , complexity ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . codeFlowComplexity = complexity ; } export function getDunderAllInfo ( node ) { const analyzerNode = node as AnalyzerNodeInfo ; return analyzerNode . dunderAllInfo ; } export function setDunderAllInfo ( node , names ) { const analyzerNode = node as AnalyzerNodeInfo ; analyzerNode . dunderAllInfo = names ; } export function isCodeUnreachable ( node ) { let curNode = node ; while ( curNode ) { const flowNode = getFlowNode ( curNode ) ; if ( flowNode ) { return ! ! ( flowNode . flags & FlowFlags . Unreachable ) ; } curNode = curNode . parent ; } return false ; }