Prof A Olowofoyeku wrote:
> I converted one small project from using OBJECTs to using CLASSes.
>
> The test program compiles and runs okay under Delphi, Virtual Pascal,
> and FreePascal.
>
> The new GPC snapshot comes up with some compilation errors. You can see
> the error log in the attached zip file. Also in the zip file are the
> sources, and the test program's outputs when compiled with Delphi 7
> (d7.txt), FreePascal (fpc.txt), and Virtual Pascal (vp.txt).
>
: baseobj.pas:52: method `init', overrides parent method
: baseobj.pas:253: method `init', overrides parent method
The two errors above (and more in the following) are because GPC is more
strict by default. You can write:
CONSTRUCTOR init ( Owner : TClass ); override;
or
CONSTRUCTOR init ( Owner : TClass ); reintroduce;
to specify the intent (to say the truth both mean the same for static
methods). Or you may use `-fdelphi-method-shadowing' to silently
accept your original code.
: baseobj.pas: In constructor `TBaseList.init':
: baseobj.pas:437: expression used as a statement
: baseobj.pas: In destructor `TBaseList.done':
: baseobj.pas:454: Delphi/OOE continuing destructor activation unsupported
The patch below should fix those (with the patch I was able to compile
your test program and got the same results as in enclsed output files)
Index: p/objects.c
===================================================================
RCS file: /mn/a8/cvsroot/gpc/p/objects.c,v
retrieving revision 1.4
diff -u -r1.4 objects.c
--- p/objects.c 4 Nov 2005 01:00:21 -0000 1.4
+++ p/objects.c 5 Nov 2005 18:01:27 -0000
@@ -145,11 +145,18 @@
if (TREE_CODE (obj) == TYPE_DECL)
{
tree cmeth = current_method ();
- if (PASCAL_CONSTRUCTOR_METHOD (fun)
- && PASCAL_TYPE_CLASS (TREE_TYPE (obj)))
+ int is_class = PASCAL_TYPE_CLASS (TREE_TYPE (obj));
+ if (PASCAL_CONSTRUCTOR_METHOD (fun) && is_class)
constructor_call = tree_cons (NULL_TREE,
obj, tree_cons (NULL_TREE, cref, args));
+ if (is_class && PASCAL_DESTRUCTOR_METHOD (fun) &&
+ (!cmeth || !PASCAL_DESTRUCTOR_METHOD (cmeth)))
+ {
+ error("Delphi/OOE continuing destructor activation outside a destructor");
+ return error_mark_node;
+ }
+
if (!cmeth)
/* Somebody is looking for the address of this method. Give them the FUNCTION_DECL. */
{
@@ -173,9 +180,10 @@
return error_mark_node;
obj = build_indirect_ref (lookup_name (self_id), "`Self' reference");
is_virtual = 0;
+ is_destructor = 0;
}
-
- is_destructor = PASCAL_DESTRUCTOR_METHOD (fun)
+ else
+ is_destructor = PASCAL_DESTRUCTOR_METHOD (fun)
&& TYPE_POINTER_TO (TREE_TYPE (obj))
&& PASCAL_TYPE_CLASS (TYPE_POINTER_TO (TREE_TYPE (obj)));
@@ -218,14 +226,8 @@
tree vobj;
gcc_assert (TREE_CODE (obj) == INDIRECT_REF);
vobj = TREE_OPERAND (obj, 0);
- if (!cmeth || !PASCAL_DESTRUCTOR_METHOD (cmeth))
- return build_predef_call (p_Dispose, tree_cons (NULL_TREE, vobj,
+ return build_predef_call (p_Dispose, tree_cons (NULL_TREE, vobj,
build_tree_list (NULL_TREE, fun)));
- else
- {
- error("Delphi/OOE continuing destructor activation unsupported");
- return error_mark_node;
- }
}
return fun;
Index: p/statements.c
===================================================================
RCS file: /mn/a8/cvsroot/gpc/p/statements.c,v
retrieving revision 1.3
diff -u -r1.3 statements.c
--- p/statements.c 28 Oct 2005 20:00:56 -0000 1.3
+++ p/statements.c 5 Nov 2005 17:33:00 -0000
@@ -1083,7 +1083,10 @@
function_called = 1;
}
if (TREE_CODE (t) == PASCAL_CONSTRUCTOR_CALL)
- t = convert (void_type_node, TREE_OPERAND (t, 1));
+ {
+ t = convert (void_type_node, TREE_OPERAND (t, 1));
+ function_called = 1;
+ }
if (!EM (t))
{
if (PASCAL_TREE_IGNORABLE (t))
--
Waldek Hebisch
hebisch(a)math.uni.wroc.pl