Last week I asked for a list of Delphi parsers/lexers, to analyze Pascal/Delphi files. One of the solutions named, and by far the best one, was the Castalia Delphi Parser. After playing with it a while I started to see what it really can do. While it is not the easiest to use, it goes a long way. However, I ran into some wall. Files like Windows.pas and System.pas from the original Delphi distribution (checked against Delphi 2007) cannot be parsed with it.
For Windows.Pas, it stops on the declaration of the type DWORD.
type { Translated from WINDEF.H } WCHAR = WideChar; {$EXTERNALSYM WCHAR} PWChar = PWideChar; LPSTR = PAnsiChar; {$EXTERNALSYM LPSTR} PLPSTR = ^LPSTR; {$EXTERNALSYM PLPSTR} LPCSTR = PAnsiChar; {$EXTERNALSYM LPCSTR} LPCTSTR = PAnsiChar; {$EXTERNALSYM LPCTSTR} LPTSTR = PAnsiChar; {$EXTERNALSYM LPTSTR} LPWSTR = PWideChar; {$EXTERNALSYM LPWSTR} PLPWSTR = ^LPWSTR; {$EXTERNALSYM PLPWSTR} LPCWSTR = PWideChar; {$EXTERNALSYM LPCWSTR} DWORD = Types.DWORD; {$EXTERNALSYM DWORD}
type
{ Translated from WINDEF.H }
{$EXTERNALSYM WCHAR}
{$EXTERNALSYM LPSTR}
{$EXTERNALSYM PLPSTR}
{$EXTERNALSYM LPCSTR}
{$EXTERNALSYM LPCTSTR}
{$EXTERNALSYM LPTSTR}
{$EXTERNALSYM LPWSTR}
{$EXTERNALSYM PLPWSTR}
{$EXTERNALSYM LPCWSTR}
{$EXTERNALSYM DWORD}
In System.pas it stops, because it cannot handle {$IFDEF} blocks very well. When coming to the second time when unwind is declared (this time for Linux) it stops, because it needs a new const before it.
const {$IFDEF MSWINDOWS} unwind = 'unwind.dll'; type UNWINDelphi-PRAXiSROC = Pointer; function UnwindRegisterIPLookup(fn: UNWINDelphi-PRAXiSROC; StartAddr, EndAddr: LongInt; Context: Pointer; GOT: LongInt): LongBool; cdecl; external unwind name '__BorUnwind_RegisterIPLookup'; function UnwindDelphiLookup(Addr: LongInt; Context: Pointer): UNWINDelphi-PRAXiSROC; cdecl; external unwind name '__BorUnwind_DelphiLookup'; function UnwindRaiseException(Exc: Pointer): LongBool; cdecl; external unwind name '__BorUnwind_RaiseException'; function UnwindClosestHandler(Context: Pointer): LongWord; cdecl; external unwind name '__BorUnwind_ClosestDelphiHandler'; {$ENDIF} {$IFDEF LINUX} unwind = 'libborunwind.so.6';
const
{$IFDEF MSWINDOWS}
'unwind.dll'
function
cdecl
external
'__BorUnwind_RegisterIPLookup'
'__BorUnwind_DelphiLookup'
'__BorUnwind_RaiseException'
'__BorUnwind_ClosestDelphiHandler'
{$ENDIF}
{$IFDEF LINUX}
'libborunwind.so.6'
Do you have a solution for those problems, or do you now another parser/lexer which will help me along.
Thanks and a Happy New Year,Daniel
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Theme design by Jelle Druyts