mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-29 20:30:21 +02:00
codetools: added update check for parsing directives
git-svn-id: trunk@11810 -
This commit is contained in:
parent
99f2a3de36
commit
06753dbd34
@ -155,11 +155,14 @@ type
|
|||||||
SrcPos: Integer;
|
SrcPos: Integer;
|
||||||
AtomStart: integer;
|
AtomStart: integer;
|
||||||
Macros: TAVLTree;// tree of TCompilerMacroStats
|
Macros: TAVLTree;// tree of TCompilerMacroStats
|
||||||
|
ParseChangeStep: integer;
|
||||||
|
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
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;
|
procedure ReduceCompilerDirectives(Undefines, Defines: TStrings;
|
||||||
var Changed: boolean);
|
var Changed: boolean);
|
||||||
procedure GatherH2PasFunctions(out ListOfH2PasFunctions: TFPList;
|
procedure GatherH2PasFunctions(out ListOfH2PasFunctions: TFPList;
|
||||||
@ -598,6 +601,7 @@ end;
|
|||||||
|
|
||||||
procedure TCompilerDirectivesTree.InitParser;
|
procedure TCompilerDirectivesTree.InitParser;
|
||||||
begin
|
begin
|
||||||
|
ParseChangeStep:=Code.ChangeStep;
|
||||||
InitKeyWordList;
|
InitKeyWordList;
|
||||||
Src:=Code.Source;
|
Src:=Code.Source;
|
||||||
SrcLen:=length(Src);
|
SrcLen:=length(Src);
|
||||||
@ -1127,7 +1131,7 @@ var
|
|||||||
Change: PDefineChange;
|
Change: PDefineChange;
|
||||||
begin
|
begin
|
||||||
if StackPointer=0 then
|
if StackPointer=0 then
|
||||||
raise Exception.Create('TCompilerDirectivesTree.DisableUnreachableBlocks.Pop');
|
raise CDirectiveParserException.Create('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];
|
||||||
@ -1614,8 +1618,17 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCompilerDirectivesTree.Parse(aCode: TCodeBuffer;
|
procedure TCompilerDirectivesTree.Clear;
|
||||||
aNestedComments: boolean): boolean;
|
begin
|
||||||
|
Tree.Clear;
|
||||||
|
if Macros<>nil then begin
|
||||||
|
Macros.FreeAndClear;
|
||||||
|
FreeAndNil(Macros);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCompilerDirectivesTree.Parse(aCode: TCodeBuffer;
|
||||||
|
aNestedComments: boolean);
|
||||||
|
|
||||||
procedure RaiseDanglingIFDEF;
|
procedure RaiseDanglingIFDEF;
|
||||||
begin
|
begin
|
||||||
@ -1629,10 +1642,14 @@ var
|
|||||||
begin
|
begin
|
||||||
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
|
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
|
||||||
{$R-}
|
{$R-}
|
||||||
Result:=false;
|
if (Code=aCode) and (NestedComments=aNestedComments) and (not UpdateNeeded)
|
||||||
|
then
|
||||||
|
exit;
|
||||||
|
|
||||||
Code:=aCode;
|
Code:=aCode;
|
||||||
NestedComments:=aNestedComments;
|
NestedComments:=aNestedComments;
|
||||||
InitParser;
|
InitParser;
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
ReadRawNextPascalAtom(Src,SrcPos,AtomStart,NestedComments);
|
ReadRawNextPascalAtom(Src,SrcPos,AtomStart,NestedComments);
|
||||||
//DebugLn(['TCompilerDirectivesTree.Parse ',copy(Src,AtomStart,SrcPos-AtomStart)]);
|
//DebugLn(['TCompilerDirectivesTree.Parse ',copy(Src,AtomStart,SrcPos-AtomStart)]);
|
||||||
@ -1656,10 +1673,17 @@ begin
|
|||||||
if CurNode<>Tree.Root then
|
if CurNode<>Tree.Root then
|
||||||
RaiseDanglingIFDEF;
|
RaiseDanglingIFDEF;
|
||||||
|
|
||||||
Result:=true;
|
|
||||||
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
|
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
|
||||||
end;
|
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(
|
procedure TCompilerDirectivesTree.ReduceCompilerDirectives(
|
||||||
Undefines, Defines: TStrings; var Changed: boolean);
|
Undefines, Defines: TStrings; var Changed: boolean);
|
||||||
(* Check and improve the following cases
|
(* Check and improve the following cases
|
||||||
|
@ -196,9 +196,19 @@ type
|
|||||||
{ TReduceCompilerDirectivesInUnit }
|
{ TReduceCompilerDirectivesInUnit }
|
||||||
|
|
||||||
TReduceCompilerDirectivesInUnit = class(TCustomTextConverterTool)
|
TReduceCompilerDirectivesInUnit = class(TCustomTextConverterTool)
|
||||||
|
private
|
||||||
|
FDefines: TStrings;
|
||||||
|
FUndefines: TStrings;
|
||||||
|
procedure SetDefines(const AValue: TStrings);
|
||||||
|
procedure SetUndefines(const AValue: TStrings);
|
||||||
public
|
public
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
class function ClassDescription: string; override;
|
class function ClassDescription: string; override;
|
||||||
function Execute(aText: TIDETextConverter): TModalResult; override;
|
function Execute(aText: TIDETextConverter): TModalResult; override;
|
||||||
|
published
|
||||||
|
property Undefines: TStrings read FUndefines write SetUndefines;
|
||||||
|
property Defines: TStrings read FDefines write SetDefines;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TReplaceConstFunctionsInUnit }
|
{ TReplaceConstFunctionsInUnit }
|
||||||
@ -3215,11 +3225,7 @@ begin
|
|||||||
try
|
try
|
||||||
Tree:=TCompilerDirectivesTree.Create;
|
Tree:=TCompilerDirectivesTree.Create;
|
||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
if not Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename))
|
Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename));
|
||||||
then begin
|
|
||||||
DebugLn(['TFixH2PasMissingIFDEFsInUnit.Execute failed parsing compiler directives']);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
Changed:=false;
|
Changed:=false;
|
||||||
Tree.FixMissingH2PasDirectives(Changed);
|
Tree.FixMissingH2PasDirectives(Changed);
|
||||||
finally
|
finally
|
||||||
@ -3230,6 +3236,32 @@ end;
|
|||||||
|
|
||||||
{ TReduceCompilerDirectivesInUnit }
|
{ 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;
|
class function TReduceCompilerDirectivesInUnit.ClassDescription: string;
|
||||||
begin
|
begin
|
||||||
Result:='Reduce compiler directives in pascal file'#13
|
Result:='Reduce compiler directives in pascal file'#13
|
||||||
@ -3249,14 +3281,10 @@ begin
|
|||||||
try
|
try
|
||||||
Tree:=TCompilerDirectivesTree.Create;
|
Tree:=TCompilerDirectivesTree.Create;
|
||||||
Code:=TCodeBuffer(aText.CodeBuffer);
|
Code:=TCodeBuffer(aText.CodeBuffer);
|
||||||
if not Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename))
|
Tree.Parse(Code,CodeToolBoss.GetNestedCommentsFlagForFile(Code.Filename));
|
||||||
then begin
|
|
||||||
DebugLn(['TReduceCompilerDirectivesInUnit.Execute failed parsing compiler directives']);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
repeat
|
repeat
|
||||||
Changed:=false;
|
Changed:=false;
|
||||||
Tree.ReduceCompilerDirectives(nil,nil,Changed);
|
Tree.ReduceCompilerDirectives(Undefines,Defines,Changed);
|
||||||
//Tree.WriteDebugReport;
|
//Tree.WriteDebugReport;
|
||||||
until not Changed;
|
until not Changed;
|
||||||
finally
|
finally
|
||||||
|
Loading…
Reference in New Issue
Block a user