back to contents FPC internals
(last updated for fpc version 1.0.x)
The task of the parser is to read the token fed by the scanner, and make sure that the pascal syntax is respected. It also populates the symbol table, and creates the intermediate nodes (the tree) which will be used by the code generator.
An overview of the parsing process, as well as its relationship with the tree the type checker
and the code generator is shown in the following diagram:
http://www.pjh2.de/fpc/CompilerInternalsFigure08.png
(last updated for fpc version 1.0.x)
Each module being compiled, be it a library , unit or main program has some information which is required. This is stored in the tmodule object in memory. To avoid recompilation of already compiled module, the dependencies of the modules is stored in a PPU file, which makes it easier to determine which modules to recompile.
type
PModule = ^TModule;
TModule = object(TLinkedList_Item)
PPUFile: PPPUFile;
Crc: Longint;
Interface_CRC: Longint;
Flags: Longint;
Compiled: Boolean;
Do_Reload: Boolean;
Do_Assemble: Boolean;
Sources_Avail: Boolean;
Sources_Checked: Boolean;
Is_Unit: Boolean;
In_Compile: Boolean;
In_Second_Compile: Boolean;
In_Second_Load: Boolean;
In_Implementation: Boolean;
In_Global: Boolean;
Recompile_Reason: TRecompile_Reason;
Islibrary: Boolean;
Map: PUnitMap;
Unitcount: Word;
Unit_index: Word;
Globalsymtable: Pointer;
Localsymtable: Pointer;
Scanner: Pointer;
Loaded_From: PModule;
Uses_Imports: Boolean;
Imports: PLinkedList;
_Exports: PLinkedList;
SourceFiles: PFileManager;
ResourceFiles: TStringContainer;
Used_Units: TLinkedList;
Dependent_Units: TLinkedList;
LocalUnitSearchPath,
LocalObjectSearchPath,
LocalIncludeSearchPath,
LocalLibrarySearchPath: TSearchPathList;
Path: PString;
OutputPath: PString;
ModuleName: PString;
ObjFileName: PString;
AsmFileName: PString;
PPUFileName: PString;
StaticLibFilename: PString;
SharedLibFilename: PString;
ExeFileName: PString;
AsmPrefix: PString;
MainSource: PString;
end;
(last updated for fpc version 1.0.x)
program or library parsing
edit
constant declarations
edit
variable declarations
edit
thread variable declarations
edit
resource string declarations
edit
typed constant declarations
edit
(last updated for fpc version 1.0.x)
|
|
| Declaration: |
var AktProcSym: PProcSym; |
| Description: |
Pointer to the symbol information for the routine currently being parsed. |
|
|
| Declaration: |
var LexLevel: Longint; |
| Description: |
Level of code currently being parsed and compiled 0 = for main program 1 = for subroutine 2 = for local / nested subroutines. |
|
|
| Declaration: |
var Current_Module: PModule; |
| Description: |
Information on the current module (program, library or unit) being compiled. |
The following variables are default type definitions which are created each time compilation begins (default system-unit definitions), these definitions should always be valid:
|
|
| Declaration: |
var VoidDef: POrdDef; |
| Description: |
Pointer to nothing type |
| Notes: |
This is loaded as a default supported type for the compiler |
|
|
| Declaration: |
var cCharDef: POrdDef; |
| Description: |
Type definition for a character (char) |
| Notes: |
This is loaded as a default supported type for the compiler |
|
|
| Declaration: |
var cWideCharDef: POrdDef; |
| Description: |
Type definition for a unicode character (WideChar) |
| Notes: |
This is loaded as a default supported type for the compiler |
|
|
| Declaration: |
var BoolDef: POrdDef; |
| Description: |
Type definition for a boolean value (boolean) |
| Notes: |
This is loaded as a default supported type for the compiler |
|
|
| Declaration: |
var u8BitDef: POrdDef; |
| Description: |
Type definition for an 8-nit unsigned value (byte) |
| Notes: |
This is loaded as a default supported type for the compiler |
|
|
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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:
|
|
| 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. |
|
|
| 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. |
|
|
| 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. |
|
|
| 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:
|
|
| 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. |
|
|
| 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. |
|
|
| Declaration: |
var cAnsiStringDef: PStringDef; |
| Description: |
Type definition for an ansistring type (AnsiString) |
| Notes: |
This is loaded as a default supported type for the compiler. |
|
|
| 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. |
|
|
| 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. |
|
|
| 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:
|
|
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| Declaration: |
var cFormalDef: PFormalDef; |
| Description: |
|
| Notes: |
This is loaded as a default supported type for the compiler |
|
|
| Declaration: |
var cfFileDef: PFileDef; |
| Description: |
This is the default file type (file) |
| Notes: |
This is loaded as a default supported type for the compiler |
Next chapter: The inline assembler parser