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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libcpp/] [directives-only.c] - Diff between revs 816 and 826

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

Rev 816 Rev 826
/* CPP Library - directive only preprocessing for distributed compilation.
/* CPP Library - directive only preprocessing for distributed compilation.
   Copyright (C) 2007, 2009
   Copyright (C) 2007, 2009
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Contributed by Ollie Wild <aaw@google.com>.
   Contributed by Ollie Wild <aaw@google.com>.
 
 
This program is free software; you can redistribute it and/or modify it
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
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
Free Software Foundation; either version 3, or (at your option) any
later version.
later version.
 
 
This program is distributed in the hope that it will be useful,
This program 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 this program; see the file COPYING3.  If not see
along with this program; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "cpplib.h"
#include "cpplib.h"
#include "internal.h"
#include "internal.h"
 
 
/* DO (Directive only) flags. */
/* DO (Directive only) flags. */
#define DO_BOL           (1 << 0) /* At the beginning of a logical line. */
#define DO_BOL           (1 << 0) /* At the beginning of a logical line. */
#define DO_STRING        (1 << 1) /* In a string constant. */
#define DO_STRING        (1 << 1) /* In a string constant. */
#define DO_CHAR          (1 << 2) /* In a character constant. */
#define DO_CHAR          (1 << 2) /* In a character constant. */
#define DO_BLOCK_COMMENT (1 << 3) /* In a block comment. */
#define DO_BLOCK_COMMENT (1 << 3) /* In a block comment. */
#define DO_LINE_COMMENT  (1 << 4) /* In a single line "//-style" comment. */
#define DO_LINE_COMMENT  (1 << 4) /* In a single line "//-style" comment. */
 
 
#define DO_LINE_SPECIAL (DO_STRING | DO_CHAR | DO_LINE_COMMENT)
#define DO_LINE_SPECIAL (DO_STRING | DO_CHAR | DO_LINE_COMMENT)
#define DO_SPECIAL      (DO_LINE_SPECIAL | DO_BLOCK_COMMENT)
#define DO_SPECIAL      (DO_LINE_SPECIAL | DO_BLOCK_COMMENT)
 
 
/* Writes out the preprocessed file, handling spacing and paste
/* Writes out the preprocessed file, handling spacing and paste
   avoidance issues.  */
   avoidance issues.  */
void
void
_cpp_preprocess_dir_only (cpp_reader *pfile,
_cpp_preprocess_dir_only (cpp_reader *pfile,
                          const struct _cpp_dir_only_callbacks *cb)
                          const struct _cpp_dir_only_callbacks *cb)
{
{
  struct cpp_buffer *buffer;
  struct cpp_buffer *buffer;
  const unsigned char *cur, *base, *next_line, *rlimit;
  const unsigned char *cur, *base, *next_line, *rlimit;
  cppchar_t c, last_c;
  cppchar_t c, last_c;
  unsigned flags;
  unsigned flags;
  linenum_type lines;
  linenum_type lines;
  int col;
  int col;
  source_location loc;
  source_location loc;
 
 
 restart:
 restart:
  /* Buffer initialization ala _cpp_clean_line(). */
  /* Buffer initialization ala _cpp_clean_line(). */
  buffer = pfile->buffer;
  buffer = pfile->buffer;
  buffer->cur_note = buffer->notes_used = 0;
  buffer->cur_note = buffer->notes_used = 0;
  buffer->cur = buffer->line_base = buffer->next_line;
  buffer->cur = buffer->line_base = buffer->next_line;
  buffer->need_line = false;
  buffer->need_line = false;
 
 
  /* This isn't really needed.  It prevents a compiler warning, though. */
  /* This isn't really needed.  It prevents a compiler warning, though. */
  loc = pfile->line_table->highest_line;
  loc = pfile->line_table->highest_line;
 
 
  /* Scan initialization. */
  /* Scan initialization. */
  next_line = cur = base = buffer->cur;
  next_line = cur = base = buffer->cur;
  rlimit = buffer->rlimit;
  rlimit = buffer->rlimit;
  flags = DO_BOL;
  flags = DO_BOL;
  lines = 0;
  lines = 0;
  col = 1;
  col = 1;
 
 
  for (last_c = '\n', c = *cur; cur < rlimit; last_c = c, c = *++cur, ++col)
  for (last_c = '\n', c = *cur; cur < rlimit; last_c = c, c = *++cur, ++col)
    {
    {
      /* Skip over escaped newlines. */
      /* Skip over escaped newlines. */
      if (__builtin_expect (c == '\\', false))
      if (__builtin_expect (c == '\\', false))
        {
        {
          const unsigned char *tmp = cur + 1;
          const unsigned char *tmp = cur + 1;
 
 
          while (is_nvspace (*tmp) && tmp < rlimit)
          while (is_nvspace (*tmp) && tmp < rlimit)
            tmp++;
            tmp++;
          if (*tmp == '\r')
          if (*tmp == '\r')
            tmp++;
            tmp++;
          if (*tmp == '\n' && tmp < rlimit)
          if (*tmp == '\n' && tmp < rlimit)
            {
            {
              CPP_INCREMENT_LINE (pfile, 0);
              CPP_INCREMENT_LINE (pfile, 0);
              lines++;
              lines++;
              col = 0;
              col = 0;
              cur = tmp;
              cur = tmp;
              c = last_c;
              c = last_c;
              continue;
              continue;
            }
            }
        }
        }
 
 
      if (__builtin_expect (last_c == '#', false) && !(flags & DO_SPECIAL))
      if (__builtin_expect (last_c == '#', false) && !(flags & DO_SPECIAL))
        {
        {
          if (c != '#' && (flags & DO_BOL))
          if (c != '#' && (flags & DO_BOL))
          {
          {
            struct line_maps *line_table;
            struct line_maps *line_table;
 
 
            if (!pfile->state.skipping && next_line != base)
            if (!pfile->state.skipping && next_line != base)
              cb->print_lines (lines, base, next_line - base);
              cb->print_lines (lines, base, next_line - base);
 
 
            /* Prep things for directive handling. */
            /* Prep things for directive handling. */
            buffer->next_line = cur;
            buffer->next_line = cur;
            buffer->need_line = true;
            buffer->need_line = true;
            _cpp_get_fresh_line (pfile);
            _cpp_get_fresh_line (pfile);
 
 
            /* Ensure proper column numbering for generated error messages. */
            /* Ensure proper column numbering for generated error messages. */
            buffer->line_base -= col - 1;
            buffer->line_base -= col - 1;
 
 
            _cpp_handle_directive (pfile, 0 /* ignore indented */);
            _cpp_handle_directive (pfile, 0 /* ignore indented */);
 
 
            /* Sanitize the line settings.  Duplicate #include's can mess
            /* Sanitize the line settings.  Duplicate #include's can mess
               things up. */
               things up. */
            line_table = pfile->line_table;
            line_table = pfile->line_table;
            line_table->highest_location = line_table->highest_line;
            line_table->highest_location = line_table->highest_line;
 
 
            /* The if block prevents us from outputing line information when
            /* The if block prevents us from outputing line information when
               the file ends with a directive and no newline.  Note that we
               the file ends with a directive and no newline.  Note that we
               must use pfile->buffer, not buffer. */
               must use pfile->buffer, not buffer. */
            if (pfile->buffer->next_line < pfile->buffer->rlimit)
            if (pfile->buffer->next_line < pfile->buffer->rlimit)
              cb->maybe_print_line (pfile->line_table->highest_line);
              cb->maybe_print_line (pfile->line_table->highest_line);
 
 
            goto restart;
            goto restart;
          }
          }
 
 
          flags &= ~DO_BOL;
          flags &= ~DO_BOL;
          pfile->mi_valid = false;
          pfile->mi_valid = false;
        }
        }
      else if (__builtin_expect (last_c == '/', false) \
      else if (__builtin_expect (last_c == '/', false) \
               && !(flags & DO_SPECIAL) && c != '*' && c != '/')
               && !(flags & DO_SPECIAL) && c != '*' && c != '/')
        {
        {
          /* If a previous slash is not starting a block comment, clear the
          /* If a previous slash is not starting a block comment, clear the
             DO_BOL flag.  */
             DO_BOL flag.  */
          flags &= ~DO_BOL;
          flags &= ~DO_BOL;
          pfile->mi_valid = false;
          pfile->mi_valid = false;
        }
        }
 
 
      switch (c)
      switch (c)
        {
        {
        case '/':
        case '/':
          if ((flags & DO_BLOCK_COMMENT) && last_c == '*')
          if ((flags & DO_BLOCK_COMMENT) && last_c == '*')
            {
            {
              flags &= ~DO_BLOCK_COMMENT;
              flags &= ~DO_BLOCK_COMMENT;
              c = 0;
              c = 0;
            }
            }
          else if (!(flags & DO_SPECIAL) && last_c == '/')
          else if (!(flags & DO_SPECIAL) && last_c == '/')
            flags |= DO_LINE_COMMENT;
            flags |= DO_LINE_COMMENT;
          else if (!(flags & DO_SPECIAL))
          else if (!(flags & DO_SPECIAL))
            /* Mark the position for possible error reporting. */
            /* Mark the position for possible error reporting. */
            LINEMAP_POSITION_FOR_COLUMN (loc, pfile->line_table, col);
            LINEMAP_POSITION_FOR_COLUMN (loc, pfile->line_table, col);
 
 
          break;
          break;
 
 
        case '*':
        case '*':
          if (!(flags & DO_SPECIAL))
          if (!(flags & DO_SPECIAL))
            {
            {
              if (last_c == '/')
              if (last_c == '/')
                flags |= DO_BLOCK_COMMENT;
                flags |= DO_BLOCK_COMMENT;
              else
              else
                {
                {
                  flags &= ~DO_BOL;
                  flags &= ~DO_BOL;
                  pfile->mi_valid = false;
                  pfile->mi_valid = false;
                }
                }
            }
            }
 
 
          break;
          break;
 
 
        case '\'':
        case '\'':
        case '"':
        case '"':
          {
          {
            unsigned state = (c == '"') ? DO_STRING : DO_CHAR;
            unsigned state = (c == '"') ? DO_STRING : DO_CHAR;
 
 
            if (!(flags & DO_SPECIAL))
            if (!(flags & DO_SPECIAL))
              {
              {
                flags |= state;
                flags |= state;
                flags &= ~DO_BOL;
                flags &= ~DO_BOL;
                pfile->mi_valid = false;
                pfile->mi_valid = false;
              }
              }
            else if ((flags & state) && last_c != '\\')
            else if ((flags & state) && last_c != '\\')
              flags &= ~state;
              flags &= ~state;
 
 
            break;
            break;
          }
          }
 
 
        case '\\':
        case '\\':
          {
          {
            if ((flags & (DO_STRING | DO_CHAR)) && last_c == '\\')
            if ((flags & (DO_STRING | DO_CHAR)) && last_c == '\\')
              c = 0;
              c = 0;
 
 
            if (!(flags & DO_SPECIAL))
            if (!(flags & DO_SPECIAL))
              {
              {
                flags &= ~DO_BOL;
                flags &= ~DO_BOL;
                pfile->mi_valid = false;
                pfile->mi_valid = false;
              }
              }
 
 
            break;
            break;
          }
          }
 
 
        case '\n':
        case '\n':
          CPP_INCREMENT_LINE (pfile, 0);
          CPP_INCREMENT_LINE (pfile, 0);
          lines++;
          lines++;
          col = 0;
          col = 0;
          flags &= ~DO_LINE_SPECIAL;
          flags &= ~DO_LINE_SPECIAL;
          if (!(flags & DO_SPECIAL))
          if (!(flags & DO_SPECIAL))
            flags |= DO_BOL;
            flags |= DO_BOL;
          break;
          break;
 
 
        case '#':
        case '#':
          next_line = cur;
          next_line = cur;
          /* Don't update DO_BOL yet. */
          /* Don't update DO_BOL yet. */
          break;
          break;
 
 
        case ' ': case '\t': case '\f': case '\v': case '\0':
        case ' ': case '\t': case '\f': case '\v': case '\0':
          break;
          break;
 
 
        default:
        default:
          if (!(flags & DO_SPECIAL))
          if (!(flags & DO_SPECIAL))
            {
            {
              flags &= ~DO_BOL;
              flags &= ~DO_BOL;
              pfile->mi_valid = false;
              pfile->mi_valid = false;
            }
            }
          break;
          break;
        }
        }
    }
    }
 
 
  if (flags & DO_BLOCK_COMMENT)
  if (flags & DO_BLOCK_COMMENT)
    cpp_error_with_line (pfile, CPP_DL_ERROR, loc, 0, "unterminated comment");
    cpp_error_with_line (pfile, CPP_DL_ERROR, loc, 0, "unterminated comment");
 
 
  if (!pfile->state.skipping && cur != base)
  if (!pfile->state.skipping && cur != base)
    {
    {
      /* If the file was not newline terminated, add rlimit, which is
      /* If the file was not newline terminated, add rlimit, which is
         guaranteed to point to a newline, to the end of our range.  */
         guaranteed to point to a newline, to the end of our range.  */
      if (cur[-1] != '\n')
      if (cur[-1] != '\n')
        {
        {
          cur++;
          cur++;
          CPP_INCREMENT_LINE (pfile, 0);
          CPP_INCREMENT_LINE (pfile, 0);
          lines++;
          lines++;
        }
        }
 
 
      cb->print_lines (lines, base, cur - base);
      cb->print_lines (lines, base, cur - base);
    }
    }
 
 
  _cpp_pop_buffer (pfile);
  _cpp_pop_buffer (pfile);
  if (pfile->buffer)
  if (pfile->buffer)
    goto restart;
    goto restart;
}
}
 
 

powered by: WebSVN 2.1.0

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