Merge of commit r44056

------------------------------------------------------------------------
r44056 | pierre | 2020-01-28 23:43:56 +0000 (Tue, 28 Jan 2020) | 1 line

 Hopefully fix problems related to loading of ppufile generated with other endianess for generics
------------------------------------------------------------------------
--- Merging r44056 into '.':
U    compiler/pdecl.pas
U    compiler/pgenutil.pas
U    compiler/scanner.pas
U    compiler/symdef.pas
--- Recording mergeinfo for merge of r44056 into '.':
 U   .

git-svn-id: branches/fixes_3_2@44060 -
This commit is contained in:
pierre 2020-01-29 21:50:42 +00:00
parent 99affa69c9
commit 7062177e1b
4 changed files with 34 additions and 26 deletions

View File

@ -504,7 +504,7 @@ implementation
isunique,
istyperenaming : boolean;
generictypelist : tfphashobjectlist;
generictokenbuf : tdynamicarray;
localgenerictokenbuf : tdynamicarray;
vmtbuilder : TVMTBuilder;
p:tnode;
gendef : tstoreddef;
@ -527,7 +527,7 @@ implementation
defpos:=current_tokenpos;
istyperenaming:=false;
generictypelist:=nil;
generictokenbuf:=nil;
localgenerictokenbuf:=nil;
{ fpc generic declaration? }
if first then
@ -584,8 +584,8 @@ implementation
{ Start recording a generic template }
if assigned(generictypelist) then
begin
generictokenbuf:=tdynamicarray.create(256);
current_scanner.startrecordtokens(generictokenbuf);
localgenerictokenbuf:=tdynamicarray.create(256);
current_scanner.startrecordtokens(localgenerictokenbuf);
end;
{ is the type already defined? -- must be in the current symtable,
@ -973,7 +973,7 @@ implementation
if assigned(generictypelist) then
begin
current_scanner.stoprecordtokens;
tstoreddef(hdef).generictokenbuf:=generictokenbuf;
tstoreddef(hdef).generictokenbuf:=localgenerictokenbuf;
{ Generic is never a type renaming }
hdef.typesym:=newtype;
generictypelist.free;

View File

@ -1059,7 +1059,7 @@ uses
replaydepth:=current_scanner.replay_stack_depth;
if genericdef.typ=procdef then
begin
current_scanner.startreplaytokens(tprocdef(genericdef).genericdecltokenbuf);
current_scanner.startreplaytokens(tprocdef(genericdef).genericdecltokenbuf,tprocdef(genericdef).generic_buf_needs_swapping);
parse_proc_head(tprocdef(genericdef).struct,tprocdef(genericdef).proctypeoption,false,genericdef,generictypelist,pd);
if assigned(pd) then
begin
@ -1073,7 +1073,7 @@ uses
end
else
begin
current_scanner.startreplaytokens(genericdef.generictokenbuf);
current_scanner.startreplaytokens(genericdef.generictokenbuf,genericdef.generic_buf_needs_swapping);
hadtypetoken:=false;
read_named_type(result,srsym,genericdef,generictypelist,false,hadtypetoken);
ttypesym(srsym).typedef:=result;
@ -1721,7 +1721,7 @@ uses
{ use the index the module got from the current compilation process }
current_filepos.moduleindex:=hmodule.unit_index;
current_tokenpos:=current_filepos;
current_scanner.startreplaytokens(tprocdef(def.genericdef).generictokenbuf);
current_scanner.startreplaytokens(tprocdef(def.genericdef).generictokenbuf,tprocdef(def.genericdef).generic_buf_needs_swapping);
read_proc_body(def);
current_filepos:=oldcurrent_filepos;
end

View File

@ -75,11 +75,12 @@ interface
patternw : pcompilerwidestring;
settings : tsettings;
tokenbuf : tdynamicarray;
tokenbuf_needs_swapping : boolean;
next : treplaystack;
constructor Create(atoken: ttoken;aidtoken:ttoken;
const aorgpattern,apattern:string;const acstringpattern:ansistring;
apatternw:pcompilerwidestring;asettings:tsettings;
atokenbuf:tdynamicarray;anext:treplaystack);
atokenbuf:tdynamicarray;change_endian:boolean;anext:treplaystack);
destructor destroy;override;
end;
@ -145,8 +146,8 @@ interface
{ true, if we are parsing preprocessor expressions }
in_preproc_comp_expr : boolean;
{ true if cross-compiling for a CPU in opposite endianess}
change_endian_for_tokens : boolean;
{ true if tokens must be converted to opposite endianess}
change_endian_for_replay : boolean;
constructor Create(const fn:string; is_macro: boolean = false);
destructor Destroy;override;
@ -184,7 +185,7 @@ interface
procedure stoprecordtokens;
function is_recording_tokens:boolean;
procedure replaytoken;
procedure startreplaytokens(buf:tdynamicarray);
procedure startreplaytokens(buf:tdynamicarray; change_endian:boolean);
{ bit length asizeint is target depend }
procedure tokenwritesizeint(val : asizeint);
procedure tokenwritelongint(val : longint);
@ -2628,7 +2629,7 @@ type
constructor treplaystack.Create(atoken:ttoken;aidtoken:ttoken;
const aorgpattern,apattern:string;const acstringpattern:ansistring;
apatternw:pcompilerwidestring;asettings:tsettings;
atokenbuf:tdynamicarray;anext:treplaystack);
atokenbuf:tdynamicarray;change_endian:boolean;anext:treplaystack);
begin
token:=atoken;
idtoken:=aidtoken;
@ -2643,6 +2644,7 @@ type
end;
settings:=asettings;
tokenbuf:=atokenbuf;
tokenbuf_needs_swapping:=change_endian;
next:=anext;
end;
@ -2700,11 +2702,8 @@ type
lasttoken:=NOTOKEN;
nexttoken:=NOTOKEN;
ignoredirectives:=TFPHashList.Create;
if (current_module is tppumodule) and assigned(tppumodule(current_module).ppufile) then
change_endian_for_tokens:=tppumodule(current_module).ppufile.change_endian
else
change_endian_for_tokens:=false;
end;
change_endian_for_replay:=false;
end;
procedure tscannerfile.firstfile;
@ -2904,7 +2903,7 @@ type
val : asizeint;
begin
replaytokenbuf.read(val,sizeof(asizeint));
if change_endian_for_tokens then
if change_endian_for_replay then
val:=swapendian(val);
result:=val;
end;
@ -2914,7 +2913,7 @@ type
val : longword;
begin
replaytokenbuf.read(val,sizeof(longword));
if change_endian_for_tokens then
if change_endian_for_replay then
val:=swapendian(val);
result:=val;
end;
@ -2924,7 +2923,7 @@ type
val : longint;
begin
replaytokenbuf.read(val,sizeof(longint));
if change_endian_for_tokens then
if change_endian_for_replay then
val:=swapendian(val);
result:=val;
end;
@ -2950,7 +2949,7 @@ type
val : smallint;
begin
replaytokenbuf.read(val,sizeof(smallint));
if change_endian_for_tokens then
if change_endian_for_replay then
val:=swapendian(val);
result:=val;
end;
@ -2960,7 +2959,7 @@ type
val : word;
begin
replaytokenbuf.read(val,sizeof(word));
if change_endian_for_tokens then
if change_endian_for_replay then
val:=swapendian(val);
result:=val;
end;
@ -2982,7 +2981,7 @@ type
i : longint;
begin
replaytokenbuf.read(b,size);
if change_endian_for_tokens then
if change_endian_for_replay then
for i:=0 to size-1 do
Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
end;
@ -3283,18 +3282,22 @@ type
end;
procedure tscannerfile.startreplaytokens(buf:tdynamicarray);
procedure tscannerfile.startreplaytokens(buf:tdynamicarray; change_endian:boolean);
begin
if not assigned(buf) then
internalerror(200511175);
{ save current scanner state }
replaystack:=treplaystack.create(token,idtoken,orgpattern,pattern,
cstringpattern,patternw,current_settings,replaytokenbuf,replaystack);
cstringpattern,patternw,current_settings,replaytokenbuf,change_endian_for_replay,replaystack);
if assigned(inputpointer) then
dec(inputpointer);
{ install buffer }
replaytokenbuf:=buf;
{ Initialize value of change_endian_for_replay variable }
change_endian_for_replay:=change_endian;
{ reload next token }
replaytokenbuf.seek(0);
replaytoken;
@ -3336,6 +3339,7 @@ type
move(replaystack.patternw^.data^,patternw^.data^,replaystack.patternw^.len*sizeof(tcompilerwidechar));
cstringpattern:=replaystack.cstringpattern;
replaytokenbuf:=replaystack.tokenbuf;
change_endian_for_replay:=replaystack.tokenbuf_needs_swapping;
{ restore compiler settings }
current_settings:=replaystack.settings;
popreplaystack;

View File

@ -88,6 +88,7 @@ interface
genericdef : tstoreddef;
genericdefderef : tderef;
generictokenbuf : tdynamicarray;
generic_buf_needs_swapping : boolean;
{ this list contains references to the symbols that make up the
generic parameters; the symbols are not owned by this list
Note: this list is allocated on demand! }
@ -1811,6 +1812,7 @@ implementation
fileinfo := current_filepos;
{$endif}
generictokenbuf:=nil;
generic_buf_needs_swapping:=false;
genericdef:=nil;
typesymderef.reset;
genericdefderef.reset;
@ -1904,6 +1906,7 @@ implementation
begin
sizeleft:=ppufile.getlongint;
initgeneric;
generic_buf_needs_swapping:=ppufile.change_endian;
while sizeleft>0 do
begin
if sizeleft>sizeof(buf) then
@ -5627,6 +5630,7 @@ implementation
import_nr:=0;
inlininginfo:=nil;
deprecatedmsg:=nil;
genericdecltokenbuf:=nil;
end;