work save

This commit is contained in:
Roy Qu 2022-11-01 22:10:54 +08:00
parent ab9aa75d1f
commit ebfb631452
2 changed files with 248 additions and 194 deletions

View File

@ -1720,7 +1720,8 @@ bool CppParser::checkForStructs(KeywordType keywordType)
{ {
int dis = 0; int dis = 0;
if (keywordType == KeywordType::Friend if (keywordType == KeywordType::Friend
|| keywordType == KeywordType::Scope) || keywordType == KeywordType::Public
|| keywordType == KeywordType::Private)
dis = 1; dis = 1;
if (mIndex >= mTokenizer.tokenCount() - 2 - dis) if (mIndex >= mTokenizer.tokenCount() - 2 - dis)
return false; return false;
@ -1796,14 +1797,13 @@ bool CppParser::checkForUsing(KeywordType keywordType)
} }
bool CppParser::checkForVar(bool& isFunctionPointer) bool CppParser::checkForVar()
{ {
int indexBackup=mIndex;
// Be pessimistic // Be pessimistic
bool result = false; bool result = false;
isFunctionPointer = false;
// Store old index // Store old index
int indexBackup = mIndex;
KeywordType keywordType; KeywordType keywordType;
// Use mIndex so we can reuse checking functions // Use mIndex so we can reuse checking functions
@ -2046,9 +2046,8 @@ void CppParser::handleCatchBlock()
mIndex=mTokenizer[mIndex]->matchIndex+1; mIndex=mTokenizer[mIndex]->matchIndex+1;
} }
void CppParser::handleEnum() void CppParser::handleEnum(bool isTypedef)
{ {
//todo : handle enum class
QString enumName = ""; QString enumName = "";
bool isEnumClass = false; bool isEnumClass = false;
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
@ -2060,30 +2059,35 @@ void CppParser::handleEnum()
mIndex++; //skip class mIndex++; //skip class
} }
bool isNameAfterBraces=false;
bool isAdhocVar=false;
int endIndex=-1;
if ((mIndex< mTokenizer.tokenCount()) && mTokenizer[mIndex]->text.startsWith('{')) { // enum {...} NAME if ((mIndex< mTokenizer.tokenCount()) && mTokenizer[mIndex]->text.startsWith('{')) { // enum {...} NAME
// Skip to the closing brace // Skip to the closing brace
int i = indexOfMatchingBrace(mIndex); int i = indexOfMatchingBrace(mIndex);
// Have we found the name? // Have we found the name?
if ((i + 1 < mTokenizer.tokenCount()) && mTokenizer[i]->text.startsWith('}')) { if (i + 1 < mTokenizer.tokenCount()) {
if (!mTokenizer[i + 1]->text.startsWith(';')) enumName = mTokenizer[i + 1]->text.trimmed();
enumName = mTokenizer[i + 1]->text.trimmed(); if (!isIdentifierOrPointer(enumName)) {
//not a valid enum, skip to j
mIndex=indexOfNextSemicolon(i+1)+1;
return;
}
if (!isTypedef) {
//it's an ad-hoc enum var define;
if (isEnumClass) {
//Enum class can't add hoc, just skip to ;
mIndex=indexOfNextSemicolon(i+1)+1;
return;
}
enumName = "__enum__"+enumName+"__";
isAdhocVar=true;
}
} }
endIndex=i+1;
isNameAfterBraces=true;
} else if (mIndex+1< mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text.startsWith('{')){ // enum NAME {...}; } else if (mIndex+1< mTokenizer.tokenCount() && mTokenizer[mIndex+1]->text.startsWith('{')){ // enum NAME {...};
if ( (mIndex< mTokenizer.tokenCount()) && mTokenizer[mIndex]->text == "class") { enumName = mTokenizer[mIndex]->text;
//enum class {...} NAME
isEnumClass = true;
mIndex++;
}
while ((mIndex < mTokenizer.tokenCount()) &&
!(mTokenizer[mIndex]->text.startsWith('{')
|| mTokenizer[mIndex]->text.startsWith(';'))) {
enumName += mTokenizer[mIndex]->text + ' ';
mIndex++;
}
enumName = enumName.trimmed();
// An opening brace must be present after NAME
if ((mIndex >= mTokenizer.tokenCount()) || !mTokenizer[mIndex]->text.startsWith('{'))
return;
} else { } else {
// enum NAME blahblah // enum NAME blahblah
// it's an old c-style enum variable definition // it's an old c-style enum variable definition
@ -2092,41 +2096,72 @@ void CppParser::handleEnum()
// Add statement for enum name too // Add statement for enum name too
PStatement enumStatement; PStatement enumStatement;
if (!enumName.isEmpty()) { if (isEnumClass) {
if (isEnumClass) { enumStatement=addStatement(
enumStatement=addStatement( getCurrentScope(),
getCurrentScope(), mCurrentFile,
mCurrentFile, "enum class",
"enum class", enumName,
enumName, "",
"", "",
"", "",
"", startLine,
startLine, StatementKind::skEnumClassType,
StatementKind::skEnumClassType, getScope(),
getScope(), mClassScope,
mClassScope, true,
true, false);
false);
} else {
enumStatement=addStatement(
getCurrentScope(),
mCurrentFile,
"enum",
enumName,
"",
"",
"",
startLine,
StatementKind::skEnumType,
getScope(),
mClassScope,
true,
false);
}
} else { } else {
enumStatement = getCurrentScope(); enumStatement=addStatement(
getCurrentScope(),
mCurrentFile,
"enum",
enumName,
"",
"",
"",
startLine,
StatementKind::skEnumType,
getScope(),
mClassScope,
true,
false);
} }
if (isAdhocVar) {
//Ad-hoc var definition
// Skip to the closing brace
int i = indexOfMatchingBrace(mIndex)+1;
QString typeSuffix="";
while (i<mTokenizer.tokenCount()) {
QString name=mTokenizer[i]->text;
if (isIdentifierOrPointer(name)) {
QString suffix;
QString args;
parseCommandTypeAndArgs(name,suffix,args);
if (!name.isEmpty()) {
addStatement(
getCurrentScope(),
mCurrentFile,
enumName+suffix,
mTokenizer[i]->text,
args,
"",
"",
mTokenizer[i]->line,
StatementKind::skVariable,
getScope(),
mClassScope,
true,
false);
}
} else if (name!=',') {
break;
}
i++;
}
endIndex=indexOfNextSemicolon(i);
}
// Skip opening brace // Skip opening brace
mIndex++; mIndex++;
@ -2137,18 +2172,12 @@ void CppParser::handleEnum()
lastType += ' ' + enumName; lastType += ' ' + enumName;
QString cmd; QString cmd;
QString args; QString args;
if (!mTokenizer[mIndex]->text.startsWith('}')) { if (mTokenizer[mIndex]->text!='}') {
while ((mIndex < mTokenizer.tokenCount()) && while ((mIndex < mTokenizer.tokenCount()) &&
!isblockChar(mTokenizer[mIndex]->text[0])) { !isblockChar(mTokenizer[mIndex]->text[0])) {
if (!mTokenizer[mIndex]->text.startsWith(',')) { if (!mTokenizer[mIndex]->text.startsWith(',')) {
if (mTokenizer[mIndex]->text.endsWith(']')) { //array; break args cmd = mTokenizer[mIndex]->text;
int p = mTokenizer[mIndex]->text.indexOf('['); args = "";
cmd = mTokenizer[mIndex]->text.mid(0,p);
args = mTokenizer[mIndex]->text.mid(p);
} else {
cmd = mTokenizer[mIndex]->text;
args = "";
}
if (isEnumClass) { if (isEnumClass) {
if (enumStatement) { if (enumStatement) {
addStatement( addStatement(
@ -2202,9 +2231,9 @@ void CppParser::handleEnum()
mIndex ++ ; mIndex ++ ;
} }
} }
// Step over closing brace if (mIndex<endIndex)
if ((mIndex < mTokenizer.tokenCount()) && mTokenizer[mIndex]->text.startsWith('}')) mIndex=endIndex;
mIndex++; mIndex = indexOfNextSemicolon(mIndex)+1;
} }
void CppParser::handleForBlock() void CppParser::handleForBlock()
@ -2285,7 +2314,6 @@ void CppParser::handleMethod(const QString &sType, const QString &sName, int arg
{ {
bool isValid = true; bool isValid = true;
bool isDeclaration = false; // assume it's not a prototype bool isDeclaration = false; // assume it's not a prototype
int i = mIndex;
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
if (mIndex >= mTokenizer.tokenCount()) // not finished define, just skip it; if (mIndex >= mTokenizer.tokenCount()) // not finished define, just skip it;
@ -2362,7 +2390,7 @@ void CppParser::handleMethod(const QString &sType, const QString &sName, int arg
mClassScope, mClassScope,
true, true,
isStatic); isStatic);
scanMethodArgs(functionStatement, sArgs); scanMethodArgs(functionStatement, argStart,argEnd);
// add variable this to the class function // add variable this to the class function
if (functionClass && functionClass->kind == StatementKind::skClass && if (functionClass && functionClass->kind == StatementKind::skClass &&
!isStatic) { !isStatic) {
@ -2461,7 +2489,7 @@ void CppParser::handleNamespace(KeywordType skipType)
if (mIndex>=mTokenizer.tokenCount()) if (mIndex>=mTokenizer.tokenCount())
return; return;
QString aliasName; QString aliasName;
if ((mIndex+2<mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text.front() == '=')) { if ((mIndex+2<mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text == '=')) {
aliasName=mTokenizer[mIndex+1]->text; aliasName=mTokenizer[mIndex+1]->text;
//namespace alias //namespace alias
addStatement( addStatement(
@ -2484,7 +2512,7 @@ void CppParser::handleNamespace(KeywordType skipType)
} else if (isInline) { } else if (isInline) {
//inline namespace , just skip it //inline namespace , just skip it
// Skip to '{' // Skip to '{'
while ((mIndex<mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text.front() != '{')) while ((mIndex<mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text != '{'))
mIndex++; mIndex++;
int i =indexOfMatchingBrace(mIndex); //skip '}' int i =indexOfMatchingBrace(mIndex); //skip '}'
if (i==mIndex) if (i==mIndex)
@ -2510,11 +2538,8 @@ void CppParser::handleNamespace(KeywordType skipType)
false); false);
addSoloScopeLevel(namespaceStatement,startLine); addSoloScopeLevel(namespaceStatement,startLine);
// Skip to '{' // Skip pass next '{'
while ((mIndex<mTokenizer.tokenCount()) && !mTokenizer[mIndex]->text.startsWith('{')) mIndex = indexOfNextLeftBrace(mIndex)+1;
mIndex++;
if (mIndex<mTokenizer.tokenCount())
mIndex++; //skip '{'
} }
} }
@ -2527,81 +2552,66 @@ void CppParser::handleOtherTypedefs()
if (mIndex>=mTokenizer.tokenCount()) if (mIndex>=mTokenizer.tokenCount())
return; return;
if (mTokenizer[mIndex]->text.front() == '(' if (mTokenizer[mIndex]->text == '('
|| mTokenizer[mIndex]->text.front() == ',' || mTokenizer[mIndex]->text == ','
|| mTokenizer[mIndex]->text.front() == ';') { // error typedef || mTokenizer[mIndex]->text == ';') { // error typedef
//skip to ; //skip over next ;
while ((mIndex< mTokenizer.tokenCount()) && !mTokenizer[mIndex]->text.startsWith(';')) mIndex=indexOfNextSemicolon(mIndex)+1;
mIndex++;
//skip ;
if ((mIndex< mTokenizer.tokenCount()) && mTokenizer[mIndex]->text.startsWith(';'))
mIndex++;
return; return;
} }
if ((mIndex+1<mTokenizer.tokenCount()) if ((mIndex+1<mTokenizer.tokenCount())
&& (mTokenizer[mIndex+1]->text == ';')) { && (mTokenizer[mIndex+1]->text == ';')) {
//no old type //no old type, not valid
QString newType = mTokenizer[mIndex]->text.trimmed();
addStatement(
getCurrentScope(),
mCurrentFile,
"",
newType,
"",
"",
"",
startLine,
StatementKind::skTypedef,
getScope(),
mClassScope,
true,
false);
mIndex+=2; //skip ; mIndex+=2; //skip ;
return; return;
} }
QString oldType;
QString oldType;
// Walk up to first new word (before first comma or ;) // Walk up to first new word (before first comma or ;)
while(true) { while(true) {
oldType += mTokenizer[mIndex]->text + ' '; oldType += mTokenizer[mIndex]->text + ' ';
mIndex++; mIndex++;
if (mIndex+1>=mTokenizer.tokenCount()) if (mIndex+1>=mTokenizer.tokenCount()) {
//not valid, just exit
return;
}
if (mTokenizer[mIndex]->text=='(') {
break; break;
}
if (mTokenizer[mIndex + 1]->text.front() == ',' if (mTokenizer[mIndex + 1]->text.front() == ','
|| mTokenizer[mIndex + 1]->text.front() == ';') || mTokenizer[mIndex + 1]->text == ';')
break;
if ((mIndex + 2 < mTokenizer.tokenCount())
&& (mTokenizer[mIndex + 2]->text.front() == ','
|| mTokenizer[mIndex + 2]->text.front() == ';')
&& (mTokenizer[mIndex + 1]->text.front() == '('))
break; break;
//typedef function pointer
} }
oldType = oldType.trimmed(); oldType = oldType.trimmed();
if (oldType.isEmpty()) {
// Add synonyms for old //skip over next ;
if ((mIndex+1 < mTokenizer.tokenCount()) && !oldType.isEmpty()) { mIndex=indexOfNextSemicolon(mIndex)+1;
QString newType; return;
while(true) { }
// Support multiword typedefs QString newType;
if ((mIndex + 2 < mTokenizer.tokenCount()) while(mIndex+1<mTokenizer.tokenCount()) {
&& (mTokenizer[mIndex + 2]->text.front() == ',' if (mTokenizer[mIndex]->text == '(') {
|| mTokenizer[mIndex + 2]->text.front() == ';') int paramStart=mTokenizer[mIndex]->matchIndex+1;
&& (mTokenizer[mIndex + 1]->text.front() == '(')) { QString newType = mTokenizer[mIndex+1]->text;
//valid function define if (paramStart>=mTokenizer.tokenCount()
newType = mTokenizer[mIndex]->text.trimmed(); || mTokenizer[paramStart]->text!='(') {
newType = newType.mid(1,newType.length()-2); //remove '(' and ')'; //not valid function pointer (no args)
newType = newType.trimmed(); //skip over next ;
int p = newType.lastIndexOf(' '); mIndex=indexOfNextSemicolon(paramStart)+1;
if (p>=0) return;
newType.truncate(p+1); }
QString args=mTokenizer[mIndex + 1]->text; if (newType.startsWith('*'))
newType = newType.mid(1);
if (newType.isEmpty()) {
addStatement( addStatement(
getCurrentScope(), getCurrentScope(),
mCurrentFile, mCurrentFile,
oldType, oldType,
newType, newType,
args, mergeArgs(paramStart,mTokenizer[paramStart]->matchIndex),
removeArgNames(args), "",
"", "",
startLine, startLine,
StatementKind::skTypedef, StatementKind::skTypedef,
@ -2609,20 +2619,20 @@ void CppParser::handleOtherTypedefs()
mClassScope, mClassScope,
true, true,
false); false);
newType = ""; }
//skip to ',' or ';' } else if (mTokenizer[mIndex+1]->text.front() ==','
mIndex+=2; || mTokenizer[mIndex+1]->text.front() ==';') {
} else if (mTokenizer[mIndex+1]->text.front() ==','
|| mTokenizer[mIndex+1]->text.front() ==';'
|| mTokenizer[mIndex+1]->text.front() =='(') {
newType += mTokenizer[mIndex]->text; newType += mTokenizer[mIndex]->text;
newType = newType.trimmed(); QString suffix;
QString args;
parseCommandTypeAndArgs(newType,suffix,args);
addStatement( addStatement(
getCurrentScope(), getCurrentScope(),
mCurrentFile, mCurrentFile,
oldType, oldType+suffix,
newType, newType,
"", args,
"", "",
"", "",
startLine, startLine,
@ -2633,16 +2643,13 @@ void CppParser::handleOtherTypedefs()
false); false);
newType = ""; newType = "";
mIndex++; mIndex++;
} else { } else if (mIndex < mTokenizer.tokenCount() && mTokenizer[mIndex]->text == ',' ) {
newType += mTokenizer[mIndex]->text + ' '; mIndex++;
mIndex++; } else if (mIndex < mTokenizer.tokenCount() && mTokenizer[mIndex]->text == ';' ) {
} break;
if (mIndex < mTokenizer.tokenCount() && mTokenizer[mIndex]->text[0] == ',' ) } else {
mIndex++; newType += mTokenizer[mIndex]->text;
if ((mIndex>= mTokenizer.tokenCount()) || (mTokenizer[mIndex]->text[0] == ';')) mIndex++;
break;
if (mIndex+1 >= mTokenizer.tokenCount())
break;
} }
} }
@ -2798,7 +2805,7 @@ bool CppParser::handleStatement()
} else if (checkForScope(keywordType)) { // public /private/proteced } else if (checkForScope(keywordType)) { // public /private/proteced
handleScope(keywordType); handleScope(keywordType);
} else if (keywordType==KeywordType::Enum) { } else if (keywordType==KeywordType::Enum) {
handleEnum(); handleEnum(false);
} else if (keywordType==KeywordType::Typedef) { } else if (keywordType==KeywordType::Typedef) {
if (mIndex+1 < mTokenizer.tokenCount()) { if (mIndex+1 < mTokenizer.tokenCount()) {
if (checkForTypedefStruct()) { // typedef struct something if (checkForTypedefStruct()) { // typedef struct something
@ -2806,7 +2813,7 @@ bool CppParser::handleStatement()
handleStructs(true); handleStructs(true);
} else if (checkForTypedefEnum()) { // typedef enum something } else if (checkForTypedefEnum()) { // typedef enum something
mIndex++; // skip 'typedef' mIndex++; // skip 'typedef'
handleEnum(); handleEnum(true);
} else } else
handleOtherTypedefs(); // typedef Foo Bar handleOtherTypedefs(); // typedef Foo Bar
} else } else
@ -2819,8 +2826,8 @@ bool CppParser::handleStatement()
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(isFunctionPointer)) { } else if (checkForVar()) {
handleVar(isFunctionPointer); handleVar();
} else } else
mIndex++; mIndex++;
@ -2992,29 +2999,22 @@ void CppParser::handleStructs(bool isTypedef)
// Add synonym before opening brace // Add synonym before opening brace
while(true) { while(true) {
i++; i++;
if (mTokenizer[i]->text=='('
if (!(mTokenizer[i]->text.front() == '{' || mTokenizer[i]->text==')') {
|| mTokenizer[i]->text.front() == ',' //skip
|| mTokenizer[i]->text.front() == ';')) { } else if (!(mTokenizer[i]->text == '{'
// if ((mTokenizer[i]->text.front() == '_') || mTokenizer[i]->text == ','
// && (mTokenizer[i]->text.back() == '_')) { || mTokenizer[i]->text == ';')) {
// // skip possible gcc attributes if (mTokenizer[i]->text.endsWith(']')) { // cut-off array brackets
// // start and end with 2 underscores (i.e. __attribute__) int pos = mTokenizer[i]->text.indexOf('[');
// // so, to avoid slow checks of strings, we just check the first and last letter of the token command += mTokenizer[i]->text.mid(0,pos) + ' ';
// // if both are underscores, we split args = mTokenizer[i]->text.mid(pos);
// break; } else if (mTokenizer[i]->text.front() == '*'
// } else { || mTokenizer[i]->text.front() == '&') { // do not add spaces after pointer operator
if (mTokenizer[i]->text.endsWith(']')) { // cut-off array brackets command += mTokenizer[i]->text;
int pos = mTokenizer[i]->text.indexOf('['); } else {
command += mTokenizer[i]->text.mid(0,pos) + ' '; command += mTokenizer[i]->text + ' ';
args = mTokenizer[i]->text.mid(pos); }
} else if (mTokenizer[i]->text.front() == '*'
|| mTokenizer[i]->text.front() == '&') { // do not add spaces after pointer operator
command += mTokenizer[i]->text;
} else {
command += mTokenizer[i]->text + ' ';
}
// }
} else { } else {
command = command.trimmed(); command = command.trimmed();
if (!command.isEmpty() && if (!command.isEmpty() &&
@ -3075,8 +3075,8 @@ void CppParser::handleStructs(bool isTypedef)
} }
if (i >= mTokenizer.tokenCount() - 1) if (i >= mTokenizer.tokenCount() - 1)
break; break;
if (mTokenizer[i]->text.front()=='{' if (mTokenizer[i]->text=='{'
|| mTokenizer[i]->text.front()== ';') || mTokenizer[i]->text== ';')
break; break;
} }
@ -3113,10 +3113,8 @@ void CppParser::handleUsing()
{ {
int startLine = mTokenizer[mIndex]->line; int startLine = mTokenizer[mIndex]->line;
if (mCurrentFile.isEmpty()) { if (mCurrentFile.isEmpty()) {
//skip to ; //skip pass next ;
while ((mIndex < mTokenizer.tokenCount()) && (mTokenizer[mIndex]->text!=';')) mIndex=indexOfNextSemicolon(mIndex)+1;
mIndex++;
mIndex++; //skip ;
return; return;
} }
@ -3139,8 +3137,7 @@ void CppParser::handleUsing()
aliasName, // name of the alias (type) aliasName, // name of the alias (type)
fullName, // command fullName, // command
"", // args "", // args
"", "", // noname args
"",
"", // values "", // values
startLine, startLine,
StatementKind::skTypedef, StatementKind::skTypedef,
@ -3165,6 +3162,7 @@ void CppParser::handleUsing()
fullName, // name of the alias (type) fullName, // name of the alias (type)
usingName, // command usingName, // command
"", // args "", // args
"", // noname args
"", // values "", // values
startLine, startLine,
StatementKind::skAlias, StatementKind::skAlias,
@ -3173,11 +3171,8 @@ void CppParser::handleUsing()
true, true,
false); false);
} }
//skip to ; //skip to ; and skip it
while ((mIndex<mTokenizer.tokenCount()) && mIndex=indexOfNextSemicolon(mIndex)+1;
(mTokenizer[mIndex]->text!=";"))
mIndex++;
mIndex++; //and skip it
return; return;
} }
mIndex++; // skip 'namespace' mIndex++; // skip 'namespace'
@ -3204,15 +3199,29 @@ void CppParser::handleUsing()
} }
} }
void CppParser::handleVar(bool isFunctionPointer) void CppParser::handleVar()
{ {
int indexBackup=mIndex;
// 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 isExtern = false; bool isExtern = false;
bool isStatic = false; bool isStatic = false;
bool varAdded = false; bool varAdded = false;
if (checkForKeyword(keywordType)
|| isInvalidVarPrefixChar(mTokenizer[mIndex]->text.front())
|| (mTokenizer[mIndex]->text.back() == '.')
|| (
(mTokenizer[mIndex]->text.length() > 1) &&
(mTokenizer[mIndex]->text[mTokenizer[mIndex]->text.length() - 2] == '-') &&
(mTokenizer[mIndex]->text[mTokenizer[mIndex]->text.length() - 1] == '>'))
) {
// Reset index and fail
mIndex = indexBackup;
return false;
if (!isFunctionPointer) { if (!isFunctionPointer) {
while (true) { while (true) {
if ((mIndex + 1 < mTokenizer.tokenCount()) if ((mIndex + 1 < mTokenizer.tokenCount())
&& (mTokenizer[mIndex + 1]->text=='(' && (mTokenizer[mIndex + 1]->text=='('
@ -4982,6 +4991,34 @@ int CppParser::indexPassBraces(int index)
return index; return index;
} }
QString CppParser::mergeArgs(int startIndex, int endIndex)
{
QString result;
for (int i=startIndex;i<=endIndex;i++) {
if (i>startIndex)
result+=' ';
result+=mTokenizer[i]->text;
}
return result;
}
void CppParser::parseCommandTypeAndArgs(QString &command, QString &typeSuffix, QString &args)
{
typeSuffix="";
while (command.startsWith('*') || command.startsWith('&')) {
typeSuffix=command.front();
command=command.mid(1);
}
int pos=command.indexOf('[');
if (pos>=0) {
args=command.mid(pos);
command=command.left(pos);
} else {
args="";
}
}
ParserLanguage CppParser::language() const ParserLanguage CppParser::language() const
{ {
return mLanguage; return mLanguage;

View File

@ -220,7 +220,7 @@ private:
bool checkForTypedefEnum(); bool checkForTypedefEnum();
bool checkForTypedefStruct(); bool checkForTypedefStruct();
bool checkForUsing(KeywordType keywordType); bool checkForUsing(KeywordType keywordType);
bool checkForVar(bool& isFunctionPointer); bool checkForVar();
void fillListOfFunctions(const QString& fileName, int line, void fillListOfFunctions(const QString& fileName, int line,
const PStatement& statement, const PStatement& statement,
@ -325,6 +325,19 @@ private:
&& !token.contains('\"')); && !token.contains('\"'));
} }
bool isIdentifierOrPointer(const QString& term) const {
switch(term[0].unicode()) {
case '*':
return true;
case '\"':
case '\'':
return false;
default:
return isLetterChar(term[0]);
}
}
bool isIntegerLiteral(const QString& token) const { bool isIntegerLiteral(const QString& token) const {
if (token.isEmpty()) if (token.isEmpty())
return false; return false;
@ -384,7 +397,7 @@ private:
PStatement getTypeDef(const PStatement& statement, PStatement getTypeDef(const PStatement& statement,
const QString& fileName, const QString& aType); const QString& fileName, const QString& aType);
void handleCatchBlock(); void handleCatchBlock();
void handleEnum(); void handleEnum(bool isTypedef);
void handleForBlock(); void handleForBlock();
void handleKeyword(KeywordType skipType); void handleKeyword(KeywordType skipType);
void handleMethod( void handleMethod(
@ -401,7 +414,7 @@ private:
bool handleStatement(); bool handleStatement();
void handleStructs(bool isTypedef = false); void handleStructs(bool isTypedef = false);
void handleUsing(); void handleUsing();
void handleVar(bool isFunctionPointer); void handleVar();
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(
@ -536,6 +549,10 @@ private:
int indexOfNextLeftBrace(int index); int indexOfNextLeftBrace(int index);
int indexPassParenthesis(int index); int indexPassParenthesis(int index);
int indexPassBraces(int index); int indexPassBraces(int index);
QString mergeArgs(int startIndex, int endIndex);
void parseCommandTypeAndArgs(QString& command,
QString& typeSuffix,
QString& args);
private: private:
int mParserId; int mParserId;
ParserLanguage mLanguage; ParserLanguage mLanguage;