Pārlūkot izejas kodu

* use more generic set type boundaries for constant sets with one
element in Delphi mode (fixes mantis #10890, but requires more
thorough changes in nadd.pas for proper fixing)

git-svn-id: trunk@10399 -

Jonas Maebe 17 gadi atpakaļ
vecāks
revīzija
a2beae0e11
4 mainītis faili ar 160 papildinājumiem un 19 dzēšanām
  1. 2 0
      .gitattributes
  2. 15 19
      compiler/ncnv.pas
  3. 82 0
      tests/webtbf/tw10890a.pp
  4. 61 0
      tests/webtbs/tw10890.pp

+ 2 - 0
.gitattributes

@@ -7624,6 +7624,7 @@ tests/webtbf/tw10425a.pp svneol=native#text/plain
 tests/webtbf/tw10457.pp svneol=native#text/plain
 tests/webtbf/tw10833a.pp svneol=native#text/plain
 tests/webtbf/tw10849.pp svneol=native#text/plain
+tests/webtbf/tw10890a.pp svneol=native#text/plain
 tests/webtbf/tw1157a.pp svneol=native#text/plain
 tests/webtbf/tw1238.pp svneol=native#text/plain
 tests/webtbf/tw1251a.pp svneol=native#text/plain
@@ -7989,6 +7990,7 @@ tests/webtbs/tw1081.pp svneol=native#text/plain
 tests/webtbs/tw10815.pp svneol=native#text/plain
 tests/webtbs/tw10825.pp svneol=native#text/plain
 tests/webtbs/tw10833.pp svneol=native#text/plain
+tests/webtbs/tw10890.pp svneol=native#text/plain
 tests/webtbs/tw1090.pp svneol=native#text/plain
 tests/webtbs/tw1092.pp svneol=native#text/plain
 tests/webtbs/tw1096.pp svneol=native#text/plain

+ 15 - 19
compiler/ncnv.pas

@@ -296,7 +296,7 @@ implementation
         constsetlo,
         constsethi  : TConstExprInt;
 
-        procedure update_constsethi(def:tdef);
+        procedure update_constsethi(def:tdef; maybetruncenumrange: boolean);
           begin
             if (def.typ=orddef) and
                ((torddef(def).high>=constsethi) or
@@ -339,6 +339,16 @@ implementation
                    constsethi:=tenumdef(def).max;
                  if (tenumdef(def).min<=constsetlo) then
                    constsetlo:=tenumdef(def).min;
+                 { for constant set elements, delphi allows the usage of elements of enumerations which
+                   have value>255 if there is no element with a value > 255 used }
+                 if (maybetruncenumrange) and
+                    (m_delphi in current_settings.modeswitches) then
+                   begin
+                    if constsethi>255 then
+                      constsethi:=255;
+                    if constsetlo<0 then
+                      constsetlo:=0;
+                   end;
               end;
           end;
 
@@ -461,10 +471,10 @@ implementation
                               end
                              else
                               begin
-                                update_constsethi(p2.resultdef);
+                                update_constsethi(p2.resultdef,false);
                                 inserttypeconv(p2,hdef);
 
-                                update_constsethi(p3.resultdef);
+                                update_constsethi(p3.resultdef,false);
                                 inserttypeconv(p3,hdef);
 
                                 if assigned(hdef) then
@@ -481,21 +491,7 @@ implementation
                          if p2.nodetype=ordconstn then
                           begin
                             if not(is_integer(p2.resultdef)) then
-                              begin
-                                { for constant set elements, delphi allows the usage of elements of enumerations which
-                                  have value>255 if there is no element with a value > 255 used }
-                                if (m_delphi in current_settings.modeswitches) and (p2.resultdef.typ=enumdef) then
-                                  begin
-                                    if tordconstnode(p2).value>constsethi then
-                                      constsethi:=tordconstnode(p2).value;
-                                    if tordconstnode(p2).value<constsetlo then
-                                      constsetlo:=tordconstnode(p2).value;
-                                    if hdef=nil then
-                                      hdef:=p2.resultdef;
-                                  end
-                                else
-                                  update_constsethi(p2.resultdef);
-                              end;
+                              update_constsethi(p2.resultdef,true);
 
                             if assigned(hdef) then
                               inserttypeconv(p2,hdef)
@@ -507,7 +503,7 @@ implementation
                           end
                          else
                           begin
-                            update_constsethi(p2.resultdef);
+                            update_constsethi(p2.resultdef,false);
 
                             if assigned(hdef) then
                               inserttypeconv(p2,hdef)

+ 82 - 0
tests/webtbf/tw10890a.pp

@@ -0,0 +1,82 @@
+{ %fail }
+
+program tester;
+
+{$mode delphi}
+
+type TXMLElemKind = (
+ elErrorFrm,
+ elInvolutiveness,
+ elIrreflexivity,
+ elIs,
+ elIt,
+ elIterEquality,
+ elIterStep,
+ elJustifiedProperty,
+ elJustifiedTheorem,
+ elLambdaVar,
+ elLet,
+ elLocusVar,
+ elMonomial,
+ elNot,
+ elPoweredVar,
+ elPred,
+ elPredInstance,
+ elPriority,
+ elPrivFunc,
+ elPrivPred,
+ elProjectivity,
+ elProof,
+ elTakeAsVar,
+ elTheorem,
+ elTheorems,
+ elThesis,
+ elThesisExpansions,
+ elTransitivity,
+ elTyp,
+ elUnexpectedProp,
+ elUniqueness,
+ elUnknownCorrCond,
+ elVar,
+ elVerum,
+ e34,e35,e36,e37,e38,e39,
+ e40, e41, e42, e43, e44, e45, e46, e47, e48, e49,
+ e50, e51, e52, e53, e54, e55, e56, e57, e58, e59,
+ e60, e61, e62, e63, e64, e65, e66, e67, e68, e69,
+ e70, e71, e72, e73, e74, e75, e76, e77, e78, e79,
+ e80, e81, e82, e83, e84, e85, e86, e87, e88, e89,
+ e90, e91, e92, e93, e94, e95, e96, e97, e98, e99,
+ e100, e101, e102, e103, e104, e105, e106, e107, e108, e109,
+ e110, e111, e112, e113, e114, e115, e116, e117, e118, e119,
+ e120, e121, e122, e123, e124, e125, e126, e127, e128, e129,
+ e130, e131, e132, e133, e134, e135, e136, e137, e138, e139,
+ e140, e141, e142, e143, e144, e145, e146, e147, e148, e149,
+ e150, e151, e152, e153, e154, e155, e156, e157, e158, e159,
+ e160, e161, e162, e163, e164, e165, e166, e167, e168, e169,
+ e170, e171, e172, e173, e174, e175, e176, e177, e178, e179,
+ e180, e181, e182, e183, e184, e185, e186, e187, e188, e189,
+ e190, e191, e192, e193, e194, e195, e196, e197, e198, e199,
+ e200, e201, e202, e203, e204, e205, e206, e207, e208, e209,
+ e210, e211, e212, e213, e214, e215, e216, e217, e218, e219,
+ e220, e221, e222, e223, e224, e225, e226, e227, e228, e229,
+ e230, e231, e232, e233, e234, e235, e236, e237, e238, e239,
+ e240, e241, e242, e243, e244, e245, e246, e247, e248, e249,
+ e250, e251, e252, e253, e254, e255, e256
+ );
+
+const TermElKinds = [
+ elVar
+ ];
+
+const FrmElKinds = [
+ elErrorFrm,
+ elIs,
+ elNot,
+ elPred,
+ elPrivPred,
+ elVerum,
+ e256
+ ];
+
+begin
+end.

+ 61 - 0
tests/webtbs/tw10890.pp

@@ -0,0 +1,61 @@
+program tester;
+
+{$mode delphi}
+
+type TXMLElemKind = (
+ elErrorFrm,
+ elInvolutiveness,
+ elIrreflexivity,
+ elIs,
+ elIt,
+ elIterEquality,
+ elIterStep,
+ elJustifiedProperty,
+ elJustifiedTheorem,
+ elLambdaVar,
+ elLet,
+ elLocusVar,
+ elMonomial,
+ elNot,
+ elPoweredVar,
+ elPred,
+ elPredInstance,
+ elPriority,
+ elPrivFunc,
+ elPrivPred,
+ elProjectivity,
+ elProof,
+ elTakeAsVar,
+ elTheorem,
+ elTheorems,
+ elThesis,
+ elThesisExpansions,
+ elTransitivity,
+ elTyp,
+ elUnexpectedProp,
+ elUniqueness,
+ elUnknownCorrCond,
+ elVar,
+ elVerum
+ );
+
+const TermElKinds = [
+ elVar
+ ];
+
+const FrmElKinds = [
+ elErrorFrm,
+ elIs,
+ elNot,
+ elPred,
+ elPrivPred,
+ elVerum
+ ];
+
+var a:TXMLElemKind;
+
+begin
+  a:=elVerum;
+  if not(a in (FrmElKinds + TermElKinds)) then
+    halt(1);
+end.