* Parse ASM blocks (Bug ID 27117)

git-svn-id: trunk@30625 -
This commit is contained in:
michael 2015-04-17 19:06:11 +00:00
parent faaae8b2a2
commit 7c33165672
3 changed files with 133 additions and 70 deletions

View File

@ -958,6 +958,17 @@ type
TFinalizationSection = class(TPasImplBlock) TFinalizationSection = class(TPasImplBlock)
end; end;
{ TPasImplAsmStatement }
TPasImplAsmStatement = class (TPasImplStatement)
private
FTokens: TStrings;
Public
constructor Create(const AName: string; AParent: TPasElement); override;
destructor Destroy; override;
Property Tokens : TStrings Read FTokens;
end;
{ TPasImplRepeatUntil } { TPasImplRepeatUntil }
TPasImplRepeatUntil = class(TPasImplBlock) TPasImplRepeatUntil = class(TPasImplBlock)
@ -1184,6 +1195,21 @@ implementation
uses SysUtils; uses SysUtils;
{ TPasImplAsmStatement }
constructor TPasImplAsmStatement.Create(const AName: string;
AParent: TPasElement);
begin
inherited Create(AName, AParent);
FTokens:=TStringList.Create;
end;
destructor TPasImplAsmStatement.Destroy;
begin
FreeAndNil(FTokens);
inherited Destroy;
end;
{ TPasClassConstructor } { TPasClassConstructor }
function TPasClassConstructor.TypeName: string; function TPasClassConstructor.TypeName: string;

View File

@ -150,6 +150,7 @@ type
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);
procedure ParseAsmBlock(AsmBlock: TPasImplAsmStatement);
procedure ParseClassLocalConsts(AType: TPasClassType; AVisibility: TPasMemberVisibility); procedure ParseClassLocalConsts(AType: TPasClassType; AVisibility: TPasMemberVisibility);
procedure ParseClassLocalTypes(AType: TPasClassType; AVisibility: TPasMemberVisibility); procedure ParseClassLocalTypes(AType: TPasClassType; AVisibility: TPasMemberVisibility);
procedure ParseVarList(Parent: TPasElement; VarList: TFPList; AVisibility: TPasMemberVisibility; Full: Boolean); procedure ParseVarList(Parent: TPasElement; VarList: TFPList; AVisibility: TPasMemberVisibility; Full: Boolean);
@ -3134,6 +3135,19 @@ begin
// writeln('TPasParser.ParseProcBeginBlock ended ',curtokenstring); // writeln('TPasParser.ParseProcBeginBlock ended ',curtokenstring);
end; end;
procedure TPasParser.ParseAsmBlock(AsmBlock : TPasImplAsmStatement);
begin
NextToken;
While CurToken<>tkEnd do
begin
AsmBlock.Tokens.Add(CurTokenText);
NextToken;
end;
// NextToken; // Eat end.
// Do not consume end. Current token will normally be end;
end;
// Next token is start of (compound) statement // Next token is start of (compound) statement
// After parsing CurToken is on last token of statement // After parsing CurToken is on last token of statement
procedure TPasParser.ParseStatement(Parent: TPasImplBlock; procedure TPasParser.ParseStatement(Parent: TPasImplBlock;
@ -3195,6 +3209,13 @@ begin
NextToken; NextToken;
//WriteLn(i,'Token=',CurTokenText); //WriteLn(i,'Token=',CurTokenText);
case CurToken of case CurToken of
tkasm :
begin
el:=TPasImplElement(CreateElement(TPasImplAsmStatement,'',CurBlock));
ParseAsmBlock(TPasImplAsmStatement(el));
CurBlock.AddElement(el);
NewImplElement:=El;
end;
tkbegin: tkbegin:
begin begin
el:=TPasImplElement(CreateElement(TPasImplBeginBlock,'',CurBlock)); el:=TPasImplElement(CreateElement(TPasImplBeginBlock,'',CurBlock));

View File

@ -92,25 +92,26 @@ Type
Procedure TestTryExceptOn2; Procedure TestTryExceptOn2;
Procedure TestTryExceptOnElse; Procedure TestTryExceptOnElse;
Procedure TestTryExceptOnIfElse; Procedure TestTryExceptOnIfElse;
Procedure TestAsm;
end; end;
implementation implementation
{ TTestStatementParser } { TTestStatementParser }
Procedure TTestStatementParser.SetUp; procedure TTestStatementParser.SetUp;
begin begin
inherited SetUp; inherited SetUp;
FVariables:=TStringList.Create; FVariables:=TStringList.Create;
end; end;
Procedure TTestStatementParser.TearDown; procedure TTestStatementParser.TearDown;
begin begin
FreeAndNil(FVariables); FreeAndNil(FVariables);
inherited TearDown; inherited TearDown;
end; end;
procedure TTestStatementParser.AddStatements(ASource: Array of string); procedure TTestStatementParser.AddStatements(ASource: array of string);
Var Var
I :Integer; I :Integer;
@ -127,8 +128,8 @@ begin
Add(' '+ASource[i]); Add(' '+ASource[i]);
end; end;
Procedure TTestStatementParser.DeclareVar(Const AVarType: String; procedure TTestStatementParser.DeclareVar(const AVarType: String;
Const AVarName: String); const AVarName: String);
begin begin
FVariables.Add(AVarName+' : '+AVarType+';'); FVariables.Add(AVarName+' : '+AVarType+';');
end; end;
@ -138,7 +139,7 @@ begin
Result:=TestStatement([ASource]); Result:=TestStatement([ASource]);
end; end;
function TTestStatementParser.TestStatement(ASource: Array of string function TTestStatementParser.TestStatement(ASource: array of string
): TPasImplElement; ): TPasImplElement;
@ -156,19 +157,19 @@ begin
Result:=FStatement; Result:=FStatement;
end; end;
Procedure TTestStatementParser.ExpectParserError(Const Msg: string); procedure TTestStatementParser.ExpectParserError(const Msg: string);
begin begin
AssertException(Msg,EParserError,@ParseModule); AssertException(Msg,EParserError,@ParseModule);
end; end;
Procedure TTestStatementParser.ExpectParserError(Const Msg: string; procedure TTestStatementParser.ExpectParserError(const Msg: string;
ASource: Array of string); ASource: array of string);
begin begin
AddStatements(ASource); AddStatements(ASource);
ExpectParserError(Msg); ExpectParserError(Msg);
end; end;
Function TTestStatementParser.AssertStatement(Msg: String; AClass: TClass; function TTestStatementParser.AssertStatement(Msg: String; AClass: TClass;
AIndex: Integer): TPasImplBlock; AIndex: Integer): TPasImplBlock;
begin begin
if not (AIndex<PasProgram.InitializationSection.Elements.Count) then if not (AIndex<PasProgram.InitializationSection.Elements.Count) then
@ -178,26 +179,26 @@ begin
Result:=TObject(PasProgram.InitializationSection.Elements[AIndex]) as TPasImplBlock; Result:=TObject(PasProgram.InitializationSection.Elements[AIndex]) as TPasImplBlock;
end; end;
Procedure TTestStatementParser.TestEmpty; procedure TTestStatementParser.TestEmpty;
begin begin
//TestStatement(';'); //TestStatement(';');
TestStatement(''); TestStatement('');
AssertEquals('No statements',0,PasProgram.InitializationSection.Elements.Count); AssertEquals('No statements',0,PasProgram.InitializationSection.Elements.Count);
end; end;
Procedure TTestStatementParser.TestEmptyStatement; procedure TTestStatementParser.TestEmptyStatement;
begin begin
TestStatement(';'); TestStatement(';');
AssertEquals('0 statement',0,PasProgram.InitializationSection.Elements.Count); AssertEquals('0 statement',0,PasProgram.InitializationSection.Elements.Count);
end; end;
Procedure TTestStatementParser.TestEmptyStatements; procedure TTestStatementParser.TestEmptyStatements;
begin begin
TestStatement(';;'); TestStatement(';;');
AssertEquals('0 statement',0,PasProgram.InitializationSection.Elements.Count); AssertEquals('0 statement',0,PasProgram.InitializationSection.Elements.Count);
end; end;
Procedure TTestStatementParser.TestBlock; procedure TTestStatementParser.TestBlock;
Var Var
B : TPasImplBeginBlock; B : TPasImplBeginBlock;
@ -211,7 +212,7 @@ begin
AssertEquals('Empty block',0,B.Elements.Count); AssertEquals('Empty block',0,B.Elements.Count);
end; end;
Procedure TTestStatementParser.TestBlockComment; procedure TTestStatementParser.TestBlockComment;
Var Var
B : TPasImplBeginBlock; B : TPasImplBeginBlock;
@ -226,7 +227,7 @@ begin
AssertEquals('No DocComment','',B.DocComment); AssertEquals('No DocComment','',B.DocComment);
end; end;
Procedure TTestStatementParser.TestBlock2Comments; procedure TTestStatementParser.TestBlock2Comments;
Var Var
B : TPasImplBeginBlock; B : TPasImplBeginBlock;
@ -241,7 +242,7 @@ begin
AssertEquals('No DocComment','',B.DocComment); AssertEquals('No DocComment','',B.DocComment);
end; end;
Procedure TTestStatementParser.TestAssignment; procedure TTestStatementParser.TestAssignment;
Var Var
A : TPasImplAssign; A : TPasImplAssign;
@ -257,7 +258,7 @@ begin
AssertExpression('Left side is variable',A.Left,pekIdent,'a'); AssertExpression('Left side is variable',A.Left,pekIdent,'a');
end; end;
Procedure TTestStatementParser.TestAssignmentAdd; procedure TTestStatementParser.TestAssignmentAdd;
Var Var
A : TPasImplAssign; A : TPasImplAssign;
@ -274,7 +275,7 @@ begin
AssertExpression('Left side is variable',A.Left,pekIdent,'a'); AssertExpression('Left side is variable',A.Left,pekIdent,'a');
end; end;
Procedure TTestStatementParser.TestAssignmentMinus; procedure TTestStatementParser.TestAssignmentMinus;
Var Var
A : TPasImplAssign; A : TPasImplAssign;
@ -290,7 +291,7 @@ begin
AssertExpression('Left side is variable',A.Left,pekIdent,'a'); AssertExpression('Left side is variable',A.Left,pekIdent,'a');
end; end;
Procedure TTestStatementParser.TestAssignmentMul; procedure TTestStatementParser.TestAssignmentMul;
Var Var
A : TPasImplAssign; A : TPasImplAssign;
@ -306,7 +307,7 @@ begin
AssertExpression('Left side is variable',A.Left,pekIdent,'a'); AssertExpression('Left side is variable',A.Left,pekIdent,'a');
end; end;
Procedure TTestStatementParser.TestAssignmentDivision; procedure TTestStatementParser.TestAssignmentDivision;
Var Var
A : TPasImplAssign; A : TPasImplAssign;
@ -322,7 +323,7 @@ begin
AssertExpression('Left side is variable',A.Left,pekIdent,'a'); AssertExpression('Left side is variable',A.Left,pekIdent,'a');
end; end;
Procedure TTestStatementParser.TestCall; procedure TTestStatementParser.TestCall;
Var Var
S : TPasImplSimple; S : TPasImplSimple;
@ -335,7 +336,7 @@ begin
AssertExpression('Doit call',S.Expr,pekIdent,'Doit'); AssertExpression('Doit call',S.Expr,pekIdent,'Doit');
end; end;
Procedure TTestStatementParser.TestCallComment; procedure TTestStatementParser.TestCallComment;
Var Var
S : TPasImplSimple; S : TPasImplSimple;
@ -350,7 +351,7 @@ begin
AssertEquals('No DocComment','',S.DocComment); AssertEquals('No DocComment','',S.DocComment);
end; end;
Procedure TTestStatementParser.TestCallQualified; procedure TTestStatementParser.TestCallQualified;
Var Var
S : TPasImplSimple; S : TPasImplSimple;
@ -368,7 +369,7 @@ begin
end; end;
Procedure TTestStatementParser.TestCallQualified2; procedure TTestStatementParser.TestCallQualified2;
Var Var
S : TPasImplSimple; S : TPasImplSimple;
B : TBinaryExpr; B : TBinaryExpr;
@ -387,7 +388,7 @@ begin
AssertExpression('Doit call',B.Right,pekIdent,'Doit'); AssertExpression('Doit call',B.Right,pekIdent,'Doit');
end; end;
Procedure TTestStatementParser.TestCallNoArgs; procedure TTestStatementParser.TestCallNoArgs;
Var Var
S : TPasImplSimple; S : TPasImplSimple;
@ -404,7 +405,7 @@ begin
AssertEquals('No params',0,Length(P.Params)); AssertEquals('No params',0,Length(P.Params));
end; end;
Procedure TTestStatementParser.TestCallOneArg; procedure TTestStatementParser.TestCallOneArg;
Var Var
S : TPasImplSimple; S : TPasImplSimple;
P : TParamsExpr; P : TParamsExpr;
@ -421,7 +422,7 @@ begin
AssertExpression('Parameter is constant',P.Params[0],pekNumber,'1'); AssertExpression('Parameter is constant',P.Params[0],pekNumber,'1');
end; end;
Procedure TTestStatementParser.TestIf; procedure TTestStatementParser.TestIf;
Var Var
I : TPasImplIfElse; I : TPasImplIfElse;
@ -435,7 +436,7 @@ begin
AssertNull('No if branch',I.IfBranch); AssertNull('No if branch',I.IfBranch);
end; end;
Procedure TTestStatementParser.TestIfBlock; procedure TTestStatementParser.TestIfBlock;
Var Var
I : TPasImplIfElse; I : TPasImplIfElse;
@ -450,7 +451,7 @@ begin
AssertEquals('begin end block',TPasImplBeginBlock,I.ifBranch.ClassType); AssertEquals('begin end block',TPasImplBeginBlock,I.ifBranch.ClassType);
end; end;
Procedure TTestStatementParser.TestIfAssignment; procedure TTestStatementParser.TestIfAssignment;
Var Var
I : TPasImplIfElse; I : TPasImplIfElse;
@ -465,7 +466,7 @@ begin
AssertEquals('assignment statement',TPasImplAssign,I.ifBranch.ClassType); AssertEquals('assignment statement',TPasImplAssign,I.ifBranch.ClassType);
end; end;
Procedure TTestStatementParser.TestIfElse; procedure TTestStatementParser.TestIfElse;
Var Var
I : TPasImplIfElse; I : TPasImplIfElse;
@ -480,7 +481,7 @@ begin
AssertEquals('begin end block',TPasImplBeginBlock,I.ifBranch.ClassType); AssertEquals('begin end block',TPasImplBeginBlock,I.ifBranch.ClassType);
end; end;
Procedure TTestStatementParser.TestIfElseBlock; procedure TTestStatementParser.TestIfElseBlock;
Var Var
I : TPasImplIfElse; I : TPasImplIfElse;
@ -495,14 +496,14 @@ begin
AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType); AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType);
end; end;
Procedure TTestStatementParser.TestIfSemiColonElseError; procedure TTestStatementParser.TestIfSemiColonElseError;
begin begin
DeclareVar('boolean'); DeclareVar('boolean');
ExpectParserError('No semicolon before else',['if a then',' begin',' end;','else',' begin',' end']); ExpectParserError('No semicolon before else',['if a then',' begin',' end;','else',' begin',' end']);
end; end;
Procedure TTestStatementParser.TestNestedIf; procedure TTestStatementParser.TestNestedIf;
Var Var
I : TPasImplIfElse; I : TPasImplIfElse;
begin begin
@ -519,7 +520,7 @@ begin
end; end;
Procedure TTestStatementParser.TestNestedIfElse; procedure TTestStatementParser.TestNestedIfElse;
Var Var
I : TPasImplIfElse; I : TPasImplIfElse;
@ -537,7 +538,7 @@ begin
AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType); AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType);
end; end;
Procedure TTestStatementParser.TestWhile; procedure TTestStatementParser.TestWhile;
Var Var
W : TPasImplWhileDo; W : TPasImplWhileDo;
@ -550,7 +551,7 @@ begin
AssertNull('Empty body',W.Body); AssertNull('Empty body',W.Body);
end; end;
Procedure TTestStatementParser.TestWhileBlock; procedure TTestStatementParser.TestWhileBlock;
Var Var
W : TPasImplWhileDo; W : TPasImplWhileDo;
@ -564,7 +565,7 @@ begin
AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count); AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count);
end; end;
Procedure TTestStatementParser.TestWhileNested; procedure TTestStatementParser.TestWhileNested;
Var Var
W : TPasImplWhileDo; W : TPasImplWhileDo;
@ -584,7 +585,7 @@ begin
AssertEquals('Empty nested block',0,TPasImplBeginBlock(W.Body).ELements.Count); AssertEquals('Empty nested block',0,TPasImplBeginBlock(W.Body).ELements.Count);
end; end;
Procedure TTestStatementParser.TestRepeat; procedure TTestStatementParser.TestRepeat;
Var Var
R : TPasImplRepeatUntil; R : TPasImplRepeatUntil;
@ -597,7 +598,7 @@ begin
AssertEquals('Empty body',0,R.Elements.Count); AssertEquals('Empty body',0,R.Elements.Count);
end; end;
Procedure TTestStatementParser.TestRepeatBlock; procedure TTestStatementParser.TestRepeatBlock;
Var Var
R : TPasImplRepeatUntil; R : TPasImplRepeatUntil;
@ -627,7 +628,7 @@ begin
AssertEquals('Empty block',0,TPasImplBeginBlock(R.Elements[0]).ELements.Count); AssertEquals('Empty block',0,TPasImplBeginBlock(R.Elements[0]).ELements.Count);
end; end;
Procedure TTestStatementParser.TestRepeatNested; procedure TTestStatementParser.TestRepeatNested;
Var Var
R : TPasImplRepeatUntil; R : TPasImplRepeatUntil;
@ -647,7 +648,7 @@ begin
AssertEquals('Empty block',0,TPasImplBeginBlock(R.Elements[0]).ELements.Count); AssertEquals('Empty block',0,TPasImplBeginBlock(R.Elements[0]).ELements.Count);
end; end;
Procedure TTestStatementParser.TestFor; procedure TTestStatementParser.TestFor;
Var Var
F : TPasImplForLoop; F : TPasImplForLoop;
@ -664,7 +665,7 @@ begin
AssertNull('Empty body',F.Body); AssertNull('Empty body',F.Body);
end; end;
Procedure TTestStatementParser.TestForIn; procedure TTestStatementParser.TestForIn;
Var Var
F : TPasImplForLoop; F : TPasImplForLoop;
@ -681,7 +682,7 @@ begin
AssertNull('Empty body',F.Body); AssertNull('Empty body',F.Body);
end; end;
Procedure TTestStatementParser.TestForExpr; procedure TTestStatementParser.TestForExpr;
Var Var
F : TPasImplForLoop; F : TPasImplForLoop;
B : TBinaryExpr; B : TBinaryExpr;
@ -703,7 +704,7 @@ begin
AssertNull('Empty body',F.Body); AssertNull('Empty body',F.Body);
end; end;
Procedure TTestStatementParser.TestForBlock; procedure TTestStatementParser.TestForBlock;
Var Var
F : TPasImplForLoop; F : TPasImplForLoop;
@ -739,7 +740,7 @@ begin
AssertEquals('Empty block',0,TPasImplBeginBlock(F.Body).ELements.Count); AssertEquals('Empty block',0,TPasImplBeginBlock(F.Body).ELements.Count);
end; end;
Procedure TTestStatementParser.TestForNested; procedure TTestStatementParser.TestForNested;
Var Var
F : TPasImplForLoop; F : TPasImplForLoop;
@ -764,7 +765,7 @@ begin
AssertEquals('Empty block',0,TPasImplBeginBlock(F.Body).ELements.Count); AssertEquals('Empty block',0,TPasImplBeginBlock(F.Body).ELements.Count);
end; end;
Procedure TTestStatementParser.TestWith; procedure TTestStatementParser.TestWith;
Var Var
W : TpasImplWithDo; W : TpasImplWithDo;
@ -780,7 +781,7 @@ begin
AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count); AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count);
end; end;
Procedure TTestStatementParser.TestWithMultiple; procedure TTestStatementParser.TestWithMultiple;
Var Var
W : TpasImplWithDo; W : TpasImplWithDo;
@ -797,14 +798,14 @@ begin
AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count); AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count);
end; end;
Procedure TTestStatementParser.TestCaseEmpty; procedure TTestStatementParser.TestCaseEmpty;
begin begin
DeclareVar('integer'); DeclareVar('integer');
AddStatements(['case a of','end;']); AddStatements(['case a of','end;']);
ExpectParserError('Empty case not allowed'); ExpectParserError('Empty case not allowed');
end; end;
Procedure TTestStatementParser.TestCaseOneInteger; procedure TTestStatementParser.TestCaseOneInteger;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
@ -826,7 +827,7 @@ begin
AssertNull('Empty case label statement',S.Body); AssertNull('Empty case label statement',S.Body);
end; end;
Procedure TTestStatementParser.TestCaseTwoIntegers; procedure TTestStatementParser.TestCaseTwoIntegers;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
@ -849,7 +850,7 @@ begin
AssertNull('Empty case label statement',S.Body); AssertNull('Empty case label statement',S.Body);
end; end;
Procedure TTestStatementParser.TestCaseRange; procedure TTestStatementParser.TestCaseRange;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
S : TPasImplCaseStatement; S : TPasImplCaseStatement;
@ -870,7 +871,7 @@ begin
AssertNull('Empty case label statement',S.Body); AssertNull('Empty case label statement',S.Body);
end; end;
Procedure TTestStatementParser.TestCaseRangeSeparate; procedure TTestStatementParser.TestCaseRangeSeparate;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
S : TPasImplCaseStatement; S : TPasImplCaseStatement;
@ -892,7 +893,7 @@ begin
AssertNull('Empty case label statement',S.Body); AssertNull('Empty case label statement',S.Body);
end; end;
Procedure TTestStatementParser.TestCase2Cases; procedure TTestStatementParser.TestCase2Cases;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
S : TPasImplCaseStatement; S : TPasImplCaseStatement;
@ -920,7 +921,7 @@ begin
AssertNull('Empty case label statement 2',S.Body); AssertNull('Empty case label statement 2',S.Body);
end; end;
Procedure TTestStatementParser.TestCaseBlock; procedure TTestStatementParser.TestCaseBlock;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
@ -946,7 +947,7 @@ begin
end; end;
Procedure TTestStatementParser.TestCaseElseBlockEmpty; procedure TTestStatementParser.TestCaseElseBlockEmpty;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
@ -973,7 +974,7 @@ begin
AssertEquals('Zero statements ',0,TPasImplCaseElse(C.ElseBranch).Elements.Count); AssertEquals('Zero statements ',0,TPasImplCaseElse(C.ElseBranch).Elements.Count);
end; end;
Procedure TTestStatementParser.TestCaseElseBlockAssignment; procedure TTestStatementParser.TestCaseElseBlockAssignment;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
S : TPasImplCaseStatement; S : TPasImplCaseStatement;
@ -999,7 +1000,7 @@ begin
AssertEquals('1 statement in else branch ',1,TPasImplCaseElse(C.ElseBranch).Elements.Count); AssertEquals('1 statement in else branch ',1,TPasImplCaseElse(C.ElseBranch).Elements.Count);
end; end;
Procedure TTestStatementParser.TestCaseElseBlock2Assignments; procedure TTestStatementParser.TestCaseElseBlock2Assignments;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
@ -1026,7 +1027,7 @@ begin
AssertEquals('2 statements in else branch ',2,TPasImplCaseElse(C.ElseBranch).Elements.Count); AssertEquals('2 statements in else branch ',2,TPasImplCaseElse(C.ElseBranch).Elements.Count);
end; end;
Procedure TTestStatementParser.TestCaseIfCaseElse; procedure TTestStatementParser.TestCaseIfCaseElse;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
@ -1044,7 +1045,7 @@ begin
AssertEquals('0 statement in else branch ',0,TPasImplCaseElse(C.ElseBranch).Elements.Count); AssertEquals('0 statement in else branch ',0,TPasImplCaseElse(C.ElseBranch).Elements.Count);
end; end;
Procedure TTestStatementParser.TestCaseIfElse; procedure TTestStatementParser.TestCaseIfElse;
Var Var
C : TPasImplCaseOf; C : TPasImplCaseOf;
S : TPasImplCaseStatement; S : TPasImplCaseStatement;
@ -1066,7 +1067,7 @@ begin
AssertNotNull('If statement has else block',TPasImplIfElse(S.Elements[0]).ElseBranch); AssertNotNull('If statement has else block',TPasImplIfElse(S.Elements[0]).ElseBranch);
end; end;
Procedure TTestStatementParser.TestRaise; procedure TTestStatementParser.TestRaise;
Var Var
R : TPasImplRaise; R : TPasImplRaise;
@ -1081,7 +1082,7 @@ begin
AssertExpression('Expression object',R.ExceptObject,pekIdent,'A'); AssertExpression('Expression object',R.ExceptObject,pekIdent,'A');
end; end;
Procedure TTestStatementParser.TestRaiseEmpty; procedure TTestStatementParser.TestRaiseEmpty;
Var Var
R : TPasImplRaise; R : TPasImplRaise;
@ -1093,7 +1094,7 @@ begin
AssertNull(R.ExceptAddr); AssertNull(R.ExceptAddr);
end; end;
Procedure TTestStatementParser.TestRaiseAt; procedure TTestStatementParser.TestRaiseAt;
Var Var
R : TPasImplRaise; R : TPasImplRaise;
@ -1109,7 +1110,7 @@ begin
AssertExpression('Expression object',R.ExceptAddr,pekIdent,'B'); AssertExpression('Expression object',R.ExceptAddr,pekIdent,'B');
end; end;
Procedure TTestStatementParser.TestTryFinally; procedure TTestStatementParser.TestTryFinally;
Var Var
T : TPasImplTry; T : TPasImplTry;
@ -1135,7 +1136,7 @@ begin
AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse'); AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse');
end; end;
Procedure TTestStatementParser.TestTryFinallyEmpty; procedure TTestStatementParser.TestTryFinallyEmpty;
Var Var
T : TPasImplTry; T : TPasImplTry;
F : TPasImplTryFinally; F : TPasImplTryFinally;
@ -1151,7 +1152,7 @@ begin
AssertEquals(0,F.Elements.Count); AssertEquals(0,F.Elements.Count);
end; end;
Procedure TTestStatementParser.TestTryFinallyNested; procedure TTestStatementParser.TestTryFinallyNested;
Var Var
T : TPasImplTry; T : TPasImplTry;
S : TPasImplSimple; S : TPasImplSimple;
@ -1279,7 +1280,7 @@ begin
AssertEquals(0,E.Elements.Count); AssertEquals(0,E.Elements.Count);
end; end;
Procedure TTestStatementParser.TestTryExceptOn; procedure TTestStatementParser.TestTryExceptOn;
Var Var
T : TPasImplTry; T : TPasImplTry;
@ -1313,7 +1314,7 @@ begin
end; end;
Procedure TTestStatementParser.TestTryExceptOn2; procedure TTestStatementParser.TestTryExceptOn2;
Var Var
T : TPasImplTry; T : TPasImplTry;
@ -1358,7 +1359,7 @@ begin
AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse2'); AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse2');
end; end;
Procedure TTestStatementParser.TestTryExceptOnElse; procedure TTestStatementParser.TestTryExceptOnElse;
Var Var
T : TPasImplTry; T : TPasImplTry;
S : TPasImplSimple; S : TPasImplSimple;
@ -1405,7 +1406,7 @@ begin
AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomethingMore'); AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomethingMore');
end; end;
Procedure TTestStatementParser.TestTryExceptOnIfElse; procedure TTestStatementParser.TestTryExceptOnIfElse;
Var Var
T : TPasImplTry; T : TPasImplTry;
S : TPasImplSimple; S : TPasImplSimple;
@ -1444,6 +1445,21 @@ begin
AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomethingMore'); AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomethingMore');
end; end;
procedure TTestStatementParser.TestAsm;
Var
T : TPasImplAsmStatement;
begin
TestStatement(['asm',' mov eax,1','end;']);
T:=AssertStatement('Asm statement',TPasImplAsmStatement) as TPasImplAsmStatement;
AssertEquals('Asm tokens',4,T.Tokens.Count);
AssertEquals('token 1 ','mov',T.Tokens[0]);
AssertEquals('token 2 ','eax',T.Tokens[1]);
AssertEquals('token 3 ',',',T.Tokens[2]);
AssertEquals('token 4 ','1',T.Tokens[3]);
end;
initialization initialization
RegisterTests([TTestStatementParser]); RegisterTests([TTestStatementParser]);