Topic: Parsing member function bodies within a class declaration.
Author: Theo Norvell <theo@engr.mun.ca>
Date: Wed, 14 Feb 2001 21:16:06 GMT Raw View
Hi. In the ARM, Stroustrup and Ellis are pretty clear that
member function definitions that occur within a class
declaration should appear to be parsed and analysed at the end of
the class declaration. (See section 9.3.2) E.g.
class Foo
{ public : int bar() { MemberType i = 41 ; return ++i ; }
private : typedef int MemberType ;
} ;
is perfectly legitimate. It is as if the compiler had rewritten
the class as:
class Foo
{ public : int bar() ;
private : typedef int MemberType ;
} ;
inline Foo::bar() { MemberType i = 41 ; return ++i ; }
Using this idea, a compiler for C++ can clearly be one-pass, as long
as it saves the tokens of the function bodies and parses those bodies
right after the end of the outermost class declaration containing the
function.
In the ISO standard, I can't seem to find a similar statement about
rewriting. Instead there is a somewhat confusing (to me, at least)
section on class scope (section 3.3.6).
I'm currently planning a front-end for a C++ subset interpreter.
My questions are:
--Does the ISO standard preclude the rewriting strategy
suggested by Stroustrup and Ellis?
--What exactly is the difference between the ISO standard
and the ARM on this point?
--Is there any other reason not to compile C++ in one-pass?
--The C standard came with a lovely companion called "the
rationale".
Is there a similar rationale for the ISO standard?
Thanks in advance for any light you can shed on this.
Cheers,
Theodore Norvell
(theo@engr.mun.ca)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Ron Natalie <ron@spamcop.net>
Date: Wed, 14 Feb 2001 23:35:05 GMT Raw View
Theo Norvell wrote:
>
> In the ISO standard, I can't seem to find a similar statement about
> rewriting. Instead there is a somewhat confusing (to me, at least)
> section on class scope (section 3.3.6).
3.3.6 provides the rule that says that the full class scope extends
inside member function bodies. It doesn't say how you have to
achieve this. You could do it as implied by the ARM, or you could
make multiple passes (even the ARM method is technically another
pass, you're squirrelling a way some unprocessed input for later
compilation).
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]