Clang import: Improved handling of empty structs/classes

This commit is contained in:
Daniel Marjamäki 2020-11-01 08:44:38 +01:00
parent 7804b28e70
commit 226e996e46
2 changed files with 15 additions and 11 deletions

View File

@ -717,8 +717,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
if (nodeType == CXXOperatorCallExpr)
return createTokensCall(tokenList);
if (nodeType == CXXRecordDecl) {
if (!children.empty())
createTokensForCXXRecord(tokenList);
createTokensForCXXRecord(tokenList);
return nullptr;
}
if (nodeType == CXXStaticCastExpr || nodeType == CXXFunctionalCastExpr) {
@ -957,13 +956,13 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
addtoken(tokenList, getSpelling());
if (children.empty())
addtoken(tokenList, ";");
else {
Scope *recordScope = createScope(tokenList, Scope::ScopeType::eStruct, children, classDef);
mData->mSymbolDatabase->typeList.push_back(Type(classDef, recordScope, classDef->scope()));
recordScope->definedType = &mData->mSymbolDatabase->typeList.back();
if (!recordName.empty())
const_cast<Scope *>(classDef->scope())->definedTypesMap[recordName] = recordScope->definedType;
}
Scope *recordScope = createScope(tokenList, Scope::ScopeType::eStruct, children, classDef);
mData->mSymbolDatabase->typeList.push_back(Type(classDef, recordScope, classDef->scope()));
recordScope->definedType = &mData->mSymbolDatabase->typeList.back();
if (!recordName.empty())
const_cast<Scope *>(classDef->scope())->definedTypesMap[recordName] = recordScope->definedType;
return nullptr;
}
if (nodeType == ReturnStmt) {
@ -1175,7 +1174,12 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList)
{
bool isStruct = (std::find(mExtTokens.begin(), mExtTokens.end(), "struct") != mExtTokens.end());
Token *classToken = addtoken(tokenList, isStruct ? "struct" : "class");
const std::string className = mExtTokens[mExtTokens.size() - 2] + getTemplateParameters();
std::string className;
if (mExtTokens[mExtTokens.size() - 2] == (isStruct?"struct":"class"))
className = mExtTokens.back();
else
className = mExtTokens[mExtTokens.size() - 2];
className += getTemplateParameters();
/*Token *nameToken =*/ addtoken(tokenList, className);
std::vector<AstNodePtr> children2;
for (AstNodePtr child: children) {

View File

@ -551,7 +551,7 @@ private:
void cxxRecordDecl1() {
const char clang[] = "`-CXXRecordDecl 0x34cc5f8 <1.cpp:2:1, col:7> col:7 class Foo";
ASSERT_EQUALS("", parse(clang));
ASSERT_EQUALS("class Foo ;", parse(clang));
}
void cxxStaticCastExpr1() {