IDE: Parse and select numbers in a set of compiler options.

git-svn-id: trunk@42351 -
This commit is contained in:
juha 2013-08-05 11:34:06 +00:00
parent 208883a516
commit feb1e4a422

View File

@ -147,6 +147,8 @@ type
TCompilerOptSet = class(TCompilerOptGroup) TCompilerOptSet = class(TCompilerOptGroup)
private private
fHasNumber: Boolean; fHasNumber: Boolean;
function SetNumberOpt(aValue: string): Boolean;
function SetBooleanOpt(aValue: string): Boolean;
protected protected
procedure AddOptions(aDescr: string; aIndent: integer); procedure AddOptions(aDescr: string; aIndent: integer);
procedure ParseOption(aDescr: string; aIndent: integer); override; procedure ParseOption(aDescr: string; aIndent: integer); override;
@ -546,8 +548,8 @@ begin
else begin else begin
// Option was not found, try separating the parameter. // Option was not found, try separating the parameter.
// ToDo: figure out the length in a more clever way. // ToDo: figure out the length in a more clever way.
Assert((Length(aOptAndValue)>2) and (aOptAndValue[1]='-'), if (Length(aOptAndValue) < 3) or (aOptAndValue[1] <> '-') then
'TCompilerOptGroup.SelectOption: Invalid option & value '+aOptAndValue); raise Exception.Create('Invalid option & value ' + aOptAndValue);
if aOptAndValue[2] in ['e', 'd', 'u', 'I', 'k', 'o'] then if aOptAndValue[2] in ['e', 'd', 'u', 'I', 'k', 'o'] then
OptLen := 2 OptLen := 2
else else
@ -601,24 +603,66 @@ begin
Result := Option + s; Result := Option + s;
end; end;
function TCompilerOptSet.SetNumberOpt(aValue: string): Boolean;
// Find a numeric value in the set and update its value. Return True on success.
var
i: Integer;
Opt: TCompilerOpt;
begin
for i := 0 to fCompilerOpts.Count-1 do
begin
Opt := TCompilerOpt(fCompilerOpts[i]);
if Opt.EditKind = oeSetNumber then
begin
Opt.Value := aValue;
Exit(True); // Found and updated.
end;
end;
Result := False; // Not found.
end;
function TCompilerOptSet.SetBooleanOpt(aValue: string): Boolean;
// Find a single letter value in the set and update its value. Return True on success.
var
i: Integer;
Opt: TCompilerOpt;
begin
for i := 0 to fCompilerOpts.Count-1 do
begin
Opt := TCompilerOpt(fCompilerOpts[i]);
if (Opt.EditKind = oeSetElem) and (Opt.Option = aValue) then
begin
Opt.Value := 'True';
Exit(True); // Found and updated.
end;
end;
Result := False; // Not found.
end;
procedure TCompilerOptSet.SelectOptions(aOptStr: string); procedure TCompilerOptSet.SelectOptions(aOptStr: string);
// Select options in this set based on the given characters. // Select options in this set based on the given characters.
var var
i, j: Integer; i, Start: Integer;
OptChar: string; OneOpt: string;
Opt: TCompilerOpt;
begin begin
for i := 1 to Length(aOptStr) do i := 1;
while i <= Length(aOptStr) do
begin begin
OptChar := aOptStr[i]; Start := i;
for j := 0 to fCompilerOpts.Count-1 do if aOptStr[i] in ['0'..'9'] then
while (aOptStr[i] in ['0'..'9']) and (i <= Length(aOptStr)) do
Inc(i)
else
Inc(i);
OneOpt := Copy(aOptStr, Start, i-Start);
if OneOpt[1] in ['0'..'9'] then
begin begin
Opt := TCompilerOpt(fCompilerOpts[j]); if not SetNumberOpt(OneOpt) then
if Opt.Option = OptChar then raise Exception.CreateFmt('Numeric value is not allowed for set %s.', [fOption]);
begin end
Opt.Value := 'True'; else begin
Break; if not SetBooleanOpt(OneOpt) then
end; raise Exception.CreateFmt('Option %s is not found in set %s.', [OneOpt, fOption]);
end; end;
end; end;
end; end;