codetools: directive tree: reraise last error

git-svn-id: trunk@41006 -
This commit is contained in:
mattias 2013-05-02 21:40:36 +00:00
parent 09853b3d90
commit b32a494336

View File

@ -136,13 +136,14 @@ type
{ TCompilerDirectivesTree } { TCompilerDirectivesTree }
TCompilerDirectivesTree = class TCompilerDirectivesTree = class
FChangeStep: integer;
private private
FChangeStep: integer;
FDefaultDirectiveFuncList: TKeyWordFunctionList; FDefaultDirectiveFuncList: TKeyWordFunctionList;
FDisableUnusedDefines: boolean; FDisableUnusedDefines: boolean;
FRemoveDisabledDirectives: boolean; FRemoveDisabledDirectives: boolean;
FSimplifyExpressions: boolean; FSimplifyExpressions: boolean;
FUndefH2PasFunctions: boolean; FUndefH2PasFunctions: boolean;
FLastErrorMsg: string;
function IfdefDirective: boolean; function IfdefDirective: boolean;
function IfCDirective: boolean; function IfCDirective: boolean;
function IfndefDirective: boolean; function IfndefDirective: boolean;
@ -175,6 +176,8 @@ type
procedure EndIFNode(const ErrorMsg: string); procedure EndIFNode(const ErrorMsg: string);
procedure InternalRemoveNode(Node: TCodeTreeNode); procedure InternalRemoveNode(Node: TCodeTreeNode);
procedure RaiseException(const ErrorMsg: string);
procedure RaiseLastError;
public public
Code: TCodeBuffer; Code: TCodeBuffer;
Src: string; Src: string;
@ -667,17 +670,10 @@ begin
end; end;
procedure TCompilerDirectivesTree.EndIFNode(const ErrorMsg: string); procedure TCompilerDirectivesTree.EndIFNode(const ErrorMsg: string);
procedure RaiseMissingStartNode;
begin
WriteDebugReport;
raise ECDirectiveParserException.Create(Self,ErrorMsg);
end;
begin begin
if (CurNode.Desc<>cdnIf) and (CurNode.Desc<>cdnElse) if (CurNode.Desc<>cdnIf) and (CurNode.Desc<>cdnElse)
and (CurNode.Desc<>cdnElseIf) then and (CurNode.Desc<>cdnElseIf) then
RaiseMissingStartNode; RaiseException(ErrorMsg);
EndChildNode; EndChildNode;
end; end;
@ -1159,7 +1155,7 @@ var
Change: PDefineChange; Change: PDefineChange;
begin begin
if StackPointer=0 then if StackPointer=0 then
raise ECDirectiveParserException.Create(Self,'TCompilerDirectivesTree.DisableUnreachableBlocks.Pop without Push'); RaiseException('TCompilerDirectivesTree.DisableUnreachableBlocks.Pop without Push');
// undo all changes // undo all changes
while Stack[StackPointer]<>nil do begin while Stack[StackPointer]<>nil do begin
Change:=Stack[StackPointer]; Change:=Stack[StackPointer];
@ -1358,7 +1354,7 @@ procedure TCompilerDirectivesTree.DisableIfNode(Node: TCodeTreeNode;
procedure RaiseImpossible; procedure RaiseImpossible;
begin begin
raise ECDirectiveParserException.Create(Self,'TCompilerDirectivesTree.DisableIfNode impossible'); RaiseException('TCompilerDirectivesTree.DisableIfNode impossible');
end; end;
function GetExpr(ExprNode: TCodeTreeNode; out Negated: boolean): string; function GetExpr(ExprNode: TCodeTreeNode; out Negated: boolean): string;
@ -1596,6 +1592,17 @@ begin
Tree.DeleteNode(Node); Tree.DeleteNode(Node);
end; end;
procedure TCompilerDirectivesTree.RaiseException(const ErrorMsg: string);
begin
fLastErrorMsg:=ErrorMsg;
raise ECDirectiveParserException.Create(Self,ErrorMsg);
end;
procedure TCompilerDirectivesTree.RaiseLastError;
begin
raise ECDirectiveParserException.Create(Self,fLastErrorMsg);
end;
procedure TCompilerDirectivesTree.RemoveEmptyNodes(var Changed: boolean); procedure TCompilerDirectivesTree.RemoveEmptyNodes(var Changed: boolean);
var var
Node: TCodeTreeNode; Node: TCodeTreeNode;
@ -1705,8 +1712,7 @@ procedure TCompilerDirectivesTree.Parse(aCode: TCodeBuffer;
procedure RaiseDanglingIFDEF; procedure RaiseDanglingIFDEF;
begin begin
WriteDebugReport; RaiseException('missing EndIf');
raise ECDirectiveParserException.Create(Self,'missing EndIf');
end; end;
var var
@ -1716,9 +1722,13 @@ begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF} {$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-} {$R-}
if (Code=aCode) and (NestedComments=aNestedComments) and (not UpdateNeeded) if (Code=aCode) and (NestedComments=aNestedComments) and (not UpdateNeeded)
then then begin
if FLastErrorMsg<>'' then
RaiseLastError;
exit; exit;
end;
FLastErrorMsg:='';
Code:=aCode; Code:=aCode;
NestedComments:=aNestedComments; NestedComments:=aNestedComments;
InitParser; InitParser;