aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/cp-tree.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-12-04 18:09:54 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-12-04 18:09:54 +0000
commite87eed2a9cbc1fe429ad550337e819cddcdc9c5a (patch)
tree7f2a3f020f12a35212f7815a094bdc273c1afce8 /gcc/cp/cp-tree.h
parentb3d5bc621f9c7da0bbac965c610ae2a4044e1a68 (diff)
downloadgcc-e87eed2a9cbc1fe429ad550337e819cddcdc9c5a.zip
gcc-e87eed2a9cbc1fe429ad550337e819cddcdc9c5a.tar.gz
gcc-e87eed2a9cbc1fe429ad550337e819cddcdc9c5a.tar.bz2
C++ FE: expression ranges
gcc/ChangeLog: * convert.c (convert_to_real_1): When converting from a REAL_TYPE, preserve the location of EXPR in the result. * tree.c (get_pure_location): Make non-static. (set_source_range): Return the resulting location_t. (make_location): New function. * tree.h (get_pure_location): New decl. (get_finish): New inline function. (set_source_range): Convert return type from void to location_t. (make_location): New decl. gcc/cp/ChangeLog: * cp-tree.h (class cp_expr): New class. (finish_parenthesized_expr): Convert return type and param to cp_expr. (perform_koenig_lookup): Convert return type and param from tree to cp_expr. (finish_increment_expr): Likewise. (finish_unary_op_expr): Likewise. (finish_id_expression): Likewise for return type. (build_class_member_access_expr): Likewise for param. (finish_class_member_access_expr): Likewise. (build_x_unary_op): Likewise. (build_c_cast): New decl. (build_x_modify_expr): Convert return type from tree to cp_expr. * cvt.c (cp_convert_and_check): When warning about conversions, attempt to use the location of "expr" if available, otherwise falling back to the old behavior of using input_location. * name-lookup.c (lookup_arg_dependent_1): Convert return type from tree to cp_expr. (lookup_arg_dependent): Likewise; also for local "ret". * name-lookup.h (lookup_arg_dependent): Likewise for return type. * parser.c (cp_lexer_previous_token): Skip past purged tokens. (struct cp_parser_expression_stack_entry): Convert field "lhs" to cp_expr. (cp_parser_identifier): Likewise for return type. Use cp_expr ctor to preserve the token's location. (cp_parser_string_literal): Likewise, building up a meaningful location for the case where a compound string literal is built by concatentation. (cp_parser_userdef_char_literal): Likewise for return type. (cp_parser_userdef_numeric_literal): Likewise. (cp_parser_statement_expr): Convert return type to cp_expr. Generate a suitable location for the expr and return it via the cp_expr ctor. (cp_parser_fold_expression): Convert return type to cp_expr. (cp_parser_primary_expression): Likewise, and for locals "expr", "lam", "id_expression", "decl". Use cp_expr ctor when parsing literals, to preserve the spelling location of the token. Preserve the locations of parentheses. Preserve location when calling objc_lookup_ivar. Preserve the location for "this" tokens. Generate suitable locations for "__builtin_va_arg" constructs and for Objective C 2.0 dot-syntax. Set the location for the result of finish_id_expression. (cp_parser_primary_expression): Convert return type from tree to cp_expr. (cp_parser_id_expression): Likewise. (cp_parser_unqualified_id): Likewise. Also for local "id". (cp_parser_postfix_expression): Likewise, also for local "postfix_expression". Generate suitable locations for C++-style casts, "_Cilk_spawn" constructs. Convert local "initializer" to cp_expr and use it to preserve the location of compound literals. Capture the location of the closing parenthesis of a call site via cp_parser_parenthesized_expression_list, and use it to build a source range for a call. Use cp_expr in ternary expression. (cp_parser_postfix_dot_deref_expression): Convert param from tree to cp_expr. Generate and set a location. (cp_parser_parenthesized_expression_list): Add "close_paren_loc" out-param, and write back to it. (cp_parser_unary_expression): Convert return type from tree to cp_expr. Also for locals "cast_expression" and "expression". Generate and use suitable locations for addresses of labels and for cast expressions. Call cp_expr::set_location where necessary. Preserve the locations of negated numeric literals. (cp_parser_new_expression): Generate meaningful locations/ranges. (cp_parser_cast_expression): Convert return type from tree to cp_expr; also for local "expr". Use the paren location to generate a meaningful range for the expression. (cp_parser_binary_expression): Convert return type from tree to cp_expr; also for local "rhs". Generate a meaningful location for the expression, and use it. Replace call to protected_set_expr_location by converting a build2 to a build2_loc and using the location in the call to build_x_binary_op, adding a cp_expr::set_location to the latter case. (cp_parser_question_colon_clause): Convert param from tree to cp_expr; also for local "assignment_expr". Set the spelling range of the expression. (cp_parser_assignment_expression): Likewise for return type and locals "expr" and "rhs". Build a meaningful spelling range for the expression. Remove saving of input_location in favor of a call to cp_expr::set_location. (cp_parser_expression): Convert return type and locals "expression" and "assignment_expression" to cp_expr. Build a meaningful spelling range for assignment expressions. (cp_parser_constant_expression): Likewise for return type and local "expression". (cp_parser_builtin_offsetof): Convert return type and local "expr" to cp_expr. Generate suitable locations. (cp_parser_lambda_expression): Convert return return type to cp_expr. (cp_parser_operator_function_id): Likewise. (cp_parser_operator): Likewise. Generate a meaningful range, using cp_expr's ctor to return it. (cp_parser_template_id): When converting a token to CPP_TEMPLATE_ID, update the location. (cp_parser_initializer_clause): Convert return type and local "initializer" to cp_expr. (cp_parser_braced_list): Likewise for return type. Generate suitable locations. (cp_parser_lookup_name): Likewise for return type. Use cp_expr's ctor to preserve the location_t of the name. (cp_parser_simple_cast_expression): Likewise for return type. (cp_parser_functional_cast): Convert return type and local "cast" to cp_expr. Generate suitable locations. (cp_parser_objc_expression): Convert return type to cp_expr.k Generate (cp_parser_objc_message_expression): Generate suitable locations. (cp_parser_objc_encode_expression): Convert return type to cp_expr. Generate suitable locations. (cp_parser_objc_protocol_expression): Generate suitable locations. (cp_parser_objc_selector_expression): Generate suitable locations. (cp_parser_omp_for_cond): Attempt to use the location of "cond" for the binary op. (cp_parser_transaction_expression): Issue the tm-not-enabled error at the location of the __transaction_foo token, rather than at input_location. * semantics.c (finish_parenthesized_expr): Convert return type and param to cp_expr. Preserve location. (perform_koenig_lookup): Likewise for return type and param. (finish_increment_expr): Likewise. Generate suitable locations. (finish_unary_op_expr): Likewise for return type and local "result". Generate suitable locations. (finish_id_expression): Convert return type to cp_expr and use cp_expr ctor to preserve location information. * typeck.c (build_class_member_access_expr): Convert param to cp_expr. (finish_class_member_access_expr): Likewise. (cp_build_binary_op): Convert a build2 to a build2_loc. (build_x_unary_op): Convert param from tree to cp_expr. (build_nop): Preserve the location of EXPR. (build_c_cast): Provide an overloaded variant that takes a cp_expr and returns a cp_expr. (build_x_modify_expr): Convert return type from tree to cp_expr. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-template14.C: Move dg-error directive. * g++.dg/gomp/loop-1.C: Update dg-error locations. * g++.dg/plugin/diagnostic-test-expressions-1.C: New file, adapted from gcc.dg/plugin/diagnostic-test-expressions-1.c. * g++.dg/plugin/plugin.exp (plugin_test_list): Add the above. * g++.dg/template/crash55.C: Update dg-error directives. * g++.dg/template/pseudodtor3.C: Update column numbers in dg-error directives. * g++.dg/template/pr64100.C: Update location of dg-error directive. * g++.dg/template/ref3.C: Add XFAIL (PR c++/68699). * g++.dg/ubsan/pr63956.C: Update dg directives to reflect improved location information. * g++.dg/warn/pr35635.C (func3): Update location of a dg-warning. * g++.dg/warn/Wconversion-real-integer2.C: Update location of dg-warning; add a dg-message. * obj-c++.dg/plugin/diagnostic-test-expressions-1.mm: New file, based on objc.dg/plugin/diagnostic-test-expressions-1.m. * obj-c++.dg/plugin/plugin.exp: New file, based on objc.dg/plugin/plugin.exp. From-SVN: r231293
Diffstat (limited to 'gcc/cp/cp-tree.h')
-rw-r--r--gcc/cp/cp-tree.h82
1 files changed, 73 insertions, 9 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 38ae70f..6ddab8a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -40,6 +40,68 @@ c-common.h, not after.
#include "c-family/c-common.h"
#include "diagnostic.h"
+/* A tree node, together with a location, so that we can track locations
+ (and ranges) during parsing.
+
+ The location is redundant for node kinds that have locations,
+ but not all node kinds do (e.g. constants, and references to
+ params, locals, etc), so we stash a copy here. */
+
+class cp_expr
+{
+public:
+ cp_expr () :
+ m_value (NULL), m_loc (UNKNOWN_LOCATION) {}
+
+ cp_expr (tree value) :
+ m_value (value), m_loc (EXPR_LOCATION (m_value)) {}
+
+ cp_expr (tree value, location_t loc):
+ m_value (value), m_loc (loc) {}
+
+ cp_expr (const cp_expr &other) :
+ m_value (other.m_value), m_loc (other.m_loc) {}
+
+ /* Implicit conversions to tree. */
+ operator tree () const { return m_value; }
+ tree & operator* () { return m_value; }
+ tree & operator-> () { return m_value; }
+
+ tree get_value () const { return m_value; }
+ location_t get_location () const { return m_loc; }
+ location_t get_start () const
+ {
+ source_range src_range = get_range_from_loc (line_table, m_loc);
+ return src_range.m_start;
+ }
+ location_t get_finish () const
+ {
+ source_range src_range = get_range_from_loc (line_table, m_loc);
+ return src_range.m_finish;
+ }
+
+ void set_location (location_t loc)
+ {
+ protected_set_expr_location (m_value, loc);
+ m_loc = loc;
+ }
+
+ void set_range (location_t start, location_t finish)
+ {
+ set_location (make_location (m_loc, start, finish));
+ }
+
+ private:
+ tree m_value;
+ location_t m_loc;
+};
+
+inline bool
+operator == (const cp_expr &lhs, tree rhs)
+{
+ return lhs.get_value () == rhs;
+}
+
#include "name-lookup.h"
/* Usage of TREE_LANG_FLAG_?:
@@ -6291,7 +6353,7 @@ extern tree finish_asm_stmt (int, tree, tree, tree, tree,
tree);
extern tree finish_label_stmt (tree);
extern void finish_label_decl (tree);
-extern tree finish_parenthesized_expr (tree);
+extern cp_expr finish_parenthesized_expr (cp_expr);
extern tree force_paren_expr (tree);
extern tree finish_non_static_data_member (tree, tree, tree);
extern tree begin_stmt_expr (void);
@@ -6299,15 +6361,15 @@ extern tree finish_stmt_expr_expr (tree, tree);
extern tree finish_stmt_expr (tree, bool);
extern tree stmt_expr_value_expr (tree);
bool empty_expr_stmt_p (tree);
-extern tree perform_koenig_lookup (tree, vec<tree, va_gc> *,
+extern cp_expr perform_koenig_lookup (cp_expr, vec<tree, va_gc> *,
tsubst_flags_t);
extern tree finish_call_expr (tree, vec<tree, va_gc> **, bool,
bool, tsubst_flags_t);
extern tree finish_template_variable (tree, tsubst_flags_t = tf_warning_or_error);
-extern tree finish_increment_expr (tree, enum tree_code);
+extern cp_expr finish_increment_expr (cp_expr, enum tree_code);
extern tree finish_this_expr (void);
extern tree finish_pseudo_destructor_expr (tree, tree, tree, location_t);
-extern tree finish_unary_op_expr (location_t, enum tree_code, tree,
+extern cp_expr finish_unary_op_expr (location_t, enum tree_code, cp_expr,
tsubst_flags_t);
extern tree finish_compound_literal (tree, tree, tsubst_flags_t);
extern tree finish_fname (tree);
@@ -6321,7 +6383,7 @@ extern tree finish_base_specifier (tree, tree, bool);
extern void finish_member_declaration (tree);
extern bool outer_automatic_var_p (tree);
extern tree process_outer_var_ref (tree, tsubst_flags_t);
-extern tree finish_id_expression (tree, tree, tree,
+extern cp_expr finish_id_expression (tree, tree, tree,
cp_id_kind *,
bool, bool, bool *,
bool, bool, bool, bool,
@@ -6564,9 +6626,9 @@ extern tree unlowered_expr_type (const_tree);
extern tree decay_conversion (tree,
tsubst_flags_t,
bool = true);
-extern tree build_class_member_access_expr (tree, tree, tree, bool,
+extern tree build_class_member_access_expr (cp_expr, tree, tree, bool,
tsubst_flags_t);
-extern tree finish_class_member_access_expr (tree, tree, bool,
+extern tree finish_class_member_access_expr (cp_expr, tree, bool,
tsubst_flags_t);
extern tree build_x_indirect_ref (location_t, tree,
ref_operator, tsubst_flags_t);
@@ -6588,7 +6650,7 @@ extern tree build_x_binary_op (location_t,
extern tree build_x_array_ref (location_t, tree, tree,
tsubst_flags_t);
extern tree build_x_unary_op (location_t,
- enum tree_code, tree,
+ enum tree_code, cp_expr,
tsubst_flags_t);
extern tree cp_build_addr_expr (tree, tsubst_flags_t);
extern tree cp_build_unary_op (enum tree_code, tree, int,
@@ -6608,8 +6670,10 @@ extern tree build_static_cast (tree, tree, tsubst_flags_t);
extern tree build_reinterpret_cast (tree, tree, tsubst_flags_t);
extern tree build_const_cast (tree, tree, tsubst_flags_t);
extern tree build_c_cast (location_t, tree, tree);
+extern cp_expr build_c_cast (location_t loc, tree type,
+ cp_expr expr);
extern tree cp_build_c_cast (tree, tree, tsubst_flags_t);
-extern tree build_x_modify_expr (location_t, tree,
+extern cp_expr build_x_modify_expr (location_t, tree,
enum tree_code, tree,
tsubst_flags_t);
extern tree cp_build_modify_expr (tree, enum tree_code, tree,