h2pas: added tool to convert c function types to pointers

git-svn-id: trunk@11953 -
This commit is contained in:
mattias 2007-09-07 10:34:35 +00:00
parent 655e3ccb20
commit ca365cd4ff
12 changed files with 338 additions and 44 deletions

View File

@ -1632,7 +1632,7 @@ var
FuncName:=GetAtom; FuncName:=GetAtom;
ReadNextAtom; ReadNextAtom;
if CurPos.Flag=cafRoundBracketOpen then begin if CurPos.Flag=cafRoundBracketOpen then begin
// skip empty parameter list () // skip optional empty parameter list ()
ReadNextAtom; ReadNextAtom;
if CurPos.Flag<>cafRoundBracketClose then exit; if CurPos.Flag<>cafRoundBracketClose then exit;
ReadNextAtom; ReadNextAtom;
@ -1717,6 +1717,8 @@ begin
TreeOfCodeTreeNodeExt:=nil; TreeOfCodeTreeNodeExt:=nil;
try try
BuildTree(false);
// first step: find all unit identifiers (excluding implementation section) // first step: find all unit identifiers (excluding implementation section)
if not GatherUnitDefinitions(Definitions,true,true) then exit; if not GatherUnitDefinitions(Definitions,true,true) then exit;
@ -1964,6 +1966,8 @@ begin
Result:=false; Result:=false;
TreeOfCodeTreeNodeExt:=nil; TreeOfCodeTreeNodeExt:=nil;
try try
BuildTree(false);
// first step: find all unit identifiers (excluding implementation section) // first step: find all unit identifiers (excluding implementation section)
if not GatherUnitDefinitions(Definitions,true,true) then exit; if not GatherUnitDefinitions(Definitions,true,true) then exit;
@ -2290,7 +2294,7 @@ begin
try try
// move the pointer types to the same type sections // move the pointer types to the same type sections
if not MovePointerTypesToTargetSections then exit; if not MovePointerTypesToTargetSections then exit;
if not BuildUnitDefinitionGraph(Definitions,Graph,false) then exit; if not BuildUnitDefinitionGraph(Definitions,Graph,true) then exit;
finally finally
NodeExtMemManager.DisposeAVLTree(Definitions); NodeExtMemManager.DisposeAVLTree(Definitions);
@ -2318,13 +2322,18 @@ function TCodeCompletionCodeTool.GatherUnitDefinitions(out
begin begin
NodeText:=GetRedefinitionNodeText(Node); NodeText:=GetRedefinitionNodeText(Node);
NodeExt:=FindCodeTreeNodeExt(TreeOfCodeTreeNodeExt,NodeText); NodeExt:=FindCodeTreeNodeExt(TreeOfCodeTreeNodeExt,NodeText);
if NodeExt=nil then begin if NodeExt<>nil then begin
NodeExt:=NodeExtMemManager.NewNode; if NodeIsForwardProc(NodeExt.Node)
NodeExt.Txt:=NodeText; and (not NodeIsForwardProc(Node)) then begin
TreeOfCodeTreeNodeExt.Add(NodeExt); // this is the procedure body of the forward definition -> skip
end else if ExceptionOnRedefinition then begin exit;
RaiseRedefinition(NodeExt.Node,Node); end;
if ExceptionOnRedefinition then
RaiseRedefinition(NodeExt.Node,Node);
end; end;
NodeExt:=NodeExtMemManager.NewNode;
NodeExt.Txt:=NodeText;
TreeOfCodeTreeNodeExt.Add(NodeExt);
NodeExt.Node:=Node; NodeExt.Node:=Node;
end; end;
@ -2395,8 +2404,8 @@ function TCodeCompletionCodeTool.BuildUnitDefinitionGraph(out
if NodeExt<>nil then begin if NodeExt<>nil then begin
if Graph=nil then if Graph=nil then
Graph:=TCodeGraph.Create; Graph:=TCodeGraph.Create;
if Graph.GetEdge(Node,NodeExt.Node,false)=nil then //if Graph.GetEdge(Node,NodeExt.Node,false)=nil then
DebugLn(['CheckRange AddEdge: ',GetRedefinitionNodeText(Node),' uses ',GetRedefinitionNodeText(NodeExt.Node)]); // DebugLn(['CheckRange AddEdge: ',GetRedefinitionNodeText(Node),' uses ',GetRedefinitionNodeText(NodeExt.Node)]);
Graph.AddEdge(Node,NodeExt.Node); Graph.AddEdge(Node,NodeExt.Node);
end; end;
end; end;

View File

@ -104,6 +104,7 @@ type
function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean; function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean;
function NodeIsFunction(ProcNode: TCodeTreeNode): boolean; function NodeIsFunction(ProcNode: TCodeTreeNode): boolean;
function NodeIsConstructor(ProcNode: TCodeTreeNode): boolean; function NodeIsConstructor(ProcNode: TCodeTreeNode): boolean;
function NodeIsForwardProc(ProcNode: TCodeTreeNode): boolean;
// classes // classes
function ExtractClassName(ClassNode: TCodeTreeNode; function ExtractClassName(ClassNode: TCodeTreeNode;
@ -1445,6 +1446,18 @@ begin
Result:=UpAtomIs('CONSTRUCTOR'); Result:=UpAtomIs('CONSTRUCTOR');
end; end;
function TPascalReaderTool.NodeIsForwardProc(ProcNode: TCodeTreeNode): boolean;
begin
Result:=false;
// check if procedure
if (ProcNode=nil) or (ProcNode.Desc<>ctnProcedure) then exit;
// check if in interface
if (ProcNode.Parent<>nil) and (ProcNode.Parent.Desc=ctnInterface) then
exit(true);
// check if has forward
if (ctnsForwardDeclaration and ProcNode.SubDesc)>0 then exit(true);
end;
function TPascalReaderTool.NodeIsPartOfTypeDefinition(ANode: TCodeTreeNode function TPascalReaderTool.NodeIsPartOfTypeDefinition(ANode: TCodeTreeNode
): boolean; ): boolean;
begin begin

View File

@ -33,7 +33,8 @@ uses
type type
{ TRemoveCPlusPlusExternCTool - Remove C++ 'extern "C"' lines } { TRemoveCPlusPlusExternCTool (for C header files)
Remove C++ 'extern "C"' lines }
TRemoveCPlusPlusExternCTool = class(TCustomTextConverterTool) TRemoveCPlusPlusExternCTool = class(TCustomTextConverterTool)
public public
@ -42,7 +43,8 @@ type
end; end;
{ TRemoveEmptyCMacrosTool - Remove empty C macros} { TRemoveEmptyCMacrosTool (for C header files)
Remove empty C macros}
TRemoveEmptyCMacrosTool = class(TCustomTextConverterTool) TRemoveEmptyCMacrosTool = class(TCustomTextConverterTool)
public public
@ -51,7 +53,8 @@ type
end; end;
{ TReplaceEdgedBracketPairWithStar - Replace [] with * } { TReplaceEdgedBracketPairWithStar (for C header files)
Replace [] with * }
TReplaceEdgedBracketPairWithStar = class(TCustomTextReplaceTool) TReplaceEdgedBracketPairWithStar = class(TCustomTextReplaceTool)
public public
@ -60,7 +63,7 @@ type
end; end;
{ TReplaceMacro0PointerWithNULL - { TReplaceMacro0PointerWithNULL (for C header files)
Replace macro values 0 pointer like (char *)0 with NULL } Replace macro values 0 pointer like (char *)0 with NULL }
TReplaceMacro0PointerWithNULL = class(TCustomTextConverterTool) TReplaceMacro0PointerWithNULL = class(TCustomTextConverterTool)
@ -70,6 +73,16 @@ type
end; end;
{ TConvertFunctionTypesToPointers (for C header files)
Replace function types with pointer to function type }
TConvertFunctionTypesToPointers = class(TCustomTextConverterTool)
public
class function ClassDescription: string; override;
function Execute(aText: TIDETextConverter): TModalResult; override;
end;
{ TReplaceUnitFilenameWithUnitName - { TReplaceUnitFilenameWithUnitName -
Replace "unit filename;" with "unit name;" } Replace "unit filename;" with "unit name;" }
@ -235,6 +248,14 @@ type
function Execute(aText: TIDETextConverter): TModalResult; override; function Execute(aText: TIDETextConverter): TModalResult; override;
end; end;
{ TFixForwardDefinitions - reorder definitions }
TFixForwardDefinitions = class(TCustomTextConverterTool)
public
class function ClassDescription: string; override;
function Execute(aText: TIDETextConverter): TModalResult; override;
end;
type type
{ TPretH2PasTools - Combines the common tools. } { TPretH2PasTools - Combines the common tools. }
@ -242,7 +263,8 @@ type
phRemoveCPlusPlusExternCTool, // Remove C++ 'extern "C"' lines phRemoveCPlusPlusExternCTool, // Remove C++ 'extern "C"' lines
phRemoveEmptyCMacrosTool, // Remove empty C macros phRemoveEmptyCMacrosTool, // Remove empty C macros
phReplaceEdgedBracketPairWithStar, // Replace [] with * phReplaceEdgedBracketPairWithStar, // Replace [] with *
phReplaceMacro0PointerWithNULL // Replace macro values 0 pointer like (char *)0 phReplaceMacro0PointerWithNULL, // Replace macro values 0 pointer like (char *)0
phConvertFunctionTypesToPointers // Convert function types to pointers
); );
TPreH2PasToolsOptions = set of TPreH2PasToolsOption; TPreH2PasToolsOptions = set of TPreH2PasToolsOption;
const const
@ -278,7 +300,8 @@ type
phRemoveRedefinitionsInUnit, // Removes redefinitions of types, variables, constants and resourcestrings phRemoveRedefinitionsInUnit, // Removes redefinitions of types, variables, constants and resourcestrings
phFixAliasDefinitionsInUnit, // fix section type of alias definitions phFixAliasDefinitionsInUnit, // fix section type of alias definitions
phReplaceConstFunctionsInUnit, // replace simple assignment functions with constants phReplaceConstFunctionsInUnit, // replace simple assignment functions with constants
phReplaceTypeCastFunctionsInUnit // replace simple type cast functions with types phReplaceTypeCastFunctionsInUnit, // replace simple type cast functions with types
phFixForwardDefinitions // fix forward definitions by reordering
); );
TPostH2PasToolsOptions = set of TPostH2PasToolsOption; TPostH2PasToolsOptions = set of TPostH2PasToolsOption;
const const
@ -2431,10 +2454,10 @@ begin
PChar(TImplicitType(Type2).Name)); PChar(TImplicitType(Type2).Name));
end; end;
function CompareImplicitTypeStringAndName(ASCIIZ, function CompareImplicitTypeStringAndName(Identifier,
ImplicitType: Pointer): integer; ImplicitType: Pointer): integer;
begin begin
Result:=CompareIdentifiers(PChar(ASCIIZ), Result:=CompareIdentifiers(PChar(Identifier),
PChar(TImplicitType(ImplicitType).Name)); PChar(TImplicitType(ImplicitType).Name));
end; end;
@ -3404,7 +3427,8 @@ begin
+'phRemoveCPlusPlusExternCTool - Remove C++ ''extern "C"'' lines'#13 +'phRemoveCPlusPlusExternCTool - Remove C++ ''extern "C"'' lines'#13
+'phRemoveEmptyCMacrosTool - Remove empty C macros'#13 +'phRemoveEmptyCMacrosTool - Remove empty C macros'#13
+'phReplaceEdgedBracketPairWithStar - Replace [] with *'#13 +'phReplaceEdgedBracketPairWithStar - Replace [] with *'#13
+'phReplace0PointerWithNULL - Replace macro values 0 pointer like (char *)0'#13; +'phReplace0PointerWithNULL - Replace macro values 0 pointer like (char *)0'#13
+'phConvertFunctionTypesToPointers - Convert function types to pointers'#13;
end; end;
function TPreH2PasTools.Execute(aText: TIDETextConverter): TModalResult; function TPreH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
@ -3451,6 +3475,16 @@ begin
end; end;
end; end;
if phConvertFunctionTypesToPointers in Options then begin
Tool:=TConvertFunctionTypesToPointers.Create(nil);
try
Result:=Tool.Execute(aText);
if Result<>mrOk then exit;
finally
Tool.Free;
end;
end;
Result:=mrOk; Result:=mrOk;
end; end;
@ -3498,7 +3532,8 @@ begin
+'phRemoveRedefinitionsInUnit - Removes redefinitions of types, variables, constants and resourcestrings'#13 +'phRemoveRedefinitionsInUnit - Removes redefinitions of types, variables, constants and resourcestrings'#13
+'phFixAliasDefinitionsInUnit - fix section type of alias definitions'#13 +'phFixAliasDefinitionsInUnit - fix section type of alias definitions'#13
+'phReplaceConstFunctionsInUnit - replace simple assignment functions with constants'#13 +'phReplaceConstFunctionsInUnit - replace simple assignment functions with constants'#13
+'phReplaceTypeCastFunctionsInUnit - replace simple type cast functions with types'#13; +'phReplaceTypeCastFunctionsInUnit - replace simple type cast functions with types'#13
+'phFixForwardDefinitions - fix forward definitions by reordering'#13;
end; end;
function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult; function TPostH2PasTools.Execute(aText: TIDETextConverter): TModalResult;
@ -3636,6 +3671,10 @@ begin
if not FixAliasDefinitions(Changed,Result) then exit; if not FixAliasDefinitions(Changed,Result) then exit;
if not ConvertSimpleFunctions(Changed,Result) then exit; if not ConvertSimpleFunctions(Changed,Result) then exit;
until Changed=false; until Changed=false;
// fix forward definitions
if not Run(phFixForwardDefinitions,
TFixForwardDefinitions,Result) then exit;
end; end;
{ TRemoveIncludeDirectives } { TRemoveIncludeDirectives }
@ -3653,4 +3692,155 @@ begin
Options:=Options+[trtRegExpr]; Options:=Options+[trtRegExpr];
end; end;
{ TConvertFunctionTypesToPointers }
class function TConvertFunctionTypesToPointers.ClassDescription: string;
begin
Result:='Convert function types to pointers';
end;
function TConvertFunctionTypesToPointers.Execute(aText: TIDETextConverter
): TModalResult;
var
Src: String;
SrcLen: Integer;
FuncTypes: TAvgLvlTree; // tree of TImplicitType
procedure CheckTypeDef(var p: integer);
// Check if it is: typedef identifier ( funcname ) (
var
StartPos: LongInt;
EndPos: LongInt;
NewType: TImplicitType;
begin
// typedef found
inc(p,length('typedef'));
// skip space
while (p<SrcLen) and IsSpaceChar[Src[p]] do inc(p);
// skip identifier
if not IsIdentStartChar[Src[p]] then exit;
while (p<SrcLen) and IsIdentChar[Src[p]] do inc(p);
// skip space
while (p<SrcLen) and IsSpaceChar[Src[p]] do inc(p);
// skip (
if Src[p]<>'(' then exit;
inc(p);
// skip space
while (p<SrcLen) and IsSpaceChar[Src[p]] do inc(p);
if p>=SrcLen then exit;
// read name of function type
StartPos:=p;
if not IsIdentStartChar[Src[p]] then exit;
while (p<SrcLen) and IsIdentChar[Src[p]] do inc(p);
EndPos:=p;
// skip space
while (p<SrcLen) and IsSpaceChar[Src[p]] do inc(p);
if p>=SrcLen then exit;
// skip )
if Src[p]<>')' then exit;
inc(p);
// skip space
while (p<SrcLen) and IsSpaceChar[Src[p]] do inc(p);
if p>=SrcLen then exit;
// skip (
if Src[p]<>'(' then exit;
// function type found
NewType:=TImplicitType.Create;
NewType.Name:=copy(Src,StartPos,EndPos-StartPos);
writeln('TConvertFunctionTypesToPointers.Execute.CheckType function type found Name=',NewType.Name);
if FuncTypes=nil then
FuncTypes:=TAvgLvlTree.Create(@CompareImplicitTypeNames);
FuncTypes.Add(NewType);
// add * in front of name
System.Insert('*',Src,StartPos);
SrcLen:=length(Src);
end;
procedure CheckIdentifier(var p: integer);
var
IdentPos: LongInt;
IdentEnd: LongInt;
begin
IdentPos:=p;
// skip identifier
while (p<=SrcLen) and IsIdentChar[Src[p]] do inc(p);
if FuncTypes.FindKey(@Src[IdentPos],@CompareImplicitTypeStringAndName)=nil
then
exit;
// this identifier is a function type
IdentEnd:=p;
// skip space
while (p<SrcLen) and IsSpaceChar[Src[p]] do inc(p);
if p>=SrcLen then exit;
// remove * behind identifier
if Src[p]<>'*' then exit;
writeln('TConvertFunctionTypesToPointers.Execute.CheckIdentifier removing * behind reference to ',GetIdentifier(@Src[IdentPos]));
System.Delete(Src,IdentEnd,p-IdentEnd+1);
SrcLen:=length(Src);
p:=IdentEnd;
end;
var
p: Integer;
begin
Result:=mrCancel;
if aText=nil then exit;
FuncTypes:=nil;
try
Src:=aText.Source;
SrcLen:=length(Src);
// Search all typedef identifier ( funcname ) (
// and insert a * in front of the funcname
p:=1;
while (p<SrcLen) do begin
if (Src[p]='t') and ((p=1) or (not IsIdentChar[Src[p-1]]))
and (CompareIdentifiers('typedef',@Src[p])=0) then begin
CheckTypeDef(p);
end else
inc(p);
end;
if FuncTypes<>nil then begin
// remove the * behind all references
p:=1;
while (p<SrcLen) do begin
if (IsIdentStartChar[Src[p]]) and ((p=1) or (not IsIdentChar[Src[p-1]]))
then begin
CheckIdentifier(p);
end else
inc(p);
end;
end;
finally
if FuncTypes<>nil then begin
FuncTypes.FreeAndClear;
FuncTypes.Free;
aText.Source:=Src;
end;
end;
Result:=mrOk;
end;
{ TFixForwardDefinitions }
class function TFixForwardDefinitions.ClassDescription: string;
begin
Result:='Fix forward definitions by reordering';
end;
function TFixForwardDefinitions.Execute(aText: TIDETextConverter
): TModalResult;
begin
Result:=mrCancel;
if (not FilenameIsPascalUnit(aText.Filename)) then begin
DebugLn(['TFixForwardDefinitions.Execute file is not pascal: ',aText.Filename]);
exit(mrOk);// ignore
end;
if not CodeToolBoss.FixForwardDefinitions(TCodeBuffer(aText.CodeBuffer)) then begin
DebugLn(['TFixForwardDefinitions.Execute failed ',CodeToolBoss.ErrorMessage]);
exit;
end;
Result:=mrOk;
end;
end. end.

View File

@ -214,6 +214,7 @@ begin
TextConverterToolClasses.RegisterClass(TRemoveEmptyCMacrosTool); TextConverterToolClasses.RegisterClass(TRemoveEmptyCMacrosTool);
TextConverterToolClasses.RegisterClass(TReplaceEdgedBracketPairWithStar); TextConverterToolClasses.RegisterClass(TReplaceEdgedBracketPairWithStar);
TextConverterToolClasses.RegisterClass(TReplaceMacro0PointerWithNULL); TextConverterToolClasses.RegisterClass(TReplaceMacro0PointerWithNULL);
TextConverterToolClasses.RegisterClass(TConvertFunctionTypesToPointers);
TextConverterToolClasses.RegisterClass(TPostH2PasTools); TextConverterToolClasses.RegisterClass(TPostH2PasTools);
TextConverterToolClasses.RegisterClass(TReplaceUnitFilenameWithUnitName); TextConverterToolClasses.RegisterClass(TReplaceUnitFilenameWithUnitName);
TextConverterToolClasses.RegisterClass(TRemoveSystemTypes); TextConverterToolClasses.RegisterClass(TRemoveSystemTypes);
@ -224,8 +225,10 @@ begin
TextConverterToolClasses.RegisterClass(TReplaceImplicitTypes); TextConverterToolClasses.RegisterClass(TReplaceImplicitTypes);
TextConverterToolClasses.RegisterClass(TFixArrayOfParameterType); TextConverterToolClasses.RegisterClass(TFixArrayOfParameterType);
TextConverterToolClasses.RegisterClass(TRemoveRedefinitionsInUnit); TextConverterToolClasses.RegisterClass(TRemoveRedefinitionsInUnit);
TextConverterToolClasses.RegisterClass(TFixAliasDefinitionsInUnit);
TextConverterToolClasses.RegisterClass(TReplaceConstFunctionsInUnit); TextConverterToolClasses.RegisterClass(TReplaceConstFunctionsInUnit);
TextConverterToolClasses.RegisterClass(TReplaceTypeCastFunctionsInUnit); TextConverterToolClasses.RegisterClass(TReplaceTypeCastFunctionsInUnit);
TextConverterToolClasses.RegisterClass(TFixForwardDefinitions);
end; end;
{ TH2PasDialog } { TH2PasDialog }

View File

@ -41,7 +41,7 @@ interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons, ExtCtrls, Spin, MaskEdit, ComCtrls, LCLType, Buttons, ExtCtrls, Spin, ComCtrls, LCLType,
Printers, OsPrinters, CUPSDyn; Printers, OsPrinters, CUPSDyn;
type type

View File

@ -25,19 +25,19 @@
</RunParams> </RunParams>
<RequiredPackages Count="4"> <RequiredPackages Count="4">
<Item1> <Item1>
<PackageName Value="SimpleIDEIntf"/> <PackageName Value="CodeTools"/>
<MinVersion Valid="True"/>
</Item1> </Item1>
<Item2> <Item2>
<PackageName Value="LCL"/>
<MinVersion Major="1" Valid="True"/>
</Item2>
<Item3>
<PackageName Value="H2PasWizard"/> <PackageName Value="H2PasWizard"/>
<MinVersion Valid="True"/> <MinVersion Valid="True"/>
</Item2>
<Item3>
<PackageName Value="LCL"/>
<MinVersion Major="1" Valid="True"/>
</Item3> </Item3>
<Item4> <Item4>
<PackageName Value="CodeTools"/> <PackageName Value="SimpleIDEIntf"/>
<MinVersion Valid="True"/>
</Item4> </Item4>
</RequiredPackages> </RequiredPackages>
<Units Count="1"> <Units Count="1">

View File

@ -53,6 +53,19 @@ begin
end; end;
end; end;
procedure TestTConvertFunctionTypesToPointers(Converter: TIDETextConverter);
var
Tool: TConvertFunctionTypesToPointers;
begin
Tool:=nil;
try
Tool:=TConvertFunctionTypesToPointers.Create(nil);
Tool.Execute(Converter);
finally
Tool.Free;
end;
end;
var var
Filename: String; Filename: String;
Converter: TIDETextConverter; Converter: TIDETextConverter;
@ -75,6 +88,7 @@ begin
// test // test
TestTReplaceImplicitTypes(Converter); TestTReplaceImplicitTypes(Converter);
TestTFixArrayOfParameterType(Converter); TestTFixArrayOfParameterType(Converter);
TestTConvertFunctionTypesToPointers(Converter);
// write result // write result
writeln(Converter.Source); writeln(Converter.Source);

View File

@ -34,9 +34,23 @@ type
TLazyTextConverterToolClasses = class(TTextConverterToolClasses) TLazyTextConverterToolClasses = class(TTextConverterToolClasses)
protected protected
function SupportsType(aTextType: TTextConverterType): boolean; override;
function GetTempFilename: string; override; function GetTempFilename: string; override;
function LoadFromFile(Converter: TIDETextConverter; const AFilename: string; function LoadFromFile(Converter: TIDETextConverter; const AFilename: string;
UpdateFromDisk, Revert: Boolean): Boolean; override; UpdateFromDisk, Revert: Boolean): Boolean; override;
function SaveCodeBufferToFile(Converter: TIDETextConverter;
const AFilename: string): Boolean; override;
function GetCodeBufferSource(Converter: TIDETextConverter;
out Source: string): boolean; override;
function CreateCodeBuffer(Converter: TIDETextConverter;
const Filename, NewSource: string;
out CodeBuffer: Pointer): boolean; override;
function LoadCodeBufferFromFile(Converter: TIDETextConverter;
const Filename: string;
UpdateFromDisk, Revert: Boolean;
out CodeBuffer: Pointer): boolean; override;
end; end;
procedure SetupTextConverters; procedure SetupTextConverters;
@ -123,6 +137,12 @@ end;
{ TLazyTextConverterToolClasses } { TLazyTextConverterToolClasses }
function TLazyTextConverterToolClasses.SupportsType(
aTextType: TTextConverterType): boolean;
begin
Result:=aTextType in [tctSource,tctFile,tctStrings];
end;
function TLazyTextConverterToolClasses.GetTempFilename: string; function TLazyTextConverterToolClasses.GetTempFilename: string;
var var
BaseDir: String; BaseDir: String;
@ -138,6 +158,43 @@ begin
Result:=Converter.LoadFromFile(AFilename,false,UpdateFromDisk,Revert); Result:=Converter.LoadFromFile(AFilename,false,UpdateFromDisk,Revert);
end; end;
function TLazyTextConverterToolClasses.SaveCodeBufferToFile(
Converter: TIDETextConverter; const AFilename: string): Boolean;
begin
raise Exception.Create('SaveCodeBufferToFile not supported');
if (Converter=nil) and (aFilename='') then;
Result:=false;
end;
function TLazyTextConverterToolClasses.GetCodeBufferSource(
Converter: TIDETextConverter; out Source: string): boolean;
begin
raise Exception.Create('GetCodeBufferSource not supported');
Source:='';
if Converter=nil then;
Result:=false;
end;
function TLazyTextConverterToolClasses.CreateCodeBuffer(
Converter: TIDETextConverter; const Filename, NewSource: string; out
CodeBuffer: Pointer): boolean;
begin
raise Exception.Create('CreateCodeBuffer not supported');
CodeBuffer:=nil;
if (Converter=nil) and (Filename='') and (NewSource='') then;
Result:=false;
end;
function TLazyTextConverterToolClasses.LoadCodeBufferFromFile(
Converter: TIDETextConverter; const Filename: string; UpdateFromDisk,
Revert: Boolean; out CodeBuffer: Pointer): boolean;
begin
raise Exception.Create('LoadCodeBufferFromFile not supported');
CodeBuffer:=nil;
if (Converter=nil) and (Filename='') and UpdateFromDisk and Revert then;
Result:=false;
end;
initialization initialization
REException:=ERegExpr; REException:=ERegExpr;
REMatchesFunction:=@SynREMatches; REMatchesFunction:=@SynREMatches;

View File

@ -1223,7 +1223,7 @@ begin
Size := GetBitsPerLine(Width, BitsPerPixel, LineEnd); Size := GetBitsPerLine(Width, BitsPerPixel, LineEnd);
Size := (Size * Description.Height) shr 3; Size := (Size * Description.Height) shr 3;
if Size <= High(DataSize) if Size < High(DataSize)
then DataSize := Size then DataSize := Size
else DataSize := High(DataSize); else DataSize := High(DataSize);
@ -1240,7 +1240,7 @@ begin
Size := GetBitsPerLine(Width, MaskBitsPerPixel, MaskLineEnd); Size := GetBitsPerLine(Width, MaskBitsPerPixel, MaskLineEnd);
Size := (Size * Description.Height) shr 3; Size := (Size * Description.Height) shr 3;
if Size <= High(MaskSize) if Size < High(MaskSize)
then MaskSize := Size then MaskSize := Size
else MaskSize := High(MaskSize); else MaskSize := High(MaskSize);

View File

@ -468,8 +468,10 @@ end;
Deletes the image identified by Index. An index of -1 deletes all Deletes the image identified by Index. An index of -1 deletes all
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomImageList.Delete(AIndex: Integer); procedure TCustomImageList.Delete(AIndex: Integer);
{$ifdef IMGLIST_OLDSTYLE}
var var
Obj : TObject; Obj : TObject;
{$ENDIF}
begin begin
if AIndex = -1 if AIndex = -1
then begin then begin
@ -510,8 +512,10 @@ end;
Destructor for the class. Destructor for the class.
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
destructor TCustomImageList.Destroy; destructor TCustomImageList.Destroy;
{$ifdef IMGLIST_OLDSTYLE}
var var
i: integer; i: integer;
{$ENDIF}
begin begin
{$ifdef IMGLIST_OLDSTYLE} {$ifdef IMGLIST_OLDSTYLE}
FBitmap.Free; FBitmap.Free;
@ -542,8 +546,10 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomImageList.Draw(ACanvas: TCanvas; AX, AY, AIndex: Integer; procedure TCustomImageList.Draw(ACanvas: TCanvas; AX, AY, AIndex: Integer;
AEnabled: Boolean); AEnabled: Boolean);
{$ifdef IMGLIST_OLDSTYLE}
var var
aBitmap: TBitmap; aBitmap: TBitmap;
{$ENDIF}
begin begin
if (FCount = 0) or (AIndex >= FCount) then Exit; if (FCount = 0) or (AIndex >= FCount) then Exit;
@ -1062,8 +1068,10 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomImageList.WriteData(AStream: TStream); procedure TCustomImageList.WriteData(AStream: TStream);
var var
{$ifdef IMGLIST_OLDSTYLE}
CurImage: TBitMap; CurImage: TBitMap;
i: Integer; i: Integer;
{$ENDIF}
Signature: TImageListSignature; Signature: TImageListSignature;
begin begin
//Write signature //Write signature
@ -1546,7 +1554,10 @@ end;
procedure TCustomImageList.StretchDraw(Canvas: TCanvas; Index: Integer; ARect: TRect; Enabled: Boolean); procedure TCustomImageList.StretchDraw(Canvas: TCanvas; Index: Integer; ARect: TRect; Enabled: Boolean);
var var
bmp, msk: TBitmap; bmp: TBitmap;
{$ifdef IMGLIST_OLDSTYLE}
msk: TBitmap;
{$ENDIF}
begin begin
if (FCount = 0) or (Index >= FCount) then Exit; if (FCount = 0) or (Index >= FCount) then Exit;

View File

@ -146,7 +146,7 @@ var
ImgDepth: Byte absolute ARawImage.Description.Depth; ImgDepth: Byte absolute ARawImage.Description.Depth;
ImgDataSize: PtrUInt absolute ARawImage.DataSize; ImgDataSize: PtrUInt absolute ARawImage.DataSize;
Drawable: PGdkDrawable; Drawable: PGdkDrawable;
Bitmap, Inverse: PGdkBitmap; Bitmap: PGdkBitmap;
Pixbuf: PGdkPixbuf; Pixbuf: PGdkPixbuf;
GC: PGdkGC; GC: PGdkGC;
Visual: PGdkVisual; Visual: PGdkVisual;
@ -292,11 +292,11 @@ begin
GdkImage := gdk_image_new(GDK_IMAGE_FASTEST, Visual, ImgWidth, ImgHeight); GdkImage := gdk_image_new(GDK_IMAGE_FASTEST, Visual, ImgWidth, ImgHeight);
{$ifdef VerboseRawImage} {$ifdef VerboseRawImage}
{DebugLn('TGtkWidgetSet.CreateBitmapFromRawImage GdkImage: ', //DebugLn('TGtkWidgetSet.CreateBitmapFromRawImage GdkImage: ',
' BytesPerLine=',dbgs(GdkImage^.bpl), // ' BytesPerLine=',dbgs(GdkImage^.bpl),
' BitsPerPixel=',dbgs(GetPGdkImageBitsPerPixel(GdkImage)), // ' BitsPerPixel=',dbgs(GetPGdkImageBitsPerPixel(GdkImage)),
' ByteOrder=',dbgs({$ifdef Gtk1}GdkImage^.byte_order{$else}ord(GdkImage^.byte_order){$endif}), // ' ByteOrder=',dbgs({$ifdef Gtk1}GdkImage^.byte_order{$else}ord(GdkImage^.byte_order){$endif}),
'');} // '');
{$endif} {$endif}
if ARawImage.Description.BitsPerPixel <> GetGdkImageBitsPerPixel(GdkImage) if ARawImage.Description.BitsPerPixel <> GetGdkImageBitsPerPixel(GdkImage)

View File

@ -2504,9 +2504,6 @@ var
var var
Width, Height, H, W, D: cardinal; Width, Height, H, W, D: cardinal;
Image: PGdkImage; Image: PGdkImage;
BytesPerLine: Integer;
SrcPtr, DstPtr: PByte;
Mask: QWord;
begin begin
Result := False; Result := False;