OSDN Git Service

2008-03-10 Paul Brook <paul@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / c-lex.c
index bc0aeb2..617cd7e 100644 (file)
@@ -1,6 +1,6 @@
 /* Mainly the interface between cpplib and the C front ends.
    Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
-   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
+   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -49,16 +49,6 @@ static splay_tree file_info_tree;
 int pending_lang_change; /* If we need to switch languages - C++ only */
 int c_header_level;     /* depth in C headers - C++ only */
 
-/* If we need to translate characters received.  This is tri-state:
-   0 means use only the untranslated string; 1 means use only
-   the translated string; -1 means chain the translated string
-   to the untranslated one.  */
-int c_lex_string_translate = 1;
-
-/* True if strings should be passed to the caller of c_lex completely
-   unmolested (no concatenation, no translation).  */
-bool c_lex_return_raw_strings = false;
-
 static tree interpret_integer (const cpp_token *, unsigned int);
 static tree interpret_float (const cpp_token *, unsigned int);
 static tree interpret_fixed (const cpp_token *, unsigned int);
@@ -66,7 +56,7 @@ static enum integer_type_kind narrowest_unsigned_type
        (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
 static enum integer_type_kind narrowest_signed_type
        (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
-static enum cpp_ttype lex_string (const cpp_token *, tree *, bool);
+static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool);
 static tree lex_charconst (const cpp_token *);
 static void update_header_times (const char *);
 static int dump_one_header (splay_tree_node, void *);
@@ -200,15 +190,7 @@ cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token,
                int parsing_args)
 {
   if (token->type != CPP_EOF && !parsing_args)
-#ifdef USE_MAPPED_LOCATION
     input_location = token->src_loc;
-#else
-    {
-      source_location loc = token->src_loc;
-      const struct line_map *map = linemap_lookup (&line_table, loc);
-      input_line = SOURCE_LINE (map, loc);
-    }
-#endif
 }
 
 void
@@ -223,17 +205,9 @@ fe_file_change (const struct line_map *new_map)
         we already did in compile_file.  */
       if (!MAIN_FILE_P (new_map))
        {
-#ifdef USE_MAPPED_LOCATION
          int included_at = LAST_SOURCE_LINE_LOCATION (new_map - 1);
 
-         input_location = included_at;
-         push_srcloc (new_map->start_location);
-#else
-         int included_at = LAST_SOURCE_LINE (new_map - 1);
-
-         input_line = included_at;
-         push_srcloc (new_map->to_file, 1);
-#endif
+         input_location = new_map->start_location;
          (*debug_hooks->start_source_file) (included_at, new_map->to_file);
 #ifndef NO_IMPLICIT_EXTERN_C
          if (c_header_level)
@@ -256,19 +230,14 @@ fe_file_change (const struct line_map *new_map)
          --pending_lang_change;
        }
 #endif
-      pop_srcloc ();
+      input_location = new_map->start_location;
 
       (*debug_hooks->end_source_file) (new_map->to_line);
     }
 
   update_header_times (new_map->to_file);
   in_system_header = new_map->sysp != 0;
-#ifdef USE_MAPPED_LOCATION
   input_location = new_map->start_location;
-#else
-  input_filename = new_map->to_file;
-  input_line = new_map->to_line;
-#endif
 }
 
 static void
@@ -281,14 +250,7 @@ cb_def_pragma (cpp_reader *pfile, source_location loc)
     {
       const unsigned char *space, *name;
       const cpp_token *s;
-#ifndef USE_MAPPED_LOCATION
-      location_t fe_loc;
-      const struct line_map *map = linemap_lookup (&line_table, loc);
-      fe_loc.file = map->to_file;
-      fe_loc.line = SOURCE_LINE (map, loc);
-#else
       location_t fe_loc = loc;
-#endif
 
       space = name = (const unsigned char *) "";
       s = cpp_get_token (pfile);
@@ -309,7 +271,7 @@ cb_def_pragma (cpp_reader *pfile, source_location loc)
 static void
 cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node)
 {
-  const struct line_map *map = linemap_lookup (&line_table, loc);
+  const struct line_map *map = linemap_lookup (line_table, loc);
   (*debug_hooks->define) (SOURCE_LINE (map, loc),
                          (const char *) cpp_macro_definition (pfile, node));
 }
@@ -319,7 +281,7 @@ static void
 cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
          cpp_hashnode *node)
 {
-  const struct line_map *map = linemap_lookup (&line_table, loc);
+  const struct line_map *map = linemap_lookup (line_table, loc);
   (*debug_hooks->undef) (SOURCE_LINE (map, loc),
                         (const char *) NODE_NAME (node));
 }
@@ -329,7 +291,8 @@ cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
    non-NULL.  */
 
 enum cpp_ttype
-c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
+c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
+                 int lex_flags)
 {
   static bool no_more_pch;
   const cpp_token *tok;
@@ -338,15 +301,10 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
 
   timevar_push (TV_CPP);
  retry:
-  tok = cpp_get_token (parse_in);
+  tok = cpp_get_token_with_location (parse_in, loc);
   type = tok->type;
 
  retry_after_at:
-#ifdef USE_MAPPED_LOCATION
-  *loc = tok->src_loc;
-#else
-  *loc = input_location;
-#endif
   switch (type)
     {
     case CPP_PADDING:
@@ -390,10 +348,11 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
       /* An @ may give the next token special significance in Objective-C.  */
       if (c_dialect_objc ())
        {
-         location_t atloc = input_location;
+         location_t atloc = *loc;
+         location_t newloc;
 
        retry_at:
-         tok = cpp_get_token (parse_in);
+         tok = cpp_get_token_with_location (parse_in, &newloc);
          type = tok->type;
          switch (type)
            {
@@ -402,7 +361,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
 
            case CPP_STRING:
            case CPP_WSTRING:
-             type = lex_string (tok, value, true);
+             type = lex_string (tok, value, true, true);
              break;
 
            case CPP_NAME:
@@ -417,6 +376,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
            default:
              /* ... or not.  */
              error ("%Hstray %<@%> in program", &atloc);
+             *loc = newloc;
              goto retry_after_at;
            }
          break;
@@ -455,9 +415,10 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
 
     case CPP_STRING:
     case CPP_WSTRING:
-      if (!c_lex_return_raw_strings)
+      if ((lex_flags & C_LEX_RAW_STRINGS) == 0)
        {
-         type = lex_string (tok, value, false);
+         type = lex_string (tok, value, false,
+                            (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
          break;
        }
       *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
@@ -878,7 +839,7 @@ interpret_fixed (const cpp_token *token, unsigned int flags)
    we must arrange to provide.  */
 
 static enum cpp_ttype
-lex_string (const cpp_token *tok, tree *valp, bool objc_string)
+lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
 {
   tree value;
   bool wide = false;
@@ -936,34 +897,12 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string)
     warning (OPT_Wtraditional,
             "traditional C rejects string constant concatenation");
 
-  if ((c_lex_string_translate
+  if ((translate
        ? cpp_interpret_string : cpp_interpret_string_notranslate)
       (parse_in, strs, concats + 1, &istr, wide))
     {
       value = build_string (istr.len, (const char *) istr.text);
       free (CONST_CAST (unsigned char *, istr.text));
-
-      if (c_lex_string_translate == -1)
-       {
-         int xlated = cpp_interpret_string_notranslate (parse_in, strs,
-                                                        concats + 1,
-                                                        &istr, wide);
-         /* Assume that, if we managed to translate the string above,
-            then the untranslated parsing will always succeed.  */
-         gcc_assert (xlated);
-
-         if (TREE_STRING_LENGTH (value) != (int) istr.len
-             || 0 != strncmp (TREE_STRING_POINTER (value),
-                              (const char *) istr.text, istr.len))
-           {
-             /* Arrange for us to return the untranslated string in
-                *valp, but to set up the C type of the translated
-                one.  */
-             *valp = build_string (istr.len, (const char *) istr.text);
-             valp = &TREE_CHAIN (*valp);
-           }
-         free (CONST_CAST (unsigned char *, istr.text));
-       }
     }
   else
     {