[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- TestClangASTImporter.cpp ------------------------------------------===//
|
2019-12-16 17:06:38 +08:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
[lldb] Move clang-based files out of Symbol
Summary:
This change represents the move of ClangASTImporter, ClangASTMetadata,
ClangExternalASTSourceCallbacks, ClangUtil, CxxModuleHandler, and
TypeSystemClang from lldbSource to lldbPluginExpressionParserClang.h
This explicitly removes knowledge of clang internals from lldbSymbol,
moving towards a more generic core implementation of lldb.
Reviewers: JDevlieghere, davide, aprantl, teemperor, clayborg, labath, jingham, shafik
Subscribers: emaste, mgorny, arphaman, jfb, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73661
2020-01-30 03:59:28 +08:00
|
|
|
#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"
|
|
|
|
#include "Plugins/ExpressionParser/Clang/ClangASTMetadata.h"
|
|
|
|
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
|
|
|
|
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
|
2019-12-23 17:38:12 +08:00
|
|
|
#include "TestingSupport/SubsystemRAII.h"
|
2019-12-20 22:09:40 +08:00
|
|
|
#include "TestingSupport/Symbol/ClangTestUtils.h"
|
2021-04-30 11:35:59 +08:00
|
|
|
#include "lldb/Core/Declaration.h"
|
2019-12-16 17:06:38 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
|
|
|
#include "lldb/Host/HostInfo.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
class TestClangASTImporter : public testing::Test {
|
|
|
|
public:
|
2019-12-23 17:38:12 +08:00
|
|
|
SubsystemRAII<FileSystem, HostInfo> subsystems;
|
2019-12-16 17:06:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, CanImportInvalidType) {
|
|
|
|
ClangASTImporter importer;
|
|
|
|
EXPECT_FALSE(importer.CanImport(CompilerType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, ImportInvalidType) {
|
|
|
|
ClangASTImporter importer;
|
|
|
|
EXPECT_FALSE(importer.Import(CompilerType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, CopyDeclTagDecl) {
|
|
|
|
// Tests that the ClangASTImporter::CopyDecl can copy TagDecls.
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
2019-12-16 17:06:38 +08:00
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> target_ast = clang_utils::createAST();
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
2019-12-20 22:09:40 +08:00
|
|
|
clang::Decl *imported =
|
2019-12-22 05:40:52 +08:00
|
|
|
importer.CopyDecl(&target_ast->getASTContext(), source.record_decl);
|
2019-12-16 17:06:38 +08:00
|
|
|
ASSERT_NE(nullptr, imported);
|
|
|
|
|
|
|
|
// Check that we got the correct decl by just comparing their qualified name.
|
|
|
|
clang::TagDecl *imported_tag_decl = llvm::cast<clang::TagDecl>(imported);
|
2019-12-20 22:09:40 +08:00
|
|
|
EXPECT_EQ(source.record_decl->getQualifiedNameAsString(),
|
2019-12-16 17:06:38 +08:00
|
|
|
imported_tag_decl->getQualifiedNameAsString());
|
2019-12-20 21:18:02 +08:00
|
|
|
// We did a minimal import of the tag decl.
|
|
|
|
EXPECT_TRUE(imported_tag_decl->hasExternalLexicalStorage());
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
// Check that origin was set for the imported declaration.
|
|
|
|
ClangASTImporter::DeclOrigin origin = importer.GetDeclOrigin(imported);
|
|
|
|
EXPECT_TRUE(origin.Valid());
|
2019-12-22 05:40:52 +08:00
|
|
|
EXPECT_EQ(origin.ctx, &source.ast->getASTContext());
|
2019-12-20 22:09:40 +08:00
|
|
|
EXPECT_EQ(origin.decl, source.record_decl);
|
2019-12-16 17:06:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, CopyTypeTagDecl) {
|
|
|
|
// Tests that the ClangASTImporter::CopyType can copy TagDecls types.
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
2019-12-16 17:06:38 +08:00
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> target_ast = clang_utils::createAST();
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
2019-12-20 22:09:40 +08:00
|
|
|
CompilerType imported = importer.CopyType(*target_ast, source.record_type);
|
2019-12-16 17:06:38 +08:00
|
|
|
ASSERT_TRUE(imported.IsValid());
|
|
|
|
|
|
|
|
// Check that we got the correct decl by just comparing their qualified name.
|
|
|
|
clang::TagDecl *imported_tag_decl = ClangUtil::GetAsTagDecl(imported);
|
2019-12-20 22:09:40 +08:00
|
|
|
EXPECT_EQ(source.record_decl->getQualifiedNameAsString(),
|
2019-12-16 17:06:38 +08:00
|
|
|
imported_tag_decl->getQualifiedNameAsString());
|
2019-12-20 21:18:02 +08:00
|
|
|
// We did a minimal import of the tag decl.
|
|
|
|
EXPECT_TRUE(imported_tag_decl->hasExternalLexicalStorage());
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
// Check that origin was set for the imported declaration.
|
|
|
|
ClangASTImporter::DeclOrigin origin =
|
|
|
|
importer.GetDeclOrigin(imported_tag_decl);
|
|
|
|
EXPECT_TRUE(origin.Valid());
|
2019-12-22 05:40:52 +08:00
|
|
|
EXPECT_EQ(origin.ctx, &source.ast->getASTContext());
|
2019-12-20 22:09:40 +08:00
|
|
|
EXPECT_EQ(origin.decl, source.record_decl);
|
2019-12-16 17:06:38 +08:00
|
|
|
}
|
|
|
|
|
2020-01-29 16:20:06 +08:00
|
|
|
TEST_F(TestClangASTImporter, CompleteFwdDeclWithOtherOrigin) {
|
|
|
|
// Create an AST with a full type that is defined.
|
|
|
|
clang_utils::SourceASTWithRecord source_with_definition;
|
|
|
|
|
|
|
|
// Create an AST with a type thst is only a forward declaration with the
|
2021-05-30 22:14:17 +08:00
|
|
|
// same name as the one in the other source.
|
2020-01-29 16:20:06 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> fwd_decl_source = clang_utils::createAST();
|
|
|
|
CompilerType fwd_decl_type = clang_utils::createRecord(
|
|
|
|
*fwd_decl_source, source_with_definition.record_decl->getName());
|
|
|
|
|
|
|
|
// Create a target and import the forward decl.
|
|
|
|
std::unique_ptr<TypeSystemClang> target = clang_utils::createAST();
|
|
|
|
ClangASTImporter importer;
|
|
|
|
CompilerType imported = importer.CopyType(*target, fwd_decl_type);
|
|
|
|
ASSERT_TRUE(imported.IsValid());
|
|
|
|
EXPECT_FALSE(imported.IsDefined());
|
|
|
|
|
|
|
|
// Now complete the forward decl with the definition from the other source.
|
|
|
|
// This should define the decl and give it the fields of the other origin.
|
|
|
|
clang::TagDecl *imported_tag_decl = ClangUtil::GetAsTagDecl(imported);
|
|
|
|
importer.CompleteTagDeclWithOrigin(imported_tag_decl,
|
|
|
|
source_with_definition.record_decl);
|
|
|
|
ASSERT_TRUE(imported.IsValid());
|
|
|
|
EXPECT_TRUE(imported.IsDefined());
|
|
|
|
EXPECT_EQ(1U, imported.GetNumFields());
|
|
|
|
}
|
|
|
|
|
2019-12-20 21:18:02 +08:00
|
|
|
TEST_F(TestClangASTImporter, DeportDeclTagDecl) {
|
|
|
|
// Tests that the ClangASTImporter::DeportDecl completely copies TagDecls.
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
2019-12-20 21:18:02 +08:00
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> target_ast = clang_utils::createAST();
|
2019-12-20 21:18:02 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
2019-12-20 22:09:40 +08:00
|
|
|
clang::Decl *imported =
|
2019-12-22 05:40:52 +08:00
|
|
|
importer.DeportDecl(&target_ast->getASTContext(), source.record_decl);
|
2019-12-20 21:18:02 +08:00
|
|
|
ASSERT_NE(nullptr, imported);
|
|
|
|
|
|
|
|
// Check that we got the correct decl by just comparing their qualified name.
|
|
|
|
clang::TagDecl *imported_tag_decl = llvm::cast<clang::TagDecl>(imported);
|
2019-12-20 22:09:40 +08:00
|
|
|
EXPECT_EQ(source.record_decl->getQualifiedNameAsString(),
|
2019-12-20 21:18:02 +08:00
|
|
|
imported_tag_decl->getQualifiedNameAsString());
|
|
|
|
// The record should be completed as we deported it.
|
|
|
|
EXPECT_FALSE(imported_tag_decl->hasExternalLexicalStorage());
|
|
|
|
|
|
|
|
// Deporting doesn't update the origin map.
|
|
|
|
EXPECT_FALSE(importer.GetDeclOrigin(imported_tag_decl).Valid());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, DeportTypeTagDecl) {
|
|
|
|
// Tests that the ClangASTImporter::CopyType can deport TagDecl types.
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
2019-12-20 21:18:02 +08:00
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> target_ast = clang_utils::createAST();
|
2019-12-20 21:18:02 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
2019-12-20 22:09:40 +08:00
|
|
|
CompilerType imported = importer.DeportType(*target_ast, source.record_type);
|
2019-12-20 21:18:02 +08:00
|
|
|
ASSERT_TRUE(imported.IsValid());
|
|
|
|
|
|
|
|
// Check that we got the correct decl by just comparing their qualified name.
|
|
|
|
clang::TagDecl *imported_tag_decl = ClangUtil::GetAsTagDecl(imported);
|
2019-12-20 22:09:40 +08:00
|
|
|
EXPECT_EQ(source.record_decl->getQualifiedNameAsString(),
|
2019-12-20 21:18:02 +08:00
|
|
|
imported_tag_decl->getQualifiedNameAsString());
|
|
|
|
// The record should be completed as we deported it.
|
|
|
|
EXPECT_FALSE(imported_tag_decl->hasExternalLexicalStorage());
|
|
|
|
|
|
|
|
// Deporting doesn't update the origin map.
|
|
|
|
EXPECT_FALSE(importer.GetDeclOrigin(imported_tag_decl).Valid());
|
|
|
|
}
|
|
|
|
|
2019-12-16 17:06:38 +08:00
|
|
|
TEST_F(TestClangASTImporter, MetadataPropagation) {
|
|
|
|
// Tests that AST metadata is propagated when copying declarations.
|
|
|
|
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
|
|
|
|
2019-12-16 17:06:38 +08:00
|
|
|
const lldb::user_id_t metadata = 123456;
|
2019-12-20 22:09:40 +08:00
|
|
|
source.ast->SetMetadataAsUserID(source.record_decl, metadata);
|
2019-12-16 17:06:38 +08:00
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> target_ast = clang_utils::createAST();
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
2019-12-20 22:09:40 +08:00
|
|
|
clang::Decl *imported =
|
2019-12-22 05:40:52 +08:00
|
|
|
importer.CopyDecl(&target_ast->getASTContext(), source.record_decl);
|
2019-12-16 17:06:38 +08:00
|
|
|
ASSERT_NE(nullptr, imported);
|
|
|
|
|
|
|
|
// Check that we got the same Metadata.
|
|
|
|
ASSERT_NE(nullptr, importer.GetDeclMetadata(imported));
|
|
|
|
EXPECT_EQ(metadata, importer.GetDeclMetadata(imported)->GetUserID());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, MetadataPropagationIndirectImport) {
|
|
|
|
// Tests that AST metadata is propagated when copying declarations when
|
|
|
|
// importing one declaration into a temporary context and then to the
|
|
|
|
// actual destination context.
|
|
|
|
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
|
|
|
|
2019-12-16 17:06:38 +08:00
|
|
|
const lldb::user_id_t metadata = 123456;
|
2019-12-20 22:09:40 +08:00
|
|
|
source.ast->SetMetadataAsUserID(source.record_decl, metadata);
|
2019-12-16 17:06:38 +08:00
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> temporary_ast = clang_utils::createAST();
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
2019-12-20 22:09:40 +08:00
|
|
|
clang::Decl *temporary_imported =
|
2019-12-22 05:40:52 +08:00
|
|
|
importer.CopyDecl(&temporary_ast->getASTContext(), source.record_decl);
|
2019-12-16 17:06:38 +08:00
|
|
|
ASSERT_NE(nullptr, temporary_imported);
|
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> target_ast = clang_utils::createAST();
|
2019-12-16 17:06:38 +08:00
|
|
|
clang::Decl *imported =
|
2019-12-22 05:40:52 +08:00
|
|
|
importer.CopyDecl(&target_ast->getASTContext(), temporary_imported);
|
2019-12-16 17:06:38 +08:00
|
|
|
ASSERT_NE(nullptr, imported);
|
|
|
|
|
|
|
|
// Check that we got the same Metadata.
|
|
|
|
ASSERT_NE(nullptr, importer.GetDeclMetadata(imported));
|
|
|
|
EXPECT_EQ(metadata, importer.GetDeclMetadata(imported)->GetUserID());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, MetadataPropagationAfterCopying) {
|
|
|
|
// Tests that AST metadata is propagated when copying declarations even
|
|
|
|
// when the metadata was set after the declaration has already been copied.
|
|
|
|
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
2019-12-16 17:06:38 +08:00
|
|
|
const lldb::user_id_t metadata = 123456;
|
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
std::unique_ptr<TypeSystemClang> target_ast = clang_utils::createAST();
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
2019-12-20 22:09:40 +08:00
|
|
|
clang::Decl *imported =
|
2019-12-22 05:40:52 +08:00
|
|
|
importer.CopyDecl(&target_ast->getASTContext(), source.record_decl);
|
2019-12-16 17:06:38 +08:00
|
|
|
ASSERT_NE(nullptr, imported);
|
|
|
|
|
|
|
|
// The TagDecl has been imported. Now set the metadata of the source and
|
|
|
|
// make sure the imported one will directly see it.
|
2019-12-20 22:09:40 +08:00
|
|
|
source.ast->SetMetadataAsUserID(source.record_decl, metadata);
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
// Check that we got the same Metadata.
|
|
|
|
ASSERT_NE(nullptr, importer.GetDeclMetadata(imported));
|
|
|
|
EXPECT_EQ(metadata, importer.GetDeclMetadata(imported)->GetUserID());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TestClangASTImporter, RecordLayout) {
|
|
|
|
// Test that it is possible to register RecordDecl layouts and then later
|
|
|
|
// correctly retrieve them.
|
|
|
|
|
2019-12-20 22:09:40 +08:00
|
|
|
clang_utils::SourceASTWithRecord source;
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
ClangASTImporter importer;
|
|
|
|
ClangASTImporter::LayoutInfo layout_info;
|
|
|
|
layout_info.bit_size = 15;
|
|
|
|
layout_info.alignment = 2;
|
2019-12-20 22:09:40 +08:00
|
|
|
layout_info.field_offsets[source.field_decl] = 1;
|
|
|
|
importer.SetRecordLayout(source.record_decl, layout_info);
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
uint64_t bit_size;
|
|
|
|
uint64_t alignment;
|
|
|
|
llvm::DenseMap<const clang::FieldDecl *, uint64_t> field_offsets;
|
|
|
|
llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> base_offsets;
|
|
|
|
llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> vbase_offsets;
|
2019-12-20 22:09:40 +08:00
|
|
|
importer.LayoutRecordType(source.record_decl, bit_size, alignment,
|
|
|
|
field_offsets, base_offsets, vbase_offsets);
|
2019-12-16 17:06:38 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(15U, bit_size);
|
|
|
|
EXPECT_EQ(2U, alignment);
|
|
|
|
EXPECT_EQ(1U, field_offsets.size());
|
2019-12-20 22:09:40 +08:00
|
|
|
EXPECT_EQ(1U, field_offsets[source.field_decl]);
|
2019-12-16 17:06:38 +08:00
|
|
|
EXPECT_EQ(0U, base_offsets.size());
|
|
|
|
EXPECT_EQ(0U, vbase_offsets.size());
|
|
|
|
}
|