codetools: added update check for parsing directives

git-svn-id: trunk@11810 -
This commit is contained in:
mattias 2007-08-14 08:36:30 +00:00
parent 99f2a3de36
commit 06753dbd34
2 changed files with 69 additions and 17 deletions

View File

@ -155,11 +155,14 @@ type
SrcPos: Integer;
AtomStart: integer;
Macros: TAVLTree;// tree of TCompilerMacroStats
ParseChangeStep: integer;
constructor Create;
destructor Destroy; override;
procedure Clear;
function Parse(aCode: TCodeBuffer; aNestedComments: boolean): boolean;
procedure Parse(aCode: TCodeBuffer; aNestedComments: boolean);
function UpdateNeeded: boolean;
procedure ReduceCompilerDirectives(Undefines, Defines: TStrings;
var Changed: boolean);
procedure GatherH2PasFunctions(out ListOfH2PasFunctions: TFPList;
@ -598,6 +601,7 @@ end;
procedure TCompilerDirectivesTree.InitParser;
begin
ParseChangeStep:=Code.ChangeStep;
InitKeyWordList;
Src:=Code.Source;
SrcLen:=length(Src);
@ -1127,7 +1131,7 @@ var
Change: PDefineChange;
begin
if StackPointer=0 then
raise Exception.Create('TCompilerDirectivesTree.DisableUnreachableBlocks.Pop');
raise CDirectiveParserException.Create('TCompilerDirectivesTree.DisableUnreachableBlocks.Pop without Push');
// undo all changes
while Stack[StackPointer]<>nil do begin
Change:=Stack[StackPointer];
@ -1614,8 +1618,17 @@ begin
inherited Destroy;
end;
function TCompilerDirectivesTree.Parse(aCode: TCodeBuffer;
aNestedComments: boolean): boolean;
procedure TCompilerDirectivesTree.Clear;
begin
Tree.Clear;
if Macros<>nil then begin
Macros.FreeAndClear;
FreeAndNil(Macros);
end;
end;
procedure TCompilerDirectivesTree.Parse(aCode: TCodeBuffer;
aNestedComments: boolean);
procedure RaiseDanglingIFDEF;
begin
@ -1629,10 +1642,14 @@ var
begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
Result:=false;
if (Code=aCode) and (NestedComments=aNestedComments) and (not UpdateNeeded)
then
exit;
Code:=aCode;
NestedComments:=aNestedComments;
InitParser;
repeat
ReadRawNextPascalAtom(Src,SrcPos,AtomStart,NestedComments);
//DebugLn(['TCompilerDirectivesTree.Parse ',copy(Src,AtomStart,SrcPos-AtomStart)]);
@ -1656,10 +1673,17 @@ begin
if CurNode<>Tree.Root then
RaiseDanglingIFDEF;
Result:=true;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end;
function TCompilerDirectivesTree.UpdateNeeded: boolean;
begin
Result:=true;
if (Code=nil) then exit;
if Code.ChangeStep<>ParseChangeStep then exit;
Result:=false;
end;
procedure TCompilerDirectivesTree.ReduceCompilerDirectives(
Undefines, Defines: TStrings; var Changed: boolean);
(* Check and improve the following cases

View File

@ -196,9 +196,19 @@ type
{ TReduceCompilerDirectivesInUnit }
TReduceCompilerDirectivesInUnit = class(TCustomTextConverterTool)
private
FDefines: TStrings;
FUndefines: TStrings;
procedure SetDefines(const AValue: TStrings);
procedure SetUndefines(const AValue: TStrings);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
class function ClassDescription: string; override;
function Execute(aText: TIDETextConverter): TModalResult; override;
published
property Undefines: TStrings read FUndefines write SetUndefines;
property Defines: TStrings read FDefines write SetDefines;
end;
{ TReplaceConstFunctionsInUnit }
@ -3215,11 +3225,7 @@ begin
try
Tree:=TCompilerDirectivesTree.Create;
Code:=TCodeBuffer(aText.CodeBuffer);
if not Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename))
then begin
DebugLn(['TFixH2PasMissingIFDEFsInUnit.Execute failed parsing compiler directives']);
exit;
end;
Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename));
Changed:=false;
Tree.FixMissingH2PasDirectives(Changed);
finally
@ -3230,6 +3236,32 @@ end;
{ TReduceCompilerDirectivesInUnit }
procedure TReduceCompilerDirectivesInUnit.SetDefines(const AValue: TStrings);
begin
if FDefines=AValue then exit;
FDefines.Assign(AValue);
end;
procedure TReduceCompilerDirectivesInUnit.SetUndefines(const AValue: TStrings);
begin
if FUndefines=AValue then exit;
FUndefines.Assign(AValue);
end;
constructor TReduceCompilerDirectivesInUnit.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FUndefines:=TStringList.Create;
FDefines:=TStringList.Create;
end;
destructor TReduceCompilerDirectivesInUnit.Destroy;
begin
FreeAndNil(FUndefines);
FreeAndNil(FDefines);
inherited Destroy;
end;
class function TReduceCompilerDirectivesInUnit.ClassDescription: string;
begin
Result:='Reduce compiler directives in pascal file'#13
@ -3249,14 +3281,10 @@ begin
try
Tree:=TCompilerDirectivesTree.Create;
Code:=TCodeBuffer(aText.CodeBuffer);
if not Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename))
then begin
DebugLn(['TReduceCompilerDirectivesInUnit.Execute failed parsing compiler directives']);
exit;
end;
Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename));
repeat
Changed:=false;
Tree.ReduceCompilerDirectives(nil,nil,Changed);
Tree.ReduceCompilerDirectives(Undefines,Defines,Changed);
//Tree.WriteDebugReport;
until not Changed;
finally