mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-09 21:08:26 +02:00
* Use dyn array of char for macro contents
This commit is contained in:
parent
ec3ed04b73
commit
166a24ae77
@ -365,7 +365,8 @@ uses
|
|||||||
begin
|
begin
|
||||||
{ create new buffer }
|
{ create new buffer }
|
||||||
SetLength(buf,len+1);
|
SetLength(buf,len+1);
|
||||||
move(p^,buf[0],len);
|
if len>0 then
|
||||||
|
move(p^,buf[0],len);
|
||||||
buf[len]:=#0;
|
buf[len]:=#0;
|
||||||
{ reset }
|
{ reset }
|
||||||
bufstart:=0;
|
bufstart:=0;
|
||||||
|
@ -168,6 +168,7 @@ type
|
|||||||
procedure writeheader;override;
|
procedure writeheader;override;
|
||||||
procedure putdata(const b;len:integer);override;
|
procedure putdata(const b;len:integer);override;
|
||||||
procedure putdata(b : tbytedynarray);
|
procedure putdata(b : tbytedynarray);
|
||||||
|
procedure putdata(b : tansichardynarray);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -528,6 +529,11 @@ begin
|
|||||||
putdata(b[0],length(b));
|
putdata(b[0],length(b));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure tppufile.putdata(b: tansichardynarray);
|
||||||
|
begin
|
||||||
|
putdata(b[0],length(b));
|
||||||
|
end;
|
||||||
|
|
||||||
function tppufile.getheadersize: longint;
|
function tppufile.getheadersize: longint;
|
||||||
begin
|
begin
|
||||||
result:=sizeof(header);
|
result:=sizeof(header);
|
||||||
|
@ -1836,7 +1836,8 @@ type
|
|||||||
else
|
else
|
||||||
len:=mac.buflen;
|
len:=mac.buflen;
|
||||||
hs[0]:=char(len);
|
hs[0]:=char(len);
|
||||||
move(mac.buftext^,hs[1],len);
|
if len>0 then
|
||||||
|
move(mac.buftext[0],hs[1],len);
|
||||||
searchstr2store:=upcase(hs);
|
searchstr2store:=upcase(hs);
|
||||||
searchstr:=@searchstr2store;
|
searchstr:=@searchstr2store;
|
||||||
mac.is_used:=true;
|
mac.is_used:=true;
|
||||||
@ -2588,6 +2589,7 @@ type
|
|||||||
current_scanner.readchar;
|
current_scanner.readchar;
|
||||||
if c <> '=' then
|
if c <> '=' then
|
||||||
exit;
|
exit;
|
||||||
|
mac.is_c_macro:=true;
|
||||||
current_scanner.readchar;
|
current_scanner.readchar;
|
||||||
current_scanner.skipspace;
|
current_scanner.skipspace;
|
||||||
end;
|
end;
|
||||||
@ -2625,7 +2627,8 @@ type
|
|||||||
until false;
|
until false;
|
||||||
|
|
||||||
{ copy the text }
|
{ copy the text }
|
||||||
move(pchar(@macrobuffer[0])^,mac.allocate_buftext(macropos)^,macropos);
|
if macropos>0 then
|
||||||
|
move(pchar(@macrobuffer[0])^,mac.allocate_buftext(macropos)^,macropos);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -2738,6 +2741,7 @@ type
|
|||||||
begin
|
begin
|
||||||
mac.defined:=false;
|
mac.defined:=false;
|
||||||
mac.is_compiler_var:=false;
|
mac.is_compiler_var:=false;
|
||||||
|
mac.is_c_macro:=false;
|
||||||
{ delete old definition }
|
{ delete old definition }
|
||||||
mac.free_buftext;
|
mac.free_buftext;
|
||||||
end;
|
end;
|
||||||
@ -5346,13 +5350,13 @@ type
|
|||||||
if (cs_support_macro in current_settings.moduleswitches) then
|
if (cs_support_macro in current_settings.moduleswitches) then
|
||||||
begin
|
begin
|
||||||
mac:=tmacro(search_macro(pattern));
|
mac:=tmacro(search_macro(pattern));
|
||||||
if assigned(mac) and (not mac.is_compiler_var) and (assigned(mac.buftext)) then
|
if assigned(mac) and (not mac.is_compiler_var) and mac.is_c_macro then
|
||||||
begin
|
begin
|
||||||
if (yylexcount<max_macro_nesting) and (macro_nesting_depth<max_macro_nesting) then
|
if (yylexcount<max_macro_nesting) and (macro_nesting_depth<max_macro_nesting) then
|
||||||
begin
|
begin
|
||||||
mac.is_used:=true;
|
mac.is_used:=true;
|
||||||
inc(yylexcount);
|
inc(yylexcount);
|
||||||
substitutemacro(pattern,mac.buftext,mac.buflen,
|
substitutemacro(pattern,pchar(mac.buftext),mac.buflen,
|
||||||
mac.fileinfo.line,mac.fileinfo.fileindex,false);
|
mac.fileinfo.line,mac.fileinfo.fileindex,false);
|
||||||
{ handle empty macros }
|
{ handle empty macros }
|
||||||
if c=#0 then
|
if c=#0 then
|
||||||
|
@ -475,11 +475,13 @@ interface
|
|||||||
{True if this is a mac style compiler variable, in which case no macro
|
{True if this is a mac style compiler variable, in which case no macro
|
||||||
substitutions shall be done.}
|
substitutions shall be done.}
|
||||||
is_compiler_var : boolean;
|
is_compiler_var : boolean;
|
||||||
|
{ true if the macro is a C macro, i.e used := }
|
||||||
|
is_c_macro : boolean;
|
||||||
{Whether the macro was used. NOTE: A use of a macro which was never defined}
|
{Whether the macro was used. NOTE: A use of a macro which was never defined}
|
||||||
{e. g. an IFDEF which returns false, will not be registered as used,}
|
{e. g. an IFDEF which returns false, will not be registered as used,}
|
||||||
{since there is no place to register its use. }
|
{since there is no place to register its use. }
|
||||||
is_used : boolean;
|
is_used : boolean;
|
||||||
buftext : pchar;
|
buftext : TAnsiCharDynArray;
|
||||||
buflen : longint;
|
buflen : longint;
|
||||||
constructor create(const n : TSymStr);
|
constructor create(const n : TSymStr);
|
||||||
constructor ppuload(ppufile:tcompilerppufile);
|
constructor ppuload(ppufile:tcompilerppufile);
|
||||||
@ -3111,17 +3113,14 @@ implementation
|
|||||||
defined:=ppufile.getboolean;
|
defined:=ppufile.getboolean;
|
||||||
is_compiler_var:=ppufile.getboolean;
|
is_compiler_var:=ppufile.getboolean;
|
||||||
is_used:=false;
|
is_used:=false;
|
||||||
buflen:= ppufile.getlongint;
|
allocate_buftext(ppufile.getlongint);
|
||||||
if buflen > 0 then
|
if buflen>0 then
|
||||||
ppufile.getdata(allocate_buftext(buflen)^, buflen)
|
ppufile.getdata(buftext)
|
||||||
else
|
|
||||||
buftext:=nil;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor tmacro.destroy;
|
destructor tmacro.destroy;
|
||||||
begin
|
begin
|
||||||
if assigned(buftext) then
|
buftext:=nil;
|
||||||
freemem(buftext);
|
|
||||||
inherited destroy;
|
inherited destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3132,29 +3131,23 @@ implementation
|
|||||||
ppufile.putboolean(is_compiler_var);
|
ppufile.putboolean(is_compiler_var);
|
||||||
ppufile.putlongint(buflen);
|
ppufile.putlongint(buflen);
|
||||||
if buflen > 0 then
|
if buflen > 0 then
|
||||||
ppufile.putdata(buftext^,buflen);
|
ppufile.putdata(buftext);
|
||||||
writeentry(ppufile,ibmacrosym);
|
writeentry(ppufile,ibmacrosym);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function tmacro.allocate_buftext(len:longint) : pchar;
|
function tmacro.allocate_buftext(len:longint) : pchar;
|
||||||
begin
|
begin
|
||||||
result:=getmem(len);
|
setlength(buftext,len);
|
||||||
if assigned(buftext) then
|
|
||||||
freemem(buftext);
|
|
||||||
buftext:=result;
|
|
||||||
buflen:=len;
|
buflen:=len;
|
||||||
|
result:=PAnsiChar(buftext);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure tmacro.free_buftext;
|
procedure tmacro.free_buftext;
|
||||||
begin
|
begin
|
||||||
if assigned(buftext) then
|
buftext:=nil;
|
||||||
begin
|
buflen:=0;
|
||||||
freemem(buftext);
|
|
||||||
buftext:=nil;
|
|
||||||
buflen:=0;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -3166,9 +3159,10 @@ implementation
|
|||||||
p.defined:=defined;
|
p.defined:=defined;
|
||||||
p.is_used:=is_used;
|
p.is_used:=is_used;
|
||||||
p.is_compiler_var:=is_compiler_var;
|
p.is_compiler_var:=is_compiler_var;
|
||||||
p.buflen:=buflen;
|
p.is_c_macro:=is_c_macro;
|
||||||
if assigned(buftext) then
|
p.allocate_buftext(buflen);
|
||||||
move(buftext^,p.allocate_buftext(buflen)^,buflen);
|
if buflen>0 then
|
||||||
|
move(buftext[0],p.buftext[0],buflen);
|
||||||
Result:=p;
|
Result:=p;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -4923,6 +4923,7 @@ implementation
|
|||||||
mac.is_compiler_var:=false;
|
mac.is_compiler_var:=false;
|
||||||
mac.free_buftext;
|
mac.free_buftext;
|
||||||
end;
|
end;
|
||||||
|
mac.is_c_macro:=true;
|
||||||
Message2(parser_c_macro_set_to,mac.name,value);
|
Message2(parser_c_macro_set_to,mac.name,value);
|
||||||
move(value[1],mac.allocate_buftext(length(value))^,length(value));
|
move(value[1],mac.allocate_buftext(length(value))^,length(value));
|
||||||
mac.defined:=true;
|
mac.defined:=true;
|
||||||
|
Loading…
Reference in New Issue
Block a user