diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 3c5feb69..2b90f899 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1620,6 +1620,7 @@ bool CppParser::checkForKeyword(KeywordType& keywordType) case KeywordType::For: case KeywordType::Public: case KeywordType::Private: + case KeywordType::Struct: case KeywordType::Enum: case KeywordType::Inline: case KeywordType::Namespace: @@ -1674,16 +1675,21 @@ bool CppParser::checkForStructs(KeywordType keywordType) || keywordType == KeywordType::Public || keywordType == KeywordType::Private) dis = 1; - if (mIndex >= mTokenizer.tokenCount() - 2 - dis) - return false; - QString word = mTokenizer[mIndex+dis]->text; - int keyLen = calcKeyLenForStruct(word); - if (keyLen<0) - return false; - bool result = (word.length() == keyLen) || isSpaceChar(word[keyLen]) - || (word[keyLen] == '['); +// int keyLen = calcKeyLenForStruct(word); +// if (keyLen<0) +// return false; +// bool result = (word.length() == keyLen) || isSpaceChar(word[keyLen]) +// || (word[keyLen] == '['); + bool result; + if (dis!=0) { + result = (mCppKeywords.value(mTokenizer[mIndex+dis]->text,KeywordType::None)==KeywordType::Struct); + } else { + result = (keywordType==KeywordType::Struct); + } if (result) { + if (mIndex >= mTokenizer.tokenCount() - 2 - dis) + return false; if (mTokenizer[mIndex + 2+dis]->text[0] != ';') { // not: class something; int i = mIndex+dis +1; // the check for ']' was added because of this example: @@ -1735,11 +1741,13 @@ bool CppParser::checkForTypedefStruct() //should call CheckForTypedef first!!! if (mIndex+1 >= mTokenizer.tokenCount()) return false; - QString word = mTokenizer[mIndex + 1]->text; - int keyLen = calcKeyLenForStruct(word); - if (keyLen<0) - return false; - return (word.length() == keyLen) || isSpaceChar(word[keyLen]) || word[keyLen]=='['; + return (mCppKeywords.value(mTokenizer[mIndex+1]->text,KeywordType::None)==KeywordType::Struct); + +// QString word = mTokenizer[mIndex + 1]->text; +// int keyLen = calcKeyLenForStruct(word); +// if (keyLen<0) +// return false; +// return (word.length() == keyLen) || isSpaceChar(word[keyLen]) || word[keyLen]=='['; } bool CppParser::checkForUsing(KeywordType keywordType) @@ -5260,15 +5268,15 @@ QSet CppParser::calculateFilesToBeReparsed(const QString &fileName) return result; } -int CppParser::calcKeyLenForStruct(const QString &word) -{ - if (word.startsWith("struct")) - return 6; - else if (word.startsWith("class") - || word.startsWith("union")) - return 5; - return -1; -} +//int CppParser::calcKeyLenForStruct(const QString &word) +//{ +// if (word.startsWith("struct")) +// return 6; +// else if (word.startsWith("class") +// || word.startsWith("union")) +// return 5; +// return -1; +//} void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart) { diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 9f81a57a..18b44201 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -501,7 +501,7 @@ private: void internalInvalidateFile(const QString& fileName); void internalInvalidateFiles(const QSet& files); QSet calculateFilesToBeReparsed(const QString& fileName); - int calcKeyLenForStruct(const QString& word); +// int calcKeyLenForStruct(const QString& word); // { // function GetClass(const Phrase: AnsiString): AnsiString; // function GetMember(const Phrase: AnsiString): AnsiString; diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index ecbca316..5bbd3fd5 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -185,11 +185,13 @@ void initParser() CppKeywords.insert("extern",KeywordType::None); // handled elsewhere - CppKeywords.insert("class",KeywordType::None); CppKeywords.insert("operator",KeywordType::None); CppKeywords.insert("static",KeywordType::None); - CppKeywords.insert("struct",KeywordType::None); - CppKeywords.insert("union",KeywordType::None); + + //struct/class/union + CppKeywords.insert("class",KeywordType::Struct); + CppKeywords.insert("struct",KeywordType::Struct); + CppKeywords.insert("union",KeywordType::Struct); CppKeywords.insert("for",KeywordType::For); diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index 5b6175b8..c8b46e31 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -69,6 +69,7 @@ enum class KeywordType { Private, Protected, Friend, + Struct, // struct/class/enum Enum, //enum Inline, // inline Namespace, //namespace