codetools: added option -M syntaxmode

git-svn-id: trunk@61193 -
This commit is contained in:
mattias 2019-05-10 08:23:03 +00:00
parent 416f2defec
commit 2248ddea17

View File

@ -38,7 +38,7 @@ uses
AvgLvlTree, LazLogger, LazFileUtils, Laz2_XMLCfg, LazUTF8, AvgLvlTree, LazLogger, LazFileUtils, Laz2_XMLCfg, LazUTF8,
// CodeTools // CodeTools
FileProcs, BasicCodeTools, CodeToolManager, CodeCache, SourceChanger, FileProcs, BasicCodeTools, CodeToolManager, CodeCache, SourceChanger,
CodeTree, DefineTemplates; CodeTree, DefineTemplates, LinkScanner;
type type
@ -62,6 +62,7 @@ type
FIncludePath: string; FIncludePath: string;
FLPKFilenames: TStrings; FLPKFilenames: TStrings;
FRemovePrivateSections: boolean; FRemovePrivateSections: boolean;
FSyntaxMode: TCompilerMode;
FUndefines: TStringToStringTree; FUndefines: TStringToStringTree;
FUnitFilenames: TStrings; FUnitFilenames: TStrings;
FVerbosity: integer; FVerbosity: integer;
@ -79,6 +80,7 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure WriteHelp; virtual; procedure WriteHelp; virtual;
property Verbosity: integer read FVerbosity write FVerbosity; property Verbosity: integer read FVerbosity write FVerbosity;
property SyntaxMode: TCompilerMode read FSyntaxMode write FSyntaxMode;
property Defines: TStringToStringTree read FDefines; property Defines: TStringToStringTree read FDefines;
property Undefines: TStringToStringTree read FUndefines; property Undefines: TStringToStringTree read FUndefines;
property IncludePath: string read FIncludePath write FIncludePath; property IncludePath: string read FIncludePath write FIncludePath;
@ -159,8 +161,8 @@ end;
procedure TSourceCloser.DoRun; procedure TSourceCloser.DoRun;
const const
ShortOpts = 'hvqc:pd:u:i:ke:'; ShortOpts = 'hvqc:pM:d:u:i:ke:';
LongOpts = 'help verbose quiet compileroptions: disablecompile define: undefine: includepath: keepprivate error:'; LongOpts = 'help verbose quiet compileroptions: disablecompile mode: define: undefine: includepath: keepprivate error:';
var var
ErrMsgIsDefault: Boolean; ErrMsgIsDefault: Boolean;
@ -174,6 +176,8 @@ var
end; end;
procedure ParseValueParam(ShortOpt: char; Value: string); procedure ParseValueParam(ShortOpt: char; Value: string);
var
m: TCompilerMode;
begin begin
case ShortOpt of case ShortOpt of
'c': 'c':
@ -198,6 +202,15 @@ var
Value:=';'+Value; Value:=';'+Value;
fIncludePath+=Value; fIncludePath+=Value;
end; end;
'M':
begin
for m in TCompilerMode do
if SameText(CompilerModeNames[m],Value) then begin
SyntaxMode:=m;
exit;
end;
E('invalid syntaxmode "'+Value+'"');
end;
'd': 'd':
begin begin
if not IsValidIdent(Value) then if not IsValidIdent(Value) then
@ -310,6 +323,7 @@ begin
Option:=copy(Param,3,p-3); Option:=copy(Param,3,p-3);
delete(Param,1,p); delete(Param,1,p);
if Option='compileroptions' then Option:='c' if Option='compileroptions' then Option:='c'
else if Option='mode' then Option:='M'
else if Option='define' then Option:='d' else if Option='define' then Option:='d'
else if Option='undefine' then Option:='u' else if Option='undefine' then Option:='u'
else if Option='includepath' then Option:='i' else if Option='includepath' then Option:='i'
@ -347,11 +361,39 @@ begin
end; end;
procedure TSourceCloser.ApplyDefines; procedure TSourceCloser.ApplyDefines;
procedure AddDefine(const MacroName, Value: string);
var
DefTemplate: TDefineTemplate;
begin
DefTemplate:=TDefineTemplate.Create('Define '+MacroName,
'Define '+MacroName,
MacroName,Value,da_DefineRecurse);
CodeToolBoss.DefineTree.Add(DefTemplate);
end;
procedure AddUndefine(const MacroName: string);
var
DefTemplate: TDefineTemplate;
begin
DefTemplate:=TDefineTemplate.Create('Undefine '+MacroName,
'Undefine '+MacroName,
MacroName,'',da_UndefineRecurse);
CodeToolBoss.DefineTree.Add(DefTemplate);
end;
procedure AddDefineUndefine(const AName: string; Define: boolean);
begin
if Define then
AddDefine(AName,'')
else
AddUndefine(AName);
end;
var var
IncPathTemplate: TDefineTemplate; IncPathTemplate: TDefineTemplate;
S2SItem: PStringToStringItem; S2SItem: PStringToStringItem;
MacroName: String; m: Integer;
DefTemplate: TDefineTemplate;
begin begin
if fDefinesApplied then exit; if fDefinesApplied then exit;
fDefinesApplied:=true; fDefinesApplied:=true;
@ -367,20 +409,15 @@ begin
); );
CodeToolBoss.DefineTree.Add(IncPathTemplate); CodeToolBoss.DefineTree.Add(IncPathTemplate);
end; end;
for S2SItem in Defines do begin
MacroName:=S2SItem^.Name; for m:=low(FPCSyntaxModes) to high(FPCSyntaxModes) do
DefTemplate:=TDefineTemplate.Create('Define '+MacroName, AddDefineUndefine('FPC_'+FPCSyntaxModes[m],
'Define '+MacroName, SameText(CompilerModeNames[SyntaxMode],FPCSyntaxModes[m]));
MacroName,S2SItem^.Value,da_DefineRecurse);
CodeToolBoss.DefineTree.Add(DefTemplate); for S2SItem in Defines do
end; AddDefine(S2SItem^.Name,S2SItem^.Value);
for S2SItem in Undefines do begin for S2SItem in Undefines do
MacroName:=S2SItem^.Name; AddUndefine(S2SItem^.Name);
DefTemplate:=TDefineTemplate.Create('Undefine '+MacroName,
'Undefine '+MacroName,
MacroName,'',da_UndefineRecurse);
CodeToolBoss.DefineTree.Add(DefTemplate);
end;
end; end;
procedure TSourceCloser.ConvertLPK(LPKFilename: string); procedure TSourceCloser.ConvertLPK(LPKFilename: string);
@ -541,6 +578,7 @@ constructor TSourceCloser.Create(TheOwner: TComponent);
begin begin
inherited Create(TheOwner); inherited Create(TheOwner);
StopOnException:=True; StopOnException:=True;
FSyntaxMode:=cmOBJFPC;
fDefines:=TStringToStringTree.Create(false); fDefines:=TStringToStringTree.Create(false);
FUndefines:=TStringToStringTree.Create(false); FUndefines:=TStringToStringTree.Create(false);
FLPKFilenames:=TStringList.Create; FLPKFilenames:=TStringList.Create;
@ -589,6 +627,7 @@ begin
writeln(' -p, --disablecompile'); writeln(' -p, --disablecompile');
writeln(' Remove all compile commands from lpk.'); writeln(' Remove all compile commands from lpk.');
writeln('Unit options:'); writeln('Unit options:');
writeln(' -M <SyntaxMode>, --mode=<SyntaxMode> : delphi|delphiunicode|objfpc|fpc|macpas, default: '+CompilerModeNames[SyntaxMode]);
writeln(' -d <MacroName>, --define=<MacroName> :'); writeln(' -d <MacroName>, --define=<MacroName> :');
writeln(' Define Free Pascal macro. Can be passed multiple times.'); writeln(' Define Free Pascal macro. Can be passed multiple times.');
writeln(' -u <MacroName>, --undefine=<MacroName> :'); writeln(' -u <MacroName>, --undefine=<MacroName> :');