Working with the Castalia Delphi Parser#

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}

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';

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

Friday, December 28, 2007 4:34:08 PM (W. Europe Standard Time, UTC+01:00) #    Comments [0]  | 

 

Google AdSense


Comments are closed.
All content © 2008, Daniel Wischnewski
On this page
Archives
Promoted Links
Blogroll OPML
My current Flickr Images
www.flickr.com
Dies ist ein Flickr Modul mit �ffentlichen Fotos und Videos von dwischnewski. Ihr eigenes Modul k�nnen Sie hier erstellen.
Recommendations
Sitemap
Special Pages
Disclaimer

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