* IF condition expression is now a real expression, not a string

git-svn-id: trunk@22006 -
This commit is contained in:
michael 2012-08-04 09:16:54 +00:00
parent b867010691
commit 2889f22b40
2 changed files with 16 additions and 6 deletions

View File

@ -877,7 +877,7 @@ type
function AddCommands: TPasImplCommands; // used by mkxmlrpc, not by pparser function AddCommands: TPasImplCommands; // used by mkxmlrpc, not by pparser
function AddBeginBlock: TPasImplBeginBlock; function AddBeginBlock: TPasImplBeginBlock;
function AddRepeatUntil: TPasImplRepeatUntil; function AddRepeatUntil: TPasImplRepeatUntil;
function AddIfElse(const ACondition: string): TPasImplIfElse; function AddIfElse(const ACondition: TPasExpr): TPasImplIfElse;
function AddWhileDo(const ACondition: string): TPasImplWhileDo; function AddWhileDo(const ACondition: string): TPasImplWhileDo;
function AddWithDo(const Expression: string): TPasImplWithDo; function AddWithDo(const Expression: string): TPasImplWithDo;
function AddCaseOf(const Expression: string): TPasImplCaseOf; function AddCaseOf(const Expression: string): TPasImplCaseOf;
@ -933,9 +933,10 @@ type
procedure AddElement(Element: TPasImplElement); override; procedure AddElement(Element: TPasImplElement); override;
function CloseOnSemicolon: boolean; override; function CloseOnSemicolon: boolean; override;
public public
Condition: string; ConditionExpr : TPasExpr;
IfBranch: TPasImplElement; IfBranch: TPasImplElement;
ElseBranch: TPasImplElement; // can be nil ElseBranch: TPasImplElement; // can be nil
Function Condition: string;
end; end;
{ TPasImplWhileDo } { TPasImplWhileDo }
@ -1812,6 +1813,7 @@ end;
destructor TPasImplIfElse.Destroy; destructor TPasImplIfElse.Destroy;
begin begin
FreeAndNil(ConditionExpr);
if Assigned(IfBranch) then if Assigned(IfBranch) then
IfBranch.Release; IfBranch.Release;
if Assigned(ElseBranch) then if Assigned(ElseBranch) then
@ -1841,6 +1843,12 @@ begin
Result:=ElseBranch<>nil; Result:=ElseBranch<>nil;
end; end;
function TPasImplIfElse.Condition: string;
begin
If Assigned(ConditionExpr) then
Result:=ConditionExpr.GetDeclaration(True);
end;
destructor TPasImplForLoop.Destroy; destructor TPasImplForLoop.Destroy;
begin begin
if Assigned(Variable) then if Assigned(Variable) then
@ -1908,10 +1916,10 @@ begin
AddElement(Result); AddElement(Result);
end; end;
function TPasImplBlock.AddIfElse(const ACondition: string): TPasImplIfElse; function TPasImplBlock.AddIfElse(const ACondition: TPasExpr): TPasImplIfElse;
begin begin
Result := TPasImplIfElse.Create('', Self); Result := TPasImplIfElse.Create('', Self);
Result.Condition := ACondition; Result.ConditionExpr := ACondition;
AddElement(Result); AddElement(Result);
end; end;

View File

@ -3061,9 +3061,11 @@ begin
end; end;
tkIf: tkIf:
begin begin
Condition:=ParseExpression(CurBlock); NextToken;
Left:=DoParseExpression(CurBlock);
UNgettoken;
el:=TPasImplIfElse(CreateElement(TPasImplIfElse,'',CurBlock)); el:=TPasImplIfElse(CreateElement(TPasImplIfElse,'',CurBlock));
TPasImplIfElse(el).Condition:=Condition; TPasImplIfElse(el).ConditionExpr:=Left;
//WriteLn(i,'IF Condition="',Condition,'" Token=',CurTokenText); //WriteLn(i,'IF Condition="',Condition,'" Token=',CurTokenText);
CreateBlock(TPasImplIfElse(el)); CreateBlock(TPasImplIfElse(el));
ExpectToken(tkthen); ExpectToken(tkthen);