Size Of Objects - Revisited_(re)

Sat, 9 Aug 1997 11:09:51 +0200 (MEST)


According to Bernhard Tschirren:
> You cannot use SizeOf with an object TYPE. See test program below:
> [...]

Now you can. :-)  Diff below.

> Sayonara

Do swidanya,

    Peter

 Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
 maintainer GNU Pascal [970714] - http://home.pages.de/~gnu-pascal/ [970125]

8< ---------------------------------------------------------------------------
--- ../../gpc-970806/p/parse.y  Wed Aug  6 14:47:15 1997
+++ parse.y     Sat Aug  9 11:30:51 1997
@@ -5238,14 +5240,30 @@
                      && DECL_BIT_FIELD (TREE_OPERAND ($3, 1)))
                    error ("`SizeOf' applied to a packed record field");

+                 /* Now $3 is either a variable access or a type declaration.
+                  * In both cases, TREE_TYPE ($3) carries the actual type.
+                  */
                  if (PASCAL_TYPE_OBJECT (TREE_TYPE ($3)))
                    {
                      /* Read the size of the object at run time from the VMT.
                       */
-                     tree vmt = build_component_ref ($3,
-                                                     get_identifier ("vmt"));
-                     $$ = build_component_ref (build_indirect_ref (vmt,
-                                                                   "`SizeOf'"),
+                     tree vmt;
+                     if (TREE_CODE ($3) == TYPE_DECL)
+                       {
+                         char *name = concat ("", "vmt_", IDENTIFIER_POINTER
(
+                                            TYPE_LANG_NAME (TREE_TYPE
($3))));
+                         vmt = lookup_name (get_identifier (name));
+                         if (! vmt)
+                           abort ();
+                         free (name);
+                       }
+                     else
+                       {
+                         vmt = build_component_ref ($3,
+                                                    get_identifier ("vmt"));
+                         vmt = build_indirect_ref (vmt, "`SizeOf'");
+                       }
+                     $$ = build_component_ref (vmt,
                                                get_identifier
("object_size"));
                    }
                  else


Peter Gerwinski (peter@agnes.dida.physik.NO-SPAM-PLEASE.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es