fcl-passrc: parser: parse dot after [] operators

git-svn-id: trunk@37251 -
This commit is contained in:
Mattias Gaertner 2017-09-18 18:18:27 +00:00
parent ce332eb2e2
commit 4a4f143d0c
3 changed files with 60 additions and 10 deletions

View File

@ -1850,7 +1850,7 @@ begin
PClose:=tkBraceClose;
end;
params:=TParamsExpr(CreateElement(TParamsExpr,'',AParent));
params:=TParamsExpr(CreateElement(TParamsExpr,'',AParent,CurTokenPos));
try
params.Kind:=paramskind;
NextToken;
@ -2061,7 +2061,8 @@ begin
NextToken;
if (CurToken=tkIdentifier) then
begin
b:=CreateBinaryExpr(AParent,Last, DoParseExpression(AParent), eopNone);
SrcPos:=CurTokenPos;
b:=CreateBinaryExpr(AParent,Last, DoParseExpression(AParent), eopNone,SrcPos);
if not Assigned(b.right) then
begin
b.Release;
@ -2328,18 +2329,17 @@ begin
x:=CreateUnaryExpr(AParent,x, TokenToExprOp(tkCaret));
NextToken;
end;
// ToDo: move dot below []
// for expressions like (PChar(a)+10)[0];
if (x<>Nil) and (CurToken=tkSquaredBraceOpen) then
begin
x:=ParseParams(x,pekArrayParams,False);
end;
// for expressions like (TObject(m)).Free;
if (x<>Nil) and (CurToken=tkDot) then
begin
NextToken;
x:=CreateBinaryExpr(AParent,x, ParseExpIdent(AParent), TokenToExprOp(tkDot));
end;
// for expressions like (PChar(a)+10)[0];
if (x<>Nil) and (CurToken=tkSquaredBraceOpen) then
begin
x:=ParseParams(x,pekArrayParams,False);
end;
end
else
begin

View File

@ -4740,7 +4740,7 @@ begin
else
Name:=CreateReferencePath(Decl,AContext,rpkPathAndName,false,Ref);
if Result=nil then
Result:=CreatePrimitiveDotExpr(Name);
Result:=CreatePrimitiveDotExpr(Name,El);
if ImplicitCall then
begin
@ -5733,6 +5733,8 @@ begin
AContext.Access:=caRead;
if Call.Expr=nil then
Call.Expr:=ConvertElement(El.Value,AContext);
//if Call.Expr is TPrimitiveExpr then
// writeln('TPasToJSConverter.ConvertFuncParams ',TPrimitiveExpr(Call.Expr).GetDeclaration(true));
if Call.Args=nil then
begin
// append ()

View File

@ -56,7 +56,10 @@ type
procedure TestEmptyProgram;
procedure TestEmptyUnit;
procedure TestIf;
procedure TestIfBegin;
procedure TestFor;
procedure TestFunction;
procedure Test;
end;
implementation
@ -235,7 +238,28 @@ begin
' i:=3456;',
'']);
ConvertProgram;
CheckSrcMap('TestEmptyProgram');
CheckSrcMap('TestIf');
end;
procedure TTestSrcMap.TestIfBegin;
begin
StartProgram(false);
Add([
'var',
' E, P: String;',
'begin',
' E:=''bla'';',
' if E=P then',
' begin',
' E:=''active'';',
' end',
' else',
' begin',
' E:=''inactive'';',
' end;',
'']);
ConvertProgram;
CheckSrcMap('TestIfBegin');
end;
procedure TTestSrcMap.TestFor;
@ -251,6 +275,30 @@ begin
CheckSrcMap('TestEmptyProgram');
end;
procedure TTestSrcMap.TestFunction;
begin
StartProgram(false);
Add([
'function DoIt(i: longint): longint;',
'var Runner, j: longint;',
'begin',
' j:=0;',
' for Runner := 1 to j do',
' inc(j);',
' Result:=j;',
'end;',
'begin',
' DoIt(2);',
'']);
ConvertProgram;
CheckSrcMap('TestFunction');
end;
procedure TTestSrcMap.Test;
begin
end;
Initialization
RegisterTests([TTestSrcMap]);