[cfe-commits] r152412 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/Expr.h lib/AST/Expr.cpp

Daniel Dunbar daniel at zuster.org
Fri Mar 9 07:39:24 PST 2012


Author: ddunbar
Date: Fri Mar  9 09:39:24 2012
New Revision: 152412

URL: http://llvm.org/viewvc/llvm-project?rev=152412&view=rev
Log:
[AST] Define a few more key getLocStart() implementations.
 - This cuts the # of getSourceRange calls by 60% on
   OGF/NSBezierPath-OAExtensions.m.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=152412&r1=152411&r2=152412&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 09:39:24 2012
@@ -633,6 +633,9 @@
   SourceLocation getOuterLocStart() const;
 
   virtual SourceRange getSourceRange() const;
+  SourceLocation getLocStart() const {
+    return getOuterLocStart();
+  }
 
   /// \brief Retrieve the nested-name-specifier that qualifies the name of this
   /// declaration, if it was present in the source.

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=152412&r1=152411&r2=152412&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Mar  9 09:39:24 2012
@@ -2127,6 +2127,8 @@
   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
   SourceRange getSourceRange() const;
+  SourceLocation getLocStart() const;
+  SourceLocation getLocEnd() const;
 
   static bool classof(const Stmt *T) {
     return T->getStmtClass() >= firstCallExprConstant &&

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=152412&r1=152411&r2=152412&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Mar  9 09:39:24 2012
@@ -905,6 +905,24 @@
     end = getArg(getNumArgs() - 1)->getLocEnd();
   return SourceRange(begin, end);
 }
+SourceLocation CallExpr::getLocStart() const {
+  if (isa<CXXOperatorCallExpr>(this))
+    return cast<CXXOperatorCallExpr>(this)->getSourceRange().getBegin();
+
+  SourceLocation begin = getCallee()->getLocStart();
+  if (begin.isInvalid() && getNumArgs() > 0)
+    begin = getArg(0)->getLocStart();
+  return begin;
+}
+SourceLocation CallExpr::getLocEnd() const {
+  if (isa<CXXOperatorCallExpr>(this))
+    return cast<CXXOperatorCallExpr>(this)->getSourceRange().getEnd();
+
+  SourceLocation end = getRParenLoc();
+  if (end.isInvalid() && getNumArgs() > 0)
+    end = getArg(getNumArgs() - 1)->getLocEnd();
+  return end;
+}
 
 OffsetOfExpr *OffsetOfExpr::Create(ASTContext &C, QualType type, 
                                    SourceLocation OperatorLoc,





More information about the cfe-commits mailing list