Handle var initialization. (#628)

This commit is contained in:
Jon Meow
2021-07-09 11:29:38 -07:00
committed by GitHub
parent c96ee2aaac
commit 3082d05f80
20 changed files with 605 additions and 468 deletions
+12 -4
View File
@@ -116,11 +116,19 @@ void VarDecl::Run() {
type_loc.getEndLoc(), 0, GetSourceManager(), GetLangOpts());
llvm::StringRef comma_source_text = GetSourceText(
clang::CharSourceRange::getCharRange(after_type_loc, decl.getLocation()));
bool has_comma = !comma_source_text.trim().empty();
clang::CharSourceRange replace_range = clang::CharSourceRange::getTokenRange(
has_comma ? decl.getLocation() : decl.getBeginLoc(), decl.getEndLoc());
clang::SourceLocation replace_start = !comma_source_text.trim().empty()
? decl.getLocation()
: decl.getBeginLoc();
AddReplacement(replace_range, after);
// Figure out where the replacement ends and initialization begins. For
// example, `int i` the end is the identifier, `int i[4]` the end is the `[4]`
// type qualifier.
clang::SourceLocation identifier_end = clang::Lexer::getLocForEndOfToken(
decl.getLocation(), 0, GetSourceManager(), GetLangOpts());
clang::SourceLocation replace_end = std::max(identifier_end, after_type_loc);
AddReplacement(
clang::CharSourceRange::getCharRange(replace_start, replace_end), after);
}
auto VarDeclFactory::GetAstMatcher() -> cam::DeclarationMatcher {