Perform pass 1 of semantic analysis, which happens immediately after parsing. This pass can't assume that any other modules have been processed yet.
(self)
| 3303 | ) |
| 3304 | |
| 3305 | def semantic_analysis_pass1(self) -> None: |
| 3306 | """Perform pass 1 of semantic analysis, which happens immediately after parsing. |
| 3307 | |
| 3308 | This pass can't assume that any other modules have been processed yet. |
| 3309 | """ |
| 3310 | options = self.options |
| 3311 | assert self.tree is not None |
| 3312 | |
| 3313 | t0 = time_ref() |
| 3314 | |
| 3315 | # Do the first pass of semantic analysis: analyze the reachability |
| 3316 | # of blocks and import statements. We must do this before |
| 3317 | # processing imports, since this may mark some import statements as |
| 3318 | # unreachable. |
| 3319 | # |
| 3320 | # TODO: This should not be considered as a semantic analysis |
| 3321 | # pass -- it's an independent pass. |
| 3322 | if not options.native_parser or not self.manager.fscache.exists( |
| 3323 | self.xpath, real_only=True |
| 3324 | ): |
| 3325 | analyzer = SemanticAnalyzerPreAnalysis() |
| 3326 | with self.wrap_context(): |
| 3327 | analyzer.visit_file(self.tree, self.xpath, self.id, options) |
| 3328 | # TODO: Do this while constructing the AST? |
| 3329 | self.tree.names = SymbolTable() |
| 3330 | if not self.tree.is_stub: |
| 3331 | if not self.options.allow_redefinition: |
| 3332 | # Perform some low-key variable renaming when assignments can't |
| 3333 | # widen inferred types |
| 3334 | self.tree.accept(LimitedVariableRenameVisitor()) |
| 3335 | if options.allow_redefinition_old: |
| 3336 | # Perform more renaming across the AST to allow variable redefinitions |
| 3337 | self.tree.accept(VariableRenameVisitor()) |
| 3338 | self.time_spent_us += time_spent_us(t0) |
| 3339 | |
| 3340 | def add_dependency(self, dep: str) -> None: |
| 3341 | if dep not in self.dependencies_set: |
no test coverage detected