fcl-passrc: parse $optimization

git-svn-id: trunk@45586 -
This commit is contained in:
Mattias Gaertner 2020-06-05 15:45:06 +00:00
parent 35c5479f96
commit 837b782159
2 changed files with 123 additions and 60 deletions

View File

@ -2366,6 +2366,7 @@ type
function GetCombinedBaseType(const A, B: TPasResolverResult; ErrorEl: TPasElement): TResolverBaseType; virtual;
function IsElementSkipped(El: TPasElement): boolean; virtual;
function FindLocalBuiltInSymbol(El: TPasElement): TPasElement; virtual;
function GetFirstSection: TPasSection;
function GetLastSection: TPasSection;
function GetShiftAndMaskForLoHiFunc(BaseType: TResolverBaseType;
isLoFunc: Boolean; out Mask: LongWord): Integer;
@ -29156,6 +29157,23 @@ begin
Result:=nil;
end;
function TPasResolver.GetFirstSection: TPasSection;
var
Module: TPasModule;
begin
Result:=nil;
Module:=RootElement;
if Module=nil then exit;
if Module is TPasProgram then
Result:=TPasProgram(Module).ProgramSection
else if Module is TPasLibrary then
Result:=TPasLibrary(Module).LibrarySection
else if Module.InterfaceSection<>nil then
Result:=Module.InterfaceSection
else
Result:=Module.ImplementationSection;
end;
function TPasResolver.GetLastSection: TPasSection;
var
Module: TPasModule;

View File

@ -821,6 +821,8 @@ type
procedure HandleMessageDirective(Param: String); virtual;
procedure HandleIncludeFile(Param: String); virtual;
procedure HandleResource(Param : string); virtual;
procedure HandleOptimizations(Param : string); virtual;
procedure DoHandleOptimization(OptName, OptValue: string); virtual;
procedure HandleUnDefine(Param: String); virtual;
@ -3416,6 +3418,47 @@ begin
end;
end;
procedure TPascalScanner.HandleOptimizations(Param: string);
// $optimization A,B-,C+
var
p, StartP, l: Integer;
OptName, Value: String;
begin
p:=1;
l:=length(Param);
while p<=l do
begin
// read next flag
// skip whitespace
while (p<=l) and (Param[p] in [' ',#9,#10,#13]) do
inc(p);
// read name
StartP:=p;
while (p<=l) and (Param[p] in ['a'..'z','A'..'Z','0'..'9','_']) do
inc(p);
if p=StartP then
Error(nWarnIllegalCompilerDirectiveX,sWarnIllegalCompilerDirectiveX,['optimization']);
OptName:=copy(Param,StartP,p-StartP);
// skip whitespace
while (p<=l) and (Param[p] in [' ',#9,#10,#13]) do
inc(p);
// read value
StartP:=p;
while (p<=l) and (Param[p]<>',') do
inc(p);
Value:=TrimRight(copy(Param,StartP,p-StartP));
DoHandleOptimization(OptName,Value);
inc(p);
end;
end;
procedure TPascalScanner.DoHandleOptimization(OptName, OptValue: string);
begin
// default: skip any optimization directive
if OptName='' then ;
if OptValue='' then ;
end;
function TPascalScanner.HandleMacro(AIndex : integer) : TToken;
Var
@ -4046,6 +4089,8 @@ begin
DoBoolDirective(bsNotes);
'OBJECTCHECKS':
DoBoolDirective(bsObjectChecks);
'OPTIMIZATION':
HandleOptimizations(Param);
'OVERFLOWCHECKS','OV':
DoBoolDirective(bsOverflowChecks);
'POINTERMATH':