clean up code

This commit is contained in:
Roy Qu 2022-11-16 10:29:20 +08:00
parent 7ab444fc06
commit a9c266c39a
7 changed files with 137 additions and 124 deletions

View File

@ -298,7 +298,7 @@ QPixmap IconsManager::getPixmapForStatement(PStatement statement)
case StatementKind::skDestructor: case StatementKind::skDestructor:
if (statement->scope == StatementScope::Global) if (statement->scope == StatementScope::Global)
return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_METHOD)); return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_METHOD));
if (statement->isInherited) { if (statement->isInherited()) {
if (statement->classScope == StatementClassScope::Protected) { if (statement->classScope == StatementClassScope::Protected) {
return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTED_METHOD)); return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTED_METHOD));
} else if (statement->classScope == StatementClassScope::Public) { } else if (statement->classScope == StatementClassScope::Public) {
@ -319,7 +319,7 @@ QPixmap IconsManager::getPixmapForStatement(PStatement statement)
case StatementKind::skLocalVariable: case StatementKind::skLocalVariable:
return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR)); return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR));
case StatementKind::skVariable: case StatementKind::skVariable:
if (statement->isInherited) { if (statement->isInherited()) {
if (statement->classScope == StatementClassScope::Protected) { if (statement->classScope == StatementClassScope::Protected) {
return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR)); return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR));
} else if (statement->classScope == StatementClassScope::Public) { } else if (statement->classScope == StatementClassScope::Public) {

View File

@ -927,8 +927,7 @@ void CppParser::parseHardDefines()
StatementKind::skPreprocessor, StatementKind::skPreprocessor,
StatementScope::Global, StatementScope::Global,
StatementClassScope::None, StatementClassScope::None,
true, StatementProperty::spHasDefinition);
false);
} }
} }
} }
@ -1154,9 +1153,7 @@ PStatement CppParser::addInheritedStatement(const PStatement& derived, const PSt
inherit->kind, inherit->kind,
inherit->scope, inherit->scope,
access, access,
true, inherit->properties & StatementProperty::spInherited);
inherit->isStatic);
statement->isInherited = true;
return statement; return statement;
} }
@ -1166,7 +1163,7 @@ PStatement CppParser::addChildStatement(const PStatement& parent, const QString
const QString& noNameArgs, const QString& noNameArgs,
const QString &value, int line, StatementKind kind, const QString &value, int line, StatementKind kind,
const StatementScope& scope, const StatementClassScope& classScope, const StatementScope& scope, const StatementClassScope& classScope,
bool isDefinition, bool isStatic) StatementProperties properties)
{ {
return addStatement( return addStatement(
parent, parent,
@ -1180,8 +1177,7 @@ PStatement CppParser::addChildStatement(const PStatement& parent, const QString
kind, kind,
scope, scope,
classScope, classScope,
isDefinition, properties);
isStatic);
} }
PStatement CppParser::addStatement(const PStatement& parent, PStatement CppParser::addStatement(const PStatement& parent,
@ -1193,7 +1189,8 @@ PStatement CppParser::addStatement(const PStatement& parent,
const QString &value, const QString &value,
int line, StatementKind kind, int line, StatementKind kind,
const StatementScope& scope, const StatementScope& scope,
const StatementClassScope& classScope, bool isDefinition, bool isStatic) const StatementClassScope& classScope,
StatementProperties properties)
{ {
// Move '*', '&' to type rather than cmd (it's in the way for code-completion) // Move '*', '&' to type rather than cmd (it's in the way for code-completion)
QString newType = aType; QString newType = aType;
@ -1212,10 +1209,10 @@ PStatement CppParser::addStatement(const PStatement& parent,
|| kind == StatementKind::skVariable || kind == StatementKind::skVariable
) { ) {
//find //find
if (isDefinition) { if (properties.testFlag(StatementProperty::spHasDefinition)) {
PStatement oldStatement = findStatementInScope(newCommand,noNameArgs,kind,parent); PStatement oldStatement = findStatementInScope(newCommand,noNameArgs,kind,parent);
if (oldStatement && !oldStatement->hasDefinition) { if (oldStatement && !oldStatement->hasDefinition()) {
oldStatement->hasDefinition = true; oldStatement->setHasDefinition(true);
if (oldStatement->fileName!=fileName) { if (oldStatement->fileName!=fileName) {
PFileIncludes fileIncludes=mPreprocessor.includesList().value(fileName); PFileIncludes fileIncludes=mPreprocessor.includesList().value(fileName);
if (fileIncludes) { if (fileIncludes) {
@ -1244,20 +1241,20 @@ PStatement CppParser::addStatement(const PStatement& parent,
result->kind = kind; result->kind = kind;
result->scope = scope; result->scope = scope;
result->classScope = classScope; result->classScope = classScope;
result->hasDefinition = isDefinition; result->properties = properties;
result->line = line; result->line = line;
result->definitionLine = line; result->definitionLine = line;
result->fileName = fileName; result->fileName = fileName;
result->definitionFileName = fileName; result->definitionFileName = fileName;
if (!fileName.isEmpty()) if (!fileName.isEmpty()) {
result->inProject = mIsProjectFile; result->setInProject(mIsProjectFile);
else result->setInSystemHeader(mIsSystemHeader);
result->inProject = false; } else {
result->inSystemHeader = mIsSystemHeader; result->setInProject(false);
result->setInSystemHeader(true);
}
//result->children; //result->children;
//result->friends; //result->friends;
result->isStatic = isStatic;
result->isInherited = false;
if (scope == StatementScope::Local) if (scope == StatementScope::Local)
result->fullName = newCommand; result->fullName = newCommand;
else else
@ -1282,7 +1279,15 @@ PStatement CppParser::addStatement(const PStatement& parent,
return result; return result;
} }
PStatement CppParser::addStatement(const PStatement &parent, const QString &fileName, const QString &aType, const QString &command, int argStart, int argEnd, const QString &value, int line, StatementKind kind, const StatementScope &scope, const StatementClassScope &classScope, bool isDefinition, bool isStatic) PStatement CppParser::addStatement(const PStatement &parent,
const QString &fileName,
const QString &aType,
const QString &command,
int argStart, int argEnd,
const QString &value, int line,
StatementKind kind, const StatementScope &scope,
const StatementClassScope &classScope,
StatementProperties properties)
{ {
Q_ASSERT(mTokenizer[argStart]->text=='('); Q_ASSERT(mTokenizer[argStart]->text=='(');
QString args; QString args;
@ -1354,8 +1359,7 @@ PStatement CppParser::addStatement(const PStatement &parent, const QString &file
kind, kind,
scope, scope,
classScope, classScope,
isDefinition, properties);
isStatic);
} }
void CppParser::setInheritance(int index, const PStatement& classStatement, bool isStruct) void CppParser::setInheritance(int index, const PStatement& classStatement, bool isStruct)
@ -2188,8 +2192,7 @@ void CppParser::handleCatchBlock()
StatementKind::skBlock, StatementKind::skBlock,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
addSoloScopeLevel(block,startLine); addSoloScopeLevel(block,startLine);
scanMethodArgs(block,mIndex); scanMethodArgs(block,mIndex);
mIndex=mTokenizer[mIndex]->matchIndex+1; mIndex=mTokenizer[mIndex]->matchIndex+1;
@ -2256,8 +2259,7 @@ void CppParser::handleEnum(bool isTypedef)
StatementKind::skEnumClassType, StatementKind::skEnumClassType,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} else { } else {
enumStatement=addStatement( enumStatement=addStatement(
getCurrentScope(), getCurrentScope(),
@ -2271,8 +2273,7 @@ void CppParser::handleEnum(bool isTypedef)
StatementKind::skEnumType, StatementKind::skEnumType,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
if (isAdhocVar) { if (isAdhocVar) {
//Ad-hoc var definition //Ad-hoc var definition
@ -2298,8 +2299,7 @@ void CppParser::handleEnum(bool isTypedef)
StatementKind::skVariable, StatementKind::skVariable,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
} else if (name!=',') { } else if (name!=',') {
break; break;
@ -2339,8 +2339,7 @@ void CppParser::handleEnum(bool isTypedef)
StatementKind::skEnum, StatementKind::skEnum,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
} else { } else {
if (enumStatement) { if (enumStatement) {
@ -2356,8 +2355,7 @@ void CppParser::handleEnum(bool isTypedef)
StatementKind::skEnum, StatementKind::skEnum,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
addStatement( addStatement(
getCurrentScope(), getCurrentScope(),
@ -2371,8 +2369,7 @@ void CppParser::handleEnum(bool isTypedef)
StatementKind::skEnum, StatementKind::skEnum,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
} }
mIndex ++ ; mIndex ++ ;
@ -2418,8 +2415,7 @@ void CppParser::handleForBlock()
StatementKind::skBlock, StatementKind::skBlock,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
addSoloScopeLevel(block,startLine); addSoloScopeLevel(block,startLine);
} }
@ -2486,8 +2482,7 @@ void CppParser::handleLambda(int index, int endIndex)
StatementKind::skBlock, StatementKind::skBlock,
StatementScope::Local, StatementScope::Local,
StatementClassScope::None, StatementClassScope::None,
true, StatementProperty::spHasDefinition);
false);
scanMethodArgs(lambdaBlock,argStart); scanMethodArgs(lambdaBlock,argStart);
addSoloScopeLevel(lambdaBlock,mTokenizer[bodyStart]->line); addSoloScopeLevel(lambdaBlock,mTokenizer[bodyStart]->line);
int i=bodyStart+1; // start after '{'; int i=bodyStart+1; // start after '{';
@ -2560,9 +2555,7 @@ void CppParser::handleLambda(int index, int endIndex)
StatementKind::skVariable, StatementKind::skVariable,
getScope(), getScope(),
mClassScope, mClassScope,
//True, StatementProperty::spHasDefinition); // TODO: not supported to pass list
false,
false); // TODO: not supported to pass list
tempType=""; tempType="";
} }
} }
@ -2670,8 +2663,8 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
functionKind, functionKind,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition
isStatic); | (isStatic?StatementProperty::spStatic:StatementProperty::spNone));
scanMethodArgs(functionStatement, argStart); scanMethodArgs(functionStatement, argStart);
// add variable this to the class function // add variable this to the class function
if (scopeStatement && scopeStatement->kind == StatementKind::skClass && if (scopeStatement && scopeStatement->kind == StatementKind::skClass &&
@ -2689,8 +2682,7 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
StatementKind::skVariable, StatementKind::skVariable,
StatementScope::Local, StatementScope::Local,
StatementClassScope::None, StatementClassScope::None,
true, StatementProperty::spHasDefinition);
false);
} }
// add "__func__ variable" // add "__func__ variable"
@ -2706,8 +2698,7 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
StatementKind::skVariable, StatementKind::skVariable,
StatementScope::Local, StatementScope::Local,
StatementClassScope::None, StatementClassScope::None,
true, StatementProperty::spHasDefinition);
false);
} else { } else {
functionStatement = addStatement( functionStatement = addStatement(
@ -2723,8 +2714,7 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
functionKind, functionKind,
getScope(), getScope(),
mClassScope, mClassScope,
false, (isStatic?StatementProperty::spStatic:StatementProperty::spNone));
isStatic);
} }
} }
@ -2787,8 +2777,7 @@ void CppParser::handleNamespace(KeywordType skipType)
StatementKind::skNamespaceAlias, StatementKind::skNamespaceAlias,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
mIndex+=2; //skip ; mIndex+=2; //skip ;
return; return;
} else if (isInline) { } else if (isInline) {
@ -2816,8 +2805,7 @@ void CppParser::handleNamespace(KeywordType skipType)
StatementKind::skNamespace, StatementKind::skNamespace,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
// find next '{' or ';' // find next '{' or ';'
mIndex = indexOfNextSemicolonOrLeftBrace(mIndex); mIndex = indexOfNextSemicolonOrLeftBrace(mIndex);
@ -2906,8 +2894,7 @@ void CppParser::handleOtherTypedefs()
StatementKind::skTypedef, StatementKind::skTypedef,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
mIndex = mTokenizer[paramStart]->matchIndex+1; mIndex = mTokenizer[paramStart]->matchIndex+1;
} else if (mTokenizer[mIndex+1]->text.front() ==',' } else if (mTokenizer[mIndex+1]->text.front() ==','
@ -2929,8 +2916,7 @@ void CppParser::handleOtherTypedefs()
StatementKind::skTypedef, StatementKind::skTypedef,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
newType = ""; newType = "";
mIndex++; mIndex++;
} else { } else {
@ -2992,8 +2978,7 @@ void CppParser::handlePreprocessor()
StatementKind::skPreprocessor, StatementKind::skPreprocessor,
StatementScope::Global, StatementScope::Global,
StatementClassScope::None, StatementClassScope::None,
true, StatementProperty::spHasDefinition);
false);
} // TODO: undef ( define has limited scope) } // TODO: undef ( define has limited scope)
handlePreprocessorEnd: handlePreprocessorEnd:
mIndex++; mIndex++;
@ -3082,8 +3067,7 @@ bool CppParser::handleStatement()
StatementKind::skBlock, StatementKind::skBlock,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
addSoloScopeLevel(block,mTokenizer[mIndex]->line,true); addSoloScopeLevel(block,mTokenizer[mIndex]->line,true);
mIndex++; mIndex++;
} else if (mTokenizer[mIndex]->text[0] == '}') { } else if (mTokenizer[mIndex]->text[0] == '}') {
@ -3219,8 +3203,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementKind::skTypedef, StatementKind::skTypedef,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
mIndex++; mIndex++;
if (mIndex >= mTokenizer.tokenCount()) if (mIndex >= mTokenizer.tokenCount())
@ -3279,8 +3262,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementKind::skClass, StatementKind::skClass,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
command = ""; command = "";
} }
mIndex++; mIndex++;
@ -3304,8 +3286,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementKind::skClass, StatementKind::skClass,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
command=""; command="";
} }
mIndex+=2; mIndex+=2;
@ -3373,8 +3354,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementKind::skClass, StatementKind::skClass,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
if (isTypedef) { if (isTypedef) {
//typedef //typedef
@ -3390,8 +3370,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementKind::skTypedef, StatementKind::skTypedef,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition); // typedef
false); // typedef
} else { } else {
//variable define //variable define
addStatement( addStatement(
@ -3406,8 +3385,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementKind::skVariable, StatementKind::skVariable,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition); // TODO: not supported to pass list
false); // TODO: not supported to pass list
} }
} }
command = ""; command = "";
@ -3437,8 +3415,7 @@ void CppParser::handleStructs(bool isTypedef)
StatementKind::skBlock, StatementKind::skBlock,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
addSoloScopeLevel(firstSynonym,startLine); addSoloScopeLevel(firstSynonym,startLine);
@ -3482,8 +3459,7 @@ void CppParser::handleUsing()
StatementKind::skTypedef, StatementKind::skTypedef,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
// skip ; // skip ;
mIndex++; mIndex++;
return; return;
@ -3507,8 +3483,7 @@ void CppParser::handleUsing()
StatementKind::skAlias, StatementKind::skAlias,
getScope(), getScope(),
mClassScope, mClassScope,
true, StatementProperty::spHasDefinition);
false);
} }
//skip to ; and skip it //skip to ; and skip it
mIndex=indexOfNextSemicolon(mIndex)+1; mIndex=indexOfNextSemicolon(mIndex)+1;
@ -3642,8 +3617,8 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
getScope(), getScope(),
mClassScope, mClassScope,
//True, //True,
!isExtern, (isExtern?StatementProperty::spNone:StatementProperty::spHasDefinition)
isStatic); | (isStatic?StatementProperty::spStatic:StatementProperty::spNone));
} }
tempType=""; tempType="";
mIndex=indexOfNextSemicolonOrLeftBrace(argEnd+1); mIndex=indexOfNextSemicolonOrLeftBrace(argEnd+1);
@ -3673,8 +3648,8 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic)
getScope(), getScope(),
mClassScope, mClassScope,
//True, //True,
!isExtern, (isExtern?StatementProperty::spNone:StatementProperty::spHasDefinition)
isStatic); | (isStatic?StatementProperty::spStatic:StatementProperty::spNone));
tempType=""; tempType="";
} }
} }
@ -4707,7 +4682,7 @@ void CppParser::internalInvalidateFile(const QString &fileName)
if (statement->fileName==fileName) { if (statement->fileName==fileName) {
mStatementList.deleteStatement(statement); mStatementList.deleteStatement(statement);
} else { } else {
statement->hasDefinition=false; statement->setHasDefinition(false);
statement->definitionFileName = statement->fileName; statement->definitionFileName = statement->fileName;
statement->definitionLine = statement->line; statement->definitionLine = statement->line;
} }
@ -4797,8 +4772,7 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart
StatementKind::skParameter, StatementKind::skParameter,
StatementScope::Local, StatementScope::Local,
StatementClassScope::None, StatementClassScope::None,
true, StatementProperty::spHasDefinition);
false);
} }
i=argEnd+1; i=argEnd+1;
varType=""; varType="";
@ -4833,8 +4807,7 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart
StatementKind::skParameter, StatementKind::skParameter,
StatementScope::Local, StatementScope::Local,
StatementClassScope::None, StatementClassScope::None,
true, StatementProperty::spHasDefinition);
false);
} }
} }
} }

View File

@ -169,8 +169,7 @@ private:
StatementKind kind, StatementKind kind,
const StatementScope& scope, const StatementScope& scope,
const StatementClassScope& classScope, const StatementClassScope& classScope,
bool isDefinition, StatementProperties properties); // TODO: InheritanceList not supported
bool isStatic); // TODO: InheritanceList not supported
PStatement addStatement( PStatement addStatement(
const PStatement& parent, const PStatement& parent,
const QString &fileName, const QString &fileName,
@ -183,8 +182,7 @@ private:
StatementKind kind, StatementKind kind,
const StatementScope& scope, const StatementScope& scope,
const StatementClassScope& classScope, const StatementClassScope& classScope,
bool isDefinition, StatementProperties properties);
bool isStatic);
PStatement addStatement( PStatement addStatement(
const PStatement& parent, const PStatement& parent,
const QString &fileName, const QString &fileName,
@ -197,8 +195,7 @@ private:
StatementKind kind, StatementKind kind,
const StatementScope& scope, const StatementScope& scope,
const StatementClassScope& classScope, const StatementClassScope& classScope,
bool isDefinition, StatementProperties properties);
bool isStatic);
void setInheritance(int index, const PStatement& classStatement, bool isStruct); void setInheritance(int index, const PStatement& classStatement, bool isStruct);
bool isCurrentScope(const QString& command); bool isCurrentScope(const QString& command);
void addSoloScopeLevel(PStatement& statement, int line, bool shouldResetBlock=false); // adds new solo level void addSoloScopeLevel(PStatement& statement, int line, bool shouldResetBlock=false); // adds new solo level

View File

@ -140,6 +140,24 @@ struct StatementMatchPosition{
int end; int end;
}; };
enum StatementProperty {
spNone = 0x0,
spStatic = 0x0001,
spHasDefinition = 0x0002,
spInProject = 0x0004,
spInSystemHeader = 0x0008,
spInherited = 0x0010,
spVirtual = 0x0020,
spOverride = 0x0040,
spConstexpr = 0x0080
};
Q_DECLARE_FLAGS(StatementProperties, StatementProperty)
Q_DECLARE_OPERATORS_FOR_FLAGS(StatementProperties)
using PStatementMathPosition = std::shared_ptr<StatementMatchPosition>; using PStatementMathPosition = std::shared_ptr<StatementMatchPosition>;
struct Statement; struct Statement;
@ -158,20 +176,16 @@ struct Statement {
StatementKind kind; // kind of statement class/variable/function/etc StatementKind kind; // kind of statement class/variable/function/etc
StatementScope scope; // global/local/classlocal StatementScope scope; // global/local/classlocal
StatementClassScope classScope; // protected/private/public StatementClassScope classScope; // protected/private/public
bool hasDefinition; // definiton line/filename is valid
int line; // declaration int line; // declaration
int definitionLine; // definition int definitionLine; // definition
QString fileName; // declaration QString fileName; // declaration
QString definitionFileName; // definition QString definitionFileName; // definition
bool inProject; // statement in project
bool inSystemHeader; // statement in system header (#include <>)
StatementMap children; // functions can be overloaded,so we use list to save children with the same name StatementMap children; // functions can be overloaded,so we use list to save children with the same name
QSet<QString> friends; // friend class / functions QSet<QString> friends; // friend class / functions
bool isStatic; // static function / variable
bool isInherited; // inherted member;
QString fullName; // fullname(including class and namespace), ClassA::foo QString fullName; // fullname(including class and namespace), ClassA::foo
QSet<QString> usingList; // using namespaces QSet<QString> usingList; // using namespaces
QString noNameArgs;// Args without name QString noNameArgs;// Args without name
StatementProperties properties;
// fields for code completion // fields for code completion
int usageCount; //Usage Count int usageCount; //Usage Count
@ -180,6 +194,38 @@ struct Statement {
int firstMatchLength; // length of first match; int firstMatchLength; // length of first match;
int caseMatched; // if match with case int caseMatched; // if match with case
QList<PStatementMathPosition> matchPositions; QList<PStatementMathPosition> matchPositions;
// definiton line/filename is valid
bool hasDefinition() {
return properties.testFlag(StatementProperty::spHasDefinition);
};
void setHasDefinition(bool on) {
properties.setFlag(StatementProperty::spHasDefinition,on);
}
// statement in project
bool inProject() {
return properties.testFlag(StatementProperty::spInProject);
}
void setInProject(bool on) {
properties.setFlag(StatementProperty::spInProject, on);
}
// statement in system header (#include <>)
bool inSystemHeader() {
return properties.testFlag(StatementProperty::spInSystemHeader);
};
void setInSystemHeader(bool on) {
properties.setFlag(StatementProperty::spInSystemHeader, on);
}
bool isStatic() {
return properties.testFlag(StatementProperty::spStatic);
} // static function / variable
void setIsStatic(bool on) {
properties.setFlag(StatementProperty::spStatic, on);
}
bool isInherited() {
return properties.testFlag(StatementProperty::spInherited);
}; // inherted member;
}; };
struct EvalStatement; struct EvalStatement;

View File

@ -328,7 +328,7 @@ void ClassBrowserModel::filterChildren(ClassBrowserNode *node, const StatementMa
{ {
for (PStatement statement:statements) { for (PStatement statement:statements) {
if (mClassBrowserType==ProjectClassBrowserType::WholeProject if (mClassBrowserType==ProjectClassBrowserType::WholeProject
&& !statement->inProject) && !statement->inProject())
continue; continue;
if (mProcessedStatements.contains(statement.get())) if (mProcessedStatements.contains(statement.get()))
@ -336,7 +336,7 @@ void ClassBrowserModel::filterChildren(ClassBrowserNode *node, const StatementMa
if (statement->kind == StatementKind::skBlock) if (statement->kind == StatementKind::skBlock)
continue; continue;
if (statement->isInherited && !pSettings->ui().classBrowserShowInherited()) if (statement->isInherited() && !pSettings->ui().classBrowserShowInherited())
continue; continue;
if (statement == node->statement) // prevent infinite recursion if (statement == node->statement) // prevent infinite recursion
@ -400,10 +400,7 @@ PStatement ClassBrowserModel::createDummy(const PStatement& statement)
result->value = statement->value; result->value = statement->value;
result->scope = statement->scope; result->scope = statement->scope;
result->classScope = statement->classScope; result->classScope = statement->classScope;
result->inProject = statement->inProject; result->properties = statement->properties;
result->inSystemHeader = statement->inSystemHeader;
result->isStatic = statement->isStatic;
result->isInherited = statement->isInherited;
result->fileName= statement->fileName; result->fileName= statement->fileName;
result->line = statement->line; result->line = statement->line;
result->definitionFileName = statement->fileName; result->definitionFileName = statement->fileName;

View File

@ -212,7 +212,7 @@ void CodeCompletionPopup::addFunctionWithoutDefinitionChildren(PStatement scopeS
return; return;
for (const PStatement& childStatement: children) { for (const PStatement& childStatement: children) {
if (childStatement->inSystemHeader) if (childStatement->inSystemHeader())
continue; continue;
if (childStatement->fileName.isEmpty()) { if (childStatement->fileName.isEmpty()) {
// hard defines, do nothing // hard defines, do nothing
@ -222,7 +222,7 @@ void CodeCompletionPopup::addFunctionWithoutDefinitionChildren(PStatement scopeS
case StatementKind::skConstructor: case StatementKind::skConstructor:
case StatementKind::skFunction: case StatementKind::skFunction:
case StatementKind::skDestructor: case StatementKind::skDestructor:
if (!childStatement->hasDefinition) if (!childStatement->hasDefinition())
addStatement(childStatement,fileName,line); addStatement(childStatement,fileName,line);
break; break;
case StatementKind::skClass: case StatementKind::skClass:
@ -306,17 +306,17 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
if (statement2->kind != StatementKind::skKeyword) { if (statement2->kind != StatementKind::skKeyword) {
//s1 keyword / s2 system defines, s1 < s2, should return true //s1 keyword / s2 system defines, s1 < s2, should return true
//s1 keyword / s2 not system defines, s2 < s1, should return false; //s1 keyword / s2 not system defines, s2 < s1, should return false;
return statement2->inSystemHeader; return statement2->inSystemHeader();
} else } else
return statement1->command < statement2->command; return statement1->command < statement2->command;
} else if (statement2->kind == StatementKind::skKeyword) { } else if (statement2->kind == StatementKind::skKeyword) {
//s1 system defines / s2 keyword, s2 < s1, should return false; //s1 system defines / s2 keyword, s2 < s1, should return false;
//s1 not system defines / s2 keyword, s1 < s2, should return true; //s1 not system defines / s2 keyword, s1 < s2, should return true;
return (!statement1->inSystemHeader); return (!statement1->inSystemHeader());
} }
// Show stuff from local headers first // Show stuff from local headers first
if (statement1->inSystemHeader != statement2->inSystemHeader) if (statement1->inSystemHeader() != statement2->inSystemHeader())
return !(statement1->inSystemHeader); return !(statement1->inSystemHeader());
// Show local statements first // Show local statements first
if (statement1->scope != StatementScope::Global if (statement1->scope != StatementScope::Global
&& statement2->scope == StatementScope::Global ) { && statement2->scope == StatementScope::Global ) {
@ -387,17 +387,17 @@ static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement stat
if (statement2->kind != StatementKind::skKeyword) { if (statement2->kind != StatementKind::skKeyword) {
//s1 keyword / s2 system defines, s1 < s2, should return true //s1 keyword / s2 system defines, s1 < s2, should return true
//s1 keyword / s2 not system defines, s2 < s1, should return false; //s1 keyword / s2 not system defines, s2 < s1, should return false;
return statement2->inSystemHeader; return statement2->inSystemHeader();
} else } else
return statement1->command < statement2->command; return statement1->command < statement2->command;
} else if (statement2->kind == StatementKind::skKeyword) { } else if (statement2->kind == StatementKind::skKeyword) {
//s1 system defines / s2 keyword, s2 < s1, should return false; //s1 system defines / s2 keyword, s2 < s1, should return false;
//s1 not system defines / s2 keyword, s1 < s2, should return true; //s1 not system defines / s2 keyword, s1 < s2, should return true;
return (!statement1->inSystemHeader); return (!statement1->inSystemHeader());
} }
// Show stuff from local headers first // Show stuff from local headers first
if (statement1->inSystemHeader != statement2->inSystemHeader) if (statement1->inSystemHeader() != statement2->inSystemHeader())
return !(statement1->inSystemHeader); return !(statement1->inSystemHeader());
// Show local statements first // Show local statements first
if (statement1->scope != StatementScope::Global if (statement1->scope != StatementScope::Global
&& statement2->scope == StatementScope::Global ) { && statement2->scope == StatementScope::Global ) {
@ -770,7 +770,7 @@ void CodeCompletionPopup::getCompletionFor(
mParser->statementList().childrenStatements(classTypeStatement); mParser->statementList().childrenStatements(classTypeStatement);
foreach (const PStatement& childStatement, children) { foreach (const PStatement& childStatement, children) {
if ( if (
(childStatement->isStatic) (childStatement->isStatic())
|| (childStatement->kind == StatementKind::skTypedef || (childStatement->kind == StatementKind::skTypedef
|| childStatement->kind == StatementKind::skClass || childStatement->kind == StatementKind::skClass
|| childStatement->kind == StatementKind::skEnum || childStatement->kind == StatementKind::skEnum
@ -786,7 +786,7 @@ void CodeCompletionPopup::getCompletionFor(
mParser->statementList().childrenStatements(classTypeStatement); mParser->statementList().childrenStatements(classTypeStatement);
foreach (const PStatement& childStatement,children) { foreach (const PStatement& childStatement,children) {
if ( if (
(childStatement->isStatic) (childStatement->isStatic())
|| (childStatement->kind == StatementKind::skTypedef || (childStatement->kind == StatementKind::skTypedef
|| childStatement->kind == StatementKind::skClass || childStatement->kind == StatementKind::skClass
|| childStatement->kind == StatementKind::skEnum || childStatement->kind == StatementKind::skEnum

View File

@ -132,7 +132,7 @@ void NewClassCandidatesModel::fillClasses()
return; return;
foreach( const PStatement& s, mParser->statementList().childrenStatements()) { foreach( const PStatement& s, mParser->statementList().childrenStatements()) {
if (s->kind==StatementKind::skClass if (s->kind==StatementKind::skClass
&& s->inProject && s->inProject()
&& !s->command.startsWith("_") && !s->command.startsWith("_")
&& !s->command.contains("<") && !s->command.contains("<")
&& !mClassNames.contains(s->fullName)) { && !mClassNames.contains(s->fullName)) {
@ -158,7 +158,7 @@ void NewClassCandidatesModel::fillClassesInNamespace(PStatement ns)
{ {
foreach( const PStatement& s, mParser->statementList().childrenStatements(ns)) { foreach( const PStatement& s, mParser->statementList().childrenStatements(ns)) {
if (s->kind==StatementKind::skClass if (s->kind==StatementKind::skClass
&& s->inProject && s->inProject()
&& !s->command.startsWith("_") && !s->command.startsWith("_")
&& !s->command.contains("<") && !s->command.contains("<")
&& !mClassNames.contains(s->fullName)) { && !mClassNames.contains(s->fullName)) {