This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Fix Objective C string concatentation


Hi Zack,

Your solution is correct, there's no reason for OBJC_STRING_CST outside the
parser. Please commit the patch if there are no regressions.

Thanks,
Ovidiu

On Thu, 3 Aug 2000 10:54:57 -0700, Zack Weinberg <zack@wolery.cumb.org> wrote:

> Current CVS fails objc/execute/string[12].m with a tree checking ICE.
> This is because an Objective C string constant - @"foo" - is
> represented as an OBJC_STRING_CST tree node, which is in all respects
> identical to a STRING_CST except for its code.  We try to run
> combine_strings on a chain of OBJC_STRING_CSTs.  combine_strings uses
> TREE_STRING_* on them.  The TREE_STRING_* checked macros do not know
> about OBJC_STRING_CSTs.  Boom.
> 
> The simplest fix seems to be to eliminate OBJC_STRING_CST.  We can
> tell the difference between "foo" and @"foo" from the parser context
> just fine.
> 
> I've compiled this and verified that it fixes the bug.  I'm running a
> complete bootstrap now.  Assuming it passes, OK to commit?
> 
> zw
> 
> 	* c-lang.c, objc/objc-act.c (build_objc_string): Delete.
> 	* c-tree.h (build_objc_string): Delete prototype.
> 	* objc/objc-tree.def: Delete OBJC_STRING_CST.
> 	* c-lex.c (yylex): Use build_string for all three kinds of strings.
> 
> 	* c-parse.in, objc/objc-act.c: Update commentary.
> 
> ===================================================================
> Index: c-lang.c
> --- c-lang.c	2000/07/31 18:10:30	1.29
> +++ c-lang.c	2000/08/03 17:47:39
> @@ -171,15 +171,6 @@ recognize_objc_keyword ()
>    return 0;
>  }
>  
> -tree
> -build_objc_string (len, str)
> -    int len ATTRIBUTE_UNUSED;
> -    const char *str ATTRIBUTE_UNUSED;
> -{
> -  abort ();
> -  return NULL_TREE;
> -}
> -
>  /* Used by c-typeck.c (build_external_ref), but only for objc.  */
>  
>  tree
> ===================================================================
> Index: c-lex.c
> --- c-lex.c	2000/07/23 16:28:30	1.90
> +++ c-lex.c	2000/08/03 17:47:39
> @@ -2268,25 +2268,19 @@ yylex ()
>  	/* We have read the entire constant.
>  	   Construct a STRING_CST for the result.  */
>  
> +	yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1);
>  	if (wide_flag)
>  	  {
> -	    yylval.ttype = build_string (p - (token_buffer + 1),
> -					 token_buffer + 1);
>  	    TREE_TYPE (yylval.ttype) = wchar_array_type_node;
>  	    value = STRING;
>  	  }
>  	else if (objc_flag)
>  	  {
> -	    /* Return an Objective-C @"..." constant string object.  */
> -	    yylval.ttype = build_objc_string (p - (token_buffer + 1),
> -					      token_buffer + 1);
>  	    TREE_TYPE (yylval.ttype) = char_array_type_node;
>  	    value = OBJC_STRING;
>  	  }
>  	else
>  	  {
> -	    yylval.ttype = build_string (p - (token_buffer + 1),
> -					 token_buffer + 1);
>  	    TREE_TYPE (yylval.ttype) = char_array_type_node;
>  	    value = STRING;
>  	  }
> ===================================================================
> Index: c-parse.in
> --- c-parse.in	2000/07/31 08:28:01	1.46
> +++ c-parse.in	2000/08/03 17:47:41
> @@ -150,7 +150,7 @@ end ifc
>  %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
>  
>  /* Objective-C string constants in raw form.
> -   yylval is an OBJC_STRING_CST node.  */
> +   yylval is an STRING_CST node.  */
>  %token OBJC_STRING
>  
>  
> @@ -753,8 +753,8 @@ end ifc
>  	;
>  
>  ifobjc
> -/* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
> -   onto it.  */
> +/* Produces an STRING_CST with perhaps more STRING_CSTs chained
> +   onto it, which is to be read as an ObjC string object.  */
>  objc_string:
>  	  OBJC_STRING
>  	| objc_string OBJC_STRING
> ===================================================================
> Index: c-tree.h
> --- c-tree.h	2000/08/02 17:01:11	1.40
> +++ c-tree.h	2000/08/03 17:47:41
> @@ -142,7 +142,6 @@ extern int maybe_objc_comptypes         
>  extern tree maybe_building_objc_message_expr    PARAMS ((void));
>  extern tree maybe_objc_method_name		PARAMS ((tree));
>  extern int recognize_objc_keyword		PARAMS ((void));
> -extern tree build_objc_string			PARAMS ((int, const char *));
>  extern tree lookup_objc_ivar			PARAMS ((tree));
>  
>  /* in c-parse.in */
> ===================================================================
> Index: objc/objc-act.c
> --- objc/objc-act.c	2000/06/19 22:28:28	1.47
> +++ objc/objc-act.c	2000/08/03 17:47:43
> @@ -1410,22 +1410,7 @@ my_build_string (len, str)
>    return a_string;
>  }
>  
> -/* Return a newly constructed OBJC_STRING_CST node whose value is
> -   the LEN characters at STR.
> -   The TREE_TYPE is not initialized.  */
> -
> -tree
> -build_objc_string (len, str)
> -     int len;
> -     const char *str;
> -{
> -  tree s = build_string (len, str);
> -
> -  TREE_SET_CODE (s, OBJC_STRING_CST);
> -  return s;
> -}
> -
> -/* Given a chain of OBJC_STRING_CST's, build a static instance of
> +/* Given a chain of STRING_CST's, build a static instance of
>     NXConstanString which points at the concatenation of those strings.
>     We place the string object in the __string_objects section of the
>     __OBJC segment.  The Objective-C runtime will initialize the isa
> @@ -1451,7 +1436,6 @@ build_objc_string_object (strings)
>  
>    add_class_reference (constant_string_id);
>  
> -  /* Combine_strings will work for OBJC_STRING_CST's too.  */
>    string = combine_strings (strings);
>    TREE_SET_CODE (string, STRING_CST);
>    length = TREE_STRING_LENGTH (string) - 1;
> ===================================================================
> Index: objc/objc-tree.def
> --- objc/objc-tree.def	1999/01/06 21:10:34	1.4
> +++ objc/objc-tree.def	2000/08/03 17:47:43
> @@ -32,6 +32,3 @@ DEFTREECODE (PROTOCOL_INTERFACE_TYPE, "p
>  DEFTREECODE (KEYWORD_DECL, "keyword_decl", 'd', 0)
>  DEFTREECODE (INSTANCE_METHOD_DECL, "instance_method_decl", 'd', 0)
>  DEFTREECODE (CLASS_METHOD_DECL, "class_method_decl", 'd', 0)
> -
> -/* Objective-C constants.  */
> -DEFTREECODE (OBJC_STRING_CST, "objc_string_cst", 'c', 3)
> 


PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]