Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find a comprehensive list of Delphi "compiler magic" declarations?

Tags:

delphi

A comment at the top of system.pas states:

{ Predefined constants, types, procedures, }
{ and functions (such as True, Integer, or }
{ Writeln) do not have actual declarations.}
{ Instead they are built into the compiler }
{ and are treated as if they were declared }
{ at the beginning of the System unit.     }

Obviously, that's nowhere near a comprehensive list. Does anyone know where I could find the complete list?

EDIT: The responses I've got so far seem to be a bit confused as to what I'm looking for. I'm trying to find a list of the built-in constants, types, procedures and functions that the compiler recognizes but are not declared in any unit. Examples include High(), Writeln(), Assert(), string, etc.

like image 652
Mason Wheeler Avatar asked Dec 23 '09 15:12

Mason Wheeler


6 Answers

For Procedures and Functions, go into the System Unit and look for the comment:

{ Procedures and functions that need compiler magic }

Below that is probably a fairly complete list. Just remove the leading underscore from each routine name.

For Keywords, the list at Delphi Basics:

  • Keywords: http://www.delphibasics.co.uk/ByType.asp?Type=Keyword

are mostly "compiler magic", undeclared in any unit.

For Constants, a short list includes: MaxInt, MaxLongInt, Nil and Pi.

And as Ken said, you can find most of the Types near the top of the System unit.

like image 143
lkessler Avatar answered Oct 01 '22 18:10

lkessler


I came here looking for the magic surrounding the leading underscore of functions and procedures in System.pas.

I found the utility tool DCU32INT (that parses *.dcu file and converts it into a close to Pascal form), also on github. It allows you to see both the buildin compiler defined functions that you are looking for, for example

function BlockRead

as well as the magic ones seen in the sources of system.pas, like

function _BlockRead

The functions which shows up from the .dcu file with a leading "@" sign (local symbol?) as:

function @BlockRead

like image 28
David Dyck Avatar answered Oct 01 '22 19:10

David Dyck


this is offical list of magic functions. Good luck about types and constants!

like image 10
Serguzest Avatar answered Nov 11 '22 00:11

Serguzest


It seemed a shame that no one has decided to make one so I will. I can't claim this is a comprehensive list. Its merely what I've been able to glean from either the documentation or by examining the source for missing identifiers. If you notice an omission feel free to edit the answer.

Conditional Symbols

Many conditional symbols vary depending on the compiler's version and targeted platform but the following should be defined regardless of version or platform:

  • DCC
  • VER<nnn>

Constants

  • CompilerVersion
  • MaxInt
  • MaxLongint

Routines

  • Abs
  • Addr
  • Append
  • Assert
  • Assigned
  • Assign
  • AssignFile
  • BlockRead
  • BlockWrite
  • Break
  • Chr
  • Close
  • CloseFile
  • Concat
  • Continue
  • Copy
  • Dec
  • Dispose
  • Eof
  • Eoln
  • Erase
  • Exclude
  • Exit
  • FilePos
  • FileSize
  • FillChar
  • Finalize
  • Flush
  • FreeMem
  • Halt
  • Hi
  • High
  • Inc
  • Include
  • Initialize
  • Insert
  • Length
  • Lo
  • Low
  • New
  • Odd
  • Pi
  • Pred
  • Ptr
  • Read
  • Readln
  • ReallocMem
  • Rename
  • Reset
  • Rewrite
  • Round
  • RunError
  • Seek
  • SeekEof
  • SeekEoln
  • SetLength
  • SetString
  • SizeOf
  • Slice
  • Sqr
  • Str
  • Succ
  • Swap
  • Trunc
  • TypeHandle
  • TypeInfo
  • TypeOf
  • Val
  • VarCast
  • VarCopy
  • Write
  • Writeln

Here's one that appears to apply only to linux (at least in the version I'm using):

  • open It is referenced in SysUtils.FileCreate but there is no open function with that signature defined anywhere in the code base. System.__open has the same signature and points to the libc open function but is not referenced outside the System unit so the compiler must be doing more "magic" to resolve open to __open.

Types

  • AnsiChar
  • Boolean
  • Byte
  • ByteBool
  • Cardinal
  • Char
  • Comp
  • Currency
  • Double
  • Extended
  • Int64
  • Integer
  • LongBool
  • Longint
  • Longword
  • NativeInt
  • NativeUInt
  • OleVariant
  • Pointer
  • Real
  • Real48
  • ShortInt
  • ShortString
  • Single
  • SmallInt
  • string (reserved word but you can "Ctrl+Click" on it if you write System.string)
  • Text
  • TextFile
  • UInt64
  • UnicodeString
  • Variant
  • WideChar
  • WideString
  • WordBool
like image 7
Kenneth Cochran Avatar answered Nov 11 '22 01:11

Kenneth Cochran


Some of the internally defined types can be found a little further down in System.pas (around line 90 in the version shipped with Delphi 2010 Update 4). You can find them easily with a search on "built-in types"; there's a list of {$EXTERNALSYM} declarations for C++Builder where things like String, AnsiString, etc. can be found.

As far as the procedures and functions, I don't know of any list anywhere. Allen Bauer or Barry Kelly might find this and be able to help, though.

like image 4
Ken White Avatar answered Nov 10 '22 23:11

Ken White


The list of types and consts is also not official, but can be deduced from the System.pas sources if you have them. It also depends on the kind of compiler (support for Unicode, Kylix, .NET, etc.).

This is the relevant portion from the Delphi 2010 System.pas:

{$EXTERNALSYM CompilerVersion}

{$EXTERNALSYM Boolean     'bool'             } {$OBJTYPENAME Boolean    'Bo'}
{$NODEFINE    ShortInt    'ShortInt'         } {$OBJTYPENAME ShortInt   'Bzc'} { signed char }
{-EXTERNALSYM ShortInt    'signed char'      } {-OBJTYPENAME ShortInt   'Bzc'}
{$EXTERNALSYM SmallInt    'short'            } {$OBJTYPENAME SmallInt   'Bs'}
{$EXTERNALSYM Integer     'int'              } {$OBJTYPENAME Integer    'Bi'}
{$NODEFINE    Byte        'Byte'             } {$OBJTYPENAME Byte       'Buc'} { unsigned char }
{$NODEFINE    Word        'Word'             } {$OBJTYPENAME Word       'Bus'} { unsigned short }
{$EXTERNALSYM Cardinal    'unsigned'         } {$OBJTYPENAME Cardinal   'Bui'}
{$EXTERNALSYM Int64       '__int64'          } {$OBJTYPENAME Int64      'Bj'}
{$EXTERNALSYM UInt64      'unsigned __int64' } {$OBJTYPENAME UInt64     'Buj'}
{$EXTERNALSYM NativeInt   'int'              } {$OBJTYPENAME NativeInt  'Bi'}
{$EXTERNALSYM NativeUInt  'unsigned'         } {$OBJTYPENAME NativeUInt 'Bui'}
{$EXTERNALSYM Single      'float'            } {$OBJTYPENAME Single     'Bf'}
{$EXTERNALSYM Double      'double'           } {$OBJTYPENAME Double     'Bd'}
{$NODEFINE    Extended    'Extended'         } {$OBJTYPENAME Extended   'Bg'} { long double }
{$NODEFINE    Currency    'Currency'    'CurrencyBase'    } {$OBJTYPENAME Currency    'NCurrency'}
{$NODEFINE    Comp        'Comp'        'CompBase'        } {$OBJTYPENAME Comp        'NComp'}
{$EXTERNALSYM Real        'double'                        } {$OBJTYPENAME Real        'Bd'}
{$NODEFINE    ShortString 'ShortString' 'ShortStringBase' } {$OBJTYPENAME ShortString 'N%SmallString$iuc$255%'}
{$NODEFINE    OpenString  'OpenString'       } {$OBJTYPENAME OpenString 'Bxpc'} { char * const }
{$NODEFINE    File        'file'             } {$OBJTYPENAME File       'Nfile'}
{$NODEFINE    Text        'TextFile'         } {$OBJTYPENAME Text       'NTextfile'}
{$NODEFINE    ByteBool    'ByteBool'         } {$OBJTYPENAME ByteBool   'Buc'} { unsigned char }
{$NODEFINE    WordBool    'WordBool'         } {$OBJTYPENAME WordBool   'Bus'} { unsigned short }
{$EXTERNALSYM LongBool    'BOOL'             } {$OBJTYPENAME LongBool   'Bi'}  { int } { from windef.h }
{$NODEFINE    Real48      } { not supported in C++ }
{$EXTERNALSYM Pointer     'void *'    }
{$NODEFINE    PWideChar   'WideChar *'}
{$EXTERNALSYM PAnsiChar   'char *'    }
{$NODEFINE    Variant     } { defined in sysvari.h }
{$NODEFINE    OleVariant  } { defined in sysvari.h }
{$NODEFINE    LongInt     } { alias of Integer     }
{$NODEFINE    LongWord    } { alias of Cardinal    }
{$NODEFINE    TextFile    } { alias of Text        }
{$IFDEF UNICODE}
  {$EXTERNALSYM AnsiChar     'char'          } {$OBJTYPENAME AnsiChar 'Bc'}
  {$IFDEF LINUX}
    {$NODEFINE  Char         'WideChar'      } {$OBJTYPENAME Char     'Bus'} { unsigned short }
                                               {-OBJTYPENAME Char     'BCs'} { char16_t }
  {$ELSE}
    {$NODEFINE  Char         'WideChar'      } {$OBJTYPENAME Char     'Bb'}  { wchar_t }
                                               {-OBJTYPENAME Char     'BCs'} { char16_t }
  {$ENDIF}
  {$NODEFINE    string       'UnicodeString' } {$OBJTYPENAME string   'NUnicodeString'} { defined in vcl/ustring.h }
  {-NODEFINE    string       'String'        } {$OBJTYPENAME string   'NUnicodeString'} { defined in vcl/ustring.h }
  {$NODEFINE    AnsiString   } { defined in vcl/dstring.h }
  {$NODEFINE    WideString   } { defined in vcl/wstring.h }
  {$NODEFINE    PChar        } { alias of PWideChar  }
  {$NODEFINE    WideChar     } { alias of Char       }
  {$NODEFINE    UnicodeString} { alias of string     }
{$ELSE}
  {$EXTERNALSYM Char         'char'          } {$OBJTYPENAME Char     'Bc'}
  {$IFDEF LINUX}
    {$NODEFINE  WideChar     'WideChar'      } {$OBJTYPENAME WideChar 'Bus'} { unsigned short }
                                               {-OBJTYPENAME WideChar 'BCs'} { char16_t }
  {$ELSE}
    {$NODEFINE  WideChar     'WideChar'      } {$OBJTYPENAME WideChar 'Bb'}  { wchar_t }
                                               {-OBJTYPENAME WideChar 'BCs'} { char16_t }
  {$ENDIF}
  {$NODEFINE    string       'AnsiString'    } { defined in vcl/dstring.h }
  {-NODEFINE    string       'String'        } { defined in vcl/dstring.h }
  {$NODEFINE    WideString   } { defined in vcl/wstring.h }
  {$NODEFINE    UnicodeString} { defined in vcl/ustring.h }
  {$NODEFINE    PChar        } { alias of PAnsiChar  }
  {$NODEFINE    AnsiChar     } { alias of Char       }
  {$NODEFINE    AnsiString   } { alias of string     }
{$ENDIF}

--jeroen

like image 3
Jeroen Wiert Pluimers Avatar answered Nov 11 '22 01:11

Jeroen Wiert Pluimers