From 3d1abd4c01566adc2dc0ceaddbbb8f01c81411e3 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 3 Nov 2015 14:05:07 -0500
Subject: [PATCH 24/27] FIXME: get parens working

---
 gcc/cp/cp-tree.h |  5 +++++
 gcc/cp/parser.c  | 17 +++++++++++++----
 gcc/tree.c       |  9 +++++----
 gcc/tree.h       |  4 ++--
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ada0aba..b45092a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -99,6 +99,11 @@ public:
     return src_range.m_finish;
   }
 
+  void set_range (location_t start, location_t finish)
+  {
+    m_loc = set_source_range (m_value, start, finish);
+  }
+
  private:
   tree m_value;
   location_t m_loc;
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0af19aa..3c97cdd 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4678,6 +4678,10 @@ cp_parser_primary_expression (cp_parser *parser,
 	cp_expr expr (NULL);
 	bool saved_greater_than_is_operator_p;
 
+	location_t open_paren_loc = token->location;
+
+        //inform (open_paren_loc, "open_paren_loc");
+
 	/* Consume the `('.  */
 	cp_lexer_consume_token (parser->lexer);
 	/* Within a parenthesized expression, a `>' token is always
@@ -4722,7 +4726,12 @@ cp_parser_primary_expression (cp_parser *parser,
 	   template-parameter-list now.  */
 	parser->greater_than_is_operator_p
 	  = saved_greater_than_is_operator_p;
+
 	/* Consume the `)'.  */
+	token = cp_lexer_peek_token (parser->lexer);
+	location_t close_paren_loc = token->location;
+	expr.set_range (open_paren_loc, close_paren_loc);
+        //inform (token->location, "foo");
 	if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)
 	    && !cp_parser_uncommitted_to_tentative_parse_p (parser))
 	  cp_parser_skip_to_end_of_statement (parser);
@@ -8524,7 +8533,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
      get_rhs:
       current.tree_type = binops_by_token[token->type].tree_type;
       current.loc = token->location;
-      inform (current.loc, "current.loc");
+      //inform (current.loc, "current.loc");
 
       /* We used the operator token.  */
       cp_lexer_consume_token (parser->lexer);
@@ -8607,10 +8616,10 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
       overload = NULL;
 
       source_range src_range;
-      inform (current.lhs.get_location (), "current.lhs");
+      //inform (current.lhs.get_location (), "current.lhs");
       src_range.m_start = current.lhs.get_start ();
       src_range.m_finish = rhs.get_finish ();
-      inform (rhs.get_location (), "rhs");
+      //inform (rhs.get_location (), "rhs");
       location_t pure_loc = get_pure_location (current.loc);
       location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
                                                        pure_loc,
@@ -8643,7 +8652,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
                                          complain_flags (decltype_p));
       current.lhs_type = current.tree_type;
 
-      inform (current.lhs.get_location (), "current.lhs.get_location ()");
+      //inform (current.lhs.get_location (), "current.lhs.get_location ()");
 
       /* If the binary operator required the use of an overloaded operator,
 	 then this expression cannot be an integral constant-expression.
diff --git a/gcc/tree.c b/gcc/tree.c
index 3bce113..fd51385 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -13681,20 +13681,20 @@ set_block (location_t loc, tree block)
   return COMBINE_LOCATION_DATA (line_table, pure_loc, src_range, block);
 }
 
-void
+location_t
 set_source_range (tree expr, location_t start, location_t finish)
 {
   source_range src_range;
   src_range.m_start = start;
   src_range.m_finish = finish;
-  set_source_range (expr, src_range);
+  return set_source_range (expr, src_range);
 }
 
-void
+location_t
 set_source_range (tree expr, source_range src_range)
 {
   if (!EXPR_P (expr))
-    return;
+    return UNKNOWN_LOCATION;
 
   location_t pure_loc = get_pure_location (EXPR_LOCATION (expr));
   location_t adhoc = COMBINE_LOCATION_DATA (line_table,
@@ -13702,6 +13702,7 @@ set_source_range (tree expr, source_range src_range)
 					    src_range,
 					    NULL);
   SET_EXPR_LOCATION (expr, adhoc);
+  return adhoc;
 }
 
 #include "gt-tree.h"
diff --git a/gcc/tree.h b/gcc/tree.h
index 3e10ae9..4406baf 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -5169,10 +5169,10 @@ extern void gt_pch_nx (tree &, gt_pointer_operator, void *);
 
 extern bool nonnull_arg_p (const_tree);
 
-extern void
+extern location_t
 set_source_range (tree expr, location_t start, location_t finish);
 
-extern void
+extern location_t
 set_source_range (tree expr, source_range src_range);
 
 static inline source_range
-- 
1.8.5.3

