From ebda493de4bb09f1da2f2f71c3292290d5872756 Mon Sep 17 00:00:00 2001 From: borutr Date: Tue, 9 Jan 2007 06:55:32 +0000 Subject: [PATCH] * get rid of diagnistic.[ch], pretty-print.[ch], c-pretty-print.[ch], ... used just for error, warning, ... message formatting * suppoprt/cpp2/pretty-print.[ch], suppoprt/cpp2/diagnostic.[ch], suppoprt/cpp2/diagnostic.def, suppoprt/cpp2/input.h, suppoprt/cpp2/pretty-print.[ch]: removed * suppoprt/cpp2/Makefile.in, suppoprt/cpp2/opts.c, suppoprt/cpp2/sdcpp-opts.c, suppoprt/cpp2/sdcpp.[ch], suppoprt/cpp2/sdcpp.dsp: changed git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4567 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 14 + support/cpp2/Makefile.in | 6 +- support/cpp2/c-pretty-print.c | 2057 --------------------------------- support/cpp2/c-pretty-print.h | 207 ---- support/cpp2/diagnostic.c | 606 ---------- support/cpp2/diagnostic.def | 9 - support/cpp2/diagnostic.h | 207 ---- support/cpp2/input.h | 101 -- support/cpp2/opts.c | 5 +- support/cpp2/pretty-print.c | 815 ------------- support/cpp2/pretty-print.h | 337 ------ support/cpp2/sdcpp-opts.c | 4 - support/cpp2/sdcpp.c | 226 ++-- support/cpp2/sdcpp.dsp | 20 - support/cpp2/sdcpp.h | 56 +- 15 files changed, 150 insertions(+), 4520 deletions(-) delete mode 100644 support/cpp2/c-pretty-print.c delete mode 100644 support/cpp2/c-pretty-print.h delete mode 100644 support/cpp2/diagnostic.c delete mode 100644 support/cpp2/diagnostic.def delete mode 100644 support/cpp2/diagnostic.h delete mode 100644 support/cpp2/input.h delete mode 100644 support/cpp2/pretty-print.c delete mode 100644 support/cpp2/pretty-print.h diff --git a/ChangeLog b/ChangeLog index 7c5536f1..a4d56166 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-01-09 Borut Razem + + * get rid of diagnistic.[ch], pretty-print.[ch], + c-pretty-print.[ch], ... used just for error, warning, ... + message formatting + * suppoprt/cpp2/pretty-print.[ch], suppoprt/cpp2/diagnostic.[ch], + suppoprt/cpp2/diagnostic.def, suppoprt/cpp2/input.h, + suppoprt/cpp2/pretty-print.[ch]: + removed + * suppoprt/cpp2/Makefile.in, suppoprt/cpp2/opts.c, + suppoprt/cpp2/sdcpp-opts.c, suppoprt/cpp2/sdcpp.[ch], + suppoprt/cpp2/sdcpp.dsp: + changed + 2007-01-08 Maarten Brock * device/lib/printf_large.c (output_float): removed recursion, diff --git a/support/cpp2/Makefile.in b/support/cpp2/Makefile.in index 43ccacc6..2c72bfd8 100644 --- a/support/cpp2/Makefile.in +++ b/support/cpp2/Makefile.in @@ -332,7 +332,7 @@ xstrerror.o: $(LIBIBERTY_DIR)/xstrerror.c $(CONFIG_H) $(LIBCPP_DEPS) ########################## # Sdcpp -SDCC_OBJS = sdcpp.o sdcpp-opts.o c-ppoutput.o cppdefault.o prefix.o version.o opts.o options.o diagnostic.o pretty-print.o c-incpath.o +SDCC_OBJS = sdcpp.o sdcpp-opts.o c-ppoutput.o cppdefault.o prefix.o version.o opts.o options.o c-incpath.o $(TARGET): $(SDCC_OBJS) $(MY_LIBIBERTY_BITS) libcpp.a $(LIBDEPS) mkdir -p $(dir $@) @@ -349,10 +349,6 @@ options.o: options.c $(CONFIG_H) $(LIBCPP_DEPS) options.h opts.o: opts.c $(CONFIG_H) $(LIBCPP_DEPS) options.h -diagnostic.o: diagnostic.c $(CONFIG_H) $(LIBCPP_DEPS) diagnostic.h options.h - -pretty-print.o: pretty-print.c $(CONFIG_H) $(LIBCPP_DEPS) pretty-print.h - c-incpath.o: $(CONFIG_H) $(LIBCPP_DEPS) c-incpath.h version.o: version.c version.h diff --git a/support/cpp2/c-pretty-print.c b/support/cpp2/c-pretty-print.c deleted file mode 100644 index 45f62ad4..00000000 --- a/support/cpp2/c-pretty-print.c +++ /dev/null @@ -1,2057 +0,0 @@ -/* Subroutines common to both C and C++ pretty-printers. - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - Contributed by Gabriel Dos Reis - -This file is part of GCC. - -GCC 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. - -GCC 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ - -#include "config.h" -#include "system.h" -#include "real.h" -#include "c-pretty-print.h" - -/* The pretty-printer code is primarily designed to closely follow - (GNU) C and C++ grammars. That is to be contrasted with spaghetti - codes we used to have in the past. Following a structured - approach (preferably the official grammars) is believed to make it - much easier to add extensions and nifty pretty-printing effects that - takes expression or declaration contexts into account. */ - - -#define pp_c_maybe_whitespace(PP) \ - do { \ - if (pp_base (PP)->padding == pp_before) \ - pp_c_whitespace (PP); \ - } while (0) - -/* literal */ -static void pp_c_char (c_pretty_printer *, int); - -/* postfix-expression */ -static void pp_c_initializer_list (c_pretty_printer *, tree); -static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree); - -static void pp_c_multiplicative_expression (c_pretty_printer *, tree); -static void pp_c_additive_expression (c_pretty_printer *, tree); -static void pp_c_shift_expression (c_pretty_printer *, tree); -static void pp_c_relational_expression (c_pretty_printer *, tree); -static void pp_c_equality_expression (c_pretty_printer *, tree); -static void pp_c_and_expression (c_pretty_printer *, tree); -static void pp_c_exclusive_or_expression (c_pretty_printer *, tree); -static void pp_c_inclusive_or_expression (c_pretty_printer *, tree); -static void pp_c_logical_and_expression (c_pretty_printer *, tree); -static void pp_c_conditional_expression (c_pretty_printer *, tree); -static void pp_c_assignment_expression (c_pretty_printer *, tree); - -/* declarations. */ - - -/* Helper functions. */ - -void -pp_c_whitespace (c_pretty_printer *pp) -{ - pp_space (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_left_paren (c_pretty_printer *pp) -{ - pp_left_paren (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_right_paren (c_pretty_printer *pp) -{ - pp_right_paren (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_left_brace (c_pretty_printer *pp) -{ - pp_left_brace (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_right_brace (c_pretty_printer *pp) -{ - pp_right_brace (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_left_bracket (c_pretty_printer *pp) -{ - pp_left_bracket (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_right_bracket (c_pretty_printer *pp) -{ - pp_right_bracket (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_dot (c_pretty_printer *pp) -{ - pp_dot (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_ampersand (c_pretty_printer *pp) -{ - pp_ampersand (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_star (c_pretty_printer *pp) -{ - pp_star (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_arrow (c_pretty_printer *pp) -{ - pp_arrow (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_semicolon (c_pretty_printer *pp) -{ - pp_semicolon (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_complement (c_pretty_printer *pp) -{ - pp_complement (pp); - pp_base (pp)->padding = pp_none; -} - -void -pp_c_exclamation (c_pretty_printer *pp) -{ - pp_exclamation (pp); - pp_base (pp)->padding = pp_none; -} - -/* Print out the external representation of CV-QUALIFIER. */ - -static void -pp_c_cv_qualifier (c_pretty_printer *pp, const char *cv) -{ - const char *p = pp_last_position_in_text (pp); - /* The C programming language does not have references, but it is much - simpler to handle those here rather than going through the same - logic in the C++ pretty-printer. */ - if (p != NULL && (*p == '*' || *p == '&')) - pp_c_whitespace (pp); - pp_c_identifier (pp, cv); -} - -/* Pretty-print T using the type-cast notation '( type-name )'. */ - -static void -pp_c_type_cast (c_pretty_printer *pp, tree t) -{ - pp_c_left_paren (pp); - pp_type_id (pp, t); - pp_c_right_paren (pp); -} - -/* We're about to pretty-print a pointer type as indicated by T. - Output a whitespace, if needed, preparing for subsequent output. */ - -void -pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t) -{ - if (POINTER_TYPE_P (t)) - { - tree pointee = strip_pointer_operator (TREE_TYPE (t)); - if (TREE_CODE (pointee) != ARRAY_TYPE - && TREE_CODE (pointee) != FUNCTION_TYPE) - pp_c_whitespace (pp); - } -} - - -/* Declarations. */ - -/* C++ cv-qualifiers are called type-qualifiers in C. Print out the - cv-qualifiers of T. If T is a declaration then it is the cv-qualifier - of its type. Take care of possible extensions. - - type-qualifier-list: - type-qualifier - type-qualifier-list type-qualifier - - type-qualifier: - const - restrict -- C99 - __restrict__ -- GNU C - volatile */ - -void -pp_c_type_qualifier_list (c_pretty_printer *pp, tree t) -{ - int qualifiers; - - if (!TYPE_P (t)) - t = TREE_TYPE (t); - - qualifiers = TYPE_QUALS (t); - if (qualifiers & TYPE_QUAL_CONST) - pp_c_cv_qualifier (pp, "const"); - if (qualifiers & TYPE_QUAL_VOLATILE) - pp_c_cv_qualifier (pp, "volatile"); - if (qualifiers & TYPE_QUAL_RESTRICT) - pp_c_cv_qualifier (pp, flag_isoc99 ? "restrict" : "__restrict__"); -} - -/* pointer: - * type-qualifier-list(opt) - * type-qualifier-list(opt) pointer */ - -static void -pp_c_pointer (c_pretty_printer *pp, tree t) -{ - if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL) - t = TREE_TYPE (t); - switch (TREE_CODE (t)) - { - case POINTER_TYPE: - /* It is easier to handle C++ reference types here. */ - case REFERENCE_TYPE: - if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) - pp_c_pointer (pp, TREE_TYPE (t)); - if (TREE_CODE (t) == POINTER_TYPE) - pp_c_star (pp); - else - pp_c_ampersand (pp); - pp_c_type_qualifier_list (pp, t); - break; - - /* ??? This node is now in GENERIC and so shouldn't be here. But - we'll fix that later. */ - case DECL_EXPR: - pp_declaration (pp, DECL_EXPR_DECL (t)); - pp_needs_newline (pp) = true; - break; - - default: - pp_unsupported_tree (pp, t); - } -} - -/* type-specifier: - void - char - short - int - long - float - double - signed - unsigned - _Bool -- C99 - _Complex -- C99 - _Imaginary -- C99 - struct-or-union-specifier - enum-specifier - typedef-name. - - GNU extensions. - simple-type-specifier: - __complex__ - __vector__ */ - -void -pp_c_type_specifier (c_pretty_printer *pp, tree t) -{ - const enum tree_code code = TREE_CODE (t); - switch (code) - { - case ERROR_MARK: - pp_c_identifier (pp, ""); - break; - - case IDENTIFIER_NODE: - pp_c_tree_decl_identifier (pp, t); - break; - - case VOID_TYPE: - case BOOLEAN_TYPE: - case CHAR_TYPE: - case INTEGER_TYPE: - case REAL_TYPE: - if (TYPE_NAME (t)) - { - t = TYPE_NAME (t); - pp_c_type_specifier (pp, t); - } - else - { - int prec = TYPE_PRECISION (t); - t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t)); - if (TYPE_NAME (t)) - { - pp_c_type_specifier (pp, t); - if (TYPE_PRECISION (t) != prec) - { - pp_string (pp, ":"); - pp_decimal_int (pp, prec); - } - } - else - { - switch (code) - { - case INTEGER_TYPE: - pp_string (pp, (TYPE_UNSIGNED (t) - ? ""); - } - } - break; - - case TYPE_DECL: - if (DECL_NAME (t)) - pp_id_expression (pp, t); - else - pp_c_identifier (pp, ""); - break; - - case UNION_TYPE: - case RECORD_TYPE: - case ENUMERAL_TYPE: - if (code == UNION_TYPE) - pp_c_identifier (pp, "union"); - else if (code == RECORD_TYPE) - pp_c_identifier (pp, "struct"); - else if (code == ENUMERAL_TYPE) - pp_c_identifier (pp, "enum"); - else - pp_c_identifier (pp, ""); - - if (TYPE_NAME (t)) - pp_id_expression (pp, TYPE_NAME (t)); - else - pp_c_identifier (pp, ""); - break; - - default: - pp_unsupported_tree (pp, t); - break; - } -} - -/* specifier-qualifier-list: - type-specifier specifier-qualifier-list-opt - type-qualifier specifier-qualifier-list-opt - - - Implementation note: Because of the non-linearities in array or - function declarations, this routine prints not just the - specifier-qualifier-list of such entities or types of such entities, - but also the 'pointer' production part of their declarators. The - remaining part is done by pp_declarator or pp_c_abstract_declarator. */ - -void -pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t) -{ - const enum tree_code code = TREE_CODE (t); - - if (TREE_CODE (t) != POINTER_TYPE) - pp_c_type_qualifier_list (pp, t); - switch (code) - { - case REFERENCE_TYPE: - case POINTER_TYPE: - { - /* Get the types-specifier of this type. */ - tree pointee = strip_pointer_operator (TREE_TYPE (t)); - pp_c_specifier_qualifier_list (pp, pointee); - if (TREE_CODE (pointee) == ARRAY_TYPE - || TREE_CODE (pointee) == FUNCTION_TYPE) - { - pp_c_whitespace (pp); - pp_c_left_paren (pp); - } - else if (!c_dialect_cxx ()) - pp_c_whitespace (pp); - pp_ptr_operator (pp, t); - } - break; - - case FUNCTION_TYPE: - case ARRAY_TYPE: - pp_c_specifier_qualifier_list (pp, TREE_TYPE (t)); - break; - - case VECTOR_TYPE: - case COMPLEX_TYPE: - pp_c_specifier_qualifier_list (pp, TREE_TYPE (t)); - if (code == COMPLEX_TYPE) - pp_c_identifier (pp, flag_isoc99 ? "_Complex" : "__complex__"); - else if (code == VECTOR_TYPE) - pp_c_identifier (pp, "__vector__"); - break; - - default: - pp_simple_type_specifier (pp, t); - break; - } -} - -/* parameter-type-list: - parameter-list - parameter-list , ... - - parameter-list: - parameter-declaration - parameter-list , parameter-declaration - - parameter-declaration: - declaration-specifiers declarator - declaration-specifiers abstract-declarator(opt) */ - -void -pp_c_parameter_type_list (c_pretty_printer *pp, tree t) -{ - bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract); - tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t); - pp_c_left_paren (pp); - if (parms == void_list_node) - pp_c_identifier (pp, "void"); - else - { - bool first = true; - for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms)) - { - if (!first) - pp_separate_with (pp, ','); - first = false; - pp_declaration_specifiers - (pp, want_parm_decl ? parms : TREE_VALUE (parms)); - if (want_parm_decl) - pp_declarator (pp, parms); - else - pp_abstract_declarator (pp, TREE_VALUE (parms)); - } - } - pp_c_right_paren (pp); -} - -/* abstract-declarator: - pointer - pointer(opt) direct-abstract-declarator */ - -static void -pp_c_abstract_declarator (c_pretty_printer *pp, tree t) -{ - if (TREE_CODE (t) == POINTER_TYPE) - { - if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE - || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) - pp_c_right_paren (pp); - t = TREE_TYPE (t); - } - - pp_direct_abstract_declarator (pp, t); -} - -/* direct-abstract-declarator: - ( abstract-declarator ) - direct-abstract-declarator(opt) [ assignment-expression(opt) ] - direct-abstract-declarator(opt) [ * ] - direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */ - -void -pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t) -{ - switch (TREE_CODE (t)) - { - case POINTER_TYPE: - pp_abstract_declarator (pp, t); - break; - - case FUNCTION_TYPE: - pp_c_parameter_type_list (pp, t); - pp_direct_abstract_declarator (pp, TREE_TYPE (t)); - break; - - case ARRAY_TYPE: - pp_c_left_bracket (pp); - if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t))) - pp_expression (pp, TYPE_MAX_VALUE (TYPE_DOMAIN (t))); - pp_c_right_bracket (pp); - pp_direct_abstract_declarator (pp, TREE_TYPE (t)); - break; - - case IDENTIFIER_NODE: - case VOID_TYPE: - case BOOLEAN_TYPE: - case INTEGER_TYPE: - case REAL_TYPE: - case ENUMERAL_TYPE: - case RECORD_TYPE: - case UNION_TYPE: - case VECTOR_TYPE: - case COMPLEX_TYPE: - case TYPE_DECL: - break; - - default: - pp_unsupported_tree (pp, t); - break; - } -} - -/* type-name: - specifier-qualifier-list abstract-declarator(opt) */ - -void -pp_c_type_id (c_pretty_printer *pp, tree t) -{ - pp_c_specifier_qualifier_list (pp, t); - pp_abstract_declarator (pp, t); -} - -/* storage-class-specifier: - typedef - extern - static - auto - register */ - -void -pp_c_storage_class_specifier (c_pretty_printer *pp, tree t) -{ - if (TREE_CODE (t) == TYPE_DECL) - pp_c_identifier (pp, "typedef"); - else if (DECL_P (t)) - { - if (DECL_REGISTER (t)) - pp_c_identifier (pp, "register"); - else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL) - pp_c_identifier (pp, "static"); - } -} - -/* function-specifier: - inline */ - -void -pp_c_function_specifier (c_pretty_printer *pp, tree t) -{ - if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t)) - pp_c_identifier (pp, "inline"); -} - -/* declaration-specifiers: - storage-class-specifier declaration-specifiers(opt) - type-specifier declaration-specifiers(opt) - type-qualifier declaration-specifiers(opt) - function-specifier declaration-specifiers(opt) */ - -void -pp_c_declaration_specifiers (c_pretty_printer *pp, tree t) -{ - pp_storage_class_specifier (pp, t); - pp_function_specifier (pp, t); - pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t); -} - -/* direct-declarator - identifier - ( declarator ) - direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ] - direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)] - direct-declarator [ type-qualifier-list static assignment-expression ] - direct-declarator [ type-qualifier-list * ] - direct-declarator ( parameter-type-list ) - direct-declarator ( identifier-list(opt) ) */ - -void -pp_c_direct_declarator (c_pretty_printer *pp, tree t) -{ - switch (TREE_CODE (t)) - { - case VAR_DECL: - case PARM_DECL: - case TYPE_DECL: - case FIELD_DECL: - case LABEL_DECL: - pp_c_space_for_pointer_operator (pp, TREE_TYPE (t)); - pp_c_tree_decl_identifier (pp, t); - break; - - case ARRAY_TYPE: - case POINTER_TYPE: - pp_abstract_declarator (pp, TREE_TYPE (t)); - break; - - case FUNCTION_TYPE: - pp_parameter_list (pp, t); - pp_abstract_declarator (pp, TREE_TYPE (t)); - break; - - case FUNCTION_DECL: - pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t))); - pp_c_tree_decl_identifier (pp, t); - if (pp_c_base (pp)->flags & pp_c_flag_abstract) - pp_abstract_declarator (pp, TREE_TYPE (t)); - else - { - pp_parameter_list (pp, t); - pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t))); - } - break; - - case INTEGER_TYPE: - case REAL_TYPE: - case ENUMERAL_TYPE: - case UNION_TYPE: - case RECORD_TYPE: - break; - - default: - pp_unsupported_tree (pp, t); - break; - } -} - - -/* declarator: - pointer(opt) direct-declarator */ - -void -pp_c_declarator (c_pretty_printer *pp, tree t) -{ - switch (TREE_CODE (t)) - { - case INTEGER_TYPE: - case REAL_TYPE: - case ENUMERAL_TYPE: - case UNION_TYPE: - case RECORD_TYPE: - break; - - case VAR_DECL: - case PARM_DECL: - case FIELD_DECL: - case ARRAY_TYPE: - case FUNCTION_TYPE: - case FUNCTION_DECL: - case TYPE_DECL: - pp_direct_declarator (pp, t); - break; - - - default: - pp_unsupported_tree (pp, t); - break; - } -} - -/* declaration: - declaration-specifiers init-declarator-list(opt) ; */ - -void -pp_c_declaration (c_pretty_printer *pp, tree t) -{ - pp_declaration_specifiers (pp, t); - pp_c_init_declarator (pp, t); -} - -/* Pretty-print ATTRIBUTES using GNU C extension syntax. */ - -void -pp_c_attributes (c_pretty_printer *pp, tree attributes) -{ - if (attributes == NULL_TREE) - return; - - pp_c_identifier (pp, "__attribute__"); - pp_c_left_paren (pp); - pp_c_left_paren (pp); - for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes)) - { - pp_tree_identifier (pp, TREE_PURPOSE (attributes)); - if (TREE_VALUE (attributes)) - pp_c_call_argument_list (pp, TREE_VALUE (attributes)); - - if (TREE_CHAIN (attributes)) - pp_separate_with (pp, ','); - } - pp_c_right_paren (pp); - pp_c_right_paren (pp); -} - -/* function-definition: - declaration-specifiers declarator compound-statement */ - -void -pp_c_function_definition (c_pretty_printer *pp, tree t) -{ - pp_declaration_specifiers (pp, t); - pp_declarator (pp, t); - pp_needs_newline (pp) = true; - pp_statement (pp, DECL_SAVED_TREE (t)); - pp_newline (pp); - pp_flush (pp); -} - - -/* Expressions. */ - -/* Print out a c-char. This is called solely for characters which are - in the *target* execution character set. We ought to convert them - back to the *host* execution character set before printing, but we - have no way to do this at present. A decent compromise is to print - all characters as if they were in the host execution character set, - and not attempt to recover any named escape characters, but render - all unprintables as octal escapes. If the host and target character - sets are the same, this produces relatively readable output. If they - are not the same, strings may appear as gibberish, but that's okay - (in fact, it may well be what the reader wants, e.g. if they are looking - to see if conversion to the target character set happened correctly). - - A special case: we need to prefix \, ", and ' with backslashes. It is - correct to do so for the *host*'s \, ", and ', because the rest of the - file appears in the host character set. */ - -static void -pp_c_char (c_pretty_printer *pp, int c) -{ - if (ISPRINT (c)) - { - switch (c) - { - case '\\': pp_string (pp, "\\\\"); break; - case '\'': pp_string (pp, "\\\'"); break; - case '\"': pp_string (pp, "\\\""); break; - default: pp_character (pp, c); - } - } - else - pp_scalar (pp, "\\%03o", (unsigned) c); -} - -/* Print out a STRING literal. */ - -void -pp_c_string_literal (c_pretty_printer *pp, tree s) -{ - const char *p = TREE_STRING_POINTER (s); - int n = TREE_STRING_LENGTH (s) - 1; - int i; - pp_doublequote (pp); - for (i = 0; i < n; ++i) - pp_c_char (pp, p[i]); - pp_doublequote (pp); -} - -/* Pretty-print an INTEGER literal. */ - -static void -pp_c_integer_constant (c_pretty_printer *pp, tree i) -{ - tree type = TREE_TYPE (i); - - if (TREE_INT_CST_HIGH (i) == 0) - pp_wide_integer (pp, TREE_INT_CST_LOW (i)); - else - { - if (tree_int_cst_sgn (i) < 0) - { - pp_character (pp, '-'); - i = build_int_cst_wide (NULL_TREE, - -TREE_INT_CST_LOW (i), - ~TREE_INT_CST_HIGH (i) - + !TREE_INT_CST_LOW (i)); - } - sprintf (pp_buffer (pp)->digit_buffer, - HOST_WIDE_INT_PRINT_DOUBLE_HEX, - TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i)); - pp_string (pp, pp_buffer (pp)->digit_buffer); - } - if (TYPE_UNSIGNED (type)) - pp_character (pp, 'u'); - if (type == long_integer_type_node || type == long_unsigned_type_node) - pp_character (pp, 'l'); - else if (type == long_long_integer_type_node - || type == long_long_unsigned_type_node) - pp_string (pp, "ll"); -} - -/* Print out a CHARACTER literal. */ - -static void -pp_c_character_constant (c_pretty_printer *pp, tree c) -{ - tree type = TREE_TYPE (c); - if (type == wchar_type_node) - pp_character (pp, 'L'); - pp_quote (pp); - if (host_integerp (c, TYPE_UNSIGNED (type))) - pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type))); - else - pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c)); - pp_quote (pp); -} - -/* Print out a BOOLEAN literal. */ - -static void -pp_c_bool_constant (c_pretty_printer *pp, tree b) -{ - if (b == boolean_false_node) - { - if (c_dialect_cxx ()) - pp_c_identifier (pp, "false"); - else if (flag_isoc99) - pp_c_identifier (pp, "_False"); - else - pp_unsupported_tree (pp, b); - } - else if (b == boolean_true_node) - { - if (c_dialect_cxx ()) - pp_c_identifier (pp, "true"); - else if (flag_isoc99) - pp_c_identifier (pp, "_True"); - else - pp_unsupported_tree (pp, b); - } - else if (TREE_CODE (b) == INTEGER_CST) - pp_c_integer_constant (pp, b); - else - pp_unsupported_tree (pp, b); -} - -/* Attempt to print out an ENUMERATOR. Return true on success. Else return - false; that means the value was obtained by a cast, in which case - print out the type-id part of the cast-expression -- the casted value - is then printed by pp_c_integer_literal. */ - -static bool -pp_c_enumeration_constant (c_pretty_printer *pp, tree e) -{ - bool value_is_named = true; - tree type = TREE_TYPE (e); - tree value; - - /* Find the name of this constant. */ - for (value = TYPE_VALUES (type); - value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e); - value = TREE_CHAIN (value)) - ; - - if (value != NULL_TREE) - pp_id_expression (pp, TREE_PURPOSE (value)); - else - { - /* Value must have been cast. */ - pp_c_type_cast (pp, type); - value_is_named = false; - } - - return value_is_named; -} - -/* Print out a REAL value as a decimal-floating-constant. */ - -static void -pp_c_floating_constant (c_pretty_printer *pp, tree r) -{ - real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r), - sizeof (pp_buffer (pp)->digit_buffer), 0, 1); - pp_string (pp, pp_buffer(pp)->digit_buffer); - if (TREE_TYPE (r) == float_type_node) - pp_character (pp, 'f'); - else if (TREE_TYPE (r) == long_double_type_node) - pp_character (pp, 'l'); -} - -/* Pretty-print a compound literal expression. GNU extensions include - vector constants. */ - -static void -pp_c_compound_literal (c_pretty_printer *pp, tree e) -{ - tree type = TREE_TYPE (e); - pp_c_type_cast (pp, type); - - switch (TREE_CODE (type)) - { - case RECORD_TYPE: - case UNION_TYPE: - case ARRAY_TYPE: - case VECTOR_TYPE: - case COMPLEX_TYPE: - pp_c_brace_enclosed_initializer_list (pp, e); - break; - - default: - pp_unsupported_tree (pp, e); - break; - } -} - -/* constant: - integer-constant - floating-constant - enumeration-constant - character-constant */ - -void -pp_c_constant (c_pretty_printer *pp, tree e) -{ - const enum tree_code code = TREE_CODE (e); - - switch (code) - { - case INTEGER_CST: - { - tree type = TREE_TYPE (e); - if (type == boolean_type_node) - pp_c_bool_constant (pp, e); - else if (type == char_type_node) - pp_c_character_constant (pp, e); - else if (TREE_CODE (type) == ENUMERAL_TYPE - && pp_c_enumeration_constant (pp, e)) - ; - else - pp_c_integer_constant (pp, e); - } - break; - - case REAL_CST: - pp_c_floating_constant (pp, e); - break; - - case STRING_CST: - pp_c_string_literal (pp, e); - break; - - default: - pp_unsupported_tree (pp, e); - break; - } -} - -/* Pretty-print an IDENTIFIER_NODE, preceded by whitespace is necessary. */ - -void -pp_c_identifier (c_pretty_printer *pp, const char *id) -{ - pp_c_maybe_whitespace (pp); - pp_identifier (pp, id); - pp_base (pp)->padding = pp_before; -} - -/* Pretty-print a C primary-expression. - primary-expression: - identifier - constant - string-literal - ( expression ) */ - -void -pp_c_primary_expression (c_pretty_printer *pp, tree e) -{ - switch (TREE_CODE (e)) - { - case VAR_DECL: - case PARM_DECL: - case FIELD_DECL: - case CONST_DECL: - case FUNCTION_DECL: - case LABEL_DECL: - pp_c_tree_decl_identifier (pp, e); - break; - - case IDENTIFIER_NODE: - pp_c_tree_identifier (pp, e); - break; - - case ERROR_MARK: - pp_c_identifier (pp, ""); - break; - - case RESULT_DECL: - pp_c_identifier (pp, ""); - break; - - case INTEGER_CST: - case REAL_CST: - case STRING_CST: - pp_c_constant (pp, e); - break; - - case TARGET_EXPR: - pp_c_identifier (pp, "__builtin_memcpy"); - pp_c_left_paren (pp); - pp_ampersand (pp); - pp_primary_expression (pp, TREE_OPERAND (e, 0)); - pp_separate_with (pp, ','); - pp_ampersand (pp); - pp_initializer (pp, TREE_OPERAND (e, 1)); - if (TREE_OPERAND (e, 2)) - { - pp_separate_with (pp, ','); - pp_c_expression (pp, TREE_OPERAND (e, 2)); - } - pp_c_right_paren (pp); - break; - - default: - /* FIXME: Make sure we won't get into an infinie loop. */ - pp_c_left_paren (pp); - pp_expression (pp, e); - pp_c_right_paren (pp); - break; - } -} - -/* Print out a C initializer -- also support C compound-literals. - initializer: - assignment-expression: - { initializer-list } - { initializer-list , } */ - -static void -pp_c_initializer (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == CONSTRUCTOR) - pp_c_brace_enclosed_initializer_list (pp, e); - else - pp_expression (pp, e); -} - -/* init-declarator: - declarator: - declarator = initializer */ - -void -pp_c_init_declarator (c_pretty_printer *pp, tree t) -{ - pp_declarator (pp, t); - /* We don't want to output function definitions here. There are handled - elsewhere (and the syntactic form is bogus anyway). */ - if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t)) - { - tree init = DECL_INITIAL (t); - /* This C++ bit is handled here because it is easier to do so. - In templates, the C++ parser builds a TREE_LIST for a - direct-initialization; the TREE_PURPOSE is the variable to - initialize and the TREE_VALUE is the initializer. */ - if (TREE_CODE (init) == TREE_LIST) - { - pp_c_left_paren (pp); - pp_expression (pp, TREE_VALUE (init)); - pp_right_paren (pp); - } - else - { - pp_space (pp); - pp_equal (pp); - pp_space (pp); - pp_c_initializer (pp, init); - } - } -} - -/* initializer-list: - designation(opt) initializer - initializer-list , designation(opt) initializer - - designation: - designator-list = - - designator-list: - designator - designator-list designator - - designator: - [ constant-expression ] - identifier */ - -static void -pp_c_initializer_list (c_pretty_printer *pp, tree e) -{ - tree type = TREE_TYPE (e); - const enum tree_code code = TREE_CODE (type); - - switch (code) - { - case RECORD_TYPE: - case UNION_TYPE: - case ARRAY_TYPE: - { - tree init = TREE_OPERAND (e, 0); - for (; init != NULL_TREE; init = TREE_CHAIN (init)) - { - if (code == RECORD_TYPE || code == UNION_TYPE) - { - pp_c_dot (pp); - pp_c_primary_expression (pp, TREE_PURPOSE (init)); - } - else - { - pp_c_left_bracket (pp); - if (TREE_PURPOSE (init)) - pp_c_constant (pp, TREE_PURPOSE (init)); - pp_c_right_bracket (pp); - } - pp_c_whitespace (pp); - pp_equal (pp); - pp_c_whitespace (pp); - pp_initializer (pp, TREE_VALUE (init)); - if (TREE_CHAIN (init)) - pp_separate_with (pp, ','); - } - } - return; - - case VECTOR_TYPE: - if (TREE_CODE (e) == VECTOR_CST) - pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e)); - else if (TREE_CODE (e) == CONSTRUCTOR) - pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e)); - else - break; - return; - - case COMPLEX_TYPE: - if (TREE_CODE (e) == CONSTRUCTOR) - pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e)); - else if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR) - { - const bool cst = TREE_CODE (e) == COMPLEX_CST; - pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0)); - pp_separate_with (pp, ','); - pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1)); - } - else - break; - return; - - default: - break; - } - - pp_unsupported_tree (pp, type); -} - -/* Pretty-print a brace-enclosed initializer-list. */ - -static void -pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l) -{ - pp_c_left_brace (pp); - pp_c_initializer_list (pp, l); - pp_c_right_brace (pp); -} - - -/* This is a convenient function, used to bridge gap between C and C++ - grammars. - - id-expression: - identifier */ - -void -pp_c_id_expression (c_pretty_printer *pp, tree t) -{ - switch (TREE_CODE (t)) - { - case VAR_DECL: - case PARM_DECL: - case CONST_DECL: - case TYPE_DECL: - case FUNCTION_DECL: - case FIELD_DECL: - case LABEL_DECL: - pp_c_tree_decl_identifier (pp, t); - break; - - case IDENTIFIER_NODE: - pp_c_tree_identifier (pp, t); - break; - - default: - pp_unsupported_tree (pp, t); - break; - } -} - -/* postfix-expression: - primary-expression - postfix-expression [ expression ] - postfix-expression ( argument-expression-list(opt) ) - postfix-expression . identifier - postfix-expression -> identifier - postfix-expression ++ - postfix-expression -- - ( type-name ) { initializer-list } - ( type-name ) { initializer-list , } */ - -void -pp_c_postfix_expression (c_pretty_printer *pp, tree e) -{ - enum tree_code code = TREE_CODE (e); - switch (code) - { - case POSTINCREMENT_EXPR: - case POSTDECREMENT_EXPR: - pp_postfix_expression (pp, TREE_OPERAND (e, 0)); - pp_identifier (pp, code == POSTINCREMENT_EXPR ? "++" : "--"); - break; - - case ARRAY_REF: - pp_postfix_expression (pp, TREE_OPERAND (e, 0)); - pp_c_left_bracket (pp); - pp_expression (pp, TREE_OPERAND (e, 1)); - pp_c_right_bracket (pp); - break; - - case CALL_EXPR: - pp_postfix_expression (pp, TREE_OPERAND (e, 0)); - pp_c_call_argument_list (pp, TREE_OPERAND (e, 1)); - break; - - case UNORDERED_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "isunordered" - : "__builtin_isunordered"); - goto two_args_fun; - - case ORDERED_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "!isunordered" - : "!__builtin_isunordered"); - goto two_args_fun; - - case UNLT_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "!isgreaterequal" - : "!__builtin_isgreaterequal"); - goto two_args_fun; - - case UNLE_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "!isgreater" - : "!__builtin_isgreater"); - goto two_args_fun; - - case UNGT_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "!islessequal" - : "!__builtin_islessequal"); - goto two_args_fun; - - case UNGE_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "!isless" - : "!__builtin_isless"); - goto two_args_fun; - - case UNEQ_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "!islessgreater" - : "!__builtin_islessgreater"); - goto two_args_fun; - - case LTGT_EXPR: - pp_c_identifier (pp, flag_isoc99 - ? "islessgreater" - : "__builtin_islessgreater"); - goto two_args_fun; - - two_args_fun: - pp_c_left_paren (pp); - pp_expression (pp, TREE_OPERAND (e, 0)); - pp_separate_with (pp, ','); - pp_expression (pp, TREE_OPERAND (e, 1)); - pp_c_right_paren (pp); - break; - - case ABS_EXPR: - pp_c_identifier (pp, "__builtin_abs"); - pp_c_left_paren (pp); - pp_expression (pp, TREE_OPERAND (e, 0)); - pp_c_right_paren (pp); - break; - - case COMPONENT_REF: - { - tree object = TREE_OPERAND (e, 0); - if (TREE_CODE (object) == INDIRECT_REF) - { - pp_postfix_expression (pp, TREE_OPERAND (object, 0)); - pp_c_arrow (pp); - } - else - { - pp_postfix_expression (pp, object); - pp_c_dot (pp); - } - pp_expression (pp, TREE_OPERAND (e, 1)); - } - break; - - case COMPLEX_CST: - case VECTOR_CST: - case COMPLEX_EXPR: - pp_c_compound_literal (pp, e); - break; - - case COMPOUND_LITERAL_EXPR: - e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e)); - /* Fall through. */ - case CONSTRUCTOR: - pp_initializer (pp, e); - break; - - case VA_ARG_EXPR: - pp_c_identifier (pp, "__builtin_va_arg"); - pp_c_left_paren (pp); - pp_assignment_expression (pp, TREE_OPERAND (e, 0)); - pp_separate_with (pp, ','); - pp_type_id (pp, TREE_TYPE (e)); - pp_c_right_paren (pp); - break; - - case ADDR_EXPR: - if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL) - { - pp_c_id_expression (pp, TREE_OPERAND (e, 0)); - break; - } - /* else fall through. */ - - default: - pp_primary_expression (pp, e); - break; - } -} - -/* Print out an expression-list; E is expected to be a TREE_LIST. */ - -void -pp_c_expression_list (c_pretty_printer *pp, tree e) -{ - for (; e != NULL_TREE; e = TREE_CHAIN (e)) - { - pp_expression (pp, TREE_VALUE (e)); - if (TREE_CHAIN (e)) - pp_separate_with (pp, ','); - } -} - -/* Print out V, which contains the elements of a constructor. */ - -void -pp_c_constructor_elts (c_pretty_printer *pp, VEC(constructor_elt,gc) *v) -{ - unsigned HOST_WIDE_INT ix; - tree value; - - FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value) - { - pp_expression (pp, value); - if (ix != VEC_length (constructor_elt, v) - 1) - pp_separate_with (pp, ','); - } -} - -/* Print out an expression-list in parens, as in a function call. */ - -void -pp_c_call_argument_list (c_pretty_printer *pp, tree t) -{ - pp_c_left_paren (pp); - if (t && TREE_CODE (t) == TREE_LIST) - pp_c_expression_list (pp, t); - pp_c_right_paren (pp); -} - -/* unary-expression: - postfix-expression - ++ cast-expression - -- cast-expression - unary-operator cast-expression - sizeof unary-expression - sizeof ( type-id ) - - unary-operator: one of - * & + - ! ~ - - GNU extensions. - unary-expression: - __alignof__ unary-expression - __alignof__ ( type-id ) - __real__ unary-expression - __imag__ unary-expression */ - -void -pp_c_unary_expression (c_pretty_printer *pp, tree e) -{ - enum tree_code code = TREE_CODE (e); - switch (code) - { - case PREINCREMENT_EXPR: - case PREDECREMENT_EXPR: - pp_identifier (pp, code == PREINCREMENT_EXPR ? "++" : "--"); - pp_c_unary_expression (pp, TREE_OPERAND (e, 0)); - break; - - case ADDR_EXPR: - case INDIRECT_REF: - case NEGATE_EXPR: - case BIT_NOT_EXPR: - case TRUTH_NOT_EXPR: - case CONJ_EXPR: - /* String literal are used by address. */ - if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST) - pp_ampersand (pp); - else if (code == INDIRECT_REF) - pp_c_star (pp); - else if (code == NEGATE_EXPR) - pp_minus (pp); - else if (code == BIT_NOT_EXPR || code == CONJ_EXPR) - pp_complement (pp); - else if (code == TRUTH_NOT_EXPR) - pp_exclamation (pp); - pp_c_cast_expression (pp, TREE_OPERAND (e, 0)); - break; - - case REALPART_EXPR: - case IMAGPART_EXPR: - pp_c_identifier (pp, code == REALPART_EXPR ? "__real__" : "__imag__"); - pp_c_whitespace (pp); - pp_unary_expression (pp, TREE_OPERAND (e, 0)); - break; - - default: - pp_postfix_expression (pp, e); - break; - } -} - -/* cast-expression: - unary-expression - ( type-name ) cast-expression */ - -void -pp_c_cast_expression (c_pretty_printer *pp, tree e) -{ - switch (TREE_CODE (e)) - { - case FLOAT_EXPR: - case FIX_TRUNC_EXPR: - case CONVERT_EXPR: - pp_c_type_cast (pp, TREE_TYPE (e)); - pp_c_cast_expression (pp, TREE_OPERAND (e, 0)); - break; - - default: - pp_unary_expression (pp, e); - } -} - -/* multiplicative-expression: - cast-expression - multiplicative-expression * cast-expression - multiplicative-expression / cast-expression - multiplicative-expression % cast-expression */ - -static void -pp_c_multiplicative_expression (c_pretty_printer *pp, tree e) -{ - enum tree_code code = TREE_CODE (e); - switch (code) - { - case MULT_EXPR: - case TRUNC_DIV_EXPR: - case TRUNC_MOD_EXPR: - pp_multiplicative_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - if (code == MULT_EXPR) - pp_c_star (pp); - else if (code == TRUNC_DIV_EXPR) - pp_slash (pp); - else - pp_modulo (pp); - pp_c_whitespace (pp); - pp_c_cast_expression (pp, TREE_OPERAND (e, 1)); - break; - - default: - pp_c_cast_expression (pp, e); - break; - } -} - -/* additive-expression: - multiplicative-expression - additive-expression + multiplicative-expression - additive-expression - multiplicative-expression */ - -static void -pp_c_additive_expression (c_pretty_printer *pp, tree e) -{ - enum tree_code code = TREE_CODE (e); - switch (code) - { - case PLUS_EXPR: - case MINUS_EXPR: - pp_c_additive_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - if (code == PLUS_EXPR) - pp_plus (pp); - else - pp_minus (pp); - pp_c_whitespace (pp); - pp_multiplicative_expression (pp, TREE_OPERAND (e, 1)); - break; - - default: - pp_multiplicative_expression (pp, e); - break; - } -} - -/* additive-expression: - additive-expression - shift-expression << additive-expression - shift-expression >> additive-expression */ - -static void -pp_c_shift_expression (c_pretty_printer *pp, tree e) -{ - enum tree_code code = TREE_CODE (e); - switch (code) - { - case LSHIFT_EXPR: - case RSHIFT_EXPR: - pp_c_shift_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_identifier (pp, code == LSHIFT_EXPR ? "<<" : ">>"); - pp_c_whitespace (pp); - pp_c_additive_expression (pp, TREE_OPERAND (e, 1)); - break; - - default: - pp_c_additive_expression (pp, e); - } -} - -/* relational-expression: - shift-expression - relational-expression < shift-expression - relational-expression > shift-expression - relational-expression <= shift-expression - relational-expression >= shift-expression */ - -static void -pp_c_relational_expression (c_pretty_printer *pp, tree e) -{ - enum tree_code code = TREE_CODE (e); - switch (code) - { - case LT_EXPR: - case GT_EXPR: - case LE_EXPR: - case GE_EXPR: - pp_c_relational_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - if (code == LT_EXPR) - pp_less (pp); - else if (code == GT_EXPR) - pp_greater (pp); - else if (code == LE_EXPR) - pp_identifier (pp, "<="); - else if (code == GE_EXPR) - pp_identifier (pp, ">="); - pp_c_whitespace (pp); - pp_c_shift_expression (pp, TREE_OPERAND (e, 1)); - break; - - default: - pp_c_shift_expression (pp, e); - break; - } -} - -/* equality-expression: - relational-expression - equality-expression == relational-expression - equality-equality != relational-expression */ - -static void -pp_c_equality_expression (c_pretty_printer *pp, tree e) -{ - enum tree_code code = TREE_CODE (e); - switch (code) - { - case EQ_EXPR: - case NE_EXPR: - pp_c_equality_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_identifier (pp, code == EQ_EXPR ? "==" : "!="); - pp_c_whitespace (pp); - pp_c_relational_expression (pp, TREE_OPERAND (e, 1)); - break; - - default: - pp_c_relational_expression (pp, e); - break; - } -} - -/* AND-expression: - equality-expression - AND-expression & equality-equality */ - -static void -pp_c_and_expression (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == BIT_AND_EXPR) - { - pp_c_and_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_ampersand (pp); - pp_c_whitespace (pp); - pp_c_equality_expression (pp, TREE_OPERAND (e, 1)); - } - else - pp_c_equality_expression (pp, e); -} - -/* exclusive-OR-expression: - AND-expression - exclusive-OR-expression ^ AND-expression */ - -static void -pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == BIT_XOR_EXPR) - { - pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0)); - pp_c_maybe_whitespace (pp); - pp_carret (pp); - pp_c_whitespace (pp); - pp_c_and_expression (pp, TREE_OPERAND (e, 1)); - } - else - pp_c_and_expression (pp, e); -} - -/* inclusive-OR-expression: - exclusive-OR-expression - inclusive-OR-expression | exclusive-OR-expression */ - -static void -pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == BIT_IOR_EXPR) - { - pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_bar (pp); - pp_c_whitespace (pp); - pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1)); - } - else - pp_c_exclusive_or_expression (pp, e); -} - -/* logical-AND-expression: - inclusive-OR-expression - logical-AND-expression && inclusive-OR-expression */ - -static void -pp_c_logical_and_expression (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == TRUTH_ANDIF_EXPR) - { - pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_identifier (pp, "&&"); - pp_c_whitespace (pp); - pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1)); - } - else - pp_c_inclusive_or_expression (pp, e); -} - -/* logical-OR-expression: - logical-AND-expression - logical-OR-expression || logical-AND-expression */ - -void -pp_c_logical_or_expression (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == TRUTH_ORIF_EXPR) - { - pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_identifier (pp, "||"); - pp_c_whitespace (pp); - pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1)); - } - else - pp_c_logical_and_expression (pp, e); -} - -/* conditional-expression: - logical-OR-expression - logical-OR-expression ? expression : conditional-expression */ - -static void -pp_c_conditional_expression (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == COND_EXPR) - { - pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_question (pp); - pp_c_whitespace (pp); - pp_expression (pp, TREE_OPERAND (e, 1)); - pp_c_whitespace (pp); - pp_colon (pp); - pp_c_whitespace (pp); - pp_c_conditional_expression (pp, TREE_OPERAND (e, 2)); - } - else - pp_c_logical_or_expression (pp, e); -} - - -/* assignment-expression: - conditional-expression - unary-expression assignment-operator assignment-expression - - assignment-expression: one of - = *= /= %= += -= >>= <<= &= ^= |= */ - -static void -pp_c_assignment_expression (c_pretty_printer *pp, tree e) -{ - if (TREE_CODE (e) == MODIFY_EXPR || TREE_CODE (e) == INIT_EXPR) - { - pp_c_unary_expression (pp, TREE_OPERAND (e, 0)); - pp_c_whitespace (pp); - pp_equal (pp); - pp_space (pp); - pp_c_expression (pp, TREE_OPERAND (e, 1)); - } - else - pp_c_conditional_expression (pp, e); -} - -/* expression: - assignment-expression - expression , assignment-expression - - Implementation note: instead of going through the usual recursion - chain, I take the liberty of dispatching nodes to the appropriate - functions. This makes some redundancy, but it worths it. That also - prevents a possible infinite recursion between pp_c_primary_expression () - and pp_c_expression (). */ - -void -pp_c_expression (c_pretty_printer *pp, tree e) -{ - switch (TREE_CODE (e)) - { - case INTEGER_CST: - pp_c_integer_constant (pp, e); - break; - - case REAL_CST: - pp_c_floating_constant (pp, e); - break; - - case STRING_CST: - pp_c_string_literal (pp, e); - break; - - case IDENTIFIER_NODE: - case FUNCTION_DECL: - case VAR_DECL: - case CONST_DECL: - case PARM_DECL: - case RESULT_DECL: - case FIELD_DECL: - case LABEL_DECL: - case ERROR_MARK: - pp_primary_expression (pp, e); - break; - - case POSTINCREMENT_EXPR: - case POSTDECREMENT_EXPR: - case ARRAY_REF: - case CALL_EXPR: - case COMPONENT_REF: - case COMPLEX_CST: - case COMPLEX_EXPR: - case VECTOR_CST: - case ORDERED_EXPR: - case UNORDERED_EXPR: - case LTGT_EXPR: - case UNEQ_EXPR: - case UNLE_EXPR: - case UNLT_EXPR: - case UNGE_EXPR: - case UNGT_EXPR: - case ABS_EXPR: - case CONSTRUCTOR: - case COMPOUND_LITERAL_EXPR: - case VA_ARG_EXPR: - pp_postfix_expression (pp, e); - break; - - case CONJ_EXPR: - case ADDR_EXPR: - case INDIRECT_REF: - case NEGATE_EXPR: - case BIT_NOT_EXPR: - case TRUTH_NOT_EXPR: - case PREINCREMENT_EXPR: - case PREDECREMENT_EXPR: - case REALPART_EXPR: - case IMAGPART_EXPR: - pp_c_unary_expression (pp, e); - break; - - case FLOAT_EXPR: - case FIX_TRUNC_EXPR: - case CONVERT_EXPR: - pp_c_cast_expression (pp, e); - break; - - case MULT_EXPR: - case TRUNC_MOD_EXPR: - case TRUNC_DIV_EXPR: - pp_multiplicative_expression (pp, e); - break; - - case LSHIFT_EXPR: - case RSHIFT_EXPR: - pp_c_shift_expression (pp, e); - break; - - case LT_EXPR: - case GT_EXPR: - case LE_EXPR: - case GE_EXPR: - pp_c_relational_expression (pp, e); - break; - - case BIT_AND_EXPR: - pp_c_and_expression (pp, e); - break; - - case BIT_XOR_EXPR: - pp_c_exclusive_or_expression (pp, e); - break; - - case BIT_IOR_EXPR: - pp_c_inclusive_or_expression (pp, e); - break; - - case TRUTH_ANDIF_EXPR: - pp_c_logical_and_expression (pp, e); - break; - - case TRUTH_ORIF_EXPR: - pp_c_logical_or_expression (pp, e); - break; - - case EQ_EXPR: - case NE_EXPR: - pp_c_equality_expression (pp, e); - break; - - case COND_EXPR: - pp_conditional_expression (pp, e); - break; - - case PLUS_EXPR: - case MINUS_EXPR: - pp_c_additive_expression (pp, e); - break; - - case MODIFY_EXPR: - case INIT_EXPR: - pp_assignment_expression (pp, e); - break; - - case COMPOUND_EXPR: - pp_c_left_paren (pp); - pp_expression (pp, TREE_OPERAND (e, 0)); - pp_separate_with (pp, ','); - pp_assignment_expression (pp, TREE_OPERAND (e, 1)); - pp_c_right_paren (pp); - break; - - case NOP_EXPR: - case NON_LVALUE_EXPR: - case SAVE_EXPR: - pp_expression (pp, TREE_OPERAND (e, 0)); - break; - - case TARGET_EXPR: - pp_postfix_expression (pp, TREE_OPERAND (e, 1)); - break; - - default: - pp_unsupported_tree (pp, e); - break; - } -} - - - -/* Statements. */ - -void -pp_c_statement (c_pretty_printer *pp, tree stmt) -{ - if (stmt == NULL) - return; - - if (pp_needs_newline (pp)) - pp_newline_and_indent (pp, 0); - - dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true); -} - - -/* Initialize the PRETTY-PRINTER for handling C codes. */ - -void -pp_c_pretty_printer_init (c_pretty_printer *pp) -{ - pp->offset_list = 0; - - pp->declaration = pp_c_declaration; - pp->declaration_specifiers = pp_c_declaration_specifiers; - pp->declarator = pp_c_declarator; - pp->direct_declarator = pp_c_direct_declarator; - pp->type_specifier_seq = pp_c_specifier_qualifier_list; - pp->abstract_declarator = pp_c_abstract_declarator; - pp->direct_abstract_declarator = pp_c_direct_abstract_declarator; - pp->ptr_operator = pp_c_pointer; - pp->parameter_list = pp_c_parameter_type_list; - pp->type_id = pp_c_type_id; - pp->simple_type_specifier = pp_c_type_specifier; - pp->function_specifier = pp_c_function_specifier; - pp->storage_class_specifier = pp_c_storage_class_specifier; - - pp->statement = pp_c_statement; - - pp->id_expression = pp_c_id_expression; - pp->primary_expression = pp_c_primary_expression; - pp->postfix_expression = pp_c_postfix_expression; - pp->unary_expression = pp_c_unary_expression; - pp->initializer = pp_c_initializer; - pp->multiplicative_expression = pp_c_multiplicative_expression; - pp->conditional_expression = pp_c_conditional_expression; - pp->assignment_expression = pp_c_assignment_expression; - pp->expression = pp_c_expression; -} - - -/* Print the tree T in full, on file FILE. */ - -void -print_c_tree (FILE *file, tree t) -{ - static c_pretty_printer pp_rec; - static bool initialized = 0; - c_pretty_printer *pp = &pp_rec; - - if (!initialized) - { - initialized = 1; - pp_construct (pp_base (pp), NULL, 0); - pp_c_pretty_printer_init (pp); - pp_needs_newline (pp) = true; - } - pp_base (pp)->buffer->stream = file; - - pp_statement (pp, t); - - pp_newline (pp); - pp_flush (pp); -} - -/* Print the tree T in full, on stderr. */ - -void -debug_c_tree (tree t) -{ - print_c_tree (stderr, t); - fputc ('\n', stderr); -} - -/* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made - up of T's memory address. */ - -void -pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t) -{ - const char *name; - - gcc_assert (DECL_P (t)); - - if (DECL_NAME (t)) - name = IDENTIFIER_POINTER (DECL_NAME (t)); - else - { - static char xname[8]; - sprintf (xname, "", ((unsigned)((unsigned long)(t) & 0xffff))); - name = xname; - } - - pp_c_identifier (pp, name); -} diff --git a/support/cpp2/c-pretty-print.h b/support/cpp2/c-pretty-print.h deleted file mode 100644 index 2b9add61..00000000 --- a/support/cpp2/c-pretty-print.h +++ /dev/null @@ -1,207 +0,0 @@ -/* Various declarations for the C and C++ pretty-printers. - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - Contributed by Gabriel Dos Reis - -This file is part of GCC. - -GCC 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. - -GCC 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ - -#ifndef GCC_C_PRETTY_PRINTER -#define GCC_C_PRETTY_PRINTER - -#include "pretty-print.h" - - -typedef enum - { - pp_c_flag_abstract = 1 << 1, - pp_c_flag_last_bit = 2 - } pp_c_pretty_print_flags; - - -/* The data type used to bundle information necessary for pretty-printing - a C or C++ entity. */ -typedef struct c_pretty_print_info c_pretty_printer; - -/* The type of a C pretty-printer 'member' function. */ -typedef void (*c_pretty_print_fn) (c_pretty_printer *, tree); - -/* The datatype that contains information necessary for pretty-printing - a tree that represents a C construct. Any pretty-printer for a - language using C/c++ syntax can derive from this datatype and reuse - facilities provided here. It can do so by having a subobject of type - c_pretty_printer and override the macro pp_c_base to return a pointer - to that subobject. Such a pretty-printer has the responsibility to - initialize the pp_base() part, then call pp_c_pretty_printer_init - to set up the components that are specific to the C pretty-printer. - A derived pretty-printer can override any function listed in the - vtable below. See cp/cxx-pretty-print.h and cp/cxx-pretty-print.c - for an example of derivation. */ -struct c_pretty_print_info -{ - pretty_printer base; - /* Points to the first element of an array of offset-list. - Not used yet. */ - int *offset_list; - - pp_flags flags; - - /* These must be overridden by each of the C and C++ front-end to - reflect their understanding of syntactic productions when they differ. */ - c_pretty_print_fn declaration; - c_pretty_print_fn declaration_specifiers; - c_pretty_print_fn declarator; - c_pretty_print_fn abstract_declarator; - c_pretty_print_fn direct_abstract_declarator; - c_pretty_print_fn type_specifier_seq; - c_pretty_print_fn direct_declarator; - c_pretty_print_fn ptr_operator; - c_pretty_print_fn parameter_list; - c_pretty_print_fn type_id; - c_pretty_print_fn simple_type_specifier; - c_pretty_print_fn function_specifier; - c_pretty_print_fn storage_class_specifier; - c_pretty_print_fn initializer; - - c_pretty_print_fn statement; - - c_pretty_print_fn id_expression; - c_pretty_print_fn primary_expression; - c_pretty_print_fn postfix_expression; - c_pretty_print_fn unary_expression; - c_pretty_print_fn multiplicative_expression; - c_pretty_print_fn conditional_expression; - c_pretty_print_fn assignment_expression; - c_pretty_print_fn expression; -}; - -/* Override the pp_base macro. Derived pretty-printers should not - touch this macro. Instead they should override pp_c_base instead. */ -#undef pp_base -#define pp_base(PP) (&pp_c_base (PP)->base) - - -#define pp_c_tree_identifier(PPI, ID) \ - pp_c_identifier (PPI, IDENTIFIER_POINTER (ID)) - -#define pp_declaration(PPI, T) \ - pp_c_base (PPI)->declaration (pp_c_base (PPI), T) -#define pp_declaration_specifiers(PPI, D) \ - pp_c_base (PPI)->declaration_specifiers (pp_c_base (PPI), D) -#define pp_abstract_declarator(PP, D) \ - pp_c_base (PP)->abstract_declarator (pp_c_base (PP), D) -#define pp_type_specifier_seq(PPI, D) \ - pp_c_base (PPI)->type_specifier_seq (pp_c_base (PPI), D) -#define pp_declarator(PPI, D) \ - pp_c_base (PPI)->declarator (pp_c_base (PPI), D) -#define pp_direct_declarator(PPI, D) \ - pp_c_base (PPI)->direct_declarator (pp_c_base (PPI), D) -#define pp_direct_abstract_declarator(PP, D) \ - pp_c_base (PP)->direct_abstract_declarator (pp_c_base (PP), D) -#define pp_ptr_operator(PP, D) \ - pp_c_base (PP)->ptr_operator (pp_c_base (PP), D) -#define pp_parameter_list(PPI, T) \ - pp_c_base (PPI)->parameter_list (pp_c_base (PPI), T) -#define pp_type_id(PPI, D) \ - pp_c_base (PPI)->type_id (pp_c_base (PPI), D) -#define pp_simple_type_specifier(PP, T) \ - pp_c_base (PP)->simple_type_specifier (pp_c_base (PP), T) -#define pp_function_specifier(PP, D) \ - pp_c_base (PP)->function_specifier (pp_c_base (PP), D) -#define pp_storage_class_specifier(PP, D) \ - pp_c_base (PP)->storage_class_specifier (pp_c_base (PP), D); - -#define pp_statement(PPI, S) \ - pp_c_base (PPI)->statement (pp_c_base (PPI), S) - -#define pp_id_expression(PP, E) \ - pp_c_base (PP)->id_expression (pp_c_base (PP), E) -#define pp_primary_expression(PPI, E) \ - pp_c_base (PPI)->primary_expression (pp_c_base (PPI), E) -#define pp_postfix_expression(PPI, E) \ - pp_c_base (PPI)->postfix_expression (pp_c_base (PPI), E) -#define pp_unary_expression(PPI, E) \ - pp_c_base (PPI)->unary_expression (pp_c_base (PPI), E) -#define pp_initializer(PPI, E) \ - pp_c_base (PPI)->initializer (pp_c_base (PPI), E) -#define pp_multiplicative_expression(PPI, E) \ - pp_c_base (PPI)->multiplicative_expression (pp_c_base (PPI), E) -#define pp_conditional_expression(PPI, E) \ - pp_c_base (PPI)->conditional_expression (pp_c_base (PPI), E) -#define pp_assignment_expression(PPI, E) \ - pp_c_base (PPI)->assignment_expression (pp_c_base (PPI), E) -#define pp_expression(PP, E) \ - pp_c_base (PP)->expression (pp_c_base (PP), E) - - -/* Returns the c_pretty_printer base object of PRETTY-PRINTER. This - macro must be overridden by any subclass of c_pretty_print_info. */ -#define pp_c_base(PP) (PP) - -extern void pp_c_pretty_printer_init (c_pretty_printer *); -void pp_c_whitespace (c_pretty_printer *); -void pp_c_left_paren (c_pretty_printer *); -void pp_c_right_paren (c_pretty_printer *); -void pp_c_left_brace (c_pretty_printer *); -void pp_c_right_brace (c_pretty_printer *); -void pp_c_left_bracket (c_pretty_printer *); -void pp_c_right_bracket (c_pretty_printer *); -void pp_c_dot (c_pretty_printer *); -void pp_c_ampersand (c_pretty_printer *); -void pp_c_star (c_pretty_printer *); -void pp_c_arrow (c_pretty_printer *); -void pp_c_semicolon (c_pretty_printer *); -void pp_c_complement (c_pretty_printer *); -void pp_c_exclamation (c_pretty_printer *); -void pp_c_space_for_pointer_operator (c_pretty_printer *, tree); - -/* Declarations. */ -void pp_c_tree_decl_identifier (c_pretty_printer *, tree); -void pp_c_function_definition (c_pretty_printer *, tree); -void pp_c_attributes (c_pretty_printer *, tree); -void pp_c_type_qualifier_list (c_pretty_printer *, tree); -void pp_c_parameter_type_list (c_pretty_printer *, tree); -void pp_c_declaration (c_pretty_printer *, tree); -void pp_c_declaration_specifiers (c_pretty_printer *, tree); -void pp_c_declarator (c_pretty_printer *, tree); -void pp_c_direct_declarator (c_pretty_printer *, tree); -void pp_c_specifier_qualifier_list (c_pretty_printer *, tree); -void pp_c_function_specifier (c_pretty_printer *, tree); -void pp_c_type_id (c_pretty_printer *, tree); -void pp_c_direct_abstract_declarator (c_pretty_printer *, tree); -void pp_c_type_specifier (c_pretty_printer *, tree); -void pp_c_storage_class_specifier (c_pretty_printer *, tree); -/* Statements. */ -void pp_c_statement (c_pretty_printer *, tree); -/* Expressions. */ -void pp_c_expression (c_pretty_printer *, tree); -void pp_c_logical_or_expression (c_pretty_printer *, tree); -void pp_c_expression_list (c_pretty_printer *, tree); -////void pp_c_constructor_elts (c_pretty_printer *, VEC(constructor_elt,gc) *); -void pp_c_call_argument_list (c_pretty_printer *, tree); -void pp_c_unary_expression (c_pretty_printer *, tree); -void pp_c_cast_expression (c_pretty_printer *, tree); -void pp_c_postfix_expression (c_pretty_printer *, tree); -void pp_c_primary_expression (c_pretty_printer *, tree); -void pp_c_init_declarator (c_pretty_printer *, tree); -void pp_c_constant (c_pretty_printer *, tree); -void pp_c_id_expression (c_pretty_printer *, tree); -void pp_c_identifier (c_pretty_printer *, const char *); -void pp_c_string_literal (c_pretty_printer *, tree); - -void print_c_tree (FILE *file, tree t); - -#endif /* GCC_C_PRETTY_PRINTER */ diff --git a/support/cpp2/diagnostic.c b/support/cpp2/diagnostic.c deleted file mode 100644 index 8dc988fd..00000000 --- a/support/cpp2/diagnostic.c +++ /dev/null @@ -1,606 +0,0 @@ -/* Language-independent diagnostic subroutines for the GNU Compiler Collection - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. - Contributed by Gabriel Dos Reis - -This file is part of GCC. - -GCC 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. - -GCC 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ - - -/* This file implements the language independent aspect of diagnostic - message module. */ - -#include "config.h" -#undef FLOAT /* This is for hpux. They should change hpux. */ -#undef FFS /* Some systems define this in param.h. */ -#include "system.h" -#include "options.h" -#include "version.h" -#include "input.h" -#include "intl.h" -#include "diagnostic.h" -#include "opts.h" - - -/* Prototypes. */ -static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; - -static void default_diagnostic_starter (diagnostic_context *, - diagnostic_info *); -static void default_diagnostic_finalizer (diagnostic_context *, - diagnostic_info *); - -static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN; -static bool diagnostic_count_diagnostic (diagnostic_context *, - diagnostic_info *); -static void diagnostic_action_after_output (diagnostic_context *, - diagnostic_info *); -static void real_abort (void) ATTRIBUTE_NORETURN; - -/* A diagnostic_context surrogate for stderr. */ -static diagnostic_context global_diagnostic_context; -diagnostic_context *global_dc = &global_diagnostic_context; - -/* Return a malloc'd string containing MSG formatted a la printf. The - caller is responsible for freeing the memory. */ -static char * -build_message_string (const char *msg, ...) -{ - char *str; - va_list ap; - - va_start (ap, msg); - vasprintf (&str, msg, ap); - va_end (ap); - - return str; -} - -/* Same as diagnostic_build_prefix, but only the source FILE is given. */ -char * -file_name_as_prefix (const char *f) -{ - return build_message_string ("%s: ", f); -} - - - -/* Initialize the diagnostic message outputting machinery. */ -void -diagnostic_initialize (diagnostic_context *context) -{ - /* Allocate a basic pretty-printer. Clients will replace this a - much more elaborated pretty-printer if they wish. */ - context->printer = xmalloc (sizeof (pretty_printer)); - pp_construct (context->printer, NULL, 0); - /* By default, diagnostics are sent to stderr. */ - context->printer->buffer->stream = stderr; - /* By default, we emit prefixes once per message. */ - context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE; - - memset (context->diagnostic_count, 0, sizeof context->diagnostic_count); - context->issue_warnings_are_errors_message = true; - context->warning_as_error_requested = false; - context->show_option_requested = false; - context->abort_on_error = false; - context->internal_error = NULL; - diagnostic_starter (context) = default_diagnostic_starter; - diagnostic_finalizer (context) = default_diagnostic_finalizer; - context->last_module = 0; - context->last_function = NULL; - context->lock = 0; -} - -/* Initialize DIAGNOSTIC, where the message MSG has already been - translated. */ -void -diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg, - va_list *args, location_t location, - diagnostic_t kind) -{ - diagnostic->message.err_no = errno; - diagnostic->message.args_ptr = args; - diagnostic->message.format_spec = msg; - diagnostic->location = location; - diagnostic->kind = kind; - diagnostic->option_index = 0; -} - -/* Initialize DIAGNOSTIC, where the message GMSGID has not yet been - translated. */ -void -diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid, - va_list *args, location_t location, - diagnostic_t kind) -{ - diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind); -} - -/* Return a malloc'd string describing a location. The caller is - responsible for freeing the memory. */ -char * -diagnostic_build_prefix (diagnostic_info *diagnostic) -{ - static const char *const diagnostic_kind_text[] = { -#define DEFINE_DIAGNOSTIC_KIND(K, T) (T), -#include "diagnostic.def" -#undef DEFINE_DIAGNOSTIC_KIND - "must-not-happen" - }; - const char *text = _(diagnostic_kind_text[diagnostic->kind]); - expanded_location s = expand_location (diagnostic->location); - gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND); - - return - (s.file == NULL - ? build_message_string ("%s: %s", progname, text) -#ifdef USE_MAPPED_LOCATION - : flag_show_column && s.column != 0 - ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text) -#endif - : build_message_string ("%s:%d: %s", s.file, s.line, text)); -} - -/* Count a diagnostic. Return true if the message should be printed. */ -static bool -diagnostic_count_diagnostic (diagnostic_context *context, - diagnostic_info *diagnostic) -{ - diagnostic_t kind = diagnostic->kind; - switch (kind) - { - default: - gcc_unreachable (); - - case DK_ICE: -#ifndef ENABLE_CHECKING - /* When not checking, ICEs are converted to fatal errors when an - error has already occurred. This is counteracted by - abort_on_error. */ - if ((diagnostic_kind_count (context, DK_ERROR) > 0 - || diagnostic_kind_count (context, DK_SORRY) > 0) - && !context->abort_on_error) - { - expanded_location s = expand_location (diagnostic->location); - fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n", - s.file, s.line); - exit (FATAL_EXIT_CODE); - } -#endif - if (context->internal_error) - (*context->internal_error) (diagnostic->message.format_spec, - diagnostic->message.args_ptr); - /* Fall through. */ - - case DK_FATAL: case DK_SORRY: - case DK_ANACHRONISM: case DK_NOTE: - ++diagnostic_kind_count (context, kind); - break; - - case DK_WARNING: - if (!diagnostic_report_warnings_p ()) - return false; - - if (!context->warning_as_error_requested) - { - ++diagnostic_kind_count (context, DK_WARNING); - break; - } - else if (context->issue_warnings_are_errors_message) - { - pp_verbatim (context->printer, - "%s: warnings being treated as errors\n", progname); - context->issue_warnings_are_errors_message = false; - } - - /* And fall through. */ - case DK_ERROR: - ++diagnostic_kind_count (context, DK_ERROR); - break; - } - - return true; -} - -/* Take any action which is expected to happen after the diagnostic - is written out. This function does not always return. */ -static void -diagnostic_action_after_output (diagnostic_context *context, - diagnostic_info *diagnostic) -{ - switch (diagnostic->kind) - { - case DK_DEBUG: - case DK_NOTE: - case DK_ANACHRONISM: - case DK_WARNING: - break; - - case DK_ERROR: - case DK_SORRY: - if (context->abort_on_error) - real_abort (); - if (flag_fatal_errors) - { - fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n"); - exit (FATAL_EXIT_CODE); - } - break; - - case DK_ICE: - if (context->abort_on_error) - real_abort (); - - fnotice (stderr, "Please submit a full bug report,\n" - "with preprocessed source if appropriate.\n" - "See %s for instructions.\n", bug_report_url); - exit (FATAL_EXIT_CODE); - - case DK_FATAL: - if (context->abort_on_error) - real_abort (); - - fnotice (stderr, "compilation terminated.\n"); - exit (FATAL_EXIT_CODE); - - default: - gcc_unreachable (); - } -} - -/* Prints out, if necessary, the name of the current function - that caused an error. Called from all error and warning functions. */ -void -diagnostic_report_current_function (diagnostic_context *context) -{ - diagnostic_report_current_module (context); - lang_hooks.print_error_function (context, input_filename); -} - -void -diagnostic_report_current_module (diagnostic_context *context) -{ - struct file_stack *p; - - if (pp_needs_newline (context->printer)) - { - pp_newline (context->printer); - pp_needs_newline (context->printer) = false; - } - - p = input_file_stack; - if (p && diagnostic_last_module_changed (context)) - { - expanded_location xloc = expand_location (p->location); - pp_verbatim (context->printer, - "In file included from %s:%d", - xloc.file, xloc.line); - while ((p = p->next) != NULL) - { - xloc = expand_location (p->location); - pp_verbatim (context->printer, - ",\n from %s:%d", - xloc.file, xloc.line); - } - pp_verbatim (context->printer, ":"); - diagnostic_set_last_module (context); - pp_newline (context->printer); - } -} - -static void -default_diagnostic_starter (diagnostic_context *context, - diagnostic_info *diagnostic) -{ - diagnostic_report_current_function (context); - pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic)); -} - -static void -default_diagnostic_finalizer (diagnostic_context *context, - diagnostic_info *diagnostic ATTRIBUTE_UNUSED) -{ - pp_destroy_prefix (context->printer); -} - -/* Report a diagnostic message (an error or a warning) as specified by - DC. This function is *the* subroutine in terms of which front-ends - should implement their specific diagnostic handling modules. The - front-end independent format specifiers are exactly those described - in the documentation of output_format. */ - -void -diagnostic_report_diagnostic (diagnostic_context *context, - diagnostic_info *diagnostic) -{ - if (context->lock > 0) - { - /* If we're reporting an ICE in the middle of some other error, - try to flush out the previous error, then let this one - through. Don't do this more than once. */ - if (diagnostic->kind == DK_ICE && context->lock == 1) - pp_flush (context->printer); - else - error_recursion (context); - } - - if (diagnostic->option_index - && ! option_enabled (diagnostic->option_index)) - return; - - context->lock++; - - if (diagnostic_count_diagnostic (context, diagnostic)) - { - const char *saved_format_spec = diagnostic->message.format_spec; - - if (context->show_option_requested && diagnostic->option_index) - diagnostic->message.format_spec - = ACONCAT ((diagnostic->message.format_spec, - " [", cl_options[diagnostic->option_index].opt_text, "]", NULL)); - - diagnostic->message.locus = &diagnostic->location; - pp_format (context->printer, &diagnostic->message); - (*diagnostic_starter (context)) (context, diagnostic); - pp_output_formatted_text (context->printer); - (*diagnostic_finalizer (context)) (context, diagnostic); - pp_flush (context->printer); - diagnostic_action_after_output (context, diagnostic); - diagnostic->message.format_spec = saved_format_spec; - } - - context->lock--; -} - -/* Given a partial pathname as input, return another pathname that - shares no directory elements with the pathname of __FILE__. This - is used by fancy_abort() to print `Internal compiler error in expr.c' - instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */ - -const char * -trim_filename (const char *name) -{ - static const char this_file[] = __FILE__; - const char *p = name, *q = this_file; - - /* First skip any "../" in each filename. This allows us to give a proper - reference to a file in a subdirectory. */ - while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2])) - p += 3; - - while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2])) - q += 3; - - /* Now skip any parts the two filenames have in common. */ - while (*p == *q && *p != 0 && *q != 0) - p++, q++; - - /* Now go backwards until the previous directory separator. */ - while (p > name && !IS_DIR_SEPARATOR (p[-1])) - p--; - - return p; -} - -/* Standard error reporting routines in increasing order of severity. - All of these take arguments like printf. */ - -/* Text to be emitted verbatim to the error message stream; this - produces no prefix and disables line-wrapping. Use rarely. */ -void -verbatim (const char *gmsgid, ...) -{ - text_info text; - va_list ap; - - va_start (ap, gmsgid); - text.err_no = errno; - text.args_ptr = ≈ - text.format_spec = _(gmsgid); - text.locus = NULL; - pp_format_verbatim (global_dc->printer, &text); - pp_flush (global_dc->printer); - va_end (ap); -} - -/* An informative note. Use this for additional details on an error - message. */ -void -inform (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_NOTE); - report_diagnostic (&diagnostic); - va_end (ap); -} - -/* A warning. Use this for code which is correct according to the - relevant language specification but is likely to be buggy anyway. */ -void -warning (int opt, const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING); - diagnostic.option_index = opt; - - report_diagnostic (&diagnostic); - va_end (ap); -} - -void -warning0 (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING); - report_diagnostic (&diagnostic); - va_end (ap); -} - -/* A "pedantic" warning: issues a warning unless -pedantic-errors was - given on the command line, in which case it issues an error. Use - this for diagnostics required by the relevant language standard, - if you have chosen not to make them errors. - - Note that these diagnostics are issued independent of the setting - of the -pedantic command-line switch. To get a warning enabled - only with that switch, write "if (pedantic) pedwarn (...);" */ -void -pedwarn (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, - pedantic_error_kind ()); - report_diagnostic (&diagnostic); - va_end (ap); -} - -/* A hard error: the code is definitely ill-formed, and an object file - will not be produced. */ -void -error (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR); - report_diagnostic (&diagnostic); - va_end (ap); -} - -/* "Sorry, not implemented." Use for a language feature which is - required by the relevant specification but not implemented by GCC. - An object file will not be produced. */ -void -sorry (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY); - report_diagnostic (&diagnostic); - va_end (ap); -} - -/* An error which is severe enough that we make no attempt to - continue. Do not use this for internal consistency checks; that's - internal_error. Use of this function should be rare. */ -void -fatal_error (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL); - report_diagnostic (&diagnostic); - va_end (ap); - - gcc_unreachable (); -} - -/* An internal consistency check has failed. We make no attempt to - continue. Note that unless there is debugging value to be had from - a more specific message, or some other good reason, you should use - abort () instead of calling this function directly. */ -void -internal_error (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE); - report_diagnostic (&diagnostic); - va_end (ap); - - gcc_unreachable (); -} - -/* Special case error functions. Most are implemented in terms of the - above, or should be. */ - -/* Print a diagnostic MSGID on FILE. This is just fprintf, except it - runs its second argument through gettext. */ -void -fnotice (FILE *file, const char *cmsgid, ...) -{ - va_list ap; - - va_start (ap, cmsgid); - vfprintf (file, _(cmsgid), ap); - va_end (ap); -} - -/* Inform the user that an error occurred while trying to report some - other error. This indicates catastrophic internal inconsistencies, - so give up now. But do try to flush out the previous error. - This mustn't use internal_error, that will cause infinite recursion. */ - -static void -error_recursion (diagnostic_context *context) -{ - diagnostic_info diagnostic; - - if (context->lock < 3) - pp_flush (context->printer); - - fnotice (stderr, - "Internal compiler error: Error reporting routines re-entered.\n"); - - /* Call diagnostic_action_after_output to get the "please submit a bug - report" message. It only looks at the kind field of diagnostic_info. */ - diagnostic.kind = DK_ICE; - diagnostic_action_after_output (context, &diagnostic); - - /* Do not use gcc_unreachable here; that goes through internal_error - and therefore would cause infinite recursion. */ - real_abort (); -} - -/* Report an internal compiler error in a friendly manner. This is - the function that gets called upon use of abort() in the source - code generally, thanks to a special macro. */ - -void -fancy_abort (const char *file, int line, const char *function) -{ - internal_error ("in %s, at %s:%d", function, trim_filename (file), line); -} - -/* Really call the system 'abort'. This has to go right at the end of - this file, so that there are no functions after it that call abort - and get the system abort instead of our macro. */ -#undef abort -static void -real_abort (void) -{ - abort (); -} diff --git a/support/cpp2/diagnostic.def b/support/cpp2/diagnostic.def deleted file mode 100644 index a4013108..00000000 --- a/support/cpp2/diagnostic.def +++ /dev/null @@ -1,9 +0,0 @@ -DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error: ") -DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error: ") -DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error: ") -DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented: ") -DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning: ") -DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism: ") -DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note: ") -DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug: ") - diff --git a/support/cpp2/diagnostic.h b/support/cpp2/diagnostic.h deleted file mode 100644 index 3a3204bd..00000000 --- a/support/cpp2/diagnostic.h +++ /dev/null @@ -1,207 +0,0 @@ -/* Various declarations for language-independent diagnostics subroutines. - Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. - Contributed by Gabriel Dos Reis - -This file is part of GCC. - -GCC 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. - -GCC 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ - -#ifndef GCC_DIAGNOSTIC_H -#define GCC_DIAGNOSTIC_H - -#include "pretty-print.h" - -/* Constants used to discriminate diagnostics. */ -typedef enum -{ -#define DEFINE_DIAGNOSTIC_KIND(K, msgid) K, -#include "diagnostic.def" -#undef DEFINE_DIAGNOSTIC_KIND - DK_LAST_DIAGNOSTIC_KIND -} diagnostic_t; - -/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of - its context and its KIND (ice, error, warning, note, ...) See complete - list in diagnostic.def. */ -typedef struct -{ - text_info message; - location_t location; - /* The kind of diagnostic it is about. */ - diagnostic_t kind; - /* Which OPT_* directly controls this diagnostic. */ - int option_index; -} diagnostic_info; - -#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) - - -/* Forward declarations. */ -typedef struct diagnostic_context diagnostic_context; -typedef void (*diagnostic_starter_fn) (diagnostic_context *, - diagnostic_info *); -typedef diagnostic_starter_fn diagnostic_finalizer_fn; - -/* This data structure bundles altogether any information relevant to - the context of a diagnostic message. */ -struct diagnostic_context -{ - /* Where most of the diagnostic formatting work is done. */ - pretty_printer *printer; - - /* The number of times we have issued diagnostics. */ - int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND]; - - /* True if we should display the "warnings are being tread as error" - message, usually displayed once per compiler run. */ - bool issue_warnings_are_errors_message; - - /* True if it has been requested that warnings be treated as errors. */ - bool warning_as_error_requested; - - /* True if we should print the command line option which controls - each diagnostic, if known. */ - bool show_option_requested; - - /* True if we should raise a SIGABRT on errors. */ - bool abort_on_error; - - /* This function is called before any message is printed out. It is - responsible for preparing message prefix and such. For example, it - might say: - In file included from "/usr/local/include/curses.h:5: - from "/home/gdr/src/nifty_printer.h:56: - ... - */ - diagnostic_starter_fn begin_diagnostic; - - /* This function is called after the diagnostic message is printed. */ - diagnostic_finalizer_fn end_diagnostic; - - /* Client hook to report an internal error. */ - void (*internal_error) (const char *, va_list *); - - /* Function of last diagnostic message; more generally, function such that - if next diagnostic message is in it then we don't have to mention the - function name. */ - tree last_function; - - /* Used to detect when input_file_stack has changed since last described. */ - int last_module; - - int lock; -}; - -/* Client supplied function to announce a diagnostic. */ -#define diagnostic_starter(DC) (DC)->begin_diagnostic - -/* Client supplied function called after a diagnostic message is - displayed. */ -#define diagnostic_finalizer(DC) (DC)->end_diagnostic - -/* Extension hook for client. */ -#define diagnostic_auxiliary_data(DC) (DC)->x_data - -/* Same as pp_format_decoder. Works on 'diagnostic_context *'. */ -#define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder) - -/* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */ -#define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule) - -/* Maximum characters per line in automatic line wrapping mode. - Zero means don't wrap lines. */ -#define diagnostic_line_cutoff(DC) ((DC)->printer->wrapping.line_cutoff) - -#define diagnostic_flush_buffer(DC) pp_base_flush ((DC)->printer) - -/* True if the last function in which a diagnostic was reported is - different from the current one. */ -#define diagnostic_last_function_changed(DC) \ - ((DC)->last_function != current_function_decl) - -/* Remember the current function as being the last one in which we report - a diagnostic. */ -#define diagnostic_set_last_function(DC) \ - (DC)->last_function = current_function_decl - -/* True if the last module or file in which a diagnostic was reported is - different from the current one. */ -#define diagnostic_last_module_changed(DC) \ - ((DC)->last_module != input_file_stack_tick) - -/* Remember the current module or file as being the last one in which we - report a diagnostic. */ -#define diagnostic_set_last_module(DC) \ - (DC)->last_module = input_file_stack_tick - -/* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */ -#define diagnostic_abort_on_error(DC) \ - (DC)->abort_on_error = true - -/* This diagnostic_context is used by front-ends that directly output - diagnostic messages without going through `error', `warning', - and similar functions. */ -extern diagnostic_context *global_dc; - -/* The total count of a KIND of diagnostics emitted so far. */ -#define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)] - -/* The number of errors that have been issued so far. Ideally, these - would take a diagnostic_context as an argument. */ -#define errorcount diagnostic_kind_count (global_dc, DK_ERROR) -/* Similarly, but for warnings. */ -#define warningcount diagnostic_kind_count (global_dc, DK_WARNING) -/* Similarly, but for sorrys. */ -#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY) - -/* Returns nonzero if warnings should be emitted. */ -#define diagnostic_report_warnings_p() \ - (!inhibit_warnings \ - && !(in_system_header && !warn_system_headers)) - -#define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D) - -/* Diagnostic related functions. */ -extern void diagnostic_initialize (diagnostic_context *); -extern void diagnostic_report_current_module (diagnostic_context *); -extern void diagnostic_report_current_function (diagnostic_context *); -extern void diagnostic_report_diagnostic (diagnostic_context *, - diagnostic_info *); -#ifdef ATTRIBUTE_GCC_DIAG -extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *, - location_t, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); -extern void diagnostic_set_info_translated (diagnostic_info *, const char *, - va_list *, location_t, - diagnostic_t) - ATTRIBUTE_GCC_DIAG(2,0); -#endif -extern char *diagnostic_build_prefix (diagnostic_info *); - -/* Pure text formatting support functions. */ -extern char *file_name_as_prefix (const char *); - -/* In tree-pretty-print.c */ -extern int dump_generic_node (pretty_printer *, tree, int, int, bool); -extern void print_generic_stmt (FILE *, tree, int); -extern void print_generic_stmt_indented (FILE *, tree, int, int); -extern void print_generic_expr (FILE *, tree, int); -extern void print_generic_decl (FILE *, tree, int); - -extern void debug_generic_expr (tree); -extern void debug_generic_stmt (tree); -extern void debug_c_tree (tree); -#endif /* ! GCC_DIAGNOSTIC_H */ diff --git a/support/cpp2/input.h b/support/cpp2/input.h deleted file mode 100644 index 0ca3ccfd..00000000 --- a/support/cpp2/input.h +++ /dev/null @@ -1,101 +0,0 @@ -/* Declarations for variables relating to reading the source file. - Used by parsers, lexical analyzers, and error message routines. - Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GCC. - -GCC 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. - -GCC 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ - -#ifndef GCC_INPUT_H -#define GCC_INPUT_H - -#include "line-map.h" -extern struct line_maps line_table; - -/* The location for declarations in "" */ -#define BUILTINS_LOCATION ((source_location) 2) - -#ifdef USE_MAPPED_LOCATION - -typedef struct -{ - /* The name of the source file involved. */ - const char *file; - - /* The line-location in the source file. */ - int line; - - int column; -} expanded_location; - -extern expanded_location expand_location (source_location); - -#define UNKNOWN_LOCATION ((source_location) 0) -typedef source_location location_t; /* deprecated typedef */ -typedef source_location source_locus; /* to be removed */ - -#else /* ! USE_MAPPED_LOCATION */ - -struct location_s GTY(()) -{ - /* The name of the source file involved. */ - const char *file; - - /* The line-location in the source file. */ - int line; -}; - -typedef struct location_s expanded_location; -typedef struct location_s location_t; -typedef location_t *source_locus; - -#define expand_location(FILELINE) (FILELINE) -extern location_t unknown_location; -#define UNKNOWN_LOCATION unknown_location - -#endif /* ! USE_MAPPED_LOCATION */ - -struct file_stack -{ - struct file_stack *next; - location_t location; -}; - -/* Top-level source file. */ -extern const char *main_input_filename; - -extern location_t input_location; -#ifdef USE_MAPPED_LOCATION -extern void push_srcloc (location_t); -#else /* ! USE_MAPPED_LOCATION */ -extern void push_srcloc (const char *name, int line); -#endif /* ! USE_MAPPED_LOCATION */ -extern void pop_srcloc (void); - -#define LOCATION_FILE(LOC) ((expand_location (LOC)).file) -#define LOCATION_LINE(LOC) ((expand_location (LOC)).line) - -#define input_line LOCATION_LINE(input_location) -#define input_filename LOCATION_FILE(input_location) - -/* Stack of currently pending input files. - The line member is not accurate for the innermost file on the stack. */ -extern struct file_stack *input_file_stack; - -/* Incremented on each change to input_file_stack. */ -extern int input_file_stack_tick; - -#endif diff --git a/support/cpp2/opts.c b/support/cpp2/opts.c index 20e8cb95..3d11d851 100644 --- a/support/cpp2/opts.c +++ b/support/cpp2/opts.c @@ -24,7 +24,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "intl.h" #include "opts.h" #include "options.h" -#include "diagnostic.h" /* True if we should exit after parsing options. */ bool exit_after_options; @@ -250,7 +249,7 @@ handle_option (const char **argv, unsigned int lang_mask) /* Check to see if the option is disabled for this configuration. */ if (option->flags & CL_DISABLED) { - error ("command line option %qs" + error ("command line option \"%s\"" " is not supported by this configuration", opt); goto done; } @@ -407,8 +406,6 @@ decode_options (unsigned int argc, const char **argv) /* Perform language-specific options initialization. */ lang_mask = lang_hooks.init_options (argc, argv); - lang_hooks.initialize_diagnostics (global_dc); - /* Scan to see what optimization level has been specified. That will determine the default value of many flags. */ diff --git a/support/cpp2/pretty-print.c b/support/cpp2/pretty-print.c deleted file mode 100644 index ca8d7a91..00000000 --- a/support/cpp2/pretty-print.c +++ /dev/null @@ -1,815 +0,0 @@ -/* Various declarations for language-independent pretty-print subroutines. - Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. - Contributed by Gabriel Dos Reis - -This file is part of GCC. - -GCC 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. - -GCC 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ - -#include "config.h" -#undef FLOAT /* This is for hpux. They should change hpux. */ -#undef FFS /* Some systems define this in param.h. */ -#include "system.h" -#include "intl.h" -#include "pretty-print.h" - -#define obstack_chunk_alloc xmalloc -#define obstack_chunk_free free - -/* A pointer to the formatted diagnostic message. */ -#define pp_formatted_text_data(PP) \ - ((const char *) obstack_base (pp_base (PP)->buffer->obstack)) - -/* Format an integer given by va_arg (ARG, type-specifier T) where - type-specifier is a precision modifier as indicated by PREC. F is - a string used to construct the appropriate format-specifier. */ -#define pp_integer_with_precision(PP, ARG, PREC, T, F) \ - do \ - switch (PREC) \ - { \ - case 0: \ - pp_scalar (PP, "%" F, va_arg (ARG, T)); \ - break; \ - \ - case 1: \ - pp_scalar (PP, "%l" F, va_arg (ARG, long T)); \ - break; \ - \ - case 2: \ - pp_scalar (PP, "%" PRINTF_INT64_MODIFIER F, va_arg (ARG, long_long)); \ - break; \ - \ - default: \ - break; \ - } \ - while (0) - - -/* Subroutine of pp_set_maximum_length. Set up PRETTY-PRINTER's - internal maximum characters per line. */ -static void -pp_set_real_maximum_length (pretty_printer *pp) -{ - /* If we're told not to wrap lines then do the obvious thing. In case - we'll emit prefix only once per message, it is appropriate - not to increase unnecessarily the line-length cut-off. */ - if (!pp_is_wrapping_line (pp) - || pp_prefixing_rule (pp) == DIAGNOSTICS_SHOW_PREFIX_ONCE - || pp_prefixing_rule (pp) == DIAGNOSTICS_SHOW_PREFIX_NEVER) - pp->maximum_length = pp_line_cutoff (pp); - else - { - int prefix_length = pp->prefix ? strlen (pp->prefix) : 0; - /* If the prefix is ridiculously too long, output at least - 32 characters. */ - if (pp_line_cutoff (pp) - prefix_length < 32) - pp->maximum_length = pp_line_cutoff (pp) + 32; - else - pp->maximum_length = pp_line_cutoff (pp); - } -} - -/* Clear PRETTY-PRINTER's output state. */ -static inline void -pp_clear_state (pretty_printer *pp) -{ - pp->emitted_prefix = false; - pp_indentation (pp) = 0; -} - -/* Flush the formatted text of PRETTY-PRINTER onto the attached stream. */ -void -pp_write_text_to_stream (pretty_printer *pp) -{ - const char *text = pp_formatted_text (pp); - fputs (text, pp->buffer->stream); - pp_clear_output_area (pp); -} - -/* Wrap a text delimited by START and END into PRETTY-PRINTER. */ -static void -pp_wrap_text (pretty_printer *pp, const char *start, const char *end) -{ - bool wrapping_line = pp_is_wrapping_line (pp); - - while (start != end) - { - /* Dump anything bordered by whitespaces. */ - { - const char *p = start; - while (p != end && !ISBLANK (*p) && *p != '\n') - ++p; - if (wrapping_line - && p - start >= pp_remaining_character_count_for_line (pp)) - pp_newline (pp); - pp_append_text (pp, start, p); - start = p; - } - - if (start != end && ISBLANK (*start)) - { - pp_space (pp); - ++start; - } - if (start != end && *start == '\n') - { - pp_newline (pp); - ++start; - } - } -} - -/* Same as pp_wrap_text but wrap text only when in line-wrapping mode. */ -static inline void -pp_maybe_wrap_text (pretty_printer *pp, const char *start, const char *end) -{ - if (pp_is_wrapping_line (pp)) - pp_wrap_text (pp, start, end); - else - pp_append_text (pp, start, end); -} - -/* Append to the output area of PRETTY-PRINTER a string specified by its - STARTing character and LENGTH. */ -static inline void -pp_append_r (pretty_printer *pp, const char *start, int length) -{ - obstack_grow (pp->buffer->obstack, start, length); - pp->buffer->line_length += length; -} - -/* Insert enough spaces into the output area of PRETTY-PRINTER to bring - the column position to the current indentation level, assuming that a - newline has just been written to the buffer. */ -void -pp_base_indent (pretty_printer *pp) -{ - int n = pp_indentation (pp); - int i; - - for (i = 0; i < n; ++i) - pp_space (pp); -} - -/* The following format specifiers are recognized as being client independent: - %d, %i: (signed) integer in base ten. - %u: unsigned integer in base ten. - %o: unsigned integer in base eight. - %x: unsigned integer in base sixteen. - %ld, %li, %lo, %lu, %lx: long versions of the above. - %lld, %lli, %llo, %llu, %llx: long long versions. - %wd, %wi, %wo, %wu, %wx: HOST_WIDE_INT versions. - %c: character. - %s: string. - %p: pointer. - %m: strerror(text->err_no) - does not consume a value from args_ptr. - %%: '%'. - %<: opening quote. - %>: closing quote. - %': apostrophe (should only be used in untranslated messages; - translations should use appropriate punctuation directly). - %.*s: a substring the length of which is specified by an argument - integer. - %Ns: likewise, but length specified as constant in the format string. - %H: location_t. - %J: a decl tree, from which DECL_SOURCE_LOCATION will be recorded. - Flag 'q': quote formatted text (must come immediately after '%'). - - Arguments can be used sequentially, or through %N$ resp. *N$ - notation Nth argument after the format string. If %N$ / *N$ - notation is used, it must be used for all arguments, except %m, %%, - %<, %> and %', which may not have a number, as they do not consume - an argument. When %M$.*N$s is used, M must be N + 1. (This may - also be written %M$.*s, provided N is not otherwise used.) The - format string must have conversion specifiers with argument numbers - 1 up to highest argument; each argument may only be used once. - A format string can have at most 30 arguments. */ - -/* Formatting phases 1 and 2: render TEXT->format_spec plus - TEXT->args_ptr into a series of chunks in PP->buffer->args[]. - Phase 3 is in pp_base_format_text. */ - -void -pp_base_format (pretty_printer *pp, text_info *text) -{ - output_buffer *buffer = pp->buffer; - const char *p; - const char **args; - struct chunk_info *new_chunk_array; - - unsigned int curarg = 0, chunk = 0, argno; - pp_wrapping_mode_t old_wrapping_mode; - bool any_unnumbered = false, any_numbered = false; - const char **formatters[PP_NL_ARGMAX]; - - /* Allocate a new chunk structure. */ - new_chunk_array = XOBNEW (&buffer->chunk_obstack, struct chunk_info); - new_chunk_array->prev = buffer->cur_chunk_array; - buffer->cur_chunk_array = new_chunk_array; - args = new_chunk_array->args; - - /* Formatting phase 1: split up TEXT->format_spec into chunks in - PP->buffer->args[]. Even-numbered chunks are to be output - verbatim, odd-numbered chunks are format specifiers. - %m, %%, %<, %>, and %' are replaced with the appropriate text at - this point. */ - - memset (formatters, 0, sizeof formatters); - - for (p = text->format_spec; *p; ) - { - while (*p != '\0' && *p != '%') - { - obstack_1grow (&buffer->chunk_obstack, *p); - p++; - } - - if (*p == '\0') - break; - - switch (*++p) - { - case '\0': - gcc_unreachable (); - - case '%': - obstack_1grow (&buffer->chunk_obstack, '%'); - p++; - continue; - - case '<': - obstack_grow (&buffer->chunk_obstack, - open_quote, strlen (open_quote)); - p++; - continue; - - case '>': - case '\'': - obstack_grow (&buffer->chunk_obstack, - close_quote, strlen (close_quote)); - p++; - continue; - - case 'm': - { - const char *errstr = xstrerror (text->err_no); - obstack_grow (&buffer->chunk_obstack, errstr, strlen (errstr)); - } - p++; - continue; - - default: - /* Handled in phase 2. Terminate the plain chunk here. */ - obstack_1grow (&buffer->chunk_obstack, '\0'); - gcc_assert (chunk < PP_NL_ARGMAX * 2); - args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *); - break; - } - - if (ISDIGIT (*p)) - { - char *end; - argno = strtoul (p, &end, 10) - 1; - p = end; - gcc_assert (*p == '$'); - p++; - - any_numbered = true; - gcc_assert (!any_unnumbered); - } - else - { - argno = curarg++; - any_unnumbered = true; - gcc_assert (!any_numbered); - } - gcc_assert (argno < PP_NL_ARGMAX); - gcc_assert (!formatters[argno]); - formatters[argno] = &args[chunk]; - do - { - obstack_1grow (&buffer->chunk_obstack, *p); - p++; - } - while (strchr ("qwl+#", p[-1])); - - if (p[-1] == '.') - { - /* We handle '%.Ns' and '%.*s' or '%M$.*N$s' - (where M == N + 1). */ - if (ISDIGIT (*p)) - { - do - { - obstack_1grow (&buffer->chunk_obstack, *p); - p++; - } - while (ISDIGIT (p[-1])); - gcc_assert (p[-1] == 's'); - } - else - { - gcc_assert (*p == '*'); - obstack_1grow (&buffer->chunk_obstack, '*'); - p++; - - if (ISDIGIT (*p)) - { - char *end; - unsigned int argno2 = strtoul (p, &end, 10) - 1; - p = end; - gcc_assert (argno2 == argno - 1); - gcc_assert (!any_unnumbered); - gcc_assert (*p == '$'); - - p++; - formatters[argno2] = formatters[argno]; - } - else - { - gcc_assert (!any_numbered); - formatters[argno+1] = formatters[argno]; - curarg++; - } - gcc_assert (*p == 's'); - obstack_1grow (&buffer->chunk_obstack, 's'); - p++; - } - } - if (*p == '\0') - break; - - obstack_1grow (&buffer->chunk_obstack, '\0'); - gcc_assert (chunk < PP_NL_ARGMAX * 2); - args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *); - } - - obstack_1grow (&buffer->chunk_obstack, '\0'); - gcc_assert (chunk < PP_NL_ARGMAX * 2); - args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *); - args[chunk] = 0; - - /* Set output to the argument obstack, and switch line-wrapping and - prefixing off. */ - buffer->obstack = &buffer->chunk_obstack; - old_wrapping_mode = pp_set_verbatim_wrapping (pp); - - /* Second phase. Replace each formatter with the formatted text it - corresponds to. */ - - for (argno = 0; formatters[argno]; argno++) - { - int precision = 0; - bool wide = false; - bool plus = false; - bool hash = false; - bool quote = false; - - /* We do not attempt to enforce any ordering on the modifier - characters. */ - - for (p = *formatters[argno];; p++) - { - switch (*p) - { - case 'q': - gcc_assert (!quote); - quote = true; - continue; - - case '+': - gcc_assert (!plus); - plus = true; - continue; - - case '#': - gcc_assert (!hash); - hash = true; - continue; - - case 'w': - gcc_assert (!wide); - wide = true; - continue; - - case 'l': - /* We don't support precision beyond that of "long long". */ - gcc_assert (precision < 2); - precision++; - continue; - } - break; - } - - gcc_assert (!wide || precision == 0); - - if (quote) - pp_string (pp, open_quote); - - switch (*p) - { - case 'c': - pp_character (pp, va_arg (*text->args_ptr, int)); - break; - - case 'd': - case 'i': - if (wide) - pp_wide_integer (pp, va_arg (*text->args_ptr, HOST_WIDE_INT)); - else - pp_integer_with_precision - (pp, *text->args_ptr, precision, int, "d"); - break; - - case 'o': - if (wide) - pp_scalar (pp, "%" HOST_WIDE_INT_PRINT "o", - va_arg (*text->args_ptr, unsigned HOST_WIDE_INT)); - else - pp_integer_with_precision - (pp, *text->args_ptr, precision, unsigned, "o"); - break; - - case 's': - pp_string (pp, va_arg (*text->args_ptr, const char *)); - break; - - case 'p': - pp_pointer (pp, va_arg (*text->args_ptr, void *)); - break; - - case 'u': - if (wide) - pp_scalar (pp, HOST_WIDE_INT_PRINT_UNSIGNED, - va_arg (*text->args_ptr, unsigned HOST_WIDE_INT)); - else - pp_integer_with_precision - (pp, *text->args_ptr, precision, unsigned, "u"); - break; - - case 'x': - if (wide) - pp_scalar (pp, HOST_WIDE_INT_PRINT_HEX, - va_arg (*text->args_ptr, unsigned HOST_WIDE_INT)); - else - pp_integer_with_precision - (pp, *text->args_ptr, precision, unsigned, "x"); - break; - - case 'H': - { - location_t *locus = va_arg (*text->args_ptr, location_t *); - gcc_assert (text->locus != NULL); - *text->locus = *locus; - } - break; - - case 'J': - { - tree t = va_arg (*text->args_ptr, tree); - gcc_assert (text->locus != NULL); - *text->locus = DECL_SOURCE_LOCATION (t); - } - break; - - case '.': - { - int n; - const char *s; - - /* We handle '%.Ns' and '%.*s' or '%M$.*N$s' - (where M == N + 1). The format string should be verified - already from the first phase. */ - p++; - if (ISDIGIT (*p)) - { - char *end; - n = strtoul (p, &end, 10); - p = end; - gcc_assert (*p == 's'); - } - else - { - gcc_assert (*p == '*'); - p++; - gcc_assert (*p == 's'); - n = va_arg (*text->args_ptr, int); - - /* This consumes a second entry in the formatters array. */ - gcc_assert (formatters[argno] == formatters[argno+1]); - argno++; - } - - s = va_arg (*text->args_ptr, const char *); - pp_append_text (pp, s, s + n); - } - break; - - default: - { - bool ok; - - gcc_assert (pp_format_decoder (pp)); - ok = pp_format_decoder (pp) (pp, text, p, - precision, wide, plus, hash); - gcc_assert (ok); - } - } - - if (quote) - pp_string (pp, close_quote); - - obstack_1grow (&buffer->chunk_obstack, '\0'); - *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *); - } - -#ifdef ENABLE_CHECKING - for (; argno < PP_NL_ARGMAX; argno++) - gcc_assert (!formatters[argno]); -#endif - - /* Revert to normal obstack and wrapping mode. */ - buffer->obstack = &buffer->formatted_obstack; - buffer->line_length = 0; - pp_wrapping_mode (pp) = old_wrapping_mode; - pp_clear_state (pp); -} - -/* Format of a message pointed to by TEXT. */ -void -pp_base_output_formatted_text (pretty_printer *pp) -{ - unsigned int chunk; - output_buffer *buffer = pp_buffer (pp); - struct chunk_info *chunk_array = buffer->cur_chunk_array; - const char **args = chunk_array->args; - - gcc_assert (buffer->obstack == &buffer->formatted_obstack); - gcc_assert (buffer->line_length == 0); - - /* This is a third phase, first 2 phases done in pp_base_format_args. - Now we actually print it. */ - for (chunk = 0; args[chunk]; chunk++) - pp_string (pp, args[chunk]); - - /* Deallocate the chunk structure and everything after it (i.e. the - associated series of formatted strings). */ - buffer->cur_chunk_array = chunk_array->prev; - obstack_free (&buffer->chunk_obstack, chunk_array); -} - -/* Helper subroutine of output_verbatim and verbatim. Do the appropriate - settings needed by BUFFER for a verbatim formatting. */ -void -pp_base_format_verbatim (pretty_printer *pp, text_info *text) -{ - /* Set verbatim mode. */ - pp_wrapping_mode_t oldmode = pp_set_verbatim_wrapping (pp); - - /* Do the actual formatting. */ - pp_format (pp, text); - pp_output_formatted_text (pp); - - /* Restore previous settings. */ - pp_wrapping_mode (pp) = oldmode; -} - -/* Flush the content of BUFFER onto the attached stream. */ -void -pp_base_flush (pretty_printer *pp) -{ - pp_write_text_to_stream (pp); - pp_clear_state (pp); - fputc ('\n', pp->buffer->stream); - fflush (pp->buffer->stream); - pp_needs_newline (pp) = false; -} - -/* Sets the number of maximum characters per line PRETTY-PRINTER can - output in line-wrapping mode. A LENGTH value 0 suppresses - line-wrapping. */ -void -pp_base_set_line_maximum_length (pretty_printer *pp, int length) -{ - pp_line_cutoff (pp) = length; - pp_set_real_maximum_length (pp); -} - -/* Clear PRETTY-PRINTER output area text info. */ -void -pp_base_clear_output_area (pretty_printer *pp) -{ - obstack_free (pp->buffer->obstack, obstack_base (pp->buffer->obstack)); - pp->buffer->line_length = 0; -} - -/* Set PREFIX for PRETTY-PRINTER. */ -void -pp_base_set_prefix (pretty_printer *pp, const char *prefix) -{ - pp->prefix = prefix; - pp_set_real_maximum_length (pp); - pp->emitted_prefix = false; - pp_indentation (pp) = 0; -} - -/* Free PRETTY-PRINTER's prefix, a previously malloc()'d string. */ -void -pp_base_destroy_prefix (pretty_printer *pp) -{ - if (pp->prefix != NULL) - { - free ((char *) pp->prefix); - pp->prefix = NULL; - } -} - -/* Write out PRETTY-PRINTER's prefix. */ -void -pp_base_emit_prefix (pretty_printer *pp) -{ - if (pp->prefix != NULL) - { - switch (pp_prefixing_rule (pp)) - { - default: - case DIAGNOSTICS_SHOW_PREFIX_NEVER: - break; - - case DIAGNOSTICS_SHOW_PREFIX_ONCE: - if (pp->emitted_prefix) - { - pp_base_indent (pp); - break; - } - pp_indentation (pp) += 3; - /* Fall through. */ - - case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: - { - int prefix_length = strlen (pp->prefix); - pp_append_r (pp, pp->prefix, prefix_length); - pp->emitted_prefix = true; - } - break; - } - } -} - -/* Construct a PRETTY-PRINTER with PREFIX and of MAXIMUM_LENGTH - characters per line. */ -void -pp_construct (pretty_printer *pp, const char *prefix, int maximum_length) -{ - memset (pp, 0, sizeof (pretty_printer)); - pp->buffer = xcalloc (1, sizeof (output_buffer)); - obstack_init (&pp->buffer->chunk_obstack); - obstack_init (&pp->buffer->formatted_obstack); - pp->buffer->obstack = &pp->buffer->formatted_obstack; - pp->buffer->stream = stderr; - pp_line_cutoff (pp) = maximum_length; - pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_ONCE; - pp_set_prefix (pp, prefix); -} - -/* Append a string delimited by START and END to the output area of - PRETTY-PRINTER. No line wrapping is done. However, if beginning a - new line then emit PRETTY-PRINTER's prefix and skip any leading - whitespace if appropriate. The caller must ensure that it is - safe to do so. */ -void -pp_base_append_text (pretty_printer *pp, const char *start, const char *end) -{ - /* Emit prefix and skip whitespace if we're starting a new line. */ - if (pp->buffer->line_length == 0) - { - pp_emit_prefix (pp); - if (pp_is_wrapping_line (pp)) - while (start != end && *start == ' ') - ++start; - } - pp_append_r (pp, start, end - start); -} - -/* Finishes constructing a NULL-terminated character string representing - the PRETTY-PRINTED text. */ -const char * -pp_base_formatted_text (pretty_printer *pp) -{ - obstack_1grow (pp->buffer->obstack, '\0'); - return pp_formatted_text_data (pp); -} - -/* Return a pointer to the last character emitted in PRETTY-PRINTER's - output area. A NULL pointer means no character available. */ -const char * -pp_base_last_position_in_text (const pretty_printer *pp) -{ - const char *p = NULL; - struct obstack *text = pp->buffer->obstack; - - if (obstack_base (text) != obstack_next_free (text)) - p = ((const char *) obstack_next_free (text)) - 1; - return p; -} - -/* Return the amount of characters PRETTY-PRINTER can accept to - make a full line. Meaningful only in line-wrapping mode. */ -int -pp_base_remaining_character_count_for_line (pretty_printer *pp) -{ - return pp->maximum_length - pp->buffer->line_length; -} - - -/* Format a message into BUFFER a la printf. */ -void -pp_printf (pretty_printer *pp, const char *msg, ...) -{ - text_info text; - va_list ap; - - va_start (ap, msg); - text.err_no = errno; - text.args_ptr = ≈ - text.format_spec = msg; - text.locus = NULL; - pp_format (pp, &text); - pp_output_formatted_text (pp); - va_end (ap); -} - - -/* Output MESSAGE verbatim into BUFFER. */ -void -pp_verbatim (pretty_printer *pp, const char *msg, ...) -{ - text_info text; - va_list ap; - - va_start (ap, msg); - text.err_no = errno; - text.args_ptr = ≈ - text.format_spec = msg; - text.locus = NULL; - pp_format_verbatim (pp, &text); - va_end (ap); -} - - - -/* Have PRETTY-PRINTER start a new line. */ -void -pp_base_newline (pretty_printer *pp) -{ - obstack_1grow (pp->buffer->obstack, '\n'); - pp->buffer->line_length = 0; -} - -/* Have PRETTY-PRINTER add a CHARACTER. */ -void -pp_base_character (pretty_printer *pp, int c) -{ - if (pp_is_wrapping_line (pp) - && pp_remaining_character_count_for_line (pp) <= 0) - { - pp_newline (pp); - if (ISSPACE (c)) - return; - } - obstack_1grow (pp->buffer->obstack, c); - ++pp->buffer->line_length; -} - -/* Append a STRING to the output area of PRETTY-PRINTER; the STRING may - be line-wrapped if in appropriate mode. */ -void -pp_base_string (pretty_printer *pp, const char *str) -{ - pp_maybe_wrap_text (pp, str, str + (str ? strlen (str) : 0)); -} - -/* Maybe print out a whitespace if needed. */ - -void -pp_base_maybe_space (pretty_printer *pp) -{ - if (pp_base (pp)->padding != pp_none) - { - pp_space (pp); - pp_base (pp)->padding = pp_none; - } -} diff --git a/support/cpp2/pretty-print.h b/support/cpp2/pretty-print.h deleted file mode 100644 index b2c6772b..00000000 --- a/support/cpp2/pretty-print.h +++ /dev/null @@ -1,337 +0,0 @@ -/* Various declarations for language-independent pretty-print subroutines. - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. - Contributed by Gabriel Dos Reis - -This file is part of GCC. - -GCC 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. - -GCC 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ - -#ifndef GCC_PRETTY_PRINT_H -#define GCC_PRETTY_PRINT_H - -#include "obstack.h" -#include "input.h" - -/* Maximum number of format string arguments. */ -#define PP_NL_ARGMAX 30 - -/* The type of a text to be formatted according a format specification - along with a list of things. */ -typedef struct -{ - const char *format_spec; - va_list *args_ptr; - int err_no; /* for %m */ - location_t *locus; -} text_info; - -/* How often diagnostics are prefixed by their locations: - o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported; - o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once; - o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical - line is started. */ -typedef enum -{ - DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0, - DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1, - DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2 -} diagnostic_prefixing_rule_t; - -/* The chunk_info data structure forms a stack of the results from the - first phase of formatting (pp_base_format) which have not yet been - output (pp_base_output_formatted_text). A stack is necessary because - the diagnostic starter may decide to generate its own output by way - of the formatter. */ -struct chunk_info -{ - /* Pointer to previous chunk on the stack. */ - struct chunk_info *prev; - - /* Array of chunks to output. Each chunk is a NUL-terminated string. - In the first phase of formatting, even-numbered chunks are - to be output verbatim, odd-numbered chunks are format specifiers. - The second phase replaces all odd-numbered chunks with formatted - text, and the third phase simply emits all the chunks in sequence - with appropriate line-wrapping. */ - const char *args[PP_NL_ARGMAX * 2]; -}; - -/* The output buffer datatype. This is best seen as an abstract datatype - whose fields should not be accessed directly by clients. */ -typedef struct -{ - /* Obstack where the text is built up. */ - struct obstack formatted_obstack; - - /* Obstack containing a chunked representation of the format - specification plus arguments. */ - struct obstack chunk_obstack; - - /* Currently active obstack: one of the above two. This is used so - that the text formatters don't need to know which phase we're in. */ - struct obstack *obstack; - - /* Stack of chunk arrays. These come from the chunk_obstack. */ - struct chunk_info *cur_chunk_array; - - /* Where to output formatted text. */ - FILE *stream; - - /* The amount of characters output so far. */ - int line_length; - - /* This must be large enough to hold any printed integer or - floating-point value. */ - char digit_buffer[128]; -} output_buffer; - -/* The type of pretty-printer flags passed to clients. */ -typedef unsigned int pp_flags; - -typedef enum -{ - pp_none, pp_before, pp_after -} pp_padding; - -/* Structure for switching in and out of verbatim mode in a convenient - manner. */ -typedef struct -{ - /* Current prefixing rule. */ - diagnostic_prefixing_rule_t rule; - - /* The ideal upper bound of number of characters per line, as suggested - by front-end. */ - int line_cutoff; -} pp_wrapping_mode_t; - -/* Maximum characters per line in automatic line wrapping mode. - Zero means don't wrap lines. */ -#define pp_line_cutoff(PP) pp_base (PP)->wrapping.line_cutoff - -/* Prefixing rule used in formatting a diagnostic message. */ -#define pp_prefixing_rule(PP) pp_base (PP)->wrapping.rule - -/* Get or set the wrapping mode as a single entity. */ -#define pp_wrapping_mode(PP) pp_base (PP)->wrapping - -/* The type of a hook that formats client-specific data onto a pretty_pinter. - A client-supplied formatter returns true if everything goes well, - otherwise it returns false. */ -typedef struct pretty_print_info pretty_printer; -typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *, - int, bool, bool, bool); - -/* Client supplied function used to decode formats. */ -#define pp_format_decoder(PP) pp_base (PP)->format_decoder - -/* TRUE if a newline character needs to be added before further - formatting. */ -#define pp_needs_newline(PP) pp_base (PP)->need_newline - -/* True if PRETTY-PTINTER is in line-wrapping mode. */ -#define pp_is_wrapping_line(PP) (pp_line_cutoff (PP) > 0) - -/* The amount of whitespace to be emitted when starting a new line. */ -#define pp_indentation(PP) pp_base (PP)->indent_skip - -/* The data structure that contains the bare minimum required to do - proper pretty-printing. Clients may derived from this structure - and add additional fields they need. */ -struct pretty_print_info -{ - /* Where we print external representation of ENTITY. */ - output_buffer *buffer; - - /* The prefix for each new line. */ - const char *prefix; - - /* Where to put whitespace around the entity being formatted. */ - pp_padding padding; - - /* The real upper bound of number of characters per line, taking into - account the case of a very very looong prefix. */ - int maximum_length; - - /* Indentation count. */ - int indent_skip; - - /* Current wrapping mode. */ - pp_wrapping_mode_t wrapping; - - /* If non-NULL, this function formats a TEXT into the BUFFER. When called, - TEXT->format_spec points to a format code. FORMAT_DECODER should call - pp_string (and related functions) to add data to the BUFFER. - FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG. - If the BUFFER needs additional characters from the format string, it - should advance the TEXT->format_spec as it goes. When FORMAT_DECODER - returns, TEXT->format_spec should point to the last character processed. - */ - printer_fn format_decoder; - - /* Nonzero if current PREFIX was emitted at least once. */ - bool emitted_prefix; - - /* Nonzero means one should emit a newline before outputting anything. */ - bool need_newline; -}; - -#define pp_set_line_maximum_length(PP, L) \ - pp_base_set_line_maximum_length (pp_base (PP), L) -#define pp_set_prefix(PP, P) pp_base_set_prefix (pp_base (PP), P) -#define pp_destroy_prefix(PP) pp_base_destroy_prefix (pp_base (PP)) -#define pp_remaining_character_count_for_line(PP) \ - pp_base_remaining_character_count_for_line (pp_base (PP)) -#define pp_clear_output_area(PP) \ - pp_base_clear_output_area (pp_base (PP)) -#define pp_formatted_text(PP) pp_base_formatted_text (pp_base (PP)) -#define pp_last_position_in_text(PP) \ - pp_base_last_position_in_text (pp_base (PP)) -#define pp_emit_prefix(PP) pp_base_emit_prefix (pp_base (PP)) -#define pp_append_text(PP, B, E) \ - pp_base_append_text (pp_base (PP), B, E) -#define pp_flush(PP) pp_base_flush (pp_base (PP)) -#define pp_format(PP, TI) pp_base_format (pp_base (PP), TI) -#define pp_output_formatted_text(PP) \ - pp_base_output_formatted_text (pp_base (PP)) -#define pp_format_verbatim(PP, TI) \ - pp_base_format_verbatim (pp_base (PP), TI) - -#define pp_character(PP, C) pp_base_character (pp_base (PP), C) -#define pp_string(PP, S) pp_base_string (pp_base (PP), S) -#define pp_newline(PP) pp_base_newline (pp_base (PP)) - -#define pp_space(PP) pp_character (PP, ' ') -#define pp_left_paren(PP) pp_character (PP, '(') -#define pp_right_paren(PP) pp_character (PP, ')') -#define pp_left_bracket(PP) pp_character (PP, '[') -#define pp_right_bracket(PP) pp_character (PP, ']') -#define pp_left_brace(PP) pp_character (PP, '{') -#define pp_right_brace(PP) pp_character (PP, '}') -#define pp_semicolon(PP) pp_character (PP, ';') -#define pp_comma(PP) pp_string (PP, ", ") -#define pp_dot(PP) pp_character (PP, '.') -#define pp_colon(PP) pp_character (PP, ':') -#define pp_colon_colon(PP) pp_string (PP, "::") -#define pp_arrow(PP) pp_string (PP, "->") -#define pp_equal(PP) pp_character (PP, '=') -#define pp_question(PP) pp_character (PP, '?') -#define pp_bar(PP) pp_character (PP, '|') -#define pp_carret(PP) pp_character (PP, '^') -#define pp_ampersand(PP) pp_character (PP, '&') -#define pp_less(PP) pp_character (PP, '<') -#define pp_greater(PP) pp_character (PP, '>') -#define pp_plus(PP) pp_character (PP, '+') -#define pp_minus(PP) pp_character (PP, '-') -#define pp_star(PP) pp_character (PP, '*') -#define pp_slash(PP) pp_character (PP, '/') -#define pp_modulo(PP) pp_character (PP, '%') -#define pp_exclamation(PP) pp_character (PP, '!') -#define pp_complement(PP) pp_character (PP, '~') -#define pp_quote(PP) pp_character (PP, '\'') -#define pp_backquote(PP) pp_character (PP, '`') -#define pp_doublequote(PP) pp_character (PP, '"') -#define pp_newline_and_indent(PP, N) \ - do { \ - pp_indentation (PP) += N; \ - pp_newline (PP); \ - pp_base_indent (pp_base (PP)); \ - pp_needs_newline (PP) = false; \ - } while (0) -#define pp_maybe_newline_and_indent(PP, N) \ - if (pp_needs_newline (PP)) pp_newline_and_indent (PP, N) -#define pp_maybe_space(PP) pp_base_maybe_space (pp_base (PP)) -#define pp_separate_with(PP, C) \ - do { \ - pp_character (PP, C); \ - pp_space (PP); \ - } while (0) -#define pp_scalar(PP, FORMAT, SCALAR) \ - do \ - { \ - sprintf (pp_buffer (PP)->digit_buffer, FORMAT, SCALAR); \ - pp_string (PP, pp_buffer (PP)->digit_buffer); \ - } \ - while (0) -#define pp_decimal_int(PP, I) pp_scalar (PP, "%d", I) -#define pp_wide_integer(PP, I) \ - pp_scalar (PP, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) I) -#define pp_widest_integer(PP, I) \ - pp_scalar (PP, HOST_WIDEST_INT_PRINT_DEC, (HOST_WIDEST_INT) I) -#define pp_pointer(PP, P) pp_scalar (PP, "%p", P) - -#define pp_identifier(PP, ID) pp_string (PP, ID) -#define pp_tree_identifier(PP, T) \ - pp_append_text(PP, IDENTIFIER_POINTER (T), \ - IDENTIFIER_POINTER (T) + IDENTIFIER_LENGTH (T)) - -#define pp_unsupported_tree(PP, T) \ - pp_verbatim (pp_base (PP), "#%qs not supported by %s#", \ - tree_code_name[(int) TREE_CODE (T)], __FUNCTION__) - - -#define pp_buffer(PP) pp_base (PP)->buffer -/* Clients that directly derive from pretty_printer need to override - this macro to return a pointer to the base pretty_printer structure. */ -#define pp_base(PP) (PP) - -extern void pp_construct (pretty_printer *, const char *, int); -extern void pp_base_set_line_maximum_length (pretty_printer *, int); -extern void pp_base_set_prefix (pretty_printer *, const char *); -extern void pp_base_destroy_prefix (pretty_printer *); -extern int pp_base_remaining_character_count_for_line (pretty_printer *); -extern void pp_base_clear_output_area (pretty_printer *); -extern const char *pp_base_formatted_text (pretty_printer *); -extern const char *pp_base_last_position_in_text (const pretty_printer *); -extern void pp_base_emit_prefix (pretty_printer *); -extern void pp_base_append_text (pretty_printer *, const char *, const char *); - -/* This header may be included before toplev.h, hence the duplicate - definitions to allow for GCC-specific formats. */ -#if GCC_VERSION >= 3005 -#define ATTRIBUTE_GCC_PPDIAG(m, n) __attribute__ ((__format__ (__gcc_diag__, m ,n))) ATTRIBUTE_NONNULL(m) -#else -#define ATTRIBUTE_GCC_PPDIAG(m, n) ATTRIBUTE_NONNULL(m) -#endif -extern void pp_printf (pretty_printer *, const char *, ...) - ATTRIBUTE_GCC_PPDIAG(2,3); - -extern void pp_verbatim (pretty_printer *, const char *, ...) - ATTRIBUTE_GCC_PPDIAG(2,3); -extern void pp_base_flush (pretty_printer *); -extern void pp_base_format (pretty_printer *, text_info *); -extern void pp_base_output_formatted_text (pretty_printer *); -extern void pp_base_format_verbatim (pretty_printer *, text_info *); - -extern void pp_base_indent (pretty_printer *); -extern void pp_base_newline (pretty_printer *); -extern void pp_base_character (pretty_printer *, int); -extern void pp_base_string (pretty_printer *, const char *); -extern void pp_write_text_to_stream (pretty_printer *pp); -extern void pp_base_maybe_space (pretty_printer *); - -/* Switch into verbatim mode and return the old mode. */ -static inline pp_wrapping_mode_t -pp_set_verbatim_wrapping_ (pretty_printer *pp) -{ - pp_wrapping_mode_t oldmode = pp_wrapping_mode (pp); - pp_line_cutoff (pp) = 0; - pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_NEVER; - return oldmode; -} -#define pp_set_verbatim_wrapping(PP) pp_set_verbatim_wrapping_ (pp_base (PP)) - -#endif /* GCC_PRETTY_PRINT_H */ diff --git a/support/cpp2/sdcpp-opts.c b/support/cpp2/sdcpp-opts.c index 506a4867..19bc2649 100644 --- a/support/cpp2/sdcpp-opts.c +++ b/support/cpp2/sdcpp-opts.c @@ -21,7 +21,6 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA #include "config.h" #include "system.h" -#include "diagnostic.h" #include "intl.h" #include "cppdefault.h" #include "c-incpath.h" @@ -315,7 +314,6 @@ sdcpp_common_handle_option (size_t scode, const char *arg, int value) case OPT_Werror: cpp_opts->warnings_are_errors = value; - global_dc->warning_as_error_requested = value; break; case OPT_Wimport: @@ -577,8 +575,6 @@ sdcpp_common_post_options (const char **pfilename) cb->dir_change = cb_dir_change; cpp_post_options (parse_in); - input_location = UNKNOWN_LOCATION; - /* If an error has occurred in cpplib, note it so we fail immediately. */ errorcount += cpp_errors (parse_in); diff --git a/support/cpp2/sdcpp.c b/support/cpp2/sdcpp.c index 76931cf9..b508ea64 100644 --- a/support/cpp2/sdcpp.c +++ b/support/cpp2/sdcpp.c @@ -1,25 +1,25 @@ /*------------------------------------------------------------------------- - sdcppmain.c - sdcpp: SDCC preprocessor main file, using cpplib. + sdcppmain.c - sdcpp: SDCC preprocessor main file, using cpplib. - Written by Borut Razem, 2006. + Written by Borut Razem, 2006. - This program 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. + This program 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. - This program 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. + This program 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 this program; if not, write to the Free Software - Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - In other words, you are welcome to use, share and improve this program. - You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ #include "config.h" @@ -30,41 +30,29 @@ #include "mkdeps.h" #include "opts.h" #include "intl.h" -#include "c-pretty-print.h" -#include "diagnostic.h" -#define CPP_FATAL_LIMIT 1000 -/* True if we have seen a "fatal" error. */ -#define CPP_FATAL_ERRORS(PFILE) (cpp_errors (PFILE) >= CPP_FATAL_LIMIT) - -const char *progname; /* Needs to be global. */ +const char *progname; /* Needs to be global. */ /* From laghooks-def.h */ /* The whole thing. The structure is defined in langhooks.h. */ #define LANG_HOOKS_INITIALIZER { \ LANG_HOOKS_INIT_OPTIONS, \ - LANG_HOOKS_INITIALIZE_DIAGNOSTICS, \ LANG_HOOKS_HANDLE_OPTION, \ LANG_HOOKS_MISSING_ARGUMENT, \ LANG_HOOKS_POST_OPTIONS, \ LANG_HOOKS_INIT, \ LANG_HOOKS_FINISH, \ - LANG_HOOKS_PRINT_ERROR_FUNCTION, \ } /* From c-lang.c */ #define LANG_HOOKS_INIT_OPTIONS sdcpp_init_options -#define LANG_HOOKS_INITIALIZE_DIAGNOSTICS sdcpp_initialize_diagnostics #define LANG_HOOKS_HANDLE_OPTION sdcpp_common_handle_option #define LANG_HOOKS_MISSING_ARGUMENT sdcpp_common_missing_argument #define LANG_HOOKS_POST_OPTIONS sdcpp_common_post_options #define LANG_HOOKS_INIT sdcpp_common_init #define LANG_HOOKS_FINISH sdcpp_common_finish -#define LANG_HOOKS_PRINT_ERROR_FUNCTION sdcpp_print_error_function static unsigned int sdcpp_init_options (unsigned int argc, const char **argv); -static void sdcpp_initialize_diagnostics (diagnostic_context *context); -static void sdcpp_print_error_function (diagnostic_context *context, const char *file); /* Each front end provides its own lang hook initializer. */ const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; @@ -75,23 +63,8 @@ const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; const char *main_input_filename; -#ifndef USE_MAPPED_LOCATION -location_t unknown_location = { NULL, 0 }; -#endif - -/* Current position in real source file. */ - -location_t input_location; - struct line_maps line_table; -/* Stack of currently pending input files. */ - -struct file_stack *input_file_stack; - -/* Incremented on each change to input_file_stack. */ -int input_file_stack_tick; - /* Temporarily suppress certain warnings. This is set while reading code from a system header file. */ @@ -102,7 +75,7 @@ int in_system_header = 0; int flag_pedantic_errors = 0; -cpp_reader *parse_in; /* Declared in c-pragma.h. */ +cpp_reader *parse_in; /* Declared in c-pragma.h. */ /* Nonzero means `char' should be signed. */ @@ -185,16 +158,16 @@ do_pragma_sdcc_hash (cpp_reader *pfile) if (tok->type == CPP_PLUS) { - CPP_OPTION(pfile, allow_naked_hash)++; + CPP_OPTION(pfile, allow_naked_hash)++; } else if (tok->type == CPP_MINUS) { - CPP_OPTION(pfile, allow_naked_hash)--; + CPP_OPTION(pfile, allow_naked_hash)--; } else { - cpp_error (pfile, CPP_DL_ERROR, - "invalid #pragma sdcc_hash directive, need '+' or '-'"); + cpp_error (pfile, CPP_DL_ERROR, + "invalid #pragma sdcc_hash directive, need '+' or '-'"); } } @@ -238,7 +211,7 @@ do_pragma_preproc_asm (cpp_reader *pfile) else { cpp_error (pfile, CPP_DL_ERROR, - "invalid #pragma preproc_asm directive, need '+' or '-'"); + "invalid #pragma preproc_asm directive, need '+' or '-'"); } } @@ -266,33 +239,6 @@ sdcpp_init_options (unsigned int argc, const char **argv) return ret; } -static void -sdcpp_initialize_diagnostics (diagnostic_context *context) -{ - pretty_printer *base = context->printer; - c_pretty_printer *pp = xmalloc (sizeof (c_pretty_printer)); - memcpy (pp_base (pp), base, sizeof (pretty_printer)); - pp_c_pretty_printer_init (pp); - context->printer = (pretty_printer *) pp; - - /* It is safe to free this object because it was previously malloc()'d. */ - free (base); -} - -/* The default function to print out name of current function that caused - an error. */ -static void -sdcpp_print_error_function (diagnostic_context *context, const char *file) -{ -} - -/* Initialize the PRETTY-PRINTER for handling C codes. */ - -void -pp_c_pretty_printer_init (c_pretty_printer *pp) -{ -} - void print_version (FILE *file, const char *indent) { @@ -321,10 +267,6 @@ general_init (const char *argv0) hex_init (); gcc_init_libintl (); - - /* Initialize the diagnostics reporting machinery, so option parsing - can give warnings and errors. */ - diagnostic_initialize (global_dc); } /* Process the options that have been parsed. */ @@ -336,71 +278,119 @@ process_options (void) sets the original filename if appropriate (e.g. foo.i -> foo.c) so we can correctly initialize debug output. */ /*no_backend =*/ (*lang_hooks.post_options) (&main_input_filename); - input_filename = main_input_filename; } -#if 0 +/* Parse a -d... command line switch. */ + +void +decode_d_option (const char *arg) +{ + int c; + + while (*arg) + switch (c = *arg++) + { + case 'D': /* These are handled by the preprocessor. */ + case 'I': + case 'M': + case 'N': + break; + + default: + warning (0, "unrecognized gcc debugging option: %c", c); + break; + } +} + +/* Diagnostic */ + +int errorcount = 0; + +/* An informative note. Use this for additional details on an error + message. */ +void +inform (const char *gmsgid, ...) +{ + va_list ap; + + va_start (ap, gmsgid); + fprintf (stderr, "%s: note: ", progname); + vfprintf (stderr, gmsgid, ap); + va_end (ap); +} + /* A warning. Use this for code which is correct according to the relevant language specification but is likely to be buggy anyway. */ void -warning (const char *msgid, ...) +warning (int opt, const char *gmsgid, ...) { va_list ap; - va_start (ap, msgid); - fprintf (stderr, "%s: error: ", progname); - vfprintf (stderr, msgid, ap); + if CPP_OPTION (parse_in, warnings_are_errors) + ++errorcount; + + va_start (ap, gmsgid); + fprintf (stderr, "%s: warning: ", progname); + vfprintf (stderr, gmsgid, ap); va_end (ap); } /* A hard error: the code is definitely ill-formed, and an object file will not be produced. */ void -error (const char *msgid, ...) +error (const char *gmsgid, ...) { va_list ap; - va_start (ap, msgid); - fprintf (stderr, "%s: warning: ", progname); - vfprintf (stderr, msgid, ap); + ++errorcount; + + va_start (ap, gmsgid); + fprintf (stderr, "%s: error: ", progname); + vfprintf (stderr, gmsgid, ap); va_end (ap); } -/* Print a fatal I/O error message. Argument are like printf. - Also include a system error message based on `errno'. */ +/* An error which is severe enough that we make no attempt to + continue. Do not use this for internal consistency checks; that's + internal_error. Use of this function should be rare. */ void -fatal_io_error (const char *msgid, ...) +fatal_error (const char *gmsgid, ...) { va_list ap; - va_start (ap, msgid); - fprintf (stderr, "%s: %s: ", progname, xstrerror (errno)); - vfprintf(stderr, msgid, ap); + va_start (ap, gmsgid); + fprintf (stderr, "%s: fatal error: ", progname); + vfprintf (stderr, gmsgid, ap); va_end (ap); - exit (FATAL_EXIT_CODE); -} -#endif -/* Parse a -d... command line switch. */ + gcc_unreachable (); +} +/* An internal consistency check has failed. We make no attempt to + continue. Note that unless there is debugging value to be had from + a more specific message, or some other good reason, you should use + abort () instead of calling this function directly. */ void -decode_d_option (const char *arg) +internal_error (const char *gmsgid, ...) { - int c; + va_list ap; - while (*arg) - switch (c = *arg++) - { - case 'D': /* These are handled by the preprocessor. */ - case 'I': - case 'M': - case 'N': - break; + va_start (ap, gmsgid); + fprintf (stderr, "%s: internal compiler error: ", progname); + vfprintf (stderr, gmsgid, ap); + va_end (ap); - default: - warning (0, "unrecognized gcc debugging option: %c", c); - break; - } + gcc_unreachable (); +} + +/* Report an internal compiler error in a friendly manner. This is + the function that gets called upon use of abort() in the source + code generally, thanks to a special macro. */ + +void +fancy_abort (const char *file, int line, const char *function) +{ + internal_error ("in %s, at %s:%d", function, file, line); } /* Language-dependent initialization. Returns nonzero on success. */ @@ -439,7 +429,7 @@ do_compile (void) } } -/* Entry point of cc1, cc1plus, jc1, f771, etc. +/* Entry point of sdcpp. Exit code is FATAL_EXIT_CODE if can't open files or if there were any errors, or SUCCESS_EXIT_CODE if compilation succeeded. @@ -448,7 +438,7 @@ do_compile (void) int main (unsigned int argc, const char **argv) { - /* Initialization of GCC's environment, and diagnostics. */ + /* Initialization of SDCPP's environment. */ general_init (argv[0]); /* Parse the options and do minimal processing; basically just @@ -459,7 +449,7 @@ main (unsigned int argc, const char **argv) if (!exit_after_options) do_compile (); - if (errorcount || sorrycount) + if (errorcount) return (FATAL_EXIT_CODE); return (SUCCESS_EXIT_CODE); diff --git a/support/cpp2/sdcpp.dsp b/support/cpp2/sdcpp.dsp index 05359e83..87fd8718 100644 --- a/support/cpp2/sdcpp.dsp +++ b/support/cpp2/sdcpp.dsp @@ -237,10 +237,6 @@ SOURCE=.\cppdefault.c # End Source File # Begin Source File -SOURCE=.\diagnostic.c -# End Source File -# Begin Source File - SOURCE=.\options.c # End Source File # Begin Source File @@ -253,10 +249,6 @@ SOURCE=.\prefix.c # End Source File # Begin Source File -SOURCE=".\pretty-print.c" -# End Source File -# Begin Source File - SOURCE=".\sdcpp-opts.c" # End Source File # Begin Source File @@ -349,18 +341,10 @@ SOURCE=.\cppdefault.h # End Source File # Begin Source File -SOURCE=.\diagnostic.h -# End Source File -# Begin Source File - SOURCE=.\hwint.h # End Source File # Begin Source File -SOURCE=.\input.h -# End Source File -# Begin Source File - SOURCE=.\intl.h # End Source File # Begin Source File @@ -385,10 +369,6 @@ SOURCE=.\prefix.h # End Source File # Begin Source File -SOURCE=".\pretty-print.h" -# End Source File -# Begin Source File - SOURCE=".\libiberty\safe-ctype.h" # End Source File # Begin Source File diff --git a/support/cpp2/sdcpp.h b/support/cpp2/sdcpp.h index 06fccfd3..fa6ae679 100644 --- a/support/cpp2/sdcpp.h +++ b/support/cpp2/sdcpp.h @@ -35,17 +35,17 @@ typedef long long long_long; #endif /* Define results of standard character escape sequences. */ -#define TARGET_BELL 007 -#define TARGET_BS 010 -#define TARGET_TAB 011 -#define TARGET_NEWLINE 012 -#define TARGET_VT 013 -#define TARGET_FF 014 -#define TARGET_CR 015 -#define TARGET_ESC 033 +#define TARGET_BELL 007 +#define TARGET_BS 010 +#define TARGET_TAB 011 +#define TARGET_NEWLINE 012 +#define TARGET_VT 013 +#define TARGET_FF 014 +#define TARGET_CR 015 +#define TARGET_ESC 033 #define CHAR_TYPE_SIZE 8 -#define WCHAR_TYPE_SIZE 32 /* ? maybe ? */ +#define WCHAR_TYPE_SIZE 32 /* ? maybe ? */ #define SUPPORTS_ONE_ONLY 0 @@ -67,10 +67,6 @@ struct lang_hooks the language mask to filter the switch array with. */ unsigned int (*init_options) (unsigned int argc, const char **argv); - /* Callback used to perform language-specific initialization for the - global diagnostic context structure. */ - void (*initialize_diagnostics) (struct diagnostic_context *); - /* Handle the switch CODE, which has real type enum opt_code from options.h. If the switch takes an argument, it is passed in ARG which points to permanent storage. The handler is responsible for @@ -103,9 +99,6 @@ struct lang_hooks /* Called at the end of compilation, as a finalizer. */ void (*finish) (void); - - /* Called by report_error_function to print out function name. */ - void (*print_error_function) (struct diagnostic_context *, const char *); }; /* Each front end provides its own. */ @@ -129,23 +122,12 @@ extern const struct lang_hooks lang_hooks; #endif extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2) ATTRIBUTE_NORETURN; -extern void warning0 (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); /* Pass one of the OPT_W* from options.h as the first parameter. */ extern void warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2) ATTRIBUTE_NORETURN; -extern void pedwarn (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); -extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); -extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); - -#ifdef BUFSIZ - /* N.B. Unlike all the others, fnotice is just gettext+fprintf, and - therefore it can have ATTRIBUTE_PRINTF. */ -extern void fnotice (FILE *, const char *, ...) - ATTRIBUTE_PRINTF_2; -#endif extern bool exit_after_options; @@ -158,7 +140,7 @@ extern void decode_d_option (const char *); compilation was started. */ extern const char *get_src_pwd (void); -extern bool set_src_pwd (const char *); +extern bool set_src_pwd (const char *); /* * From flags.h @@ -242,10 +224,18 @@ extern void pp_dir_change (cpp_reader *, const char *); extern struct cpp_reader* parse_in; /* - * From tree.h + * From input.h */ -#include "input.h" +extern struct line_maps line_table; + +typedef source_location location_t; /* deprecated typedef */ + +/* Top-level source file. */ +extern const char *main_input_filename; +/* + * From tree.h + */ /* Define the overall contents of a tree node. just to make diagnostic.c happy */ @@ -259,4 +249,10 @@ union tree_node #define DECL_SOURCE_LOCATION(NODE) ((NODE)->decl.locus) +/* + * From diagnostic.h + */ +extern int errorcount; + + #endif /* __SDCPP_H */ -- 2.47.2