]> granicus.if.org Git - clang/commitdiff
Fix InitListExpr::getSourceRange() to work in the case of no locations for '(' and...
authorTed Kremenek <kremenek@apple.com>
Tue, 9 Nov 2010 02:11:40 +0000 (02:11 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 9 Nov 2010 02:11:40 +0000 (02:11 +0000)
in the case of transparent unions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118472 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp

index 3ba0667efc12933734a684716f02531869aa2107..d7e8fd8d9083bc44ac0f3deb7e9d518cdd2185ba 100644 (file)
@@ -2934,9 +2934,8 @@ public:
     HadArrayRangeDesignator = ARD;
   }
 
-  virtual SourceRange getSourceRange() const {
-    return SourceRange(LBraceLoc, RBraceLoc);
-  }
+  virtual SourceRange getSourceRange() const;
+
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == InitListExprClass;
   }
index 078bd7c8a1bc15e68cd273c6fc4b457c4ec0bb2f..7d05bdb26486395b9254440e09e81cb18b2e162a 100644 (file)
@@ -1028,6 +1028,35 @@ Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) {
   return Result;
 }
 
+SourceRange InitListExpr::getSourceRange() const {
+  if (SyntacticForm)
+    return SyntacticForm->getSourceRange();
+  SourceLocation Beg = LBraceLoc, End = RBraceLoc;
+  if (Beg.isInvalid()) {
+    // Find the first non-null initializer.
+    for (InitExprsTy::const_iterator I = InitExprs.begin(),
+                                     E = InitExprs.end(); 
+      I != E; ++I) {
+      if (Stmt *S = *I) {
+        Beg = S->getLocStart();
+        break;
+      }  
+    }
+  }
+  if (End.isInvalid()) {
+    // Find the first non-null initializer from the end.
+    for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(),
+                                             E = InitExprs.rend();
+      I != E; ++I) {
+      if (Stmt *S = *I) {
+        End = S->getSourceRange().getEnd();
+        break;
+      }  
+    }
+  }
+  return SourceRange(Beg, End);
+}
+
 /// getFunctionType - Return the underlying function type for this block.
 ///
 const FunctionType *BlockExpr::getFunctionType() const {