gcc/fixincludes/fixtests.c

156 lines
4.1 KiB
C
Raw Normal View History

/*
Test to see if a particular fix should be applied to a header file.
2000-02-26 21:02:01 +01:00
Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
= = = = = = = = = = = = = = = = = = = = = = = = =
NOTE TO DEVELOPERS
The routines you write here must work closely with fixincl.c.
Here are the rules:
1. Every test procedure name must be suffixed with "_test".
These routines will be referenced from inclhack.def, sans the suffix.
2. Use the "TEST_FOR_FIX_PROC_HEAD()" macro _with_ the "_test" suffix
(I cannot use the ## magic from ANSI C) for defining your entry point.
3. Put your test name into the FIX_TEST_TABLE
4. Do not write anything to stdout. It may be closed.
5. Write to stderr only in the event of a reportable error
In such an event, call "exit(1)".
= = = = = = = = = = = = = = = = = = = = = = = = =
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, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "fixlib.h"
#define _ENV_(v,m,n,t) extern tCC* v;
ENV_TABLE
#undef _ENV_
typedef apply_fix_p_t t_test_proc ( tCC* file, tCC* text );
2000-09-12 16:28:55 +02:00
typedef struct {
2000-09-12 16:28:55 +02:00
tCC* test_name;
t_test_proc* test_proc;
} test_entry_t;
#define FIX_TEST_TABLE \
_FT_( "machine_name", machine_name_test ) \
_FT_( "stdc_0_in_system_headers", stdc_0_in_system_headers_test )
#define TEST_FOR_FIX_PROC_HEAD( test ) \
static apply_fix_p_t test ( tCC* fname ATTRIBUTE_UNUSED, \
tCC* text ATTRIBUTE_UNUSED )
TEST_FOR_FIX_PROC_HEAD( machine_name_test )
{
regex_t *label_re, *name_re;
regmatch_t match[2];
tCC *base, *limit;
IGNORE_ARG(fname);
if (!mn_get_regexps (&label_re, &name_re, "machine_name_test"))
return SKIP_FIX;
for (base = text;
xregexec (label_re, base, 2, match, 0) == 0;
base = limit)
{
base += match[0].rm_eo;
/* We're looking at an #if or #ifdef. Scan forward for the
next non-escaped newline. */
limit = base;
do
{
limit++;
limit = strchr (limit, '\n');
if (!limit)
return SKIP_FIX;
}
while (limit[-1] == '\\');
/* If the 'name_pat' matches in between base and limit, we have
a bogon. It is not worth the hassle of excluding comments,
because comments on #if/#ifdef/#ifndef lines are rare,
and strings on such lines are illegal.
REG_NOTBOL means 'base' is not at the beginning of a line, which
shouldn't matter since the name_re has no ^ anchor, but let's
be accurate anyway. */
if (xregexec (name_re, base, 1, match, REG_NOTBOL))
return SKIP_FIX; /* No match in file - no fix needed */
/* Match; is it on the line? */
if (match[0].rm_eo <= limit - base)
return APPLY_FIX; /* Yup */
/* Otherwise, keep looking... */
}
return SKIP_FIX;
}
TEST_FOR_FIX_PROC_HEAD( stdc_0_in_system_headers_test )
{
#ifdef STDC_0_IN_SYSTEM_HEADERS
return (pz_machine == NULL) ? APPLY_FIX : SKIP_FIX;
#else
return APPLY_FIX;
#endif
}
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
test for fix selector
THIS IS THE ONLY EXPORTED ROUTINE
*/
apply_fix_p_t
run_test( tCC* tname, tCC* fname, tCC* text )
{
#define _FT_(n,p) { n, p },
static test_entry_t test_table[] = { FIX_TEST_TABLE { NULL, NULL }};
#undef _FT_
optabs.c (init_optabs): Initialize fixtab... * optabs.c (init_optabs): Initialize fixtab, fixtrunctab, floattab, and extendtab within their proper array boundaries. * emit-rtl.c (init_emit_once): Pass `const_tiny_rtx' with bounds for the entire array. * config/arm/arm.c (arm_override_options): Use ARRAY_SIZE. * config/alpha/alpha.c (alpha_lookup_xfloating_lib_func): Likewise. * config/avr/avr.c (order_regs_for_local_alloc): Likewise. * config/fr30/fr30.c (fr30_print_operand): Likewise. * config/i386/dgux.c (output_options): Likewise. * config/i386/dgux.h (ASM_FILE_START): Likewise. * config/m88k/m88k.c (output_options): Likewise. * config/m88k/m88k.h (ASM_FILE_START): Likewise. * config/mcore/mcore.c (mcore_output_inline_const_forced, layout_mcore_frame, handle_structs_in_regs): Likewise. * config/mips/mips.c (output_block_move): Likewise. * config/rs6000/rs6000.c (rs6000_override_options, rs6000_file_start): Likewise. * config/sparc/sparc.c (sparc_add_gc_roots): Likewise. * fixinc/fixfixes.c (FIX_TABLE_CT): Likewise. * fixinc/fixtests.c (TEST_TABLE_CT): Likewise. * builtins.c (expand_builtin_setjmp): Likewise. * expr.c (safe_from_p): Likewise. * flow.c (life_analysis): Likewise. * fold-const.c (size_int_type_wide): Likewise. * gcc.c (translate_options, init_spec, set_spec, main): Likewise. * genattrtab.c (make_length_attrs): Likewise. * genopinit.c (gen_insn): Likewise. * genrecog.c (NUM_KNOWN_PREDS, NUM_SPECIAL_MODE_PREDS): Likewise. * global.c (global_alloc): Likewise. * local-alloc.c (find_free_reg): Likewise. * mips-tdump.c (print_symbol): Likewise. * mips-tfile.c (parse_def, parse_input): Likewise. * reload1.c (NUM_ELIMINABLE_REGS): Likewise. * stmt.c (expand_nl_goto_receiver): Likewise. * stor-layout.c (set_sizetype): Likewise. * varasm.c (decode_reg_name): Likewise. * toplev.c (decode_f_option, decode_W_option, set_target_switch, print_switch_values): Likewise. (NUM_ELEM): Remove macro. (display_help, main): s/NUM_ELEM/ARRAY_SIZE/ From-SVN: r35949
2000-08-24 22:31:35 +02:00
#define TEST_TABLE_CT (ARRAY_SIZE (test_table)-1)
int ct = TEST_TABLE_CT;
test_entry_t* pte = test_table;
do
{
if (strcmp( pte->test_name, tname ) == 0)
return (*pte->test_proc)( fname, text );
pte++;
} while (--ct > 0);
fprintf( stderr, "fixincludes error: the `%s' fix test is unknown\n",
tname );
exit( 3 );
}