Symbol entries/fr

From Lazarus wiki
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

English (en) français (fr)

Retour au contenu FPC internals

Entrées de symbole

Architecture

Warning-icon.png

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

Il y a différents types de symbole possibles, chacun ayant différents champs des autres. Chaque symbole a une signature spécifique pour indiquer quel type d'entrée il s'agit. Chaque entrée dans la table de symboles est effectivement une des entrées de symbole décrite dans les sections suivantes. La relation entre une entrée de symbole, une définition de type, et l'entrée de symbole du nom de type est montrée dans la figure suivante:

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

Types d'entrée de symbole

Warning-icon.png

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

Type de base de symbole (TSym)

Tous les types d'entrée dans la table de symboles sont dérivés de la classe de base qui contient l'information sur le type du symbole aussi bien que sur le propriétaire de l'entrée de symbole.

type
  PSym = ^TSym;
  TSym = object(TSymTableEntry)
    SymOptions: TSymOptions;  // Indicate the access scope of the symbol
    FileInfo: TFilePosInfo;
    Refs: Longint;            // Indicates how many times this label is refered in the
                              // parsed code (is only used with variable and assembler
                              // label symbols).
    LastRef: PRef;
    DefRef: PRef;
    LastWritten: PRef;
    RefCount: Longint;        // Browser information indicating the reference count
    Typ: TSymTyp;             // Indicates the symbol type
    IsStabWritten: Boolean;   // Set to TRUE if the stabs debugging information has
                              // been written for this symbol.
  end;
TSymTyp Description
AbstractSym C'(est un symbole abstrait spécial (ne devrait jamais être rencontré)
VarSym Ce symbole est une déclaration de variable dans la section var, ou un paramètre var
TypeSym Ce symbole est un nom de type
ProcSym Ce symbole est un nom de routine ou de méthode
UnitSym Ce symbole est un nom d'unité
ProgramSym Ce symbole est un nom de programme principal
ConstSym Ce symbole est une constante
EnumSym Ce symbole est un symbole d'énumération (un élément dans une énumeration)
TypedConstSym Ce symbole est une variable pré-initialisée (constante typée Pascal)
ErrorSym Ce symbole est créé pour une génération d'erreur
SysSym Ce symbole représenté une routine d'unité system inline-ée
LabelSym Ce symbole représente une étiquette dans une déclaration Pascal d'étiquette
AbsoluteSym Ce symbole représente un symbole suivant une déclaration de variable absolute
PropertySym Ce symbole est un nom de propriété
FuncRetSym Ce symbole est le nom de la valeur de retour pour les fonctions
MacroSym Ce symbole est un symbole de macro (tout comme un #define en C)

Symbole d'Etiquette (TLabelSym)

L'entrée de table de symboles d'étiquette est seulement créé quand une étiquette Pascal est déclarée via le mot-clé label. L'objet expose publiquement les champs suivants:

type
  PLabelSym = ^TLabelSym;
  TLabelSym = object(TSym)
    Used: Boolean;                 // Set to TRUE if this pascal label is used using a goto
                                   // or in an assembler statement
    Defined: Boolean;              // Set to TRUE if this label has been declared
    Lab: PAsmLabel;                // Points to the actual assembler label structure which
                                   // will be emitted by the code generator
    Code: Pointer;
  end;


Symbole d'Unité (TUnitSym)

Le symbole d'unité est créé et ajouté à une table de symbole chaque fois que la clause uses est analysée et qu'un nom d'unité est trouvé, c'est aussi utilisé lors de la compilation d'une unité, avec la première entrée dans cette table de symbole devenant le nom d'unité se compilant. L'entrée de symbole d'unité fait partie d'une liste chaînée utilisée dans la table de symboles d'unité.

type
  PUnitSym = ^TUnitSym;
  TUnitSym = object(TSym)
    UnitSymTable: PUnitSymTable;  // Pointer to the global symbol table for that
                                  // unit, containing entries for each public?
                                  // symbol in that unit
    PrevSym: PUnitSym;            // Pointer to previous entry in the linked list
  end;

Symbole Macro (TMacroSym)

Les symboles de macro sont utilisés dans le préprocesseur pour des instructions de compilation conditionnelle. Il existe une telle entrée créée pour chaque directive $define, elle contient la valeur du define (stockée sous forme de chaîne).

type
  PMacroSym = ^TMacroSym;
  TMacroSym = object(TSym)
    Defined: Boolean;              // TRUE if the symbol has been defined with a 
                                   // $define directive, or false if it has been 
                                   // undefined with a $undef directive
    Defined_At_Startup: Boolean;   // TRUE if the symbol is a system wide define
    Is_Used: Boolean;              // TRUE if the define has been used such as in 
                                   // a $ifdef directive.
    BufText: PChar;                // The actual string text of the define
    BufLength: Longint;            // The actual string length of the define
  end;

Symbole Erreur (TErrorSym)

Ce symbole est en fait une entrée de table de symboles vide. Lorsque l'analyseur rencontre une erreur lors de l'analyse d'un symbole, au lieu de ne rien mettre dans la table des symboles, il place cette entrée de symbole. Cela évite les accès mémoire illégaux ultérieurement lors de l'analyse.

Symbole Procédure (TProcSym)

Le symbole de procédure est créé chaque fois qu'une routine est définie dans le code. Cela peut être soit une déclaration avancée (forward) ou l'implémentaiton réelle de la routine. Après la création, le symbole est ajouté dans la pile de table de symbole appropriée.

type
  PProcSym = ^TProcSym;
  TProcSym = object(TSym)
    Is_Global: Boolean;           // Set if the routine is exported by the unit
    Definition: PProcDef;         // Procedure definition, including parameter 
                                  // information and return values
  end;

Symbole Type (TTypeSym)

Le symbole de Type est créé chaque fois qu'une nouvelle déclaration de type est faite, il est alors insérée dans la pile courante de la table symbole. De plus, chaque fois que le compilateur compile un module, les types de base par défaut sont initialisés et ajoutés dans la table des symboles (psystem.pas). Le symbole de Type contient le nom d'un type, ainsi qu'un pointeur vers sa définition de type.

type
  PTypeSym = ^TTypeSym;
  TTypeSym = object(TSym)
    ResType: TType;               // Contains base type information as well as the type
                                  // definition
  end;

Symbole Variable (TVarSym)

Déclaration de variables, aussi bien les paramètres qui sont passés aux routines que les types de symboles Variable. L'accès à l'information, aussi bien que l'information de type et l'information d'optimisation sont enregistrés dans ce type de symbole.

type
  PVarSym = ^TVarSym;
  TVarSym = object(TSym)
    Reg: TRegister;              // If the value is a register variable, the reg field will
                                 // be different then R_NO
    VarSpez: TVarSpez;           // Indicates the variable type (parameters only) (Cf. 32).
    Address: Longint;            // In the case where the variable is a routine parameter,
                                 // this indicates the positive offset from theframe_pointer 
                                 // to access this variable. In the caseof a local variable,
                                 // this field indicates the negative offset from the 
                                 // frame_pointer. to access this variable.
    LocalVarSym: PVarSym;
    VarType: TType;              // Contains base type information as well as the type
                                 // definition
    VarOptions: TVarOptions;     // Flags for this variable (Cf. 31)
    VarState: TVarState;         // Indicates the state of the variable, if it’s used or
                                 // declared
  end;


TVarOptions Description
vo_regable La variable peut être placée dans un registre matériel générique
vo_is_c_var La variable est importée depuis un module C
vo_is_external La variable est déclarée external
vo_is_Dll_var La variable est une variable de bibliothèque partagée
vo_is_thread_var La variable est déclarée comme étant thread safe
vo_fpuregable La variable peut être placée dans un registre matériel en virgule flottante
vo_is_local_copy  
vo_is_const inutilisé et inutile
vo_is_exported La variable est is déclarée comme exportée dans une bibliothèque à liaison dynamique


TVarSpez Description
vs_value C'est un paramètre valeur
vs_const C'est un paramètre constant, une propriété ou un tableau
vs_var C'est un paramètre variable

Symbole Propriétét (TPropertySym)

type
  PPropertySym = ^TPropertySym;
  TPropertySym = object(TSym)
    PropOptions: TPropertyOptions;    // ???
    PropType: TType;                  // Indicates the type of the property
    PropOverriden: PPropertySym;      // ???
    IndexType: TType;
    Index: Longint;                   // ????
    Default: Longint;                 // ???
    ReadAccess: PSymList;             // ???
    WriteAccess: PSymList;            // ???
    StoredAccess: PSymList;           // ???
  end;

Symbole Valeur de retour de fonction

...

Symbole déclaré Absolute (TAbsoluteSym)

This symbol represents a variable declared with the absolute keyword. The address of the TVarSym object holds the address of the variable in the case of an absolute address variable.

The possible types of absolute symbols, are from an external object reference, an absolute address (for certain targets only), or on top of another declared variable.

type
  PAbsoluteSym = ^TAbsoluteSym;
  TAbsoluteSym = object(TVarSym)
    AbsTyp: TAbsoluteTyp;         // Indicates the type of absolute symbol it is 
    AbsSeg: Boolean;              // ???
    Ref: PSym;                    // In case abstyp is tovar, this field indicates the
                                  // symbol which is overlaid with this symbol. Otherwise
                                  // this field is unused.
    AsmName: PString;             // In case abstyp is toasm, this field indicates label
                                  // name for the variable.
  end;
TAbsoluteTyp Description
toVar The symbol will be declared on top of another symbol (variable or typed constant)
toAsm The variable is imported from an external module
toAddr The variable is declared as being at an absolute address

Symbole constante typée

...

Symbole Constante (TConstSym)

This symbol type will contain all constants defined and encountered during the parsing. The values of the constants are also set in this symbol type entry.

type
  PConstSym = ^TConstSym;
  TConstSym = object(TSym)
    ConstType: TType;       // Type information for this constant (?).
    ConstTyp: TConstTyp;    // Indicates the type of the constant
    ResStrIndex: Longint;   // If this is a resource string constant, it indicates the
                            // index in the resource table
    Value: Longint;         // In certain cases, contains the value of the constant
    Len: Longint;
  end;

Symbole Enumération

...

Symbole Programme

The program symbol type (TProgramSym) is used to store the name of the program, which is declared using program in the pascal source. This symbol type is currently unused in FreePascal.

Symbole Sys

The TSysSym symbol type is used to load indexes into the symbol table of the internal routines which are inlined directly by the compiler. It has a single field, which is the index of the inline routine.

Symbole Interface

Prochain chapitre: Information de type