Lexical scope linkage

The model of a program envisioned by this document is that programs have nested scopes. The outermost scope is module scope which encompasses all of the symbols not defined within any inner (lexical) scope. Symbols and types defined at one scoping level are visible to all scopes nested within it. Symbols and types defined at module scope are visible to all inner scopes.

The next level of scoping is "function" scope, which in turn contains lexical blocks (including other functions scopes) that can be further nested. Nested lexical scopes are opened by a procedure, method, thunk, with, or block start symbol. They are closed by the matching block-end symbol.

In general, symbol searching within a module's symbol table is performed in the following manner. The lexical scope that contains the current program address is searched for the symbol. If the symbol is not found within that scope, the enclosing lexical scope is searched. This search is repeated outward until the symbol is found or module scope is searched unsuccessfully. Note that lexical scopes at the same depth level are not searched. As an optimization for CodeView, symbols that open a lexical scope have fields that contain offsets from the beginning of the symbols for the module that point to the parent of the scope, the next lexical scope that is at the same scoping level and the S_END symbol that closes this lexical scope.

The pParent, pNext and pEnd fields described below are filled in by CVPACK and should be emitted as zeroes by the language processor.

Field

Linkage

pParent

Used in local procedures, global procedures, thunk start, with start, and block start symbols. If the scope is not enclosed by another lexical scopes, then pParent is zero. Otherwise, the parent of this scope is the symbol within this module that opens the outer scope that encloses this scope but encloses no other scope that encloses this scope. The pParent field contains the offset from the begining of the module's symbol table of the symbol that opens the enclosing lexical scope.

pNext

Used in start search local procedures, global procedures, and thunk start symbols. The pNext field, along with the start search symbol, defines a group of lexically scoped symbols within a symbol table that are contained within a code segment or PE section. For each segment or section represented in the symbol table, there is a start search symbol that contains the offset from the start of the symbols for this module to the first procedure or thunk contained in the segment. Each outermost lexical scope symbol has a next field containing the next outermost scope symbol contained in the segment. The last outermost scope in the symbol table for each segment has a next field of zero.

pEnd

This field is defined for local procedures, global procedures, thunk, block, and with symbols. The end field contains the offset from the start of the symbols for this module to the matching block end symbol that terminates the lexical scope.