Browse Source

* Add is_systemunit_unicode function (cchartype suymbol)

Michaël Van Canneyt 2 years ago
parent
commit
cd6d048588
2 changed files with 23 additions and 0 deletions
  1. 22 0
      compiler/defutil.pas
  2. 1 0
      compiler/symdef.pas

+ 22 - 0
compiler/defutil.pas

@@ -313,6 +313,9 @@ interface
     { true, if def is a signed int type, equal in size to the processor's native int size }
     function is_nativesint(def : tdef) : boolean;
 
+    { true, if the char type is a widechar in the system unit }
+    function is_systemunit_unicode : boolean;
+
   type
     tperformrangecheck = (
       rc_internal,  { nothing, internal conversion }
@@ -417,6 +420,7 @@ implementation
 
     uses
        verbose,cutils,
+       symtable, // search_system_type
        symsym,
        cpuinfo;
 
@@ -1250,6 +1254,24 @@ implementation
          result:=is_nativeint(def) and (def.typ=orddef) and (torddef(def).ordtype in [s64bit,s32bit,s16bit,s8bit]);
       end;
 
+    function is_systemunit_unicode: boolean;
+
+    var
+      t : ttypesym;
+
+    begin
+      if cchartype=nil then
+        begin
+          t:=search_system_type('CHAR');
+          if t<>nil then
+            cchartype:=t.typedef;
+        end;
+      if cchartype=nil then
+        is_systemunit_unicode:=(sizeof(char)=2)
+      else
+        is_systemunit_unicode:=(cchartype.size=2);
+    end;
+
     { if l isn't in the range of todef a range check error (if not explicit) is generated and
       the value is placed within the range }
     procedure adaptrange(todef : tdef;var l : tconstexprint; rangecheck: tperformrangecheck);

+ 1 - 0
compiler/symdef.pas

@@ -1177,6 +1177,7 @@ interface
        voidtype,                  { Void (procedure) }
        cansichartype,             { Char }
        cwidechartype,             { WideChar }
+       cchartype,                 { either cansichartype or cwidechartype. Do not free }
        pasbool1type,              { boolean type }
        pasbool8type,
        pasbool16type,