Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple spaces after IFDEF is causing defect #269

Open
sglienke opened this issue Sep 18, 2018 · 4 comments
Open

Multiple spaces after IFDEF is causing defect #269

sglienke opened this issue Sep 18, 2018 · 4 comments

Comments

@sglienke
Copy link
Contributor

sglienke commented Sep 18, 2018

Following code is a simplified test case for this defect - originally found when trying to parse System.pas from Delphi 10.2

unit Unit1;

interface

implementation

procedure Foo;
{$IFDEF  CPUX86}
begin
end;
{$ENDIF}

initialization

end.

I traced it down to TmwBasePasLex.GetDirectiveParam returning the string with a leading space character in this case.

@sglienke
Copy link
Contributor Author

I fixed this by changing the before mentioned method as follows:

-  if FBuffer.Buf[TempRun] = ' ' then Inc(TempRun);
+  while FBuffer.Buf[TempRun] = ' ' do Inc(TempRun);
+  while FBuffer.Buf[EndPos - 1] = ' ' do Dec(EndPos);

Only the first added line is in fact necessary to make System.pas being parsed again but I added the second one to see if that fixes any trailing spaces.

However there are more defects like this. For example following code still fails because of the implementation of TmwBasePasLex.EvaluateConditionalExpression.

unit Unit1;

interface

implementation

procedure Foo;
{$IF defined( CPUX86 )}
begin
end;
{$ENDIF}

initialization

end.

I think this will also fail because of tabs which is why I am not proposing some pull request for this because my fixes are just incomplete.

@JBontes
Copy link

JBontes commented Nov 2, 2018

Why not just do:

while CharInSet(FBuffer.Buf[TempRun], whitespace) do Inc(TempRun);
while CharInSet(FBuffer.Buf[EndPos - 1], whitespace) do Dec(EndPos);

Where whitespace is [#32,#9,#10,#13] and whatever else happens to qualify.
Not sure about unicode issues though.

@sglienke
Copy link
Contributor Author

Why not just do:

while CharInSet(FBuffer.Buf[TempRun], whitespace) do Inc(TempRun);
while CharInSet(FBuffer.Buf[EndPos - 1], whitespace) do Dec(EndPos);

Where whitespace is [#32,#9,#10,#13] and whatever else happens to qualify.
Not sure about unicode issues though.

Simple, because IFDEF cannot span multiple lines. I mentioned tabs because I noticed but there are also not handled in some other places where they should be valid so I would not address that one in the context of this particular issue.

@bogdanpolak
Copy link

@RomanYankovsky it look like Resolved. Maybe time to close the issue? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants