Bladeren bron

* Rework the constexprint to allow operations from low(int64) to high(qword).
+ Some initial work on a formaldef which also carries the typinfo of a parameter.

git-svn-id: trunk@7639 -

daniel 18 jaren geleden
bovenliggende
commit
9adb202a92
100 gewijzigde bestanden met toevoegingen van 730 en 720 verwijderingen
  1. 3 3
      .gitattributes
  2. 4 2
      compiler/aasmtai.pas
  3. 1 1
      compiler/aggas.pas
  4. 9 9
      compiler/arm/narmset.pas
  5. 1 1
      compiler/assemble.pas
  6. 2 6
      compiler/cfileutl.pas
  7. 2 2
      compiler/cg64f32.pas
  8. 5 5
      compiler/cgobj.pas
  9. 1 1
      compiler/compiler.pas
  10. 1 1
      compiler/comprsrc.pas
  11. 65 65
      compiler/crefs.pas
  12. 2 2
      compiler/dbgdwarf.pas
  13. 4 4
      compiler/dbgstabs.pas
  14. 1 1
      compiler/defcmp.pas
  15. 41 92
      compiler/defutil.pas
  16. 1 1
      compiler/finput.pas
  17. 4 4
      compiler/fmodule.pas
  18. 1 1
      compiler/fppu.pas
  19. 2 10
      compiler/globals.pas
  20. 6 10
      compiler/globtype.pas
  21. 2 2
      compiler/htypechk.pas
  22. 12 12
      compiler/i386/n386mat.pas
  23. 8 8
      compiler/i386/n386set.pas
  24. 1 1
      compiler/link.pas
  25. 49 89
      compiler/nadd.pas
  26. 14 6
      compiler/ncal.pas
  27. 2 2
      compiler/ncgcon.pas
  28. 24 24
      compiler/ncgflw.pas
  29. 3 3
      compiler/ncginl.pas
  30. 3 3
      compiler/ncgld.pas
  31. 3 3
      compiler/ncgmat.pas
  32. 10 10
      compiler/ncgmem.pas
  33. 1 1
      compiler/ncgopt.pas
  34. 16 9
      compiler/ncgrtti.pas
  35. 34 33
      compiler/ncgset.pas
  36. 1 1
      compiler/ncgutil.pas
  37. 18 18
      compiler/ncnv.pas
  38. 3 3
      compiler/ncon.pas
  39. 3 3
      compiler/nflw.pas
  40. 36 20
      compiler/ninl.pas
  41. 5 15
      compiler/nmat.pas
  42. 5 5
      compiler/nmem.pas
  43. 8 8
      compiler/nset.pas
  44. 2 2
      compiler/nutils.pas
  45. 1 1
      compiler/ogmap.pas
  46. 1 1
      compiler/options.pas
  47. 1 1
      compiler/optunrol.pas
  48. 2 2
      compiler/pbase.pas
  49. 4 4
      compiler/pdecl.pas
  50. 66 13
      compiler/pdecsub.pas
  51. 23 7
      compiler/pdecvar.pas
  52. 9 2
      compiler/pexports.pas
  53. 11 11
      compiler/pexpr.pas
  54. 3 3
      compiler/pinline.pas
  55. 1 1
      compiler/pmodules.pas
  56. 8 8
      compiler/powerpc/nppcmat.pas
  57. 4 4
      compiler/powerpc64/nppcmat.pas
  58. 10 10
      compiler/ppcgen/ngppcset.pas
  59. 2 3
      compiler/ppu.pas
  60. 5 5
      compiler/pstatmnt.pas
  61. 1 1
      compiler/psub.pas
  62. 9 6
      compiler/psystem.pas
  63. 33 20
      compiler/ptconst.pas
  64. 18 11
      compiler/ptype.pas
  65. 2 2
      compiler/rautils.pas
  66. 2 2
      compiler/rgobj.pas
  67. 1 1
      compiler/scandir.pas
  68. 4 4
      compiler/scanner.pas
  69. 1 1
      compiler/script.pas
  70. 5 5
      compiler/sparc/ncpumat.pas
  71. 3 3
      compiler/sparc/ncpuset.pas
  72. 2 1
      compiler/symconst.pas
  73. 19 27
      compiler/symdef.pas
  74. 1 1
      compiler/symsym.pas
  75. 19 20
      compiler/symtype.pas
  76. 1 1
      compiler/symutil.pas
  77. 2 2
      compiler/systems/i_embed.pas
  78. 1 1
      compiler/systems/i_linux.pas
  79. 1 1
      compiler/systems/t_amiga.pas
  80. 1 1
      compiler/systems/t_beos.pas
  81. 1 1
      compiler/systems/t_bsd.pas
  82. 3 3
      compiler/systems/t_embed.pas
  83. 3 3
      compiler/systems/t_emx.pas
  84. 1 1
      compiler/systems/t_gba.pas
  85. 1 1
      compiler/systems/t_go32v2.pas
  86. 1 1
      compiler/systems/t_linux.pas
  87. 1 1
      compiler/systems/t_macos.pas
  88. 1 1
      compiler/systems/t_morph.pas
  89. 1 1
      compiler/systems/t_nds.pas
  90. 1 1
      compiler/systems/t_nwl.pas
  91. 1 1
      compiler/systems/t_nwm.pas
  92. 3 3
      compiler/systems/t_os2.pas
  93. 1 1
      compiler/systems/t_palmos.pas
  94. 1 1
      compiler/systems/t_sunos.pas
  95. 1 1
      compiler/systems/t_symbian.pas
  96. 1 1
      compiler/systems/t_watcom.pas
  97. 1 1
      compiler/systems/t_win.pas
  98. 4 2
      compiler/verbose.pas
  99. 5 4
      compiler/x86/aasmcpu.pas
  100. 2 2
      compiler/x86/nx86inl.pas

+ 3 - 3
.gitattributes

@@ -79,7 +79,7 @@ compiler/bsdcompile -text
 compiler/catch.pas svneol=native#text/plain
 compiler/cclasses.pas svneol=native#text/plain
 compiler/cfidwarf.pas svneol=native#text/plain
-compiler/cfileutils.pas svneol=native#text/plain
+compiler/cfileutl.pas svneol=native#text/plain
 compiler/cg64f32.pas svneol=native#text/plain
 compiler/cgbase.pas svneol=native#text/plain
 compiler/cgobj.pas svneol=native#text/plain
@@ -453,7 +453,7 @@ compiler/systems/i_amiga.pas svneol=native#text/plain
 compiler/systems/i_atari.pas svneol=native#text/plain
 compiler/systems/i_beos.pas svneol=native#text/plain
 compiler/systems/i_bsd.pas svneol=native#text/plain
-compiler/systems/i_embedded.pas svneol=native#text/plain
+compiler/systems/i_embed.pas svneol=native#text/plain
 compiler/systems/i_emx.pas svneol=native#text/plain
 compiler/systems/i_gba.pas svneol=native#text/plain
 compiler/systems/i_go32v2.pas svneol=native#text/plain
@@ -475,7 +475,7 @@ compiler/systems/t_amiga.pas svneol=native#text/plain
 compiler/systems/t_atari.pas svneol=native#text/plain
 compiler/systems/t_beos.pas svneol=native#text/plain
 compiler/systems/t_bsd.pas svneol=native#text/plain
-compiler/systems/t_embedded.pas svneol=native#text/plain
+compiler/systems/t_embed.pas svneol=native#text/plain
 compiler/systems/t_emx.pas svneol=native#text/plain
 compiler/systems/t_gba.pas svneol=native#text/plain
 compiler/systems/t_go32v2.pas svneol=native#text/plain

+ 4 - 2
compiler/aasmtai.pas

@@ -33,7 +33,7 @@ interface
 
     uses
        cutils,cclasses,
-       globtype,globals,systems,
+       globtype,systems,
        cpuinfo,cpubase,
        cgbase,cgutils,
        symtype,
@@ -651,7 +651,9 @@ implementation
 
     uses
       SysUtils,
-      verbose;
+      verbose,
+      globals,
+      fmodule;
 
     const
       pputaimarker = 254;

+ 1 - 1
compiler/aggas.pas

@@ -91,7 +91,7 @@ implementation
 
     uses
       SysUtils,
-      cutils,cfileutils,systems,
+      cutils,cfileutl,systems,
       fmodule,finput,verbose,
       itcpugas,cpubase
       ;

+ 9 - 9
compiler/arm/narmset.pas

@@ -42,7 +42,7 @@ implementation
 
     uses
       systems,
-      verbose,globals,
+      verbose,globals,constexp,
       symconst,symdef,defutil,
       aasmbase,aasmtai,aasmdata,aasmcpu,
       cgbase,pass_2,
@@ -81,11 +81,11 @@ implementation
             if assigned(t^.less) then
               genitem(list,t^.less);
             { fill possible hole }
-            for i:=last+1 to t^._low-1 do
+            for i:=last.svalue+1 to t^._low.svalue-1 do
               list.concat(Tai_const.Create_sym(elselabel));
-            for i:=t^._low to t^._high do
+            for i:=t^._low.svalue to t^._high.svalue do
               list.concat(Tai_const.Create_sym(blocklabel(t^.blockid)));
-            last:=t^._high;
+            last:=t^._high.svalue;
             if assigned(t^.greater) then
               genitem(list,t^.greater);
           end;
@@ -129,7 +129,7 @@ implementation
              { need we to test the first value }
              if first and (t^._low>get_min_value(left.resultdef)) then
                begin
-                 cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,aint(t^._low),hregister,elselabel);
+                 cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,aint(t^._low.svalue),hregister,elselabel);
                end;
              if t^._low=t^._high then
                begin
@@ -138,7 +138,7 @@ implementation
                   else
                     begin
                       tcgarm(cg).cgsetflags:=true;
-                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low-last), hregister);
+                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(int64(t^._low-last)), hregister);
                       tcgarm(cg).cgsetflags:=false;
                       cg.a_jmp_flags(current_asmdata.CurrAsmList,F_EQ,blocklabel(t^.blockid));
                     end;
@@ -156,7 +156,7 @@ implementation
                        if (t^._low>get_min_value(left.resultdef)) then
                          begin
                            tcgarm(cg).cgsetflags:=true;
-                           cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low), hregister);
+                           cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(int64(t^._low)), hregister);
                            tcgarm(cg).cgsetflags:=false;
                          end;
                     end
@@ -167,7 +167,7 @@ implementation
                       { immediately. else check the range in between:       }
 
                       tcgarm(cg).cgsetflags:=true;
-                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low-last), hregister);
+                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(int64(t^._low-last)), hregister);
                       tcgarm(cg).cgsetflags:=false;
                       { no jump necessary here if the new range starts at }
                       { at the value following the previous one           }
@@ -176,7 +176,7 @@ implementation
                         cg.a_jmp_flags(current_asmdata.CurrAsmList,cond_lt,elselabel);
                     end;
                   tcgarm(cg).cgsetflags:=true;
-                  cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,opsize,aint(t^._high-t^._low),hregister);
+                  cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,opsize,aint(int64(t^._high-t^._low)),hregister);
                   tcgarm(cg).cgsetflags:=false;
                   cg.a_jmp_flags(current_asmdata.CurrAsmList,cond_le,blocklabel(t^.blockid));
 

+ 1 - 1
compiler/assemble.pas

@@ -167,7 +167,7 @@ Implementation
 {$ifdef hasunix}
       unix,
 {$endif}
-      cutils,cfileutils,
+      cutils,cfileutl,
 {$ifdef memdebug}
       cclasses,
 {$endif memdebug}

+ 2 - 6
compiler/cfileutils.pas → compiler/cfileutl.pas

@@ -19,7 +19,7 @@
 
  ****************************************************************************
 }
-unit cfileutils;
+unit cfileutl;
 
 {$i fpcdefs.inc}
 
@@ -153,10 +153,6 @@ implementation
                  (dir.Name<>'.') or
                  (dir.Name<>'..') then
                 begin
-                  { Force Archive bit so the attribute always has a value. This is needed
-                    to be able to see the difference in the directoryentries lookup if a file
-                    exists or not }
-                  Dir.Attr:=Dir.Attr or faArchive;
                   if not(tf_files_case_sensitive in source_info.flags) then
                     DirectoryEntries.Add(Lower(Dir.Name),Pointer(Ptrint(Dir.Attr)))
                   else
@@ -1007,7 +1003,7 @@ implementation
              while (pc^<>sepch) and (pc^<>';') and (pc^<>#0) do
               inc(pc);
              SetLength(singlepathstring, pc-startpc);
-             move(startpc^,singlepathstring[1],pc-startpc);
+             move(startpc^,singlepathstring[1],pc-startpc);            
              singlepathstring:=FixPath(ExpandFileName(singlepathstring),false);
              result:=FileExistsNonCase(singlepathstring,f,allowcache,FoundFile);
              if result then

+ 2 - 2
compiler/cg64f32.pas

@@ -97,7 +97,7 @@ unit cg64f32;
   implementation
 
     uses
-       globtype,systems,
+       globtype,systems,constexp,
        verbose,
        symbase,symconst,symdef,symtable,defutil,paramgr;
 
@@ -784,7 +784,7 @@ unit cg64f32;
                  { if we get here, the 64bit value lies between }
                  { longint($80000000) and -1 (JM)               }
                  cg.a_label(list,neglabel);
-                 hdef:=torddef.create(s32bit,longint($80000000),-1);
+                 hdef:=torddef.create(s32bit,int64(longint($80000000)),int64(-1));
                  location_copy(temploc,l);
                  temploc.size:=OS_32;
                  cg.g_rangecheck(list,temploc,hdef,todef);

+ 5 - 5
compiler/cgobj.pas

@@ -36,7 +36,7 @@ unit cgobj;
   interface
 
     uses
-       cclasses,globtype,
+       cclasses,globtype,constexp,
        cpubase,cgbase,cgutils,parabase,
        aasmbase,aasmtai,aasmdata,aasmcpu,
        symconst,symbase,symtype,symdef,symtable,rgobj
@@ -3300,8 +3300,8 @@ implementation
         if (fromdef = todef) and
            (fromdef.typ=orddef) and
            (((((torddef(fromdef).ordtype = s32bit) and
-               (lfrom = low(longint)) and
-               (hfrom = high(longint))) or
+               (lfrom = int64(low(longint))) and
+               (hfrom = int64(high(longint)))) or
               ((torddef(fromdef).ordtype = u32bit) and
                (lfrom = low(cardinal)) and
                (hfrom = high(cardinal)))))) then
@@ -3402,7 +3402,7 @@ implementation
           end;
         hreg:=getintregister(list,OS_INT);
         a_load_loc_reg(list,OS_INT,l,hreg);
-        a_op_const_reg(list,OP_SUB,OS_INT,aint(lto),hreg);
+        a_op_const_reg(list,OP_SUB,OS_INT,aint(int64(lto)),hreg);
         current_asmdata.getjumplabel(neglabel);
         {
         if from_signed then
@@ -3414,7 +3414,7 @@ implementation
           a_cmp_const_reg_label(list,OS_INT,OC_BE,aintmax,hreg,neglabel)
         else
 {$endif cpu64bit}
-          a_cmp_const_reg_label(list,OS_INT,OC_BE,aint(hto-lto),hreg,neglabel);
+          a_cmp_const_reg_label(list,OS_INT,OC_BE,aint(int64(hto-lto)),hreg,neglabel);
         a_call_name(list,'FPC_RANGEERROR');
         a_label(list,neglabel);
       end;

+ 1 - 1
compiler/compiler.pas

@@ -39,7 +39,7 @@ uses
   fksysutl,
 {$ENDIF}
   verbose,comphook,systems,
-  cutils,cfileutils,cclasses,globals,options,fmodule,parser,symtable,
+  cutils,cfileutl,cclasses,globals,options,fmodule,parser,symtable,
   assemble,link,dbgbase,import,export,tokens,pass_1
   { cpu parameter handling }
   ,cpupara

+ 1 - 1
compiler/comprsrc.pas

@@ -58,7 +58,7 @@ implementation
 
 uses
   SysUtils,
-  cutils,cfileutils,cclasses,
+  cutils,cfileutl,cclasses,
   Globtype,Globals,Verbose,Fmodule,
   Script;
   

+ 65 - 65
compiler/crefs.pas

@@ -1,65 +1,65 @@
-{
-    Copyright (c) 2007 by Pierre Muller
-
-    Common reference types
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
-}
-
-unit crefs;
-
-{$i fpcdefs.inc}
-
-interface
-
-uses
-  globals,
-  cclasses;
-
-  type
-
-   TrefItem = class (TLinkedListItem)
-     refinfo  : tfileposinfo;
-     constructor create(const ARefInfo : tfileposinfo);
-     Function GetCopy:TLinkedListItem;virtual;
-   end;
-
-   TRefLinkedList = class(TLinkedList)
-     procedure WriteToPPU;
-   end;
-
-implementation
-
-constructor TRefItem.Create(const ARefInfo : tfileposinfo);
-begin
-  Inherited Create;
-  RefInfo:=ARefInfo;
-end;
-
-Function TRefItem.GetCopy : TLinkedListItem;
-var
-  NR : TRefItem;
-begin
-  NR.Create(RefInfo);
-  GetCopy:=NR;
-end;
-
-procedure TRefLinkedList.WriteToPPU;
-begin
-end;
-
-begin
-end.
+{
+    Copyright (c) 2007 by Pierre Muller
+
+    Common reference types
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ****************************************************************************
+}
+
+unit crefs;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype,
+  cclasses;
+
+  type
+
+   TrefItem = class (TLinkedListItem)
+     refinfo  : tfileposinfo;
+     constructor create(const ARefInfo : tfileposinfo);
+     Function GetCopy:TLinkedListItem;virtual;
+   end;
+
+   TRefLinkedList = class(TLinkedList)
+     procedure WriteToPPU;
+   end;
+
+implementation
+
+constructor TRefItem.Create(const ARefInfo : tfileposinfo);
+begin
+  Inherited Create;
+  RefInfo:=ARefInfo;
+end;
+
+Function TRefItem.GetCopy : TLinkedListItem;
+var
+  NR : TRefItem;
+begin
+  NR.Create(RefInfo);
+  GetCopy:=NR;
+end;
+
+procedure TRefLinkedList.WriteToPPU;
+begin
+end;
+
+begin
+end.

+ 2 - 2
compiler/dbgdwarf.pas

@@ -331,7 +331,7 @@ interface
 implementation
 
     uses
-      cutils,cfileutils,
+      cutils,cfileutl,
       version,globtype,globals,verbose,systems,
       cpubase,cgbase,paramgr,
       fmodule,
@@ -1885,7 +1885,7 @@ implementation
             constord:
               begin
                 current_asmdata.asmlists[al_dwarf_abbrev].concat(tai_const.create_uleb128bit(ord(DW_FORM_sdata)));
-                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord));
+                current_asmdata.asmlists[al_dwarf_info].concat(tai_const.create_sleb128bit(sym.value.valueord.svalue));
               end;
             constnil:
               begin

+ 4 - 4
compiler/dbgstabs.pas

@@ -88,8 +88,8 @@ interface
 implementation
 
     uses
-      SysUtils,cutils,cfileutils,
-      systems,globals,globtype,verbose,
+      SysUtils,cutils,cfileutl,
+      systems,globals,globtype,verbose,constexp,
       symconst,defutil,
       cpuinfo,cpubase,cgbase,paramgr,
       aasmbase,procinfo,
@@ -564,7 +564,7 @@ implementation
                   u64bit :
                     result:=def_stabstr_evaluate(def,'r${numberstring};0;-1;',[]);
                   else
-                    result:=def_stabstr_evaluate(def,'r${numberstring};$1;$2;',[tostr(longint(def.low)),tostr(longint(def.high))]);
+                    result:=def_stabstr_evaluate(def,'r${numberstring};$1;$2;',[tostr(longint(def.low.svalue)),tostr(longint(def.high.svalue))]);
                 end;
               end
             else
@@ -591,7 +591,7 @@ implementation
                     result:=strpnew('-31;');
                   {u32bit : result:=def_stab_number(s32inttype)+';0;-1;'); }
                   else
-                    result:=def_stabstr_evaluate(def,'r${numberstring};$1;$2;',[tostr(longint(def.low)),tostr(longint(def.high))]);
+                    result:=def_stabstr_evaluate(def,'r${numberstring};$1;$2;',[tostr(longint(def.low.svalue)),tostr(longint(def.high.svalue))]);
                 end;
              end;
           end;

+ 1 - 1
compiler/defcmp.pas

@@ -126,7 +126,7 @@ interface
 implementation
 
     uses
-      verbose,systems,
+      verbose,systems,constexp,
       symtable,symsym,
       defutil,symutil;
 

+ 41 - 92
compiler/defutil.pas

@@ -27,7 +27,7 @@ interface
 
     uses
        cclasses,
-       globtype,globals,
+       globtype,globals,constexp,
        symconst,symbase,symtype,symdef,
        cgbase,cpubase;
 
@@ -86,7 +86,7 @@ interface
       orddefs, false otherwise                                              }
     function is_in_limit(def_from,def_to : tdef) : boolean;
 
-    function is_in_limit_value(val_from:TConstExprInt;def_from,def_to : tdef) : boolean;
+{    function is_in_limit_value(val_from:TConstExprInt;def_from,def_to : tdef) : boolean;}
 
 {*****************************************************************************
                               Array helper functions
@@ -201,7 +201,7 @@ interface
     {# If @var(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 testrange(fromdef, todef : tdef;var l : tconstexprint;explicit:boolean);
+    procedure testrange(todef : tdef;var l : tconstexprint;explicit:boolean);
 
     {# Returns the range of def, where @var(l) is the low-range and @var(h) is
       the high-range.
@@ -295,15 +295,15 @@ implementation
     function range_to_basetype(l,h:TConstExprInt):tordtype;
       begin
         { prefer signed over unsigned }
-        if (l>=-128) and (h<=127) then
+        if (l>=int64(-128)) and (h<=127) then
          range_to_basetype:=s8bit
         else if (l>=0) and (h<=255) then
          range_to_basetype:=u8bit
-        else if (l>=-32768) and (h<=32767) then
+        else if (l>=int64(-32768)) and (h<=32767) then
          range_to_basetype:=s16bit
         else if (l>=0) and (h<=65535) then
          range_to_basetype:=u16bit
-        else if (l>=low(longint)) and (h<=high(longint)) then
+        else if (l>=int64(low(longint))) and (h<=high(longint)) then
          range_to_basetype:=s32bit
         else if (l>=low(cardinal)) and (h<=high(cardinal)) then
          range_to_basetype:=u32bit
@@ -315,20 +315,22 @@ implementation
     procedure range_to_type(l,h:TConstExprInt;var def:tdef);
       begin
         { prefer signed over unsigned }
-        if (l>=-128) and (h<=127) then
+        if (l>=int64(-128)) and (h<=127) then
          def:=s8inttype
         else if (l>=0) and (h<=255) then
          def:=u8inttype
-        else if (l>=-32768) and (h<=32767) then
+        else if (l>=int64(-32768)) and (h<=32767) then
          def:=s16inttype
         else if (l>=0) and (h<=65535) then
          def:=u16inttype
-        else if (l>=low(longint)) and (h<=high(longint)) then
+        else if (l>=int64(low(longint))) and (h<=high(longint)) then
          def:=s32inttype
         else if (l>=low(cardinal)) and (h<=high(cardinal)) then
          def:=u32inttype
+        else if (l>=low(int64)) and (h<=high(int64)) then
+         def:=s64inttype
         else
-         def:=s64inttype;
+         def:=u64inttype;
       end;
 
 
@@ -367,7 +369,7 @@ implementation
            orddef:
              result:=torddef(def).low;
            enumdef:
-             result:=tenumdef(def).min;
+             result:=int64(tenumdef(def).min);
            else
              result:=0;
          end;
@@ -451,40 +453,15 @@ implementation
         fromqword, toqword: boolean;
 
       begin
-         if (def_from.typ <> orddef) or
-            (def_to.typ <> orddef) then
+         if (def_from.typ <> orddef) or (def_to.typ <> orddef) then
            begin
              is_in_limit := false;
              exit;
            end;
-         fromqword := torddef(def_from).ordtype = u64bit;
-         toqword := torddef(def_to).ordtype = u64bit;
-         is_in_limit:=(toqword and is_signed(def_from)) or
-                      ((not fromqword) and
-                       (torddef(def_from).low>=torddef(def_to).low) and
-                       (torddef(def_from).high<=torddef(def_to).high));
+         is_in_limit:=(torddef(def_from).low>=torddef(def_to).low) and
+                      (torddef(def_from).high<=torddef(def_to).high);
       end;
 
-
-    function is_in_limit_value(val_from:TConstExprInt;def_from,def_to : tdef) : boolean;
-
-      begin
-         if (def_from.typ <> orddef) and
-            (def_to.typ <> orddef) then
-           internalerror(200210062);
-         if (torddef(def_to).ordtype = u64bit) then
-          begin
-            is_in_limit_value:=((TConstExprUInt(val_from)>=TConstExprUInt(torddef(def_to).low)) and
-                                (TConstExprUInt(val_from)<=TConstExprUInt(torddef(def_to).high)));
-          end
-         else
-          begin;
-            is_in_limit_value:=((val_from>=torddef(def_to).low) and
-                                (val_from<=torddef(def_to).high));
-          end;
-      end;
-
-
     { true, if p points to an open array def }
     function is_open_string(p : tdef) : boolean;
       begin
@@ -692,57 +669,26 @@ implementation
 
     { 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 testrange(fromdef, todef : tdef;var l : tconstexprint;explicit:boolean);
+    procedure testrange(todef : tdef;var l : tconstexprint;explicit:boolean);
       var
          lv,hv: TConstExprInt;
-         error: boolean;
       begin
-         error := false;
          { for 64 bit types we need only to check if it is less than }
          { zero, if def is a qword node                              }
-         if is_64bitint(todef) then
-           begin
-              if (l<0) and
-                 (torddef(todef).ordtype=u64bit) and
-                 { since tconstexprint is an int64, values > high(int64) will }
-                 { always be stored as negative numbers                       }
-                 (not is_64bitint(fromdef) or
-                  (torddef(fromdef).ordtype<>u64bit)) then
-                begin
-                   { don't zero the result, because it may come from hex notation
-                     like $ffffffffffffffff! (JM)
-                   l:=0; }
-                   if not explicit then
-                    begin
-                      if (cs_check_range in current_settings.localswitches) then
-                        Message(parser_e_range_check_error)
-                      else
-                        Message(parser_w_range_check_error);
-                    end;
-                   error := true;
-                end;
-           end
-         else
+         getrange(todef,lv,hv);
+         if (l<lv) or (l>hv) then
            begin
-              getrange(todef,lv,hv);
-              if (l<lv) or (l>hv) then
-                begin
-                   if not explicit then
-                    begin
-                      if ((todef.typ=enumdef) and
-                          { delphi allows range check errors in
-                           enumeration type casts FK }
-                          not(m_delphi in current_settings.modeswitches)) or
-                         (cs_check_range in current_settings.localswitches) then
-                        Message(parser_e_range_check_error)
-                      else
-                        Message(parser_w_range_check_error);
-                    end;
-                   error := true;
-                end;
-           end;
-         if error then
-          begin
+             if not explicit then
+               begin
+                 if ((todef.typ=enumdef) and
+                     { delphi allows range check errors in
+                      enumeration type casts FK }
+                     not(m_delphi in current_settings.modeswitches)) or
+                    (cs_check_range in current_settings.localswitches) then
+                   Message(parser_e_range_check_error)
+                 else
+                   Message(parser_w_range_check_error);
+               end;
              { Fix the value to fit in the allocated space for this type of variable }
              case longint(todef.size) of
                1: l := l and $ff;
@@ -750,16 +696,19 @@ implementation
                { work around sign extension bug (to be fixed) (JM) }
                4: l := l and (int64($fffffff) shl 4 + $f);
              end;
+             {reset sign, i.e. converting -1 to qword changes the value to high(qword)}
+             l.signed:=false;
              { do sign extension if necessary (JM) }
              if is_signed(todef) then
               begin
                 case longint(todef.size) of
-                  1: l := shortint(l);
-                  2: l := smallint(l);
-                  4: l := longint(l);
+                  1: l.svalue := shortint(l.svalue);
+                  2: l.svalue := smallint(l.svalue);
+                  4: l.svalue := longint(l.svalue);
                 end;
+                l.signed:=true;
               end;
-          end;
+           end;
       end;
 
 
@@ -774,13 +723,13 @@ implementation
             end;
           enumdef :
             begin
-              l:=tenumdef(def).min;
-              h:=tenumdef(def).max;
+              l:=int64(tenumdef(def).min);
+              h:=int64(tenumdef(def).max);
             end;
           arraydef :
             begin
-              l:=tarraydef(def).lowrange;
-              h:=tarraydef(def).highrange;
+              l:=int64(tarraydef(def).lowrange);
+              h:=int64(tarraydef(def).highrange);
             end;
           else
             internalerror(200611054);

+ 1 - 1
compiler/finput.pas

@@ -169,7 +169,7 @@ uses
   fmodule,
   ppheap,
 {$endif heaptrc}
-  CFileUtils,
+  cfileutl,
   Globals,Systems
   ;
 

+ 4 - 4
compiler/fmodule.pas

@@ -42,8 +42,8 @@ unit fmodule;
 interface
 
     uses
-       cutils,cclasses,cfileutils,
-       globals,finput,ogbase,
+       cutils,cclasses,cfileutl,
+       globtype,finput,ogbase,
        symbase,symsym,aasmbase,aasmtai,aasmdata;
 
 
@@ -195,6 +195,7 @@ interface
        SmartLinkOFiles   : TCmdStrList; { List of .o files which are generated,
                                           used to delete them after linking }
 
+
     procedure set_current_module(p:tmodule);
     function get_module(moduleindex : longint) : tmodule;
     function get_source_file(moduleindex,fileindex : longint) : tinputfile;
@@ -204,8 +205,7 @@ interface
 implementation
 
     uses
-      SysUtils,
-      GlobType,
+      SysUtils,globals,
       verbose,systems,
       scanner,ppu,
       procinfo;

+ 1 - 1
compiler/fppu.pas

@@ -94,7 +94,7 @@ implementation
 
 uses
   SysUtils,
-  cfileutils,
+  cfileutl,
   verbose,systems,version,
   symtable, symsym,
   scanner,

+ 2 - 10
compiler/globals.pas

@@ -43,7 +43,7 @@ interface
 {$ENDIF}
 
       { comphook pulls in sysutils anyways }
-      cutils,cclasses,cfileutils,
+      cutils,cclasses,cfileutl,
       cpuinfo,
       globtype,version,systems;
 
@@ -102,14 +102,6 @@ interface
 {$endif}
 
     type
-       pfileposinfo = ^tfileposinfo;
-       tfileposinfo = record
-         line      : longint;
-         column    : word;
-         fileindex : word;
-         moduleindex : word;
-       end;
-
        tcodepagestring = string[20];
 
        tsettings = record
@@ -235,7 +227,7 @@ interface
        RelocSectionSetExplicitly : boolean;
        LinkTypeSetExplicitly : boolean;
 
-       current_tokenpos,                       { position of the last token }
+       current_tokenpos,                  { position of the last token }
        current_filepos : tfileposinfo;    { current position }
 
        nwscreenname : string;

+ 6 - 10
compiler/globtype.pas

@@ -52,10 +52,6 @@ interface
        PAWord = ^AWord;
        PAInt = ^AInt;
 
-       { the ordinal type used when evaluating constant integer expressions }
-       TConstExprInt = int64;
-       { ... the same unsigned }
-       TConstExprUInt = qword;
        { This must be an ordinal type with the same size as a pointer
          Note: Must be unsigned! Otherwise, ugly code like
          pointer(-1) will result in a pointer with the value
@@ -341,12 +337,12 @@ interface
        plongint   = ^longint;
        plongintarray = plongint;
 
-       Tconstant=record
-            case signed:boolean of
-                false:
-                    (valueu:cardinal);
-                true:
-                    (values:longint);
+       pfileposinfo = ^tfileposinfo;
+       tfileposinfo = record
+         line      : longint;
+         column    : word;
+         fileindex : word;
+         moduleindex : word;
        end;
 
   {$ifndef xFPC}

+ 2 - 2
compiler/htypechk.pas

@@ -27,7 +27,7 @@ interface
 
     uses
       tokens,cpuinfo,
-      node,globals,
+      node,globtype,
       symconst,symtype,symdef,symsym,symbase;
 
     type
@@ -157,7 +157,7 @@ implementation
 
     uses
        sysutils,
-       globtype,systems,
+       systems,constexp,globals,
        cutils,cclasses,verbose,
        symtable,
        defutil,defcmp,

+ 12 - 12
compiler/i386/n386mat.pas

@@ -48,7 +48,7 @@ interface
 implementation
 
     uses
-      globtype,systems,
+      globtype,systems,constexp,
       cutils,verbose,globals,
       symconst,symdef,aasmbase,aasmtai,aasmdata,defutil,
       cgbase,pass_2,
@@ -99,7 +99,7 @@ implementation
 
         if (nodetype=divn) and (right.nodetype=ordconstn) then
           begin
-            if ispowerof2(tordconstnode(right).value,power) then
+            if ispowerof2(tordconstnode(right).value.svalue,power) then
               begin
                 { for signed numbers, the numerator must be adjusted before the
                   shift instruction, but not wih unsigned numbers! Otherwise,
@@ -117,7 +117,7 @@ implementation
                         {If the left value is signed, hreg2=$ffffffff, otherwise 0.}
                         emit_const_reg(A_SAR,S_L,31,hreg2);
                         {If signed, hreg2=right value-1, otherwise 0.}
-                        emit_const_reg(A_AND,S_L,tordconstnode(right).value-1,hreg2);
+                        emit_const_reg(A_AND,S_L,tordconstnode(right).value.svalue-1,hreg2);
                         { add to the left value }
                         emit_reg_reg(A_ADD,S_L,hreg2,hreg1);
                         { do the shift }
@@ -132,7 +132,7 @@ implementation
                         if power=1 then
                           emit_reg(A_INC,S_L,hreg1)
                         else
-                          emit_const_reg(A_ADD,S_L,tordconstnode(right).value-1,hreg1);
+                          emit_const_reg(A_ADD,S_L,tordconstnode(right).value.svalue-1,hreg1);
                         cg.a_label(current_asmdata.CurrAsmList,hl);
                         emit_const_reg(A_SAR,S_L,power,hreg1);
                       end
@@ -145,7 +145,7 @@ implementation
               begin
                 if is_signed(left.resultdef) then
                   begin
-                    e:=tordconstnode(right).value;
+                    e:=tordconstnode(right).value.svalue;
                     d:=abs(e);
                     { Determine algorithm (a), multiplier (m), and shift factor (s) for 32-bit
                       signed integer division. Based on: Granlund, T.; Montgomery, P.L.:
@@ -219,7 +219,7 @@ implementation
                   end
                 else
                   begin
-                    d:=tordconstnode(right).value;
+                    d:=tordconstnode(right).value.svalue;
                     if d>=$80000000 then
                       begin
                         emit_const_reg(A_CMP,S_L,aint(d),hreg1);
@@ -385,13 +385,13 @@ implementation
                   begin
                     emit_reg_reg(A_XOR,S_L,hreg64hi,hreg64hi);
                     if ((v and 31) <> 0) then
-                      emit_const_reg(A_SHL,S_L,v and 31,hreg64lo);
+                      emit_const_reg(A_SHL,S_L,v.svalue and 31,hreg64lo);
                   end
                 else
                   begin
                     emit_reg_reg(A_XOR,S_L,hreg64lo,hreg64lo);
                     if ((v and 31) <> 0) then
-                      emit_const_reg(A_SHR,S_L,v and 31,hreg64hi);
+                      emit_const_reg(A_SHR,S_L,v.svalue and 31,hreg64hi);
                   end;
                 location.register64.reghi:=hreg64lo;
                 location.register64.reglo:=hreg64hi;
@@ -400,13 +400,13 @@ implementation
               begin
                 if nodetype=shln then
                   begin
-                    emit_const_reg_reg(A_SHLD,S_L,v and 31,hreg64lo,hreg64hi);
-                    emit_const_reg(A_SHL,S_L,v and 31,hreg64lo);
+                    emit_const_reg_reg(A_SHLD,S_L,v.svalue and 31,hreg64lo,hreg64hi);
+                    emit_const_reg(A_SHL,S_L,v.svalue and 31,hreg64lo);
                   end
                 else
                   begin
-                    emit_const_reg_reg(A_SHRD,S_L,v and 31,hreg64hi,hreg64lo);
-                    emit_const_reg(A_SHR,S_L,v and 31,hreg64hi);
+                    emit_const_reg_reg(A_SHRD,S_L,v.svalue and 31,hreg64hi,hreg64lo);
+                    emit_const_reg(A_SHR,S_L,v.svalue and 31,hreg64hi);
                   end;
                 location.register64.reglo:=hreg64lo;
                 location.register64.reghi:=hreg64hi;

+ 8 - 8
compiler/i386/n386set.pas

@@ -42,7 +42,7 @@ implementation
 
     uses
       systems,
-      verbose,globals,
+      verbose,globals,constexp,
       symconst,symdef,defutil,
       aasmbase,aasmtai,aasmdata,aasmcpu,
       cgbase,pass_2,
@@ -90,9 +90,9 @@ implementation
             if assigned(t^.less) then
               genitem(list,t^.less);
             { fill possible hole }
-            for i:=last+1 to t^._low-1 do
+            for i:=last.svalue+1 to t^._low.svalue-1 do
               list.concat(Tai_const.Create_sym(elselabel));
-            for i:=t^._low to t^._high do
+            for i:=t^._low.svalue to t^._high.svalue do
               list.concat(Tai_const.Create_sym(blocklabel(t^.blockid)));
             last:=t^._high;
             if assigned(t^.greater) then
@@ -139,7 +139,7 @@ implementation
              { need we to test the first value }
              if first and (t^._low>get_min_value(left.resultdef)) then
                begin
-                 cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,aint(t^._low),hregister,elselabel);
+                 cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,aint(t^._low.svalue),hregister,elselabel);
                end;
              if t^._low=t^._high then
                begin
@@ -147,7 +147,7 @@ implementation
                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ,0,hregister,blocklabel(t^.blockid))
                   else
                     begin
-                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low-last), hregister);
+                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low.svalue-last.svalue), hregister);
                       cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,blocklabel(t^.blockid));
                     end;
                   last:=t^._low;
@@ -162,7 +162,7 @@ implementation
                     begin
                        { have we to ajust the first value ? }
                        if (t^._low>get_min_value(left.resultdef)) then
-                         cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low), hregister);
+                         cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low.svalue), hregister);
                     end
                   else
                     begin
@@ -170,7 +170,7 @@ implementation
                       { present label then the lower limit can be checked    }
                       { immediately. else check the range in between:       }
 
-                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low-last), hregister);
+                      cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low.svalue-last.svalue), hregister);
                       { no jump necessary here if the new range starts at }
                       { at the value following the previous one           }
                       if ((t^._low-last) <> 1) or
@@ -179,7 +179,7 @@ implementation
                     end;
                   {we need to use A_SUB, because A_DEC does not set the correct flags, therefor
                    using a_op_const_reg(OP_SUB) is not possible }
-                  emit_const_reg(A_SUB,TCGSize2OpSize[opsize],aint(t^._high-t^._low),hregister);
+                  emit_const_reg(A_SUB,TCGSize2OpSize[opsize],aint(t^._high.svalue-t^._low.svalue),hregister);
                   cg.a_jmp_flags(current_asmdata.CurrAsmList,cond_le,blocklabel(t^.blockid));
                   last:=t^._high;
                   lastrange:=true;

+ 1 - 1
compiler/link.pas

@@ -125,7 +125,7 @@ interface
 Implementation
 
     uses
-      cutils,cfileutils,
+      cutils,cfileutl,
       script,globals,verbose,comphook,ppu,
       aasmbase,aasmtai,aasmdata,aasmcpu,
       owbase,owar,ogmap;

+ 49 - 89
compiler/nadd.pas

@@ -85,7 +85,7 @@ implementation
 {$ELSE}
       fksysutl,
 {$ENDIF}
-      globtype,systems,
+      globtype,systems,constexp,
       cutils,verbose,globals,widestr,
       symconst,symdef,symsym,symtable,defutil,defcmp,
       cgbase,
@@ -140,7 +140,7 @@ implementation
         t : tnode;
         lt,rt   : tnodetype;
         rd,ld   : tdef;
-        rv,lv   : tconstexprint;
+        rv,lv,v : tconstexprint;
         rvd,lvd : bestreal;
         ws1,ws2 : pcompilerwidestring;
         concatstrings : boolean;
@@ -254,90 +254,53 @@ implementation
              case nodetype of
                addn :
                  begin
-                   {$ifopt Q-}
-                     {$define OVERFLOW_OFF}
-                     {$Q+}
-                   {$endif}
-                   try
-                     if (lt=pointerconstn) then
-                       t := cpointerconstnode.create(lv+rv,left.resultdef)
-                     else
-                       if is_integer(ld) then
-                         t := genintconstnode(lv+rv)
+                   v:=lv+rv;
+                   if v.overflow then
+                     begin
+                       Message(parser_e_arithmetic_operation_overflow);
+                       { Recover }
+                       t:=genintconstnode(0)
+                     end
+                   else if (lt=pointerconstn) then
+                     t := cpointerconstnode.create(qword(v),left.resultdef)
+                   else
+                     if is_integer(ld) then
+                       t := genintconstnode(v)
                      else
-                       t := cordconstnode.create(lv+rv,left.resultdef,(ld.typ<>enumdef));
-                   except
-                     on E:EIntOverflow do
-                       begin
-                         Message(parser_e_arithmetic_operation_overflow);
-                         { Recover }
-                         t:=genintconstnode(0)
-                       end;
-                   end;
-                   {$ifdef OVERFLOW_OFF}
-                     {$Q-}
-                     {$undef OVERFLOW_OFF}
-                   {$endif}
+                       t := cordconstnode.create(v,left.resultdef,(ld.typ<>enumdef));
                  end;
                subn :
                  begin
-                   {$ifopt Q-}
-                     {$define OVERFLOW_OFF}
-                     {$Q+}
-                   {$endif}
-                   try
-                     if (lt=pointerconstn) then
-                       begin
-                         { pointer-pointer results in an integer }
-                         if (rt=pointerconstn) then
-                           t := genintconstnode((lv-rv) div tpointerdef(ld).pointeddef.size)
-                         else
-                           t := cpointerconstnode.create(lv-rv,left.resultdef);
-                       end
+                   v:=lv-rv;
+                   if v.overflow then
+                     begin
+                       Message(parser_e_arithmetic_operation_overflow);
+                       { Recover }
+                       t:=genintconstnode(0)
+                     end
+                   else if (lt=pointerconstn) then
+                     { pointer-pointer results in an integer }
+                     if (rt=pointerconstn) then
+                       t := genintconstnode(v div tpointerdef(ld).pointeddef.size)
                      else
-                       begin
-                         if is_integer(ld) then
-                           t:=genintconstnode(lv-rv)
-                         else
-                           t:=cordconstnode.create(lv-rv,left.resultdef,(ld.typ<>enumdef));
-                       end;
-                   except
-                     on E:EIntOverflow do
-                       begin
-                         Message(parser_e_arithmetic_operation_overflow);
-                         { Recover }
-                         t:=genintconstnode(0)
-                       end;
-                   end;
-                   {$ifdef OVERFLOW_OFF}
-                     {$Q-}
-                     {$undef OVERFLOW_OFF}
-                   {$endif}
+                       t := cpointerconstnode.create(qword(v),left.resultdef)
+                   else
+                     if is_integer(ld) then
+                       t:=genintconstnode(v)
+                     else
+                       t:=cordconstnode.create(v,left.resultdef,(ld.typ<>enumdef));
                  end;
                muln :
                  begin
-                   {$ifopt Q-}
-                     {$define OVERFLOW_OFF}
-                     {$Q+}
-                   {$endif}
-                   try
-                     if (torddef(ld).ordtype <> u64bit) or
-                        (torddef(rd).ordtype <> u64bit) then
-                       t:=genintconstnode(lv*rv)
-                     else
-                       t:=genintconstnode(int64(qword(lv)*qword(rv)));
-                   except
-                     on E:EIntOverflow do
-                       begin
-                         Message(parser_e_arithmetic_operation_overflow);
-                         { Recover }
-                         t:=genintconstnode(0)
-                       end;
-                   end;
-                   {$ifdef OVERFLOW_OFF}
-                     {$Q-}
-                     {$undef OVERFLOW_OFF}
-                   {$endif}
+                   v:=lv*rv;
+                   if v.overflow then
+                     begin
+                       message(parser_e_arithmetic_operation_overflow);
+                       { Recover }
+                       t:=genintconstnode(0)
+                     end
+                   else
+                     t:=genintconstnode(v)
                  end;
                xorn :
                  if is_integer(ld) then
@@ -388,9 +351,6 @@ implementation
            if a>0 then
          ... always evaluates to true. (DM)}
         else if is_constintnode(left) and (right.resultdef.typ=orddef) and
-            { all type limits are stored using tconstexprint = int64   }
-            { currently, so u64bit support would need extra type casts }
-            (Torddef(right.resultdef).ordtype<>u64bit) and
             { don't ignore type checks }
             is_subequal(left.resultdef,right.resultdef) then
             begin
@@ -432,9 +392,9 @@ implementation
                 end
             end
           else if (left.resultdef.typ=orddef) and is_constintnode(right) and
-              { all type limits are stored using tconstexprint = int64   }
+(*              { all type limits are stored using tconstexprint = int64   }
               { currently, so u64bit support would need extra type casts }
-              (Torddef(left.resultdef).ordtype<>u64bit) and
+              (Torddef(left.resultdef).ordtype<>u64bit) and*)
               { don't ignore type checks }
               is_subequal(left.resultdef,right.resultdef) then
             begin
@@ -620,10 +580,10 @@ implementation
         if (lt=ordconstn) and (rt=ordconstn) and
            is_char(ld) and is_char(rd) then
           begin
-             c1[0]:=char(byte(tordconstnode(left).value));
+             c1[0]:=char(int64(tordconstnode(left).value));
              c1[1]:=#0;
              l1:=1;
-             c2[0]:=char(byte(tordconstnode(right).value));
+             c2[0]:=char(int64(tordconstnode(right).value));
              c2[1]:=#0;
              l2:=1;
              s1:=@c1[0];
@@ -634,7 +594,7 @@ implementation
           begin
              s1:=tstringconstnode(left).value_str;
              l1:=tstringconstnode(left).len;
-             c2[0]:=char(byte(tordconstnode(right).value));
+             c2[0]:=char(int64(tordconstnode(right).value));
              c2[1]:=#0;
              s2:=@c2[0];
              l2:=1;
@@ -642,7 +602,7 @@ implementation
           end
         else if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
           begin
-             c1[0]:=char(byte(tordconstnode(left).value));
+             c1[0]:=char(int64(tordconstnode(left).value));
              c1[1]:=#0;
              l1:=1;
              s1:=@c1[0];
@@ -2168,8 +2128,8 @@ implementation
             result :=
              ((v >= 0) or
               todefsigned) and
-             (v >= low(longint)) and
-             (v <= high(longint))
+             (v >= int64(low(longint))) and
+             (v <= int64(high(longint)))
           else
             result :=
              (qword(v) >= low(cardinal)) and

+ 14 - 6
compiler/ncal.pas

@@ -27,7 +27,7 @@ interface
 
     uses
        cutils,cclasses,
-       globtype,
+       globtype,constexp,
        paramgr,parabase,
        node,nbas,nutils,
        {$ifdef state_tracking}
@@ -238,7 +238,7 @@ implementation
         statements : tstatementnode;
         result_data,
         params : ttempcreatenode;
-        paramssize : longint;
+        paramssize : cardinal;
         calldescnode : tdataconstnode;
         para : tcallparanode;
         currargpos,
@@ -377,7 +377,7 @@ implementation
                 addstatement(statements,cassignmentnode.create(
                   ctypeconvnode.create_internal(cderefnode.create(caddnode.create(addn,
                     caddrnode.create(ctemprefnode.create(params)),
-                    cordconstnode.create(paramssize,ptruinttype,false)
+                    cordconstnode.create(qword(paramssize),ptruinttype,false)
                   )),voidpointertype),
                   ctypeconvnode.create_internal(caddrnode.create_internal(para.left),voidpointertype)))
               else
@@ -1748,8 +1748,7 @@ implementation
               else
                if vo_is_high_para in currpara.varoptions then
                 begin
-                  if not assigned(pt) or
-                     (i=0) then
+                  if not assigned(pt) or (i=0) then
                     internalerror(200304082);
                   { we need the information of the previous parameter }
                   hiddentree:=gen_high_tree(pt.left,tparavarsym(procdefinition.paras[i-1]).vardef);
@@ -1791,7 +1790,16 @@ implementation
                if vo_is_overflow_check in currpara.varoptions then
                  begin
                    hiddentree:=cordconstnode.create(Ord(cs_check_overflow in current_settings.localswitches),booltype,false);
-                 end;
+                 end
+              else
+                if vo_is_typinfo_para in currpara.varoptions then
+                  begin
+                    if not assigned(pt) or (i=0) then
+                      internalerror(200304082);
+                    hiddentree:=caddrnode.create_internal(
+                      crttinode.create(Tstoreddef(pt.resultdef),fullrtti,rdt_normal)
+                    );
+                  end;
               { add the hidden parameter }
               if not assigned(hiddentree) then
                 internalerror(200304073);

+ 2 - 2
compiler/ncgcon.pas

@@ -242,9 +242,9 @@ implementation
       begin
          location_reset(location,LOC_CONSTANT,def_cgsize(resultdef));
 {$ifdef cpu64bit}
-         location.value:=value;
+         location.value:=value.svalue;
 {$else cpu64bit}
-         location.value64:=int64(value);
+         location.value64:=value.svalue;
 {$endif cpu64bit}
       end;
 

+ 24 - 24
compiler/ncgflw.pas

@@ -91,7 +91,7 @@ interface
 implementation
 
     uses
-      verbose,globals,systems,globtype,
+      verbose,globals,systems,globtype,constexp,
       symconst,symdef,symsym,aasmtai,aasmdata,aasmcpu,defutil,
       procinfo,cgbase,pass_2,parabase,
       cpubase,cpuinfo,
@@ -495,7 +495,7 @@ implementation
              if lnf_testatbegin in loopflags then
                begin
                  cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,opsize,hcond,
-                   tordconstnode(t1).value,
+                   tordconstnode(t1).value.svalue,
                    left.location,current_procinfo.CurrBreakLabel);
                end;
            end;
@@ -599,7 +599,7 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if byte(cmp_const)=low(byte) then
+                           if byte(cmp_const.svalue)=low(byte) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=high(byte);
@@ -607,7 +607,7 @@ implementation
                          end
                        else
                          begin
-                           if byte(cmp_const)=high(byte) then
+                           if byte(cmp_const.svalue)=high(byte) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=low(byte);
@@ -618,7 +618,7 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if word(cmp_const)=high(word) then
+                           if word(cmp_const.svalue)=high(word) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=low(word);
@@ -626,7 +626,7 @@ implementation
                          end
                        else
                          begin
-                           if word(cmp_const)=low(word) then
+                           if word(cmp_const.svalue)=low(word) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=high(word);
@@ -637,7 +637,7 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if cardinal(cmp_const)=high(cardinal) then
+                           if cardinal(cmp_const.svalue)=high(cardinal) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=low(cardinal);
@@ -645,7 +645,7 @@ implementation
                          end
                        else
                          begin
-                           if cardinal(cmp_const)=low(cardinal) then
+                           if cardinal(cmp_const.svalue)=low(cardinal) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=high(cardinal);
@@ -656,7 +656,7 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if qword(cmp_const)=high(qword) then
+                           if qword(cmp_const.uvalue)=high(qword) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=low(qword);
@@ -664,7 +664,7 @@ implementation
                          end
                        else
                          begin
-                           if qword(cmp_const)=low(qword) then
+                           if qword(cmp_const.uvalue)=low(qword) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=high(qword);
@@ -675,7 +675,7 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if shortint(cmp_const)=low(shortint) then
+                           if shortint(cmp_const.svalue)=low(shortint) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=high(shortint);
@@ -683,10 +683,10 @@ implementation
                          end
                        else
                          begin
-                           if shortint(cmp_const)=high(shortint) then
+                           if shortint(cmp_const.svalue)=high(shortint) then
                              begin
                                hcond:=OC_NE;
-                               cmp_const:=low(shortint);
+                               cmp_const:=int64(low(shortint));
                              end
                          end
                      end;
@@ -694,18 +694,18 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if integer(cmp_const)=high(smallint) then
+                           if integer(cmp_const.svalue)=high(smallint) then
                              begin
                                hcond:=OC_NE;
-                               cmp_const:=low(smallint);
+                               cmp_const:=int64(low(smallint));
                              end
                          end
                        else
                          begin
-                           if integer(cmp_const)=low(smallint) then
+                           if integer(cmp_const.svalue)=low(smallint) then
                              begin
                                hcond:=OC_NE;
-                               cmp_const:=high(smallint);
+                               cmp_const:=int64(high(smallint));
                              end
                          end
                      end;
@@ -713,18 +713,18 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if longint(cmp_const)=high(longint) then
+                           if longint(cmp_const.svalue)=high(longint) then
                              begin
                                hcond:=OC_NE;
-                               cmp_const:=low(longint);
+                               cmp_const:=int64(low(longint));
                              end
                          end
                        else
                          begin
-                           if longint(cmp_const)=low(longint) then
+                           if longint(cmp_const.svalue)=low(longint) then
                              begin
                                hcond:=OC_NE;
-                               cmp_const:=high(longint);
+                               cmp_const:=int64(high(longint));
                              end
                          end
                      end;
@@ -732,7 +732,7 @@ implementation
                      begin
                        if lnf_backward in loopflags then
                          begin
-                           if int64(cmp_const)=high(int64) then
+                           if int64(cmp_const.svalue)=high(int64) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=low(int64);
@@ -740,7 +740,7 @@ implementation
                          end
                        else
                          begin
-                           if int64(cmp_const)=low(int64) then
+                           if int64(cmp_const.svalue)=low(int64) then
                              begin
                                hcond:=OC_NE;
                                cmp_const:=high(int64);
@@ -753,7 +753,7 @@ implementation
                end;
 
              cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,opsize,hcond,
-               aint(cmp_const),left.location,l3);
+               aint(cmp_const.svalue),left.location,l3);
            end;
 
          { this is the break label: }

+ 3 - 3
compiler/ncginl.pas

@@ -58,7 +58,7 @@ interface
 implementation
 
     uses
-      globtype,systems,
+      globtype,systems,constexp,
       cutils,verbose,globals,fmodule,
       symconst,symdef,defutil,symsym,
       aasmbase,aasmtai,aasmdata,aasmcpu,parabase,
@@ -444,7 +444,7 @@ implementation
 {$endif cpu64bit}
                   { insert multiply with addvalue if its >1 }
                   if addvalue>1 then
-                    cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,cgsize,addvalue,hregister);
+                    cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,cgsize,addvalue.svalue,hregister);
                   addconstant:=false;
                 end;
             end;
@@ -457,7 +457,7 @@ implementation
               else
 {$endif cpu64bit}
                 cg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],
-                  aint(addvalue),tcallparanode(left).left.location);
+                  aint(addvalue.svalue),tcallparanode(left).left.location);
             end
            else
              begin

+ 3 - 3
compiler/ncgld.pas

@@ -54,7 +54,7 @@ implementation
     uses
       cutils,
       systems,
-      verbose,globtype,globals,
+      verbose,globtype,globals,constexp,
       nutils,
       symconst,symtype,symdef,symsym,defutil,paramgr,
       ncnv,ncon,nmem,nbas,ncgrtti,
@@ -610,10 +610,10 @@ implementation
                 if right.nodetype=ordconstn then
                   begin
                     if (target_info.endian = endian_little) then
-                      cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_16,(tordconstnode(right).value shl 8) or 1,
+                      cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_16,(tordconstnode(right).value.svalue shl 8) or 1,
                           left.location.reference)
                     else
-                      cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_16,tordconstnode(right).value or (1 shl 8),
+                      cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_16,tordconstnode(right).value.svalue or (1 shl 8),
                           left.location.reference);
                   end
                 else

+ 3 - 3
compiler/ncgmat.pas

@@ -308,7 +308,7 @@ implementation
 
               if (nodetype=divn) and
                  (right.nodetype=ordconstn) and
-                 ispowerof2(tordconstnode(right).value,power) then
+                 ispowerof2(tordconstnode(right).value.svalue,power) then
                 Begin
                   { for signed numbers, the numerator must be adjusted before the
                     shift instruction, but not wih unsigned numbers! Otherwise,
@@ -320,7 +320,7 @@ implementation
                       if power=1 then
                         cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_INT,1,hreg1)
                       else
-                        cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_INT,tordconstnode(right).value-1,hreg1);
+                        cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_INT,Tordconstnode(right).value.svalue-1,hreg1);
                       cg.a_label(current_asmdata.CurrAsmList,hl);
                       cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,power,hreg1);
                     End
@@ -400,7 +400,7 @@ implementation
               if right.value<=31 then
               }
               cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,
-                tordconstnode(right).value and 31,location.register);
+                tordconstnode(right).value.uvalue and 31,location.register);
               {
               else
                 emit_reg_reg(A_XOR,S_L,hregister1,

+ 10 - 10
compiler/ncgmem.pas

@@ -79,7 +79,7 @@ implementation
 
     uses
       systems,
-      cutils,verbose,globals,
+      cutils,verbose,globals,constexp,
       symconst,symdef,symsym,symtable,defutil,paramgr,
       aasmbase,aasmtai,aasmdata,
       procinfo,pass_2,parabase,
@@ -722,8 +722,8 @@ implementation
                         not(is_array_of_const(left.resultdef)) and
                         not(is_dynamic_array(left.resultdef)) then
                        begin
-                          if (tordconstnode(right).value>tarraydef(left.resultdef).highrange) or
-                             (tordconstnode(right).value<tarraydef(left.resultdef).lowrange) then
+                          if (tordconstnode(right).value.svalue>tarraydef(left.resultdef).highrange) or
+                             (tordconstnode(right).value.svalue<tarraydef(left.resultdef).lowrange) then
                             begin
                               { this should be caught in the typecheckpass! (JM) }
                               if (cs_check_range in current_settings.localswitches) then
@@ -753,7 +753,7 @@ implementation
                               paramanager.getintparaloc(pocall_default,1,paraloc1);
                               paramanager.getintparaloc(pocall_default,2,paraloc2);
                               paramanager.allocparaloc(current_asmdata.CurrAsmList,paraloc2);
-                              cg.a_param_const(current_asmdata.CurrAsmList,OS_INT,tordconstnode(right).value,paraloc2);
+                              cg.a_param_const(current_asmdata.CurrAsmList,OS_INT,tordconstnode(right).value.svalue,paraloc2);
                               href:=location.reference;
                               dec(href.offset,sizeof(aint)-offsetdec);
                               paramanager.allocparaloc(current_asmdata.CurrAsmList,paraloc1);
@@ -786,7 +786,7 @@ implementation
                    not is_ordinal(resultdef))) then
                 begin
                   inc(location.reference.offset,
-                    bytemulsize*tordconstnode(right).value);
+                    bytemulsize*tordconstnode(right).value.svalue);
                   { don't do this for floats etc.; needed to properly set the }
                   { size for bitpacked arrays (e.g. a bitpacked array of      }
                   { enums who are size 2 but fit in one byte -> in the array  }
@@ -802,9 +802,9 @@ implementation
                   if not ispowerof2(subsetref.ref.alignment,temp) then
                     internalerror(2006081212);
                   alignpow:=temp;
-                  inc(subsetref.ref.offset,((mulsize * (tordconstnode(right).value-tarraydef(left.resultdef).lowrange)) shr (3+alignpow)) shl alignpow);
+                  inc(subsetref.ref.offset,((mulsize * (tordconstnode(right).value.svalue-tarraydef(left.resultdef).lowrange)) shr (3+alignpow)) shl alignpow);
                   subsetref.bitindexreg := NR_NO;
-                  subsetref.startbit := (mulsize * (tordconstnode(right).value-tarraydef(left.resultdef).lowrange)) and ((1 shl (3+alignpow))-1);
+                  subsetref.startbit := (mulsize * (tordconstnode(right).value.svalue-tarraydef(left.resultdef).lowrange)) and ((1 shl (3+alignpow))-1);
                   subsetref.bitlen := resultdef.packedbitsize;
                   if (left.location.loc = LOC_REFERENCE) then
                     location.loc := LOC_SUBSETREF
@@ -829,7 +829,7 @@ implementation
                      begin
                         if taddnode(right).right.nodetype=ordconstn then
                           begin
-                             extraoffset:=tordconstnode(taddnode(right).right).value;
+                             extraoffset:=tordconstnode(taddnode(right).right).value.svalue;
                              t:=taddnode(right).left;
                              { First pass processed this with the assumption   }
                              { that there was an add node which may require an }
@@ -841,7 +841,7 @@ implementation
                           end
                         else if taddnode(right).left.nodetype=ordconstn then
                           begin
-                             extraoffset:=tordconstnode(taddnode(right).left).value;
+                             extraoffset:=tordconstnode(taddnode(right).left).value.svalue;
                              t:=taddnode(right).right;
                              t.registersint :=  right.registersint;
                              taddnode(right).right:=nil;
@@ -853,7 +853,7 @@ implementation
                      begin
                         if taddnode(right).right.nodetype=ordconstn then
                           begin
-                             extraoffset:=-tordconstnode(taddnode(right).right).value;
+                             extraoffset:=-tordconstnode(taddnode(right).right).value.svalue;
                              t:=taddnode(right).left;
                              t.registersint :=  right.registersint;
                              taddnode(right).left:=nil;

+ 1 - 1
compiler/ncgopt.pas

@@ -178,7 +178,7 @@ begin
       cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_8,OS_8,hreg,href2);
     end
   else
-    cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_8,tordconstnode(right).value,href2);
+    cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_8,tordconstnode(right).value.svalue,href2);
   lengthreg:=cg.makeregsize(current_asmdata.CurrAsmList,lengthreg,OS_8);
   { increase the string length }
   cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_8,1,lengthreg);

+ 16 - 9
compiler/ncgrtti.pas

@@ -26,7 +26,7 @@ unit ncgrtti;
 interface
 
     uses
-      cclasses,
+      cclasses,constexp,
       aasmbase,
       symbase,symconst,symtype,symdef;
 
@@ -231,7 +231,7 @@ implementation
         var
            typvalue : byte;
            hp : ppropaccesslistitem;
-           address : longint;
+           address,space : longint;
            def : tdef;
            hpropsym : tpropertysym;
            propaccesslist : tpropaccesslist;
@@ -273,7 +273,12 @@ implementation
                            if not(assigned(def) and (def.typ=arraydef)) then
                              internalerror(200402172);
                            def:=tarraydef(def).elementdef;
-                           inc(address,def.size*hp^.value);
+                           {Hp.value is a Tconstexprint, which can be rather large,
+                            sanity check for longint overflow.}
+                           space:=(high(address)-address) div def.size;
+                           if int64(space)<hp^.value then
+                             internalerror(200706101);
+                           inc(address,int64(def.size*hp^.value));
                          end;
                      end;
                      hp:=hp^.next;
@@ -434,8 +439,9 @@ implementation
             current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(byte(trans[def.ordtype])));
             if (tf_requires_proper_alignment in target_info.flags) then
               current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
-            current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.low)));
-            current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.high)));
+            {Convert to longint to smuggle values in high(longint)+1..high(cardinal) into asmlist.}
+            current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.low.svalue)));
+            current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(def.high.svalue)));
           end;
 
         begin
@@ -447,9 +453,9 @@ implementation
                 if (tf_requires_proper_alignment in target_info.flags) then
                   current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
                 { low }
-                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(int64($80000000) shl 32));
+                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.low.svalue));
                 { high }
-                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
+                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.high.svalue));
               end;
             u64bit :
               begin
@@ -457,10 +463,11 @@ implementation
                 write_rtti_name(def);
                 if (tf_requires_proper_alignment in target_info.flags) then
                   current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
+                {use svalue because Create_64bit accepts int64, prevents range checks}
                 { low }
-                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(0));
+                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.low.svalue));
                 { high }
-                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
+                current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(def.high.svalue));
               end;
             bool8bit:
               begin

+ 34 - 33
compiler/ncgset.pas

@@ -26,7 +26,7 @@ unit ncgset;
 interface
 
     uses
-       globtype,globals,
+       globtype,globals,constexp,
        node,nset,cpubase,cgbase,cgutils,cgobj,aasmbase,aasmtai,aasmdata;
 
     type
@@ -474,17 +474,18 @@ implementation
              genitem(t^.less);
            { do we need to test the first value? }
            if first and (t^._low>get_min_value(left.resultdef)) then
-             cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,aint(t^._low),hregister,elselabel);
+             cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,aint(t^._low.svalue),hregister,elselabel);
            if t^._low=t^._high then
              begin
-                if t^._low-last=0 then
-                  cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_EQ,0,hregister,blocklabel(t^.blockid))
-                else
-                  begin
-                      gensub(aint(t^._low-last));
-                      cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_EQ,aint(t^._low-last),scratch_reg,blocklabel(t^.blockid));
-                  end;
-                last:=t^._low;
+               if t^._low-last=0 then
+                 cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_EQ,0,hregister,blocklabel(t^.blockid))
+               else
+                 begin
+                   gensub(aint(t^._low.svalue-last.svalue));
+                   cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,
+                                            OC_EQ,aint(t^._low.svalue-last.svalue),scratch_reg,blocklabel(t^.blockid));
+                 end;
+               last:=t^._low;
              end
            else
              begin
@@ -495,18 +496,18 @@ implementation
                   begin
                      { have we to ajust the first value ? }
                      if (t^._low>get_min_value(left.resultdef)) then
-                       gensub(aint(t^._low));
+                       gensub(aint(t^._low.svalue));
                   end
                 else
                   begin
                     { if there is no unused label between the last and the }
                     { present label then the lower limit can be checked    }
                     { immediately. else check the range in between:       }
-                    gensub(aint(t^._low-last));
-                    cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize,jmp_lt,aint(t^._low-last),scratch_reg,elselabel);
+                    gensub(aint(t^._low.svalue-last.svalue));
+                    cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize,jmp_lt,aint(t^._low.svalue-last.svalue),scratch_reg,elselabel);
                   end;
-                gensub(aint(t^._high-t^._low));
-                cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_le,aint(t^._high-t^._low),scratch_reg,blocklabel(t^.blockid));
+                gensub(aint(t^._high.svalue-t^._low.svalue));
+                cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_le,aint(t^._high.svalue-t^._low.svalue),scratch_reg,blocklabel(t^.blockid));
                 last:=t^._high;
              end;
            first:=false;
@@ -551,14 +552,14 @@ implementation
                 if opsize in [OS_S64,OS_64] then
                   begin
                      current_asmdata.getjumplabel(l1);
-                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_NE, aint(hi(int64(t^._low))),hregister2,l1);
-                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_EQ, aint(lo(int64(t^._low))),hregister, blocklabel(t^.blockid));
+                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_NE, aint(hi(int64(t^._low.svalue))),hregister2,l1);
+                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_EQ, aint(lo(int64(t^._low.svalue))),hregister, blocklabel(t^.blockid));
                      cg.a_label(current_asmdata.CurrAsmList,l1);
                   end
                 else
 {$endif cpu64bit}
                   begin
-                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ, aint(t^._low),hregister, blocklabel(t^.blockid));
+                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ, aint(t^._low.svalue),hregister, blocklabel(t^.blockid));
                   end;
                 { Reset last here, because we've only checked for one value and need to compare
                   for the next range both the lower and upper bound }
@@ -575,18 +576,18 @@ implementation
                      if opsize in [OS_64,OS_S64] then
                        begin
                           current_asmdata.getjumplabel(l1);
-                          cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_lt, aint(hi(int64(t^._low))),
+                          cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_lt, aint(hi(int64(t^._low.svalue))),
                                hregister2, elselabel);
-                          cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_gt, aint(hi(int64(t^._low))),
+                          cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_gt, aint(hi(int64(t^._low.svalue))),
                                hregister2, l1);
                           { the comparisation of the low dword must be always unsigned! }
-                          cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_B, aint(lo(int64(t^._low))), hregister, elselabel);
+                          cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_B, aint(lo(int64(t^._low.svalue))), hregister, elselabel);
                           cg.a_label(current_asmdata.CurrAsmList,l1);
                        end
                      else
 {$endif cpu64bit}
                        begin
-                        cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_lt, aint(t^._low), hregister,
+                        cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_lt, aint(t^._low.svalue), hregister,
                            elselabel);
                        end;
                   end;
@@ -594,17 +595,17 @@ implementation
                 if opsize in [OS_S64,OS_64] then
                   begin
                      current_asmdata.getjumplabel(l1);
-                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_lt, aint(hi(int64(t^._high))), hregister2,
+                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_lt, aint(hi(int64(t^._high.svalue))), hregister2,
                            blocklabel(t^.blockid));
-                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_gt, aint(hi(int64(t^._high))), hregister2,
+                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_gt, aint(hi(int64(t^._high.svalue))), hregister2,
                            l1);
-                    cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_BE, aint(lo(int64(t^._high))), hregister, blocklabel(t^.blockid));
+                    cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_BE, aint(lo(int64(t^._high.svalue))), hregister, blocklabel(t^.blockid));
                     cg.a_label(current_asmdata.CurrAsmList,l1);
                   end
                 else
 {$endif cpu64bit}
                   begin
-                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_le, aint(t^._high), hregister, blocklabel(t^.blockid));
+                     cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_le, aint(t^._high.svalue), hregister, blocklabel(t^.blockid));
                   end;
 
                 last:=t^._high;
@@ -725,13 +726,13 @@ implementation
 
                    if (min_label<0) and (max_label>0) then
                      begin
-                        if min_label=TConstExprInt(low(aint)) then
-                          dist:=aword(max_label)+aword(low(aint))
+                        if min_label=TConstExprInt(int64(low(aint))) then
+                          dist:=aword(max_label.uvalue)+aword(low(aint))
                         else
-                          dist:=aword(max_label)+aword(-min_label)
+                          dist:=aword(max_label.uvalue)+aword(-min_label.svalue)
                      end
                    else
-                     dist:=max_label-min_label;
+                     dist:=max_label.uvalue-min_label.uvalue;
 
                    { optimize for size ? }
                    if cs_opt_size in current_settings.optimizerswitches  then
@@ -742,7 +743,7 @@ implementation
                               ((max_label-min_label)>3*labelcnt)) then
                          begin
                            { if the labels less or more a continuum then }
-                           genjumptable(labels,min_label,max_label);
+                           genjumptable(labels,min_label.svalue,max_label.svalue);
                          end
                        else
                          begin
@@ -767,9 +768,9 @@ implementation
                           begin
                             if (has_jumptable) and
                                (dist<max_dist) and
-                               (min_label>=low(aint)) and
+                               (min_label>=int64(low(aint))) and
                                (max_label<=high(aint)) then
-                              genjumptable(labels,min_label,max_label)
+                              genjumptable(labels,min_label.svalue,max_label.svalue)
                             else
                               genlinearlist(labels);
                           end;

+ 1 - 1
compiler/ncgutil.pas

@@ -280,7 +280,7 @@ implementation
 {$endif OLDREGVARS}
               if is_constboolnode(p) then
                 begin
-                   if tordconstnode(p).value<>0 then
+                   if Tordconstnode(p).value.uvalue<>0 then
                      cg.a_jmp_always(list,current_procinfo.CurrTrueLabel)
                    else
                      cg.a_jmp_always(list,current_procinfo.CurrFalseLabel)

+ 18 - 18
compiler/ncnv.pas

@@ -211,7 +211,7 @@ interface
 implementation
 
    uses
-      cclasses,globtype,systems,
+      cclasses,globtype,systems,constexp,
       cutils,verbose,globals,widestr,
       symconst,symdef,symsym,symbase,symtable,
       ncon,ncal,nset,nadd,ninl,nmem,nmat,nbas,nutils,
@@ -416,7 +416,7 @@ implementation
                                      inserttypeconv(p2,u8inttype);
                                    end;
 
-                                for l:=tordconstnode(p2).value to tordconstnode(p3).value do
+                                for l:=tordconstnode(p2).value.svalue to tordconstnode(p3).value.svalue do
                                   do_set(l);
                                 p2.free;
                                 p3.free;
@@ -462,7 +462,7 @@ implementation
                             else
                               inserttypeconv(p2,u8inttype);
 
-                            do_set(tordconstnode(p2).value);
+                            do_set(tordconstnode(p2).value.svalue);
                             p2.free;
                           end
                          else
@@ -515,7 +515,7 @@ implementation
            p.free;
          end;
         { set the initial set type }
-        constp.resultdef:=tsetdef.create(hdef,constsethi);
+        constp.resultdef:=tsetdef.create(hdef,constsethi.svalue);
         { determine the resultdef for the tree }
         typecheckpass(buildp);
         { set the new tree }
@@ -744,19 +744,19 @@ implementation
             if (sizeof(pointer) > sizeof(TConstPtrUInt)) then
               if (sizeof(TConstPtrUInt) = 4) then
                 begin
-                  if (tordconstnode(left).value < low(longint)) or
-                     (tordconstnode(left).value > high(cardinal)) then
+                  if (tordconstnode(left).value < int64(low(longint))) or
+                     (tordconstnode(left).value > int64(high(cardinal))) then
                   CGMessage(parser_e_range_check_error);
                 end
               else if (sizeof(TConstPtrUInt) = 8) then
                 begin
-                  if (tordconstnode(left).value < low(int64)) or
-                     (tordconstnode(left).value > high(qword)) then
+                  if (tordconstnode(left).value < int64(low(int64))) or
+                     (tordconstnode(left).value > int64(high(qword))) then
                   CGMessage(parser_e_range_check_error);
                 end
               else
                 internalerror(2001020801);
-            t:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resultdef);
+            t:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value.uvalue),resultdef);
             result:=t;
           end
          else
@@ -896,15 +896,15 @@ implementation
                begin
                  initwidestring(ws);
                  if torddef(left.resultdef).ordtype=uwidechar then
-                   concatwidestringchar(ws,tcompilerwidechar(tordconstnode(left).value))
+                   concatwidestringchar(ws,tcompilerwidechar(tordconstnode(left).value.uvalue))
                  else
-                   concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value)));
+                   concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value.uvalue)));
                  hp:=cstringconstnode.createwstr(ws);
                  donewidestring(ws);
                end
               else
                 begin
-                  hp:=cstringconstnode.createstr(chr(tordconstnode(left).value));
+                  hp:=cstringconstnode.createstr(chr(tordconstnode(left).value.uvalue));
                   tstringconstnode(hp).changestringtype(resultdef);
                 end;
               result:=hp;
@@ -970,7 +970,7 @@ implementation
                 (torddef(left.resultdef).ordtype=uwidechar) then
               begin
                 hp:=cordconstnode.create(
-                      ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value))),
+                      ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue))),
                       cchartype,true);
                 result:=hp;
               end
@@ -978,7 +978,7 @@ implementation
                      (torddef(left.resultdef).ordtype=uchar) then
               begin
                 hp:=cordconstnode.create(
-                      asciichar2unicode(chr(tordconstnode(left).value)),
+                      asciichar2unicode(chr(tordconstnode(left).value.uvalue)),
                       cwidechartype,true);
                 result:=hp;
               end
@@ -1000,7 +1000,7 @@ implementation
            if is_currency(resultdef) then
              v:=v*10000;
            if (resultdef.typ=pointerdef) then
-             result:=cpointerconstnode.create(TConstPtrUInt(v),resultdef)
+             result:=cpointerconstnode.create(TConstPtrUInt(v.uvalue),resultdef)
            else
              begin
                if is_currency(left.resultdef) then
@@ -1012,7 +1012,7 @@ implementation
          begin
            v:=tpointerconstnode(left).value;
            if (resultdef.typ=pointerdef) then
-             result:=cpointerconstnode.create(v,resultdef)
+             result:=cpointerconstnode.create(v.uvalue,resultdef)
            else
              begin
                if is_currency(resultdef) then
@@ -1847,7 +1847,7 @@ implementation
               if (resultdef.typ=pointerdef) and
                  (convtype<>tc_cchar_2_pchar) then
                 begin
-                   hp:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resultdef);
+                   hp:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value.uvalue),resultdef);
                    if ([nf_explicit,nf_internal] * flags <> []) then
                      include(hp.flags, nf_explicit);
                    result:=hp;
@@ -1859,7 +1859,7 @@ implementation
                    { replace the resultdef and recheck the range }
                    if ([nf_explicit,nf_internal] * flags <> []) then
                      include(left.flags, nf_explicit);
-                   testrange(left.resultdef,resultdef,tordconstnode(left).value,(nf_explicit in flags));
+                   testrange(resultdef,tordconstnode(left).value,(nf_explicit in flags));
                    left.resultdef:=resultdef;
                    result:=left;
                    left:=nil;

+ 3 - 3
compiler/ncon.pas

@@ -26,7 +26,7 @@ unit ncon;
 interface
 
     uses
-      globtype,widestr,
+      globtype,widestr,constexp,
       cclasses,
       node,
       aasmbase,aasmtai,aasmdata,cpuinfo,globals,
@@ -623,7 +623,7 @@ implementation
         resultdef:=typedef;
         { only do range checking when explicitly asked for it }
         if rangecheck then
-           testrange(resultdef,resultdef,value,false);
+           testrange(resultdef,value,false);
       end;
 
     function tordconstnode.pass_1 : tnode;
@@ -643,7 +643,7 @@ implementation
     procedure Tordconstnode.printnodedata(var t:text);
       begin
         inherited printnodedata(t);
-        writeln(t,printnodeindention,'value = ',value);
+        writeln(t,printnodeindention,'value = ',tostr(value));
       end;
 
 

+ 3 - 3
compiler/nflw.pas

@@ -219,7 +219,7 @@ interface
 implementation
 
     uses
-      globtype,systems,
+      globtype,systems,constexp,
       cutils,verbose,globals,
       symconst,paramgr,defcmp,defutil,htypechk,pass_1,
       ncal,nadd,ncon,nmem,nld,ncnv,nbas,cgobj,nutils,
@@ -394,7 +394,7 @@ implementation
            while false do }
          if (lnf_testatbegin in loopflags) and
             (left.nodetype=ordconstn) and
-            (tordconstnode(left).value=0) and
+            (tordconstnode(left).value.uvalue=0) and
             assigned(right) then
            CGMessagePos(right.fileinfo,cg_w_unreachable_code);
       end;
@@ -665,7 +665,7 @@ implementation
         { optimize constant expressions }
         if left.nodetype=ordconstn then
           begin
-             if tordconstnode(left).value=1 then
+             if tordconstnode(left).value.uvalue=1 then
                begin
                   if assigned(right) then
                     result:=right

+ 36 - 20
compiler/ninl.pas

@@ -80,7 +80,7 @@ interface
 implementation
 
     uses
-      verbose,globals,systems,
+      verbose,globals,systems,constexp,
       globtype, cutils,
       symconst,symdef,symsym,symtable,paramgr,defutil,
       pass_1,
@@ -239,14 +239,14 @@ implementation
             if not assigned(fracpara) then
               begin
                 tmppara.right := ccallparanode.create(
-                  cordconstnode.create(-1,s32inttype,false),
+                  cordconstnode.create(int64(-1),s32inttype,false),
                    tmppara.right);
                 fracpara := tcallparanode(tmppara.right);
               end;
             { if necessary, insert a length para }
             if not assigned(lenpara) then
               fracpara.right := ccallparanode.create(
-                cordconstnode.create(-32767,s32inttype,false),
+                cordconstnode.create(int64(-32767),s32inttype,false),
                    fracpara.right);
           end
         else if is_enum then
@@ -271,14 +271,14 @@ implementation
             if not assigned(lenpara) then
               Tcallparanode(Tcallparanode(newparas.right).right).right:=
                 Ccallparanode.create(
-                  cordconstnode.create(-1,s32inttype,false),
+                  cordconstnode.create(int64(-1),s32inttype,false),
                   Tcallparanode(Tcallparanode(newparas.right).right).right
                 );
           end
         else
           { for a normal parameter, insert a only length parameter if one is missing }
           if not assigned(lenpara) then
-            newparas.right := ccallparanode.create(cordconstnode.create(-1,s32inttype,false),
+            newparas.right := ccallparanode.create(cordconstnode.create(int64(-1),s32inttype,false),
               newparas.right);
 
         { remove the parameters from the original node so they won't get disposed, }
@@ -566,11 +566,11 @@ implementation
                     begin
                       if not assigned(lenpara) then
                         lenpara := ccallparanode.create(
-                          cordconstnode.create(-32767,s32inttype,false),nil);
+                          cordconstnode.create(int64(-32767),s32inttype,false),nil);
                       { also create a default fracpara if necessary }
                       if not assigned(fracpara) then
                         fracpara := ccallparanode.create(
-                          cordconstnode.create(-1,s32inttype,false),nil);
+                          cordconstnode.create(int64(-1),s32inttype,false),nil);
                       { add it to the lenpara }
                       lenpara.right := fracpara;
                       if not is_currency(para.left.resultdef) then
@@ -1298,6 +1298,8 @@ implementation
                     v:=torddef(def).low
                   else
                     v:=torddef(def).high;
+(*
+Low and high are not anymore longints, but Tconstexprints (DM)
                   { low/high of torddef are longints, so we need special }
                   { handling for cardinal and 64bit types (JM)           }
                   { 1.0.x doesn't support int64($ffffffff) correct, it'll expand
@@ -1323,12 +1325,15 @@ implementation
                           v := cardinal(v);
                       end;
                   end;
+*)
                   hp:=cordconstnode.create(v,def,true);
                   typecheckpass(hp);
+(*
                   { fix high(qword) }
                   if (torddef(def).ordtype=u64bit) and
                      (inlinenumber = in_high_x) then
-                    tordconstnode(hp).value := -1; { is the same as qword($ffffffffffffffff) }
+                    tordconstnode(hp).value := int64(-1); { is the same as qword($ffffffffffffffff) }
+*)
                   do_lowhigh:=hp;
                end;
              enumdef:
@@ -1474,9 +1479,9 @@ implementation
                  (index.left.nodetype = ordconstn) and
                  not is_special_array(unpackedarraydef) then
                 begin
-                  testrange(index.left.resultdef,unpackedarraydef,tordconstnode(index.left).value,false);
+                  testrange(unpackedarraydef,tordconstnode(index.left).value,false);
                   tempindex := tordconstnode(index.left).value + packedarraydef.highrange-packedarraydef.lowrange;
-                  testrange(index.left.resultdef,unpackedarraydef,tempindex,false);
+                  testrange(unpackedarraydef,tempindex,false);
                 end;
             end;
 
@@ -1544,19 +1549,30 @@ implementation
                end;
                case inlinenumber of
                  in_const_abs :
-                   hp:=genintconstnode(abs(vl));
-                 in_const_sqr :
-                   hp:=genintconstnode(sqr(vl));
+                   if vl.signed then
+                     hp:=genintconstnode(abs(vl.svalue))
+                   else
+                     hp:=genintconstnode(vl.uvalue);
+                 in_const_sqr:
+                   if vl.signed then
+                     hp:=genintconstnode(sqr(vl.svalue))
+                   else
+                     hp:=genintconstnode(sqr(vl.uvalue));
                  in_const_odd :
-                   hp:=cordconstnode.create(byte(odd(vl)),booltype,true);
+                   hp:=cordconstnode.create(qword(odd(int64(vl))),booltype,true);
                  in_const_swap_word :
                    hp:=cordconstnode.create((vl and $ff) shl 8+(vl shr 8),left.resultdef,true);
                  in_const_swap_long :
                    hp:=cordconstnode.create((vl and $ffff) shl 16+(vl shr 16),left.resultdef,true);
                  in_const_swap_qword :
                    hp:=cordconstnode.create((vl and $ffff) shl 32+(vl shr 32),left.resultdef,true);
-                 in_const_ptr :
-                   hp:=cpointerconstnode.create((vl2 shl 4)+vl,voidfarpointertype);
+                 in_const_ptr:
+                   begin
+                     {Don't construct pointers from negative values.}
+                     if (vl.signed and (vl.svalue<0)) or (vl2.signed and (vl2.svalue<0)) then
+                       cgmessage(parser_e_range_check_error);
+                     hp:=cpointerconstnode.create((vl2.uvalue shl 4)+vl.uvalue,voidfarpointertype);
+                   end
                  else
                    internalerror(88);
                end;
@@ -2084,8 +2100,8 @@ implementation
                         if inlinenumber=in_low_x then
                          begin
                            set_varstate(left,vs_read,[]);
-                           result:=cordconstnode.create(tarraydef(
-                            left.resultdef).lowrange,tarraydef(left.resultdef).rangedef,true);
+                           result:=cordconstnode.create(int64(tarraydef(
+                            left.resultdef).lowrange),tarraydef(left.resultdef).rangedef,true);
                          end
                         else
                          begin
@@ -2110,8 +2126,8 @@ implementation
                            else
                             begin
                               set_varstate(left,vs_read,[]);
-                              result:=cordconstnode.create(tarraydef(
-                               left.resultdef).highrange,tarraydef(left.resultdef).rangedef,true);
+                              result:=cordconstnode.create(int64(tarraydef(
+                               left.resultdef).highrange),tarraydef(left.resultdef).rangedef,true);
                             end;
                          end;
                       end;

+ 5 - 15
compiler/nmat.pas

@@ -89,7 +89,7 @@ implementation
     uses
       systems,
       verbose,globals,cutils,
-      globtype,
+      globtype,constexp,
       symconst,symtype,symdef,symtable,
       defutil,
       htypechk,pass_1,
@@ -133,17 +133,9 @@ implementation
 
             case nodetype of
               modn:
-                if (torddef(ld).ordtype <> u64bit) or
-                   (torddef(rd).ordtype <> u64bit) then
-                  t:=genintconstnode(lv mod rv)
-                else
-                  t:=genintconstnode(int64(qword(lv) mod qword(rv)));
+                t:=genintconstnode(lv mod rv);
               divn:
-                if (torddef(ld).ordtype <> u64bit) or
-                   (torddef(rd).ordtype <> u64bit) then
-                  t:=genintconstnode(lv div rv)
-                else
-                  t:=genintconstnode(int64(qword(lv) div qword(rv)));
+                t:=genintconstnode(lv div rv);
             end;
             result:=t;
             exit;
@@ -418,7 +410,7 @@ implementation
               end
             else
               begin
-                dec(tordconstnode(right).value);
+                dec(tordconstnode(right).value.uvalue);
                 result := caddnode.create(andn,left,right);
               end;
             { left and right are reused }
@@ -834,9 +826,7 @@ implementation
                bool32bit,
                bool64bit:
                  begin
-                   { here we do a boolean(byte(..)) type cast because }
-                   { boolean(<int64>) is buggy in 1.00                }
-                   v:=byte(not(boolean(byte(v))));
+                   v:=byte(not(boolean(int64(v))));
                  end;
                uchar,
                uwidechar,

+ 5 - 5
compiler/nmem.pas

@@ -724,7 +724,7 @@ implementation
                not(is_char(right.resultdef) or is_widechar(right.resultdef)) and
                not(is_boolean(right.resultdef))
              ) or
-             (left.resultdef.typ <> arraydef) 
+             (left.resultdef.typ <> arraydef)
             ) then
            begin
              inserttypeconv(right,sinttype);
@@ -763,8 +763,8 @@ implementation
                      hightree:=load_high_value_node(tparavarsym(tloadnode(left).symtableentry));
                      hightree.free;
                    end;
-      
-      
+
+
              end;
            pointerdef :
              begin
@@ -810,7 +810,7 @@ implementation
                  begin
                    { indexed access to 0 element is only allowed for shortstrings }
                    if (right.nodetype=ordconstn) and
-                      (tordconstnode(right).value=0) and
+                      (Tordconstnode(right).value.svalue=0) and
                       not is_shortstring(left.resultdef) then
                      CGMessage(cg_e_can_access_element_zero);
                    resultdef:=elementdef;
@@ -986,7 +986,7 @@ implementation
 
     function is_big_untyped_addrnode(p: tnode): boolean;
       begin
-        is_big_untyped_addrnode:=(p.nodetype=addrn) and 
+        is_big_untyped_addrnode:=(p.nodetype=addrn) and
 	  not (nf_typedaddr in p.flags) and (taddrnode(p).left.resultdef.size > 1);
       end;
 

+ 8 - 8
compiler/nset.pas

@@ -26,7 +26,7 @@ unit nset;
 interface
 
     uses
-       cclasses,
+       cclasses,constexp,
        node,globtype,globals,
        aasmbase,aasmtai,aasmdata,symtype;
 
@@ -192,7 +192,7 @@ implementation
               end;
             orddef :
               begin
-                for i:=torddef(psd.elementdef).low to torddef(psd.elementdef).high do
+                for i:=int64(torddef(psd.elementdef).low) to int64(torddef(psd.elementdef).high) do
                   include(pcs^,i);
               end;
           end;
@@ -301,20 +301,20 @@ implementation
                  { to the rule above -> will give range check error if      }
                  { value > high(longint) if we don't take the signedness    }
                  { into account                                             }
-                 if is_signed(left.resultdef) then
-                   t:=cordconstnode.create(byte(tordconstnode(left).value in Tsetconstnode(right).value_set^),
+                 if Tordconstnode(left).value.signed then
+                   t:=cordconstnode.create(byte(tordconstnode(left).value.svalue in Tsetconstnode(right).value_set^),
                      booltype,true)
                  else
-                   t:=cordconstnode.create(byte(TConstExprUInt(tordconstnode(left).value) in Tsetconstnode(right).value_set^),
-                     booltype,true);                   
+                   t:=cordconstnode.create(byte(tordconstnode(left).value.uvalue in Tsetconstnode(right).value_set^),
+                     booltype,true);
                  typecheckpass(t);
                  result:=t;
                  exit;
                end
              else
                begin
-                 if (is_signed(left.resultdef) and (tordconstnode(left).value < 0)) or
-                    (TConstExprUInt(tordconstnode(left).value) > tsetdef(right.resultdef).setmax) then
+                 if (Tordconstnode(left).value.signed and (Tordconstnode(left).value<0)) or
+                    (Tordconstnode(left).value.uvalue>Tsetdef(right.resultdef).setmax) then
                    begin
                      t:=cordconstnode.create(0, booltype, true);
                      typecheckpass(t);

+ 2 - 2
compiler/nutils.pas

@@ -26,7 +26,7 @@ unit nutils;
 interface
 
   uses
-    globals,
+    globtype,
     symtype,symsym,node;
 
   const
@@ -83,7 +83,7 @@ interface
 implementation
 
     uses
-      globtype,verbose,
+      verbose,constexp,globals,
       symconst,symbase,symdef,symtable,
       defutil,defcmp,
       nbas,ncon,ncnv,nld,nflw,nset,ncal,nadd,nmem,

+ 1 - 1
compiler/ogmap.pas

@@ -57,7 +57,7 @@ interface
 implementation
 
     uses
-      cutils,cfileutils,
+      cutils,cfileutl,
       globals,verbose;
 
 

+ 1 - 1
compiler/options.pas

@@ -26,7 +26,7 @@ unit options;
 interface
 
 uses
-  CClasses,CFileUtils,
+  CClasses,cfileutl,
   globtype,globals,verbose,systems,cpuinfo;
 
 Type

+ 1 - 1
compiler/optunrol.pas

@@ -33,7 +33,7 @@ unit optunrol;
   implementation
 
     uses
-      globtype,globals,
+      globtype,globals,constexp,
       cpuinfo,
       nutils,
       nbas,nflw,ncon,ninl,ncal;

+ 2 - 2
compiler/pbase.pas

@@ -27,7 +27,7 @@ interface
 
     uses
        cutils,cclasses,
-       tokens,globals,
+       tokens,globtype,
        symconst,symbase,symtype,symdef,symsym,symtable
        ;
 
@@ -98,7 +98,7 @@ interface
 implementation
 
     uses
-       globtype,htypechk,scanner,systems,verbose;
+       globals,htypechk,scanner,systems,verbose;
 
 {****************************************************************************
                                Token Parsing

+ 4 - 4
compiler/pdecl.pas

@@ -27,7 +27,7 @@ interface
 
     uses
       { global }
-      globals,
+      globtype,
       { symtable }
       symsym,
       { pass_1 }
@@ -50,7 +50,7 @@ implementation
        { common }
        cutils,cclasses,
        { global }
-       globtype,tokens,verbose,widestr,
+       globals,tokens,verbose,widestr,constexp,
        systems,
        { aasm }
        aasmbase,aasmtai,aasmdata,fmodule,
@@ -90,7 +90,7 @@ implementation
            ordconstn:
              begin
                if p.resultdef.typ=pointerdef then
-                 hp:=tconstsym.create_ordptr(orgname,constpointer,tordconstnode(p).value,p.resultdef)
+                 hp:=tconstsym.create_ordptr(orgname,constpointer,tordconstnode(p).value.uvalue,p.resultdef)
                else
                  hp:=tconstsym.create_ord(orgname,constord,tordconstnode(p).value,p.resultdef);
              end;
@@ -663,7 +663,7 @@ implementation
                            if is_constcharnode(p) then
                              begin
                                 getmem(sp,2);
-                                sp[0]:=chr(tordconstnode(p).value);
+                                sp[0]:=chr(tordconstnode(p).value.svalue);
                                 sp[1]:=#0;
                                 sym:=tconstsym.create_string(orgname,constresourcestring,sp,1);
                              end

+ 66 - 13
compiler/pdecsub.pas

@@ -67,7 +67,7 @@ implementation
        { common }
        cutils,cclasses,
        { global }
-       globtype,globals,verbose,
+       globtype,globals,verbose,constexp,
        systems,
        cpuinfo,
        { symtable }
@@ -292,6 +292,12 @@ implementation
                  if not (po_external in pd.procoptions) then
                    Message(parser_w_cdecl_has_no_high);
                end;
+              if (vardef.typ=formaldef) and (Tformaldef(vardef).typed) then
+                begin
+                  hvs:=tparavarsym.create('$typinfo'+name,paranr+1,vs_const,voidpointertype,
+                                          [vo_is_typinfo_para,vo_is_hidden_para]);
+                  owner.insert(hvs);
+                end;
             end;
          end;
       end;
@@ -525,7 +531,10 @@ implementation
               begin
                 if (m_mac in current_settings.modeswitches) then
                   try_to_consume(_UNIV); {currently does nothing}
-                single_type(hdef,false);
+                if try_to_consume(_TYPE) then
+                  hdef:=ctypedformaltype
+                else
+                  single_type(hdef,false);
 
                 { open string ? }
                 if (varspez in [vs_out,vs_var]) and
@@ -1188,20 +1197,36 @@ begin
   pd.parast.SymList.ForEachCall(@check_inline_para,pd);
 end;
 
+
 procedure pd_internconst(pd:tabstractprocdef);
+
+var v:Tconstexprint;
+
 begin
   if pd.typ<>procdef then
     internalerror(200304268);
   consume(_COLON);
-  tprocdef(pd).extnumber:=longint(get_intconst);
+  v:=get_intconst;
+  if (v<int64(low(longint))) or (v>int64(high(longint))) then
+    message(parser_e_range_check_error)
+  else
+    Tprocdef(pd).extnumber:=longint(v.svalue);
 end;
 
+
 procedure pd_internproc(pd:tabstractprocdef);
+
+var v:Tconstexprint;
+
 begin
   if pd.typ<>procdef then
     internalerror(200304268);
   consume(_COLON);
-  tprocdef(pd).extnumber:=longint(get_intconst);
+  v:=get_intconst;
+  if (v<int64(low(longint))) or (v>int64(high(longint))) then
+    message(parser_e_range_check_error)
+  else
+    Tprocdef(pd).extnumber:=longint(v.svalue);
   { the proc is defined }
   tprocdef(pd).forwarddef:=false;
 end;
@@ -1255,16 +1280,21 @@ end;
 
 
 procedure pd_dispid(pd:tabstractprocdef);
-var
-  pt : tnode;
+
+var pt:Tnode;
+    v:Tconstexprint;
+
 begin
   if pd.typ<>procdef then
     internalerror(200604301);
   pt:=comp_expr(true);
   if is_constintnode(pt) then
-    tprocdef(pd).dispid:=tordconstnode(pt).value
+    if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
+      message(parser_e_range_check_error)
+    else
+      Tprocdef(pd).dispid:=Tordconstnode(pt).value.svalue
   else
-    Message(parser_e_dispid_must_be_ord_const);
+    message(parser_e_dispid_must_be_ord_const);
   pt.free;
 end;
 
@@ -1318,7 +1348,11 @@ begin
    if is_constintnode(pt) then
     begin
       include(pd.procoptions,po_msgint);
-      tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
+      if (Tordconstnode(pt).value<int64(low(Tprocdef(pd).messageinf.i))) or
+         (Tordconstnode(pt).value>int64(high(Tprocdef(pd).messageinf.i))) then
+        message(parser_e_range_check_error)
+      else
+        Tprocdef(pd).messageinf.i:=tordconstnode(pt).value.svalue;
     end
   else
     Message(parser_e_ill_msg_expr);
@@ -1341,6 +1375,7 @@ var
   vs  : tparavarsym;
   sym : tsym;
   symtable : TSymtable;
+  v: Tconstexprint;
 {$endif defined(powerpc) or defined(m68k)}
 begin
   if (pd.typ<>procdef) and (target_info.system <> system_powerpc_amiga) then
@@ -1373,7 +1408,11 @@ begin
       (paramanager as tm68kparamanager).create_funcretloc_info(pd,calleeside);
       (paramanager as tm68kparamanager).create_funcretloc_info(pd,callerside);
 
-      tprocdef(pd).extnumber:=get_intconst;
+      v:=get_intconst;
+      if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
+        message(parser_e_range_check_error)
+      else
+        Tprocdef(pd).extnumber:=v.uvalue;
     end;
 {$endif m68k}
 {$ifdef powerpc}
@@ -1400,7 +1439,11 @@ begin
       (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
       (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
 
-      tprocdef(pd).extnumber:=get_intconst;
+      v:=get_intconst;
+      if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
+        message(parser_e_range_check_error)
+      else
+        Tprocdef(pd).extnumber:=v.uvalue;
     end else
 
    if target_info.system = system_powerpc_morphos then
@@ -1488,7 +1531,11 @@ begin
       (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
       (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
 
-      tprocdef(pd).extnumber:=get_intconst;
+      v:=get_intconst;
+      if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
+        message(parser_e_range_check_error)
+      else
+        Tprocdef(pd).extnumber:=v.uvalue;
     end;
 {$endif powerpc}
 end;
@@ -1505,6 +1552,8 @@ procedure pd_external(pd:tabstractprocdef);
 }
 var
   hs : string;
+  v:Tconstexprint;
+
 begin
   if pd.typ<>procdef then
     internalerror(2003042615);
@@ -1540,7 +1589,11 @@ begin
            begin
              {After the word index follows the index number in the DLL.}
              consume(_INDEX);
-             import_nr:=longint(get_intconst);
+             v:=get_intconst;
+             if (v<int64(low(import_nr))) or (v>int64(high(import_nr))) then
+               message(parser_e_range_check_error)
+             else
+               import_nr:=longint(v.svalue);
            end;
           { default is to used the realname of the procedure }
           if (import_nr=0) and not assigned(import_name) then

+ 23 - 7
compiler/pdecvar.pas

@@ -47,7 +47,7 @@ implementation
        { common }
        cutils,cclasses,
        { global }
-       globtype,globals,tokens,verbose,
+       globtype,globals,tokens,verbose,constexp,
        systems,
        { symtable }
        symconst,symbase,symtype,symtable,defutil,defcmp,
@@ -178,7 +178,11 @@ implementation
                                  begin
                                    { type/range checking }
                                    inserttypeconv(p,tarraydef(def).rangedef);
-                                   idx:=tordconstnode(p).value
+                                   if (Tordconstnode(p).value<int64(low(longint))) or
+                                      (Tordconstnode(p).value>int64(high(longint))) then
+                                     message(parser_e_array_range_out_of_bounds)
+                                   else
+                                     idx:=Tordconstnode(p).value.svalue
                                  end
                                else
                                 Message(type_e_ordinal_expr_expected)
@@ -345,7 +349,7 @@ implementation
                      begin
                        if is_integer(pt.resultdef) then
                          inserttypeconv_internal(pt,s32inttype);
-                       p.index:=tordconstnode(pt).value;
+                       p.index:=tordconstnode(pt).value.svalue;
                      end
                    else
                      begin
@@ -596,7 +600,11 @@ implementation
                     setconstn :
                       p.default:=plongint(tsetconstnode(pt).value_set)^;
                     ordconstn :
-                      p.default:=longint(tordconstnode(pt).value);
+                      if (Tordconstnode(pt).value<int64(low(p.default))) or
+                         (Tordconstnode(pt).value>int64(high(p.default))) then
+                        message(parser_e_range_check_error)
+                      else
+                        p.default:=longint(tordconstnode(pt).value.svalue);
                     niln :
                       p.default:=0;
                     realconstn:
@@ -771,7 +779,7 @@ implementation
               if pt.nodetype=stringconstn then
                 abssym.asmname:=stringdup(strpas(tstringconstnode(pt).value_str))
               else
-                abssym.asmname:=stringdup(chr(tordconstnode(pt).value));
+                abssym.asmname:=stringdup(chr(tordconstnode(pt).value.svalue));
               consume(token);
               abssym.abstyp:=toasm;
             end
@@ -781,7 +789,11 @@ implementation
               abssym:=tabsolutevarsym.create(vs.realname,vs.vardef);
               abssym.fileinfo:=vs.fileinfo;
               abssym.abstyp:=toaddr;
-              abssym.addroffset:=tordconstnode(pt).value;
+              if (Tordconstnode(pt).value<int64(low(abssym.addroffset))) or
+                 (Tordconstnode(pt).value>int64(high(abssym.addroffset))) then
+                message(parser_e_range_check_error)
+              else
+                abssym.addroffset:=Tordconstnode(pt).value.svalue;
 {$ifdef i386}
               abssym.absseg:=false;
               if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
@@ -791,7 +803,11 @@ implementation
                   pt:=expr;
                   if is_constintnode(pt) then
                     begin
-                      abssym.addroffset:=abssym.addroffset shl 4+tordconstnode(pt).value;
+                      if (Tordconstnode(pt).value<int64(low(abssym.addroffset))) or
+                         (Tordconstnode(pt).value>int64(high(abssym.addroffset))) then
+                        message(parser_e_range_check_error)
+                      else
+                        abssym.addroffset:=abssym.addroffset shl 4+tordconstnode(pt).value.svalue;
                       abssym.absseg:=true;
                     end
                   else

+ 9 - 2
compiler/pexports.pas

@@ -34,7 +34,7 @@ implementation
        { common }
        cutils,
        { global }
-       globals,tokens,verbose,
+       globals,tokens,verbose,constexp,
        systems,
        ppu,fmodule,
        { symtable }
@@ -126,7 +126,14 @@ implementation
                  begin
                    pt:=comp_expr(true);
                    if pt.nodetype=ordconstn then
-                    hp.index:=tordconstnode(pt).value
+                    if (Tordconstnode(pt).value<int64(low(hp.index))) or
+                       (Tordconstnode(pt).value>int64(high(hp.index))) then
+                      begin
+                        hp.index:=0;
+                        message(parser_e_range_check_error)
+                      end
+                    else
+                      hp.index:=Tordconstnode(pt).value.svalue
                    else
                     begin
                       hp.index:=0;

+ 11 - 11
compiler/pexpr.pas

@@ -28,7 +28,7 @@ interface
     uses
       symtype,symdef,symbase,
       node,ncal,
-      tokens,globtype,globals;
+      tokens,globtype,globals,constexp;
 
     { reads a whole expression }
     function expr : tnode;
@@ -123,11 +123,11 @@ implementation
 {                   t:=tstringdef.createlong(tordconstnode(p).value))}
                      Message(parser_e_invalid_string_size);
                      tordconstnode(p).value:=255;
-                     def:=tstringdef.createshort(tordconstnode(p).value);
+                     def:=tstringdef.createshort(int64(tordconstnode(p).value));
                   end
                  else
                    if tordconstnode(p).value<>255 then
-                     def:=tstringdef.createshort(tordconstnode(p).value);
+                     def:=tstringdef.createshort(int64(tordconstnode(p).value));
                end;
               p.free;
            end
@@ -543,13 +543,13 @@ implementation
                   p1:=p2;
                 end;
               if p1.nodetype=typen then
-                ttypenode(p1).allowed:=true
-              else
+                ttypenode(p1).allowed:=true;
+{              else
                 begin
                    p1.destroy;
                    p1:=cerrornode.create;
                    Message(parser_e_illegal_parameter_list);
-                end;
+                end;}
               consume(_RKLAMMER);
               p2:=geninlinenode(in_typeinfo_x,false,p1);
               statement_syssym:=p2;
@@ -2396,8 +2396,8 @@ implementation
                if code=0 then
                  begin
                     consume(_INTCONST);
-                    int_to_type(card,hdef);
-                    p1:=cordconstnode.create(card,hdef,true);
+                    int_to_type(qword(card),hdef);
+                    p1:=cordconstnode.create(qword(card),hdef,true);
                  end
                else
                  begin
@@ -2406,8 +2406,8 @@ implementation
                    if code = 0 then
                      begin
                        consume(_INTCONST);
-                       int_to_type(l,hdef);
-                       p1:=cordconstnode.create(l,hdef,true);
+                       int_to_type(int64(l),hdef);
+                       p1:=cordconstnode.create(int64(l),hdef,true);
                      end
                    else
                      begin
@@ -2922,7 +2922,7 @@ implementation
       if p.nodetype<>stringconstn then
         begin
           if (p.nodetype=ordconstn) and is_char(p.resultdef) then
-            get_stringconst:=char(tordconstnode(p).value)
+            get_stringconst:=char(int64(tordconstnode(p).value))
           else
             Message(parser_e_illegal_expression);
         end

+ 3 - 3
compiler/pinline.pas

@@ -46,7 +46,7 @@ implementation
        { common }
        cutils,
        { global }
-       globtype,tokens,verbose,
+       globtype,tokens,verbose,constexp,
        systems,
        { symtable }
        symbase,symconst,symdef,symsym,symtable,defutil,
@@ -745,8 +745,8 @@ implementation
             else
              begin
                { use special -1,-1 argument to copy the whole array }
-               highppn:=cordconstnode.create(-1,s32inttype,false);
-               lowppn:=cordconstnode.create(-1,s32inttype,false);
+               highppn:=cordconstnode.create(int64(-1),s32inttype,false);
+               lowppn:=cordconstnode.create(int64(-1),s32inttype,false);
              end;
 
             { create call to fpc_dynarray_copy }

+ 1 - 1
compiler/pmodules.pas

@@ -34,7 +34,7 @@ implementation
     uses
        SysUtils,
        globtype,version,systems,tokens,
-       cutils,cfileutils,cclasses,comphook,
+       cutils,cfileutl,cclasses,comphook,
        globals,verbose,fmodule,finput,fppu,
        symconst,symbase,symtype,symdef,symsym,symtable,
        aasmtai,aasmdata,aasmcpu,aasmbase,

+ 8 - 8
compiler/powerpc/nppcmat.pas

@@ -51,7 +51,7 @@ interface
 implementation
 
     uses
-      globtype,systems,
+      globtype,systems,constexp,
       cutils,verbose,globals,
       symconst,
       aasmbase,aasmcpu,aasmtai,aasmdata,
@@ -205,7 +205,7 @@ end;
                  internalerror(2005061701);
              end else if (tordconstnode(right).value = 1) then begin
                 cg.a_load_reg_reg(current_asmdata.CurrAsmList, OS_INT, OS_INT, numerator, resultreg);
-             end else if (tordconstnode(right).value = -1) then begin
+             end else if (tordconstnode(right).value = int64(-1)) then begin
                 // note: only in the signed case possible..., may overflow
                 current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(negops[cs_check_overflow in current_settings.localswitches], resultreg, numerator));
              end else if (ispowerof2(tordconstnode(right).value, power)) then begin
@@ -222,7 +222,7 @@ end;
                  { from "The PowerPC Compiler Writer's Guide" pg. 53ff      }
                  divreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
                  if (is_signed(right.resultdef)) then begin
-                     getmagic_signed32(tordconstnode(right).value, magic, shift);
+                     getmagic_signed32(tordconstnode(right).value.svalue, magic, shift);
                      // load magic value
                      cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, magic, divreg);
                      // multiply
@@ -243,7 +243,7 @@ end;
                      end;                     
                      cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_ADD, OS_INT, resultreg, divreg, resultreg);
                  end else begin
-                     getmagic_unsigned32(tordconstnode(right).value, u_magic, u_add, u_shift);
+                     getmagic_unsigned32(tordconstnode(right).value.uvalue, u_magic, u_add, u_shift);
                      // load magic in divreg
                      cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, aint(u_magic), divreg);
                      current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_MULHWU, resultreg, numerator, divreg));
@@ -286,11 +286,11 @@ end;
                      cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, modreg, maskreg, maskreg);
                      cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_OR, OS_INT, maskreg, tempreg, resultreg);
                  end else begin
-                     cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, tordconstnode(right).value-1, numerator, resultreg);
+                     cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, tordconstnode(right).value.svalue-1, numerator, resultreg);
                  end;
              end else begin
                  genOrdConstNodeDiv();
-                 cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_MUL, OS_INT, tordconstnode(right).value, resultreg, resultreg);
+                 cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_MUL, OS_INT, tordconstnode(right).value.svalue, resultreg, resultreg);
                  cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_SUB, OS_INT, resultreg, numerator, resultreg);
              end;
          end;
@@ -406,7 +406,7 @@ end;
                end;
              if (right.nodetype = ordconstn) then
                begin
-                 shiftval := tordconstnode(right).value;
+                 shiftval := tordconstnode(right).value.svalue;
                  shiftval := shiftval and 63;
 {
               I think the statements below is much more correct instead of the hack above,
@@ -529,7 +529,7 @@ end;
              { shifting by a constant directly coded: }
              if (right.nodetype=ordconstn) then
                cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,location.size,
-                 tordconstnode(right).value and 31,hregister1,resultreg)
+                 tordconstnode(right).value.svalue and 31,hregister1,resultreg)
              else
                begin
                  { load shift count in a register if necessary }

+ 4 - 4
compiler/powerpc64/nppcmat.pas

@@ -50,7 +50,7 @@ implementation
 
 uses
   sysutils,
-  globtype, systems,
+  globtype, systems,constexp,
   cutils, verbose, globals,
   symconst, symdef,
   aasmbase, aasmcpu, aasmtai,aasmdata,
@@ -145,7 +145,7 @@ var
   begin
     if (tordconstnode(right).value = 0) then begin
       internalerror(2005061702);
-    end else if (abs(tordconstnode(right).value) = 1) then begin
+    end else if (abs(tordconstnode(right).value.svalue) = 1) then begin
       { x mod +/-1 is always zero }
       cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, 0, resultreg);
     end else if (ispowerof2(tordconstnode(right).value, power)) then begin
@@ -154,7 +154,7 @@ var
         maskreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
         modreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
 
-        cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, abs(tordconstnode(right).value)-1, modreg);
+        cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, abs(tordconstnode(right).value.svalue)-1, modreg);
         cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SAR, OS_INT, 63, numerator, maskreg);
         cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, numerator, modreg, tempreg);
 
@@ -170,7 +170,7 @@ var
     end else begin
       cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, divCgOps[is_signed(right.resultdef)], OS_INT, 
         tordconstnode(right).value, numerator, resultreg);
-      cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_MUL, OS_INT, tordconstnode(right).value, resultreg, 
+      cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_MUL, OS_INT, tordconstnode(right).value.svalue, resultreg, 
         resultreg);
       cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_SUB, OS_INT, resultreg, numerator, resultreg);
     end;

+ 10 - 10
compiler/ppcgen/ngppcset.pas

@@ -42,7 +42,7 @@ implementation
 
     uses
       systems,
-      verbose,globals,
+      verbose,globals,constexp,
       symconst,symdef,defutil,
       paramgr,
       cpuinfo,
@@ -83,13 +83,13 @@ implementation
             if assigned(t^.less) then
               genitem(list,t^.less);
             { fill possible hole }
-            i:=last+1;
+            i:=last.svalue+1;
             while i<=t^._low-1 do
               begin
                 list.concat(Tai_const.Create_sym(elselabel));
                 inc(i);
               end;
-            i:=t^._low;
+            i:=t^._low.svalue;
             while i<=t^._high do
               begin
                 list.concat(Tai_const.Create_sym(blocklabel(t^.blockid)));
@@ -159,8 +159,8 @@ implementation
           end;
 
         begin
-           if (get_min_value(left.resultdef) >= low(smallint)) and
-              (get_max_value(left.resultdef) <= high(word)) then
+           if (get_min_value(left.resultdef) >= int64(low(smallint))) and
+              (get_max_value(left.resultdef) <= int64(high(word))) then
              begin
                genlinearcmplist(hp);
                exit;
@@ -170,14 +170,14 @@ implementation
            { need we to test the first value }
            if first and (t^._low>get_min_value(left.resultdef)) then
              begin
-               cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,jmp_lt,aword(t^._low),hregister,elselabel);
+               cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,jmp_lt,aword(t^._low.svalue),hregister,elselabel);
              end;
            if t^._low=t^._high then
              begin
                 if t^._low-last=0 then
                   cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ,0,hregister,blocklabel(t^.blockid))
                 else
-                  gensub(longint(t^._low-last));
+                  gensub(longint(int64(t^._low-last)));
                 tcgppc(cg).a_jmp_cond(current_asmdata.CurrAsmList,OC_EQ,blocklabel(t^.blockid));
                 last:=t^._low;
                 lastrange := false;
@@ -191,19 +191,19 @@ implementation
                   begin
                      { have we to ajust the first value ? }
                      if (t^._low>get_min_value(left.resultdef)) then
-                       gensub(longint(t^._low));
+                       gensub(longint(int64(t^._low)));
                   end
                 else
                   begin
                     { if there is no unused label between the last and the }
                     { present label then the lower limit can be checked    }
                     { immediately. else check the range in between:       }
-                    gensub(longint(t^._low-last));
+                    gensub(longint(int64(t^._low-last)));
                     if ((t^._low-last) <> 1) or
                        (not lastrange) then
                       tcgppc(cg).a_jmp_cond(current_asmdata.CurrAsmList,jmp_lt,elselabel);
                   end;
-                gensub(longint(t^._high-t^._low));
+                gensub(longint(int64(t^._high-t^._low)));
                 tcgppc(cg).a_jmp_cond(current_asmdata.CurrAsmList,jmp_le,blocklabel(t^.blockid));
                 last:=t^._high;
                 lastrange := true;

+ 2 - 3
compiler/ppu.pas

@@ -26,7 +26,7 @@ unit ppu;
 interface
 
   uses
-    globtype;
+    globtype,constexp;
 
 { Also write the ppu if only crc if done, this can be used with ppudump to
   see the differences between the intf and implementation }
@@ -43,7 +43,7 @@ type
 {$endif Test_Double_checksum}
 
 const
-  CurrentPPUVersion=80;
+  CurrentPPUVersion=81;
 
 { buffer sizes }
   maxentrysize = 1024;
@@ -1011,7 +1011,6 @@ begin
   putdata(i,sizeof(aint));
 end;
 
-
 procedure tppufile.putreal(d:ppureal);
 var
   hd : double;

+ 5 - 5
compiler/pstatmnt.pas

@@ -41,7 +41,7 @@ implementation
        { common }
        cutils,cclasses,
        { global }
-       globtype,globals,verbose,
+       globtype,globals,verbose,constexp,
        systems,
        { aasm }
        cpubase,aasmbase,aasmtai,aasmdata,
@@ -183,8 +183,8 @@ implementation
                         CGMessage(parser_e_case_lower_less_than_upper_bound);
                       if not casedeferror then
                        begin
-                         testrange(casedef,casedef,hl1,false);
-                         testrange(casedef,casedef,hl2,false);
+                         testrange(casedef,hl1,false);
+                         testrange(casedef,hl2,false);
                        end;
                     end
                   else
@@ -198,7 +198,7 @@ implementation
                     CGMessage(parser_e_case_mismatch);
                   hl1:=get_ordinal_value(p);
                   if not casedeferror then
-                    testrange(casedef,casedef,hl1,false);
+                    testrange(casedef,hl1,false);
                   casenode.addlabel(blockid,hl1,hl1);
                end;
              p.free;
@@ -286,7 +286,7 @@ implementation
 {$ifndef cpu64bit}
           if hp.nodetype=ordconstn then
             begin
-              if (tordconstnode(hp).value<low(longint)) or
+              if (tordconstnode(hp).value<int64(low(longint))) or
                  (tordconstnode(hp).value>high(longint)) then
                 begin
                   CGMessage(parser_e_range_check_error);

+ 1 - 1
compiler/psub.pas

@@ -78,7 +78,7 @@ implementation
        { common }
        cutils,
        { global }
-       globtype,tokens,verbose,comphook,
+       globtype,tokens,verbose,comphook,constexp,
        systems,
        { aasm }
        cpubase,aasmbase,aasmtai,aasmdata,

+ 9 - 6
compiler/psystem.pas

@@ -40,7 +40,7 @@ interface
 implementation
 
     uses
-      globals,globtype,verbose,
+      globals,globtype,verbose,constexp,
       systems,
       symconst,symtype,symsym,symdef,symtable,
       aasmtai,aasmdata,aasmcpu,
@@ -121,15 +121,16 @@ implementation
       begin
         symtablestack.push(systemunit);
         cundefinedtype:=tundefineddef.create;
-        cformaltype:=tformaldef.create;
+        cformaltype:=tformaldef.create(false);
+        ctypedformaltype:=tformaldef.create(true);
         voidtype:=torddef.create(uvoid,0,0);
         u8inttype:=torddef.create(u8bit,0,255);
-        s8inttype:=torddef.create(s8bit,-128,127);
+        s8inttype:=torddef.create(s8bit,int64(-128),127);
         u16inttype:=torddef.create(u16bit,0,65535);
-        s16inttype:=torddef.create(s16bit,-32768,32767);
+        s16inttype:=torddef.create(s16bit,int64(-32768),32767);
         u32inttype:=torddef.create(u32bit,0,high(longword));
-        s32inttype:=torddef.create(s32bit,low(longint),high(longint));
-        u64inttype:=torddef.create(u64bit,low(qword),TConstExprInt(high(qword)));
+        s32inttype:=torddef.create(s32bit,int64(low(longint)),int64(high(longint)));
+        u64inttype:=torddef.create(u64bit,low(qword),high(qword));
         s64inttype:=torddef.create(s64bit,low(int64),high(int64));
         booltype:=torddef.create(bool8bit,0,1);
         bool16type:=torddef.create(bool16bit,0,1);
@@ -268,6 +269,7 @@ implementation
         { Internal types }
         addtype('$undefined',cundefinedtype);
         addtype('$formal',cformaltype);
+        addtype('$typedformal',ctypedformaltype);
         addtype('$void',voidtype);
         addtype('$byte',u8inttype);
         addtype('$shortint',s8inttype);
@@ -359,6 +361,7 @@ implementation
         loadtype('int64',s64inttype);
         loadtype('undefined',cundefinedtype);
         loadtype('formal',cformaltype);
+        loadtype('typedformal',ctypedformaltype);
         loadtype('void',voidtype);
         loadtype('char',cchartype);
         loadtype('widechar',cwidechartype);

+ 33 - 20
compiler/ptconst.pas

@@ -34,7 +34,7 @@ implementation
 
     uses
        SysUtils,
-       globtype,systems,tokens,verbose,
+       globtype,systems,tokens,verbose,constexp,
        cutils,globals,widestr,scanner,
        symconst,symbase,symdef,symtable,
        aasmbase,aasmtai,aasmcpu,defutil,defcmp,
@@ -179,28 +179,28 @@ implementation
               bool8bit :
                 begin
                    if is_constboolnode(n) then
-                     list.concat(Tai_const.Create_8bit(byte(tordconstnode(n).value)))
+                     list.concat(Tai_const.Create_8bit(byte(tordconstnode(n).value.svalue)))
                    else
                      IncompatibleTypes(n.resultdef, def);
                 end;
               bool16bit :
                 begin
                    if is_constboolnode(n) then
-                     list.concat(Tai_const.Create_16bit(word(tordconstnode(n).value)))
+                     list.concat(Tai_const.Create_16bit(word(tordconstnode(n).value.svalue)))
                    else
                      IncompatibleTypes(n.resultdef, def);
                 end;
               bool32bit :
                 begin
                    if is_constboolnode(n) then
-                     list.concat(Tai_const.Create_32bit(longint(tordconstnode(n).value)))
+                     list.concat(Tai_const.Create_32bit(longint(tordconstnode(n).value.svalue)))
                    else
                      IncompatibleTypes(n.resultdef, def);
                 end;
               bool64bit :
                 begin
                    if is_constboolnode(n) then
-                     list.concat(Tai_const.Create_64bit(int64(tordconstnode(n).value)))
+                     list.concat(Tai_const.Create_64bit(int64(tordconstnode(n).value.svalue)))
                    else
                      IncompatibleTypes(n.resultdef, def);
                 end;
@@ -210,7 +210,7 @@ implementation
                      ((m_delphi in current_settings.modeswitches) and
                       is_constwidecharnode(n) and
                       (tordconstnode(n).value <= 255)) then
-                     list.concat(Tai_const.Create_8bit(byte(tordconstnode(n).value)))
+                     list.concat(Tai_const.Create_8bit(byte(tordconstnode(n).value.svalue)))
                    else
                      IncompatibleTypes(n.resultdef, def);
                 end;
@@ -219,7 +219,7 @@ implementation
                    if is_constcharnode(n) then
                      inserttypeconv(n,cwidechartype);
                    if is_constwidecharnode(n) then
-                     list.concat(Tai_const.Create_16bit(word(tordconstnode(n).value)))
+                     list.concat(Tai_const.Create_16bit(word(tordconstnode(n).value.svalue)))
                    else
                      IncompatibleTypes(n.resultdef, def);
                 end;
@@ -230,16 +230,16 @@ implementation
                 begin
                    if is_constintnode(n) then
                      begin
-                       testrange(n.resultdef,def,tordconstnode(n).value,false);
+                       testrange(def,tordconstnode(n).value,false);
                        case def.size of
                          1 :
-                           list.concat(Tai_const.Create_8bit(byte(tordconstnode(n).value)));
+                           list.concat(Tai_const.Create_8bit(byte(tordconstnode(n).value.svalue)));
                          2 :
-                           list.concat(Tai_const.Create_16bit(word(tordconstnode(n).value)));
+                           list.concat(Tai_const.Create_16bit(word(tordconstnode(n).value.svalue)));
                          4 :
-                           list.concat(Tai_const.Create_32bit(longint(tordconstnode(n).value)));
+                           list.concat(Tai_const.Create_32bit(longint(tordconstnode(n).value.svalue)));
                          8 :
-                           list.concat(Tai_const.Create_64bit(tordconstnode(n).value));
+                           list.concat(Tai_const.Create_64bit(tordconstnode(n).value.svalue));
                        end;
                      end
                    else
@@ -334,6 +334,7 @@ implementation
           i,len     : longint;
           base,
           offset    : aint;
+          v         : Tconstexprint;
           ll        : tasmlabel;
           varalign  : shortint;
         begin
@@ -399,7 +400,7 @@ implementation
                   end
                 else
                   if is_constcharnode(p) then
-                    current_asmdata.asmlists[al_const].concat(Tai_string.Create(char(byte(tordconstnode(p).value))+#0))
+                    current_asmdata.asmlists[al_const].concat(Tai_string.Create(char(byte(tordconstnode(p).value.svalue))+#0))
                 else
                   IncompatibleTypes(p.resultdef, def);
             end
@@ -473,7 +474,16 @@ implementation
                                    Message(parser_e_illegal_expression);
                                end;
                                if is_constintnode(tvecnode(hp).right) then
-                                 inc(offset,len*(get_ordinal_value(tvecnode(hp).right)-base))
+                                 begin
+                                   {Prevent overflow.}
+                                   v:=get_ordinal_value(tvecnode(hp).right)-base;
+                                   if (v<int64(low(offset))) or (v>int64(high(offset))) then
+                                     message(parser_e_range_check_error);
+                                   if high(offset)-offset div len>v then
+                                     inc(offset,len*v.svalue)
+                                   else
+                                     message(parser_e_range_check_error);
+                                 end
                                else
                                  Message(parser_e_illegal_expression);
                              end;
@@ -592,9 +602,9 @@ implementation
                  is_subequal(p.resultdef,def) then
                 begin
                   case longint(p.resultdef.size) of
-                    1 : list.concat(Tai_const.Create_8bit(Byte(tordconstnode(p).value)));
-                    2 : list.concat(Tai_const.Create_16bit(Word(tordconstnode(p).value)));
-                    4 : list.concat(Tai_const.Create_32bit(Longint(tordconstnode(p).value)));
+                    1 : list.concat(Tai_const.Create_8bit(Byte(tordconstnode(p).value.svalue)));
+                    2 : list.concat(Tai_const.Create_16bit(Word(tordconstnode(p).value.svalue)));
+                    4 : list.concat(Tai_const.Create_32bit(Longint(tordconstnode(p).value.svalue)));
                   end;
                 end
               else
@@ -629,7 +639,7 @@ implementation
             begin
               { strval:=pchar(@tordconstnode(n).value);
                 THIS FAIL on BIG_ENDIAN MACHINES PM }
-              strch:=chr(tordconstnode(n).value and $ff);
+              strch:=chr(tordconstnode(n).value.svalue and $ff);
               strval:=@strch;
               strlength:=1
             end
@@ -742,7 +752,10 @@ implementation
                 result:=false;
                 exit;
               end;
-            bitpackval(tordconstnode(n).value,bp);
+            if (Tordconstnode(n).value<qword(low(Aword))) or (Tordconstnode(n).value>qword(high(Aword))) then
+              message(parser_e_range_check_error)
+            else
+              bitpackval(Tordconstnode(n).value.uvalue,bp);
             if (bp.curbitoffset>=AIntBits) then
               flush_packed_value(list,bp);
             n.free;
@@ -829,7 +842,7 @@ implementation
                else
                  if is_constcharnode(n) then
                   begin
-                    ch:=chr(tordconstnode(n).value and $ff);
+                    ch:=chr(tordconstnode(n).value.uvalue and $ff);
                     ca:=@ch;
                     len:=1;
                   end

+ 18 - 11
compiler/ptype.pas

@@ -60,7 +60,7 @@ implementation
        { common }
        cutils,
        { global }
-       globals,tokens,verbose,
+       globals,tokens,verbose,constexp,
        systems,
        { target }
        paramgr,
@@ -379,13 +379,15 @@ implementation
                    hv:=tordconstnode(pt2).value;
                    { Check bounds }
                    if hv<lv then
-                     Message(parser_e_upper_lower_than_lower)
+                     message(parser_e_upper_lower_than_lower)
+                   else if (lv.signed and (lv.svalue<0)) and (not hv.signed and (hv.uvalue>qword(high(int64)))) then
+                     message(type_e_cant_eval_constant_expr)
                    else
                      begin
                        { All checks passed, create the new def }
                        case pt1.resultdef.typ of
                          enumdef :
-                           def:=tenumdef.create_subrange(tenumdef(pt1.resultdef),lv,hv);
+                           def:=tenumdef.create_subrange(tenumdef(pt1.resultdef),lv.svalue,hv.svalue);
                          orddef :
                            begin
                              if is_char(pt1.resultdef) then
@@ -393,6 +395,8 @@ implementation
                              else
                                if is_boolean(pt1.resultdef) then
                                  def:=torddef.create(bool8bit,lv,hv)
+                               else if is_signed(pt1.resultdef) then
+                                 def:=torddef.create(range_to_basetype(lv,hv),lv,hv)
                                else
                                  def:=torddef.create(range_to_basetype(lv,hv),lv,hv);
                            end;
@@ -440,7 +444,10 @@ implementation
                    if (torddef(tt2).ordtype<>uvoid) and
                       (torddef(tt2).low>=0) then
                      // !! def:=tsetdef.create(tt2,torddef(tt2.def).low,torddef(tt2.def).high))
-                     def:=tsetdef.create(tt2,torddef(tt2).high)
+                     if Torddef(tt2).high>int64(high(longint)) then
+                       message(sym_e_ill_type_decl_set)
+                     else
+                       def:=tsetdef.create(tt2,torddef(tt2).high.svalue)
                    else
                      Message(sym_e_ill_type_decl_set);
                  end;
@@ -504,7 +511,7 @@ implementation
              begin
                 { defaults }
                 indexdef:=generrordef;
-                lowval:=low(aint);
+                lowval:=int64(low(aint));
                 highval:=high(aint);
                 repeat
                   { read the expression and check it, check apart if the
@@ -540,7 +547,7 @@ implementation
                                    Message(parser_e_array_lower_less_than_upper_bound);
                                    highval:=lowval;
                                  end
-                                else if (lowval < low(aint)) or
+                                else if (lowval<int64(low(aint))) or
                                         (highval > high(aint)) then
                                   begin
                                     Message(parser_e_array_range_out_of_bounds);
@@ -565,12 +572,12 @@ implementation
                     as element of the existing array, otherwise create a new array }
                   if assigned(arrdef) then
                     begin
-                      arrdef.elementdef:=tarraydef.create(lowval,highval,indexdef);
+                      arrdef.elementdef:=tarraydef.create(lowval.svalue,highval.svalue,indexdef);
                       arrdef:=tarraydef(arrdef.elementdef);
                     end
                   else
                     begin
-                      arrdef:=tarraydef.create(lowval,highval,indexdef);
+                      arrdef:=tarraydef.create(lowval.svalue,highval.svalue,indexdef);
                       def:=arrdef;
                     end;
                   if is_packed then
@@ -623,7 +630,7 @@ implementation
                 consume(_LKLAMMER);
                 first := true;
                 { allow negativ value_str }
-                l:=-1;
+                l:=int64(-1);
                 enumdupmsg:=false;
                 aktenumdef:=tenumdef.create;
                 repeat
@@ -668,11 +675,11 @@ implementation
                        l:=v;
                     end
                   else
-                    inc(l);
+                    inc(l.svalue);
                   first := false;
                   storepos:=current_tokenpos;
                   current_tokenpos:=defpos;
-                  tstoredsymtable(aktenumdef.owner).insert(tenumsym.create(s,aktenumdef,l));
+                  tstoredsymtable(aktenumdef.owner).insert(tenumsym.create(s,aktenumdef,l.svalue));
                   current_tokenpos:=storepos;
                 until not try_to_consume(_COMMA);
                 def:=aktenumdef;

+ 2 - 2
compiler/rautils.pas

@@ -872,7 +872,7 @@ Begin
       begin
         if tconstsym(sym).consttyp=constord then
          begin
-           setconst(tconstsym(sym).value.valueord);
+           setconst(tconstsym(sym).value.valueord.svalue);
            SetupVar:=true;
            Exit;
          end;
@@ -1250,7 +1250,7 @@ Begin
          begin
            if tconstsym(srsym).consttyp=constord then
             Begin
-              l:=tconstsym(srsym).value.valueord;
+              l:=tconstsym(srsym).value.valueord.svalue;
               SearchIConstant:=TRUE;
               exit;
             end;

+ 2 - 2
compiler/rgobj.pas

@@ -250,8 +250,8 @@ unit rgobj;
   implementation
 
     uses
-       systems,
-       globals,verbose,tgobj,procinfo;
+       systems,fmodule,globals,
+       verbose,tgobj,procinfo;
 
 
     procedure sort_movelist(ml:Pmovelist);

+ 1 - 1
compiler/scandir.pas

@@ -32,7 +32,7 @@ implementation
 
     uses
       SysUtils,
-      cutils,cfileutils,
+      cutils,cfileutl,
       globtype,globals,systems,widestr,cpuinfo,
       verbose,comphook,ppu,
       scanner,switches,

+ 4 - 4
compiler/scanner.pas

@@ -27,7 +27,7 @@ interface
 
     uses
        cclasses,
-       globtype,globals,version,tokens,
+       globtype,globals,constexp,version,tokens,
        verbose,comphook,
        finput,
        widestr;
@@ -209,7 +209,7 @@ implementation
 
     uses
       SysUtils,
-      cutils,cfileutils,
+      cutils,cfileutl,
       systems,
       switches,
       symbase,symtable,symtype,symsym,symconst,symdef,defutil,
@@ -282,7 +282,7 @@ implementation
           current_settings.modeswitches:=objfpcmodeswitches;
           { TODO: enable this for 2.3/2.9 }
           //  include(current_settings.localswitches, cs_typed_addresses);
-        end 
+        end
 {$ifdef gpc_mode}
         else if s='GPC' then
           current_settings.modeswitches:=gpcmodeswitches
@@ -964,7 +964,7 @@ In case not, the value returned can be arbitrary.
                                                   end
                                                 else if is_char(constdef) then
                                                   begin
-                                                    read_factor:=chr(value.valueord);
+                                                    read_factor:=char(qword(value.valueord));
                                                     factorType:= [ctetString];
                                                   end
                                               end;

+ 1 - 1
compiler/script.pas

@@ -109,7 +109,7 @@ uses
 {$ifdef hasUnix}
   BaseUnix,
 {$endif}
-  cutils,cfileutils,
+  cutils,cfileutl,
   globals,systems,verbose;
 
 

+ 5 - 5
compiler/sparc/ncpumat.pas

@@ -46,7 +46,7 @@ interface
 implementation
 
     uses
-      globtype,systems,
+      globtype,systems,constexp,
       cutils,verbose,globals,
       symconst,
       aasmbase,aasmcpu,aasmtai,aasmdata,
@@ -98,14 +98,14 @@ implementation
 
          if (nodetype = divn) and
             (right.nodetype = ordconstn) and
-            ispowerof2(tordconstnode(right).value,power) then
+            ispowerof2(tordconstnode(right).value.svalue,power) then
            begin
              if is_signed(left.resultdef) Then
                begin
                  tmpreg:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_INT);
                  cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,31,numerator,tmpreg);
                  { if signed, tmpreg=right value-1, otherwise 0 }
-                 cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_AND,OS_INT,tordconstnode(right).value-1,tmpreg);
+                 cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_AND,OS_INT,tordconstnode(right).value.svalue-1,tmpreg);
                  { add to the left value }
                  cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_ADD,OS_INT,numerator,tmpreg);
                  cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,aword(power),tmpreg,resultreg);
@@ -203,7 +203,7 @@ implementation
             hreg64hi:=left.location.register64.reghi;
             hreg64lo:=left.location.register64.reglo;
 
-            shiftval := tordconstnode(right).value and 63;
+            shiftval := tordconstnode(right).value.svalue and 63;
             if shiftval > 31 then
               begin
                 if nodetype = shln then
@@ -264,7 +264,7 @@ implementation
             if (right.nodetype=ordconstn) then
               begin
                 if tordconstnode(right).value and 31<>0 then
-                  cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,OS_32,tordconstnode(right).value and 31,hregister1,resultreg)
+                  cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,OS_32,tordconstnode(right).value.svalue and 31,hregister1,resultreg)
               end
             else
               begin

+ 3 - 3
compiler/sparc/ncpuset.pas

@@ -42,7 +42,7 @@ unit ncpuset;
   implementation
 
     uses
-      globals,
+      globals,constexp,
       systems,
       cpubase,
       aasmbase,aasmtai,aasmdata,aasmcpu,
@@ -76,9 +76,9 @@ unit ncpuset;
             if assigned(t^.less) then
               genitem(list,t^.less);
             { fill possible hole }
-            for i:=last+1 to t^._low-1 do
+            for i:=last.svalue+1 to t^._low.svalue-1 do
               list.concat(Tai_const.Create_sym(elselabel));
-            for i:=t^._low to t^._high do
+            for i:=t^._low.svalue to t^._high.svalue do
               list.concat(Tai_const.Create_sym(blocklabel(t^.blockid)));
             last:=t^._high;
             if assigned(t^.greater) then

+ 2 - 1
compiler/symconst.pas

@@ -355,7 +355,8 @@ type
     vo_has_mangledname,
     vo_is_typed_const,
     vo_is_range_check,
-    vo_is_overflow_check
+    vo_is_overflow_check,
+    vo_is_typinfo_para
   );
   tvaroptions=set of tvaroption;
 

+ 19 - 27
compiler/symdef.pas

@@ -28,7 +28,7 @@ interface
        { common }
        cclasses,
        { global }
-       globtype,globals,tokens,
+       globtype,globals,tokens,constexp,
        { symtable }
        symconst,symbase,symtype,
        { ppu }
@@ -119,7 +119,8 @@ interface
        end;
 
        tformaldef = class(tstoreddef)
-          constructor create;
+          typed:boolean;
+          constructor create(Atyped:boolean);
           constructor ppuload(ppufile:tcompilerppufile);
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           function  GetTypeName:string;override;
@@ -569,6 +570,7 @@ interface
        voidfarpointertype,
        cundefinedtype,
        cformaltype,               { unique formal definition }
+       ctypedformaltype,          { unique typed formal definition }
        voidtype,                  { Void (procedure) }
        cchartype,                 { Char }
        cwidechartype,             { WideChar }
@@ -1447,16 +1449,8 @@ implementation
       begin
          inherited ppuload(orddef,ppufile);
          ordtype:=tordtype(ppufile.getbyte);
-         if sizeof(TConstExprInt)=8 then
-           begin
-             low:=ppufile.getint64;
-             high:=ppufile.getint64;
-           end
-         else
-           begin
-             low:=ppufile.getlongint;
-             high:=ppufile.getlongint;
-           end;
+         low:=ppufile.getexprint;
+         high:=ppufile.getexprint;
          setsize;
       end;
 
@@ -1544,16 +1538,8 @@ implementation
       begin
          inherited ppuwrite(ppufile);
          ppufile.putbyte(byte(ordtype));
-         if sizeof(TConstExprInt)=8 then
-          begin
-            ppufile.putint64(low);
-            ppufile.putint64(high);
-          end
-         else
-          begin
-            ppufile.putlongint(low);
-            ppufile.putlongint(high);
-          end;
+         ppufile.putexprint(low);
+         ppufile.putexprint(high);
          ppufile.writeentry(iborddef);
       end;
 
@@ -1755,9 +1741,9 @@ implementation
         case filetyp of
           ft_text :
             if target_info.system in [system_x86_64_win64,system_ia64_win64] then
-              savesize:=632
+              savesize:=632{+8}
             else
-              savesize:=628;
+              savesize:=628{+8};
           ft_typed,
           ft_untyped :
             if target_info.system in [system_x86_64_win64,system_ia64_win64] then
@@ -1768,7 +1754,7 @@ implementation
 {$else cpu64bit}
         case filetyp of
           ft_text :
-            savesize:=592;
+            savesize:=592{+4};
           ft_typed,
           ft_untyped :
             savesize:=332;
@@ -2111,9 +2097,10 @@ implementation
                                  TFORMALDEF
 ***************************************************************************}
 
-    constructor tformaldef.create;
+    constructor tformaldef.create(Atyped:boolean);
       begin
          inherited create(formaldef);
+         typed:=Atyped;
          savesize:=0;
       end;
 
@@ -2121,6 +2108,7 @@ implementation
     constructor tformaldef.ppuload(ppufile:tcompilerppufile);
       begin
          inherited ppuload(formaldef,ppufile);
+         typed:=boolean(ppufile.getbyte);
          savesize:=0;
       end;
 
@@ -2128,13 +2116,17 @@ implementation
     procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
       begin
          inherited ppuwrite(ppufile);
+         ppufile.putbyte(byte(typed));
          ppufile.writeentry(ibformaldef);
       end;
 
 
     function tformaldef.GetTypeName : string;
       begin
-         GetTypeName:='<Formal type>';
+         if typed then
+           GetTypeName:='<Typed formal type>'
+         else
+           GetTypeName:='<Formal type>';
       end;
 
 

+ 1 - 1
compiler/symsym.pas

@@ -28,7 +28,7 @@ interface
        { common }
        cutils,
        { target }
-       globtype,globals,widestr,
+       globtype,globals,widestr,constexp,
        { symtable }
        symconst,symbase,symtype,symdef,defcmp,
        { ppu }

+ 19 - 20
compiler/symtype.pas

@@ -29,7 +29,7 @@ interface
       cutils,
       cclasses,
       { global }
-      globtype,globals,
+      globtype,globals,constexp,
       { symtable }
       symconst,symbase,
       { aasm }
@@ -171,14 +171,14 @@ interface
        public
          procedure checkerror;
          procedure getguid(var g: tguid);
-         function  getexprint:tconstexprint;
+         function  getexprint:Tconstexprint;
          function  getptruint:TConstPtrUInt;
          procedure getposinfo(var p:tfileposinfo);
          procedure getderef(var d:tderef);
          function  getpropaccesslist:tpropaccesslist;
          function  getasmsymbol:tasmsymbol;
          procedure putguid(const g: tguid);
-         procedure putexprint(v:tconstexprint);
+         procedure putexprint(const v:tconstexprint);
          procedure PutPtrUInt(v:TConstPtrUInt);
          procedure putposinfo(const p:tfileposinfo);
          procedure putderef(const d:tderef);
@@ -763,13 +763,13 @@ implementation
       end;
 
 
-    function tcompilerppufile.getexprint:tconstexprint;
-      begin
-        if sizeof(tconstexprint)=8 then
-          result:=tconstexprint(getint64)
-        else
-          result:=tconstexprint(getlongint);
-      end;
+    function tcompilerppufile.getexprint:Tconstexprint;
+
+    begin
+      getexprint.overflow:=false;
+      getexprint.signed:=boolean(getbyte);
+      getexprint.svalue:=getint64;
+    end;
 
 
     function tcompilerppufile.getPtrUInt:TConstPtrUInt;
@@ -953,15 +953,14 @@ implementation
       end;
 
 
-    procedure tcompilerppufile.putexprint(v:tconstexprint);
-      begin
-        if sizeof(TConstExprInt)=8 then
-          putint64(int64(v))
-        else if sizeof(TConstExprInt)=4 then
-          putlongint(longint(v))
-        else
-          internalerror(2002082601);
-      end;
+    procedure Tcompilerppufile.putexprint(const v:Tconstexprint);
+
+    begin
+      if v.overflow then
+        internalerror(200706102);
+      putbyte(byte(v.signed));
+      putint64(v.svalue);
+    end;
 
 
     procedure tcompilerppufile.PutPtrUInt(v:TConstPtrUInt);
@@ -1005,7 +1004,7 @@ implementation
                putderef(hp^.defderef);
              sl_vec :
                begin
-                 putlongint(hp^.value);
+                 putlongint(int64(hp^.value));
                  putderef(hp^.valuedefderef);
                end;
              else

+ 1 - 1
compiler/symutil.pas

@@ -37,7 +37,7 @@ implementation
 
     uses
        cclasses,
-       globtype,cpuinfo,procinfo,
+       globtype,cpuinfo,procinfo,constexp,
        symconst,widestr;
 
 

+ 2 - 2
compiler/systems/i_embedded.pas → compiler/systems/i_embed.pas

@@ -18,7 +18,7 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  ****************************************************************************
 }
-unit i_embedded;
+unit i_embed;
 
   interface
 
@@ -32,7 +32,7 @@ unit i_embedded;
             name         : 'Embedded';
             shortname    : 'embedded';
             flags        : [tf_needs_symbol_size,tf_files_case_sensitive,tf_use_function_relative_addresses
-	                          ,tf_smartlink_sections,tf_requires_proper_alignment ];
+	                          ,tf_smartlink_sections];
             cpu          : cpu_arm;
             unit_env     : '';
             extradefines : '';

+ 1 - 1
compiler/systems/i_linux.pas

@@ -52,7 +52,7 @@ unit i_linux;
             system       : system_i386_LINUX;
             name         : 'Linux for i386';
             shortname    : 'Linux';
-            flags        : [tf_needs_symbol_size,tf_pic_uses_got{,tf_smartlink_sections},
+            flags        : [tf_needs_symbol_size,tf_pic_uses_got{,tf_smartlink_sections},tf_winlikewidestring,
 {$ifdef segment_threadvars}
                             tf_section_threadvars,
 {$endif segment_threadvars}

+ 1 - 1
compiler/systems/t_amiga.pas

@@ -50,7 +50,7 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
+       cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,script,fmodule,i_amiga;
 
 {$IF DEFINED(MORPHOS) OR DEFINED(AMIGA)}

+ 1 - 1
compiler/systems/t_beos.pas

@@ -57,7 +57,7 @@ implementation
 
   uses
     SysUtils,
-    cutils,cfileutils,cclasses,
+    cutils,cfileutl,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,i_beos,ogbase;

+ 1 - 1
compiler/systems/t_bsd.pas

@@ -32,7 +32,7 @@ implementation
 
   uses
     sysutils,
-    cutils,cfileutils,cclasses,
+    cutils,cfileutl,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,

+ 3 - 3
compiler/systems/t_embedded.pas → compiler/systems/t_embed.pas

@@ -20,7 +20,7 @@
 
  ****************************************************************************
 }
-unit t_embedded;
+unit t_embed;
 
 {$i fpcdefs.inc}
 
@@ -31,8 +31,8 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
-       globtype,globals,systems,verbose,script,fmodule,i_embedded,link;
+       cutils,cfileutl,cclasses,
+       globtype,globals,systems,verbose,script,fmodule,i_embed,link;
 
     type
        TlinkerEmbedded=class(texternallinker)

+ 3 - 3
compiler/systems/t_emx.pas

@@ -24,8 +24,8 @@
    A lot of code in this unit has been ported from C to Pascal from the
    emximp utility, part of the EMX development system. Emximp is copyrighted
    by Eberhard Mattes. Note: Eberhard doesn't know much about the Pascal
-   port, please send questions to Daniel Mantione
-   <[email protected]>.
+   port, please send questions to Tomas Hajny <[email protected]> or
+   Daniel Mantione <[email protected]>.
 }
 unit t_emx;
 
@@ -38,7 +38,7 @@ implementation
 
   uses
      sysutils,
-     cutils,cfileutils,cclasses,
+     cutils,cfileutl,cclasses,
      globtype,comphook,systems,symconst,symsym,symdef,
      globals,verbose,fmodule,script,ogbase,
      comprsrc,import,link,i_emx,ppu;

+ 1 - 1
compiler/systems/t_gba.pas

@@ -31,7 +31,7 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
+       cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,script,fmodule,i_gba,link;
 
     type

+ 1 - 1
compiler/systems/t_go32v2.pas

@@ -31,7 +31,7 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
+       cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,script,
        fmodule,i_go32v2,
        link,ogcoff;

+ 1 - 1
compiler/systems/t_linux.pas

@@ -66,7 +66,7 @@ implementation
 
   uses
     SysUtils,
-    cutils,cfileutils,cclasses,
+    cutils,cfileutl,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,

+ 1 - 1
compiler/systems/t_macos.pas

@@ -46,7 +46,7 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
+       cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,script,fmodule,i_macos,
        ogbase,
        symconst;

+ 1 - 1
compiler/systems/t_morph.pas

@@ -31,7 +31,7 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
+       cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,script,fmodule,i_morph,link;
 
     type

+ 1 - 1
compiler/systems/t_nds.pas

@@ -31,7 +31,7 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
+       cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,script,fmodule,i_nds,link;
 
     type

+ 1 - 1
compiler/systems/t_nwl.pas

@@ -99,7 +99,7 @@ implementation
 
   uses
     SysUtils,
-    cutils,cfileutils,
+    cutils,cfileutl,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,

+ 1 - 1
compiler/systems/t_nwm.pas

@@ -93,7 +93,7 @@ implementation
 
   uses
     SysUtils,
-    cutils,cfileutils,
+    cutils,cfileutl,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,

+ 3 - 3
compiler/systems/t_os2.pas

@@ -24,8 +24,8 @@
    A lot of code in this unit has been ported from C to Pascal from the
    emximp utility, part of the EMX development system. Emximp is copyrighted
    by Eberhard Mattes. Note: Eberhard doesn't know much about the Pascal
-   port, please send questions to Daniel Mantione
-   <[email protected]>.
+   port, please send questions to Tomas Hajny <[email protected]> or
+   Daniel Mantione <[email protected]>.
 }
 unit t_os2;
 
@@ -38,7 +38,7 @@ implementation
 
   uses
      SysUtils,
-     cutils,cfileutils,cclasses,
+     cutils,cfileutl,cclasses,
      globtype,systems,symconst,symdef,
      globals,verbose,fmodule,script,
      import,link,i_os2,ogbase;

+ 1 - 1
compiler/systems/t_palmos.pas

@@ -44,7 +44,7 @@ implementation
 
     uses
        SysUtils,
-       cutils,cfileutils,cclasses,
+       cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,script,fmodule,i_palmos,
        comprsrc;
 

+ 1 - 1
compiler/systems/t_sunos.pas

@@ -35,7 +35,7 @@ implementation
 
   uses
     sysutils,
-    cutils,cfileutils,cclasses,
+    cutils,cfileutl,cclasses,
     verbose,systems,globtype,globals,
     symconst,script,
     fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,

+ 1 - 1
compiler/systems/t_symbian.pas

@@ -45,7 +45,7 @@ implementation
 
   uses
     SysUtils,
-    cfileutils,
+    cfileutl,
     cpuinfo,cgutils,dbgbase,
     owar,ogbase,ogcoff, t_win;
 

+ 1 - 1
compiler/systems/t_watcom.pas

@@ -32,7 +32,7 @@ implementation
     uses
        link,
        SysUtils,
-       cclasses,cutils,cfileutils,globtype,globals,
+       cclasses,cutils,cfileutl,globtype,globals,
        systems,verbose,script,fmodule,i_watcom;
 
 

+ 1 - 1
compiler/systems/t_win.pas

@@ -100,7 +100,7 @@ implementation
 
   uses
     SysUtils,
-    cfileutils,
+    cfileutl,
     cpuinfo,cgutils,dbgbase,
     owar,ogbase,ogcoff;
 

+ 4 - 2
compiler/verbose.pas

@@ -32,7 +32,7 @@ interface
       fksysutl,
 {$ENDIF}
       cutils,
-      globals,finput,
+      globtype,finput,
       cmsgs;
 
 {$ifndef EXTERN_MSG}
@@ -67,6 +67,7 @@ interface
 
     var
       msg : pmessage;
+      paraprintnodetree : byte;
 
     type
       tmsgqueueevent = procedure(s:string;v,w:longint) of object;
@@ -117,7 +118,7 @@ interface
 implementation
 
     uses
-      comphook,fmodule;
+      comphook,fmodule,constexp,globals;
 
 
 {****************************************************************************
@@ -876,6 +877,7 @@ end;
 
 
 initialization
+  constexp.internalerror:=@internalerror;
 finalization
   { Be sure to close the redirect files to flush all data }
   DoneRedirectFile;

+ 5 - 4
compiler/x86/aasmcpu.pas

@@ -30,7 +30,7 @@ unit aasmcpu;
 interface
 
     uses
-      globtype,globals,verbose,
+      globtype,verbose,
       cpubase,
       cgbase,cgutils,
       symtype,
@@ -180,7 +180,7 @@ interface
         ops     : byte;
         optypes : array[0..2] of longint;
         code    : array[0..maxinfolen] of char;
-        flags   : longint;
+        flags   : cardinal;
       end;
       pinsentry=^tinsentry;
 
@@ -273,6 +273,7 @@ implementation
 
      uses
        cutils,
+       globals,
        itcpugas,
        symsym;
 
@@ -337,7 +338,7 @@ implementation
        IF_CENTAUR = $0d000000;  { centaur-specific instruction  }
        { added flags }
        IF_PRE    = $40000000;  { it's a prefix instruction }
-       IF_PASS2  = longint($80000000);  { if the instruction can change in a second pass }
+       IF_PASS2  = $80000000;  { if the instruction can change in a second pass }
 
      type
        TInsTabCache=array[TasmOp] of longint;
@@ -1037,9 +1038,9 @@ implementation
       }
       var
         insot,
-        insflags,
         currot,
         i,j,asize,oprs : longint;
+        insflags:cardinal;
         siz : array[0..2] of longint;
       begin
         result:=false;

+ 2 - 2
compiler/x86/nx86inl.pas

@@ -478,7 +478,7 @@ implementation
           if tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn then
             begin
               { calculate bit position }
-              l:=1 shl (tordconstnode(tcallparanode(tcallparanode(left).right).left).value mod bitsperop);
+              l:=1 shl (tordconstnode(tcallparanode(tcallparanode(left).right).left).value.svalue mod bitsperop);
 
               { determine operator }
               if inlinenumber=in_include_x_y then
@@ -492,7 +492,7 @@ implementation
                 LOC_REFERENCE :
                   begin
                     inc(tcallparanode(left).left.location.reference.offset,
-                      (tordconstnode(tcallparanode(tcallparanode(left).right).left).value div bitsperop)*tcgsize2size[opsize]);
+                      (tordconstnode(tcallparanode(tcallparanode(left).right).left).value.svalue div bitsperop)*tcgsize2size[opsize]);
                     cg.a_op_const_ref(current_asmdata.CurrAsmList,cgop,opsize,l,tcallparanode(left).left.location.reference);
                   end;
                 LOC_CREGISTER :

Some files were not shown because too many files changed in this diff