* A routine's declarations and body, walked for its calls with the routine * as their caller. A routine nested in it (`procedure Inner;` between its * header and `begin`) is a function of its own, qualified under it * (`TFoo::Bar::Inner`), whose calls are its own; it sees the names the *
(node: SyntaxNode, routineId: string, classQn: string | null, routine: string, qualifiedName: () => string)
| 9431 | * routine declares above it, as the routine's body sees them all. |
| 9432 | */ |
| 9433 | private walkPascalRoutine(node: SyntaxNode, routineId: string, classQn: string | null, routine: string, qualifiedName: () => string): void { |
| 9434 | const locals = this.pascalRoutineLocals(node, true); |
| 9435 | this.pascalScopes.push({ locals, classQn, routine, startLine: node.startPosition.row + 1 }); |
| 9436 | this.nodeStack.push(routineId); |
| 9437 | let block: SyntaxNode | null = null; |
| 9438 | const misplaced: SyntaxNode[] = []; |
| 9439 | const broken = node.hasError; |
| 9440 | for (const c of node.namedChildren) { |
| 9441 | if (c.type === 'declVars' || c.type === 'declConsts') { |
| 9442 | for (const decl of c.namedChildren) this.declarePascalLocal(locals, decl); |
| 9443 | } else if (c.type === 'defProc') { |
| 9444 | // A nested routine comes before the body. Where the routine's tree |
| 9445 | // has errors, its parse can swallow the unit's routines after it, |
| 9446 | // which start their lines where it does: those are the unit's. |
| 9447 | if (block || (broken && c.startPosition.column <= node.startPosition.column)) misplaced.push(c); |
| 9448 | else this.extractPascalNestedRoutine(c, classQn, qualifiedName()); |
| 9449 | } else if (c.type === 'block' && !block) { |
| 9450 | // The first: `{$IFDEF}`s around two bodies leave a second. |
| 9451 | block = c; |
| 9452 | } |
| 9453 | } |
| 9454 | if (block) this.visitPascalBlock(block); |
| 9455 | this.nodeStack.pop(); |
| 9456 | this.pascalScopes.pop(); |
| 9457 | for (const c of misplaced) this.extractPascalDefProc(c); |
| 9458 | } |
| 9459 | |
| 9460 | /** A routine nested in another (see walkPascalRoutine), under the qualified name of the one it is nested in. */ |
| 9461 | private extractPascalNestedRoutine(node: SyntaxNode, classQn: string | null, outerQualifiedName: string): void { |
no test coverage detected