]> granicus.if.org Git - clang/commitdiff
Add location info for indirect goto.
authorChris Lattner <sabre@nondot.org>
Sun, 19 Apr 2009 01:04:21 +0000 (01:04 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 19 Apr 2009 01:04:21 +0000 (01:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69497 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
lib/AST/StmtSerialization.cpp
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp
lib/Sema/SemaStmt.cpp

index f665cfd58265aac00550ec924c7afca0d1c1f944..3c1e04f47aad4822df9222e8440c76f5ce72e56f 100644 (file)
@@ -850,22 +850,26 @@ public:
 /// IndirectGotoStmt - This represents an indirect goto.
 ///
 class IndirectGotoStmt : public Stmt {
+  SourceLocation GotoLoc;
   Stmt *Target;
-  // FIXME: Add location information (e.g. SourceLocation objects).
-  //        When doing so, update the PCH serialization routines.
 public:
-  IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass),
-                                   Target((Stmt*)target){}
+  IndirectGotoStmt(SourceLocation gotoLoc, Expr *target)
+    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), Target((Stmt*)target) {}
 
   /// \brief Build an empty indirect goto statement.
   explicit IndirectGotoStmt(EmptyShell Empty) 
     : Stmt(IndirectGotoStmtClass, Empty) { }
   
+  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
+  SourceLocation getGotoLoc() const { return GotoLoc; }
+  
   Expr *getTarget();
   const Expr *getTarget() const;
   void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
 
-  virtual SourceRange getSourceRange() const { return SourceRange(); }
+  virtual SourceRange getSourceRange() const {
+    return SourceRange(GotoLoc, Target->getLocEnd());
+  }
   
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() == IndirectGotoStmtClass; 
index 0d920fa23e3fcd110be3c08a67c753ac18209552..7a37a16550d156897fa8f3d5e4e5b04c5312b4bb 100644 (file)
@@ -691,7 +691,7 @@ void IndirectGotoStmt::EmitImpl(Serializer& S) const {
 
 IndirectGotoStmt* IndirectGotoStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   Expr* Target = D.ReadOwnedPtr<Expr>(C);
-  return new IndirectGotoStmt(Target);
+  return new IndirectGotoStmt(SourceLocation(), Target);
 }
 
 void InitListExpr::EmitImpl(Serializer& S) const {
index 6c79b8a5a57d6c3ad7b71c10a07740effea1d378..9af75aef2b4f90687849a2926a53931b4ef61367 100644 (file)
@@ -415,6 +415,7 @@ unsigned PCHStmtReader::VisitGotoStmt(GotoStmt *S) {
 
 unsigned PCHStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
   VisitStmt(S);
+  S->setGotoLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   S->setTarget(cast_or_null<Expr>(StmtStack.back()));
   return 1;
 }
index 1efe70f270feaef5d7995eef2797a7e50b97b5d5..9f22f13134bf3d69877e6bb06e1a18390a9ca8ae 100644 (file)
@@ -610,6 +610,7 @@ void PCHStmtWriter::VisitGotoStmt(GotoStmt *S) {
 
 void PCHStmtWriter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
   VisitStmt(S);
+  Writer.AddSourceLocation(S->getGotoLoc(), Record);
   Writer.WriteSubStmt(S->getTarget());
   Code = pch::STMT_INDIRECT_GOTO;
 }
index 6595b881220ee8e7ee50eb883905797355716403..4a5facb39ccec9540e5e682c7786a5b35f88b417 100644 (file)
@@ -666,7 +666,7 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
 }
 
 Action::OwningStmtResult
-Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
+Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc,
                             ExprArg DestExp) {
   // Convert operand to void*
   Expr* E = DestExp.takeAs<Expr>();
@@ -676,7 +676,7 @@ Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
   if (DiagnoseAssignmentResult(ConvTy, StarLoc, Context.VoidPtrTy, ETy,
                                E, "passing"))
     return StmtError();
-  return Owned(new (Context) IndirectGotoStmt(E));
+  return Owned(new (Context) IndirectGotoStmt(GotoLoc, E));
 }
 
 Action::OwningStmtResult