Clang import: Improved handling of empty structs/classes
This commit is contained in:
parent
7804b28e70
commit
226e996e46
|
@ -717,8 +717,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
|
||||||
if (nodeType == CXXOperatorCallExpr)
|
if (nodeType == CXXOperatorCallExpr)
|
||||||
return createTokensCall(tokenList);
|
return createTokensCall(tokenList);
|
||||||
if (nodeType == CXXRecordDecl) {
|
if (nodeType == CXXRecordDecl) {
|
||||||
if (!children.empty())
|
createTokensForCXXRecord(tokenList);
|
||||||
createTokensForCXXRecord(tokenList);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (nodeType == CXXStaticCastExpr || nodeType == CXXFunctionalCastExpr) {
|
if (nodeType == CXXStaticCastExpr || nodeType == CXXFunctionalCastExpr) {
|
||||||
|
@ -957,13 +956,13 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
|
||||||
addtoken(tokenList, getSpelling());
|
addtoken(tokenList, getSpelling());
|
||||||
if (children.empty())
|
if (children.empty())
|
||||||
addtoken(tokenList, ";");
|
addtoken(tokenList, ";");
|
||||||
else {
|
|
||||||
Scope *recordScope = createScope(tokenList, Scope::ScopeType::eStruct, children, classDef);
|
Scope *recordScope = createScope(tokenList, Scope::ScopeType::eStruct, children, classDef);
|
||||||
mData->mSymbolDatabase->typeList.push_back(Type(classDef, recordScope, classDef->scope()));
|
mData->mSymbolDatabase->typeList.push_back(Type(classDef, recordScope, classDef->scope()));
|
||||||
recordScope->definedType = &mData->mSymbolDatabase->typeList.back();
|
recordScope->definedType = &mData->mSymbolDatabase->typeList.back();
|
||||||
if (!recordName.empty())
|
if (!recordName.empty())
|
||||||
const_cast<Scope *>(classDef->scope())->definedTypesMap[recordName] = recordScope->definedType;
|
const_cast<Scope *>(classDef->scope())->definedTypesMap[recordName] = recordScope->definedType;
|
||||||
}
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (nodeType == ReturnStmt) {
|
if (nodeType == ReturnStmt) {
|
||||||
|
@ -1175,7 +1174,12 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList)
|
||||||
{
|
{
|
||||||
bool isStruct = (std::find(mExtTokens.begin(), mExtTokens.end(), "struct") != mExtTokens.end());
|
bool isStruct = (std::find(mExtTokens.begin(), mExtTokens.end(), "struct") != mExtTokens.end());
|
||||||
Token *classToken = addtoken(tokenList, isStruct ? "struct" : "class");
|
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);
|
/*Token *nameToken =*/ addtoken(tokenList, className);
|
||||||
std::vector<AstNodePtr> children2;
|
std::vector<AstNodePtr> children2;
|
||||||
for (AstNodePtr child: children) {
|
for (AstNodePtr child: children) {
|
||||||
|
|
|
@ -551,7 +551,7 @@ private:
|
||||||
|
|
||||||
void cxxRecordDecl1() {
|
void cxxRecordDecl1() {
|
||||||
const char clang[] = "`-CXXRecordDecl 0x34cc5f8 <1.cpp:2:1, col:7> col:7 class Foo";
|
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() {
|
void cxxStaticCastExpr1() {
|
||||||
|
|
Loading…
Reference in New Issue