Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
Patch 3407: correctly parse c++98 enums
thomas:
--- Quote from: MortenMacFly on January 21, 2013, 04:49:25 pm ---
--- Quote from: killerbot on January 21, 2013, 07:33:00 am ---please keep the enum class also working.
--- End quote ---
Dunno what that means?! What class?
--- End quote ---
C++11 strongly typed enumerations: enum class.
killerbot:
I have tested : this patch is NOT acceptable. It breaks C++11 enum classes.
I think it is better to hand this problem over to our CC gurus, and have them, fix it properly.
--- Code: ---#include <iostream>
struct B
{
enum Eb
{
ebAsd1, ebAsd2, ebAsd3,
};
enum{ unnamedEnumerator };
enum class Fruit2
{
Apple,
Strawberry,
Orange,
Cherry
};
};
enum class Fruit
{
Apple,
Strawberry,
Orange,
Cherry
};
enum class Color
{
Red,
Orange,
Green
};
int main()
{
return 0;
}
--- End code ---
Fruit2 is broken, their values end up in the higher scope, which is incorrect. This workaround (patch) should not trigger when enum class.
To which CC guru do we send this ?
oBFusCATed:
--- Quote from: killerbot on January 21, 2013, 08:18:46 pm ---To which CC guru do we send this ?
--- End quote ---
Ollydbg he is the only one:)
Keep in mind that we don't claim support for C++11, also the normal C++98/C style enums are way more common.
The old code worked by chance I suppose. So if you ask me and there are no other blocker it is better.
p2rkw:
How about this:
--- Code: ---Index: src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- src/plugins/codecompletion/parser/parserthread.cpp (wersja 8785)
+++ src/plugins/codecompletion/parser/parserthread.cpp (kopia robocza)
@@ -2263,10 +2282,13 @@
// enums have the following rough definition:
// enum [xxx] { type1 name1 [= 1][, [type2 name2 [= 2]]] };
bool isUnnamed = false;
+ bool isEnumClass = false;
int lineNr = m_Tokenizer.GetLineNumber();
wxString token = m_Tokenizer.GetToken();
- if (token == ParserConsts::kw_class)
+ if (token == ParserConsts::kw_class){
token = m_Tokenizer.GetToken();
+ isEnumClass = true;
+ }
if (token.IsEmpty())
return;
@@ -2357,7 +2379,8 @@
{
Token* lastParent = m_LastParent;
m_LastParent = newEnum;
- DoAddToken(tkEnumerator, token, m_Tokenizer.GetLineNumber());
+ Token* enumerator = DoAddToken(tkEnumerator, token, m_Tokenizer.GetLineNumber());
+ enumerator->m_Scope = isEnumClass ? tsPrivate : tsPublic;
m_LastParent = lastParent;
}
if (peek==ParserConsts::colon)
Index: src/plugins/codecompletion/nativeparser_base.h
===================================================================
--- src/plugins/codecompletion/nativeparser_base.h (wersja 8785)
+++ src/plugins/codecompletion/nativeparser_base.h (kopia robocza)
@@ -396,14 +396,16 @@
// for GenerateResultSet()
bool AddChildrenOfUnnamed(TokenTree* tree, const Token* parent, TokenIdxSet& result)
{
- if (parent->m_TokenKind == tkClass && parent->m_Name.StartsWith(g_UnnamedSymbol))
+ if (((parent->m_TokenKind & (tkClass | tkEnum)) != 0)
+ && parent->m_Name.StartsWith(g_UnnamedSymbol))
{
// add all its children
for (TokenIdxSet::const_iterator it = parent->m_Children.begin();
it != parent->m_Children.end(); ++it)
{
Token* tokenChild = tree->at(*it);
- if (tokenChild)
+ if (tokenChild &&
+ (parent->m_TokenKind == tkClass || tokenChild->m_Scope != tsPrivate))
result.insert(*it);
}
@@ -411,7 +413,25 @@
}
return false;
}
+
+ bool AddChildrenOfEnum(TokenTree* tree, const Token* parent, TokenIdxSet& result)
+ {
+ if (parent->m_TokenKind == tkEnum)
+ {
+ // add all its children
+ for (TokenIdxSet::const_iterator it = parent->m_Children.begin();
+ it != parent->m_Children.end(); ++it)
+ {
+ Token* tokenChild = tree->at(*it);
+ if (tokenChild && tokenChild->m_Scope != tsPrivate)
+ result.insert(*it);
+ }
+ return true;
+ }
+ return false;
+ }
+
// for GenerateResultSet()
bool MatchText(const wxString& text, const wxString& target, bool caseSens, bool isPrefix)
{
Index: src/plugins/codecompletion/nativeparser_base.cpp
===================================================================
--- src/plugins/codecompletion/nativeparser_base.cpp (wersja 8785)
+++ src/plugins/codecompletion/nativeparser_base.cpp (kopia robocza)
@@ -1318,7 +1318,11 @@
if (!token)
continue;
if ( !AddChildrenOfUnnamed(tree, token, result) )
+ {
result.insert(*it);
+ AddChildrenOfEnum(tree, token, result);
+ }
+
}
tree->RecalcInheritanceChain(parent);
@@ -1334,7 +1338,10 @@
if (!token)
continue;
if ( !AddChildrenOfUnnamed(tree, token, result) )
+ {
result.insert(*it2);
+ AddChildrenOfEnum(tree, token, result);
+ }
}
}
}
--- End code ---
oBFusCATed:
p2rkw: Can you try to add some tests? See Morten's comment.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version