diff options
-rw-r--r-- | compiler/defcmp.pas | 8 | ||||
-rw-r--r-- | compiler/pexpr.pas | 78 |
2 files changed, 47 insertions, 39 deletions
diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas index 068354da60..bfc445c5a9 100644 --- a/compiler/defcmp.pas +++ b/compiler/defcmp.pas @@ -340,10 +340,14 @@ implementation end; end else - { Same string type, for shortstrings also the length must match } + { same string type ? } if (tstringdef(def_from).stringtype=tstringdef(def_to).stringtype) and + { for shortstrings also the length must match } ((tstringdef(def_from).stringtype<>st_shortstring) or - (tstringdef(def_from).len=tstringdef(def_to).len)) then + (tstringdef(def_from).len=tstringdef(def_to).len)) and + { for ansi- and unicodestrings also the encoding must match } + (not(tstringdef(def_from).stringtype in [st_ansistring,st_unicodestring]) or + (tstringdef(def_from).stringencoding=tstringdef(def_to).stringencoding))then eq:=te_equal else begin diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 7176a4ea80..b78288921f 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -92,48 +92,52 @@ implementation { and returns a pointer to the string } { definition } var - p : tnode; + p : tnode; begin - def:=cshortstringtype; - consume(_STRING); - if try_to_consume(_LECKKLAMMER) then - begin - p:=comp_expr(true); - if not is_constintnode(p) then - begin - Message(parser_e_illegal_expression); - { error recovery } - consume(_RECKKLAMMER); - end - else - begin - if (tordconstnode(p).value<=0) then - begin - Message(parser_e_invalid_string_size); - tordconstnode(p).value:=255; - end; + def:=cshortstringtype; + consume(_STRING); + if try_to_consume(_LECKKLAMMER) then + begin + p:=comp_expr(true); + if not is_constintnode(p) then + begin + Message(parser_e_illegal_expression); + { error recovery } consume(_RECKKLAMMER); - if tordconstnode(p).value>255 then + end + else + begin + if (tordconstnode(p).value<=0) then begin - { longstring is currently unsupported (CEC)! } -{ t:=tstringdef.createlong(tordconstnode(p).value))} Message(parser_e_invalid_string_size); tordconstnode(p).value:=255; - def:=tstringdef.createshort(int64(tordconstnode(p).value)); - end - else - if tordconstnode(p).value<>255 then - def:=tstringdef.createshort(int64(tordconstnode(p).value)); - end; - p.free; - end - else - begin - if cs_ansistrings in current_settings.localswitches then - def:=cansistringtype - else - def:=cshortstringtype; - end; + end; + consume(_RECKKLAMMER); + if tordconstnode(p).value>255 then + begin + { longstring is currently unsupported (CEC)! } +{ t:=tstringdef.createlong(tordconstnode(p).value))} + Message(parser_e_invalid_string_size); + tordconstnode(p).value:=255; + def:=tstringdef.createshort(int64(tordconstnode(p).value)); + end + else + if tordconstnode(p).value<>255 then + def:=tstringdef.createshort(int64(tordconstnode(p).value)); + end; + p.free; + end + else if try_to_consume(_GT) then + begin + consume(_LT); + end + else + begin + if cs_ansistrings in current_settings.localswitches then + def:=cansistringtype + else + def:=cshortstringtype; + end; end; |