* 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)
| 9125 | * routine declares above it, as the routine's body sees them all. |
| 9126 | */ |
| 9127 | private walkPascalRoutine(node: SyntaxNode, routineId: string, classQn: string | null, routine: string, qualifiedName: () => string): void { |
| 9128 | const locals = this.pascalRoutineLocals(node, true); |
| 9129 | this.pascalScopes.push({ locals, classQn, routine, startLine: node.startPosition.row + 1 }); |
| 9130 | this.nodeStack.push(routineId); |
| 9131 | let block: SyntaxNode | null = null; |
| 9132 | const misplaced: SyntaxNode[] = []; |
| 9133 | const broken = node.hasError; |
| 9134 | for (const c of node.namedChildren) { |
| 9135 | if (c.type === 'declVars' || c.type === 'declConsts') { |
| 9136 | for (const decl of c.namedChildren) this.declarePascalLocal(locals, decl); |
| 9137 | } else if (c.type === 'defProc') { |
| 9138 | // A nested routine comes before the body. Where the routine's tree |
| 9139 | // has errors, its parse can swallow the unit's routines after it, |
| 9140 | // which start their lines where it does: those are the unit's. |
| 9141 | if (block || (broken && c.startPosition.column <= node.startPosition.column)) misplaced.push(c); |
| 9142 | else this.extractPascalNestedRoutine(c, classQn, qualifiedName()); |
| 9143 | } else if (c.type === 'block' && !block) { |
| 9144 | // The first: `{$IFDEF}`s around two bodies leave a second. |
| 9145 | block = c; |
| 9146 | } |
| 9147 | } |
| 9148 | if (block) this.visitPascalBlock(block); |
| 9149 | this.nodeStack.pop(); |
| 9150 | this.pascalScopes.pop(); |
| 9151 | for (const c of misplaced) this.extractPascalDefProc(c); |
| 9152 | } |
| 9153 | |
| 9154 | /** A routine nested in another (see walkPascalRoutine), under the qualified name of the one it is nested in. */ |
| 9155 | private extractPascalNestedRoutine(node: SyntaxNode, classQn: string | null, outerQualifiedName: string): void { |
no test coverage detected