浏览代码

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

git-svn-id: trunk@22006 -
michael 13 年之前
父节点
当前提交
2889f22b40
共有 2 个文件被更改,包括 16 次插入6 次删除
  1. 12 4
      packages/fcl-passrc/src/pastree.pp
  2. 4 2
      packages/fcl-passrc/src/pparser.pp

+ 12 - 4
packages/fcl-passrc/src/pastree.pp

@@ -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;
 
 

+ 4 - 2
packages/fcl-passrc/src/pparser.pp

@@ -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);