IDE: conditional compiler options: diff, assign

git-svn-id: trunk@17886 -
This commit is contained in:
mattias 2008-12-22 21:40:35 +00:00
parent 7784d73eb5
commit f4560dae0c
4 changed files with 177 additions and 118 deletions

View File

@ -239,32 +239,6 @@ type
type
{ TCompilerDiffTool
A tool to create the difference between two option sets }
TCompilerDiffTool = class
private
FDiff: TStrings;
FDiffer: boolean;
FPath: string;
procedure SetDiff(const AValue: TStrings);
procedure SetDiffer(const AValue: boolean);
procedure SetPath(const AValue: string);
public
constructor Create(DiffList: TStrings);
procedure AddDiffItem(const PropertyName, Value: string);
procedure AddDiff(const PropertyName: string; const Old, New: string);
procedure AddDiff(const PropertyName: string; const Old, New: integer);
procedure AddDiff(const PropertyName: string; const Old, New: boolean);
procedure AddPathsDiff(const PropertyName: string; const Old, New: string);
procedure AddSetDiff(const PropertyName: string; const Old, New: integer;
const EnumNames: PString);
property Diff: TStrings read FDiff write SetDiff;
property Path: string read FPath write SetPath;
property Differ: boolean read FDiffer write SetDiffer;
end;
{ TCompilationToolOptions }
TCompilationToolOptions = class
@ -2558,11 +2532,14 @@ begin
Libraries := CompOpts.fLibraryPaths;
OtherUnitFiles := CompOpts.fUnitPaths;
UnitOutputDirectory := CompOpts.fUnitOutputDir;
fLCLWidgetType := CompOpts.fLCLWidgetType;
ObjectPath := CompOpts.FObjectPath;
SrcPath := CompOpts.SrcPath;
DebugPath := CompOpts.DebugPath;
// conditionals
fLCLWidgetType := CompOpts.fLCLWidgetType;
Conditionals.Assign(CompOpts.Conditionals);
// Parsing
FSyntaxMode := CompOpts.FSyntaxMode;
fAssemblerStyle := CompOpts.fAssemblerStyle;
@ -2647,7 +2624,7 @@ var
begin
Tool:=TCompilerDiffTool.Create(nil);
CreateDiff(CompOpts,Tool);
Result:= not Tool.Differ;
Result:=not Tool.Differ;
Tool.Free;
end;
@ -2682,6 +2659,8 @@ begin
Tool.AddPathsDiff('SrcPath',FSrcPath,CompOpts.FSrcPath);
Tool.AddPathsDiff('DebugPath',fDebugPath,CompOpts.fDebugPath);
// conditionals
TCompOptConditionals(Conditionals).CreateDiff(CompOpts.Conditionals,Tool);
Tool.AddDiff('LCLWidgetType',fLCLWidgetType,CompOpts.fLCLWidgetType);
// parsing
@ -3209,94 +3188,6 @@ begin
FTargetOS:=AValue;
end;
{ TCompilerDiffTool }
procedure TCompilerDiffTool.SetDiff(const AValue: TStrings);
begin
if FDiff=AValue then exit;
FDiff:=AValue;
end;
procedure TCompilerDiffTool.SetDiffer(const AValue: boolean);
begin
if FDiffer=AValue then exit;
FDiffer:=AValue;
end;
procedure TCompilerDiffTool.SetPath(const AValue: string);
begin
if FPath=AValue then exit;
FPath:=AValue;
// ! config path, not file path. Always /, not PathDelim
if (FPath<>'') and (Path[length(Path)]<>'/') then FPath:=FPath+'/';
end;
constructor TCompilerDiffTool.Create(DiffList: TStrings);
begin
FDiff:=DiffList;
if Diff<>nil then
Diff.Clear;
end;
procedure TCompilerDiffTool.AddDiffItem(const PropertyName, Value: string);
begin
Differ:=true;
if Diff<>nil then
Diff.Add(Path+PropertyName+'='+Value);
end;
procedure TCompilerDiffTool.AddDiff(const PropertyName: string; const Old,
New: string);
begin
if Old=New then exit;
AddDiffItem(PropertyName,New);
end;
procedure TCompilerDiffTool.AddDiff(const PropertyName: string; const Old,
New: integer);
begin
if Old=New then exit;
AddDiffItem(PropertyName,IntToStr(New));
end;
procedure TCompilerDiffTool.AddDiff(const PropertyName: string; const Old,
New: boolean);
begin
if Old=New then exit;
AddDiffItem(PropertyName,dbgs(New));
end;
procedure TCompilerDiffTool.AddPathsDiff(const PropertyName: string; const Old,
New: string);
begin
if Old=New then exit;
AddDiff(PropertyName,Old,New);
end;
procedure TCompilerDiffTool.AddSetDiff(const PropertyName: string; const Old,
New: integer; const EnumNames: PString);
var
i: Integer;
Mask: LongInt;
s: String;
begin
if Old=New then exit;
Mask := 1;
s:='';
for i := 0 to 31 do begin
if (New and Mask) <> (Old and Mask) then begin
if s<>'' then s:=s+',';
if (New and Mask) <> 0 then
s:=s+'+'
else
s:=s+'-';
s:=s+EnumNames[i];
end;
Mask := Mask shl 1;
end;
AddDiffItem(PropertyName,s);
end;
{ TBuildModes }
constructor TBuildModes.Create;

View File

@ -38,10 +38,36 @@ unit CompOptsModes;
interface
uses
Classes, SysUtils, Laz_XMLCfg, ExprEval,
Classes, SysUtils, LCLProc, Laz_XMLCfg, ExprEval,
IDEProcs, ProjectIntf;
type
{ TCompilerDiffTool
A tool to create the difference between two option sets }
TCompilerDiffTool = class
private
FDiff: TStrings;
FDiffer: boolean;
FPath: string;
procedure SetDiff(const AValue: TStrings);
procedure SetDiffer(const AValue: boolean);
procedure SetPath(const AValue: string);
public
constructor Create(DiffList: TStrings);
procedure AddDiffItem(const PropertyName, Value: string);
procedure AddDiff(const PropertyName: string; const Old, New: string);
procedure AddDiff(const PropertyName: string; const Old, New: integer);
procedure AddDiff(const PropertyName: string; const Old, New: boolean);
procedure AddPathsDiff(const PropertyName: string; const Old, New: string);
procedure AddSetDiff(const PropertyName: string; const Old, New: integer;
const EnumNames: PString);
property Diff: TStrings read FDiff write SetDiff;
property Path: string read FPath write SetPath;
property Differ: boolean read FDiffer write SetDiffer;
end;
{ TCompOptConditionals }
TCompOptConditionals = class(TLazCompOptConditionals)
@ -62,6 +88,9 @@ type
procedure Clear;
procedure ClearNodes;
procedure InvalidateValues; override;
procedure Assign(Source: TLazCompOptConditionals); override;
procedure CreateDiff(CompOpts: TLazCompOptConditionals;
Tool: TCompilerDiffTool); virtual;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string;
DoSwitchPathDelims: boolean); virtual;
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string); virtual;
@ -242,6 +271,39 @@ begin
FErrorMsg:='';
end;
procedure TCompOptConditionals.Assign(Source: TLazCompOptConditionals);
begin
ClearNodes;
Root.Assign(Source.Root);
end;
procedure TCompOptConditionals.CreateDiff(CompOpts: TLazCompOptConditionals;
Tool: TCompilerDiffTool);
procedure Diff(CurNode, OtherNode: TCompOptCondNode);
var
i: Integer;
OldPath: String;
begin
Tool.AddDiff('NodeType',COCNodeTypeNames[CurNode.NodeType],COCNodeTypeNames[OtherNode.NodeType]);
Tool.AddDiff('ValueType',COCValueTypeNames[CurNode.ValueType],COCValueTypeNames[OtherNode.ValueType]);
Tool.AddDiff('Value',CurNode.Value,OtherNode.Value);
if CurNode.Count<>OtherNode.Count then begin
Tool.AddDiff('Count',IntToStr(CurNode.Count),IntToStr(OtherNode.Count));
exit;
end;
for i:=0 to CurNode.Count-1 do begin
OldPath:=Tool.Path;
Tool.Path:=Tool.Path+'Item'+IntToStr(i)+'/';
Diff(CurNode.Childs[i],OtherNode.Childs[i]);
Tool.Path:=OldPath;
end;
end;
begin
Diff(Root,CompOpts.Root);
end;
procedure TCompOptConditionals.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string; DoSwitchPathDelims: boolean);
@ -301,5 +363,93 @@ begin
FChangeStamp:=Low(Integer);
end;
{ TCompilerDiffTool }
procedure TCompilerDiffTool.SetDiff(const AValue: TStrings);
begin
if FDiff=AValue then exit;
FDiff:=AValue;
end;
procedure TCompilerDiffTool.SetDiffer(const AValue: boolean);
begin
if FDiffer=AValue then exit;
FDiffer:=AValue;
end;
procedure TCompilerDiffTool.SetPath(const AValue: string);
begin
if FPath=AValue then exit;
FPath:=AValue;
// ! config path, not file path. Always /, not PathDelim
if (FPath<>'') and (Path[length(Path)]<>'/') then FPath:=FPath+'/';
end;
constructor TCompilerDiffTool.Create(DiffList: TStrings);
begin
FDiff:=DiffList;
if Diff<>nil then
Diff.Clear;
end;
procedure TCompilerDiffTool.AddDiffItem(const PropertyName, Value: string);
begin
Differ:=true;
if Diff<>nil then
Diff.Add(Path+PropertyName+'='+Value);
end;
procedure TCompilerDiffTool.AddDiff(const PropertyName: string; const Old,
New: string);
begin
if Old=New then exit;
AddDiffItem(PropertyName,New);
end;
procedure TCompilerDiffTool.AddDiff(const PropertyName: string; const Old,
New: integer);
begin
if Old=New then exit;
AddDiffItem(PropertyName,IntToStr(New));
end;
procedure TCompilerDiffTool.AddDiff(const PropertyName: string; const Old,
New: boolean);
begin
if Old=New then exit;
AddDiffItem(PropertyName,dbgs(New));
end;
procedure TCompilerDiffTool.AddPathsDiff(const PropertyName: string; const Old,
New: string);
begin
if Old=New then exit;
AddDiff(PropertyName,Old,New);
end;
procedure TCompilerDiffTool.AddSetDiff(const PropertyName: string; const Old,
New: integer; const EnumNames: PString);
var
i: Integer;
Mask: LongInt;
s: String;
begin
if Old=New then exit;
Mask := 1;
s:='';
for i := 0 to 31 do begin
if (New and Mask) <> (Old and Mask) then begin
if s<>'' then s:=s+',';
if (New and Mask) <> 0 then
s:=s+'+'
else
s:=s+'-';
s:=s+EnumNames[i];
end;
Mask := Mask shl 1;
end;
AddDiffItem(PropertyName,s);
end;
end.

View File

@ -118,6 +118,7 @@ type
procedure Insert(Index: integer; Child: TCompOptCondNode);
procedure Move(OldIndex, NewIndex: integer);
procedure Delete(Index: integer);
procedure Assign(Source: TCompOptCondNode);
property NodeType: TCOCNodeType read FNodeType write SetNodeType;
property ValueType: TCOCValueType read FValueType write SetValueType;
property Value: string read FValue write SetValue;
@ -136,6 +137,7 @@ type
constructor Create;
destructor Destroy; override;
procedure InvalidateValues; virtual; abstract;
procedure Assign(Source: TLazCompOptConditionals); virtual; abstract;
property Root: TCompOptCondNode read FRoot write FRoot;
end;
@ -1021,6 +1023,22 @@ begin
Childs[Index].Free;
end;
procedure TCompOptCondNode.Assign(Source: TCompOptCondNode);
var
i: Integer;
Child: TCompOptCondNode;
begin
ClearNodes;
NodeType:=Source.NodeType;
ValueType:=Source.ValueType;
Value:=Source.Value;
for i:=0 to Source.Count-1 do begin
Child:=TCompOptCondNode.Create(Owner);
AddLast(Child);
Child.Assign(Source.Childs[i]);
end;
end;
{ TProjectFileDescriptor }
procedure TProjectFileDescriptor.SetResourceClass(

View File

@ -48,7 +48,7 @@ uses
Classes, SysUtils, LCLProc, LResources, Graphics, Forms, FileUtil,
AVL_Tree,
DefineTemplates, CodeToolManager, Laz_XMLWrite, Laz_XMLCfg, CodeCache,
EditDefineTree, CompilerOptions,
EditDefineTree, CompilerOptions, CompOptsModes,
PropEdits, LazIDEIntf, MacroIntf,
LazarusIDEStrConsts, IDEProcs, ComponentReg,
TransferMacros, FileReferenceList, PublishModule;