Difference between revisions of "Symbol tables/fr"

From Free Pascal wiki
Jump to navigationJump to search
Line 21: Line 21:
 
{{Warning|Dernière mise à jour pour FPC version 2.5.1}}
 
{{Warning|Dernière mise à jour pour FPC version 2.5.1}}
  
All 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.
+
Toutes les tables de symboles dans le compilateur proviennent de ce type d'objet, qui contient des champs pour la taille totale des donnnées dans la table de symboles, et des méthodes pour lire la table de symboles dans un flux. Le départ de la liste chaînée des tables de symboles actives est la variable '''symtablestack'''.
  
 
http://www.pjh2.de/fpc/CompilerInternalsFigure04.png
 
http://www.pjh2.de/fpc/CompilerInternalsFigure04.png
Line 27: Line 27:
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
 
type
 
type
   TSymTable = class
+
   TSymTable = classu
 
     name: pshortstring;              // uppercased realname
 
     name: pshortstring;              // uppercased realname
 
     realname  : pshortstring;        // used to generate long symbol names (like symble.name + '.' + sym.name)
 
     realname  : pshortstring;        // used to generate long symbol names (like symble.name + '.' + sym.name)
     DefList  : TFPObjectList;        // list of definintions
+
     DefList  : TFPObjectList;        // list of definitions
 
     SymList  : TFPHashObjectList;    // list of symbols
 
     SymList  : TFPHashObjectList;    // list of symbols
     defowner  : TDefEntry;            // The owner definition. Valud for records, objects and enumerations.
+
     defowner  : TDefEntry;            // The owner definition. Value for records, objects and enumerations.
 
     moduleid  : longint;              // unit index
 
     moduleid  : longint;              // unit index
 
     refcount  : smallint;            // count of references. if few objects shares the same
 
     refcount  : smallint;            // count of references. if few objects shares the same
Line 45: Line 45:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The type of possible symbol tables are shown in the following table:
+
Le type des tables de symboles possibles sont montrés dnas la table suivante:
  
 
{| class="wikitable"
 
{| class="wikitable"
 
! Champ !! Description
 
! Champ !! Description
 
|-  
 
|-  
| abstractsymtable || Default value when the symbol table is created and its type is not defined. Used for debugging purposes
+
| abstractsymtable || Valeur par défaut quand la tables est créée et que son type n'est pas défini. Utilisé à des fins de mise au point
 
|-  
 
|-  
| WithSymTable || All symbols accessed in a with statement
+
| WithSymTable || Tous les symboles accédés dans une instruction with
 
|-  
 
|-  
| StaticSymTable || Contains unit implementation or program symbols
+
| StaticSymTable || Contient les symboles de la partie implémentation de l'unité ou du programme
 
|-  
 
|-  
| GlobalSymTable || Contains unit interface symbols
+
| GlobalSymTable || Contient les symboles de l'interface de l'unité
 
|-  
 
|-  
| ObjectSymTable || Contains all symbols within an object/class/interface/objc class and other object types statement
+
| ObjectSymTable || Contient tous les symboles dans un objet/une classe/une interface/une classe objc et les autres instructions de types d'objet
 
|-  
 
|-  
| RecordSymTable || Contains all symbols within a record statement
+
| RecordSymTable || Contient tous les symboles dans une instruction records
 
|-  
 
|-  
| LocalSymTable || Hold symbols for all local variables of a routine
+
| LocalSymTable || Tient les symboles pour toutes les variables locales d'une routine
 
|-  
 
|-  
| ParaSymTable || Holds symbols for all parameters of a routine (the actual parameter declaration symbols)
+
| ParaSymTable || Tient les symboles pour tous les paramètres d'une routine (les symboles de déclaration de paramètre effectif)
 
|-  
 
|-  
| Stt_ExceptSymTable || Contains all exception symbols defined in the except block
+
| Stt_ExceptSymTable || Contient tous les symboles d'exception définis dans un bloc except
 
|-  
 
|-  
| exportedmacrosymtable || Holds all exported macros
+
| exportedmacrosymtable || Tient toutes les macros exportées
 
|-  
 
|-  
| localmacrosymtable || Holds all macros currently in scope
+
| localmacrosymtable || Tient toutes les macros actuellement dans la portée
 
|-  
 
|-  
| enumsymtable || Contains all enumeration elements symbols of an enumeration
+
| enumsymtable || Contient tous les symboles d'éléments d'une énumération
 
|}
 
|}
  

Revision as of 12:25, 24 December 2020

English (en) français (fr)

Retour au contenu FPC internals

Tables de symboles

Architecture

Warning-icon.png

Avertissement: Dernière mise à jour pour FPC version 1.0.x

La table des symboles contient toutes les définitions pour tous les symboles dans le compilateur. Il contient aussi toute information de type de tous les symboles rencontrés pendant le processus d'analyse. Tous les symboles sont accessibles sous forme de flux et sont utilisés dans les fichiers PPU pour éviter de tout recompiler pour vérifier si tous les symboles sont valides.

Il y a différents types de tables de symboles, qui peuvent tous être actives à un moment ou à un autre selon le contexte de l'analyseur.

Une vue d'ensemble architecturale de l'interaction entre les tables de symboles, les entrées de symboles et les entrées de définition est présentée dans la figure 4.1.

Comme cela peut être vu, les entrées de tables de symboles sont faites en utilisant un algorithme de hachage rapide avec un dictionnaire d'empreinte (hash dictionary).

L'Objet Table de symboles

Warning-icon.png

Avertissement: Dernière mise à jour pour FPC version 2.5.1

Toutes les tables de symboles dans le compilateur proviennent de ce type d'objet, qui contient des champs pour la taille totale des donnnées dans la table de symboles, et des méthodes pour lire la table de symboles dans un flux. Le départ de la liste chaînée des tables de symboles actives est la variable symtablestack.

http://www.pjh2.de/fpc/CompilerInternalsFigure04.png

type
  TSymTable = classu
    name: pshortstring;               // uppercased realname
    realname  : pshortstring;         // used to generate long symbol names (like symble.name + '.' + sym.name)
    DefList   : TFPObjectList;        // list of definitions
    SymList   : TFPHashObjectList;    // list of symbols
    defowner  : TDefEntry;            // The owner definition. Value for records, objects and enumerations.
    moduleid  : longint;              // unit index
    refcount  : smallint;             // count of references. if few objects shares the same
                                      // symbol table - they add a new reference instead of 
                                      // full copying the symbols
    currentvisibility : tvisibility;  // current visibility of symtable - used while parsing object members
                                      // to put them into symtable with the correct visibility
    currentlyoptional : boolean;      // used while parsing of objc protocol
    symtablelevel : byte;             // level of symtable, used for nested procedures
    symtabletype  : TSymtabletype;    // Indicates the type of this symbol table (2).
  end;

Le type des tables de symboles possibles sont montrés dnas la table suivante:

Champ Description
abstractsymtable Valeur par défaut quand la tables est créée et que son type n'est pas défini. Utilisé à des fins de mise au point
WithSymTable Tous les symboles accédés dans une instruction with
StaticSymTable Contient les symboles de la partie implémentation de l'unité ou du programme
GlobalSymTable Contient les symboles de l'interface de l'unité
ObjectSymTable Contient tous les symboles dans un objet/une classe/une interface/une classe objc et les autres instructions de types d'objet
RecordSymTable Contient tous les symboles dans une instruction records
LocalSymTable Tient les symboles pour toutes les variables locales d'une routine
ParaSymTable Tient les symboles pour tous les paramètres d'une routine (les symboles de déclaration de paramètre effectif)
Stt_ExceptSymTable Contient tous les symboles d'exception définis dans un bloc except
exportedmacrosymtable Tient toutes les macros exportées
localmacrosymtable Tient toutes les macros actuellement dans la portée
enumsymtable Contient tous les symboles d'éléments d'une énumération

Insertion de symboles dans une table de symboles

(Dernière mise à jour pour FPC version 1.0.x)

To 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.

http://www.pjh2.de/fpc/CompilerInternalsFigure05.png

Symbol table interface

(Dernière mise à jour pour FPC version 1.0.x)

Routines

Search_a_Symtable

Déclaration: function Search_a_Symtable(const Symbol: String; SymTableType: TSymTableType): PSym;
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.

GetSym

Déclaration: procedure GetSym(const S: StringId; NotFoundError: Boolean);
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.

GlobalDef

Déclaration: function GlobalDef(const S: String): PDef;
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.

Variables

SrSym

Déclaration: var SrSym: PSym;
Description: This points to the symbol entry found, when calling getsym.

SrSymTable

Déclaration: var SrSymTable: PSymTable;
Description: This points to the symbol table of the symbol SrSym when calling GetSym.

Prochain chapitre: Entrée de table de symboles