mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 10:39:18 +02:00
+ more fixes to mark symbols used by preprocessor expressions properly
+ made MarkSymbolAsUsed more fail safe + tests
This commit is contained in:
parent
8b19929ad9
commit
397293f09f
@ -1875,7 +1875,9 @@ type
|
|||||||
procedure MarkSymbolAsUsed(sym: tsym);
|
procedure MarkSymbolAsUsed(sym: tsym);
|
||||||
begin
|
begin
|
||||||
tabstractvarsym(sym).IncRefCount;
|
tabstractvarsym(sym).IncRefCount;
|
||||||
inc(current_module.unitmap[sym.owner.moduleid].refs);
|
{ do we know an owner? }
|
||||||
|
if Assigned(current_module) and Assigned(current_module.unitmap) and Assigned(sym.owner) then
|
||||||
|
inc(current_module.unitmap[sym.owner.moduleid].refs);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function preproc_factor(eval: Boolean):texprvalue;
|
function preproc_factor(eval: Boolean):texprvalue;
|
||||||
@ -2107,9 +2109,15 @@ type
|
|||||||
staticvarsym,
|
staticvarsym,
|
||||||
localvarsym,
|
localvarsym,
|
||||||
paravarsym :
|
paravarsym :
|
||||||
hdef:=tabstractvarsym(srsym).vardef;
|
begin
|
||||||
|
hdef:=tabstractvarsym(srsym).vardef;
|
||||||
|
MarkSymbolAsUsed(srsym);
|
||||||
|
end;
|
||||||
typesym:
|
typesym:
|
||||||
hdef:=ttypesym(srsym).typedef;
|
begin
|
||||||
|
hdef:=ttypesym(srsym).typedef;
|
||||||
|
MarkSymbolAsUsed(srsym);
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
Message(scan_e_error_in_preproc_expr);
|
Message(scan_e_error_in_preproc_expr);
|
||||||
end;
|
end;
|
||||||
@ -2206,6 +2214,7 @@ type
|
|||||||
result:=texprvalue.create_bool(false)
|
result:=texprvalue.create_bool(false)
|
||||||
else
|
else
|
||||||
result:=texprvalue.create_bool(true);
|
result:=texprvalue.create_bool(true);
|
||||||
|
MarkSymbolAsUsed(srsym);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
result:=texprvalue.create_bool(false);
|
result:=texprvalue.create_bool(false);
|
||||||
@ -2303,7 +2312,7 @@ type
|
|||||||
begin
|
begin
|
||||||
result.free;
|
result.free;
|
||||||
result:=texprvalue.create_const(tconstsym(srsym));
|
result:=texprvalue.create_const(tconstsym(srsym));
|
||||||
tconstsym(srsym).IncRefCount;
|
MarkSymbolAsUsed(tconstsym(srsym));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
enumsym:
|
enumsym:
|
||||||
@ -2322,11 +2331,11 @@ type
|
|||||||
begin
|
begin
|
||||||
result.free;
|
result.free;
|
||||||
result:=texprvalue.create_int(tenumsym(srsym).value);
|
result:=texprvalue.create_int(tenumsym(srsym).value);
|
||||||
tenumsym(srsym).IncRefCount;
|
MarkSymbolAsUsed(tenumsym(srsym));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
;
|
MarkSymbolAsUsed(tconstsym(srsym));
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
{ the id must be belong to the set type }
|
{ the id must be belong to the set type }
|
||||||
|
13
tests/test/tpreproc2.pp
Normal file
13
tests/test/tpreproc2.pp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{ %opt=-vh -Seh }
|
||||||
|
program unused;
|
||||||
|
|
||||||
|
uses
|
||||||
|
ctypes;
|
||||||
|
|
||||||
|
begin
|
||||||
|
{$IF HIGH(cint) >255 )}
|
||||||
|
Writeln('cint is larger than one byte')
|
||||||
|
{$ELSE}
|
||||||
|
Writeln('cint is one byte')
|
||||||
|
{$ENDIF}
|
||||||
|
end.
|
13
tests/test/tpreproc3.pp
Normal file
13
tests/test/tpreproc3.pp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{ %opt=-vh -Seh }
|
||||||
|
program unused;
|
||||||
|
|
||||||
|
uses
|
||||||
|
types;
|
||||||
|
|
||||||
|
begin
|
||||||
|
{$IF CurveKappa > 1 )}
|
||||||
|
Writeln('CurveKappa > 1');
|
||||||
|
{$ELSE}
|
||||||
|
Writeln('CurveKappa <= 1');
|
||||||
|
{$ENDIF}
|
||||||
|
end.
|
13
tests/test/tpreproc4.pp
Normal file
13
tests/test/tpreproc4.pp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{ %opt=-vh -Seh }
|
||||||
|
program unused;
|
||||||
|
|
||||||
|
uses
|
||||||
|
types;
|
||||||
|
|
||||||
|
begin
|
||||||
|
{$IF Epsilon > '1' )}
|
||||||
|
Writeln('Epsilon > 1');
|
||||||
|
{$ELSE}
|
||||||
|
Writeln('Epsilon <= 1');
|
||||||
|
{$ENDIF}
|
||||||
|
end.
|
13
tests/test/tpreproc5.pp
Normal file
13
tests/test/tpreproc5.pp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{ %opt=-vh -Seh }
|
||||||
|
program unused;
|
||||||
|
|
||||||
|
uses
|
||||||
|
types;
|
||||||
|
|
||||||
|
begin
|
||||||
|
{$IF FromBeginning > 1 )}
|
||||||
|
Writeln('FromBeginning > 1');
|
||||||
|
{$ELSE}
|
||||||
|
Writeln('FromBeginning <= 1');
|
||||||
|
{$ENDIF}
|
||||||
|
end.
|
13
tests/test/tpreproc6.pp
Normal file
13
tests/test/tpreproc6.pp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{ %opt=-vh -Seh }
|
||||||
|
program unused;
|
||||||
|
|
||||||
|
uses
|
||||||
|
types;
|
||||||
|
|
||||||
|
begin
|
||||||
|
{$IF Declared(Epsilon)}
|
||||||
|
Writeln('Epsilon declared');
|
||||||
|
{$ELSE}
|
||||||
|
Writeln('Epsilon not declared');
|
||||||
|
{$ENDIF}
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user