- enhancement: Support "extern template" in parser.

This commit is contained in:
Roy Qu 2024-04-01 10:59:01 +08:00
parent 158945f8db
commit 1372ac774f
5 changed files with 40 additions and 11 deletions

View File

@ -111,6 +111,7 @@ Red Panda C++ Version 2.27
- enhancement: Make colors in code suggestion popup consistent with the editor. - enhancement: Make colors in code suggestion popup consistent with the editor.
- enhancement: Make colors in header suggestion popup consistent with the editor. - enhancement: Make colors in header suggestion popup consistent with the editor.
- fix: C++ source after ';' are treated as comments in cpu info window. - fix: C++ source after ';' are treated as comments in cpu info window.
- enhancement: Support "extern template" in code parser.
Red Panda C++ Version 2.26 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.

View File

@ -636,6 +636,23 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement) const
return doFindAliasedStatement(statement,foundSet); return doFindAliasedStatement(statement,foundSet);
} }
PStatement CppParser::doFindNoTemplateSpecializationClass(const PStatement &statement) const
{
Q_ASSERT(statement!=nullptr);
Q_ASSERT(statement->kind == StatementKind::skClass);
if (statement->templateSpecializationParams.isEmpty())
return statement;
PStatement parent = statement->parentScope.lock();
const StatementMap & statementMap = mStatementList.childrenStatements(parent);
QList<PStatement> list = statementMap.values(statement->command);
foreach(const PStatement &child, list) {
if (child->kind == StatementKind::skClass
&& child->templateSpecializationParams.isEmpty())
return child;
}
return statement;
}
PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<Statement *> foundSet) const PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<Statement *> foundSet) const
{ {
if (!statement) if (!statement)
@ -2040,6 +2057,7 @@ bool CppParser::checkForKeyword(KeywordType& keywordType)
case KeywordType::Operator: case KeywordType::Operator:
case KeywordType::Requires: case KeywordType::Requires:
case KeywordType::Concept: case KeywordType::Concept:
case KeywordType::Extern:
return false; return false;
default: default:
return true; return true;
@ -3548,11 +3566,21 @@ bool CppParser::handleStatement(int maxIndex)
} else if (keywordType == KeywordType::Inline) { } else if (keywordType == KeywordType::Inline) {
mIndex++; mIndex++;
}else { }else {
if (keywordType == KeywordType::Extern) {
if (mIndex+1<maxIndex) {
if (mTokenizer[mIndex+1]->text=="template") {
//extern template, skit it
mIndex+=2;
goto _exit;
}
}
keywordType = KeywordType::None;
}
// it should be method/constructor/var // it should be method/constructor/var
checkAndHandleMethodOrVar(keywordType, maxIndex); checkAndHandleMethodOrVar(keywordType, maxIndex);
} }
//Q_ASSERT(mIndex<999999); //Q_ASSERT(mIndex<999999);
_exit:
return mIndex < maxIndex; return mIndex < maxIndex;
} }
@ -5256,18 +5284,14 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
case StatementKind::skNamespaceAlias: case StatementKind::skNamespaceAlias:
result = doFindAliasedNamespace(statement); result = doFindAliasedNamespace(statement);
break; break;
// case StatementKind::skAlias: {
// statement =
// if (statement)
// result = doCreateEvalType(fileName,statement);
// }
// break;
case StatementKind::skVariable: case StatementKind::skVariable:
case StatementKind::skParameter: case StatementKind::skParameter:
result = doCreateEvalVariable(fileName,statement, previousResult?previousResult->templateParams:"",scope); result = doCreateEvalVariable(fileName,statement, previousResult?previousResult->templateParams:"",scope);
break; break;
case StatementKind::skEnumType:
case StatementKind::skClass: case StatementKind::skClass:
statement = doFindNoTemplateSpecializationClass(statement);
[[fallthrough]];
case StatementKind::skEnumType:
case StatementKind::skEnumClassType: case StatementKind::skEnumClassType:
case StatementKind::skTypedef: case StatementKind::skTypedef:
result = doCreateEvalType(fileName,statement); result = doCreateEvalType(fileName,statement);
@ -5542,7 +5566,7 @@ PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatem
int pointerLevel=0; int pointerLevel=0;
QString templateParams; QString templateParams;
PStatement tempStatement; PStatement tempStatement;
PStatement effetiveTypeStatement = doParseEvalTypeInfo( PStatement effectiveTypeStatement = doParseEvalTypeInfo(
fileName, fileName,
typeStatement->parentScope.lock(), typeStatement->parentScope.lock(),
typeStatement->type + typeStatement->args, typeStatement->type + typeStatement->args,
@ -5550,12 +5574,14 @@ PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatem
tempStatement, tempStatement,
pointerLevel, pointerLevel,
templateParams); templateParams);
if (effectiveTypeStatement && effectiveTypeStatement->kind == StatementKind::skClass)
effectiveTypeStatement = doFindNoTemplateSpecializationClass(effectiveTypeStatement);
return std::make_shared<EvalStatement>( return std::make_shared<EvalStatement>(
baseType, baseType,
EvalStatementKind::Type, EvalStatementKind::Type,
PStatement(), PStatement(),
typeStatement, typeStatement,
effetiveTypeStatement, effectiveTypeStatement,
pointerLevel, pointerLevel,
templateParams templateParams
); );

View File

@ -262,6 +262,7 @@ private:
int line) const; int line) const;
PStatement doFindAliasedStatement(const PStatement& statement, QSet<Statement *> foundSet) const; PStatement doFindAliasedStatement(const PStatement& statement, QSet<Statement *> foundSet) const;
PStatement doFindAliasedStatement(const PStatement& statement) const; PStatement doFindAliasedStatement(const PStatement& statement) const;
PStatement doFindNoTemplateSpecializationClass(const PStatement& statement) const;
QList<PStatement> doListTypeStatements(const QString& fileName,int line) const; QList<PStatement> doListTypeStatements(const QString& fileName,int line) const;

View File

@ -218,7 +218,7 @@ void initParser()
// it's part of type info // it's part of type info
CppKeywords.insert("const",KeywordType::None); CppKeywords.insert("const",KeywordType::None);
CppKeywords.insert("extern",KeywordType::None); CppKeywords.insert("extern",KeywordType::Extern);
CppKeywords.insert("operator",KeywordType::Operator); CppKeywords.insert("operator",KeywordType::Operator);

View File

@ -84,6 +84,7 @@ enum class KeywordType {
Concept, //concept Concept, //concept
Requires, //requires Requires, //requires
None, // It's a keyword but don't process here None, // It's a keyword but don't process here
Extern,
NotKeyword NotKeyword
}; };