From 569523bbef57f3a29bee7cd3d8f848fcf3119ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 25 Jan 2020 09:31:47 +0100 Subject: [PATCH] Clang import; Better handling of enums --- lib/clangimport.cpp | 3 ++- lib/symboldatabase.cpp | 5 +++++ test/testclangimport.cpp | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index ef1727829..1097c91ad 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -464,10 +464,11 @@ Scope *clangimport::AstNode::createScope(TokenList *tokenList, Scope::ScopeType { SymbolDatabase *symbolDatabase = mData->mSymbolDatabase; - const Scope *nestedIn = getNestedInScope(tokenList); + Scope *nestedIn = const_cast(getNestedInScope(tokenList)); symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, nestedIn)); Scope *scope = &symbolDatabase->scopeList.back(); + nestedIn->nestedList.push_back(scope); scope->type = scopeType; scope->classDef = def; Token *bodyStart = children[0]->addtoken(tokenList, "{"); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 38ca0545f..ccaa1034f 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5547,6 +5547,11 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V if (container) { valuetype->type = ValueType::Type::CONTAINER; valuetype->container = container; + } else { + const Scope *scope = type->scope(); + valuetype->typeScope = scope->check->findScope(typeTokens.front(), scope); + if (valuetype->typeScope) + valuetype->type = (scope->type == Scope::ScopeType::eClass) ? ValueType::Type::RECORD : ValueType::Type::NONSTD; } } else if (const Library::Container *container = settings->library.detectContainer(type)) { valuetype->type = ValueType::Type::CONTAINER; diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 477dc91ce..66e577163 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -99,6 +99,7 @@ private: std::string parse(const char clang[]) { Settings settings; + settings.clang = true; Tokenizer tokenizer(&settings, this); std::istringstream istr(clang); clangimport::parseClangAstDump(&tokenizer, istr); @@ -793,6 +794,7 @@ private: #define GET_SYMBOL_DB(clang) \ Settings settings; \ + settings.clang = true; \ settings.platform(cppcheck::Platform::PlatformType::Unix64); \ Tokenizer tokenizer(&settings, this); \ std::istringstream istr(clang); \ @@ -829,7 +831,8 @@ private: const Token *vartok = Token::findsimplematch(tokenizer.tokens(), "x"); ASSERT(vartok); ASSERT(vartok->variable()); - //ASSERT(vartok->variable()->valueType()); + ASSERT(vartok->variable()->valueType()); + ASSERT_EQUALS(uintptr_t(&enumScope), uintptr_t(vartok->variable()->valueType()->typeScope)); } void symbolDatabaseFunction1() {