forked from OSchip/llvm-project
Finish converting SwitchStmt AST to source ranges.
Move DumpSourceRange() to DumpStmt(). Now -parse-ast-dump will display source range info for all stmts/exprs. One day we should implement the source range protocol for Decls. llvm-svn: 41670
This commit is contained in:
parent
2089a21360
commit
42a350a18a
|
@ -78,7 +78,7 @@ namespace {
|
||||||
fprintf(F, " ");
|
fprintf(F, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DumpType(QualType T) const {
|
void DumpType(QualType T) {
|
||||||
fprintf(F, "'%s'", T.getAsString().c_str());
|
fprintf(F, "'%s'", T.getAsString().c_str());
|
||||||
|
|
||||||
// If the type is directly a typedef, strip off typedefness to give at
|
// If the type is directly a typedef, strip off typedefness to give at
|
||||||
|
@ -86,22 +86,18 @@ namespace {
|
||||||
if (TypedefType *TDT = dyn_cast<TypedefType>(T))
|
if (TypedefType *TDT = dyn_cast<TypedefType>(T))
|
||||||
fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
|
fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
|
||||||
}
|
}
|
||||||
|
void DumpStmt(const Stmt *Node) {
|
||||||
void DumpStmt(const Stmt *Node) const {
|
|
||||||
Indent();
|
Indent();
|
||||||
fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
|
fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
|
||||||
|
DumpSourceRange(Node);
|
||||||
}
|
}
|
||||||
|
void DumpExpr(const Expr *Node) {
|
||||||
void DumpExpr(Expr *Node) {
|
|
||||||
DumpStmt(Node);
|
DumpStmt(Node);
|
||||||
fprintf(F, " ");
|
fprintf(F, " ");
|
||||||
DumpType(Node->getType());
|
DumpType(Node->getType());
|
||||||
DumpSourceRange(Node);
|
|
||||||
}
|
}
|
||||||
|
void DumpSourceRange(const Stmt *Node);
|
||||||
void DumpSourceRange(Expr *Node);
|
|
||||||
void DumpLocation(SourceLocation Loc);
|
void DumpLocation(SourceLocation Loc);
|
||||||
|
|
||||||
|
|
||||||
// Stmts.
|
// Stmts.
|
||||||
void VisitStmt(Stmt *Node);
|
void VisitStmt(Stmt *Node);
|
||||||
|
@ -158,7 +154,7 @@ void StmtDumper::DumpLocation(SourceLocation Loc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StmtDumper::DumpSourceRange(Expr *Node) {
|
void StmtDumper::DumpSourceRange(const Stmt *Node) {
|
||||||
// Can't translate locations if a SourceManager isn't available.
|
// Can't translate locations if a SourceManager isn't available.
|
||||||
if (SM == 0) return;
|
if (SM == 0) return;
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ Sema::FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Body) {
|
||||||
SwitchStmt *SS = SwitchStack.back();
|
SwitchStmt *SS = SwitchStack.back();
|
||||||
assert(SS == (SwitchStmt*)Switch && "switch stack missing push/pop!");
|
assert(SS == (SwitchStmt*)Switch && "switch stack missing push/pop!");
|
||||||
|
|
||||||
SS->setBody(BodyStmt);
|
SS->setBody(BodyStmt, SwitchLoc);
|
||||||
SwitchStack.pop_back();
|
SwitchStack.pop_back();
|
||||||
|
|
||||||
Expr *CondExpr = SS->getCond();
|
Expr *CondExpr = SS->getCond();
|
||||||
|
|
|
@ -375,6 +375,7 @@ class SwitchStmt : public Stmt {
|
||||||
Stmt* SubExprs[END_EXPR];
|
Stmt* SubExprs[END_EXPR];
|
||||||
// This points to a linked list of case and default statements.
|
// This points to a linked list of case and default statements.
|
||||||
SwitchCase *FirstCase;
|
SwitchCase *FirstCase;
|
||||||
|
SourceLocation SwitchLoc;
|
||||||
public:
|
public:
|
||||||
SwitchStmt(Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0) {
|
SwitchStmt(Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0) {
|
||||||
SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
|
SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
|
||||||
|
@ -389,17 +390,19 @@ public:
|
||||||
Stmt *getBody() { return SubExprs[BODY]; }
|
Stmt *getBody() { return SubExprs[BODY]; }
|
||||||
SwitchCase *getSwitchCaseList() { return FirstCase; }
|
SwitchCase *getSwitchCaseList() { return FirstCase; }
|
||||||
|
|
||||||
void setBody(Stmt *S) { SubExprs[BODY] = S; }
|
void setBody(Stmt *S, SourceLocation SL) {
|
||||||
|
SubExprs[BODY] = S;
|
||||||
|
SwitchLoc = SL;
|
||||||
|
}
|
||||||
void addSwitchCase(SwitchCase *SC) {
|
void addSwitchCase(SwitchCase *SC) {
|
||||||
if (FirstCase)
|
if (FirstCase)
|
||||||
SC->setNextSwitchCase(FirstCase);
|
SC->setNextSwitchCase(FirstCase);
|
||||||
|
|
||||||
FirstCase = SC;
|
FirstCase = SC;
|
||||||
}
|
}
|
||||||
|
virtual SourceRange getSourceRange() const {
|
||||||
virtual SourceRange getSourceRange() const { return SourceRange(); }
|
return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
|
||||||
|
}
|
||||||
static bool classof(const Stmt *T) {
|
static bool classof(const Stmt *T) {
|
||||||
return T->getStmtClass() == SwitchStmtClass;
|
return T->getStmtClass() == SwitchStmtClass;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue