You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
INPUTS
bindings
cmake
docs
examples
include
lib
runtime
tools
unittests
AST
ASTContextParentMapTest.cpp
ASTImporterTest.cpp
ASTTypeTraitsTest.cpp
ASTVectorTest.cpp
CMakeLists.txt
CommentLexer.cpp
CommentParser.cpp
DataCollectionTest.cpp
DeclPrinterTest.cpp
DeclTest.cpp
EvaluateAsRValueTest.cpp
ExternalASTSourceTest.cpp
MatchVerifier.h
NamedDeclPrinterTest.cpp
PostOrderASTVisitor.cpp
SourceLocationTest.cpp
StmtPrinterTest.cpp
ASTMatchers
Analysis
Basic
CodeGen
CrossTU
Driver
Format
Frontend
Lex
Rename
Rewrite
Sema
StaticAnalyzer
Tooling
libclang
CMakeLists.txt
utils
www
.arcconfig
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
INSTALL.txt
LICENSE.TXT
ModuleInfo.txt
NOTES.txt
README.txt
clang-tools-extra
compiler-rt
libcxx
libcxxabi
libunwind
lld
lldb
llvm
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
85 lines
2.7 KiB
C++
85 lines
2.7 KiB
C++
//===- unittest/AST/ExternalASTSourceTest.cpp -----------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains tests for Clang's ExternalASTSource.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/AST/ASTConsumer.h"
|
|
#include "clang/AST/ASTContext.h"
|
|
#include "clang/AST/ExternalASTSource.h"
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
#include "clang/Frontend/CompilerInvocation.h"
|
|
#include "clang/Frontend/FrontendActions.h"
|
|
#include "clang/Lex/PreprocessorOptions.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace clang;
|
|
using namespace llvm;
|
|
|
|
|
|
class TestFrontendAction : public ASTFrontendAction {
|
|
public:
|
|
TestFrontendAction(ExternalASTSource *Source) : Source(Source) {}
|
|
|
|
private:
|
|
void ExecuteAction() override {
|
|
getCompilerInstance().getASTContext().setExternalSource(Source);
|
|
getCompilerInstance().getASTContext().getTranslationUnitDecl()
|
|
->setHasExternalVisibleStorage();
|
|
return ASTFrontendAction::ExecuteAction();
|
|
}
|
|
|
|
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
|
StringRef InFile) override {
|
|
return llvm::make_unique<ASTConsumer>();
|
|
}
|
|
|
|
IntrusiveRefCntPtr<ExternalASTSource> Source;
|
|
};
|
|
|
|
bool testExternalASTSource(ExternalASTSource *Source,
|
|
StringRef FileContents) {
|
|
CompilerInstance Compiler;
|
|
Compiler.createDiagnostics();
|
|
|
|
auto Invocation = std::make_shared<CompilerInvocation>();
|
|
Invocation->getPreprocessorOpts().addRemappedFile(
|
|
"test.cc", MemoryBuffer::getMemBuffer(FileContents).release());
|
|
const char *Args[] = { "test.cc" };
|
|
CompilerInvocation::CreateFromArgs(*Invocation, Args,
|
|
Args + array_lengthof(Args),
|
|
Compiler.getDiagnostics());
|
|
Compiler.setInvocation(std::move(Invocation));
|
|
|
|
TestFrontendAction Action(Source);
|
|
return Compiler.ExecuteAction(Action);
|
|
}
|
|
|
|
|
|
// Ensure that a failed name lookup into an external source only occurs once.
|
|
TEST(ExternalASTSourceTest, FailedLookupOccursOnce) {
|
|
struct TestSource : ExternalASTSource {
|
|
TestSource(unsigned &Calls) : Calls(Calls) {}
|
|
|
|
bool FindExternalVisibleDeclsByName(const DeclContext *,
|
|
DeclarationName Name) override {
|
|
if (Name.getAsString() == "j")
|
|
++Calls;
|
|
return false;
|
|
}
|
|
|
|
unsigned &Calls;
|
|
};
|
|
|
|
unsigned Calls = 0;
|
|
ASSERT_TRUE(testExternalASTSource(new TestSource(Calls), "int j, k = j;"));
|
|
EXPECT_EQ(1u, Calls);
|
|
}
|