1992-01-28 22:42:48 -05:00
|
|
|
|
/* Language-level data type conversion for GNU C.
|
1999-01-06 15:44:41 -05:00
|
|
|
|
Copyright (C) 1987, 1988, 1991, 1998 Free Software Foundation, Inc.
|
1992-01-28 22:42:48 -05:00
|
|
|
|
|
|
|
|
|
This file is part of GNU CC.
|
|
|
|
|
|
|
|
|
|
GNU CC is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
GNU CC is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with GNU CC; see the file COPYING. If not, write to
|
1995-06-15 07:33:25 -04:00
|
|
|
|
the Free Software Foundation, 59 Temple Place - Suite 330,
|
|
|
|
|
Boston, MA 02111-1307, USA. */
|
1992-01-28 22:42:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* This file contains the functions for converting C expressions
|
|
|
|
|
to different data types. The only entry point is `convert'.
|
|
|
|
|
Every language front end must have a `convert' function
|
|
|
|
|
but what kind of conversions it does will depend on the language. */
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
1999-09-07 01:49:18 -04:00
|
|
|
|
#include "system.h"
|
1992-01-28 22:42:48 -05:00
|
|
|
|
#include "tree.h"
|
|
|
|
|
#include "flags.h"
|
1993-01-08 21:03:56 -05:00
|
|
|
|
#include "convert.h"
|
toplev.h: New file.
Wed May 6 06:35:38 1998 Robert Lipe <robertl@dgii.com>
* toplev.h: New file. Protypes for functions in toplev.c.
* tree.h, rtl.h: Deleted protos for functions in toplev.c.
* c-common.c, c-convert.c, c-decl.c, c-iterate.c, c-lex.c,
c-parse.in, c-parse.y, c-pragma.c, c-typeck.c, calls.c,
convert.c, dwarf2out.c, except.c, expr.c, final.c, fold-const.c,
function.c, hash.c, profile.c, real.c, reg-stack.c, regclass.c,
reload.c, reload1.c, stmt.c, stor-layout.c, tlink.c, tree.c,
varasm.c: include it.
From-SVN: r19563
1998-05-06 00:45:47 -04:00
|
|
|
|
#include "toplev.h"
|
1992-01-28 22:42:48 -05:00
|
|
|
|
|
|
|
|
|
/* Change of width--truncation and extension of integers or reals--
|
|
|
|
|
is represented with NOP_EXPR. Proper functioning of many things
|
|
|
|
|
assumes that no other conversions can be NOP_EXPRs.
|
|
|
|
|
|
|
|
|
|
Conversion between integer and pointer is represented with CONVERT_EXPR.
|
|
|
|
|
Converting integer to real uses FLOAT_EXPR
|
|
|
|
|
and real to integer uses FIX_TRUNC_EXPR.
|
|
|
|
|
|
|
|
|
|
Here is a list of all the functions that assume that widening and
|
|
|
|
|
narrowing is always done with a NOP_EXPR:
|
1993-01-08 21:03:56 -05:00
|
|
|
|
In convert.c, convert_to_integer.
|
1992-01-28 22:42:48 -05:00
|
|
|
|
In c-typeck.c, build_binary_op (boolean ops), and truthvalue_conversion.
|
|
|
|
|
In expr.c: expand_expr, for operands of a MULT_EXPR.
|
|
|
|
|
In fold-const.c: fold.
|
|
|
|
|
In tree.c: get_narrower and get_unwidened. */
|
|
|
|
|
|
|
|
|
|
/* Subroutines of `convert'. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create an expression whose value is that of EXPR,
|
|
|
|
|
converted to type TYPE. The TREE_TYPE of the value
|
|
|
|
|
is always TYPE. This function implements all reasonable
|
|
|
|
|
conversions; callers should filter out those that are
|
|
|
|
|
not permitted by the language being compiled. */
|
|
|
|
|
|
|
|
|
|
tree
|
|
|
|
|
convert (type, expr)
|
|
|
|
|
tree type, expr;
|
|
|
|
|
{
|
|
|
|
|
register tree e = expr;
|
|
|
|
|
register enum tree_code code = TREE_CODE (type);
|
|
|
|
|
|
1992-07-31 02:13:07 -04:00
|
|
|
|
if (type == TREE_TYPE (expr)
|
c-convert.c (convert): Return if output or input type is ERROR_MARK.
* c-convert.c (convert): Return if output or input type is ERROR_MARK.
* c-decl.c (duplicate_decls): Only look at DECL_BUILT_IN_NONANSI
and DECL_INLINE if FUNCTION_DECL.
(pushdecl, redeclaration_error_message): Likewise, for DECL_INLINE.
(store_parm_decls): Check for type of PARM_DECL being ERROR_MARK.
Use DECL_WEAK, not DECL_RESULT, to flag for already seen.
(combine_parm_decls): Likewise.
* ggc-common.c (gcc_mark_tree_children, case 'd'): Use DECL_RESULT_FLD.
* print-tree.c (print_node): Likewise.
Only test DECL_PACKED, DECL_INLINE, DECL_BIT_FIELD, and
DECL_TRANSPARENT_UNION on proper decl types.
Properly handly DECL_INCOMING_RTL and DECL_SAVED_INSNS.
* stor-layout.c (layout_decl): Only check DECL_PACKED and
DECL_BIT_FIELD of FIELD_DECL.
* tree.h (DECL_RESULT_FLD): New macro.
* cp/class.c (check_field_decl): Fix typo.
(build_vtbl_or_vbase_field): Don't clear DECL_SAVED_INSNS.
(check_methods): Likewise.
(check_field_decls): Likewise.
Use DECL_CONTEXT, not DECL_FIELD_CONTEXT.
* cp-tree.h (DECL_SHADOWED_FOR_VAR, DECL_TEMPLATE_RESULT):
Use DECL_RESULT_FLD, not DECL_RESULT.
* cp/decl.c (xref_tag): Use DECL_TEMPLATE_RESULT.
* cp/lex.c (identifier_type): Likewise.
* cp/pt.c (determine_specialization, lookup_template_class): Likewise.
(tsubst_friend_function, tsubst_decl, instantiate_template): Likewise.
(resolve_overloaded_unification, more_specialized): Likewise.
* cp/semantics.c (finish_member_declaration): Likewise.
* cp/typeck.c (build_x_function_call): Likewise.
From-SVN: r32759
2000-03-26 20:26:18 -05:00
|
|
|
|
|| TREE_CODE (expr) == ERROR_MARK
|
|
|
|
|
|| code == ERROR_MARK || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
|
1992-01-28 22:42:48 -05:00
|
|
|
|
return expr;
|
c-convert.c (convert): Return if output or input type is ERROR_MARK.
* c-convert.c (convert): Return if output or input type is ERROR_MARK.
* c-decl.c (duplicate_decls): Only look at DECL_BUILT_IN_NONANSI
and DECL_INLINE if FUNCTION_DECL.
(pushdecl, redeclaration_error_message): Likewise, for DECL_INLINE.
(store_parm_decls): Check for type of PARM_DECL being ERROR_MARK.
Use DECL_WEAK, not DECL_RESULT, to flag for already seen.
(combine_parm_decls): Likewise.
* ggc-common.c (gcc_mark_tree_children, case 'd'): Use DECL_RESULT_FLD.
* print-tree.c (print_node): Likewise.
Only test DECL_PACKED, DECL_INLINE, DECL_BIT_FIELD, and
DECL_TRANSPARENT_UNION on proper decl types.
Properly handly DECL_INCOMING_RTL and DECL_SAVED_INSNS.
* stor-layout.c (layout_decl): Only check DECL_PACKED and
DECL_BIT_FIELD of FIELD_DECL.
* tree.h (DECL_RESULT_FLD): New macro.
* cp/class.c (check_field_decl): Fix typo.
(build_vtbl_or_vbase_field): Don't clear DECL_SAVED_INSNS.
(check_methods): Likewise.
(check_field_decls): Likewise.
Use DECL_CONTEXT, not DECL_FIELD_CONTEXT.
* cp-tree.h (DECL_SHADOWED_FOR_VAR, DECL_TEMPLATE_RESULT):
Use DECL_RESULT_FLD, not DECL_RESULT.
* cp/decl.c (xref_tag): Use DECL_TEMPLATE_RESULT.
* cp/lex.c (identifier_type): Likewise.
* cp/pt.c (determine_specialization, lookup_template_class): Likewise.
(tsubst_friend_function, tsubst_decl, instantiate_template): Likewise.
(resolve_overloaded_unification, more_specialized): Likewise.
* cp/semantics.c (finish_member_declaration): Likewise.
* cp/typeck.c (build_x_function_call): Likewise.
From-SVN: r32759
2000-03-26 20:26:18 -05:00
|
|
|
|
|
1992-07-31 02:13:07 -04:00
|
|
|
|
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
|
1992-08-14 04:36:14 -04:00
|
|
|
|
return fold (build1 (NOP_EXPR, type, expr));
|
1992-01-28 22:42:48 -05:00
|
|
|
|
if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
|
|
|
|
|
return error_mark_node;
|
|
|
|
|
if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE)
|
|
|
|
|
{
|
|
|
|
|
error ("void value not ignored as it ought to be");
|
|
|
|
|
return error_mark_node;
|
|
|
|
|
}
|
|
|
|
|
if (code == VOID_TYPE)
|
|
|
|
|
return build1 (CONVERT_EXPR, type, e);
|
|
|
|
|
#if 0
|
|
|
|
|
/* This is incorrect. A truncation can't be stripped this way.
|
|
|
|
|
Extensions will be stripped by the use of get_unwidened. */
|
|
|
|
|
if (TREE_CODE (expr) == NOP_EXPR)
|
|
|
|
|
return convert (type, TREE_OPERAND (expr, 0));
|
|
|
|
|
#endif
|
|
|
|
|
if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
|
|
|
|
|
return fold (convert_to_integer (type, e));
|
2000-11-13 09:14:44 -05:00
|
|
|
|
if (code == BOOLEAN_TYPE)
|
|
|
|
|
return fold (build1 (NOP_EXPR, type, truthvalue_conversion (expr)));
|
2000-04-10 07:59:46 -04:00
|
|
|
|
if (code == POINTER_TYPE || code == REFERENCE_TYPE)
|
1992-01-28 22:42:48 -05:00
|
|
|
|
return fold (convert_to_pointer (type, e));
|
|
|
|
|
if (code == REAL_TYPE)
|
|
|
|
|
return fold (convert_to_real (type, e));
|
1993-03-04 14:42:13 -05:00
|
|
|
|
if (code == COMPLEX_TYPE)
|
|
|
|
|
return fold (convert_to_complex (type, e));
|
2000-06-24 15:26:42 -04:00
|
|
|
|
if (code == VECTOR_TYPE)
|
|
|
|
|
return fold (convert_to_vector (type, e));
|
1992-01-28 22:42:48 -05:00
|
|
|
|
|
|
|
|
|
error ("conversion to non-scalar type requested");
|
|
|
|
|
return error_mark_node;
|
|
|
|
|
}
|