Browse Source

* Fix bug ID #31700: asm block in If..Then

git-svn-id: trunk@35915 -
michael 8 years ago
parent
commit
6f951e7be9
2 changed files with 33 additions and 5 deletions
  1. 13 3
      packages/fcl-passrc/src/pparser.pp
  2. 20 2
      packages/fcl-passrc/tests/tcstatements.pas

+ 13 - 3
packages/fcl-passrc/src/pparser.pp

@@ -4159,6 +4159,12 @@ procedure TPasParser.ParseAsmBlock(AsmBlock: TPasImplAsmStatement);
 Var
   LastToken : TToken;
 
+  Function atEndofAsm : Boolean;
+
+  begin
+    Result:=(CurToken=tkEnd) and (LastToken<>tkAt);
+  end;
+
 begin
   if po_asmwhole in Options then
     begin
@@ -4193,9 +4199,8 @@ begin
     begin
     LastToken:=tkEOF;
     NextToken;
-    While Not ((CurToken=tkEnd) and (LastToken<>tkAt)) do
+    While Not AtEndOfAsm do
       begin
-      // ToDo: allow @@end
       AsmBlock.Tokens.Add(CurTokenText);
       LastToken:=CurToken;
       NextToken;
@@ -4276,7 +4281,7 @@ begin
       ParseAsmBlock(TPasImplAsmStatement(El));
       CurBlock.AddElement(El);
       if NewImplElement=nil then NewImplElement:=CurBlock;
-      if CloseStatement(true) then
+      if CloseStatement(False) then
         break;
       end;
     tkbegin:
@@ -4345,6 +4350,11 @@ begin
         //if .. then Raise Exception else ..
         CloseBlock;
         UngetToken;
+      end else if (CurBlock is TPasImplAsmStatement) then
+      begin
+        //if .. then asm end else ..
+        CloseBlock;
+        UngetToken;
       end else if (CurBlock is TPasImplTryExcept) then
       begin
         CloseBlock;

+ 20 - 2
packages/fcl-passrc/tests/tcstatements.pas

@@ -113,7 +113,8 @@ Type
     procedure TestTryExceptRaise;
     Procedure TestAsm;
     Procedure TestAsmBlock;
-    Procedure TestAdmBlockWithEndLabel;
+    Procedure TestAsmBlockWithEndLabel;
+    Procedure TestAsmBlockInIfThen;
     Procedure TestGotoInIfThen;
     procedure AssignToAddress;
   end;
@@ -1661,7 +1662,7 @@ begin
   ParseModule;
 end;
 
-procedure TTestStatementParser.TestAdmBlockWithEndLabel;
+procedure TTestStatementParser.TestAsmBlockWithEndLabel;
 begin
   Source.Add('{$MODE DELPHI}');
   Source.Add('function BitsHighest(X: Cardinal): Integer;');
@@ -1678,6 +1679,23 @@ begin
   ParseModule;
 end;
 
+procedure TTestStatementParser.TestAsmBlockInIfThen;
+begin
+  Source.Add('{$MODE DELPHI}');
+  Source.Add('function Get8087StatusWord(ClearExceptions: Boolean): Word;');
+  Source.Add('  begin');
+  Source.Add('    if ClearExceptions then');
+  Source.Add('    asm');
+  Source.Add('    end');
+  Source.Add('    else');
+  Source.Add('    asm');
+  Source.Add('    end;');
+  Source.Add('  end;');
+  Source.Add('  begin');
+  Source.Add('  end.');
+  ParseModule;
+end;
+
 Procedure TTestStatementParser.AssignToAddress;
 
 begin