Prechádzať zdrojové kódy

* rework the checks for a helper's extended def to be a class so that it can be more easily extended by other objecttypes

git-svn-id: trunk@37022 -
svenbarth 8 rokov pred
rodič
commit
236a9b0aa5

+ 13 - 2
compiler/htypechk.pas

@@ -2197,7 +2197,12 @@ implementation
         while assigned(structdef) do
          begin
            { first search in helpers for this type }
-           if (is_class(structdef) or is_record(structdef))
+           if ((structdef.typ=recorddef) or
+                 (
+                   (structdef.typ=objectdef) and
+                   (tobjectdef(structdef).objecttype in objecttypes_with_helpers)
+                 )
+               )
                and searchhelpers then
              begin
                if search_last_objectpascal_helper(structdef,nil,helperdef) then
@@ -2235,7 +2240,13 @@ implementation
                  break;
              end;
            if is_objectpascal_helper(structdef) and
-              (tobjectdef(structdef).extendeddef.typ in [recorddef,objectdef]) then
+              (
+                (tobjectdef(structdef).extendeddef.typ=recorddef) or
+                (
+                  (tobjectdef(structdef).extendeddef.typ=objectdef) and
+                  (tobjectdef(tobjectdef(structdef).extendeddef).objecttype in objecttypes_with_helpers)
+                )
+              ) then
              begin
                { remember the first extendeddef of the hierarchy }
                if not assigned(extendeddef) then

+ 5 - 3
compiler/pdecobj.pas

@@ -705,7 +705,7 @@ implementation
               filedef,classrefdef,abstractdef,forwarddef,formaldef]) or
               (
                 (def.typ=objectdef) and
-                (tobjectdef(def).objecttype<>odt_class)
+                not (tobjectdef(def).objecttype in objecttypes_with_helpers)
               ) then
             begin
               Message1(type_e_type_not_allowed_for_type_helper,def.typename);
@@ -729,7 +729,8 @@ implementation
         begin
           if (def.typ<>errordef) and assigned(current_objectdef.childof) then
             begin
-              if not is_class(current_objectdef.childof.extendeddef) then
+              if (current_objectdef.childof.extendeddef.typ<>objectdef) or
+                 not (tobjectdef(current_objectdef.childof.extendeddef).objecttype in objecttypes_with_helpers) then
                 Internalerror(2011021101);
               if not def_is_related(def,current_objectdef.childof.extendeddef) then
                 begin
@@ -795,7 +796,8 @@ implementation
               ht_type:
                 begin
                   validate_extendeddef_typehelper(hdef);
-                  if is_class(hdef) then
+                  if (hdef.typ=objectdef) and
+                      (tobjectdef(hdef).objecttype in objecttypes_with_helpers) then
                     check_inheritance_class_helper(hdef)
                   else
                     { a type helper must extend the same type as the

+ 2 - 0
compiler/symconst.pas

@@ -889,6 +889,8 @@ inherited_objectoptions : tobjectoptions = [oo_has_virtual,oo_has_private,oo_has
      default_class_type=odt_javaclass;
 {$endif not jvm}
 
+     objecttypes_with_helpers=[odt_class];
+
 { !! Be sure to keep these in sync with ones in rtl/inc/varianth.inc }
       varempty = 0;
       varnull = 1;

+ 1 - 1
compiler/symtable.pas

@@ -3473,7 +3473,7 @@ implementation
               begin
                 { search for a class helper method first if this is an Object
                   Pascal class and we haven't yet found a helper symbol }
-                if is_class(classh) and
+                if (classh.objecttype in objecttypes_with_helpers) and
                     (ssf_search_helper in flags) then
                   begin
                     result:=search_objectpascal_helper(classh,contextclassh,s,srsym,srsymtable);