Sign in Join
Wiki copytemporary

Symbol tables: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11back to contents [[FPC internals]]
22
33# Symbol tables
44
55## Architecture
66
77> **Warning:** Last updated for FPC version 1.0.x
88
99The symbol table contains all definitions for all symbols in the compiler. It also contains all type information for all symbols encountered during the parsing process. All symbols and definitions are streamable, and are used within PPU files to avoid recompiling everything to verify if all symbols are valid.
1010
1111There are different types of symbol tables, all of which maybe active at one time or another depending on the context of the parser.
1212
1313An architectural overview of the interaction between the symbol tables, the symbol entries and the definition entries is displayed in figure 4.1.
1414
1515As can be seen, the symbol table entries in the symbol table are done using the fast hashing algorithm with a hash dictionary.
1616
1717## The Symbol table object
1818
1919> **Warning:** Last updated for FPC version 2.5.1
2020
2121All symbol tables in the compiler are from this type of object, which contains fields for the total size of the data in the symbol table, and methods to read and write the symbol table into a stream. The start of the linked list of active symbol tables is the **symtablestack** variable.
2222
2323<http://www.pjh2.de/fpc/CompilerInternalsFigure04.png>
2424
2525``` pascal
2626type
2727 TSymTable = class
2828 name: pshortstring; // uppercased realname
2929 realname : pshortstring; // used to generate long symbol names (like symble.name + '.' + sym.name)
3030 DefList : TFPObjectList; // list of definintions
3131 SymList : TFPHashObjectList; // list of symbols
3232 defowner : TDefEntry; // The owner definition. Valud for records, objects and enumerations.
3333 moduleid : longint; // unit index
3434 refcount : smallint; // count of references. if few objects shares the same
3535 // symbol table - they add a new reference instead of
3636 // full copying the symbols
3737 currentvisibility : tvisibility; // current visibility of symtable - used while parsing object members
3838 // to put them into symtable with the correct visibility
3939 currentlyoptional : boolean; // used while parsing of objc protocol
4040 symtablelevel : byte; // level of symtable, used for nested procedures
4141 symtabletype : TSymtabletype; // Indicates the type of this symbol table (2).
4242 end;
4343```
4444
4545The type of possible symbol tables are shown in the following table:
4646
4747| Field | Description |
4848|----|----|
4949| abstractsymtable | Default value when the symbol table is created and its type is not defined. Used for debugging purposes |
5050| WithSymTable | All symbols accessed in a with statement |
5151| StaticSymTable | Contains unit implementation or program symbols |
5252| GlobalSymTable | Contains unit interface symbols |
5353| ObjectSymTable | Contains all symbols within an object/class/interface/objc class and other object types statement |
5454| RecordSymTable | Contains all symbols within a record statement |
5555| LocalSymTable | Hold symbols for all local variables of a routine |
5656| ParaSymTable | Holds symbols for all parameters of a routine (the actual parameter declaration symbols) |
5757| Stt_ExceptSymTable | Contains all exception symbols defined in the except block |
5858| exportedmacrosymtable | Holds all exported macros |
5959| localmacrosymtable | Holds all macros currently in scope |
6060| enumsymtable | Contains all enumeration elements symbols of an enumeration |
6161
6262## Inserting symbols into a symbol table
6363
6464*(last updated for fpc version 1.0.x)*
6565
6666To add a symbol into a specific symbol table, that’s symbol table’s Insert method is called, which in turns call the Insert_In_Data method of that symbol. Insert_In_Data, depending on the symbol type, adjusts the alignment and sizes of the data and actually creates the data entry in the correct segment.
6767
6868<http://www.pjh2.de/fpc/CompilerInternalsFigure05.png>
6969
7070## Symbol table interface
7171
7272*(last updated for fpc version 1.0.x)*
7373
7474### Routines
7575
7676#### Search_a_Symtable
7777
7878| | |
7979|----|----|
80-| Declaration: | <b>`function`</b>` Search_a_Symtable(`<b>`const`</b>` Symbol: String; SymTableType: TSymTableType): PSym;` |
80+| Declaration: | `function`` Search_a_Symtable(``const`` Symbol: String; SymTableType: TSymTableType): PSym;` |
8181| Description: | Search for a symbol Symbol in a specified symbol table SymTableType. Returns NIL if the symbol table is not found, and also if the symbol cannot be found in the desired symbol table. |
8282
8383#### GetSym
8484
8585| | |
8686|----|----|
87-| Declaration: | <b>`procedure`</b>` GetSym(`<b>`const`</b>` S: StringId; NotFoundError: Boolean);` |
87+| Declaration: | `procedure`` GetSym(``const`` S: StringId; NotFoundError: Boolean);` |
8888| Description: | Search all the active symbol tables for the symbol s,setting the global variable SrSym to the found symbol, or to nil if the symbol was not found. notfounderror should be set to TRUE if the routine must give out an error when the symbol is not found. |
8989
9090#### GlobalDef
9191
9292| | |
9393|----|----|
94-| Declaration: | <b>`function`</b>` GlobalDef(`<b>`const`</b>` S: String): PDef;` |
94+| Declaration: | `function`` GlobalDef(``const`` S: String): PDef;` |
9595| Description: | Returns a pointer to the definition of the fully qualified type symbol S, or NIL if not found. Notes: It is fully qualified, in that the symbol system.byte, for example, will be fully resolved to a unit and byte type component The symbol must have a global scope, and it must be a type symbol, otherwise NIL will be returned. |
9696
9797### Variables
9898
9999#### SrSym
100100
101101| | |
102102|--------------|-------------------------------------------------------------|
103-| Declaration: | <b>`var`</b>` SrSym: PSym;` |
103+| Declaration: | `var`` SrSym: PSym;` |
104104| Description: | This points to the symbol entry found, when calling getsym. |
105105
106106#### SrSymTable
107107
108108| | |
109109|----|----|
110-| Declaration: | <b>`var`</b>` SrSymTable: PSymTable;` |
110+| Declaration: | `var`` SrSymTable: PSymTable;` |
111111| Description: | This points to the symbol table of the symbol SrSym when calling GetSym. |
112112
113113Next chapter: [[Symbol entries]]
114114
115115---
116116*From the Free Pascal wiki, page "Symbol tables", as it stood on 2020-12-24 after a change by E-ric, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history