[cfe-dev] C++ using-directive parsing
Piotr Rak
piotr.rak at gmail.com
Fri Dec 26 17:01:56 PST 2008
Hi all,
I have played bit with clang, and implemented parsing of C++ using-directive.
I would like to work on Sema support for it too, but I'm still
unfamiliar with project,
and not really sure if I am going in *right* direction. Hints and
comments are highly welcome :)
Attached contains things I have done so far. Before I will continue
adding AST and Sema support,
I would like to explain what in am planing to do, because I might be
missing something.
Using directive basically fits concept of ScopedDecl, but not really
well NamedDecl concept.
It is not really clear, how it should be represented. And ofcourse
lookup will have to deal with it
in special way.
My idea is to represent it as ScopedDecl and introduce special name
(DeclarationNameExtra instance),
shared by all UsingDirectiveDecl's. Those would be added to
DeclContext in which they appear
(in case of namespace only to original namespace). Does it sound sane?
On lookup, list of all namespaces, both introduced directly and
indirectly by using directive
would be build. I belive it would be wise to cache it, which would
introduce another member to DeclContext.
DeclContext should be pretty common citizen in AST, well maybe not in
headers, so it could be some memory
overhead, especially for C. Or Maybe I just worry to early.
There are few possible options to deal with it not increasing size of
DeclContext:
- Add this member to each concrete ScopedDecl in which it may appear,
or even new base class and MI
- (Ab)use DeclContext.LookupPtr structure and associate this list with
special name,
(same as used by UsingDirectiveDecl's?)
- any others?
First is probably more clean, but IMO using directives are not so
often, and it would introduce some
memory overhead for Decl's that don't use it.
Second feels like ugly hack, but it doesn't share this disadvantage
with first, but requires some overhead
(hashtable lookup). Initially I would be in favour of implementing of
second option. There is also FIXME,
that says about need of replacing structure held by LookupPtr, so it
could be smartly abstracted later.
Another minor issue is keeping list of used namespaces up to date,
which probably will require some
knowledge from namespace about its 'users'. Here I would like to
introduce distinction between original-namespace,
and extended-namespace. This not really required, but seems to be good
idea, because original namespace will
have to keep bit more information than extended namespace, later also
things like C++0x
inline namespace/gnu strong-using extension. This could be done same
*transparent* way, that was suggested
by Mr. Douglas Gregor some time ago (strangely couldn't find pointers
to this message now).
I have also attached 'make report' results, since I have noticed
CodeGenObjC/encode-test.m failure,
not introduced by my change. I'am using gentoo gcc-4.3.2 x86 linux.
so it might be compiler issue.
Thanks, Piotr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Initial-Parser-support-for-C-using-directive.patch
Type: text/x-patch
Size: 18880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081227/09bee228/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: make-report-result-r61444.txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081227/09bee228/attachment.txt>
More information about the cfe-dev
mailing list