Gale Paeper wrote:
In case it helps, CodeWarrior Pascal (as well as MPW Pascal) also supports a forward directive declaration form for objects, i.e,:
MyObject = object; forward;
A test program using a slightly modified expample from CodeWarrior Pascal's documentation:
program ForwardObjectTest;
BTW, Waldek, are you collecting these test programs (also Peter's) and putting them into your patch (now or later), so we'll have them in place when integrating the patch? (As far as we decide to support the features, of course.)
The forward object type declaration must have a complete type declaration in the same type declaration part (like Pascal's requirement for pointer types). The commented out var declaration part and type keyword is what I used to test that requirement. Uncomment that part and you get:
Error : unresolved forward class reference to 'objA' ForwardObjectTest.p line 11 var
Good (in accordance with OOE, except for the syntax).
CW takes the approach that any unknown type identifier it sees in a type definition is pointer sized (a pointer or object) and must be defined by the end of the type block.
type rec = record a: UndefinedA; b: UndefinedB; end; UndefinedA = ^Integer; UndefinedB = object end;
Note that UndefinedA = UInt32 is not legal, it must be a pointer or object.
It's actually not a bad methodology and makes it easy to write data structures that is self or mutually referential, but it does not add anything over pre defining pointers or object names as EP/Delphi.
Does it allow the same in nested scopes? AFAIU objects are not allowed in nested scopes, but pointers still make sense. Also, what happens if the name is a predefined type (or a name declared in outer scope)? Normal Pascal rules are that the new definition should be used (even if the definition follows use), are they obeyed?
CodeWarrior Pascal doesn't correctly handle nested scope forward pointer redeclarations and you need some additional erroneous code construct (such as a type mismatch) for the compiler to report an error. A snippet inserted into the above test program:
type UndefinedA = ^Integer;
procedure test;
type rec = record a: UndefinedA; end; UndefinedA = ^boolean;
var testrec : rec; begin new(testrec.a); testrec.a^ := true; end;
yields:
Error : type mismatch ForwardObjectTest.p line 36 testrec.a^ := true;
which indicates the compiler is incorrectly using the outer scope declaration for UndefinedA when compiling the inner scope rec type.
In fairness, I'll note CodeWarrior Pascal isn't the only Pascal compiler I've used that has problems in correctly handling nested scope use before redeclaration cases.
Indeed, it's a nasty thing to detect. I finally did in in GPC recently (az25.pas, fjf1059*.pas), but it was a bit of effort ...
Frank