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]
Other format: [Raw text]

Re: PATCH: Introducing objc_is_reserved_word()


OK, my patch bootstrapped beautifully, so I'll commit it unless I hear objections.

--Zem

On 27 Aug 2004, at 17.01, Ziemowit Laski wrote:

We need to call objc_is_reserved_word() from the lexer to detect
ObjC keywords (@interface, @implementation, etc.).  The reason
this is now a separate function is that its implementation differs
slightly between ObjC and ObjC++ (see the objc-act.c fragment of
my patch below). The good news is that objc_is_reserved_word() is
now stubbed out for plain C and C++, so that ObjC keywords will not
be detected in those cases.

Since I needed to teach C++ about stub-objc.o, I took the opportunity
to factor CXX_AND_OBJCXX_OBJS out of CXX_OBJS, analogously to how
C and ObjC are set up.

Finally, the patch cleans up some comments in c-common.h, and removes
duplicate prototypes from c-tree.h.

Any objections to my committing this, provided the result bootstraps with
no regressions?


Thank you,

--Zem

[gcc/ChangeLog]
2004-08-27  Ziemowit Laski  <zlaski@apple.com>

	* c-common.h: Update comments about ObjC/ObjC++ entry points.
	(objc_is_reserved_word): New prototype.
	(get_current_scope, objc_mark_locals_volatile): Move prototypes to
	separate section; these are call-backs.
	* c-lex.c (c_lex_with_flags): Call objc_is_reserved_word() to detect
	ObjC/ObjC++ "@" keywords.
	* c-tree.h (get_current_scope, objc_mark_locals_volatile): Remove
	prototypes; they already live in c-common.h.
	* stub-objc.c: Update copyright notice.
	(objc_is_reserved_word): New stub.

[gcc/cp/ChangeLog]
2004-08-27  Ziemowit Laski  <zlaski@apple.com>

	* Make-lang.in (CXX_OBJS): Split up into CXX_OBJS and
	CXX_AND_OBJCXX_OBJS.
	(CXX_C_OBJS): Include in CXX_AND_OBJCXX_OBJS instead of listing
	separately on the link line.

[gcc/objc/ChangeLog]
2004-08-27  Ziemowit Laski  <zlaski@apple.com>

* objc-act.c (objc_is_reserved_word): New function.

Index: gcc/c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.258
diff -u -3 -p -r1.258 c-common.h
--- gcc/c-common.h      27 Aug 2004 00:37:47 -0000      1.258
+++ gcc/c-common.h      27 Aug 2004 23:30:42 -0000
@@ -891,21 +891,26 @@ extern void c_stddef_cpp_builtins (void)
 extern void fe_file_change (const struct line_map *);
 extern void c_parse_error (const char *, enum cpp_ttype, tree);

-/* The following have been moved here from c-tree.h, since they're needed
- in the ObjC++ world, too. What is more, stub-objc.c could use a few
- prototypes. */
+/* Objective-C / Objective-C++ entry points. */
+
+/* The following ObjC/ObjC++ functions are called by the C and/or C++
+ front-ends; they all must have corresponding stubs in stub-objc.c. */
extern tree lookup_interface (tree);
extern tree is_class_name (tree);
extern tree objc_is_object_ptr (tree);
extern void objc_check_decl (tree);
+extern int objc_is_reserved_word (tree);
extern int objc_comptypes (tree, tree, int);
extern tree objc_message_selector (void);
extern tree lookup_objc_ivar (tree);
-extern void *get_current_scope (void);
-extern void objc_mark_locals_volatile (void *);
extern void objc_clear_super_receiver (void);
extern int objc_is_public (tree, tree);


+/* The following are provided by the C and C++ front-ends, and called by
+ ObjC/ObjC++. */
+extern void *get_current_scope (void);
+extern void objc_mark_locals_volatile (void *);
+
/* In c-ppoutput.c */
extern void init_pp_output (FILE *);
extern void preprocess_file (cpp_reader *);
Index: gcc/c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.233
diff -u -3 -p -r1.233 c-lex.c
--- gcc/c-lex.c 25 Aug 2004 09:51:20 -0000 1.233
+++ gcc/c-lex.c 27 Aug 2004 23:30:42 -0000
@@ -389,8 +389,7 @@ c_lex_with_flags (tree *value, unsigned
{
case CPP_NAME:
val = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node));
- if (C_IS_RESERVED_WORD (val)
- && OBJC_IS_AT_KEYWORD (C_RID_CODE (val)))
+ if (objc_is_reserved_word (val))
{
*value = val;
return CPP_AT_NAME;
Index: gcc/c-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.170
diff -u -3 -p -r1.170 c-tree.h
--- gcc/c-tree.h 27 Aug 2004 00:37:48 -0000 1.170
+++ gcc/c-tree.h 27 Aug 2004 23:30:42 -0000
@@ -307,8 +307,6 @@ extern bool c_eh_initialized_p;


 /* In c-decl.c */
 extern void c_finish_incomplete_decl (tree);
-extern void *get_current_scope (void);
-extern void objc_mark_locals_volatile (void *);
 extern void c_write_global_declarations (void);

 /* In order for the format checking to accept the C frontend
Index: gcc/stub-objc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stub-objc.c,v
retrieving revision 2.4
diff -u -3 -p -r2.4 stub-objc.c
--- gcc/stub-objc.c     25 Jul 2004 00:13:00 -0000      2.4
+++ gcc/stub-objc.c     27 Aug 2004 23:30:42 -0000
@@ -2,7 +2,7 @@
    that are called from within the C and C++ front-ends,
    respectively.
    Copyright (C) 1991, 1995, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.

This file is part of GCC.

@@ -57,6 +57,12 @@ objc_check_decl (tree ARG_UNUSED (decl))
 }

 int
+objc_is_reserved_word (tree ARG_UNUSED (ident))
+{
+  return 0;
+}
+
+int
 objc_comptypes (tree ARG_UNUSED (lhs), tree ARG_UNUSED (rhs),
                 int ARG_UNUSED (reflexive))
 {
Index: gcc/cp/Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Make-lang.in,v
retrieving revision 1.190
diff -u -3 -p -r1.190 Make-lang.in
--- gcc/cp/Make-lang.in 4 Aug 2004 16:19:14 -0000       1.190
+++ gcc/cp/Make-lang.in 27 Aug 2004 23:30:48 -0000
@@ -76,21 +76,23 @@ CXX_C_OBJS = attribs.o c-common.o c-form
        c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
        c-gimplify.o tree-inline.o

-# Language-specific object files.
-CXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
+# Language-specific object files for C++ and Objective C++.
+CXX_AND_OBJCXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
cp/class.o cp/decl2.o cp/error.o cp/lex.o cp/parser.o cp/ptree.o cp/rtti.o \
cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o cp/optimize.o \
- cp/mangle.o cp/cp-lang.o cp/name-lookup.o cp/cxx-pretty-print.o \
- cp/cp-gimplify.o tree-mudflap.o
+ cp/mangle.o cp/name-lookup.o cp/cxx-pretty-print.o \
+ cp/cp-gimplify.o tree-mudflap.o $(CXX_C_OBJS)
+
+# Language-specific object files for C++.
+CXX_OBJS = cp/cp-lang.o stub-objc.o $(CXX_AND_OBJCXX_OBJS)


 # Use strict warnings for this front end.
 cp-warn = $(STRICT_WARN) $(WERROR)

-cc1plus$(exeext): $(CXX_OBJS) $(CXX_C_OBJS) $(BACKEND) \
-                 $(LIBDEPS)
+cc1plus$(exeext): $(CXX_OBJS) $(BACKEND) $(LIBDEPS)
        $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
-             $(CXX_OBJS) $(CXX_C_OBJS) $(BACKEND) $(LIBS)
+             $(CXX_OBJS) $(BACKEND) $(LIBS)

 # Special build rules.
 $(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf
Index: gcc/objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.240
diff -u -3 -p -r1.240 objc-act.c
--- gcc/objc/objc-act.c 25 Aug 2004 09:52:54 -0000      1.240
+++ gcc/objc/objc-act.c 27 Aug 2004 23:30:48 -0000
@@ -608,6 +608,23 @@ lookup_protocol_in_reflist (tree rproto_
   return 0;
 }

+/* Return 1 if IDENT is an ObjC/ObjC++ reserved keyword in the context of
+ an '@'. */
+
+int
+objc_is_reserved_word (tree ident)
+{
+ unsigned char code = C_RID_CODE (ident);
+
+ return (OBJC_IS_AT_KEYWORD (code)
+#ifdef OBJCPLUS
+ || code == RID_CLASS || code == RID_PUBLIC
+ || code == RID_PROTECTED || code == RID_PRIVATE
+ || code == RID_TRY || code == RID_THROW || code == RID_CATCH
+#endif
+ );
+}
+
/* Return true if TYPE is 'id'. */


static bool




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