[AST] add parenthesis locations for IfStmt and SwitchStmt
Differential Revision: https://reviews.llvm.org/D85696
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index ee6daf4..7334d5b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6067,6 +6067,8 @@
auto ToInit = importChecked(Err, S->getInit());
auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
auto ToCond = importChecked(Err, S->getCond());
+ auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
+ auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
auto ToThen = importChecked(Err, S->getThen());
auto ToElseLoc = importChecked(Err, S->getElseLoc());
auto ToElse = importChecked(Err, S->getElse());
@@ -6074,8 +6076,8 @@
return std::move(Err);
return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(),
- ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc,
- ToElse);
+ ToInit, ToConditionVariable, ToCond, ToLParenLoc,
+ ToRParenLoc, ToThen, ToElseLoc, ToElse);
}
ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) {
@@ -6084,13 +6086,16 @@
auto ToInit = importChecked(Err, S->getInit());
auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
auto ToCond = importChecked(Err, S->getCond());
+ auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
+ auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
auto ToBody = importChecked(Err, S->getBody());
auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
if (Err)
return std::move(Err);
- auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit,
- ToConditionVariable, ToCond);
+ auto *ToStmt =
+ SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
+ ToCond, ToLParenLoc, ToRParenLoc);
ToStmt->setBody(ToBody);
ToStmt->setSwitchLoc(ToSwitchLoc);
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp
index 25e685b..25078e7 100644
--- a/clang/lib/AST/Stmt.cpp
+++ b/clang/lib/AST/Stmt.cpp
@@ -827,9 +827,9 @@
}
IfStmt::IfStmt(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr,
- Stmt *Init, VarDecl *Var, Expr *Cond, Stmt *Then,
- SourceLocation EL, Stmt *Else)
- : Stmt(IfStmtClass) {
+ Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL,
+ SourceLocation RPL, Stmt *Then, SourceLocation EL, Stmt *Else)
+ : Stmt(IfStmtClass), LParenLoc(LPL), RParenLoc(RPL) {
bool HasElse = Else != nullptr;
bool HasVar = Var != nullptr;
bool HasInit = Init != nullptr;
@@ -862,7 +862,8 @@
IfStmt *IfStmt::Create(const ASTContext &Ctx, SourceLocation IL,
bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond,
- Stmt *Then, SourceLocation EL, Stmt *Else) {
+ SourceLocation LPL, SourceLocation RPL, Stmt *Then,
+ SourceLocation EL, Stmt *Else) {
bool HasElse = Else != nullptr;
bool HasVar = Var != nullptr;
bool HasInit = Init != nullptr;
@@ -871,7 +872,7 @@
NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
alignof(IfStmt));
return new (Mem)
- IfStmt(Ctx, IL, IsConstexpr, Init, Var, Cond, Then, EL, Else);
+ IfStmt(Ctx, IL, IsConstexpr, Init, Var, Cond, LPL, RPL, Then, EL, Else);
}
IfStmt *IfStmt::CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
@@ -947,8 +948,10 @@
}
SwitchStmt::SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
- Expr *Cond)
- : Stmt(SwitchStmtClass), FirstCase(nullptr) {
+ Expr *Cond, SourceLocation LParenLoc,
+ SourceLocation RParenLoc)
+ : Stmt(SwitchStmtClass), FirstCase(nullptr), LParenLoc(LParenLoc),
+ RParenLoc(RParenLoc) {
bool HasInit = Init != nullptr;
bool HasVar = Var != nullptr;
SwitchStmtBits.HasInit = HasInit;
@@ -973,13 +976,14 @@
}
SwitchStmt *SwitchStmt::Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
- Expr *Cond) {
+ Expr *Cond, SourceLocation LParenLoc,
+ SourceLocation RParenLoc) {
bool HasInit = Init != nullptr;
bool HasVar = Var != nullptr;
void *Mem = Ctx.Allocate(
totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
alignof(SwitchStmt));
- return new (Mem) SwitchStmt(Ctx, Init, Var, Cond);
+ return new (Mem) SwitchStmt(Ctx, Init, Var, Cond, LParenLoc, RParenLoc);
}
SwitchStmt *SwitchStmt::CreateEmpty(const ASTContext &Ctx, bool HasInit,