* Forbid use of string alias in system unit

This commit is contained in:
Michael VAN CANNEYT 2023-01-04 14:41:51 +01:00 committed by Michael Van Canneyt
parent fb9c718371
commit f364bb6b11
7 changed files with 696 additions and 687 deletions

View File

@ -1654,6 +1654,9 @@ parser_e_suspending_externals_not_supported_on_current_platform=03368_E_Declarin
parser_w_widechar_set_reduced=03369_W_Reducing Widechar set to single-byte AnsiChar set. parser_w_widechar_set_reduced=03369_W_Reducing Widechar set to single-byte AnsiChar set.
% The base type of a set can only have 255 elements. Sets of wide characters % The base type of a set can only have 255 elements. Sets of wide characters
% are reduced to sets of 1-byte characters. % are reduced to sets of 1-byte characters.
parser_e_nostringaliasinsystem=03370_e_Using 'string' alias is not allowed in the system unit. Use short-,ansi- or unicodestring.
% As a safeguard, the system unit may only use basic string types, not the
% string alias which is dependent on the mode in which a unit is compiled.
% %
% \end{description} % \end{description}
% %

View File

@ -483,6 +483,7 @@ const
parser_e_promising_exports_not_supported_on_current_platform=03367; parser_e_promising_exports_not_supported_on_current_platform=03367;
parser_e_suspending_externals_not_supported_on_current_platform=03368; parser_e_suspending_externals_not_supported_on_current_platform=03368;
parser_w_widechar_set_reduced=03369; parser_w_widechar_set_reduced=03369;
parser_e_nostringaliasinsystem=03370;
type_e_mismatch=04000; type_e_mismatch=04000;
type_e_incompatible_types=04001; type_e_incompatible_types=04001;
type_e_not_equal_types=04002; type_e_not_equal_types=04002;
@ -1168,9 +1169,9 @@ const
option_info=11024; option_info=11024;
option_help_pages=11025; option_help_pages=11025;
MsgTxtSize = 91613; MsgTxtSize = 91712;
MsgIdxMax : array[1..20] of longint=( MsgIdxMax : array[1..20] of longint=(
28,109,370,134,102,63,148,38,223,71, 28,109,371,134,102,63,148,38,223,71,
68,20,30,1,1,1,1,1,1,1 68,20,30,1,1,1,1,1,1,1
); );

File diff suppressed because it is too large Load Diff

View File

@ -372,7 +372,7 @@ implementation
exit(true); exit(true);
end; end;
{ system.char? (char=widechar comes from the implicit { system.char? (char=widechar comes from the implicit
uuchar unit -> override) } uachar/uuchar unit -> override) }
if (pattern='CHAR') and if (pattern='CHAR') and
(tmodule(tunitsym(srsym).module).globalsymtable=systemunit) then (tmodule(tunitsym(srsym).module).globalsymtable=systemunit) then
begin begin
@ -399,6 +399,8 @@ implementation
end; end;
_STRING: _STRING:
begin begin
if cs_compilesystem in current_settings.moduleswitches then
Message(parser_e_nostringaliasinsystem);
{ system.string? } { system.string? }
if tmodule(tunitsym(srsym).module).globalsymtable=systemunit then if tmodule(tunitsym(srsym).module).globalsymtable=systemunit then
begin begin

View File

@ -141,6 +141,9 @@ implementation
end end
else else
begin begin
// string[x] is allowed in system unit since it is a shortstring.
if cs_compilesystem in current_settings.moduleswitches then
Message(parser_e_nostringaliasinsystem);
if cs_refcountedstrings in current_settings.localswitches then if cs_refcountedstrings in current_settings.localswitches then
begin begin
if m_default_unicodestring in current_settings.modeswitches then if m_default_unicodestring in current_settings.modeswitches then
@ -4036,6 +4039,8 @@ implementation
_STRING : _STRING :
begin begin
if cs_compilesystem in current_settings.moduleswitches then
Message(parser_e_nostringaliasinsystem);
string_dec(hdef,true); string_dec(hdef,true);
{ STRING can be also a type cast } { STRING can be also a type cast }
if try_to_consume(_LKLAMMER) then if try_to_consume(_LKLAMMER) then
@ -5017,11 +5022,11 @@ implementation
end end
else if (tstringconstnode(p).cst_type in [cst_unicodestring,cst_widestring]) then else if (tstringconstnode(p).cst_type in [cst_unicodestring,cst_widestring]) then
begin begin
pw:=pcompilerwideString(tstringconstnode(p).value_str); pw:=pcompilerwideString(tstringconstnode(p).value_str);
pc:=getmem(getlengthwidestring(pw)); pc:=getmem(getlengthwidestring(pw));
unicode2ascii(pw,pc,current_settings.sourcecodepage); unicode2ascii(pw,pc,current_settings.sourcecodepage);
get_stringconst:=strpas(pc); get_stringconst:=strpas(pc);
freemem(pc); freemem(pc);
end end
else else
get_stringconst:=strpas(snode.value_str); get_stringconst:=strpas(snode.value_str);

View File

@ -495,7 +495,6 @@ implementation
case token of case token of
_STRING: _STRING:
string_dec(def,stoAllowTypeDef in options); string_dec(def,stoAllowTypeDef in options);
_FILE: _FILE:
begin begin
consume(_FILE); consume(_FILE);
@ -1324,8 +1323,8 @@ implementation
begin begin
if (m_default_unicodestring in current_settings.modeswitches) then if (m_default_unicodestring in current_settings.modeswitches) then
begin begin
Message(parser_w_widechar_set_reduced); Message(parser_w_widechar_set_reduced);
def:=csetdef.create(cansichartype,torddef(cansichartype).low.svalue,torddef(cansichartype).high.svalue,true); def:=csetdef.create(cansichartype,torddef(cansichartype).low.svalue,torddef(cansichartype).high.svalue,true);
end end
else else
Message(sym_e_ill_type_decl_set); Message(sym_e_ill_type_decl_set);

View File

@ -1635,7 +1635,7 @@ type
case current_scanner.preproc_token of case current_scanner.preproc_token of
_ID: _ID:
{ system.char? (char=widechar comes from the implicit { system.char? (char=widechar comes from the implicit
uuchar unit -> override) } uachar/uuchar unit -> override) }
if (current_scanner.preproc_pattern='CHAR') and if (current_scanner.preproc_pattern='CHAR') and
(tmodule(tunitsym(srsym).module).globalsymtable=systemunit) then (tmodule(tunitsym(srsym).module).globalsymtable=systemunit) then
begin begin