Bläddra i källkod

* (finally) fixed tests/test/trangeob.pp

git-svn-id: trunk@5434 -
Jonas Maebe 18 år sedan
förälder
incheckning
c0d46e65ee
1 ändrade filer med 30 tillägg och 3 borttagningar
  1. 30 3
      compiler/ncnv.pas

+ 30 - 3
compiler/ncnv.pas

@@ -1453,6 +1453,9 @@ implementation
         aprocdef : tprocdef;
         aprocdef : tprocdef;
         eq : tequaltype;
         eq : tequaltype;
         cdoptions : tcompare_defs_options;
         cdoptions : tcompare_defs_options;
+        newblock: tblocknode;
+        newstatement: tstatementnode;
+        tempnode: ttempcreatenode;
       begin
       begin
         result:=nil;
         result:=nil;
         resultdef:=totypedef;
         resultdef:=totypedef;
@@ -1670,13 +1673,37 @@ implementation
                            end;
                            end;
 
 
                          { Add runtime check? }
                          { Add runtime check? }
-                         if (cs_check_object in current_settings.localswitches) then
+                         if (cs_check_object in current_settings.localswitches) and
+                            not(nf_internal in flags) then
                            begin
                            begin
                              { we can translate the typeconvnode to 'as' when
                              { we can translate the typeconvnode to 'as' when
                                typecasting to a class or interface }
                                typecasting to a class or interface }
-                             hp:=casnode.create(left,cloadvmtaddrnode.create(ctypenode.create(resultdef)));
+                             { we need to make sure the result can still be
+                               passed as a var parameter                    }
+                             newblock:=internalstatements(newstatement);
+                             if (valid_for_var(left,false)) then
+                               begin
+                                 tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
+                                 addstatement(newstatement,tempnode);
+                                 addstatement(newstatement,cassignmentnode.create(
+                                   ctemprefnode.create(tempnode),
+                                   caddrnode.create_internal(left)));
+                                 left:=ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),left.resultdef);
+                               end
+                             else
+                               begin
+                                 tempnode:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,true);
+                                 addstatement(newstatement,tempnode);
+                                 addstatement(newstatement,cassignmentnode.create(
+                                   ctemprefnode.create(tempnode),
+                                   left));
+                                 left:=ctemprefnode.create(tempnode);
+                               end;
+                             addstatement(newstatement,casnode.create(left.getcopy,cloadvmtaddrnode.create(ctypenode.create(resultdef))));
+                             addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
+                             addstatement(newstatement,ctypeconvnode.create_internal(left,resultdef));
                              left:=nil;
                              left:=nil;
-                             result:=hp;
+                             result:=newblock;
                              exit;
                              exit;
                            end;
                            end;
                        end
                        end