refactor: enum to enum class

This commit is contained in:
Roy Qu 2024-04-03 10:37:29 +08:00
parent 494a5c61e4
commit 648e555fc5
11 changed files with 433 additions and 428 deletions

View File

@ -694,53 +694,53 @@ void ColorManager::updateStatementColors(std::shared_ptr<QHash<StatementKind, st
PColorSchemeItem item; PColorSchemeItem item;
item = getItem(schemeName, SYNS_AttrFunction); item = getItem(schemeName, SYNS_AttrFunction);
if (item) { if (item) {
statementColors->insert(StatementKind::skFunction,item); statementColors->insert(StatementKind::Function,item);
statementColors->insert(StatementKind::skConstructor,item); statementColors->insert(StatementKind::Constructor,item);
statementColors->insert(StatementKind::skDestructor,item); statementColors->insert(StatementKind::Destructor,item);
} }
item = getItem(schemeName, SYNS_AttrClass); item = getItem(schemeName, SYNS_AttrClass);
if (item) { if (item) {
statementColors->insert(StatementKind::skClass,item); statementColors->insert(StatementKind::Class,item);
statementColors->insert(StatementKind::skTypedef,item); statementColors->insert(StatementKind::Typedef,item);
statementColors->insert(StatementKind::skAlias,item); statementColors->insert(StatementKind::Alias,item);
} }
item = getItem(schemeName, SYNS_AttrIdentifier); item = getItem(schemeName, SYNS_AttrIdentifier);
if (item) { if (item) {
statementColors->insert(StatementKind::skEnumType,item); statementColors->insert(StatementKind::EnumType,item);
statementColors->insert(StatementKind::skEnumClassType,item); statementColors->insert(StatementKind::EnumClassType,item);
} }
item = getItem(schemeName, SYNS_AttrVariable); item = getItem(schemeName, SYNS_AttrVariable);
if (item) { if (item) {
statementColors->insert(StatementKind::skVariable,item); statementColors->insert(StatementKind::Variable,item);
} }
item = getItem(schemeName, SYNS_AttrLocalVariable); item = getItem(schemeName, SYNS_AttrLocalVariable);
if (item) { if (item) {
statementColors->insert(StatementKind::skLocalVariable,item); statementColors->insert(StatementKind::LocalVariable,item);
statementColors->insert(StatementKind::skParameter,item); statementColors->insert(StatementKind::Parameter,item);
} }
item = getItem(schemeName, SYNS_AttrGlobalVariable); item = getItem(schemeName, SYNS_AttrGlobalVariable);
if (item) { if (item) {
statementColors->insert(StatementKind::skGlobalVariable,item); statementColors->insert(StatementKind::GlobalVariable,item);
} }
item = getItem(schemeName, SYNS_AttrPreprocessor); item = getItem(schemeName, SYNS_AttrPreprocessor);
if (item) { if (item) {
statementColors->insert(StatementKind::skPreprocessor,item); statementColors->insert(StatementKind::Preprocessor,item);
statementColors->insert(StatementKind::skEnum,item); statementColors->insert(StatementKind::Enum,item);
} }
item = getItem(schemeName, SYNS_AttrReservedWord); item = getItem(schemeName, SYNS_AttrReservedWord);
if (item) { if (item) {
statementColors->insert(StatementKind::skKeyword,item); statementColors->insert(StatementKind::Keyword,item);
statementColors->insert(StatementKind::skUserCodeSnippet,item); statementColors->insert(StatementKind::UserCodeSnippet,item);
statementColors->insert(StatementKind::skKeywordType,item); statementColors->insert(StatementKind::KeywordType,item);
} }
item = getItem(schemeName, SYNS_AttrReserveWord_Type); item = getItem(schemeName, SYNS_AttrReserveWord_Type);
if (item) { if (item) {
statementColors->insert(StatementKind::skKeywordType,item); statementColors->insert(StatementKind::KeywordType,item);
} }
item = getItem(schemeName, SYNS_AttrString); item = getItem(schemeName, SYNS_AttrString);
if (item) { if (item) {
statementColors->insert(StatementKind::skNamespace,item); statementColors->insert(StatementKind::Namespace,item);
statementColors->insert(StatementKind::skNamespaceAlias,item); statementColors->insert(StatementKind::NamespaceAlias,item);
} }
} }

View File

@ -840,7 +840,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
QString funcName = function->command; QString funcName = function->command;
bool isVoid = (function->type == "void"); bool isVoid = (function->type == "void");
foreach (const PStatement& child, function->children) { foreach (const PStatement& child, function->children) {
if (child->kind == StatementKind::skParameter) if (child->kind == StatementKind::Parameter)
params.append(child->command); params.append(child->command);
} }
insertString.append(QString(" * @brief ")+USER_CODE_IN_INSERT_POS); insertString.append(QString(" * @brief ")+USER_CODE_IN_INSERT_POS);
@ -975,11 +975,11 @@ void Editor::keyPressEvent(QKeyEvent *event)
return; return;
} else if (CppTypeKeywords.contains(lastWord)) { } else if (CppTypeKeywords.contains(lastWord)) {
PStatement currentScope = mParser->findScopeStatement(mFilename,caretY()); PStatement currentScope = mParser->findScopeStatement(mFilename,caretY());
while(currentScope && currentScope->kind==StatementKind::skBlock) { while(currentScope && currentScope->kind==StatementKind::Block) {
currentScope = currentScope->parentScope.lock(); currentScope = currentScope->parentScope.lock();
} }
if (!currentScope || currentScope->kind == StatementKind::skNamespace if (!currentScope || currentScope->kind == StatementKind::Namespace
|| currentScope->kind == StatementKind::skClass) { || currentScope->kind == StatementKind::Class) {
//may define a function //may define a function
processCommand(QSynedit::EditCommand::Char,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false,CodeCompletionType::FunctionWithoutDefinition); showCompletion(lastWord,false,CodeCompletionType::FunctionWithoutDefinition);
@ -1010,16 +1010,16 @@ void Editor::keyPressEvent(QKeyEvent *event)
lastWord, lastWord,
caretY()); caretY());
StatementKind kind = getKindOfStatement(statement); StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skClass if (kind == StatementKind::Class
|| kind == StatementKind::skEnumClassType || kind == StatementKind::EnumClassType
|| kind == StatementKind::skEnumType || kind == StatementKind::EnumType
|| kind == StatementKind::skTypedef) { || kind == StatementKind::Typedef) {
PStatement currentScope = mParser->findScopeStatement(mFilename,caretY()); PStatement currentScope = mParser->findScopeStatement(mFilename,caretY());
while(currentScope && currentScope->kind==StatementKind::skBlock) { while(currentScope && currentScope->kind==StatementKind::Block) {
currentScope = currentScope->parentScope.lock(); currentScope = currentScope->parentScope.lock();
} }
if (!currentScope || currentScope->kind == StatementKind::skNamespace) { if (!currentScope || currentScope->kind == StatementKind::Namespace) {
//may define a function //may define a function
processCommand(QSynedit::EditCommand::Char,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition); showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition);
@ -1034,10 +1034,10 @@ void Editor::keyPressEvent(QKeyEvent *event)
lastWord = getPreviousWordAtPositionForCompleteFunctionDefinition(ws); lastWord = getPreviousWordAtPositionForCompleteFunctionDefinition(ws);
if (mParser && !lastWord.isEmpty()) { if (mParser && !lastWord.isEmpty()) {
PStatement currentScope = mParser->findScopeStatement(mFilename,caretY()); PStatement currentScope = mParser->findScopeStatement(mFilename,caretY());
while(currentScope && currentScope->kind==StatementKind::skBlock) { while(currentScope && currentScope->kind==StatementKind::Block) {
currentScope = currentScope->parentScope.lock(); currentScope = currentScope->parentScope.lock();
} }
if (!currentScope || currentScope->kind == StatementKind::skNamespace) { if (!currentScope || currentScope->kind == StatementKind::Namespace) {
//may define a function //may define a function
processCommand(QSynedit::EditCommand::Char,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition); showCompletion("",false,CodeCompletionType::FunctionWithoutDefinition);
@ -1339,28 +1339,28 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
StatementKind kind; StatementKind kind;
if (mParser->parsing()){ if (mParser->parsing()){
kind=mIdentCache.value(QString("%1 %2").arg(aChar).arg(token),StatementKind::skUnknown); kind=mIdentCache.value(QString("%1 %2").arg(aChar).arg(token),StatementKind::Unknown);
} else { } else {
QStringList expression = getExpressionAtPosition(p); QStringList expression = getExpressionAtPosition(p);
PStatement statement = parser()->findStatementOf( PStatement statement = parser()->findStatementOf(
filename(), filename(),
expression, expression,
p.line); p.line);
while (statement && statement->kind == StatementKind::skAlias) while (statement && statement->kind == StatementKind::Alias)
statement = mParser->findAliasedStatement(statement); statement = mParser->findAliasedStatement(statement);
kind = getKindOfStatement(statement); kind = getKindOfStatement(statement);
mIdentCache.insert(QString("%1 %2").arg(aChar).arg(token),kind); mIdentCache.insert(QString("%1 %2").arg(aChar).arg(token),kind);
} }
if (kind == StatementKind::skUnknown) { if (kind == StatementKind::Unknown) {
QSynedit::BufferCoord pBeginPos,pEndPos; QSynedit::BufferCoord pBeginPos,pEndPos;
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
if ((pEndPos.line>=1) if ((pEndPos.line>=1)
&& (pEndPos.ch>=0) && (pEndPos.ch>=0)
&& (pEndPos.ch+1 < document()->getLine(pEndPos.line-1).length()) && (pEndPos.ch+1 < document()->getLine(pEndPos.line-1).length())
&& (document()->getLine(pEndPos.line-1)[pEndPos.ch+1] == '(')) { && (document()->getLine(pEndPos.line-1)[pEndPos.ch+1] == '(')) {
kind = StatementKind::skFunction; kind = StatementKind::Function;
} else { } else {
kind = StatementKind::skVariable; kind = StatementKind::Variable;
} }
} }
PColorSchemeItem item = mStatementColors->value(kind,PColorSchemeItem()); PColorSchemeItem item = mStatementColors->value(kind,PColorSchemeItem());
@ -1398,7 +1398,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
) )
) )
{ {
PColorSchemeItem item = mStatementColors->value(StatementKind::skKeywordType,PColorSchemeItem()); PColorSchemeItem item = mStatementColors->value(StatementKind::KeywordType,PColorSchemeItem());
if (item) { if (item) {
foreground = item->foreground(); foreground = item->foreground();
@ -1534,10 +1534,10 @@ void Editor::inputMethodEvent(QInputMethodEvent *event)
lastWord, lastWord,
caretY()); caretY());
StatementKind kind = getKindOfStatement(statement); StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skClass if (kind == StatementKind::Class
|| kind == StatementKind::skEnumClassType || kind == StatementKind::EnumClassType
|| kind == StatementKind::skEnumType || kind == StatementKind::EnumType
|| kind == StatementKind::skTypedef) { || kind == StatementKind::Typedef) {
//last word is a typedef/class/struct, this is a var or param define, and dont show suggestion //last word is a typedef/class/struct, this is a var or param define, and dont show suggestion
// if devEditor.UseTabnine then // if devEditor.UseTabnine then
// ShowTabnineCompletion; // ShowTabnineCompletion;
@ -3843,7 +3843,7 @@ void Editor::completionInsert(bool appendFunc)
return; return;
if (pSettings->codeCompletion().recordUsage() if (pSettings->codeCompletion().recordUsage()
&& statement->kind != StatementKind::skUserCodeSnippet) { && statement->kind != StatementKind::UserCodeSnippet) {
statement->usageCount+=1; statement->usageCount+=1;
pMainWindow->symbolUsageManager()->updateUsage(statement->fullName, pMainWindow->symbolUsageManager()->updateUsage(statement->fullName,
statement->usageCount); statement->usageCount);
@ -3863,20 +3863,20 @@ void Editor::completionInsert(bool appendFunc)
// if we are inserting a function, // if we are inserting a function,
if (appendFunc) { if (appendFunc) {
if (statement->kind == StatementKind::skAlias) { if (statement->kind == StatementKind::Alias) {
PStatement newStatement = mParser->findAliasedStatement(statement); PStatement newStatement = mParser->findAliasedStatement(statement);
while (newStatement && newStatement->kind==StatementKind::skAlias) { while (newStatement && newStatement->kind==StatementKind::Alias) {
newStatement = mParser->findAliasedStatement(newStatement); newStatement = mParser->findAliasedStatement(newStatement);
} }
if (newStatement) if (newStatement)
statement = newStatement; statement = newStatement;
} }
if ( (statement->kind == StatementKind::skFunction if ( (statement->kind == StatementKind::Function
&& !IOManipulators.contains(statement->fullName)) && !IOManipulators.contains(statement->fullName))
|| statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::Constructor
|| statement->kind == StatementKind::skDestructor || statement->kind == StatementKind::Destructor
|| ||
(statement->kind == StatementKind::skPreprocessor (statement->kind == StatementKind::Preprocessor
&& !statement->args.isEmpty())) { && !statement->args.isEmpty())) {
QChar nextCh = nextNonSpaceChar(caretY()-1,p.ch-1); QChar nextCh = nextNonSpaceChar(caretY()-1,p.ch-1);
if (nextCh=='(') { if (nextCh=='(') {
@ -3891,14 +3891,14 @@ void Editor::completionInsert(bool appendFunc)
} }
// ... by replacing the selection // ... by replacing the selection
if (statement->kind == StatementKind::skUserCodeSnippet) { // it's a user code template if (statement->kind == StatementKind::UserCodeSnippet) { // it's a user code template
// insertUserCodeIn(Statement->value); // insertUserCodeIn(Statement->value);
//first move caret to the begin of the word to be replaced //first move caret to the begin of the word to be replaced
insertCodeSnippet(statement->value); insertCodeSnippet(statement->value);
} else { } else {
if ( if (
(statement->kind == StatementKind::skKeyword (statement->kind == StatementKind::Keyword
|| statement->kind == StatementKind::skPreprocessor) || statement->kind == StatementKind::Preprocessor)
&& (statement->command.startsWith('#') && (statement->command.startsWith('#')
|| statement->command.startsWith('@')) || statement->command.startsWith('@'))
) { ) {
@ -4168,9 +4168,9 @@ QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/
line); line);
if (!statement) if (!statement)
return result; return result;
if (statement->kind == StatementKind::skFunction if (statement->kind == StatementKind::Function
|| statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::Constructor
|| statement->kind == StatementKind::skDestructor) { || statement->kind == StatementKind::Destructor) {
result = getHintForFunction(statement,mFilename,line); result = getHintForFunction(statement,mFilename,line);
} else if (statement->line>0) { } else if (statement->line>0) {
QFileInfo fileInfo(statement->fileName); QFileInfo fileInfo(statement->fileName);
@ -4190,10 +4190,10 @@ void Editor::showDebugHint(const QString &s, int line)
return; return;
PStatement statement = mParser->findStatementOf(mFilename,s,line); PStatement statement = mParser->findStatementOf(mFilename,s,line);
if (statement) { if (statement) {
if (statement->kind != StatementKind::skVariable if (statement->kind != StatementKind::Variable
&& statement->kind != StatementKind::skGlobalVariable && statement->kind != StatementKind::GlobalVariable
&& statement->kind != StatementKind::skLocalVariable && statement->kind != StatementKind::LocalVariable
&& statement->kind != StatementKind::skParameter) { && statement->kind != StatementKind::Parameter) {
return; return;
} }
} }
@ -4426,7 +4426,7 @@ void Editor::updateFunctionTip(bool showTip)
pos.line); pos.line);
if (statement) { if (statement) {
PStatement typeStatement = mParser->findTypeDef(statement,mFilename); PStatement typeStatement = mParser->findTypeDef(statement,mFilename);
if (typeStatement && typeStatement->kind == StatementKind::skClass) { if (typeStatement && typeStatement->kind == StatementKind::Class) {
s = previousWord; s = previousWord;
functionNamePos = pos; functionNamePos = pos;
} }
@ -4540,52 +4540,52 @@ void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int c
// qDebug()<<s; // qDebug()<<s;
PStatement statement = mParser->findStatementOf(mFilename, PStatement statement = mParser->findStatementOf(mFilename,
s , p.line); s , p.line);
while (statement && statement->kind == StatementKind::skAlias) while (statement && statement->kind == StatementKind::Alias)
statement = mParser->findAliasedStatement(statement); statement = mParser->findAliasedStatement(statement);
StatementKind kind = getKindOfStatement(statement); StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skUnknown) { if (kind == StatementKind::Unknown) {
if ((pEndPos.line>=1) if ((pEndPos.line>=1)
&& (pEndPos.ch>=0) && (pEndPos.ch>=0)
&& (pEndPos.ch < document()->getLine(pEndPos.line-1).length()) && (pEndPos.ch < document()->getLine(pEndPos.line-1).length())
&& (document()->getLine(pEndPos.line-1)[pEndPos.ch] == '(')) { && (document()->getLine(pEndPos.line-1)[pEndPos.ch] == '(')) {
kind = StatementKind::skFunction; kind = StatementKind::Function;
} else { } else {
kind = StatementKind::skVariable; kind = StatementKind::Variable;
} }
} }
QSynedit::CppSyntaxer* cppSyntaxer = dynamic_cast<QSynedit::CppSyntaxer*>(syntaxer.get()); QSynedit::CppSyntaxer* cppSyntaxer = dynamic_cast<QSynedit::CppSyntaxer*>(syntaxer.get());
switch(kind) { switch(kind) {
case StatementKind::skFunction: case StatementKind::Function:
case StatementKind::skConstructor: case StatementKind::Constructor:
case StatementKind::skDestructor: case StatementKind::Destructor:
attr = cppSyntaxer->functionAttribute(); attr = cppSyntaxer->functionAttribute();
break; break;
case StatementKind::skClass: case StatementKind::Class:
case StatementKind::skTypedef: case StatementKind::Typedef:
attr = cppSyntaxer->classAttribute(); attr = cppSyntaxer->classAttribute();
break; break;
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
case StatementKind::skEnumType: case StatementKind::EnumType:
break; break;
case StatementKind::skLocalVariable: case StatementKind::LocalVariable:
case StatementKind::skParameter: case StatementKind::Parameter:
attr = cppSyntaxer->localVarAttribute(); attr = cppSyntaxer->localVarAttribute();
break; break;
case StatementKind::skVariable: case StatementKind::Variable:
attr = cppSyntaxer->variableAttribute(); attr = cppSyntaxer->variableAttribute();
break; break;
case StatementKind::skGlobalVariable: case StatementKind::GlobalVariable:
attr = cppSyntaxer->globalVarAttribute(); attr = cppSyntaxer->globalVarAttribute();
break; break;
case StatementKind::skEnum: case StatementKind::Enum:
case StatementKind::skPreprocessor: case StatementKind::Preprocessor:
attr = cppSyntaxer->preprocessorAttribute(); attr = cppSyntaxer->preprocessorAttribute();
break; break;
case StatementKind::skKeyword: case StatementKind::Keyword:
attr = cppSyntaxer->keywordAttribute(); attr = cppSyntaxer->keywordAttribute();
break; break;
case StatementKind::skNamespace: case StatementKind::Namespace:
case StatementKind::skNamespaceAlias: case StatementKind::NamespaceAlias:
attr = cppSyntaxer->stringAttribute(); attr = cppSyntaxer->stringAttribute();
break; break;
default: default:

View File

@ -285,22 +285,22 @@ QPixmap IconsManager::getPixmapForStatement(PStatement statement)
return QPixmap(); return QPixmap();
StatementKind kind = getKindOfStatement(statement); StatementKind kind = getKindOfStatement(statement);
switch (kind) { switch (kind) {
case StatementKind::skTypedef: case StatementKind::Typedef:
return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE)); return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE));
case StatementKind::skClass: case StatementKind::Class:
return *(pIconsManager->getPixmap(IconsManager::PARSER_CLASS)); return *(pIconsManager->getPixmap(IconsManager::PARSER_CLASS));
case StatementKind::skNamespace: case StatementKind::Namespace:
case StatementKind::skNamespaceAlias: case StatementKind::NamespaceAlias:
return *(pIconsManager->getPixmap(IconsManager::PARSER_NAMESPACE)); return *(pIconsManager->getPixmap(IconsManager::PARSER_NAMESPACE));
case StatementKind::skPreprocessor: case StatementKind::Preprocessor:
return *(pIconsManager->getPixmap(IconsManager::PARSER_DEFINE)); return *(pIconsManager->getPixmap(IconsManager::PARSER_DEFINE));
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
case StatementKind::skEnumType: case StatementKind::EnumType:
case StatementKind::skEnum: case StatementKind::Enum:
return *(pIconsManager->getPixmap(IconsManager::PARSER_ENUM)); return *(pIconsManager->getPixmap(IconsManager::PARSER_ENUM));
case StatementKind::skFunction: case StatementKind::Function:
case StatementKind::skConstructor: case StatementKind::Constructor:
case StatementKind::skDestructor: case StatementKind::Destructor:
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()) {
@ -321,11 +321,11 @@ QPixmap IconsManager::getPixmapForStatement(PStatement statement)
} }
} }
break; break;
case StatementKind::skGlobalVariable: case StatementKind::GlobalVariable:
return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_VAR)); return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_VAR));
case StatementKind::skLocalVariable: case StatementKind::LocalVariable:
return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR)); return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR));
case StatementKind::skVariable: case StatementKind::Variable:
if (statement->isInherited()) { if (statement->isInherited()) {
if (statement->accessibility == StatementAccessibility::Protected) { if (statement->accessibility == StatementAccessibility::Protected) {
return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR)); return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR));
@ -344,11 +344,11 @@ QPixmap IconsManager::getPixmapForStatement(PStatement statement)
} }
} }
break; break;
case StatementKind::skKeyword: case StatementKind::Keyword:
return *(pIconsManager->getPixmap(IconsManager::PARSER_KEYWORD)); return *(pIconsManager->getPixmap(IconsManager::PARSER_KEYWORD));
case StatementKind::skUserCodeSnippet: case StatementKind::UserCodeSnippet:
return *(pIconsManager->getPixmap(IconsManager::PARSER_CODE_SNIPPET)); return *(pIconsManager->getPixmap(IconsManager::PARSER_CODE_SNIPPET));
case StatementKind::skAlias: case StatementKind::Alias:
return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE)); return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE));
default: default:
break; break;

View File

@ -156,7 +156,7 @@ QList<PStatement> CppParser::getListOfFunctions(const QString &fileName, const Q
PStatement statement = doFindStatementOf(fileName,phrase, line); PStatement statement = doFindStatementOf(fileName,phrase, line);
if (!statement) if (!statement)
return result; return result;
if (statement->kind == StatementKind::skPreprocessor) { if (statement->kind == StatementKind::Preprocessor) {
if (statement->args.isEmpty()) { if (statement->args.isEmpty()) {
QString name = expandMacro(statement->value); QString name = expandMacro(statement->value);
statement = doFindStatementOf(fileName, name ,line); statement = doFindStatementOf(fileName, name ,line);
@ -164,16 +164,16 @@ QList<PStatement> CppParser::getListOfFunctions(const QString &fileName, const Q
return result; return result;
} }
} }
while(statement && statement->kind == StatementKind::skAlias) while(statement && statement->kind == StatementKind::Alias)
statement = doFindAliasedStatement(statement); statement = doFindAliasedStatement(statement);
if (!statement) if (!statement)
return result; return result;
PStatement parentScope; PStatement parentScope;
if (statement->kind == StatementKind::skClass) { if (statement->kind == StatementKind::Class) {
parentScope = statement; parentScope = statement;
} else } else
parentScope = statement->parentScope.lock(); parentScope = statement->parentScope.lock();
if (parentScope && parentScope->kind == StatementKind::skNamespace) { if (parentScope && parentScope->kind == StatementKind::Namespace) {
PStatementList namespaceStatementsList = doFindNamespace(parentScope->command); PStatementList namespaceStatementsList = doFindNamespace(parentScope->command);
if (namespaceStatementsList) { if (namespaceStatementsList) {
for (PStatement& namespaceStatement : *namespaceStatementsList) { for (PStatement& namespaceStatement : *namespaceStatementsList) {
@ -237,9 +237,9 @@ PStatement CppParser::findFunctionAt(const QString &fileName, int line)
if (!fileIncludes) if (!fileIncludes)
return PStatement(); return PStatement();
for (PStatement& statement : fileIncludes->statements) { for (PStatement& statement : fileIncludes->statements) {
if (statement->kind != StatementKind::skFunction if (statement->kind != StatementKind::Function
&& statement->kind != StatementKind::skConstructor && statement->kind != StatementKind::Constructor
&& statement->kind != StatementKind::skDestructor) && statement->kind != StatementKind::Destructor)
continue; continue;
if (statement->line == line || statement->definitionLine == line) if (statement->line == line || statement->definitionLine == line)
return statement; return statement;
@ -297,7 +297,7 @@ PStatement CppParser::doFindStatement(const QString &fullname) const
for (int i=(phrases[0].isEmpty()?1:0);i<phrases.count();i++) { for (int i=(phrases[0].isEmpty()?1:0);i<phrases.count();i++) {
const QString& phrase=phrases[i]; const QString& phrase=phrases[i];
if (parentStatement && parentStatement->kind == StatementKind::skNamespace) { if (parentStatement && parentStatement->kind == StatementKind::Namespace) {
PStatementList lst = doFindNamespace(parentStatement->fullName); PStatementList lst = doFindNamespace(parentStatement->fullName);
foreach (const PStatement& namespaceStatement, *lst) { foreach (const PStatement& namespaceStatement, *lst) {
statement = findMemberOfStatement(phrase,namespaceStatement); statement = findMemberOfStatement(phrase,namespaceStatement);
@ -390,20 +390,20 @@ PStatement CppParser::doFindStatementOf(const QString &fileName,
return PStatement(); return PStatement();
} }
if (!memberName.isEmpty() && (statement->kind == StatementKind::skTypedef)) { if (!memberName.isEmpty() && (statement->kind == StatementKind::Typedef)) {
PStatement typeStatement = doFindTypeDefinitionOf(fileName,statement->type, parentScopeType); PStatement typeStatement = doFindTypeDefinitionOf(fileName,statement->type, parentScopeType);
if (typeStatement) if (typeStatement)
statement = typeStatement; statement = typeStatement;
} }
//using alias like 'using std::vector;' //using alias like 'using std::vector;'
while (statement->kind == StatementKind::skAlias) { while (statement->kind == StatementKind::Alias) {
statement = doFindAliasedStatement(statement); statement = doFindAliasedStatement(statement);
if (!statement) if (!statement)
return PStatement(); return PStatement();
} }
if (statement->kind == StatementKind::skConstructor) { if (statement->kind == StatementKind::Constructor) {
// we need the class, not the construtor // we need the class, not the construtor
statement = statement->parentScope.lock(); statement = statement->parentScope.lock();
if (!statement) if (!statement)
@ -413,17 +413,17 @@ PStatement CppParser::doFindStatementOf(const QString &fileName,
QString typeName; QString typeName;
PStatement typeStatement; PStatement typeStatement;
while (!memberName.isEmpty()) { while (!memberName.isEmpty()) {
if (statement->kind!=StatementKind::skClass if (statement->kind!=StatementKind::Class
&& operatorToken == "::") { && operatorToken == "::") {
return PStatement(); return PStatement();
} }
if (statement->kind == StatementKind::skVariable if (statement->kind == StatementKind::Variable
|| statement->kind == StatementKind::skParameter || statement->kind == StatementKind::Parameter
|| statement->kind == StatementKind::skFunction) { || statement->kind == StatementKind::Function) {
bool isSTLContainerFunctions = false; bool isSTLContainerFunctions = false;
if (statement->kind == StatementKind::skFunction){ if (statement->kind == StatementKind::Function){
PStatement parentScope = statement->parentScope.lock(); PStatement parentScope = statement->parentScope.lock();
if (parentScope if (parentScope
&& STLContainers.contains(parentScope->fullName) && STLContainers.contains(parentScope->fullName)
@ -488,7 +488,7 @@ PStatement CppParser::doFindStatementOf(const QString &fileName,
parentScopeType=statement; parentScopeType=statement;
statement = memberStatement; statement = memberStatement;
if (!memberName.isEmpty() && (statement->kind == StatementKind::skTypedef)) { if (!memberName.isEmpty() && (statement->kind == StatementKind::Typedef)) {
PStatement typeStatement = doFindTypeDefinitionOf(fileName,statement->type, parentScopeType); PStatement typeStatement = doFindTypeDefinitionOf(fileName,statement->type, parentScopeType);
if (typeStatement) if (typeStatement)
statement = typeStatement; statement = typeStatement;
@ -556,7 +556,7 @@ PStatement CppParser::doFindStatementOf(const QString &fileName, const QStringLi
return PStatement(); return PStatement();
} }
if (ownerEvalStatement->effectiveTypeStatement && if (ownerEvalStatement->effectiveTypeStatement &&
ownerEvalStatement->effectiveTypeStatement->kind == StatementKind::skNamespace) { ownerEvalStatement->effectiveTypeStatement->kind == StatementKind::Namespace) {
PStatementList lst = doFindNamespace(ownerEvalStatement->effectiveTypeStatement->fullName); PStatementList lst = doFindNamespace(ownerEvalStatement->effectiveTypeStatement->fullName);
foreach (const PStatement& namespaceStatement, *lst) { foreach (const PStatement& namespaceStatement, *lst) {
PStatement statement = findMemberOfStatement(phrase,namespaceStatement); PStatement statement = findMemberOfStatement(phrase,namespaceStatement);
@ -639,14 +639,14 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement) const
PStatement CppParser::doFindNoTemplateSpecializationClass(const PStatement &statement) const PStatement CppParser::doFindNoTemplateSpecializationClass(const PStatement &statement) const
{ {
Q_ASSERT(statement!=nullptr); Q_ASSERT(statement!=nullptr);
Q_ASSERT(statement->kind == StatementKind::skClass); Q_ASSERT(statement->kind == StatementKind::Class);
if (statement->templateSpecializationParams.isEmpty()) if (statement->templateSpecializationParams.isEmpty())
return statement; return statement;
PStatement parent = statement->parentScope.lock(); PStatement parent = statement->parentScope.lock();
const StatementMap & statementMap = mStatementList.childrenStatements(parent); const StatementMap & statementMap = mStatementList.childrenStatements(parent);
QList<PStatement> list = statementMap.values(statement->command); QList<PStatement> list = statementMap.values(statement->command);
foreach(const PStatement &child, list) { foreach(const PStatement &child, list) {
if (child->kind == StatementKind::skClass if (child->kind == StatementKind::Class
&& child->templateSpecializationParams.isEmpty()) && child->templateSpecializationParams.isEmpty())
return child; return child;
} }
@ -697,7 +697,7 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<S
return PStatement(); return PStatement();
if (foundSet.contains(result.get())) if (foundSet.contains(result.get()))
return PStatement(); return PStatement();
if (result->kind == StatementKind::skAlias) if (result->kind == StatementKind::Alias)
result = doFindAliasedStatement(result, foundSet); result = doFindAliasedStatement(result, foundSet);
return result; return result;
} }
@ -821,7 +821,7 @@ QStringList CppParser::getClassesList()
PStatement statement = queue.dequeue(); PStatement statement = queue.dequeue();
StatementMap statementMap = mStatementList.childrenStatements(statement); StatementMap statementMap = mStatementList.childrenStatements(statement);
for (PStatement& child:statementMap) { for (PStatement& child:statementMap) {
if (child->kind == StatementKind::skClass) if (child->kind == StatementKind::Class)
list.append(child->command); list.append(child->command);
if (!child->children.isEmpty()) if (!child->children.isEmpty())
queue.enqueue(child); queue.enqueue(child);
@ -1119,10 +1119,10 @@ void CppParser::parseHardDefines()
"", "",
define->value, define->value,
-1, -1,
StatementKind::skPreprocessor, StatementKind::Preprocessor,
StatementScope::Global, StatementScope::Global,
StatementAccessibility::None, StatementAccessibility::None,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
} }
} }
@ -1214,7 +1214,7 @@ QString CppParser::prettyPrintStatement(const PStatement& statement, const QStri
{ {
QString result; QString result;
switch(statement->kind) { switch(statement->kind) {
case StatementKind::skPreprocessor: case StatementKind::Preprocessor:
if (statement->command == "__FILE__") if (statement->command == "__FILE__")
result = '"'+filename+'"'; result = '"'+filename+'"';
else if (statement->command == "__LINE__") else if (statement->command == "__LINE__")
@ -1234,13 +1234,13 @@ QString CppParser::prettyPrintStatement(const PStatement& statement, const QStri
result = hintText; result = hintText;
} }
break; break;
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
result = "enum class "+statement->command; result = "enum class "+statement->command;
break; break;
case StatementKind::skEnumType: case StatementKind::EnumType:
result = "enum "+statement->command; result = "enum "+statement->command;
break; break;
case StatementKind::skEnum: case StatementKind::Enum:
if (!statement->type.isEmpty()) if (!statement->type.isEmpty())
result = statement->type + "::"; result = statement->type + "::";
else else
@ -1249,35 +1249,35 @@ QString CppParser::prettyPrintStatement(const PStatement& statement, const QStri
if (!statement->value.isEmpty()) if (!statement->value.isEmpty())
result += "(" + statement->value + ")"; result += "(" + statement->value + ")";
break; break;
case StatementKind::skTypedef: case StatementKind::Typedef:
result = "typedef "+statement->type+" "+statement->command; result = "typedef "+statement->type+" "+statement->command;
if (!statement->args.isEmpty()) if (!statement->args.isEmpty())
result += " "+statement->args; result += " "+statement->args;
break; break;
case StatementKind::skAlias: case StatementKind::Alias:
result = "using "+statement->type; result = "using "+statement->type;
break; break;
case StatementKind::skFunction: case StatementKind::Function:
case StatementKind::skVariable: case StatementKind::Variable:
case StatementKind::skParameter: case StatementKind::Parameter:
case StatementKind::skClass: case StatementKind::Class:
if (statement->scope!= StatementScope::Local) if (statement->scope!= StatementScope::Local)
result = getScopePrefix(statement)+ ' '; // public result = getScopePrefix(statement)+ ' '; // public
result += statement->type + ' '; // void result += statement->type + ' '; // void
result += statement->fullName; // A::B::C::Bar result += statement->fullName; // A::B::C::Bar
result += statement->args; // (int a) result += statement->args; // (int a)
break; break;
case StatementKind::skNamespace: case StatementKind::Namespace:
result = statement->fullName; // Bar result = statement->fullName; // Bar
break; break;
case StatementKind::skConstructor: case StatementKind::Constructor:
result = getScopePrefix(statement); // public result = getScopePrefix(statement); // public
result += QObject::tr("constructor") + ' '; // constructor result += QObject::tr("constructor") + ' '; // constructor
result += statement->type + ' '; // void result += statement->type + ' '; // void
result += statement->fullName; // A::B::C::Bar result += statement->fullName; // A::B::C::Bar
result += statement->args; // (int a) result += statement->args; // (int a)
break; break;
case StatementKind::skDestructor: case StatementKind::Destructor:
result = getScopePrefix(statement); // public result = getScopePrefix(statement); // public
result += QObject::tr("destructor") + ' '; // constructor result += QObject::tr("destructor") + ' '; // constructor
result += statement->type + ' '; // void result += statement->type + ' '; // void
@ -1298,7 +1298,7 @@ QString CppParser::getTemplateParam(const PStatement& statement,
{ {
if (!statement) if (!statement)
return ""; return "";
if (statement->kind != StatementKind::skTypedef) if (statement->kind != StatementKind::Typedef)
return ""; return "";
if (statement->type == phrase) // prevent infinite loop if (statement->type == phrase) // prevent infinite loop
return ""; return "";
@ -1368,7 +1368,7 @@ PStatement CppParser::addInheritedStatement(const PStatement& derived, const PSt
inherit->kind, inherit->kind,
inherit->scope, inherit->scope,
access, access,
inherit->properties | StatementProperty::spInherited); inherit->properties | StatementProperty::Inherited);
return statement; return statement;
} }
@ -1424,13 +1424,13 @@ PStatement CppParser::addStatement(const PStatement& parent,
// if (newCommand.startsWith("::") && parent && kind!=StatementKind::skBlock ) { // if (newCommand.startsWith("::") && parent && kind!=StatementKind::skBlock ) {
// qDebug()<<command<<fileName<<line<<kind<<parent->fullName; // qDebug()<<command<<fileName<<line<<kind<<parent->fullName;
// } // }
if (kind == StatementKind::skConstructor if (kind == StatementKind::Constructor
|| kind == StatementKind::skFunction || kind == StatementKind::Function
|| kind == StatementKind::skDestructor || kind == StatementKind::Destructor
|| kind == StatementKind::skVariable || kind == StatementKind::Variable
) { ) {
//find //find
if (properties.testFlag(StatementProperty::spHasDefinition)) { if (properties.testFlag(StatementProperty::HasDefinition)) {
PStatement oldStatement = findStatementInScope(newCommand,noNameArgs,kind,parent); PStatement oldStatement = findStatementInScope(newCommand,noNameArgs,kind,parent);
if (oldStatement && !oldStatement->hasDefinition()) { if (oldStatement && !oldStatement->hasDefinition()) {
oldStatement->setHasDefinition(true); oldStatement->setHasDefinition(true);
@ -1486,7 +1486,7 @@ PStatement CppParser::addStatement(const PStatement& parent,
result->value.squeeze(); result->value.squeeze();
result->type.squeeze(); result->type.squeeze();
mStatementList.add(result); mStatementList.add(result);
if (result->kind == StatementKind::skNamespace) { if (result->kind == StatementKind::Namespace) {
PStatementList namespaceList = mNamespaces.value(result->fullName,PStatementList()); PStatementList namespaceList = mNamespaces.value(result->fullName,PStatementList());
if (!namespaceList) { if (!namespaceList) {
namespaceList=std::make_shared<StatementList>(); namespaceList=std::make_shared<StatementList>();
@ -1495,7 +1495,7 @@ PStatement CppParser::addStatement(const PStatement& parent,
namespaceList->append(result); namespaceList->append(result);
} }
if (result->kind!= StatementKind::skBlock) { if (result->kind!= StatementKind::Block) {
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(fileName); PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(fileName);
if (fileIncludes) { if (fileIncludes) {
fileIncludes->statements.insert(result->fullName,result); fileIncludes->statements.insert(result->fullName,result);
@ -1616,10 +1616,10 @@ void CppParser::addMethodParameterStatement(QStringList words, int line, const P
"", "",
"", "",
line, line,
StatementKind::skParameter, StatementKind::Parameter,
StatementScope::Local, StatementScope::Local,
StatementAccessibility::None, StatementAccessibility::None,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
} }
} }
@ -1728,9 +1728,9 @@ void CppParser::addSoloScopeLevel(PStatement& statement, int line, bool shouldRe
// Add class list // Add class list
PStatement parentScope; PStatement parentScope;
if (shouldResetBlock && statement && (statement->kind == StatementKind::skBlock)) { if (shouldResetBlock && statement && (statement->kind == StatementKind::Block)) {
parentScope = statement->parentScope.lock(); parentScope = statement->parentScope.lock();
while (parentScope && (parentScope->kind == StatementKind::skBlock)) { while (parentScope && (parentScope->kind == StatementKind::Block)) {
parentScope = parentScope->parentScope.lock(); parentScope = parentScope->parentScope.lock();
} }
if (!parentScope) if (!parentScope)
@ -1752,7 +1752,7 @@ void CppParser::addSoloScopeLevel(PStatement& statement, int line, bool shouldRe
// Set new scope // Set new scope
if (!statement) if (!statement)
mCurrentMemberAccessibility = StatementAccessibility::None; // {}, namespace or class that doesn't exist mCurrentMemberAccessibility = StatementAccessibility::None; // {}, namespace or class that doesn't exist
else if (statement->kind == StatementKind::skNamespace) else if (statement->kind == StatementKind::Namespace)
mCurrentMemberAccessibility = StatementAccessibility::None; mCurrentMemberAccessibility = StatementAccessibility::None;
else if (statement->type == "class") else if (statement->type == "class")
mCurrentMemberAccessibility = StatementAccessibility::Private; // classes are private by default mCurrentMemberAccessibility = StatementAccessibility::Private; // classes are private by default
@ -1777,7 +1777,7 @@ void CppParser::removeScopeLevel(int line, int maxIndex)
PStatement currentScope = getCurrentScope(); PStatement currentScope = getCurrentScope();
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile); PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(mCurrentFile);
if (currentScope) { if (currentScope) {
if (currentScope->kind == StatementKind::skBlock) { if (currentScope->kind == StatementKind::Block) {
if (currentScope->children.isEmpty()) { if (currentScope->children.isEmpty()) {
// remove no children block // remove no children block
if (fileIncludes) if (fileIncludes)
@ -1787,7 +1787,7 @@ void CppParser::removeScopeLevel(int line, int maxIndex)
if (fileIncludes) if (fileIncludes)
fileIncludes->statements.insert(currentScope->fullName,currentScope); fileIncludes->statements.insert(currentScope->fullName,currentScope);
} }
} else if (currentScope->kind == StatementKind::skClass) { } else if (currentScope->kind == StatementKind::Class) {
mIndex=indexOfNextSemicolon(mIndex, maxIndex); mIndex=indexOfNextSemicolon(mIndex, maxIndex);
} }
} }
@ -1998,10 +1998,10 @@ int CppParser::evaluateConstExprTerm(int endIndex, bool &ok)
ok=false; ok=false;
return result; return result;
} }
if (statement->kind == StatementKind::skEnum) { if (statement->kind == StatementKind::Enum) {
result = statement->value.toInt(&ok); result = statement->value.toInt(&ok);
break; break;
} else if (statement->kind == StatementKind::skAlias) { } else if (statement->kind == StatementKind::Alias) {
s = statement->value; s = statement->value;
} else { } else {
ok=false; ok=false;
@ -2207,7 +2207,7 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex)
// operator overloading like (operator int) // operator overloading like (operator int)
if (mTokenizer[mIndex+1]->text=="operator") { if (mTokenizer[mIndex+1]->text=="operator") {
mIndex=indexAfterParentheis; mIndex=indexAfterParentheis;
handleMethod(StatementKind::skFunction,"", handleMethod(StatementKind::Function,"",
mergeArgs(mIndex+1,mTokenizer[mIndex]->matchIndex-1), mergeArgs(mIndex+1,mTokenizer[mIndex]->matchIndex-1),
indexAfterParentheis,false,false,true, maxIndex); indexAfterParentheis,false,false,true, maxIndex);
} else { } else {
@ -2234,7 +2234,7 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex)
if (name.startsWith('~')) if (name.startsWith('~'))
name=name.mid(1); name=name.mid(1);
if (removeTemplateParams(name)==removeTemplateParams(parentName)) { if (removeTemplateParams(name)==removeTemplateParams(parentName)) {
handleMethod( (isDestructor?StatementKind::skDestructor:StatementKind::skConstructor), handleMethod( (isDestructor?StatementKind::Destructor:StatementKind::Constructor),
"", "",
currentText, currentText,
mIndex,false,false, false, maxIndex); mIndex,false,false, false, maxIndex);
@ -2246,9 +2246,9 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex)
// Foo(); // Foo();
// }; // };
PStatement scope=getCurrentScope(); PStatement scope=getCurrentScope();
if (scope && scope->kind==StatementKind::skClass if (scope && scope->kind==StatementKind::Class
&& removeTemplateParams(scope->command) == removeTemplateParams(currentText)) { && removeTemplateParams(scope->command) == removeTemplateParams(currentText)) {
handleMethod(StatementKind::skConstructor,"", handleMethod(StatementKind::Constructor,"",
currentText, currentText,
mIndex,false,false, false, maxIndex); mIndex,false,false, false, maxIndex);
return; return;
@ -2343,13 +2343,13 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex)
PStatement currentScope=getCurrentScope(); PStatement currentScope=getCurrentScope();
if (currentScope) { if (currentScope) {
//in namespace, it might be function or object initilization //in namespace, it might be function or object initilization
if (currentScope->kind == StatementKind::skNamespace) { if (currentScope->kind == StatementKind::Namespace) {
if (isNotFuncArgs(mIndex + 1)) { if (isNotFuncArgs(mIndex + 1)) {
// var decl with init // var decl with init
handleVar(sType+" "+sName,isExtern,isStatic, maxIndex); handleVar(sType+" "+sName,isExtern,isStatic, maxIndex);
return; return;
} }
} else if (currentScope->kind != StatementKind::skClass) { } else if (currentScope->kind != StatementKind::Class) {
//not in class, it can't be a valid function definition //not in class, it can't be a valid function definition
// var decl with init // var decl with init
handleVar(sType+" "+sName,isExtern,isStatic, maxIndex); handleVar(sType+" "+sName,isExtern,isStatic, maxIndex);
@ -2378,15 +2378,15 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex)
mIndex++; mIndex++;
if (isDestructor) if (isDestructor)
handleMethod(StatementKind::skDestructor,sType, handleMethod(StatementKind::Destructor,sType,
sName,mIndex,false,isFriend, false, maxIndex); sName,mIndex,false,isFriend, false, maxIndex);
else { else {
sType=sType.trimmed(); sType=sType.trimmed();
if (sType.isEmpty()) if (sType.isEmpty())
handleMethod(StatementKind::skConstructor,sType, handleMethod(StatementKind::Constructor,sType,
sName,mIndex,false,isFriend, false, maxIndex); sName,mIndex,false,isFriend, false, maxIndex);
else else
handleMethod(StatementKind::skFunction,sType, handleMethod(StatementKind::Function,sType,
sName,mIndex,isStatic,isFriend, false, maxIndex); sName,mIndex,isStatic,isFriend, false, maxIndex);
} }
@ -2569,7 +2569,7 @@ PStatement CppParser::getIncompleteClass(const QString &command, const PStatemen
s.truncate(p); s.truncate(p);
} }
PStatement result = doFindStatementOf(mCurrentFile,s,parentScope); PStatement result = doFindStatementOf(mCurrentFile,s,parentScope);
if (result && result->kind!=StatementKind::skClass) if (result && result->kind!=StatementKind::Class)
return PStatement(); return PStatement();
return result; return result;
} }
@ -2580,9 +2580,9 @@ StatementScope CppParser::getScope()
PStatement currentScope = getCurrentScope(); PStatement currentScope = getCurrentScope();
// Invalid class or namespace/extern // Invalid class or namespace/extern
if (!currentScope || (currentScope->kind == StatementKind::skNamespace)) if (!currentScope || (currentScope->kind == StatementKind::Namespace))
return StatementScope::Global; return StatementScope::Global;
else if (currentScope->kind == StatementKind::skClass) else if (currentScope->kind == StatementKind::Class)
return StatementScope::ClassLocal; return StatementScope::ClassLocal;
else else
return StatementScope::Local; return StatementScope::Local;
@ -2599,18 +2599,18 @@ PStatement CppParser::getTypeDef(const PStatement& statement,
if (!statement) { if (!statement) {
return PStatement(); return PStatement();
} }
if (statement->kind == StatementKind::skClass if (statement->kind == StatementKind::Class
|| statement->kind == StatementKind::skEnumType || statement->kind == StatementKind::EnumType
|| statement->kind == StatementKind::skEnumClassType) { || statement->kind == StatementKind::EnumClassType) {
return statement; return statement;
} else if (statement->kind == StatementKind::skTypedef) { } else if (statement->kind == StatementKind::Typedef) {
if (statement->type == aType) // prevent infinite loop if (statement->type == aType) // prevent infinite loop
return statement; return statement;
PStatement result = doFindTypeDefinitionOf(fileName,statement->type, statement->parentScope.lock()); PStatement result = doFindTypeDefinitionOf(fileName,statement->type, statement->parentScope.lock());
if (!result) // found end of typedef trail, return result if (!result) // found end of typedef trail, return result
return statement; return statement;
return result; return result;
} else if (statement->kind == StatementKind::skAlias) { } else if (statement->kind == StatementKind::Alias) {
PStatement result = doFindAliasedStatement(statement); PStatement result = doFindAliasedStatement(statement);
if (!result) // found end of typedef trail, return result if (!result) // found end of typedef trail, return result
return statement; return statement;
@ -2703,10 +2703,10 @@ void CppParser::handleEnum(bool isTypedef, int maxIndex)
"", "",
"", "",
startLine, startLine,
StatementKind::skEnumClassType, StatementKind::EnumClassType,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} else { } else {
enumStatement=addStatement( enumStatement=addStatement(
getCurrentScope(), getCurrentScope(),
@ -2717,11 +2717,11 @@ void CppParser::handleEnum(bool isTypedef, int maxIndex)
"", "",
"", "",
startLine, startLine,
StatementKind::skEnumType, StatementKind::EnumType,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
isAdhocVar?(StatementProperty::spHasDefinition|StatementProperty::spDummyStatement) isAdhocVar?(StatementProperty::HasDefinition|StatementProperty::DummyStatement)
:StatementProperty::spHasDefinition ); :StatementProperty::HasDefinition );
} }
} }
if (isAdhocVar) { if (isAdhocVar) {
@ -2745,10 +2745,10 @@ void CppParser::handleEnum(bool isTypedef, int maxIndex)
"", "",
"", "",
mTokenizer[i]->line, mTokenizer[i]->line,
StatementKind::skVariable, StatementKind::Variable,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
} else if (name!=',') { } else if (name!=',') {
break; break;
@ -2795,10 +2795,10 @@ void CppParser::handleEnum(bool isTypedef, int maxIndex)
"", "",
canCalcValue?QString("%1").arg(value):"", canCalcValue?QString("%1").arg(value):"",
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skEnum, StatementKind::Enum,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
} else { } else {
QString strValue=canCalcValue?QString("%1").arg(value):""; QString strValue=canCalcValue?QString("%1").arg(value):"";
@ -2812,10 +2812,10 @@ void CppParser::handleEnum(bool isTypedef, int maxIndex)
"", "",
strValue, strValue,
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skEnum, StatementKind::Enum,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
addStatement( addStatement(
getCurrentScope(), getCurrentScope(),
@ -2826,10 +2826,10 @@ void CppParser::handleEnum(bool isTypedef, int maxIndex)
"", "",
strValue, strValue,
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skEnum, StatementKind::Enum,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
value++; value++;
} }
@ -2924,10 +2924,10 @@ void CppParser::handleLambda(int index, int maxIndex)
"", "",
"", "",
startLine, startLine,
StatementKind::skLambda, StatementKind::Lambda,
StatementScope::Local, StatementScope::Local,
StatementAccessibility::None, StatementAccessibility::None,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
lambdaBlock->lambdaCaptures = captures; lambdaBlock->lambdaCaptures = captures;
scanMethodArgs(lambdaBlock,argStart); scanMethodArgs(lambdaBlock,argStart);
addSoloScopeLevel(lambdaBlock,mTokenizer[bodyStart]->line); addSoloScopeLevel(lambdaBlock,mTokenizer[bodyStart]->line);
@ -2978,7 +2978,7 @@ void CppParser::handleOperatorOverloading(const QString &sType,
} }
Q_ASSERT(!op.isEmpty()); Q_ASSERT(!op.isEmpty());
if (isIdentChar(op.front())) { if (isIdentChar(op.front())) {
handleMethod(StatementKind::skFunction, handleMethod(StatementKind::Function,
sType+" "+op, sType+" "+op,
"operator("+op+")", "operator("+op+")",
index, index,
@ -2987,7 +2987,7 @@ void CppParser::handleOperatorOverloading(const QString &sType,
true, true,
maxIndex); maxIndex);
} else { } else {
handleMethod(StatementKind::skFunction, handleMethod(StatementKind::Function,
sType, sType,
"operator"+op, "operator"+op,
index, index,
@ -3085,12 +3085,12 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
functionKind, functionKind,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition StatementProperty::HasDefinition
| (isStatic?StatementProperty::spStatic:StatementProperty::spNone) | (isStatic?StatementProperty::Static:StatementProperty::None)
| (isOperatorOverload?StatementProperty::spOperatorOverloading:StatementProperty::spNone)); | (isOperatorOverload?StatementProperty::OperatorOverloading:StatementProperty::None));
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::Class &&
!isStatic) { !isStatic) {
//add this to non-static class member function //add this to non-static class member function
addStatement( addStatement(
@ -3102,11 +3102,11 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
"", "",
"", "",
startLine, startLine,
StatementKind::skVariable, StatementKind::Variable,
StatementScope::Local, StatementScope::Local,
StatementAccessibility::None, StatementAccessibility::None,
StatementProperty::spHasDefinition StatementProperty::HasDefinition
| (isOperatorOverload?StatementProperty::spOperatorOverloading:StatementProperty::spNone)); | (isOperatorOverload?StatementProperty::OperatorOverloading:StatementProperty::None));
} }
// add "__func__ variable" // add "__func__ variable"
@ -3119,11 +3119,11 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
"", "",
"\""+scopelessName+"\"", "\""+scopelessName+"\"",
startLine+1, startLine+1,
StatementKind::skVariable, StatementKind::Variable,
StatementScope::Local, StatementScope::Local,
StatementAccessibility::None, StatementAccessibility::None,
StatementProperty::spHasDefinition StatementProperty::HasDefinition
| (isOperatorOverload?StatementProperty::spOperatorOverloading:StatementProperty::spNone)); | (isOperatorOverload?StatementProperty::OperatorOverloading:StatementProperty::None));
} else { } else {
functionStatement = addStatement( functionStatement = addStatement(
@ -3139,8 +3139,8 @@ void CppParser::handleMethod(StatementKind functionKind,const QString &sType, co
functionKind, functionKind,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
(isStatic?StatementProperty::spStatic:StatementProperty::spNone) (isStatic?StatementProperty::Static:StatementProperty::None)
| (isOperatorOverload?StatementProperty::spOperatorOverloading:StatementProperty::spNone)); | (isOperatorOverload?StatementProperty::OperatorOverloading:StatementProperty::None));
} }
} }
@ -3211,10 +3211,10 @@ void CppParser::handleNamespace(KeywordType skipType, int maxIndex)
"", // values "", // values
//mTokenizer[mIndex]^.Line, //mTokenizer[mIndex]^.Line,
startLine, startLine,
StatementKind::skNamespaceAlias, StatementKind::NamespaceAlias,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
mIndex++; // skip ; mIndex++; // skip ;
return; return;
} else if (isInline) { } else if (isInline) {
@ -3239,10 +3239,10 @@ void CppParser::handleNamespace(KeywordType skipType, int maxIndex)
"", // noname args "", // noname args
"", // values "", // values
startLine, startLine,
StatementKind::skNamespace, StatementKind::Namespace,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
// find next '{' or ';' // find next '{' or ';'
mIndex = indexOfNextSemicolonOrLeftBrace(mIndex, maxIndex); mIndex = indexOfNextSemicolonOrLeftBrace(mIndex, maxIndex);
@ -3337,10 +3337,10 @@ void CppParser::handleOtherTypedefs(int maxIndex)
"", "",
"", "",
startLine, startLine,
StatementKind::skTypedef, StatementKind::Typedef,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
tempType=""; tempType="";
} }
mIndex = mTokenizer[paramStart]->matchIndex+1; mIndex = mTokenizer[paramStart]->matchIndex+1;
@ -3360,10 +3360,10 @@ void CppParser::handleOtherTypedefs(int maxIndex)
"", "",
"", "",
startLine, startLine,
StatementKind::skTypedef, StatementKind::Typedef,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
tempType=""; tempType="";
newType = ""; newType = "";
mIndex++; mIndex++;
@ -3429,10 +3429,10 @@ void CppParser::handlePreprocessor()
"",// noname args "",// noname args
value, value,
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skPreprocessor, StatementKind::Preprocessor,
StatementScope::Global, StatementScope::Global,
StatementAccessibility::None, StatementAccessibility::None,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} // TODO: undef ( define has limited scope) } // TODO: undef ( define has limited scope)
handlePreprocessorEnd: handlePreprocessorEnd:
mIndex++; mIndex++;
@ -3496,10 +3496,10 @@ bool CppParser::handleStatement(int maxIndex)
"", "",
//mTokenizer[mIndex]^.Line, //mTokenizer[mIndex]^.Line,
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skBlock, StatementKind::Block,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
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] == '}') {
@ -3524,7 +3524,7 @@ bool CppParser::handleStatement(int maxIndex)
&& isIdentChar(mTokenizer[mIndex+1]->text[0]) && isIdentChar(mTokenizer[mIndex+1]->text[0])
&& mTokenizer[mIndex+2]->text=='(') { && mTokenizer[mIndex+2]->text=='(') {
//dont further check to speed up //dont further check to speed up
handleMethod(StatementKind::skDestructor, "", '~'+mTokenizer[mIndex+1]->text, mIndex+2, false, false, false, maxIndex); handleMethod(StatementKind::Destructor, "", '~'+mTokenizer[mIndex+1]->text, mIndex+2, false, false, false, maxIndex);
} else { } else {
//error //error
mIndex=moveToEndOfStatement(mIndex,false, maxIndex); mIndex=moveToEndOfStatement(mIndex,false, maxIndex);
@ -3633,10 +3633,10 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
"", // noname args "", // noname args
"", // values "", // values
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skTypedef, StatementKind::Typedef,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
tempType=""; tempType="";
mIndex++; //skip , ; mIndex++; //skip , ;
if (mTokenizer[mIndex]->text.front() == ';') if (mTokenizer[mIndex]->text.front() == ';')
@ -3695,10 +3695,10 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
"", // values "", // values
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
//startLine, //startLine,
StatementKind::skClass, StatementKind::Class,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
command = ""; command = "";
} }
mIndex++; mIndex++;
@ -3720,10 +3720,10 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
"", // values "", // values
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
//startLine, //startLine,
StatementKind::skClass, StatementKind::Class,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
command=""; command="";
} }
mIndex+=2; mIndex+=2;
@ -3790,10 +3790,10 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
"", "",
mTokenizer[i]->line, mTokenizer[i]->line,
//startLine, //startLine,
StatementKind::skClass, StatementKind::Class,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition | StatementProperty::spDummyStatement); StatementProperty::HasDefinition | StatementProperty::DummyStatement);
} }
if (isTypedef) { if (isTypedef) {
//typedef //typedef
@ -3806,10 +3806,10 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
"", "",
"", "",
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skTypedef, StatementKind::Typedef,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); // typedef StatementProperty::HasDefinition); // typedef
} else { } else {
//variable define //variable define
addStatement( addStatement(
@ -3821,10 +3821,10 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
"", "",
"", "",
mTokenizer[i]->line, mTokenizer[i]->line,
StatementKind::skVariable, StatementKind::Variable,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); // TODO: not supported to pass list StatementProperty::HasDefinition); // TODO: not supported to pass list
} }
} }
command = ""; command = "";
@ -3841,7 +3841,7 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
} }
if (!firstSynonym) { if (!firstSynonym) {
PStatement scope = getCurrentScope(); PStatement scope = getCurrentScope();
if (scope && scope->kind == StatementKind::skClass if (scope && scope->kind == StatementKind::Class
&& mIndex<maxIndex && mTokenizer[mIndex]->text=="{") { && mIndex<maxIndex && mTokenizer[mIndex]->text=="{") {
//C11 anonymous union/struct //C11 anonymous union/struct
addSoloScopeLevel(scope, mTokenizer[mIndex]->line); addSoloScopeLevel(scope, mTokenizer[mIndex]->line);
@ -3859,10 +3859,10 @@ void CppParser::handleStructs(bool isTypedef, int maxIndex)
"", "",
"", "",
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skBlock, StatementKind::Block,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
} }
if (mIndex < maxIndex) if (mIndex < maxIndex)
@ -3907,10 +3907,10 @@ void CppParser::handleUsing(int maxIndex)
"", // noname args "", // noname args
"", // values "", // values
startLine, startLine,
StatementKind::skTypedef, StatementKind::Typedef,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
// skip ; // skip ;
mIndex++; mIndex++;
return; return;
@ -3944,10 +3944,10 @@ void CppParser::handleUsing(int maxIndex)
"", // noname args "", // noname args
"", // values "", // values
startLine, startLine,
StatementKind::skAlias, StatementKind::Alias,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
//skip ; //skip ;
mIndex++; mIndex++;
@ -4023,7 +4023,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic,
&& isIdentChar(mTokenizer[mIndex+1]->text.front()) && isIdentChar(mTokenizer[mIndex+1]->text.front())
&& (isIdentChar(mTokenizer[mIndex+1]->text.back()) || isDigitChar(mTokenizer[mIndex+1]->text.back())) && (isIdentChar(mTokenizer[mIndex+1]->text.back()) || isDigitChar(mTokenizer[mIndex+1]->text.back()))
&& addedVar && addedVar
&& !(addedVar->properties & StatementProperty::spFunctionPointer) && !(addedVar->properties & StatementProperty::FunctionPointer)
&& AutoTypes.contains(addedVar->type)) { && AutoTypes.contains(addedVar->type)) {
//handle e.g.: for(auto x:vec) //handle e.g.: for(auto x:vec)
// for(auto x:vec ) is replaced by "for { auto x: vec ;" in handleForAndCatch(); // for(auto x:vec ) is replaced by "for { auto x: vec ;" in handleForAndCatch();
@ -4082,7 +4082,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic,
if (mIndex+1<maxIndex if (mIndex+1<maxIndex
&& mTokenizer[mIndex+1]->text!="{" && mTokenizer[mIndex+1]->text!="{"
&& addedVar && addedVar
&& !(addedVar->properties & StatementProperty::spFunctionPointer) && !(addedVar->properties & StatementProperty::FunctionPointer)
&& AutoTypes.contains(addedVar->type)) { && AutoTypes.contains(addedVar->type)) {
//handle e.g.: auto x=blahblah; //handle e.g.: auto x=blahblah;
int pos = 0; int pos = 0;
@ -4156,13 +4156,13 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic,
"", "",
"", "",
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skVariable, StatementKind::Variable,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
//True, //True,
(isExtern?StatementProperty::spNone:StatementProperty::spHasDefinition) (isExtern?StatementProperty::None:StatementProperty::HasDefinition)
| (isStatic?StatementProperty::spStatic:StatementProperty::spNone) | (isStatic?StatementProperty::Static:StatementProperty::None)
| StatementProperty::spFunctionPointer); | StatementProperty::FunctionPointer);
} }
addedVar.reset(); addedVar.reset();
tempType=""; tempType="";
@ -4176,7 +4176,7 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic,
if (mIndex+1<maxIndex if (mIndex+1<maxIndex
&& isIdentifier(mTokenizer[mIndex+1]->text) && isIdentifier(mTokenizer[mIndex+1]->text)
&& addedVar && addedVar
&& !(addedVar->properties & StatementProperty::spFunctionPointer) && !(addedVar->properties & StatementProperty::FunctionPointer)
&& AutoTypes.contains(addedVar->type)) { && AutoTypes.contains(addedVar->type)) {
int pos = 0; int pos = 0;
int endIndex = mTokenizer[mIndex]->matchIndex; int endIndex = mTokenizer[mIndex]->matchIndex;
@ -4244,12 +4244,12 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic,
"", "",
"", "",
mTokenizer[mIndex]->line, mTokenizer[mIndex]->line,
StatementKind::skVariable, StatementKind::Variable,
getScope(), getScope(),
mCurrentMemberAccessibility, mCurrentMemberAccessibility,
//True, //True,
(isExtern?StatementProperty::spNone:StatementProperty::spHasDefinition) (isExtern?StatementProperty::None:StatementProperty::HasDefinition)
| (isStatic?StatementProperty::spStatic:StatementProperty::spNone)); | (isStatic?StatementProperty::Static:StatementProperty::None));
tempType=""; tempType="";
} }
} }
@ -4273,7 +4273,7 @@ void CppParser::handleInheritance(PStatement derivedStatement, PClassInheritance
inheritanceInfo->parentClassName, inheritanceInfo->parentClassName,
inheritanceInfo->isGlobal?PStatement():derivedStatement->parentScope.lock()); inheritanceInfo->isGlobal?PStatement():derivedStatement->parentScope.lock());
if (statement && statement->kind == StatementKind::skClass) { if (statement && statement->kind == StatementKind::Class) {
inheritClassStatement(derivedStatement, inheritClassStatement(derivedStatement,
inheritanceInfo->isStruct, inheritanceInfo->isStruct,
statement, statement,
@ -4418,8 +4418,8 @@ void CppParser::inheritClassStatement(const PStatement& derived, bool isStruct,
} }
foreach (const PStatement& statement, base->children) { foreach (const PStatement& statement, base->children) {
if (statement->accessibility == StatementAccessibility::Private if (statement->accessibility == StatementAccessibility::Private
|| statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::Constructor
|| statement->kind == StatementKind::skDestructor) || statement->kind == StatementKind::Destructor)
continue; continue;
if (derived->children.contains(statement->command)) { if (derived->children.contains(statement->command)) {
// Check if it's overwritten(hidden) by the derived // Check if it's overwritten(hidden) by the derived
@ -4460,7 +4460,7 @@ QList<PStatement> CppParser::getListOfFunctions(const QString &fileName, int lin
QSet<QString> includedFiles = internalGetIncludedFiles(fileName); QSet<QString> includedFiles = internalGetIncludedFiles(fileName);
for (const PStatement& child:children) { for (const PStatement& child:children) {
if (statement->command == child->command) { if (statement->command == child->command) {
if (child->kind == StatementKind::skAlias) if (child->kind == StatementKind::Alias)
continue; continue;
if (!includedFiles.contains(fileName)) if (!includedFiles.contains(fileName))
continue; continue;
@ -4480,7 +4480,7 @@ PStatement CppParser::findMacro(const QString &phrase, const QString &fileName)
StatementList statements = statementMap.values(phrase); StatementList statements = statementMap.values(phrase);
PFileIncludes includes = mPreprocessor.findFileIncludes(fileName); PFileIncludes includes = mPreprocessor.findFileIncludes(fileName);
foreach (const PStatement& s, statements) { foreach (const PStatement& s, statements) {
if (s->kind == StatementKind::skPreprocessor) { if (s->kind == StatementKind::Preprocessor) {
if (includes && fileName != s->fileName && !includes->includeFiles.contains(s->fileName)) if (includes && fileName != s->fileName && !includes->includeFiles.contains(s->fileName))
continue; continue;
return s; return s;
@ -4583,7 +4583,7 @@ QList<PStatement> CppParser::findMembersOfStatement(const QString &phrase, const
PStatement CppParser::findStatementInScope(const QString &name, const QString &noNameArgs, PStatement CppParser::findStatementInScope(const QString &name, const QString &noNameArgs,
StatementKind kind, const PStatement& scope) const StatementKind kind, const PStatement& scope) const
{ {
if (scope && scope->kind == StatementKind::skNamespace) { if (scope && scope->kind == StatementKind::Namespace) {
PStatementList namespaceStatementsList = doFindNamespace(scope->command); PStatementList namespaceStatementsList = doFindNamespace(scope->command);
if (!namespaceStatementsList) if (!namespaceStatementsList)
return PStatement(); return PStatement();
@ -4602,7 +4602,7 @@ PStatement CppParser::findStatementInScope(const QString &name, const PStatement
{ {
if (!scope) if (!scope)
return findMemberOfStatement(name,scope); return findMemberOfStatement(name,scope);
if (scope->kind == StatementKind::skNamespace) { if (scope->kind == StatementKind::Namespace) {
return findStatementInNamespace(name, scope->fullName); return findStatementInNamespace(name, scope->fullName);
} else { } else {
return findMemberOfStatement(name,scope); return findMemberOfStatement(name,scope);
@ -5272,33 +5272,33 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
// } // }
} }
pos++; pos++;
if (statement && statement->kind == StatementKind::skConstructor) { if (statement && statement->kind == StatementKind::Constructor) {
statement = statement->parentScope.lock(); statement = statement->parentScope.lock();
} }
while (statement && statement->kind == StatementKind::skAlias) { while (statement && statement->kind == StatementKind::Alias) {
statement = doFindAliasedStatement(statement); statement = doFindAliasedStatement(statement);
} }
if (statement) { if (statement) {
switch (statement->kind) { switch (statement->kind) {
case StatementKind::skNamespace: case StatementKind::Namespace:
result = doCreateEvalNamespace(statement); result = doCreateEvalNamespace(statement);
break; break;
case StatementKind::skNamespaceAlias: case StatementKind::NamespaceAlias:
result = doFindAliasedNamespace(statement); result = doFindAliasedNamespace(statement);
break; break;
case StatementKind::skVariable: case StatementKind::Variable:
case StatementKind::skParameter: case StatementKind::Parameter:
result = doCreateEvalVariable(fileName,statement, previousResult?previousResult->templateParams:"",scope); result = doCreateEvalVariable(fileName,statement, previousResult?previousResult->templateParams:"",scope);
break; break;
case StatementKind::skClass: case StatementKind::Class:
statement = doFindNoTemplateSpecializationClass(statement); statement = doFindNoTemplateSpecializationClass(statement);
[[fallthrough]]; [[fallthrough]];
case StatementKind::skEnumType: case StatementKind::EnumType:
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
case StatementKind::skTypedef: case StatementKind::Typedef:
result = doCreateEvalType(fileName,statement); result = doCreateEvalType(fileName,statement);
break; break;
case StatementKind::skFunction: { case StatementKind::Function: {
if (statement->type=="auto") { if (statement->type=="auto") {
PStatement scopeStatement = statement->parentScope.lock(); PStatement scopeStatement = statement->parentScope.lock();
if (scopeStatement) { if (scopeStatement) {
@ -5563,7 +5563,7 @@ PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatem
{ {
if (!typeStatement) if (!typeStatement)
return PEvalStatement(); return PEvalStatement();
if (typeStatement->kind == StatementKind::skTypedef) { if (typeStatement->kind == StatementKind::Typedef) {
QString baseType; QString baseType;
int pointerLevel=0; int pointerLevel=0;
QString templateParams; QString templateParams;
@ -5576,7 +5576,7 @@ PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatem
tempStatement, tempStatement,
pointerLevel, pointerLevel,
templateParams); templateParams);
if (effectiveTypeStatement && effectiveTypeStatement->kind == StatementKind::skClass) if (effectiveTypeStatement && effectiveTypeStatement->kind == StatementKind::Class)
effectiveTypeStatement = doFindNoTemplateSpecializationClass(effectiveTypeStatement); effectiveTypeStatement = doFindNoTemplateSpecializationClass(effectiveTypeStatement);
return std::make_shared<EvalStatement>( return std::make_shared<EvalStatement>(
baseType, baseType,
@ -5810,8 +5810,8 @@ PStatement CppParser::doParseEvalTypeInfo(
typeStatement = doFindStatementOf(fileName,baseType,scope); typeStatement = doFindStatementOf(fileName,baseType,scope);
PStatement effectiveTypeStatement = typeStatement; PStatement effectiveTypeStatement = typeStatement;
int level=0; int level=0;
while (effectiveTypeStatement && (effectiveTypeStatement->kind == StatementKind::skTypedef while (effectiveTypeStatement && (effectiveTypeStatement->kind == StatementKind::Typedef
|| effectiveTypeStatement->kind == StatementKind::skPreprocessor)) { || effectiveTypeStatement->kind == StatementKind::Preprocessor)) {
if (level >20) // prevent infinite loop if (level >20) // prevent infinite loop
break; break;
level++; level++;
@ -6006,10 +6006,10 @@ void CppParser::scanMethodArgs(const PStatement& functionStatement, int argStart
"", "",
"", "",
mTokenizer[i+1]->line, mTokenizer[i+1]->line,
StatementKind::skParameter, StatementKind::Parameter,
StatementScope::Local, StatementScope::Local,
StatementAccessibility::None, StatementAccessibility::None,
StatementProperty::spHasDefinition); StatementProperty::HasDefinition);
} }
i=argEnd+1; i=argEnd+1;
words.clear(); words.clear();
@ -6277,9 +6277,9 @@ bool CppParser::isNotFuncArgs(int startIndex)
bool CppParser::isNamedScope(StatementKind kind) const bool CppParser::isNamedScope(StatementKind kind) const
{ {
switch(kind) { switch(kind) {
case StatementKind::skClass: case StatementKind::Class:
case StatementKind::skNamespace: case StatementKind::Namespace:
case StatementKind::skFunction: case StatementKind::Function:
return true; return true;
default: default:
return false; return false;
@ -6289,10 +6289,10 @@ bool CppParser::isNamedScope(StatementKind kind) const
bool CppParser::isTypeStatement(StatementKind kind) const bool CppParser::isTypeStatement(StatementKind kind) const
{ {
switch(kind) { switch(kind) {
case StatementKind::skClass: case StatementKind::Class:
case StatementKind::skTypedef: case StatementKind::Typedef:
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
case StatementKind::skEnumType: case StatementKind::EnumType:
return true; return true;
default: default:
return false; return false;

View File

@ -618,10 +618,10 @@ MemberOperatorType getOperatorType(const QString &phrase, int index)
bool isScopeTypeKind(StatementKind kind) bool isScopeTypeKind(StatementKind kind)
{ {
switch(kind) { switch(kind) {
case StatementKind::skClass: case StatementKind::Class:
case StatementKind::skNamespace: case StatementKind::Namespace:
case StatementKind::skEnumType: case StatementKind::EnumType:
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
return true; return true;
default: default:
return false; return false;
@ -713,17 +713,17 @@ bool isMemberOperator(QString token)
StatementKind getKindOfStatement(const PStatement& statement) StatementKind getKindOfStatement(const PStatement& statement)
{ {
if (!statement) if (!statement)
return StatementKind::skUnknown; return StatementKind::Unknown;
if (statement->kind == StatementKind::skVariable) { if (statement->kind == StatementKind::Variable) {
if (!statement->parentScope.lock()) { if (!statement->parentScope.lock()) {
return StatementKind::skGlobalVariable; return StatementKind::GlobalVariable;
} else if (statement->scope == StatementScope::Local) { } else if (statement->scope == StatementScope::Local) {
return StatementKind::skLocalVariable; return StatementKind::LocalVariable;
} else { } else {
return StatementKind::skVariable; return StatementKind::Variable;
} }
} else if (statement->kind == StatementKind::skParameter) { } else if (statement->kind == StatementKind::Parameter) {
return StatementKind::skLocalVariable; return StatementKind::LocalVariable;
} }
return statement->kind; return statement->kind;
} }
@ -755,12 +755,12 @@ bool isCppControlKeyword(const QString &word)
bool isTypeKind(StatementKind kind) bool isTypeKind(StatementKind kind)
{ {
switch(kind) { switch(kind) {
case StatementKind::skClass: case StatementKind::Class:
case StatementKind::skNamespace: case StatementKind::Namespace:
case StatementKind::skEnumType: case StatementKind::EnumType:
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
case StatementKind::skTypedef: case StatementKind::Typedef:
case StatementKind::skPreprocessor: case StatementKind::Preprocessor:
return true; return true;
default: default:
return false; return false;

View File

@ -25,7 +25,7 @@
using GetFileStreamCallBack = std::function<bool (const QString&, QStringList&)>; using GetFileStreamCallBack = std::function<bool (const QString&, QStringList&)>;
enum ParserLanguage { enum class ParserLanguage {
C, C,
CPlusPlus, CPlusPlus,
#ifdef ENABLE_SDCC #ifdef ENABLE_SDCC
@ -33,6 +33,10 @@ enum ParserLanguage {
#endif #endif
}; };
inline qHash(const ParserLanguage& value, uint seed) {
return qHash((int)value, seed);
}
struct CodeSnippet { struct CodeSnippet {
QString caption; //Name QString caption; //Name
QString prefix; //Prefix used in code suggestion QString prefix; //Prefix used in code suggestion
@ -88,34 +92,35 @@ enum class KeywordType {
NotKeyword NotKeyword
}; };
//It will be used as hash key. DONT make it enum class!!!!! enum class StatementKind {
enum StatementKind { Unknown,
skUnknown, Namespace,
skNamespace, NamespaceAlias,
skNamespaceAlias, Class,
skClass, Preprocessor,
skPreprocessor, EnumType,
skEnumType, EnumClassType,
skEnumClassType, Typedef,
skTypedef, Constructor,
skConstructor, Destructor,
skDestructor, Function,
skFunction, Variable,
skVariable, GlobalVariable,
skGlobalVariable, LocalVariable,
skLocalVariable, Enum,
skEnum, Operator,
skOperator, Parameter,
skParameter, Block,
skBlock, Lambda,
skLambda, UserCodeSnippet, // user code template
skUserCodeSnippet, // user code template Keyword, // keywords
skKeyword, // keywords KeywordType, //keywords for type (for color management)
skKeywordType, //keywords for type (for color management) Alias, // using alias
skAlias
}; };
using StatementKindSet = QSet<StatementKind>; inline qHash(const StatementKind& value, uint seed) {
return qHash((int)value, seed);
}
enum class StatementScope { enum class StatementScope {
Global, Global,
@ -131,10 +136,10 @@ enum class StatementAccessibility {
}; };
enum class MemberOperatorType { enum class MemberOperatorType {
Arrow, Arrow,
Dot, Dot,
DColon, DColon,
Other Other
}; };
enum class EvalStatementKind { enum class EvalStatementKind {
@ -150,19 +155,19 @@ struct StatementMatchPosition{
uint16_t end; uint16_t end;
}; };
enum StatementProperty { enum class StatementProperty {
spNone = 0x0, None = 0x0,
spStatic = 0x0001, Static = 0x0001,
spHasDefinition = 0x0002, HasDefinition = 0x0002,
spInProject = 0x0004, InProject = 0x0004,
spInSystemHeader = 0x0008, InSystemHeader = 0x0008,
spInherited = 0x0010, Inherited = 0x0010,
spVirtual = 0x0020, Virtual = 0x0020,
spOverride = 0x0040, Override = 0x0040,
spConstexpr = 0x0080, Constexpr = 0x0080,
spFunctionPointer = 0x0100, FunctionPointer = 0x0100,
spOperatorOverloading = 0x0200, OperatorOverloading = 0x0200,
spDummyStatement = 0x0400 DummyStatement = 0x0400
}; };
Q_DECLARE_FLAGS(StatementProperties, StatementProperty) Q_DECLARE_FLAGS(StatementProperties, StatementProperty)
@ -212,33 +217,33 @@ struct Statement {
// definiton line/filename is valid // definiton line/filename is valid
bool hasDefinition() { bool hasDefinition() {
return properties.testFlag(StatementProperty::spHasDefinition); return properties.testFlag(StatementProperty::HasDefinition);
} }
void setHasDefinition(bool on) { void setHasDefinition(bool on) {
properties.setFlag(StatementProperty::spHasDefinition,on); properties.setFlag(StatementProperty::HasDefinition,on);
} }
// statement in project // statement in project
bool inProject() { bool inProject() {
return properties.testFlag(StatementProperty::spInProject); return properties.testFlag(StatementProperty::InProject);
} }
void setInProject(bool on) { void setInProject(bool on) {
properties.setFlag(StatementProperty::spInProject, on); properties.setFlag(StatementProperty::InProject, on);
} }
// statement in system header (#include <>) // statement in system header (#include <>)
bool inSystemHeader() { bool inSystemHeader() {
return properties.testFlag(StatementProperty::spInSystemHeader); return properties.testFlag(StatementProperty::InSystemHeader);
} }
void setInSystemHeader(bool on) { void setInSystemHeader(bool on) {
properties.setFlag(StatementProperty::spInSystemHeader, on); properties.setFlag(StatementProperty::InSystemHeader, on);
} }
bool isStatic() { bool isStatic() {
return properties.testFlag(StatementProperty::spStatic); return properties.testFlag(StatementProperty::Static);
} // static function / variable } // static function / variable
void setIsStatic(bool on) { void setIsStatic(bool on) {
properties.setFlag(StatementProperty::spStatic, on); properties.setFlag(StatementProperty::Static, on);
} }
bool isInherited() { bool isInherited() {
return properties.testFlag(StatementProperty::spInherited); return properties.testFlag(StatementProperty::Inherited);
} // inherted member; } // inherted member;
}; };

View File

@ -149,14 +149,14 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
if (node->statement) { if (node->statement) {
if (!(node->statement->type.isEmpty())) { if (!(node->statement->type.isEmpty())) {
if ((node->statement->kind == StatementKind::skFunction) if ((node->statement->kind == StatementKind::Function)
|| (node->statement->kind == StatementKind::skVariable) || (node->statement->kind == StatementKind::Variable)
|| (node->statement->kind == StatementKind::skTypedef) || (node->statement->kind == StatementKind::Typedef)
) { ) {
return node->statement->command + node->statement->args + " : " + node->statement->type; return node->statement->command + node->statement->args + " : " + node->statement->type;
} }
} }
if (node->statement->kind == StatementKind::skEnum) { if (node->statement->kind == StatementKind::Enum) {
if (!node->statement->value.isEmpty()) if (!node->statement->value.isEmpty())
return node->statement->command + node->statement->args + QString("(%1)").arg(node->statement->value); return node->statement->command + node->statement->args + QString("(%1)").arg(node->statement->value);
else else
@ -168,9 +168,9 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
if (mColors && node->statement) { if (mColors && node->statement) {
PStatement statement = (node->statement); PStatement statement = (node->statement);
StatementKind kind = getKindOfStatement(statement); StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skKeyword) { if (kind == StatementKind::Keyword) {
if (statement->command.startsWith('#')) if (statement->command.startsWith('#'))
kind = StatementKind::skPreprocessor; kind = StatementKind::Preprocessor;
} }
PColorSchemeItem item = mColors->value(kind,PColorSchemeItem()); PColorSchemeItem item = mColors->value(kind,PColorSchemeItem());
if (item) { if (item) {
@ -361,9 +361,9 @@ void ClassBrowserModel::filterChildren(ClassBrowserNode *node, const StatementMa
// if (statement->properties.testFlag(StatementProperty::spDummyStatement)) // if (statement->properties.testFlag(StatementProperty::spDummyStatement))
// continue; // continue;
if (statement->kind == StatementKind::skBlock) if (statement->kind == StatementKind::Block)
continue; continue;
if (statement->kind == StatementKind::skLambda) if (statement->kind == StatementKind::Lambda)
continue; continue;
if (statement->isInherited() && !pSettings->ui().classBrowserShowInherited()) if (statement->isInherited() && !pSettings->ui().classBrowserShowInherited())
continue; continue;
@ -457,10 +457,10 @@ ClassBrowserNode* ClassBrowserModel::getParentNode(const PStatement &parentState
bool ClassBrowserModel::isScopeStatement(const PStatement &statement) bool ClassBrowserModel::isScopeStatement(const PStatement &statement)
{ {
switch(statement->kind) { switch(statement->kind) {
case StatementKind::skClass: case StatementKind::Class:
case StatementKind::skNamespace: case StatementKind::Namespace:
case StatementKind::skEnumClassType: case StatementKind::EnumClassType:
case StatementKind::skEnumType: case StatementKind::EnumType:
return true; return true;
default: default:
return false; return false;

View File

@ -274,14 +274,14 @@ void CodeCompletionPopup::addFunctionWithoutDefinitionChildren(const PStatement&
continue; continue;
} }
switch(childStatement->kind) { switch(childStatement->kind) {
case StatementKind::skConstructor: case StatementKind::Constructor:
case StatementKind::skFunction: case StatementKind::Function:
case StatementKind::skDestructor: case StatementKind::Destructor:
if (!childStatement->hasDefinition()) if (!childStatement->hasDefinition())
addStatement(childStatement,fileName,line); addStatement(childStatement,fileName,line);
break; break;
case StatementKind::skClass: case StatementKind::Class:
case StatementKind::skNamespace: case StatementKind::Namespace:
if (isIncluded(childStatement->fileName)) if (isIncluded(childStatement->fileName))
addStatement(childStatement,fileName,line); addStatement(childStatement,fileName,line);
break; break;
@ -295,12 +295,12 @@ void CodeCompletionPopup::addStatement(const PStatement& statement, const QStrin
{ {
if (mAddedStatements.contains(statement->command)) if (mAddedStatements.contains(statement->command))
return; return;
if (statement->kind == StatementKind::skConstructor if (statement->kind == StatementKind::Constructor
|| statement->kind == StatementKind::skDestructor || statement->kind == StatementKind::Destructor
|| statement->kind == StatementKind::skBlock || statement->kind == StatementKind::Block
|| statement->kind == StatementKind::skLambda || statement->kind == StatementKind::Lambda
|| statement->properties.testFlag(StatementProperty::spOperatorOverloading) || statement->properties.testFlag(StatementProperty::OperatorOverloading)
|| statement->properties.testFlag(StatementProperty::spDummyStatement) || statement->properties.testFlag(StatementProperty::DummyStatement)
) )
return; return;
if ((line!=-1) if ((line!=-1)
@ -308,7 +308,7 @@ void CodeCompletionPopup::addStatement(const PStatement& statement, const QStrin
&& (fileName == statement->fileName)) && (fileName == statement->fileName))
return; return;
mAddedStatements.insert(statement->command); mAddedStatements.insert(statement->command);
if (statement->kind == StatementKind::skUserCodeSnippet || !statement->command.contains("<")) if (statement->kind == StatementKind::UserCodeSnippet || !statement->command.contains("<"))
mFullCompletionStatementList.append(statement); mFullCompletionStatementList.append(statement);
} }
@ -326,19 +326,19 @@ static bool defaultComparator(PStatement statement1,PStatement statement2) {
if (statement1->caseMatched != statement2->caseMatched) if (statement1->caseMatched != statement2->caseMatched)
return statement1->caseMatched > statement2->caseMatched; return statement1->caseMatched > statement2->caseMatched;
// Show user template first // Show user template first
if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement1->kind == StatementKind::UserCodeSnippet) {
if (statement2->kind != StatementKind::skUserCodeSnippet) if (statement2->kind != StatementKind::UserCodeSnippet)
return true; return true;
else else
return statement1->command < statement2->command; return statement1->command < statement2->command;
} else if (statement2->kind == StatementKind::skUserCodeSnippet) { } else if (statement2->kind == StatementKind::UserCodeSnippet) {
return false; return false;
// show keywords first // show keywords first
} else if ((statement1->kind == StatementKind::skKeyword) } else if ((statement1->kind == StatementKind::Keyword)
&& (statement2->kind != StatementKind::skKeyword)) { && (statement2->kind != StatementKind::Keyword)) {
return true; return true;
} else if ((statement1->kind != StatementKind::skKeyword) } else if ((statement1->kind != StatementKind::Keyword)
&& (statement2->kind == StatementKind::skKeyword)) { && (statement2->kind == StatementKind::Keyword)) {
return false; return false;
} else } else
return nameComparator(statement1,statement2); return nameComparator(statement1,statement2);
@ -354,22 +354,22 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
if (statement1->caseMatched != statement2->caseMatched) if (statement1->caseMatched != statement2->caseMatched)
return statement1->caseMatched > statement2->caseMatched; return statement1->caseMatched > statement2->caseMatched;
// Show user template first // Show user template first
if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement1->kind == StatementKind::UserCodeSnippet) {
if (statement2->kind != StatementKind::skUserCodeSnippet) if (statement2->kind != StatementKind::UserCodeSnippet)
return true; return true;
else else
return statement1->command < statement2->command; return statement1->command < statement2->command;
} else if (statement2->kind == StatementKind::skUserCodeSnippet) { } else if (statement2->kind == StatementKind::UserCodeSnippet) {
return false; return false;
// show non-system defines before keyword // show non-system defines before keyword
} else if (statement1->kind == StatementKind::skKeyword) { } else if (statement1->kind == StatementKind::Keyword) {
if (statement2->kind != StatementKind::skKeyword) { if (statement2->kind != StatementKind::Keyword) {
//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::Keyword) {
//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());
@ -398,23 +398,23 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2)
if (statement1->caseMatched != statement2->caseMatched) if (statement1->caseMatched != statement2->caseMatched)
return statement1->caseMatched > statement2->caseMatched; return statement1->caseMatched > statement2->caseMatched;
// Show user template first // Show user template first
if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement1->kind == StatementKind::UserCodeSnippet) {
if (statement2->kind != StatementKind::skUserCodeSnippet) if (statement2->kind != StatementKind::UserCodeSnippet)
return true; return true;
else else
return statement1->command < statement2->command; return statement1->command < statement2->command;
} else if (statement2->kind == StatementKind::skUserCodeSnippet) { } else if (statement2->kind == StatementKind::UserCodeSnippet) {
return false; return false;
//show most freq first //show most freq first
} }
if (statement1->usageCount != statement2->usageCount) if (statement1->usageCount != statement2->usageCount)
return statement1->usageCount > statement2->usageCount; return statement1->usageCount > statement2->usageCount;
if ((statement1->kind != StatementKind::skKeyword) if ((statement1->kind != StatementKind::Keyword)
&& (statement2->kind == StatementKind::skKeyword)) { && (statement2->kind == StatementKind::Keyword)) {
return true; return true;
} else if ((statement1->kind == StatementKind::skKeyword) } else if ((statement1->kind == StatementKind::Keyword)
&& (statement2->kind != StatementKind::skKeyword)) { && (statement2->kind != StatementKind::Keyword)) {
return false; return false;
} else } else
return nameComparator(statement1,statement2); return nameComparator(statement1,statement2);
@ -430,12 +430,12 @@ static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement stat
if (statement1->caseMatched != statement2->caseMatched) if (statement1->caseMatched != statement2->caseMatched)
return statement1->caseMatched > statement2->caseMatched; return statement1->caseMatched > statement2->caseMatched;
// Show user template first // Show user template first
if (statement1->kind == StatementKind::skUserCodeSnippet) { if (statement1->kind == StatementKind::UserCodeSnippet) {
if (statement2->kind != StatementKind::skUserCodeSnippet) if (statement2->kind != StatementKind::UserCodeSnippet)
return true; return true;
else else
return statement1->command < statement2->command; return statement1->command < statement2->command;
} else if (statement2->kind == StatementKind::skUserCodeSnippet) { } else if (statement2->kind == StatementKind::UserCodeSnippet) {
return false; return false;
//show most freq first //show most freq first
} }
@ -443,14 +443,14 @@ static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement stat
return statement1->usageCount > statement2->usageCount; return statement1->usageCount > statement2->usageCount;
// show non-system defines before keyword // show non-system defines before keyword
if (statement1->kind == StatementKind::skKeyword) { if (statement1->kind == StatementKind::Keyword) {
if (statement2->kind != StatementKind::skKeyword) { if (statement2->kind != StatementKind::Keyword) {
//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::Keyword) {
//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());
@ -598,7 +598,7 @@ void CodeCompletionPopup::getMacroCompletionList(const QString &fileName, int li
{ {
const StatementMap& statementMap = mParser->statementList().childrenStatements(nullptr); const StatementMap& statementMap = mParser->statementList().childrenStatements(nullptr);
foreach(const PStatement& statement, statementMap.values()) { foreach(const PStatement& statement, statementMap.values()) {
if (statement->kind==StatementKind::skPreprocessor) if (statement->kind==StatementKind::Preprocessor)
addStatement(statement,fileName,line); addStatement(statement,fileName,line);
} }
} }
@ -649,7 +649,7 @@ void CodeCompletionPopup::getCompletionFor(
PStatement statement = std::make_shared<Statement>(); PStatement statement = std::make_shared<Statement>();
statement->command = codeIn->prefix; statement->command = codeIn->prefix;
statement->value = codeIn->code; statement->value = codeIn->code;
statement->kind = StatementKind::skUserCodeSnippet; statement->kind = StatementKind::UserCodeSnippet;
statement->fullName = codeIn->prefix; statement->fullName = codeIn->prefix;
statement->usageCount = 0; statement->usageCount = 0;
mFullCompletionStatementList.append(statement); mFullCompletionStatementList.append(statement);
@ -686,13 +686,13 @@ void CodeCompletionPopup::getCompletionFor(
// repeat until reach global // repeat until reach global
while (scopeStatement) { while (scopeStatement) {
//add members of current scope that not added before //add members of current scope that not added before
if (scopeStatement->kind == StatementKind::skNamespace) { if (scopeStatement->kind == StatementKind::Namespace) {
PStatementList namespaceStatementsList = PStatementList namespaceStatementsList =
mParser->findNamespace(scopeStatement->fullName); mParser->findNamespace(scopeStatement->fullName);
foreach (const PStatement& namespaceStatement,*namespaceStatementsList) { foreach (const PStatement& namespaceStatement,*namespaceStatementsList) {
addChildren(namespaceStatement, fileName, line, isLambdaReturnType); addChildren(namespaceStatement, fileName, line, isLambdaReturnType);
} }
} else if (scopeStatement->kind == StatementKind::skClass) { } else if (scopeStatement->kind == StatementKind::Class) {
addChildren(scopeStatement, fileName, -1, isLambdaReturnType); addChildren(scopeStatement, fileName, -1, isLambdaReturnType);
} else { } else {
addChildren(scopeStatement, fileName, line, isLambdaReturnType); addChildren(scopeStatement, fileName, line, isLambdaReturnType);
@ -708,7 +708,7 @@ void CodeCompletionPopup::getCompletionFor(
addChildren(namespaceStatement, fileName, line, isLambdaReturnType); addChildren(namespaceStatement, fileName, line, isLambdaReturnType);
} }
} }
if (scopeStatement->kind == StatementKind::skLambda) { if (scopeStatement->kind == StatementKind::Lambda) {
foreach (const QString& phrase, scopeStatement->lambdaCaptures) { foreach (const QString& phrase, scopeStatement->lambdaCaptures) {
if (phrase=="&" || phrase == "=" || phrase =="this") if (phrase=="&" || phrase == "=" || phrase =="this")
continue; continue;
@ -724,12 +724,12 @@ void CodeCompletionPopup::getCompletionFor(
} else if (scopeStatement->lambdaCaptures.contains("this")) { } else if (scopeStatement->lambdaCaptures.contains("this")) {
do { do {
scopeStatement = scopeStatement->parentScope.lock(); scopeStatement = scopeStatement->parentScope.lock();
} while (scopeStatement && scopeStatement->kind!=StatementKind::skClass } while (scopeStatement && scopeStatement->kind!=StatementKind::Class
&& scopeStatement->kind!=StatementKind::skNamespace); && scopeStatement->kind!=StatementKind::Namespace);
} else { } else {
do { do {
scopeStatement = scopeStatement->parentScope.lock(); scopeStatement = scopeStatement->parentScope.lock();
} while (scopeStatement && scopeStatement->kind!=StatementKind::skNamespace); } while (scopeStatement && scopeStatement->kind!=StatementKind::Namespace);
} }
continue; continue;
} }
@ -863,8 +863,8 @@ void CodeCompletionPopup::getCompletionFor(
foreach (const PStatement& childStatement, children) { foreach (const PStatement& childStatement, children) {
if ((childStatement->accessibility==StatementAccessibility::Public) if ((childStatement->accessibility==StatementAccessibility::Public)
&& !( && !(
childStatement->kind == StatementKind::skConstructor childStatement->kind == StatementKind::Constructor
|| childStatement->kind == StatementKind::skDestructor) || childStatement->kind == StatementKind::Destructor)
&& !mAddedStatements.contains(childStatement->command)) { && !mAddedStatements.contains(childStatement->command)) {
addStatement(childStatement,fileName,-1); addStatement(childStatement,fileName,-1);
} }
@ -880,8 +880,8 @@ void CodeCompletionPopup::getCompletionFor(
if (!isIncluded(classTypeStatement->fileName) && if (!isIncluded(classTypeStatement->fileName) &&
!isIncluded(classTypeStatement->definitionFileName)) !isIncluded(classTypeStatement->definitionFileName))
return; return;
if (classTypeStatement->kind == StatementKind::skEnumType if (classTypeStatement->kind == StatementKind::EnumType
|| classTypeStatement->kind == StatementKind::skEnumClassType) { || classTypeStatement->kind == StatementKind::EnumClassType) {
const StatementMap& children = const StatementMap& children =
mParser->statementList().childrenStatements(classTypeStatement); mParser->statementList().childrenStatements(classTypeStatement);
foreach (const PStatement& child,children) { foreach (const PStatement& child,children) {
@ -896,11 +896,11 @@ void CodeCompletionPopup::getCompletionFor(
foreach (const PStatement& childStatement, children) { foreach (const PStatement& childStatement, children) {
if ( if (
(childStatement->isStatic()) (childStatement->isStatic())
|| (childStatement->kind == StatementKind::skTypedef || (childStatement->kind == StatementKind::Typedef
|| childStatement->kind == StatementKind::skClass || childStatement->kind == StatementKind::Class
|| childStatement->kind == StatementKind::skEnum || childStatement->kind == StatementKind::Enum
|| childStatement->kind == StatementKind::skEnumClassType || childStatement->kind == StatementKind::EnumClassType
|| childStatement->kind == StatementKind::skEnumType || childStatement->kind == StatementKind::EnumType
)) { )) {
addStatement(childStatement,fileName,-1); addStatement(childStatement,fileName,-1);
} }
@ -912,11 +912,11 @@ void CodeCompletionPopup::getCompletionFor(
foreach (const PStatement& childStatement,children) { foreach (const PStatement& childStatement,children) {
if ( if (
(childStatement->isStatic()) (childStatement->isStatic())
|| (childStatement->kind == StatementKind::skTypedef || (childStatement->kind == StatementKind::Typedef
|| childStatement->kind == StatementKind::skClass || childStatement->kind == StatementKind::Class
|| childStatement->kind == StatementKind::skEnum || childStatement->kind == StatementKind::Enum
|| childStatement->kind == StatementKind::skEnumClassType || childStatement->kind == StatementKind::EnumClassType
|| childStatement->kind == StatementKind::skEnumType || childStatement->kind == StatementKind::EnumType
)) { )) {
if (childStatement->accessibility == StatementAccessibility::Public) if (childStatement->accessibility == StatementAccessibility::Public)
addStatement(childStatement,fileName,-1); addStatement(childStatement,fileName,-1);
@ -950,12 +950,12 @@ void CodeCompletionPopup::getCompletionForFunctionWithoutDefinition(const QStrin
getCompletionListForComplexKeyword(preWord); getCompletionListForComplexKeyword(preWord);
PStatement scopeStatement = mCurrentScope; PStatement scopeStatement = mCurrentScope;
//add members of current scope that not added before //add members of current scope that not added before
while (scopeStatement && scopeStatement->kind!=StatementKind::skNamespace while (scopeStatement && scopeStatement->kind!=StatementKind::Namespace
&& scopeStatement->kind!=StatementKind::skClass) { && scopeStatement->kind!=StatementKind::Class) {
scopeStatement = scopeStatement->parentScope.lock(); scopeStatement = scopeStatement->parentScope.lock();
} }
if (scopeStatement) { if (scopeStatement) {
if (scopeStatement->kind == StatementKind::skNamespace) { if (scopeStatement->kind == StatementKind::Namespace) {
//namespace; //namespace;
PStatementList namespaceStatementsList = PStatementList namespaceStatementsList =
mParser->findNamespace(scopeStatement->fullName); mParser->findNamespace(scopeStatement->fullName);
@ -1007,7 +1007,7 @@ void CodeCompletionPopup::getCompletionForFunctionWithoutDefinition(const QStrin
} }
} }
return; return;
} else if (ownerStatement->effectiveTypeStatement->kind == StatementKind::skClass) { } else if (ownerStatement->effectiveTypeStatement->kind == StatementKind::Class) {
addKeyword("operator"); addKeyword("operator");
addFunctionWithoutDefinitionChildren(ownerStatement->effectiveTypeStatement, fileName, line); addFunctionWithoutDefinitionChildren(ownerStatement->effectiveTypeStatement, fileName, line);
} }
@ -1104,7 +1104,7 @@ void CodeCompletionPopup::addKeyword(const QString &keyword)
{ {
PStatement statement = std::make_shared<Statement>(); PStatement statement = std::make_shared<Statement>();
statement->command = keyword; statement->command = keyword;
statement->kind = StatementKind::skKeyword; statement->kind = StatementKind::Keyword;
statement->fullName = keyword; statement->fullName = keyword;
statement->usageCount = 0; statement->usageCount = 0;
mFullCompletionStatementList.append(statement); mFullCompletionStatementList.append(statement);

View File

@ -131,7 +131,7 @@ void NewClassCandidatesModel::fillClasses()
if (!mParser->freeze()) if (!mParser->freeze())
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::Class
&& s->inProject() && s->inProject()
&& !s->command.startsWith("_") && !s->command.startsWith("_")
&& !s->command.contains("<") && !s->command.contains("<")
@ -141,7 +141,7 @@ void NewClassCandidatesModel::fillClasses()
mCandidates.append(s); mCandidates.append(s);
mClassNames.insert(s->fullName); mClassNames.insert(s->fullName);
} }
} else if (s->kind == StatementKind::skNamespace } else if (s->kind == StatementKind::Namespace
&& !s->command.startsWith("_") && !s->command.startsWith("_")
&& !s->command.contains("<")) { && !s->command.contains("<")) {
fillClassesInNamespace(s); fillClassesInNamespace(s);
@ -157,7 +157,7 @@ void NewClassCandidatesModel::fillClasses()
void NewClassCandidatesModel::fillClassesInNamespace(PStatement ns) 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::Class
&& s->inProject() && s->inProject()
&& !s->command.startsWith("_") && !s->command.startsWith("_")
&& !s->command.contains("<") && !s->command.contains("<")
@ -167,7 +167,7 @@ void NewClassCandidatesModel::fillClassesInNamespace(PStatement ns)
mCandidates.append(s); mCandidates.append(s);
mClassNames.insert(s->fullName); mClassNames.insert(s->fullName);
} }
} else if (s->kind == StatementKind::skNamespace } else if (s->kind == StatementKind::Namespace
&& !s->command.startsWith("_") && !s->command.startsWith("_")
&& !s->command.contains("<")) { && !s->command.contains("<")) {
fillClassesInNamespace(s); fillClassesInNamespace(s);

View File

@ -170,7 +170,7 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
setAcceptDrops(true); setAcceptDrops(true);
setFont(mFontDummy); setFont(mFontDummy);
setScrollBars(ScrollStyle::ssBoth); setScrollBars(ScrollStyle::Both);
} }
int QSynEdit::displayLineCount() const int QSynEdit::displayLineCount() const
@ -3801,7 +3801,7 @@ ScrollStyle QSynEdit::scrollBars() const
void QSynEdit::setScrollBars(ScrollStyle newScrollBars) void QSynEdit::setScrollBars(ScrollStyle newScrollBars)
{ {
mScrollBars = newScrollBars; mScrollBars = newScrollBars;
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) { if (mScrollBars == ScrollStyle::Both || mScrollBars == ScrollStyle::OnlyHorizontal) {
if (mOptions.testFlag(EditorOption::AutoHideScrollbars)) { if (mOptions.testFlag(EditorOption::AutoHideScrollbars)) {
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
} else { } else {
@ -3811,7 +3811,7 @@ void QSynEdit::setScrollBars(ScrollStyle newScrollBars)
} else { } else {
setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
} }
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssVertical) { if (mScrollBars == ScrollStyle::Both || mScrollBars == ScrollStyle::OnlyVertical) {
if (mOptions.testFlag(EditorOption::AutoHideScrollbars)) { if (mOptions.testFlag(EditorOption::AutoHideScrollbars)) {
setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
} else { } else {
@ -6816,7 +6816,7 @@ void QSynEdit::setLeftPos(int value)
if (mDocument->maxLineWidth()<0) if (mDocument->maxLineWidth()<0)
mLeftPos = value; mLeftPos = value;
setStatusChanged(StatusChange::LeftPos); setStatusChanged(StatusChange::LeftPos);
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal) if (mScrollBars == ScrollStyle::Both || mScrollBars == ScrollStyle::OnlyHorizontal)
horizontalScrollBar()->setValue(value); horizontalScrollBar()->setValue(value);
else { else {
if (mDocument->maxLineWidth()>0) { if (mDocument->maxLineWidth()>0) {
@ -6845,7 +6845,7 @@ void QSynEdit::setTopPos(int value)
if (value != mTopPos) { if (value != mTopPos) {
setStatusChanged(StatusChange::TopPos); setStatusChanged(StatusChange::TopPos);
mTopPos = value; mTopPos = value;
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssVertical) { if (mScrollBars == ScrollStyle::Both || mScrollBars == ScrollStyle::OnlyVertical) {
verticalScrollBar()->setValue(value); verticalScrollBar()->setValue(value);
} else { } else {
invalidate(); invalidate();

View File

@ -35,7 +35,7 @@
namespace QSynedit { namespace QSynedit {
enum class ScrollStyle { enum class ScrollStyle {
ssNone, ssHorizontal, ssVertical, ssBoth None, OnlyHorizontal, OnlyVertical, Both
}; };
enum class EditCaretType { enum class EditCaretType {