Procházet zdrojové kódy

compiler:
- return default compiler codepage to 8859-1
- emit ansistring constants in CP_NONE by default
- add new modeswitch systemcodepage which sets default compiler codepage to system and emits ansistring constants with systemcodepage as delphi do
- add new mode DelphiUnicode with has the same switches as delphi mode + systemcodepage switch. Later it will also have string = unicodestring by default.

git-svn-id: trunk@19165 -

paul před 14 roky
rodič
revize
828367bebd

+ 1 - 1
compiler/asmutils.pas

@@ -59,7 +59,7 @@ uses
             current_asmdata.getdatalabel(referencelab);
             list.concat(tai_label.create(referencelab));
           end;
-        if encoding=CP_NONE then
+        if (encoding=CP_NONE) and (m_systemcodepage in current_settings.modeswitches) then
           encoding:=current_settings.sourcecodepage;
         list.concat(tai_const.create_16bit(encoding));
         list.concat(tai_const.create_16bit(1));

+ 1 - 2
compiler/globals.pas

@@ -53,6 +53,7 @@ interface
           m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
           m_out,m_default_para,m_duplicate_names,m_hintdirective,
           m_property,m_default_inline,m_except,m_advanced_records];
+       delphiunicodemodeswitches = delphimodeswitches + [m_systemcodepage];
        fpcmodeswitches =
          [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
           m_cvar_support,m_initfinal,m_hintdirective,
@@ -1532,8 +1533,6 @@ implementation
         init_settings:=default_settings;
         if init_settings.optimizecputype=cpu_none then
           init_settings.optimizecputype:=init_settings.cputype;
-        { Compiler codepage should be default system codepage }
-        init_settings.sourcecodepage:=DefaultSystemCodePage;
 
         LinkLibraryAliases :=TLinkStrMap.Create;
         LinkLibraryOrder   :=TLinkStrMap.Create;

+ 4 - 2
compiler/globtype.pas

@@ -295,7 +295,8 @@ interface
          m_nested_procvars,     { support nested procedural variables }
          m_non_local_goto,      { support non local gotos (like iso pascal) }
          m_advanced_records,    { advanced record syntax with visibility sections, methods and properties }
-         m_isolike_unary_minus  { unary minus like in iso pascal: same precedence level as binary minus/plus }
+         m_isolike_unary_minus, { unary minus like in iso pascal: same precedence level as binary minus/plus }
+         m_systemcodepage       { use system codepage as compiler codepage by default, emit ansistrings with system codepage }
        );
        tmodeswitches = set of tmodeswitch;
 
@@ -427,7 +428,8 @@ interface
          'NESTEDPROCVARS',
          'NONLOCALGOTO',
          'ADVANCEDRECORDS',
-         'ISOUNARYMINUS');
+         'ISOUNARYMINUS',
+         'SYSTEMCODEPAGE');
 
 
      type

+ 11 - 0
compiler/scanner.pas

@@ -324,6 +324,14 @@ implementation
            if changeinit then
             exclude(init_settings.localswitches,cs_do_inline);
          end;
+
+        { turn system codepage by default }
+        if m_systemcodepage in current_settings.modeswitches then
+          begin
+            current_settings.sourcecodepage:=DefaultSystemCodePage;
+            if changeinit then
+              init_settings.sourcecodepage:=DefaultSystemCodePage;
+          end;
       end;
 
 
@@ -340,6 +348,9 @@ implementation
         else
          if s='DELPHI' then
           current_settings.modeswitches:=delphimodeswitches
+        else
+         if s='DELPHIUNICODE' then
+          current_settings.modeswitches:=delphiunicodemodeswitches
         else
          if s='TP' then
           current_settings.modeswitches:=tpmodeswitches

+ 3 - 2
tests/test/tcpstr9.pp

@@ -1,11 +1,12 @@
 program tcpstr9;
+{$mode delphiunicode}
 {$apptype console}
 begin
   // this test can be only run with the compiler built right now on the
   // same system
-  if StringCodePage('test') <> DefaultSystemCodePage then
+  if StringCodePage(AnsiString('test')) <> DefaultSystemCodePage then
   begin
-    WriteLn(StringCodePage('test'), ' <> ', DefaultSystemCodePage);
+    WriteLn(StringCodePage(AnsiString('test')), ' <> ', DefaultSystemCodePage);
     halt(1);
   end;
   Writeln('ok');