Context-awareness in Cpp parser
David Nolden
david.nolden.kdevelop at art-master.de
Tue May 31 17:29:49 UTC 2011
2011/5/31 Milian Wolff <mail at milianw.de>:
> David Nolden, 31.05.2011:
>> 2011/5/31 Milian Wolff <mail at milianw.de>:
>> > Hey all, esp. David :)
>> >
>> > While hacking away at C++0x support, I tripped over the following issue:
>> > The parser sometimes seems to ignore some rules / does not take the
>> > context into account properly. One case which I'm hit by right now is
>> > parseDeclarator. It supports bitfields everywhere, even outside of
>> > struct/class contexts.
>> >
>> > On one hand this can lead to false-positives (the following is accepted
>> > as valid by our parser):
>> >
>> > int main() {
>> > int i : 1;
>> > return 0;
>> > }
>> >
>> > even though it will not compile. Furthermore it makes me jump through
>> > hoops when trying to reuse that function in implementing range-based for
>> > (as there the colon has a different meaning).
>> >
>> > So what would you guys suggest - should I try to add rough context
>> > sensitivity?
>>
>> Yes, I guess there is no other way. You might check the C++
>> specification to see where bit-fields are allowed (I guess only in
>> class/struct/union member declarations), and then give a "bool
>> isClassMember" parameter to parseDeclarator, or something like that.
>
> Probably I'll pick a member variable as the declarator is only called by
> helper functions itself and I don't want to pollute the signatures. For now I
> did it in a ugly way to get the range-based-for working, only DUChain
> integration is missing there for now.
A member _might_ be problematic in case of recursion, ag. "struct A {
bool b: 1; void test() {" <-- bitfield not allowed here. You would
have to pollute many places with "PushValue"'s.
Greetings, David
More information about the KDevelop-devel
mailing list