Difference between revisions of "Type information/fr"

From Lazarus wiki
Jump to navigationJump to search
Line 229: Line 229:
 
=== Définition d'enregistrement (TRecordDef) ===
 
=== Définition d'enregistrement (TRecordDef) ===
  
The record definition entry is created each time a record type declaration is parsed. It contains the symbol table to the elements in the record.
+
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.
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>

Revision as of 20:43, 28 December 2020

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)

This type definition is the one used for all ordinal values such as char, bytes and other numeric integer type values. Some of the predefined type definitions are automatically created and loaded when the compiler starts. Others are created at compile time, when declared.

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 user defined ordinal type definition
uvoid Represents a void return value or node
uchar ASCII character (1 byte)
u8bit unsigned 8-bit value
u16bit unsigned 16-bit value
u32bit unsigned 32-bit value
s16bit signed 16-bit value
s32bit signed 32-bit value
bool8bit boolean 8-bit value
bool16bit boolean 16-bit value
bool32bit boolean 32-bit value
u64bit unsigned 64-bit value (not fully supported/tested)
s64bit signed 64-bit value
uwidechar Currently not supported and unused


Définition de flottant (TFloatDef)

This type definition is the one used for all floating point values such as SINGLE, DOUBLE. Some of the predefined type definitions are automatically created and loaded when the compiler starts.

type
  PFloatDef = ^TFloatDef;
  TFloatDef = object(TDef)
    Typ: TFloatType;       // The type of floating point value.
  end;
Type de base de virgule flottante (TFloatType) Description
s32real IEEE Single precision floating point value
s64real IEEE Double precision floating point value
s80real Extended precision floating point value (cpu-specific, usually maps to double)
s64comp 63-bit signed value, using 1 bit for sign indication
f16bit Unsupported
f32bit Unsupported

Définition de procédure abstraite (tabstractprocdef)

This is the base of all routine type definitions. This object is abstract, and is not directly used in a useful way. The derived object of this object are used for the actual parsing process.

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 Routine is the program entry point (defined as 'main' in the compiler).
poType_UnitInit Routine is the unit initialization code

(defined as unitname_init in the compiler

poType_UnitFinalize Routine is the unit exit code

(defined as unitname_finalize in the compiler)

poType_Constructor Routine is an object or class constructor
poType_Destructor Routine is an object or class destructor
poType_Operator Procedure is an operator


Options d'appel (TProcCallOptions) Description
pocall_clearstack The routine caller clears the stack upon return
pocall_leftright Send parameters to routine from left to right
pocall_cdecl Passing parameters is done using the GCC alignment scheme, passing parameter values is directly copied into the stack space
pocall_register unused (Send parameters via registers)
pocall_stdcall Passing parameters is done using GCC alignment scheme, standard GCC registers are saved
pocall_safecall Standard GCC registers are saved
pocall_palmsssyscall This is a special syscall macro for embedded system
pocall_system unused
pocall_inline Routine is an inline assembler macro (not a true call)
pocall_internproc System unit code generator helper routine
pocall_internconst System unit code generator helper macro routine


Options de routine (TProcOptions) Description
po_classmethod This is a class method
po_virtualmethod This is a virtual method
po_abstractmethod This is an abstract method
po_staticmethod This is a static method
po_overridingmethod This is an overriden method (with po_virtual flag usually)
po_methodpointer This is a method pointer (not a normal routine pointer)
po_containsself self is passed explicitly as a parameter to the method
po_interrupt This routine is an interrupt handler
po_iocheck IO checking should be done after a call to the procedure
po_assembler The routine is in assembler
po_msgstr method for string message handling
po_msgint method for int message handling
po_exports Routine has export directive
po_external Routine is external (in other object or lib)
po_savestdregs Routine entry should save all registers used by GCC
po_saveregisters Routine entry should save all registers
po_overload Routine is declared as being overloaded

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