RE: gdb-patches RFA: Fix pascal behavior for class fields

"Pierre Muller" <[email protected]>
Newsgroups gmane.comp.compilers.gpc
Message-ID <[email protected]>
 Hi Peter,

> >   The problem is that GPC and Free Pascal support several
> >
> > pascal 'dialects'. But this requires command line options.
> >
> >
> >
> >   The -Mobjfpc option is required for Free Pascal compiler
> >
> > to understand class type definition, but is rejected in default mode.
> >
> >
> >
> >   I expect GNU GPC to also reject class in 'normal' mode...
> >
> > Maybe someone on the gpc mailing list knows if classes are supported
> >
> > by GPC and if it requires a special compiler option.
> >
> >
> >
> > Pierre Muller
> >
> >
> >
> > FYI: Here is the example code that is included in the bug report.
> >
> >
> >
> > $ cat ~/pas/test/test-class-pascal.pas
> >
> >
> >
> > type
> >
> >   TA = class
> >
> >   public
> >
> >   x, y : integer;
> >
> >   constructor Create;
> >
> >   function check(b : TA) : boolean;
> >
> >   destructor Done; virtual;
> >
> > end;
> >
> >
> >
> > constructor TA.Create;
> >
> > begin
> >
> >   x:=-1;
> >
> >   y:=-1;
> >
> > end;
> >
> >
> >
> > destructor TA.Done;
> >
> > begin
> >
> > end;
> >
> >
> >
> > function TA.check (b : TA) : boolean;
> >
> > begin
> >
> >   check:=(x < b.x);
> >
> > end;
> >
> >
> >
> >
> >
> >
> >
> > var
> >
> >   a, b : TA;
> >
> >
> >
> > begin
> >
> >   a:=TA.Create;
> >
> >   b:=TA.Create;
> >
> >   a.x := 67;
> >
> >   a.y := 33;
> >
> >   a.check (b);
> >
> > end.
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > Gpc mailing list
> > [email protected]
> > https://www.g-n-u.de/mailman/listinfo/gpc
> 
> It compiles if you put a 'program' statement at the beginning, and
> change a.check(b) to assign the function result,
  I tried this,
but here is what I get after your changes:
$ gpc  test-class-pascal.pas
test-class-pascal.pas:4: error: undeclared identifier `class' (first use in
this routine)
test-class-pascal.pas:4: error:  (Each undeclared identifier is reported
only once
test-class-pascal.pas:4: error:  for each routine it appears in.)
test-class-pascal.pas:6: error: undeclared identifier `x' (first use in this
routine)
test-class-pascal.pas:6: error: syntax error before `,'

Pierre@d620-muller ~/pas/test
$ gpc --version
gpc 20050331, based on gcc-3.4.4 (cygming special, gdc 0.12, using dmd
0.125)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Is it because I am using version 3.4.4?
The problem is that I did not find any system 
with easy installation of GPC,
and finally tested it on an old Cygwin installation
which had GPC, but it's version 3.4.4

> ie as
> 
> 
> VAR OK : Boolean;
> ...
> OK := a.check(b);
> 
> 
> No special command line switches are needed.
> 
> 
> 
> Program test;
> 
> type
>   TA =
>   class
>     public
>       x, y : integer;
>     constructor Create;
>     function check(b : TA) : boolean;
>     destructor Done; virtual;
>  end;
> 
> constructor TA.Create;
> begin
>   x:=-1;
>   y:=-1;
> end;
> 
> destructor TA.Done;
> begin
> end;
> 
> function TA.check (b : TA) : boolean;
> begin
>   check:=(x < b.x);
> end;
> 
> var
>   a, b : TA;
>   OK : boolean;
> 
> begin
>   a:=TA.Create;
>   b:=TA.Create;
>   a.x := 67;
>   a.y := 33;
>   OK := a.check (b);
> end.

 Anyhow, by using objects instead of classes, I was able to compile the
modified program,
and it turns out that GPC is using 'Self' for the hidden 
object name for stabs debugging, so that the problem probably does not apply
to
GPC compiled sources.

Thanks Peter


Pierre Muller

_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.