mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 09:10:10 +01:00
Handle var initialization. (#628)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user