Browse Source

+ hooks for target-specific handling of explicit type conversions and
as-nodes (required for JVM target: bit pattern reinterpretations
have to be handled via conversion because of type safety reasons,
and as-nodes will also have to be able to handled class<->dynarray
checks/conversions)

git-svn-id: branches/jvmbackend@18375 -

Jonas Maebe 14 years ago
parent
commit
8643ab7905
1 changed files with 31 additions and 2 deletions
  1. 31 2
      compiler/ncnv.pas

+ 31 - 2
compiler/ncnv.pas

@@ -88,6 +88,7 @@ interface
           function typecheck_interface_to_variant : tnode;
           function typecheck_interface_to_variant : tnode;
           function typecheck_array_2_dynarray : tnode;
           function typecheck_array_2_dynarray : tnode;
        protected
        protected
+          function target_specific_explicit_typeconv: tnode;virtual;
           function first_int_to_int : tnode;virtual;
           function first_int_to_int : tnode;virtual;
           function first_cstring_to_pchar : tnode;virtual;
           function first_cstring_to_pchar : tnode;virtual;
           function first_cstring_to_int : tnode;virtual;
           function first_cstring_to_int : tnode;virtual;
@@ -190,6 +191,10 @@ interface
 
 
        { common functionality of as-nodes and is-nodes }
        { common functionality of as-nodes and is-nodes }
        tasisnode = class(tbinarynode)
        tasisnode = class(tbinarynode)
+          protected
+           { if non-standard usage of as-nodes is possible, targets can override
+           this method and return true in case the conditions are fulfilled }
+          function target_specific_typecheck: boolean;virtual;
          public
          public
           function pass_typecheck:tnode;override;
           function pass_typecheck:tnode;override;
        end;
        end;
@@ -1568,6 +1573,12 @@ implementation
       end;
       end;
 
 
 
 
+    function ttypeconvnode.target_specific_explicit_typeconv: tnode;
+      begin
+        result:=nil;
+      end;
+
+
     procedure copyparasym(p:TObject;arg:pointer);
     procedure copyparasym(p:TObject;arg:pointer);
       var
       var
         newparast : TSymtable absolute arg;
         newparast : TSymtable absolute arg;
@@ -1982,7 +1993,15 @@ implementation
                                  (left.nodetype=derefn)
                                  (left.nodetype=derefn)
                                 )
                                 )
                                ) then
                                ) then
-                           CGMessage2(type_e_illegal_type_conversion,left.resultdef.typename,resultdef.typename);
+                           CGMessage2(type_e_illegal_type_conversion,left.resultdef.typename,resultdef.typename)
+                         else
+                           begin
+                             { perform target-specific explicit typecast
+                               checks }
+                             result:=target_specific_explicit_typeconv;
+                             if assigned(result) then
+                               exit;
+                           end;
                        end;
                        end;
                    end
                    end
                   else
                   else
@@ -3313,6 +3332,12 @@ implementation
                                 TASNODE
                                 TASNODE
 *****************************************************************************}
 *****************************************************************************}
 
 
+    function tasisnode.target_specific_typecheck: boolean;
+      begin
+        result:=false;
+      end;
+
+
     function tasisnode.pass_typecheck: tnode;
     function tasisnode.pass_typecheck: tnode;
       var
       var
         hp : tnode;
         hp : tnode;
@@ -3327,7 +3352,11 @@ implementation
         if codegenerror then
         if codegenerror then
           exit;
           exit;
 
 
-        if (right.resultdef.typ=classrefdef) then
+        if target_specific_typecheck then
+          begin
+            // ok
+          end
+        else if (right.resultdef.typ=classrefdef) then
           begin
           begin
             { left maybe an interface reference }
             { left maybe an interface reference }
             if is_interfacecom(left.resultdef) then
             if is_interfacecom(left.resultdef) then