refactor check for struct/class/union defines in the parser
This commit is contained in:
parent
16258cc015
commit
b246e3d145
|
@ -1620,6 +1620,7 @@ bool CppParser::checkForKeyword(KeywordType& keywordType)
|
||||||
case KeywordType::For:
|
case KeywordType::For:
|
||||||
case KeywordType::Public:
|
case KeywordType::Public:
|
||||||
case KeywordType::Private:
|
case KeywordType::Private:
|
||||||
|
case KeywordType::Struct:
|
||||||
case KeywordType::Enum:
|
case KeywordType::Enum:
|
||||||
case KeywordType::Inline:
|
case KeywordType::Inline:
|
||||||
case KeywordType::Namespace:
|
case KeywordType::Namespace:
|
||||||
|
@ -1674,16 +1675,21 @@ bool CppParser::checkForStructs(KeywordType keywordType)
|
||||||
|| keywordType == KeywordType::Public
|
|| keywordType == KeywordType::Public
|
||||||
|| keywordType == KeywordType::Private)
|
|| keywordType == KeywordType::Private)
|
||||||
dis = 1;
|
dis = 1;
|
||||||
if (mIndex >= mTokenizer.tokenCount() - 2 - dis)
|
// int keyLen = calcKeyLenForStruct(word);
|
||||||
return false;
|
// if (keyLen<0)
|
||||||
QString word = mTokenizer[mIndex+dis]->text;
|
// return false;
|
||||||
int keyLen = calcKeyLenForStruct(word);
|
// bool result = (word.length() == keyLen) || isSpaceChar(word[keyLen])
|
||||||
if (keyLen<0)
|
// || (word[keyLen] == '[');
|
||||||
return false;
|
bool result;
|
||||||
bool result = (word.length() == keyLen) || isSpaceChar(word[keyLen])
|
if (dis!=0) {
|
||||||
|| (word[keyLen] == '[');
|
result = (mCppKeywords.value(mTokenizer[mIndex+dis]->text,KeywordType::None)==KeywordType::Struct);
|
||||||
|
} else {
|
||||||
|
result = (keywordType==KeywordType::Struct);
|
||||||
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
if (mIndex >= mTokenizer.tokenCount() - 2 - dis)
|
||||||
|
return false;
|
||||||
if (mTokenizer[mIndex + 2+dis]->text[0] != ';') { // not: class something;
|
if (mTokenizer[mIndex + 2+dis]->text[0] != ';') { // not: class something;
|
||||||
int i = mIndex+dis +1;
|
int i = mIndex+dis +1;
|
||||||
// the check for ']' was added because of this example:
|
// the check for ']' was added because of this example:
|
||||||
|
@ -1735,11 +1741,13 @@ bool CppParser::checkForTypedefStruct()
|
||||||
//should call CheckForTypedef first!!!
|
//should call CheckForTypedef first!!!
|
||||||
if (mIndex+1 >= mTokenizer.tokenCount())
|
if (mIndex+1 >= mTokenizer.tokenCount())
|
||||||
return false;
|
return false;
|
||||||
QString word = mTokenizer[mIndex + 1]->text;
|
return (mCppKeywords.value(mTokenizer[mIndex+1]->text,KeywordType::None)==KeywordType::Struct);
|
||||||
int keyLen = calcKeyLenForStruct(word);
|
|
||||||
if (keyLen<0)
|
// QString word = mTokenizer[mIndex + 1]->text;
|
||||||
return false;
|
// int keyLen = calcKeyLenForStruct(word);
|
||||||
return (word.length() == keyLen) || isSpaceChar(word[keyLen]) || word[keyLen]=='[';
|
// if (keyLen<0)
|
||||||
|
// return false;
|
||||||
|
// return (word.length() == keyLen) || isSpaceChar(word[keyLen]) || word[keyLen]=='[';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppParser::checkForUsing(KeywordType keywordType)
|
bool CppParser::checkForUsing(KeywordType keywordType)
|
||||||
|
@ -5260,15 +5268,15 @@ QSet<QString> CppParser::calculateFilesToBeReparsed(const QString &fileName)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CppParser::calcKeyLenForStruct(const QString &word)
|
//int CppParser::calcKeyLenForStruct(const QString &word)
|
||||||
{
|
//{
|
||||||
if (word.startsWith("struct"))
|
// if (word.startsWith("struct"))
|
||||||
return 6;
|
// return 6;
|
||||||
else if (word.startsWith("class")
|
// else if (word.startsWith("class")
|
||||||
|| word.startsWith("union"))
|
// || word.startsWith("union"))
|
||||||
return 5;
|
// return 5;
|
||||||
return -1;
|
// return -1;
|
||||||
}
|
//}
|
||||||
|
|
||||||
void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart)
|
void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart)
|
||||||
{
|
{
|
||||||
|
|
|
@ -501,7 +501,7 @@ private:
|
||||||
void internalInvalidateFile(const QString& fileName);
|
void internalInvalidateFile(const QString& fileName);
|
||||||
void internalInvalidateFiles(const QSet<QString>& files);
|
void internalInvalidateFiles(const QSet<QString>& files);
|
||||||
QSet<QString> calculateFilesToBeReparsed(const QString& fileName);
|
QSet<QString> calculateFilesToBeReparsed(const QString& fileName);
|
||||||
int calcKeyLenForStruct(const QString& word);
|
// int calcKeyLenForStruct(const QString& word);
|
||||||
// {
|
// {
|
||||||
// function GetClass(const Phrase: AnsiString): AnsiString;
|
// function GetClass(const Phrase: AnsiString): AnsiString;
|
||||||
// function GetMember(const Phrase: AnsiString): AnsiString;
|
// function GetMember(const Phrase: AnsiString): AnsiString;
|
||||||
|
|
|
@ -185,11 +185,13 @@ void initParser()
|
||||||
CppKeywords.insert("extern",KeywordType::None);
|
CppKeywords.insert("extern",KeywordType::None);
|
||||||
|
|
||||||
// handled elsewhere
|
// handled elsewhere
|
||||||
CppKeywords.insert("class",KeywordType::None);
|
|
||||||
CppKeywords.insert("operator",KeywordType::None);
|
CppKeywords.insert("operator",KeywordType::None);
|
||||||
CppKeywords.insert("static",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);
|
CppKeywords.insert("for",KeywordType::For);
|
||||||
|
|
|
@ -69,6 +69,7 @@ enum class KeywordType {
|
||||||
Private,
|
Private,
|
||||||
Protected,
|
Protected,
|
||||||
Friend,
|
Friend,
|
||||||
|
Struct, // struct/class/enum
|
||||||
Enum, //enum
|
Enum, //enum
|
||||||
Inline, // inline
|
Inline, // inline
|
||||||
Namespace, //namespace
|
Namespace, //namespace
|
||||||
|
|
Loading…
Reference in New Issue