work save

This commit is contained in:
Roy Qu 2022-11-01 00:01:46 +08:00
parent f8ab38b634
commit f78a4953ef
5 changed files with 174 additions and 223 deletions

View File

@ -1474,42 +1474,6 @@ void CppParser::removeScopeLevel(int line)
} }
} }
int CppParser::skipBraces(int startAt)
{
int i = startAt;
int level = 0; // assume we start on top of {
while (i < mTokenizer.tokenCount()) {
switch(mTokenizer[i]->text.front().unicode()) {
case '{': level++;
break;
case '}':
level--;
if (level==0)
return i;
}
i++;
}
return startAt;
}
int CppParser::skipBracket(int startAt)
{
int i = startAt;
int level = 0; // assume we start on top of {
while (i < mTokenizer.tokenCount()) {
switch(mTokenizer[i]->text.front().unicode()) {
case '[': level++;
break;
case ']':
level--;
if (level==0)
return i;
}
i++;
}
return startAt;
}
void CppParser::internalClear() void CppParser::internalClear()
{ {
mCurrentScope.clear(); mCurrentScope.clear();
@ -1579,31 +1543,25 @@ QStringList CppParser::sortFilesByIncludeRelations(const QSet<QString> &files)
return result; return result;
} }
bool CppParser::checkForCatchBlock() bool CppParser::checkForKeyword(SkipType& skipType)
{ {
// return mIndex < mTokenizer.tokenCount() && skipType = mCppKeywords.value(mTokenizer[mIndex]->text,SkipType::skNone);
// mTokenizer[mIndex]->text == "catch"; switch(skipType) {
return mTokenizer[mIndex]->text == "catch"; case SkipType::skCatch:
} case SkipType::skFor:
case SkipType::skNone:
bool CppParser::checkForEnum() case SkipType::skScope:
{ case SkipType::skEnum:
// return mIndex < mTokenizer.tokenCount() && case SkipType::skInline:
// mTokenizer[mIndex]->text == "enum"; case SkipType::skNamespace:
return mTokenizer[mIndex]->text == "enum"; case SkipType::skTypedef:
} case SkipType::skUsing:
case SkipType::skFriend:
bool CppParser::checkForForBlock() case SkipType::skProtected:
{ return false;
// return mIndex < mTokenizer.tokenCount() && default:
// mTokenizer[mIndex]->text == "for"; return true;
return mTokenizer[mIndex]->text == "for"; }
}
bool CppParser::checkForKeyword()
{
SkipType st = mCppKeywords.value(mTokenizer[mIndex]->text,SkipType::skNone);
return st!=SkipType::skNone;
} }
bool CppParser::checkForMethod(QString &sType, QString &sName, int &argStartIndex, bool CppParser::checkForMethod(QString &sType, QString &sName, int &argStartIndex,
@ -1696,7 +1654,7 @@ bool CppParser::checkForMethod(QString &sType, QString &sName, int &argStartInde
} else { } else {
//if IsValidIdentifier(mTokenizer[mIndex]->text) then //if IsValidIdentifier(mTokenizer[mIndex]->text) then
// Still walking through type // Still walking through type
QString s = expandMacroType(mTokenizer[mIndex]->text); //todo: do we really need expand macro? it should be done in preprocessor QString s = mTokenizer[mIndex]->text; //todo: do we really need expand macro? it should be done in preprocessor
if (s == "static") if (s == "static")
isStatic = true; isStatic = true;
if (s == "friend") if (s == "friend")
@ -1719,14 +1677,14 @@ bool CppParser::checkForMethod(QString &sType, QString &sName, int &argStartInde
return false; return false;
} }
bool CppParser::checkForNamespace() bool CppParser::checkForNamespace(SkipType skipType)
{ {
return ((mIndex < mTokenizer.tokenCount()-1) return (skipType==SkipType::skNamespace &&(mIndex < mTokenizer.tokenCount()-1))
&& (mTokenizer[mIndex]->text == "namespace")) || (
|| ( skipType==SkipType::skInline
(mIndex+1 < mTokenizer.tokenCount()-1) && (mIndex+1 < mTokenizer.tokenCount()-1)
&& (mTokenizer[mIndex]->text == "inline") &&mTokenizer[mIndex+1]->text == "namespace"
&& (mTokenizer[mIndex+1]->text == "namespace")); );
} }
bool CppParser::checkForPreprocessor() bool CppParser::checkForPreprocessor()
@ -1736,14 +1694,11 @@ bool CppParser::checkForPreprocessor()
return (mTokenizer[mIndex]->text.startsWith('#')); return (mTokenizer[mIndex]->text.startsWith('#'));
} }
bool CppParser::checkForScope() bool CppParser::checkForScope(SkipType skipType)
{ {
return (mIndex < mTokenizer.tokenCount() - 1) return ( (skipType == SkipType::skScope || skipType == SkipType::skProtected)
&& (mTokenizer[mIndex + 1]->text == ':') && mIndex+1 < mTokenizer.tokenCount()
&& ( && mTokenizer[mIndex + 1]->text == ':'
(mTokenizer[mIndex]->text == "public")
|| (mTokenizer[mIndex]->text == "protected")
|| (mTokenizer[mIndex]->text == "private")
); );
} }
@ -1758,12 +1713,11 @@ void CppParser::checkForSkipStatement()
} }
} }
bool CppParser::checkForStructs() bool CppParser::checkForStructs(SkipType skipType)
{ {
int dis = 0; int dis = 0;
if ((mTokenizer[mIndex]->text == "friend") if (skipType == SkipType::skFriend
|| (mTokenizer[mIndex]->text == "public") || skipType == SkipType::skScope)
|| (mTokenizer[mIndex]->text == "private"))
dis = 1; dis = 1;
if (mIndex >= mTokenizer.tokenCount() - 2 - dis) if (mIndex >= mTokenizer.tokenCount() - 2 - dis)
return false; return false;
@ -1789,9 +1743,12 @@ bool CppParser::checkForStructs()
break; break;
switch(ch.unicode()) { switch(ch.unicode()) {
case ';': case ';':
case '{':
case '}': case '}':
case ',': case ',':
case '(':
case ')': case ')':
case '[':
case ']': case ']':
case '=': case '=':
case '*': case '*':
@ -1809,16 +1766,11 @@ bool CppParser::checkForStructs()
return result; return result;
} }
bool CppParser::checkForTypedef()
{
return mTokenizer[mIndex]->text == "typedef";
}
bool CppParser::checkForTypedefEnum() bool CppParser::checkForTypedefEnum()
{ {
//we assume that typedef is the current index, so we check the next //we assume that typedef is the current index, so we check the next
//should call CheckForTypedef first!!! //should call CheckForTypedef first!!!
return (mIndex < mTokenizer.tokenCount() - 1) && return (mIndex+1 < mTokenizer.tokenCount() ) &&
(mTokenizer[mIndex + 1]->text == "enum"); (mTokenizer[mIndex + 1]->text == "enum");
} }
@ -1835,25 +1787,27 @@ bool CppParser::checkForTypedefStruct()
return (word.length() == keyLen) || isSpaceChar(word[keyLen]) || word[keyLen]=='['; return (word.length() == keyLen) || isSpaceChar(word[keyLen]) || word[keyLen]=='[';
} }
bool CppParser::checkForUsing() bool CppParser::checkForUsing(SkipType skipType)
{ {
return (mIndex < mTokenizer.tokenCount()-1) && mTokenizer[mIndex]->text == "using"; return skipType==SkipType::skUsing == (mIndex < mTokenizer.tokenCount()-1);
} }
bool CppParser::checkForVar() bool CppParser::checkForVar(bool& isFunctionPointer)
{ {
// Be pessimistic // Be pessimistic
bool result = false; bool result = false;
isFunctionPointer = false;
// Store old index // Store old index
int indexBackup = mIndex; int indexBackup = mIndex;
SkipType skipType;
// Use mIndex so we can reuse checking functions // Use mIndex so we can reuse checking functions
if (mIndex + 1 < mTokenizer.tokenCount()) { if (mIndex + 1 < mTokenizer.tokenCount()) {
// Check the current and the next token // Check the current and the next token
for (int i = 0; i<=1; i++) { for (int i = 0; i<=1; i++) {
if (checkForKeyword() if (checkForKeyword(skipType)
|| isInvalidVarPrefixChar(mTokenizer[mIndex]->text.front()) || isInvalidVarPrefixChar(mTokenizer[mIndex]->text.front())
|| (mTokenizer[mIndex]->text.back() == '.') || (mTokenizer[mIndex]->text.back() == '.')
|| ( || (
@ -1865,39 +1819,46 @@ bool CppParser::checkForVar()
mIndex = indexBackup; mIndex = indexBackup;
return false; return false;
} // Could be a function pointer? } // Could be a function pointer?
else if (mTokenizer[mIndex]->text.front() == '(') { else if (mTokenizer[mIndex]->text == '(') {
// Quick fix: there must be a pointer operator in the first tiken int nextIndex = mTokenizer[mIndex]->matchIndex+1;
if ( (mIndex + 1 >= mTokenizer.tokenCount()) if ( (nextIndex >= mTokenizer.tokenCount())
|| (mTokenizer[mIndex + 1]->text.front() != '(') || (mTokenizer[nextIndex]->text != '(')
|| mTokenizer[mIndex]->text.indexOf('*')<0) { || !mTokenizer[mIndex+1]->text.startsWith('*')) {
// Reset index and fail // Reset index and fail
mIndex = indexBackup; mIndex = indexBackup;
return false; return false;
} else {
nextIndex = mTokenizer[nextIndex]->matchIndex+1;
if (mTokenizer[mIndex]->text!=';') {
mIndex = indexBackup;
return false;
}
isFunctionPointer=true;
mIndex = indexBackup;
return true;
} }
} }
mIndex++; mIndex++;
} }
} }
// Revert to the point we started at
mIndex = indexBackup;
// Fail if we do not find a comma or a semicolon or a ( (inline constructor) // Fail if we do not find a comma or a semicolon or a ( (inline constructor)
while (mIndex < mTokenizer.tokenCount()) { while (mIndex < mTokenizer.tokenCount()) {
if (mTokenizer[mIndex]->text.front() == '#' if (mTokenizer[mIndex]->text.front() == '#'
|| mTokenizer[mIndex]->text.front() == '}' || mTokenizer[mIndex]->text == '}'
|| checkForKeyword()) { || checkForKeyword(skipType)) {
break; // fail break; // fail
// } else if ((mTokenizer[mIndex]->text.length()>1) && (mTokenizer[mIndex]->text[0] == '(')
// && (mTokenizer[mIndex]->text[1] == '(')) { // TODO: is this used to remove __attribute stuff?
// break;
} else if (mTokenizer[mIndex]->text.front() == ',' } else if (mTokenizer[mIndex]->text.front() == ','
|| mTokenizer[mIndex]->text.front() == ';' || mTokenizer[mIndex]->text.front() == ';'
|| mTokenizer[mIndex]->text.front() == '{') { || mTokenizer[mIndex]->text.front() == '{') {
result = true; result = true;
break; break;
} }
mIndex++; //skip '(' ')'
if (mTokenizer[mIndex]->text=='(' || mTokenizer[mIndex]->text=='[')
mIndex=mTokenizer[mIndex]->matchIndex;
else
mIndex++;
} }
// Revert to the point we started at // Revert to the point we started at
@ -2291,10 +2252,9 @@ void CppParser::handleForBlock()
addSoloScopeLevel(block,startLine); addSoloScopeLevel(block,startLine);
} }
void CppParser::handleKeyword() void CppParser::handleKeyword(SkipType skipType)
{ {
// Skip // Skip
SkipType skipType = mCppKeywords.value(mTokenizer[mIndex]->text,SkipType::skNone);
switch (skipType) { switch (skipType) {
case SkipType::skItself: case SkipType::skItself:
// skip it; // skip it;
@ -2313,18 +2273,18 @@ void CppParser::handleKeyword()
break; break;
case SkipType::skToRightParenthesis: case SkipType::skToRightParenthesis:
// skip to ) // skip to )
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.endsWith(')')) while (mIndex < mTokenizer.tokenCount() && mTokenizer[mIndex]->text!=')')
mIndex++; mIndex++;
mIndex++; // step over mIndex++; // step over
break; break;
case SkipType::skToLeftBrace: case SkipType::skToLeftBrace:
// Skip to { // Skip to {
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.startsWith('{')) while (mIndex < mTokenizer.tokenCount() && mTokenizer[mIndex]->text!='{')
mIndex++; mIndex++;
break; break;
case SkipType::skToRightBrace: case SkipType::skToRightBrace:
// Skip to } // Skip to }
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.startsWith('}')) while (mIndex < mTokenizer.tokenCount() && mTokenizer[mIndex]->text!='}')
mIndex++; mIndex++;
mIndex++; // step over mIndex++; // step over
break; break;
@ -2496,15 +2456,16 @@ void CppParser::handleMethod(const QString &sType, const QString &sName, int arg
} }
} }
void CppParser::handleNamespace() void CppParser::handleNamespace(SkipType skipType)
{ {
bool isInline=false; bool isInline=false;
if (mTokenizer[mIndex]->text == "inline") { int startLine = mTokenizer[mIndex]->line;
if (skipType==SkipType::skInline) {
isInline = true; isInline = true;
mIndex++; //skip 'inline' mIndex++; //skip 'inline'
} }
int startLine = mTokenizer[mIndex]->line;
mIndex++; //skip 'namespace' mIndex++; //skip 'namespace'
if (!isLetterChar(mTokenizer[mIndex]->text.front())) if (!isLetterChar(mTokenizer[mIndex]->text.front()))
@ -2794,6 +2755,8 @@ bool CppParser::handleStatement()
int idx=getCurrentBlockEndSkip(); int idx=getCurrentBlockEndSkip();
int idx2=getCurrentBlockBeginSkip(); int idx2=getCurrentBlockBeginSkip();
int idx3=getCurrentInlineNamespaceEndSkip(); int idx3=getCurrentInlineNamespaceEndSkip();
SkipType skipType;
bool isFunctionPointer;
if (mIndex >= idx2) { if (mIndex >= idx2) {
//skip (previous handled) block begin //skip (previous handled) block begin
mBlockBeginSkips.pop_back(); mBlockBeginSkips.pop_back();
@ -2836,17 +2799,17 @@ bool CppParser::handleStatement()
mIndex++; mIndex++;
} else if (checkForPreprocessor()) { } else if (checkForPreprocessor()) {
handlePreprocessor(); handlePreprocessor();
} else if (checkForKeyword()) { // includes template now } else if (checkForKeyword(skipType)) { // includes template now
handleKeyword(); handleKeyword(skipType);
} else if (checkForForBlock()) { // (for/catch) } else if (skipType==SkipType::skFor) { // (for/catch)
handleForBlock(); handleForBlock();
} else if (checkForCatchBlock()) { // (for/catch) } else if (skipType==SkipType::skCatch) { // (for/catch)
handleCatchBlock(); handleCatchBlock();
} else if (checkForScope()) { // public /private/proteced } else if (checkForScope(skipType)) { // public /private/proteced
handleScope(); handleScope();
} else if (checkForEnum()) { } else if (skipType==SkipType::skEnum) {
handleEnum(); handleEnum();
} else if (checkForTypedef()) { } else if (skipType==SkipType::skTypedef) {
if (mIndex+1 < mTokenizer.tokenCount()) { if (mIndex+1 < mTokenizer.tokenCount()) {
if (checkForTypedefStruct()) { // typedef struct something if (checkForTypedefStruct()) { // typedef struct something
mIndex++; // skip 'typedef' mIndex++; // skip 'typedef'
@ -2858,16 +2821,16 @@ bool CppParser::handleStatement()
handleOtherTypedefs(); // typedef Foo Bar handleOtherTypedefs(); // typedef Foo Bar
} else } else
mIndex++; mIndex++;
} else if (checkForNamespace()) { } else if (checkForNamespace(skipType)) {
handleNamespace(); handleNamespace(skipType);
} else if (checkForUsing()) { } else if (checkForUsing(skipType)) {
handleUsing(); handleUsing();
} else if (checkForStructs()) { } else if (checkForStructs(skipType)) {
handleStructs(false); handleStructs(false);
} else if (checkForMethod(funcType, funcName, argStart,argEnd, isStatic, isFriend)) { } else if (checkForMethod(funcType, funcName, argStart,argEnd, isStatic, isFriend)) {
handleMethod(funcType, funcName, argStart, argEnd, isStatic, isFriend); // don't recalculate parts handleMethod(funcType, funcName, argStart, argEnd, isStatic, isFriend); // don't recalculate parts
} else if (checkForVar()) { } else if (checkForVar(isFunctionPointer)) {
handleVar(); handleVar(isFunctionPointer);
} else } else
mIndex++; mIndex++;
@ -3251,63 +3214,60 @@ void CppParser::handleUsing()
} }
} }
void CppParser::handleVar() void CppParser::handleVar(bool isFunctionPointer)
{ {
// Keep going and stop on top of the variable name // Keep going and stop on top of the variable name
QString lastType = ""; QString lastType = "";
bool isFunctionPointer = false;
bool isExtern = false; bool isExtern = false;
bool isStatic = false; bool isStatic = false;
bool varAdded = false; bool varAdded = false;
while (true) {
if ((mIndex + 2 < mTokenizer.tokenCount())
&& (mTokenizer[mIndex + 1]->text.front() == '(')
&& (mTokenizer[mIndex + 2]->text.front() == '(')) {
isFunctionPointer = mTokenizer[mIndex + 1]->text.indexOf('*') >= 0;
if (!isFunctionPointer)
break; // inline constructor
} else if ((mIndex + 1 < mTokenizer.tokenCount())
&& (mTokenizer[mIndex + 1]->text.front()=='('
|| mTokenizer[mIndex + 1]->text.front()==','
|| mTokenizer[mIndex + 1]->text.front()==';'
|| mTokenizer[mIndex + 1]->text.front()==':'
|| mTokenizer[mIndex + 1]->text.front()=='}'
|| mTokenizer[mIndex + 1]->text.front()=='#'
|| mTokenizer[mIndex + 1]->text.front()=='{')) {
break;
}
if (!isFunctionPointer) {
while (true) {
if ((mIndex + 1 < mTokenizer.tokenCount())
&& (mTokenizer[mIndex + 1]->text=='('
|| mTokenizer[mIndex + 1]->text==','
|| mTokenizer[mIndex + 1]->text==';'
|| mTokenizer[mIndex + 1]->text.front()==':'
|| mTokenizer[mIndex + 1]->text=='}'
|| mTokenizer[mIndex + 1]->text.front()=='#'
|| mTokenizer[mIndex + 1]->text=='{')) {
break;
}
// we've made a mistake, this is a typedef , not a variable definition. // struct/class/union is part of the type signature
if (mTokenizer[mIndex]->text == "typedef") // but we dont store it in the type cache, so must trim it to find the type info
return; if (mTokenizer[mIndex]->text!="struct"
&& mTokenizer[mIndex]->text!="class"
// struct/class/union is part of the type signature && mTokenizer[mIndex]->text!="union") {
// but we dont store it in the type cache, so must trim it to find the type info if (mTokenizer[mIndex]->text == ':') {
if (mTokenizer[mIndex]->text!="struct" lastType += ':';
&& mTokenizer[mIndex]->text!="class"
&& mTokenizer[mIndex]->text!="union") {
if (mTokenizer[mIndex]->text == ':') {
lastType += ':';
} else {
QString s=expandMacroType(mTokenizer[mIndex]->text);
if (s == "extern") {
isExtern = true;
} else { } else {
if (!s.isEmpty()) QString s=mTokenizer[mIndex]->text;
lastType += ' '+s; if (s == "extern") {
if (s == "static") isExtern = true;
isStatic = true; } else {
if (!s.isEmpty())
lastType += ' '+s;
if (s == "static")
isStatic = true;
}
} }
} }
mIndex++;
if(mIndex >= mTokenizer.tokenCount())
break;
} }
mIndex++; lastType = lastType.trimmed();
if(mIndex >= mTokenizer.tokenCount()) } else {
break; QString s=mTokenizer[mIndex]->text;
if (isFunctionPointer) if (s == "extern") {
break; isExtern = true;
} else if (s=="static") {
isStatic = true;
} else
lastType=s;
} }
lastType = lastType.trimmed();
// Don't bother entering the scanning loop when we have failed // Don't bother entering the scanning loop when we have failed
if (mIndex >= mTokenizer.tokenCount()) if (mIndex >= mTokenizer.tokenCount())
@ -3315,7 +3275,6 @@ void CppParser::handleVar()
// Find the variable name // Find the variable name
while (true) { while (true) {
// Skip bit identifiers, // Skip bit identifiers,
// e.g.: // e.g.:
// handle // handle
@ -3325,12 +3284,11 @@ void CppParser::handleVar()
if ( (mIndex < mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text.front() == ':')) { if ( (mIndex < mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text.front() == ':')) {
while ( (mIndex < mTokenizer.tokenCount()) while ( (mIndex < mTokenizer.tokenCount())
&& !( && !(
mTokenizer[mIndex]->text.front() == ',' mTokenizer[mIndex]->text.startsWith(',')
|| isblockChar(';') || mTokenizer[mIndex]->text.startsWith(';')
)) ))
mIndex++; mIndex++;
} }
// Skip inline constructors, // Skip inline constructors,
// e.g.: // e.g.:
// handle // handle
@ -3339,13 +3297,8 @@ void CppParser::handleVar()
// int a // int a
if (!isFunctionPointer && if (!isFunctionPointer &&
mIndex < mTokenizer.tokenCount() && mIndex < mTokenizer.tokenCount() &&
mTokenizer[mIndex]->text.front() == '(') { mTokenizer[mIndex]->text == '(') {
while ((mIndex < mTokenizer.tokenCount()) mIndex=mTokenizer[mIndex]->matchIndex+1;
&& !(
mTokenizer[mIndex]->text.front() == ','
|| isblockChar(mTokenizer[mIndex]->text.front())
))
mIndex++;
} }
// Did we stop on top of the variable name? // Did we stop on top of the variable name?
@ -3354,9 +3307,10 @@ void CppParser::handleVar()
&& mTokenizer[mIndex]->text.front()!=';') { && mTokenizer[mIndex]->text.front()!=';') {
QString cmd; QString cmd;
QString args; QString args;
if (isFunctionPointer && (mIndex + 1 < mTokenizer.tokenCount())) { if (isFunctionPointer) {
QString s = mTokenizer[mIndex]->text; QString s = mTokenizer[mIndex+1]->text;
cmd = s.mid(2,s.length()-3).trimmed(); // (*foo) -> foo cmd = s.mid(1); // (*foo) -> foo
//TODO: parse args
args = mTokenizer[mIndex + 1]->text; // (int a,int b) args = mTokenizer[mIndex + 1]->text; // (int a,int b)
lastType += "(*)" + args; // void(int a,int b) lastType += "(*)" + args; // void(int a,int b)
mIndex++; mIndex++;
@ -3508,12 +3462,6 @@ void CppParser::inheritClassStatement(const PStatement& derived, bool isStruct,
} }
} }
QString CppParser::expandMacroType(const QString &name)
{
//its done in the preprocessor
return name;
}
void CppParser::fillListOfFunctions(const QString& fileName, int line, void CppParser::fillListOfFunctions(const QString& fileName, int line,
const PStatement& statement, const PStatement& statement,
const PStatement& scopeStatement, QStringList &list) const PStatement& scopeStatement, QStringList &list)
@ -4596,7 +4544,7 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart
if (mTokenizer[mIndex]->text == ':') { if (mTokenizer[mIndex]->text == ':') {
lastType += ':'; lastType += ':';
} else { } else {
QString s=expandMacroType(mTokenizer[mIndex]->text); QString s=mTokenizer[mIndex]->text;
if (s == "extern") { if (s == "extern") {
isExtern = true; isExtern = true;
} else { } else {

View File

@ -200,30 +200,26 @@ private:
bool isCurrentScope(const QString& command); bool isCurrentScope(const QString& command);
void addSoloScopeLevel(PStatement& statement, int line, bool shouldResetBlock = true); // adds new solo level void addSoloScopeLevel(PStatement& statement, int line, bool shouldResetBlock = true); // adds new solo level
void removeScopeLevel(int line); // removes level void removeScopeLevel(int line); // removes level
int skipBraces(int startAt); int skipBraces(int startAt) {
int skipBracket(int startAt); return mTokenizer[startAt]->matchIndex;
}
void internalClear(); void internalClear();
QStringList sortFilesByIncludeRelations(const QSet<QString> &files); QStringList sortFilesByIncludeRelations(const QSet<QString> &files);
bool checkForCatchBlock(); bool checkForKeyword(SkipType &skipType);
bool checkForEnum();
bool checkForForBlock();
bool checkForKeyword();
bool checkForMethod(QString &sType, QString &sName, int &argStartIndex, bool checkForMethod(QString &sType, QString &sName, int &argStartIndex,
int &argEndIndex, bool &isStatic, bool &isFriend); // caching of results int &argEndIndex, bool &isStatic, bool &isFriend); // caching of results
bool checkForNamespace(); bool checkForNamespace(SkipType skipType);
bool checkForPreprocessor(); bool checkForPreprocessor();
bool checkForScope(); bool checkForScope(SkipType skipType);
void checkForSkipStatement(); void checkForSkipStatement();
bool checkForStructs(); bool checkForStructs(SkipType skipType);
bool checkForTypedef();
bool checkForTypedefEnum(); bool checkForTypedefEnum();
bool checkForTypedefStruct(); bool checkForTypedefStruct();
bool checkForUsing(); bool checkForUsing(SkipType skipType);
bool checkForVar(); bool checkForVar(bool& isFunctionPointer);
QString expandMacroType(const QString& name);
void fillListOfFunctions(const QString& fileName, int line, void fillListOfFunctions(const QString& fileName, int line,
const PStatement& statement, const PStatement& statement,
@ -388,7 +384,7 @@ private:
void handleCatchBlock(); void handleCatchBlock();
void handleEnum(); void handleEnum();
void handleForBlock(); void handleForBlock();
void handleKeyword(); void handleKeyword(SkipType skipType);
void handleMethod( void handleMethod(
const QString& sType, const QString& sType,
const QString& sName, const QString& sName,
@ -396,14 +392,14 @@ private:
int argEnd, int argEnd,
bool isStatic, bool isStatic,
bool isFriend); bool isFriend);
void handleNamespace(); void handleNamespace(SkipType skipType);
void handleOtherTypedefs(); void handleOtherTypedefs();
void handlePreprocessor(); void handlePreprocessor();
void handleScope(); void handleScope();
bool handleStatement(); bool handleStatement();
void handleStructs(bool isTypedef = false); void handleStructs(bool isTypedef = false);
void handleUsing(); void handleUsing();
void handleVar(); void handleVar(bool isFunctionPointer);
void internalParse(const QString& fileName); void internalParse(const QString& fileName);
// function FindMacroDefine(const Command: AnsiString): PStatement; // function FindMacroDefine(const Command: AnsiString): PStatement;
void inheritClassStatement( void inheritClassStatement(

View File

@ -64,13 +64,13 @@ void CppTokenizer::tokenize(const QStringList &buffer)
addToken(s,mCurrentLine,tokenType); addToken(s,mCurrentLine,tokenType);
} }
while (!mUnmatchedBraces.isEmpty()) { while (!mUnmatchedBraces.isEmpty()) {
mTokenList[mUnmatchedBraces.back()]->matchIndex=mTokenList.count()-1; addToken("}",mCurrentLine,TokenType::RightBrace);
} }
while (!mUnmatchedBrackets.isEmpty()) { while (!mUnmatchedBrackets.isEmpty()) {
mTokenList[mUnmatchedBrackets.back()]->matchIndex=mTokenList.count()-1; addToken("]",mCurrentLine,TokenType::RightBrace);
} }
while (!mUnmatchedParenthesis.isEmpty()) { while (!mUnmatchedParenthesis.isEmpty()) {
mTokenList[mUnmatchedParenthesis.back()]->matchIndex=mTokenList.count()-1; addToken(")",mCurrentLine,TokenType::RightBrace);
} }
} }

View File

@ -179,28 +179,25 @@ void initParser()
// it's part of type info // it's part of type info
CppKeywords.insert("const",SkipType::skNone); CppKeywords.insert("const",SkipType::skNone);
CppKeywords.insert("extern",SkipType::skNone); CppKeywords.insert("extern",SkipType::skNone);
CppKeywords.insert("inline",SkipType::skNone);
// handled elsewhere // handled elsewhere
CppKeywords.insert("class",SkipType::skNone); CppKeywords.insert("class",SkipType::skNone);
CppKeywords.insert("enum",SkipType::skNone); CppKeywords.insert("operator",SkipType::skNone);
CppKeywords.insert("friend",SkipType::skNone);
CppKeywords.insert("operator",SkipType::skNone);
CppKeywords.insert("private",SkipType::skNone);
CppKeywords.insert("protected",SkipType::skNone);
CppKeywords.insert("public",SkipType::skNone);
CppKeywords.insert("static",SkipType::skNone); CppKeywords.insert("static",SkipType::skNone);
CppKeywords.insert("struct",SkipType::skNone); CppKeywords.insert("struct",SkipType::skNone);
CppKeywords.insert("typedef",SkipType::skNone);
CppKeywords.insert("union",SkipType::skNone); CppKeywords.insert("union",SkipType::skNone);
// namespace
CppKeywords.insert("namespace",SkipType::skNone);
CppKeywords.insert("using",SkipType::skNone);
CppKeywords.insert("for",SkipType::skNone);
CppKeywords.insert("catch",SkipType::skNone);
CppKeywords.insert("for",SkipType::skFor);
CppKeywords.insert("catch",SkipType::skCatch);
CppKeywords.insert("private",SkipType::skScope);
CppKeywords.insert("public",SkipType::skScope);
CppKeywords.insert("enum",SkipType::skEnum);
CppKeywords.insert("namespace",SkipType::skNamespace);
CppKeywords.insert("inline",SkipType::skInline);
CppKeywords.insert("typedef",SkipType::skTypedef);
CppKeywords.insert("using",SkipType::skUsing);
CppKeywords.insert("protected",SkipType::skProtected);
CppKeywords.insert("friend",SkipType::skFriend);
// nullptr is value // nullptr is value
CppKeywords.insert("nullptr",SkipType::skNone); CppKeywords.insert("nullptr",SkipType::skNone);

View File

@ -63,6 +63,16 @@ enum class SkipType {
skToRightParenthesis, // skip to ) skToRightParenthesis, // skip to )
skToLeftBrace,// Skip to { skToLeftBrace,// Skip to {
skToRightBrace, // skip to } skToRightBrace, // skip to }
skFor, //for
skCatch, //catch
skScope, // public/private
skProtected,
skFriend,
skEnum, //enum
skInline, // inline
skNamespace, //namespace
skTypedef, //typedef
skUsing, //using
skNone // It's a keyword but don't process here skNone // It's a keyword but don't process here
}; };