Ver código fonte

+ evaluate typeinfo(<type1>)=/<>typeinfo(<type2>) at compile time, resolves #30260

git-svn-id: trunk@47008 -
florian 4 anos atrás
pai
commit
e124b07e86
3 arquivos alterados com 44 adições e 1 exclusões
  1. 1 0
      .gitattributes
  2. 22 1
      compiler/nadd.pas
  3. 21 0
      tests/webtbs/tw30260.pp

+ 1 - 0
.gitattributes

@@ -18064,6 +18064,7 @@ tests/webtbs/tw30207.pp svneol=native#text/plain
 tests/webtbs/tw30208.pp svneol=native#text/pascal
 tests/webtbs/tw30208.pp svneol=native#text/pascal
 tests/webtbs/tw3023.pp svneol=native#text/plain
 tests/webtbs/tw3023.pp svneol=native#text/plain
 tests/webtbs/tw30240.pp svneol=native#text/plain
 tests/webtbs/tw30240.pp svneol=native#text/plain
+tests/webtbs/tw30260.pp svneol=native#text/pascal
 tests/webtbs/tw3028.pp svneol=native#text/plain
 tests/webtbs/tw3028.pp svneol=native#text/plain
 tests/webtbs/tw30299.pp svneol=native#text/plain
 tests/webtbs/tw30299.pp svneol=native#text/plain
 tests/webtbs/tw30310.pp svneol=native#text/plain
 tests/webtbs/tw30310.pp svneol=native#text/plain

+ 22 - 1
compiler/nadd.pas

@@ -490,7 +490,7 @@ implementation
 
 
 
 
       var
       var
-        t       , vl, hp: tnode;
+        t,vl,hp,lefttarget,righttarget: tnode;
         lt,rt   : tnodetype;
         lt,rt   : tnodetype;
         hdef,
         hdef,
         rd,ld   , inttype: tdef;
         rd,ld   , inttype: tdef;
@@ -1309,6 +1309,27 @@ implementation
               end;
               end;
           end;
           end;
 
 
+        { check if
+           typeinfo(<type1>)=/<>typeinfo(<type2>)
+          can be evaluated at compile time
+        }
+        lefttarget:=actualtargetnode(@left)^;
+        righttarget:=actualtargetnode(@right)^;
+        if (nodetype in [equaln,unequaln]) and (lefttarget.nodetype=inlinen) and (righttarget.nodetype=inlinen) and
+          (tinlinenode(lefttarget).inlinenumber=in_typeinfo_x) and (tinlinenode(righttarget).inlinenumber=in_typeinfo_x) and
+          (tinlinenode(lefttarget).left.nodetype=typen) and (tinlinenode(righttarget).left.nodetype=typen) then
+          begin
+            case nodetype of
+              equaln:
+                result:=cordconstnode.create(ord(ttypenode(tinlinenode(lefttarget).left).resultdef=ttypenode(tinlinenode(righttarget).left).resultdef),bool8type,false);
+              unequaln:
+                result:=cordconstnode.create(ord(ttypenode(tinlinenode(lefttarget).left).resultdef<>ttypenode(tinlinenode(righttarget).left).resultdef),bool8type,false);
+              else
+                Internalerror(2020092901);
+            end;
+            exit;
+          end;
+
         { slow simplifications }
         { slow simplifications }
         if cs_opt_level2 in current_settings.optimizerswitches then
         if cs_opt_level2 in current_settings.optimizerswitches then
           begin
           begin

+ 21 - 0
tests/webtbs/tw30260.pp

@@ -0,0 +1,21 @@
+program test;
+
+// {$mode ObjFPC}
+{$mode Delphi}
+//{$mode DelphiUnicode}
+
+const
+  b1 = TypeInfo(String)=TypeInfo(RawByteString);
+  b2 = TypeInfo(NativeInt)=TypeInfo(NativeInt);
+
+begin
+  if TypeInfo(String)=TypeInfo(RawByteString) then
+    writeln('equal')
+  else
+    writeln('not equal');
+
+  if TypeInfo(NativeInt)=TypeInfo(NativeInt) then
+    writeln('equal')
+  else
+    writeln('not equal');
+end.