forked from OSchip/llvm-project
[clang-move] Fix incorrect EndLoc for declarations in macros.
Reviewers: ioeric Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D27713 llvm-svn: 289541
This commit is contained in:
parent
79d1255e26
commit
dc4edba576
|
@ -219,7 +219,8 @@ SourceLocation
|
|||
getLocForEndOfDecl(const clang::Decl *D,
|
||||
const LangOptions &LangOpts = clang::LangOptions()) {
|
||||
const auto &SM = D->getASTContext().getSourceManager();
|
||||
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(D->getLocEnd());
|
||||
auto EndExpansionLoc = SM.getExpansionLoc(D->getLocEnd());
|
||||
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(EndExpansionLoc);
|
||||
// Try to load the file buffer.
|
||||
bool InvalidTemp = false;
|
||||
llvm::StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
|
||||
|
@ -235,7 +236,7 @@ getLocForEndOfDecl(const clang::Decl *D,
|
|||
// FIXME: this is a bit hacky to get ReadToEndOfLine work.
|
||||
Lex.setParsingPreprocessorDirective(true);
|
||||
Lex.ReadToEndOfLine(&Line);
|
||||
SourceLocation EndLoc = D->getLocEnd().getLocWithOffset(Line.size());
|
||||
SourceLocation EndLoc = EndExpansionLoc.getLocWithOffset(Line.size());
|
||||
// If we already reach EOF, just return the EOF SourceLocation;
|
||||
// otherwise, move 1 offset ahead to include the trailing newline character
|
||||
// '\n'.
|
||||
|
|
|
@ -386,6 +386,24 @@ TEST(ClangMove, MacroInFunction) {
|
|||
EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]);
|
||||
}
|
||||
|
||||
TEST(ClangMove, DefinitionInMacro) {
|
||||
const char TestHeader[] = "#define DEF(CLASS) void CLASS##_::f() {}\n"
|
||||
"class A_ {\nvoid f();\n};\n"
|
||||
"class B {};\n";
|
||||
const char TestCode[] = "#include \"foo.h\"\n"
|
||||
"DEF(A)\n";
|
||||
const char ExpectedNewCode[] = "#include \"new_foo.h\"\n\n"
|
||||
"DEF(A)\n";
|
||||
move::MoveDefinitionSpec Spec;
|
||||
Spec.Names.push_back("A_");
|
||||
Spec.OldHeader = "foo.h";
|
||||
Spec.OldCC = "foo.cc";
|
||||
Spec.NewHeader = "new_foo.h";
|
||||
Spec.NewCC = "new_foo.cc";
|
||||
auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
|
||||
EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]);
|
||||
}
|
||||
|
||||
TEST(ClangMove, WellFormattedCode) {
|
||||
const std::string CommonHeader =
|
||||
"namespace a {\n"
|
||||
|
|
Loading…
Reference in New Issue