Type information/fr

From Lazarus wiki
Jump to navigationJump to search

English (en) français (fr)

Retour au contenu FPC internals

Information de Type

Architecture

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

Une déclaration de type, qui est la base de la table de symboles, car par nature tout se résume à un type après analyse est une structure spéciale avec deux champs principaux, qui pointent vers une entrée de table de symboles qui est le nom du type, et la définition réelle qui donne les informations sur les autres symboles du type, la taille du type et d'autres informations similaires.

type
  TType = object
    Sym: PSym;      // Points to the symbol table of this type
    Def: PDef;      // Points to the actual definition of this type
  end;

Types de définition

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

Les définitions représentent l'information de type pour tous les symboles possibles qui peuvent être rencontrés par l'analyseur. Les types de définition avec les symboles dans la table des symboles, et sont utilisés par le processus d'analyse (entre autres choses) pour réaliser le contrôle de type.

Les types de définition actuels possibles sont énumérés dans TDefType et peuvent avoir l'une des valeurs symboliques: The current possible definition types are enumerated in TDefType and can have one of the following symbolic values:

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

deftype d'objet TDef Description
AbstractDef  
ArrayDef Définition de type Tableau
RecordDef Définition de type Enregistrement
PointerDef Définition de type Pointeur
OrdDef Définition de type ordinal (valeur numérique)
StringDef Définition de type String
EnumDef Définition de type Enumération
ProcDef Définition de type Procédure
ObjectDef Définition de type Object ou classe
ErrorDef Définition d'erreur (vide, utilisé pour reprise d'erreur)
FileDef Définition de type Fichier
FormalDef  
SetDef Définition de type Ensemble
ProcVarDef Définition de type variable procédurale
FloatDef Définition de type Virgule flottante
ClassrefDef  
ForwardDef  

Définition de base (TDef)

Toutes les défintions de type sont basées sur cet classe. Par conséquent, tous les objets dérivés possèdent tous les champs de cet objet en plus de leurs propres champs privés.

type
  PDef = ^TDef;
  TDef = object(TSymTableEntry)
    TypeSym: PTypeSym;                    // Pointer to symbol table entry for this type
                                          // definition
    InitTable_Label: PAsmLabel;           // Label to initialization information (required
                                          // for some complex types)
    Rtti_Label: PAsmLabel;                // Label to the runtime type information.
    NextGlobal: PDef;
    PreviousGlobal: PDef;
    SaveSize: Longint;                    // Size in bytes of the data definition
    DefType: TDefType;                    // Indicates the definition type (see table ??).
    Has_InitTable: Boolean;
    Has_Rtti: Boolean;
    Is_Def_Stab_Written: TDefStabStatus;  // Can be one of the following states :
                                          // (Not_Written, written, Being_Written)
                                          // which indicates if the debug information
                                          // for this type has been defined or not.
     GlobalNb: Longint;                   // Internal stabs debug information type signature
                                          // (each type definition has a numeric
                                          // signature).
  end;

Définition de fichier (TFileDef)

La définition de fichier ne peut se produire que dans de rares cas, lorsqu'un file of type est analysé, une définition de fichier de ce type sera créée. De plus, en interne, une définition d'un type de fichier Text et d'un type de fichier untyped est créée lors du chargement de l'unité centrale. Ces types sont toujours définis lors de la compilation d'une unité ou d'un programme.

type
  PFileDef = ^TFileDef;
  TFileDef = object(TDef)
    FileTyp: TFileTyp;        // Indicates what type of file definition it is 
                              // (text, untyped or typed).
    TypedFileType: TType;     // In the case of a typed file definition, 
                              // definition of the type of the file
  end;


Définition formelle (TFormalDef)

Définition avancée (TForwardDef)

La définition avancée (forward) est créée, lorsqu'un type est déclaré avant qu'une définition réelle n'existe. C'est le cas lorsque, par exemple, type PMyObject = TMyObject, alors que TMyObject n'a pas encore été défini.

type
  PForwardDef = ^TForwardDef;
  TForwardDef = object(TDef)
    toSymName: String;         // The symbol name for this forward declaration
                               // (the actual real definition does not exist yet)
    ForwardPos: TFilePosInfo;  // Indicates file position where this forward
                               // definition was declared.
  end;


Définition d'erreur (TErrorDef)

Cette définition est réellement une entrée de définition vide. Quand l'analyseur rencontre une erreur lors de l'analyse d'une définition au lieu de ne rien mettre dans le type pour un symbole, il pose cette entrée. Cela évite les accès illégaux en mémoire plus tard dans l'analyse.

Définition de pointeur (TPointerDef)

La définition de pointeur est utilisée pour distinguer entre différents types de pointeurs dans le compilateur et est créée à chaque construction d'analyse typename trouvée.

type
  PPointerDef = ^TPointerDef;
  TPointerDef = object(TDef)
    Is_Far: Boolean;         // Used to indicate if this is a far pointer or not 
                             // (this flag is cpu-specific)
    PointerType: TType;      // This indicates to what type definition this pointer
                             // points to.
  end;

Définition d'objet (TObjectDef)

La définition d'objet est créée chaque fois qu'une déclaration d'objet est trouvée dans la déclaration de la section type.

type
  PObjectDef = ^TObjectDef;
  TObjectDef = object(TDef)
    ChildOf: PObjectDef;                 // This is a pointer to the parent object
                                         // definition. It is set to nil, if
                                         // this object definition has no parent.
    ObjName: PString;                    // This is the object name
    SymTable: PSymTable;                 // This is a pointer to the symbol
                                         // table entries within this object.
    ObjectOptions: TObjectOptions;       // The options for this object, see
                                         // the following table for the possible
                                         // options for the object.
    VMT_Offset: Longint;                 // This is the offset from the start
                                         // of the object image in memory
                                         // where the virtual method table is
                                         // located.
    Writing_Class_Record_Stab: Boolean;
  end;


Options d'objet (TObjectOptions) Description
oo_is_class This is a delphi styled class declaration, and not a Turbo Pascal object.
oo_is_forward This flag is set to indicate that the object has been declared in a type section, but there is no implementation yet.
oo_has_virtual This object / class contains virtual methods
oo_has_private This object / class contains private fields or methods
oo_has_protected This object / class contains protected fields or methods
oo_has_constructor This object / class has a constructor method
oo_has_destructor This object / class has a destructor method
oo_has_vmt This object / class has a virtual method table
oo_has_msgstr This object / class contains one or more message handlers
oo_has_msgint This object / class contains one or more message handlers
oo_has_abstract This object / class contains one or more abstract methods
oo_can_have_published the class has runtime type information, i.e. you can publish properties
oo_cpp_class the object/class uses an C++ compatible class layout
oo_interface this class is a delphi styled interface

Définition de référence de classe (TClassRefDef)

Définition de tableau (TArrayDef)

Cette définition est créée quand une déclaration de type tableau est analysée. Elle contient toute l'information nécessaire pour le contrôle de type du tableau et la génération de code.

type
  PArrayDef = ^TArrayDef;
  TArrayDef = object(TDef)
    IsVariant: Boolean;
    IsConstructor : Boolean;
    RangeNr: Longint;          // Label number associated with the index values
                               // when range checking is on
    LowRange : Longint;        // The lower index range of the array definition
    HighRange : Longint;       // The higher index range of the array definition
    ElementType : TType;       // The type information for the elements of the array
    RangeType : TType;         // The type information for the index ranges of the array
    IsArrayofConst : Boolean;
  end;

Définition d'enregistrement (TRecordDef)

L'entrée de définition d'enregistrement est créée chaque fois qu'un enregistrement est analysé. Il contient la table de symboles des éléments dans l'enregistrement.

type
  PRecordDef = ^TRecordDef;
  TRecordDef = object(TDef)
    SymTable: PSymTable;    // This is a pointer to the symbol table entries within
                            // this record.
  end;

Définition d'ordinal (TOrdDef)

Cette définition de type est celle utilisée pour toutes les valeurs ordinales comme les Char, les octets et autres valeurs de type numérique entier. Certaines des définitions de type prédéfinies sont automatiquement créées et chargées quand le compilateur démarre. Les autres sont créées durant la compilation, lorsqu'elles sont déclarés.

type
  POrdDef = ^TOrdDef;
  TOrdDef = object(TDef)
    Low: Longint;        // The minimum value of this ordinal type
    High: Longint;       // The maximum value of this ordinal type
    Typ: TBaseType;      // The type of ordinal value
  end;


Type ordinal de base (TBaseType) Description
uauto Définition de type ordinal utilisateur
uvoid Représente une valeur de retour vide (void) ou un noeud
uchar Caractère ASCII
u8bit Valeur 8-bit non signée
u16bit Valeur 16-bit non signée
u32bit Valeur 32-bit non signée
s16bit Valeur 16-bit signée
s32bit Valeur 32-bit signée
bool8bit Valeur booléenne 8-bit
bool16bit Valeur booléenne 16-bit
bool32bit Valeur booléenne 32-bit
u64bit Valeur 64-bit non signée (non complètement supportée/testée)
s64bit Valeur 64-bit signée
uwidechar Actuellement non supporté et inutilisé

Définition de flottant (TFloatDef)

Cette définition de type est celle utilisée pour toutes les valeurs en virgule flottante telles que SINGLE, DOUBLE. Certaines des définitions de type prédéfinies sont automatiquement créées et chargées lorsque le compilateur démarre.

type
  PFloatDef = ^TFloatDef;
  TFloatDef = object(TDef)
    Typ: TFloatType;       // The type of floating point value.
  end;
Type de base de virgule flottante (TFloatType) Description
s32real Valeur virgule flottante en simple précision IEEE
s64real Valeur virgule flottante en double précision IEEE
s80real Valeur virgule flottante étendue (spécifique à la CPU, en général mappé vers le type Double)
s64comp Valeur 63-bit signée, utilisant 1 bit pour l'indication de signe
f16bit Non supporté
f32bit Non supporté

Définition de procédure abstraite (tabstractprocdef)

Ceci est la base de définitions de type Routine. Cet objet est abstrait, et ne peut pas être directement utilisé de manière utile. L'objet dérivé de cet objet est utilisé pour le processus réel d'analyse.

type
  PAbstractProcDef = ^TAbstractProcDef;
  TAbstractProcDef = object(TDef)
    SymtableLevel: Byte;
    Fpu_Used: Byte;                     // Number of floating point registers
                                        // used in this routine
    RetType: TType;                     // Type information for the return value
                                        // (uvoid if it returns nothing)
    ProcTypeOption: TProcTypeOption;    // Indicates the type of routine it is.
    ProcCallOptions: TProcCallOptions;  // Indicates the calling convention
                                        // of the routine.
    ProcOptions: TProcOptions;          // Indicates general procedure options.
    Para: PLinkedList;                  // This is a linked list of parameters
                                        // (pparaitem list)
  end;
Options de Procédure (TProcTypeOption) Description
poType_ProgInit La routine est le point d'entrée du programme

(défini comme main dans le compilateur).

poType_UnitInit La routine est le code d'initialisation de l'unité

(défini comme unité unitname_init dans le compilateur)

poType_UnitFinalize La routine est Routine est le code de sortie de l'unité

(défini comme unitname_finalize dnas le compilateur)

poType_Constructor La routine est une constructeur d'objet ou de classe
poType_Destructor La routine est un destructeur d'objet ou de classe
poType_Operator La procédure est un opérateur


Options d'appel (TProcCallOptions) Description
pocall_clearstack L'appelant de la routine nettoie la pile apreès le retour
pocall_leftright Envoyer les paramètres à la routine de gauche à droite
pocall_cdecl Le passage des paramètres est fait en utilisant le schéma d'alignement GCC, le passage des valeurs de paramètre est directement copié dans l'espace de la pile
pocall_register inutilisé (envoie les paramètres via les registres)
pocall_stdcall Le passage des paramètres est fait en utilisant le schéma d'alignement GCC, les registres standard GCC sont sauvegardés
pocall_safecall Les registres standard GCC sont sauvegardés
pocall_palmsssyscall Ceci est une macro spéciale syscall pour les systèmes embarqués
pocall_system inutilisé
pocall_inline La routine est une macro assemnbleur inline (et non un véritable appelnot a true call)
pocall_internproc Routine d'assistance (helper) du générateur de code de l'unité système
pocall_internconst Routine macro d'assistance (helper) du générateur de code de l'unité système


Options de routine (TProcOptions) Description
po_classmethod Ceci est une méthode de classse
po_virtualmethod Ceci est une méthode virtuelle
po_abstractmethod Ceci est une méthode abstraite
po_staticmethod Ceci est une méthode statique
po_overridingmethod Ceci est une méthode surchargée (avec le drapeau po_virtual en général)
po_methodpointer Ceci est un pointeur de méthode (et non pas un pointeur de routine normal)
po_containsself self est passé explicitement comme paramètre de la méthode
po_interrupt Cette routine est un gestionnaire d'interruption
po_iocheck Le contrôle des E/S doit être fait après un appel à cette routine
po_assembler La routine est en assembleur
po_msgstr Méthode pour la gestion des messages string
po_msgint Méthode pour la gestion des messages Int
po_exports La routine a une directive d'export
po_external La routine est externe (dans un autre objet ou bibliotèque)
po_savestdregs Entrée de routine devrait sauver tous les registres utilisés par GCC
po_saveregisters L'entrée de routinedevrait sauver tous les registres
po_overload La routine est declarée comme surchargée

Définition de variable procédurale (TProcVarDef)

This definition is created when a procedure variable type is declared. It gives information on the type of a procedure, and is used when assigning and directly calling a routine through a pointer.

type
  PProcVarDef = ^TProcVarDef;
  TProcVarDef = object(TAbstractProcDef)
  end;

Définition de procédure (TProcDef)

When a procedure head is parsed, the definition of the routine is created. Thereafter, other fields containing information on the definition of the routine are populated as required.

type
  PProcDef = ^TProcDef;
  TProcDef = object(TAbstractProcDef)
    ForwardDef: Boolean;               // TRUE if this is a forward definition
    InterfaceDef: Boolean;
    ExtNumber: Longint;
    MessageInf: TMessageInf;
    NextOverloaded: PProcDef;
    FileInfo: TFilePosInfo;            // Position in source code for the declaration of
                                       // this routine. Used for error management.
    Localst: PSymTable;                // The local variables symbol table
    Parast: PSymTable;                 // The parameter symbol table
    ProcSym: PProcSym;                 // Points to owner of this definition
    LastRef: PRef;
    DefRef: PRef;
    CrossRef: PRef;
    LastWritten: PRef;
    RefCount: Longint;
    _Class: ProbjectDef;
    Code: Pointer;                     // The actual code for the routine 
                                       // (only for inlined routines)
    UsedRegisters: TRegisterSet;       // The set of registers used in this routine
    HasForward: Boolean;
    Count: Boolean;
    Is_Used: Boolean;
  end;

Définition de chaîne de caractère (TStringDef)

This definition represents all string types as well as derived types. Some of the default string type definitions are loaded when the compiler starts up. Others are created at compile time as they are declared with a specific length type.

type
  PStringDef = ^TStringDef;
  TStringDef = object(TDef)
    String_Typ: TStringType;   // Indicates the string type definition
    Len: Longint;              // This is the maximum length which can have the string
  end;
Type String (TStringType) Description
st_default Depends on current compiler switches, can either be a st_ShortString or st_AnsiString
st_shortstring short string (length byte followed by actual ASCII characters (1 byte/char))
st_longstring long string (length longint followed by actual ASCII characters (1 byte/char))
st_ansistring long string garbage collected (pointer to a length, reference count followed by actual ASCII characters (1 byte/char))
st_widestring long string garbage collected (pointer to a length, reference count followed by actual unicode characters (1 word/char (utf16)))


Définition d'énumération (TEnumDef)

An enumeration definition is created each time an enumeration is declared and parsed. Each element in the enumeration will be added to the enumeration symtable and if $SCOPEDENUMS directive is off then to the unit symtable also.

type
  tenumdef = class(tstoreddef)
    has_jumps: Boolean;   // True if enum has jumps between elements
    minval: aint;         // Value of the first element in the enumeration
    maxval: aint;         // Value of the last element in the enumeration
    BaseDef: tenumdef;    // In the case where the enumeration is a 
                          // subrange of another enumeration or a unique 
                          // enumeration copied from the another, this gives 
                          // information on the base range of the elements
   symtable: TSymtable;   // Enumeration symbol table - stores enumeration elements
  end;

Définition d'ensemble (TSetDef)

This definition is created when a set type construct is parsed (set of declaration).

type
  PSetDef = ^TSetDef;
  TSetDef = object(TDef)
    SetType: TSetType; Indicates the storage type of the set.
    ElementType: TType; Points the type definition and symbol
      table to the elements in the set.
  end;
Type d'ensemble (TSetType) Description
NormSet Normal set of up to 256 elements (32 byte storage space required)
SmallSet Small set of up to 32 elements (4 byte storage space)
VarSet Variable number of element set (storage size is dependent on number of elements) (currently unused and unsupported)

Définition d'interface

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

Routines

TDef.Size

Déclaration: function TDef.Size: Longint;
Description: This method returns the true size of the memory space required in bytes for this type definition (after alignment considerations).


TDef.Alignment

Déclaration: function TDef.Alignment: Longint;
Description: This method returns the alignment of the data for complex types such as records and objects, otherwise returns 0 or 1 (no alignment).


Prochain chapitre: L'analyseur