[cfe-dev] [PATCH]: Parsing for C++ classes
Argiris Kirtzidis
akyrtzi at gmail.com
Fri Jun 20 07:14:22 PDT 2008
I've attached patches against the latest trunk of Parser and Sema
changes for C++ classes support.
The Parser->Sema diff for "cxx-sema.patch" was kinda manually created to
make reviewing just the Sema changes easier, so you cannot apply it. If
you want to try out Parser+Sema changes you need to apply the
"cxx-parser-sema.patch", which contains the unified diff.
Here's a few more details in addition to the summary for the parser
changes which I mentioned in the previous post:
When the parser encounters an inline method definition, it lexes and
stores its tokens so that it can parse it just after the parsing of the
topmost class. I.e:
class C {
void m1() {}
class NC {
void m2() {}
};
};
The parsing of the above class is something like this:
class C {
void m1();
class NC {
void m2();
};
};
void m1() {} // of class C
void m2() {} // of class C::NC
For local classes, it would be like a function is defined inside another
function. The Action module is supposed to be aware of this and allow it
if the function being defined is an inline class method.
-Argiris
Argiris Kirtzidis wrote:
> Hi,
>
> The attached patch adds C++ classes support to the Parser. I'll
> provide the Sema support in a separate patch.
> Here's what can be parsed:
>
> -Access specifiers
> -method declarations and inline method definitions
> -static members
> -typedefs, enums, and nested classes
> -'this' keyword
>
> Inline method definitions are lexed and their tokens stored for later
> parsing, after the class is complete.
>
> This test is representative of the new features:
>
> // RUN: clang -parse-noop -verify %s
> class C {
>
> protected:
> typedef int A,B;
> static int sf(), u;
>
> auto int sx; // expected-error {{error: storage class specified for a
> member declaration}}
> register int sy; // expected-error {{error: storage class specified
> for a member declaration}}
> extern int sz; // expected-error {{error: storage class specified for
> a member declaration}}
>
> struct S {};
> enum {};
> int; // expected-error {{error: declaration does not declare anything}}
>
> int b : 1, w : 2;
> typedef int E : 1; // expected-error {{error: cannot declare 'E' to
> be a bit-field type}}
> static int sb : 1; // expected-error {{error: static member 'sb'
> cannot be a bit-field}}
>
> int i = 0; // expected-error {{error: member 'i' can be initialized
> only if it is a static const integral data member}}
>
> public:
> void m() {
> int l = 2;
> }
>
> private:
> int x,f(),y,g();
> };
>
> int x = this; // expected-error {{error: invalid use of 'this' at top
> level}}
>
>
>
> -Argiris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cxx-parser.patch
Type: text/x-diff
Size: 36715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080620/00995e65/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cxx-parser-sema.patch
Type: text/x-diff
Size: 52044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080620/00995e65/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cxx-sema.patch
Type: text/x-diff
Size: 16990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080620/00995e65/attachment-0002.patch>
More information about the cfe-dev
mailing list