OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [fixincludes/] [fixtests.c] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
 
 
/*
/*
 
 
   Test to see if a particular fix should be applied to a header file.
   Test to see if a particular fix should be applied to a header file.
 
 
   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
 
 
= = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = =
 
 
NOTE TO DEVELOPERS
NOTE TO DEVELOPERS
 
 
The routines you write here must work closely with fixincl.c.
The routines you write here must work closely with fixincl.c.
 
 
Here are the rules:
Here are the rules:
 
 
1.  Every test procedure name must be suffixed with "_test".
1.  Every test procedure name must be suffixed with "_test".
    These routines will be referenced from inclhack.def, sans the suffix.
    These routines will be referenced from inclhack.def, sans the suffix.
 
 
2.  Use the "TEST_FOR_FIX_PROC_HEAD()" macro _with_ the "_test" 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.
    (I cannot use the ## magic from ANSI C) for defining your entry point.
 
 
3.  Put your test name into the FIX_TEST_TABLE
3.  Put your test name into the FIX_TEST_TABLE
 
 
4.  Do not write anything to stdout.  It may be closed.
4.  Do not write anything to stdout.  It may be closed.
 
 
5.  Write to stderr only in the event of a reportable error
5.  Write to stderr only in the event of a reportable error
    In such an event, call "exit(1)".
    In such an event, call "exit(1)".
 
 
= = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = =
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
any later version.
 
 
GCC is distributed in the hope that it will be useful,
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING.  If not, write to
along with GCC; see the file COPYING.  If not, write to
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  */
Boston, MA 02110-1301, USA.  */
 
 
#include "fixlib.h"
#include "fixlib.h"
 
 
#define _ENV_(v,m,n,t)   extern tCC* v;
#define _ENV_(v,m,n,t)   extern tCC* v;
ENV_TABLE
ENV_TABLE
#undef _ENV_
#undef _ENV_
 
 
typedef apply_fix_p_t t_test_proc ( tCC* file, tCC* text );
typedef apply_fix_p_t t_test_proc ( tCC* file, tCC* text );
 
 
typedef struct {
typedef struct {
    tCC*         test_name;
    tCC*         test_name;
    t_test_proc* test_proc;
    t_test_proc* test_proc;
} test_entry_t;
} test_entry_t;
 
 
#define FIX_TEST_TABLE                                                  \
#define FIX_TEST_TABLE                                                  \
  _FT_( "machine_name",     machine_name_test )                         \
  _FT_( "machine_name",     machine_name_test )                         \
  _FT_( "stdc_0_in_system_headers",    stdc_0_in_system_headers_test )
  _FT_( "stdc_0_in_system_headers",    stdc_0_in_system_headers_test )
 
 
#define TEST_FOR_FIX_PROC_HEAD( test ) \
#define TEST_FOR_FIX_PROC_HEAD( test ) \
static apply_fix_p_t test ( tCC* fname ATTRIBUTE_UNUSED, \
static apply_fix_p_t test ( tCC* fname ATTRIBUTE_UNUSED, \
                            tCC* text  ATTRIBUTE_UNUSED )
                            tCC* text  ATTRIBUTE_UNUSED )
 
 
TEST_FOR_FIX_PROC_HEAD( machine_name_test )
TEST_FOR_FIX_PROC_HEAD( machine_name_test )
{
{
  regex_t *label_re, *name_re;
  regex_t *label_re, *name_re;
  regmatch_t match[2];
  regmatch_t match[2];
  tCC *base, *limit;
  tCC *base, *limit;
  IGNORE_ARG(fname);
  IGNORE_ARG(fname);
 
 
  if (!mn_get_regexps (&label_re, &name_re, "machine_name_test"))
  if (!mn_get_regexps (&label_re, &name_re, "machine_name_test"))
    return SKIP_FIX;
    return SKIP_FIX;
 
 
  for (base = text;
  for (base = text;
       xregexec (label_re, base, 2, match, 0) == 0;
       xregexec (label_re, base, 2, match, 0) == 0;
       base = limit)
       base = limit)
    {
    {
      base += match[0].rm_eo;
      base += match[0].rm_eo;
      /* We're looking at an #if or #ifdef.  Scan forward for the
      /* We're looking at an #if or #ifdef.  Scan forward for the
         next non-escaped newline.  */
         next non-escaped newline.  */
      limit = base;
      limit = base;
      do
      do
        {
        {
          limit++;
          limit++;
          limit = strchr (limit, '\n');
          limit = strchr (limit, '\n');
          if (!limit)
          if (!limit)
            return SKIP_FIX;
            return SKIP_FIX;
        }
        }
      while (limit[-1] == '\\');
      while (limit[-1] == '\\');
 
 
      /* If the 'name_pat' matches in between base and limit, we have
      /* If the 'name_pat' matches in between base and limit, we have
         a bogon.  It is not worth the hassle of excluding comments,
         a bogon.  It is not worth the hassle of excluding comments,
         because comments on #if/#ifdef/#ifndef lines are rare,
         because comments on #if/#ifdef/#ifndef lines are rare,
         and strings on such lines are illegal.
         and strings on such lines are illegal.
 
 
         REG_NOTBOL means 'base' is not at the beginning of a line, which
         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
         shouldn't matter since the name_re has no ^ anchor, but let's
         be accurate anyway.  */
         be accurate anyway.  */
 
 
      if (xregexec (name_re, base, 1, match, REG_NOTBOL))
      if (xregexec (name_re, base, 1, match, REG_NOTBOL))
        return SKIP_FIX;  /* No match in file - no fix needed */
        return SKIP_FIX;  /* No match in file - no fix needed */
 
 
      /* Match; is it on the line?  */
      /* Match; is it on the line?  */
      if (match[0].rm_eo <= limit - base)
      if (match[0].rm_eo <= limit - base)
        return APPLY_FIX;  /* Yup */
        return APPLY_FIX;  /* Yup */
 
 
      /* Otherwise, keep looking... */
      /* Otherwise, keep looking... */
    }
    }
  return SKIP_FIX;
  return SKIP_FIX;
}
}
 
 
 
 
TEST_FOR_FIX_PROC_HEAD( stdc_0_in_system_headers_test )
TEST_FOR_FIX_PROC_HEAD( stdc_0_in_system_headers_test )
{
{
#ifdef STDC_0_IN_SYSTEM_HEADERS
#ifdef STDC_0_IN_SYSTEM_HEADERS
  return (pz_machine == NULL) ? APPLY_FIX : SKIP_FIX;
  return (pz_machine == NULL) ? APPLY_FIX : SKIP_FIX;
#else
#else
  return APPLY_FIX;
  return APPLY_FIX;
#endif
#endif
}
}
 
 
 
 
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
 
 
     test for fix selector
     test for fix selector
 
 
     THIS IS THE ONLY EXPORTED ROUTINE
     THIS IS THE ONLY EXPORTED ROUTINE
 
 
*/
*/
apply_fix_p_t
apply_fix_p_t
run_test( tCC* tname, tCC* fname, tCC* text )
run_test( tCC* tname, tCC* fname, tCC* text )
{
{
#define _FT_(n,p) { n, p },
#define _FT_(n,p) { n, p },
  static test_entry_t test_table[] = { FIX_TEST_TABLE { NULL, NULL }};
  static test_entry_t test_table[] = { FIX_TEST_TABLE { NULL, NULL }};
#undef _FT_
#undef _FT_
#define TEST_TABLE_CT (ARRAY_SIZE (test_table)-1)
#define TEST_TABLE_CT (ARRAY_SIZE (test_table)-1)
 
 
  int ct = TEST_TABLE_CT;
  int ct = TEST_TABLE_CT;
  test_entry_t* pte = test_table;
  test_entry_t* pte = test_table;
 
 
  do
  do
    {
    {
      if (strcmp( pte->test_name, tname ) == 0)
      if (strcmp( pte->test_name, tname ) == 0)
        return (*pte->test_proc)( fname, text );
        return (*pte->test_proc)( fname, text );
      pte++;
      pte++;
    } while (--ct > 0);
    } while (--ct > 0);
  fprintf( stderr, "fixincludes error:  the `%s' fix test is unknown\n",
  fprintf( stderr, "fixincludes error:  the `%s' fix test is unknown\n",
           tname );
           tname );
  exit( 3 );
  exit( 3 );
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.