The parser/fr

From Lazarus wiki
Revision as of 13:40, 31 December 2020 by E-ric (talk | contribs) (u8BitDef)

English (en) français (fr)

Retour au contenu FPC internals

L'analyseur syntaxique

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

La tâche de l'analyseur syntaxique est de lire le jeton produit par l'analyseur lexicale et de s'assurer du respect de la syntaxe du Pascal. Il remplit aussi la table des symboles et créée les noeuds intermédiaires (l'arbre) qui sera utilisé par le générateur de code.

Une vue d'ensemble du processus d'analyse, aussi bien que la relation entre l'arbre, le contrôle de type et le générateur de code est montré dans le diagramme suivant :

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

Information de module

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

Chaque module étant compilé, qu'il soit une bibliothèque, une unité ou un programme principal a de l'information qui est requise. Ceci est stocké en mémoire dans l'objet TModule. Pour éviter la recompilation des modules déjà compilés, les dépendances des modules sont stockées dans le fichier PPU, ce qui rend aisée la détermination des modules à recompiler.

type
  PModule = ^TModule;
  TModule = object(TLinkedList_Item)
    PPUFile: PPPUFile;                        // Pointer to PPU file object (unit file)
    Crc: Longint;                             // CRC-32 bit of the whole PPU file
    Interface_CRC: Longint;                   // CRC-32 bit of the interface part of
                                              // the PPU file
    Flags: Longint;                           // Unit file flags
    Compiled: Boolean;                        // TRUE if module is already compiled
    Do_Reload: Boolean;                       // TRUE if the PPU file must be reloaded
    Do_Assemble: Boolean;                     // Only assemble, don’t recompile unit
    Sources_Avail: Boolean;                   // TRUE if all sources of module are available
    Sources_Checked: Boolean;                 // TRUE if the sources has already been checked
    Is_Unit: Boolean;                         // TRUE if this is a unit (otherwise a library 
                                              // or a main program)
    In_Compile: Boolean;                      // module is currently being recompiled
    In_Second_Compile: Boolean;               // module is being compiled for second time
    In_Second_Load: Boolean;                  // module is being reloaded a second time
    In_Implementation: Boolean;               // currently compiling implementation part 
                                              // (units only)
    In_Global: Boolean;                       // currently compiling implementation part
                                              // (units only)
    Recompile_Reason: TRecompile_Reason;      // Reason why module should be recompiled
    Islibrary: Boolean;                       // TRUE if this module is a shared library
    Map: PUnitMap;                            // Map of all used units for this unit
    Unitcount: Word;                          // Internal identifier of unit (for GDB support)
    Unit_index: Word;
    Globalsymtable: Pointer;                  // Symbol table for this module of externally
                                              // visible symbols
    Localsymtable: Pointer;                   // Symbol table for this module of locally
                                              // visible symbols
    Scanner: Pointer;                         // Scanner object pointer
    Loaded_From: PModule;                     // Module which referred to this module
    Uses_Imports: Boolean;                    // TRUE if this module imports symbols
                                              // from a shared library
    Imports: PLinkedList;                     // Linked list of imported symbols
    _Exports: PLinkedList;                    // Linked list of exported symbols (libraries only)
    SourceFiles: PFileManager;                // List of all source files for this module
    ResourceFiles: TStringContainer;          // List of all resource files for this module
    Used_Units: TLinkedList;                  // Information on units used by this module 
                                              // (pused_unit)
    Dependent_Units: TLinkedList;
    LocalUnitSearchPath,                      // Search path for obtaining module source code
    LocalObjectSearchPath,
    LocalIncludeSearchPath,                   // Search path for includes for this module
    LocalLibrarySearchPath: TSearchPathList;
    Path: PString;                            // Path were module is located or created
    OutputPath: PString;                      // Path where object files (unit), 
                                              // executable (program) or 
                                              // shared library (library) is created
    ModuleName: PString;                      // Name of the module in uppercase
    ObjFileName: PString;                     // Full name of object file or executable file
    AsmFileName: PString;                     // Full name of the assembler file
    PPUFileName: PString;                     // Full name of the PPU file
    StaticLibFilename: PString;               // Full name of the static library name
                                              // (used when smart linking is used)
    SharedLibFilename: PString;               // Filename of the output shared library
                                              // (in the case of a library)
    ExeFileName: PString;                     // Filename of the output executable
                                              // (in the case of a program)
    AsmPrefix: PString;                       // Filename prefix of output assembler
                                              // files when using smartlinking
    MainSource: PString;                      // Name of the main source file
  end;

Types d'analyse

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

Entrée

Analyse de programme ou de bibliothèque

Analyse d'unité

Analyse de routine

Déclarations d'étiquette

Déclarations de constante

Déclarations de type

Déclarations de variable

Déclarations de variable thread

Déclarations de ressource de chaîne

Déclarations d'exports

Analyse d'expression

Déclarations de constante typée

Interface de l'analyseur

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

variables

AktProcSym

Déclaration: var AktProcSym: PProcSym;
Description: Pointeur vers l'information de symbole pour la routine en cours d'analyse.

LexLevel

Déclaration: var LexLevel: Longint;
Description: Niveau de code en cours d'analyse et compilé

0 = pour le programme principal
1 = pour une sous-routine
2 = pour des sous-routines locales/imbriquées

Current_Module

Déclaration: var Current_Module: PModule;
Description: Information sur le module courant (programme, bibliothèque ou unité) en cours de compilation.

Les variables suivantes ont des définitions de type par défaut qui sont créées chaque fois que la compilation commence (définition par défaut de l'unité System), ces définitions doivent toujours être valides:


VoidDef

Déclaration: var VoidDef: POrdDef;
Description: Pointeur vers le type rien
Notes: Ceci est chargé comme un type supporté par défaut pour le compilateur

cCharDef

Déclaration: var cCharDef: POrdDef;
Description: Définition de type pour un caractère (char)
Notes: Ceci est chargé comme un type supporté par défaut pour le compilateur

cWideCharDef

Déclaration: var cWideCharDef: POrdDef;
Description: Définition de type pour un caractère unicode (WideChar)
Notes: Ceci est chargé comme un type supporté par défaut pour le compilateur

BoolDef

Déclaration: var BoolDef: POrdDef;
Description: Définition de type pour une valeur booléenne (boolean)
Notes: Ceci est chargé comme un type supporté par défaut pour le compilateur

u8BitDef

Déclaration: var u8BitDef: POrdDef;
Description: Deéfinition de type pour une value 8-bit non signée (byte)
Notes: Ceci est chargé comme un type supporté par défaut pour le compilateur

u16BitDef

Declaration: var u16BitDef: POrdDef;
Description: Type definition for an unsigned 16-bit value (word)
Notes: This is loaded as a default supported type for the compiler


u32BitDef

Declaration: var u32BitDef: POrdDef;
Description: Type definition for an unsigned 32-bit value (cardinal)
Notes: This is loaded as a default supported type for the compiler


s32BitDef

Declaration: var s32BitDef: POrdDef;
Description: Type definition for a signed 32-bit value (Longint)
Notes: This is loaded as a default supported type for the compiler


cu64BitDef

Declaration: var cu64BitDef: POrdDef;
Description: Type definition for an unsigned 64-bit value (QWord)
Notes: This is loaded as a default supported type for the compiler


cs64BitDef

Declaration: var cs64BitDef: POrdDef;
Description: Type definition for a signed 64-bit value (Int64)
Notes: This is loaded as a default supported type for the compiler


The following variables are default type definitions which are created each time compilation begins (default system-unit definitions), these definitions should always be valid:

s64FloatDef

Declaration: var s64FloatDef: PFloatDef;
Description: Type definition for a 64-bit IEEE floating point type (double)
Notes: This is loaded as a default supported type for the compiler. This might not actually really point to the double type if the cpu does not support it.


s32FloatDef

Declaration: var s32FloatDef: PFloatDef;
Description: Type definition for a 32-bit IEEE floating point type (single)
Notes: This is loaded as a default supported type for the compiler. This might not actually really point to the single type if the cpu does not support it.


s80FloatDef

Declaration: var s80FloatDef : PFloatDef;
Description: Type definition for an extended floating point type (extended)
Notes: This is loaded as a default supported type for the compiler. This might not actually really point to the extended type if the cpu does not support it.


s32FixedDef

Declaration: var s32FixedDef: PFloatDef;
Description: Type definition for a fixed point 32-bit value (fixed)
Notes: This is loaded as a default supported type for the compiler. This is not supported officially in FPC 1.0


The following variables are default type definitions which are created each time compilation begins (default system-unit definitions), these definitions should always be valid:

cShortStringDef

Declaration: var cShortStringDef: PStringDef;
Description: Type definition for a short string type (ShortString)
Notes: This is loaded as a default supported type for the compiler.


cLongStringDef

Declaration: var cLongStringDef: PStringDef;
Description: Type definition for a long string type (LongString)
Notes: This is loaded as a default supported type for the compiler.


cAnsiStringDef

Declaration: var cAnsiStringDef: PStringDef;
Description: Type definition for an ansistring type (AnsiString)
Notes: This is loaded as a default supported type for the compiler.


cWideStringDef

Declaration: var cWideStringDef: PStringDef;
Description: Type definition for an wide string type (WideString)
Notes: This is loaded as a default supported type for the compiler.


OpenShortStringDef

Declaration: var OpenShortStringDef: PStringDef;
Description: Type definition for an open string type (OpenString)
Notes: This is loaded as a default supported type for the compiler.


OpenCharArrayDef

Declaration: var OpenCharArrayDef: PArrayDef;
Description: Type definition for an open char array type(OpenCharArray)
Notes: This is loaded as a default supported type for the compiler.


The following variables are default type definitions which are created each time compilation begins (default system-unit definitions), these definitions should always be valid:

VoidPointerDef

Declaration: var VoidPointerDef: PPointerDef;
Description: Type definition for a pointer which can point to anything (Pointer)
Notes: This is loaded as a default supported type for the compiler


CharPointerDef

Declaration: var CharPointerDef: PPointerDef;
Description: Type definition for a pointer which can point to characters (PChar)
Notes: This is loaded as a default supported type for the compiler


VoidFarPointerDef

Declaration: var VoidFarPointerDef: PPointerDef;
Description: Type definition for a pointer which can point to anything (intra-segment) (far Pointer)
Notes: This is loaded as a default supported type for the compiler


cFormalDef

Declaration: var cFormalDef: PFormalDef;
Description:  
Notes: This is loaded as a default supported type for the compiler


cfFileDef

Declaration: var cfFileDef: PFileDef;
Description: This is the default file type (file)
Notes: This is loaded as a default supported type for the compiler

Prochain chapitre: L'analyseur d'assembleur inline