mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-01 14:10:32 +02:00
* Some small fixes so sdo is parsed
git-svn-id: trunk@22210 -
This commit is contained in:
parent
926d39e604
commit
2252b71ae9
@ -104,6 +104,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPasSrcAnalysis.CheckParser;
|
procedure TPasSrcAnalysis.CheckParser;
|
||||||
|
|
||||||
|
Var
|
||||||
|
D : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
If (FParser<>Nil) then
|
If (FParser<>Nil) then
|
||||||
exit;
|
exit;
|
||||||
@ -115,11 +119,16 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
FResolver:=TFileResolver.Create;
|
FResolver:=TFileResolver.Create;
|
||||||
FResolver.BaseDirectory:=ExtractFilePath(Filename);
|
D:=ExtractFilePath(FileName);
|
||||||
|
If (D='') then
|
||||||
|
D:='.';
|
||||||
|
FResolver.BaseDirectory:=D;
|
||||||
|
FResolver.AddIncludePath(D);
|
||||||
FScanner:=TPascalScanner.Create(FResolver);
|
FScanner:=TPascalScanner.Create(FResolver);
|
||||||
FScanner.OpenFile(FileName);
|
FScanner.OpenFile(FileName);
|
||||||
FContainer:=TSrcContainer.Create;
|
FContainer:=TSrcContainer.Create;
|
||||||
FParser:=TPasParser.Create(FScanner,FResolver,FContainer);
|
FParser:=TPasParser.Create(FScanner,FResolver,FContainer);
|
||||||
|
FScanner.AddDefine('FPC');
|
||||||
except
|
except
|
||||||
FreeParser;
|
FreeParser;
|
||||||
Raise;
|
Raise;
|
||||||
|
@ -115,6 +115,7 @@ type
|
|||||||
|
|
||||||
|
|
||||||
TExprKind = (ek_Normal, ek_PropertyIndex);
|
TExprKind = (ek_Normal, ek_PropertyIndex);
|
||||||
|
TIndentAction = (iaNone,iaIndent,iaUndent);
|
||||||
|
|
||||||
{ TPasParser }
|
{ TPasParser }
|
||||||
|
|
||||||
@ -134,8 +135,9 @@ type
|
|||||||
FTokenStringBuffer: array[0..1] of String;
|
FTokenStringBuffer: array[0..1] of String;
|
||||||
FTokenBufferIndex: Integer; // current index in FTokenBuffer
|
FTokenBufferIndex: Integer; // current index in FTokenBuffer
|
||||||
FTokenBufferSize: Integer; // maximum valid index in FTokenBuffer
|
FTokenBufferSize: Integer; // maximum valid index in FTokenBuffer
|
||||||
|
FDumpIndent : String;
|
||||||
function CheckOverloadList(AList: TFPList; AName: String; out OldMember: TPasElement): TPasOverloadedProc;
|
function CheckOverloadList(AList: TFPList; AName: String; out OldMember: TPasElement): TPasOverloadedProc;
|
||||||
procedure DumpCurToken(Const Msg : String);
|
procedure DumpCurToken(Const Msg : String; IndentAction : TIndentAction = iaNone);
|
||||||
function GetVariableModifiers(Out VarMods : TVariableModifiers; Out Libname,ExportName : string): string;
|
function GetVariableModifiers(Out VarMods : TVariableModifiers; Out Libname,ExportName : string): string;
|
||||||
function GetVariableValueAndLocation(Parent : TPasElement; Out Value : TPasExpr; Out Location: String): Boolean;
|
function GetVariableValueAndLocation(Parent : TPasElement; Out Value : TPasExpr; Out Location: String): Boolean;
|
||||||
procedure HandleProcedureModifier(Parent: TPasElement; pm : TProcedureModifier);
|
procedure HandleProcedureModifier(Parent: TPasElement; pm : TProcedureModifier);
|
||||||
@ -1187,7 +1189,8 @@ begin
|
|||||||
//x:=TPrimitiveExpr.Create(AParent,pekString, CurTokenText); //function(self);
|
//x:=TPrimitiveExpr.Create(AParent,pekString, CurTokenText); //function(self);
|
||||||
x:=TSelfExpr.Create(AParent);
|
x:=TSelfExpr.Create(AParent);
|
||||||
NextToken;
|
NextToken;
|
||||||
if CurToken = tkDot then begin // self.Write(EscapeText(AText));
|
if CurToken = tkDot then
|
||||||
|
begin // self.Write(EscapeText(AText));
|
||||||
optk:=CurToken;
|
optk:=CurToken;
|
||||||
NextToken;
|
NextToken;
|
||||||
b:=TBinaryExpr.Create(AParent,x, ParseExpIdent(AParent), TokenToExprOp(optk));
|
b:=TBinaryExpr.Create(AParent,x, ParseExpIdent(AParent), TokenToExprOp(optk));
|
||||||
@ -1196,9 +1199,9 @@ begin
|
|||||||
B.Free;
|
B.Free;
|
||||||
Exit; // error
|
Exit; // error
|
||||||
end;
|
end;
|
||||||
x:=b;
|
x:=b;
|
||||||
end
|
end;
|
||||||
else UngetToken;
|
UngetToken;
|
||||||
end;
|
end;
|
||||||
tkAt: begin
|
tkAt: begin
|
||||||
// P:=@function;
|
// P:=@function;
|
||||||
@ -1280,6 +1283,8 @@ end;
|
|||||||
function TPasParser.OpLevel(t: TToken): Integer;
|
function TPasParser.OpLevel(t: TToken): Integer;
|
||||||
begin
|
begin
|
||||||
case t of
|
case t of
|
||||||
|
// tkDot:
|
||||||
|
// Result:=5;
|
||||||
tknot,tkAt:
|
tknot,tkAt:
|
||||||
Result:=4;
|
Result:=4;
|
||||||
tkMul, tkDivision, tkdiv, tkmod, tkand, tkShl,tkShr, tkas, tkPower :
|
tkMul, tkDivision, tkdiv, tkmod, tkand, tkShl,tkShr, tkas, tkPower :
|
||||||
@ -1305,7 +1310,7 @@ var
|
|||||||
|
|
||||||
const
|
const
|
||||||
PrefixSym = [tkPlus, tkMinus, tknot, tkAt]; // + - not @
|
PrefixSym = [tkPlus, tkMinus, tknot, tkAt]; // + - not @
|
||||||
BinaryOP = [tkMul, tkDivision, tkdiv, tkmod, tkDotDot,
|
BinaryOP = [tkMul, tkDivision, tkdiv, tkmod, tkDotDot,
|
||||||
tkand, tkShl,tkShr, tkas, tkPower,
|
tkand, tkShl,tkShr, tkas, tkPower,
|
||||||
tkPlus, tkMinus, tkor, tkxor, tkSymmetricalDifference,
|
tkPlus, tkMinus, tkor, tkxor, tkSymmetricalDifference,
|
||||||
tkEqual, tkNotEqual, tkLessThan, tkLessEqualThan,
|
tkEqual, tkNotEqual, tkLessThan, tkLessEqualThan,
|
||||||
@ -1350,6 +1355,7 @@ const
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
//DumpCurToken('Entry',iaIndent);
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
expstack := TFPList.Create;
|
expstack := TFPList.Create;
|
||||||
opstack := TFPList.Create;
|
opstack := TFPList.Create;
|
||||||
@ -1358,7 +1364,7 @@ begin
|
|||||||
NotBinary:=True;
|
NotBinary:=True;
|
||||||
pcount:=0;
|
pcount:=0;
|
||||||
if not Assigned(InitExpr) then
|
if not Assigned(InitExpr) then
|
||||||
begin
|
begin
|
||||||
// the first part of the expression has been parsed externally.
|
// the first part of the expression has been parsed externally.
|
||||||
// this is used by Constant Expresion parser (CEP) parsing only,
|
// this is used by Constant Expresion parser (CEP) parsing only,
|
||||||
// whenever it makes a false assuming on constant expression type.
|
// whenever it makes a false assuming on constant expression type.
|
||||||
@ -1372,13 +1378,15 @@ begin
|
|||||||
//
|
//
|
||||||
// quite ugly. type information is required for CEP to work clean
|
// quite ugly. type information is required for CEP to work clean
|
||||||
|
|
||||||
while CurToken in PrefixSym do begin
|
while CurToken in PrefixSym do
|
||||||
|
begin
|
||||||
PushOper(CurToken);
|
PushOper(CurToken);
|
||||||
inc(pcount);
|
inc(pcount);
|
||||||
NextToken;
|
NextToken;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if CurToken = tkBraceOpen then begin
|
if (CurToken = tkBraceOpen) then
|
||||||
|
begin
|
||||||
NextToken;
|
NextToken;
|
||||||
x:=DoParseExpression(AParent);
|
x:=DoParseExpression(AParent);
|
||||||
if CurToken<>tkBraceClose then
|
if CurToken<>tkBraceClose then
|
||||||
@ -1387,21 +1395,27 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
NextToken;
|
NextToken;
|
||||||
|
// DumpCurToken('Here 1');
|
||||||
|
// for the expression like (TObject(m)).Free;
|
||||||
|
if (x<>Nil) and (CurToken=tkDot) then
|
||||||
|
begin
|
||||||
|
NextToken;
|
||||||
|
// DumpCurToken('Here 2');
|
||||||
|
x:=TBinaryExpr.Create(AParent,x, ParseExpIdent(AParent), TokenToExprOp(tkDot));
|
||||||
|
// DumpCurToken('Here 3');
|
||||||
|
end;
|
||||||
|
|
||||||
// for the expression like (TObject(m)).Free;
|
end
|
||||||
if CurToken = tkDot then begin
|
else
|
||||||
NextToken;
|
begin
|
||||||
x:=TBinaryExpr.Create(AParent,x, ParseExpIdent(AParent), TokenToExprOp(tkDot));
|
|
||||||
end;
|
|
||||||
|
|
||||||
end else begin
|
|
||||||
x:=ParseExpIdent(AParent);
|
x:=ParseExpIdent(AParent);
|
||||||
end;
|
end;
|
||||||
|
if not Assigned(x) then
|
||||||
if not Assigned(x) then Exit;
|
Exit;
|
||||||
expstack.Add(x);
|
expstack.Add(x);
|
||||||
|
|
||||||
for i:=1 to pcount do begin
|
for i:=1 to pcount do
|
||||||
|
begin
|
||||||
tempop:=PopOper;
|
tempop:=PopOper;
|
||||||
x:=popexp;
|
x:=popexp;
|
||||||
if (tempop=tkMinus) and (X.Kind=pekRange) then
|
if (tempop=tkMinus) and (X.Kind=pekRange) then
|
||||||
@ -1409,16 +1423,17 @@ begin
|
|||||||
TBinaryExpr(x).Left:=TUnaryExpr.Create(x, TBinaryExpr(X).left, eopSubtract);
|
TBinaryExpr(x).Left:=TUnaryExpr.Create(x, TBinaryExpr(X).left, eopSubtract);
|
||||||
expstack.Add(x);
|
expstack.Add(x);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
expstack.Add( TUnaryExpr.Create(AParent, x, TokenToExprOp(tempop) ));
|
expstack.Add( TUnaryExpr.Create(AParent, x, TokenToExprOp(tempop) ));
|
||||||
end;
|
end;
|
||||||
|
end
|
||||||
end else
|
else
|
||||||
begin
|
begin
|
||||||
expstack.Add(InitExpr);
|
expstack.Add(InitExpr);
|
||||||
InitExpr:=nil;
|
InitExpr:=nil;
|
||||||
end;
|
end;
|
||||||
if (CurToken in BinaryOP) then begin
|
if (CurToken in BinaryOP) then
|
||||||
|
begin
|
||||||
// Adjusting order of the operations
|
// Adjusting order of the operations
|
||||||
NotBinary:=False;
|
NotBinary:=False;
|
||||||
tempop:=PeekOper;
|
tempop:=PeekOper;
|
||||||
@ -1428,8 +1443,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
PushOper(CurToken);
|
PushOper(CurToken);
|
||||||
NextToken;
|
NextToken;
|
||||||
end;
|
end;
|
||||||
|
// Writeln('Bin ',NotBinary ,' or EOE ',isEndOfExp, ' Ex ',Assigned(x),' stack ',ExpStack.Count);
|
||||||
until NotBinary or isEndOfExp;
|
until NotBinary or isEndOfExp;
|
||||||
|
|
||||||
if not NotBinary then ParseExc(SParserExpectedIdentifier);
|
if not NotBinary then ParseExc(SParserExpectedIdentifier);
|
||||||
@ -1440,6 +1455,10 @@ begin
|
|||||||
if expstack.Count=1 then Result:=TPasExpr(expstack[0]);
|
if expstack.Count=1 then Result:=TPasExpr(expstack[0]);
|
||||||
|
|
||||||
finally
|
finally
|
||||||
|
{if Not Assigned(Result) then
|
||||||
|
DumpCurToken('Exiting (no result)',iaUndent)
|
||||||
|
else
|
||||||
|
DumpCurtoken('Exiting (Result: "'+Result.GetDeclaration(true)+'") ',iaUndent);}
|
||||||
if not Assigned(Result) then begin
|
if not Assigned(Result) then begin
|
||||||
// expression error!
|
// expression error!
|
||||||
for i:=0 to expstack.Count-1 do
|
for i:=0 to expstack.Count-1 do
|
||||||
@ -3340,6 +3359,8 @@ begin
|
|||||||
NextToken;
|
NextToken;
|
||||||
TPasImplRaise(el).ExceptAddr:=DoParseExpression(el);
|
TPasImplRaise(el).ExceptAddr:=DoParseExpression(el);
|
||||||
end;
|
end;
|
||||||
|
if Curtoken in [tkSemicolon,tkEnd] then
|
||||||
|
UngetToken
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
tkend:
|
tkend:
|
||||||
@ -3547,10 +3568,14 @@ begin
|
|||||||
Until Done;
|
Until Done;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPasParser.DumpCurToken(Const Msg : String);
|
procedure TPasParser.DumpCurToken(Const Msg : String; IndentAction : TIndentAction = iaNone);
|
||||||
begin
|
begin
|
||||||
Writeln(Msg,' : ',TokenInfos[CurToken],' "',CurTokenString,'"',Scanner.CurFilename,'(',Scanner.CurRow,',',SCanner.CurColumn,') : ',Scanner.CurLine);
|
if IndentAction=iaUndent then
|
||||||
Flush(output)
|
FDumpIndent:=copy(FDumpIndent,1,Length(FDumpIndent)-2);
|
||||||
|
Writeln(FDumpIndent,Msg,' : ',TokenInfos[CurToken],' "',CurTokenString,'", Position: ',Scanner.CurFilename,'(',Scanner.CurRow,',',SCanner.CurColumn,') : ',Scanner.CurLine);
|
||||||
|
if IndentAction=iaIndent then
|
||||||
|
FDumpIndent:=FDumpIndent+' ';
|
||||||
|
Flush(output);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Starts on first token after Record or (. Ends on AEndToken
|
// Starts on first token after Record or (. Ends on AEndToken
|
||||||
|
@ -905,7 +905,10 @@ end;
|
|||||||
|
|
||||||
procedure TBaseFileResolver.AddIncludePath(const APath: string);
|
procedure TBaseFileResolver.AddIncludePath(const APath: string);
|
||||||
begin
|
begin
|
||||||
FIncludePaths.Add(IncludeTrailingPathDelimiter(ExpandFileName(APath)));
|
if (APath='') then
|
||||||
|
FIncludePaths.Add('./')
|
||||||
|
else
|
||||||
|
FIncludePaths.Add(IncludeTrailingPathDelimiter(ExpandFileName(APath)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ ---------------------------------------------------------------------
|
{ ---------------------------------------------------------------------
|
||||||
|
@ -118,6 +118,8 @@ type
|
|||||||
Procedure TestPrecedencePlusMod;
|
Procedure TestPrecedencePlusMod;
|
||||||
Procedure TestPrecedenceMultiplyDiv;
|
Procedure TestPrecedenceMultiplyDiv;
|
||||||
Procedure TestPrecedenceDivMultiply;
|
Procedure TestPrecedenceDivMultiply;
|
||||||
|
Procedure TestTypeCast;
|
||||||
|
Procedure TestCreate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -460,6 +462,18 @@ begin
|
|||||||
AssertLeftPrecedence(1,eopDiv,2,eopMultiply,3);
|
AssertLeftPrecedence(1,eopDiv,2,eopMultiply,3);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestExpressions.TestTypeCast;
|
||||||
|
begin
|
||||||
|
DeclareVar('TSDOBaseDataObjectClass');
|
||||||
|
ParseExpression('TSDOBaseDataObjectClass(Self.ClassType).Create');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestExpressions.TestCreate;
|
||||||
|
begin
|
||||||
|
DeclareVar('ESDOSerializationException');
|
||||||
|
ParseExpression('ESDOSerializationException.CreateFmt(SERR_InvalidDataTypeInContext,[IntToStr(Ord(AOwner^.DataType))])');
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TTestExpressions.TestUnaryMinus;
|
procedure TTestExpressions.TestUnaryMinus;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user