]> granicus.if.org Git - clang/commitdiff
add a sourcelocation to binary operator to keep track of the location of the operator.
authorChris Lattner <sabre@nondot.org>
Tue, 28 Aug 2007 18:36:55 +0000 (18:36 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 28 Aug 2007 18:36:55 +0000 (18:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41550 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaExpr.cpp
include/clang/AST/Expr.h

index 88a057930b32ccb09a7585a028ed9f468a8383b2..af0e6d4e8e2dd65f2554af1116ff62b8e3edf7dc 100644 (file)
@@ -1561,9 +1561,9 @@ Action::ExprResult Sema::ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
   if (ResultTy.isNull())
     return true;
   if (CompTy.isNull())
-    return new BinaryOperator(lhs, rhs, Opc, ResultTy);
+    return new BinaryOperator(lhs, rhs, Opc, ResultTy, TokLoc);
   else
-    return new CompoundAssignOperator(lhs, rhs, Opc, ResultTy, CompTy);
+    return new CompoundAssignOperator(lhs, rhs, Opc, ResultTy, CompTy, TokLoc);
 }
 
 // Unary Operators.  'Tok' is the token for the operator.
index 8a4f6affbbc74b8bf82c7f3e2eb2af970fc1783f..138db62cf95d3fc1fd7246be685cee734a753297 100644 (file)
@@ -722,15 +722,23 @@ public:
     OrAssign,
     Comma             // [C99 6.5.17] Comma operator.
   };
+private:
+  enum { LHS, RHS, END_EXPR };
+  Expr* SubExprs[END_EXPR];
+  Opcode Opc;
+  SourceLocation OpLoc;
+public:  
   
-  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy)
-    : Expr(BinaryOperatorClass, ResTy), Opc(opc) {
+  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
+                 SourceLocation opLoc)
+    : Expr(BinaryOperatorClass, ResTy), Opc(opc), OpLoc(opLoc) {
     SubExprs[LHS] = lhs;
     SubExprs[RHS] = rhs;
     assert(!isCompoundAssignmentOp() && 
            "Use ArithAssignBinaryOperator for compound assignments");
   }
 
+  SourceLocation getOperatorLoc() const { return OpLoc; }
   Opcode getOpcode() const { return Opc; }
   Expr *getLHS() const { return SubExprs[LHS]; }
   Expr *getRHS() const { return SubExprs[RHS]; }
@@ -764,14 +772,10 @@ public:
   virtual child_iterator child_begin();
   virtual child_iterator child_end();
 
-private:
-  enum { LHS, RHS, END_EXPR };
-  Expr* SubExprs[END_EXPR];
-  Opcode Opc;
-
 protected:
-  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, bool dead)
-    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc) {
+  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
+                 SourceLocation oploc, bool dead)
+    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
     SubExprs[LHS] = lhs;
     SubExprs[RHS] = rhs;
   }
@@ -787,8 +791,10 @@ class CompoundAssignOperator : public BinaryOperator {
   QualType ComputationType;
 public:
   CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
-                         QualType ResType, QualType CompType)
-    : BinaryOperator(lhs, rhs, opc, ResType, true), ComputationType(CompType) {
+                         QualType ResType, QualType CompType,
+                         SourceLocation OpLoc)
+    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
+      ComputationType(CompType) {
     assert(isCompoundAssignmentOp() && 
            "Only should be used for compound assignments");
   }