RomanYankovsky / DelphiAST

Abstract syntax tree builder for Delphi
Mozilla Public License 2.0
275 stars 117 forks source link

Can't parse System.Classes.pas #276

Open chuacw opened 5 years ago

chuacw commented 5 years ago

When attempting to parse the RTL's System.Classes.pas in "C:\Program Files (x86)\Embarcadero\Studio\20.0\source\rtl\System.Classes.pas" throws the error: First chance exception at $7744C5AF. Exception class EParserException with message ''Begin' expected found 'initialization''. Process ProjectIndexerResearch.exe (1936)

sglienke commented 3 years ago

This issue is still the case and I found the cause:

DelphiAST cannot handle $IF SizeOf which makes it trip on TMemoryStream.SetCapacity which has two $IF checking SizeOf(LongInt) but no else causing all following routine being treated as nested to that method and eventually failing when arriving at initialization.

bogdanpolak commented 2 years ago

@RomanYankovsky I'd suggest adding help wanted label if you are open for the PR

sglienke commented 2 weeks ago

Snippet for DelphiASTTest would be this:

unit if_sizeof;

interface

implementation

procedure test;
{$if sizeof(integer) = 4}
begin
end;
{$ifend}

end.
sglienke commented 2 weeks ago

There are actually some more things that DelphiAST does not understand when it comes to conditionals - for example it is possible to write {$if declared(some_symbol)} - this in the current state is completely impossible to resolve. These are used throughout the code that ships with Delphi but most of the time evaluating those as False (see TmwBasePasLex.EvaluateConditionalExpression) does not cause a parsing error.