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]

[Preprocessor] small cleanups


From the modules branch, here are some cleanups inspired by changes I've made there.

1) directive handling gets a bool arg, not a 0/1 int
2) documented the enumerators of an enum
3) make a bunch of structure flags 1-bit bools.

applying to trunk.

nathan

--
Nathan Sidwell
2019-08-28  Nathan Sidwell  <nathan@acm.org>

	* directives-only.c (_cpp_preprocess_dir_only): Use false, not
	zero for _cpp_handle_directive call.
	* directives.c (_cpp_handle_directive): Indented is bool.
	* files.c (struct _cpp_file): Make bools 1 bit bitfields.
	* internal.h (enum include_type): Reformat and comment.
	(struct cpp_buffer): Make flags 1 bit bitfields.
	(_cpp_handle_directive): Indented is bool.

Index: libcpp/directives-only.c
===================================================================
--- libcpp/directives-only.c	(revision 274992)
+++ libcpp/directives-only.c	(working copy)
@@ -102,5 +102,5 @@ _cpp_preprocess_dir_only (cpp_reader *pf
 	    buffer->line_base -= col - 1;
 
-	    _cpp_handle_directive (pfile, 0 /* ignore indented */);
+	    _cpp_handle_directive (pfile, false /* ignore indented */);
 
 	    /* Sanitize the line settings.  Duplicate #include's can mess
Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c	(revision 274992)
+++ libcpp/directives.c	(working copy)
@@ -407,5 +407,5 @@ directive_diagnostics (cpp_reader *pfile
 }
 
-/* Check if we have a known directive.  INDENTED is nonzero if the
+/* Check if we have a known directive.  INDENTED is true if the
    '#' of the directive was indented.  This function is in this file
    to save unnecessarily exporting dtable etc. to lex.c.  Returns
@@ -413,5 +413,5 @@ directive_diagnostics (cpp_reader *pfile
    continue processing the line.  */
 int
-_cpp_handle_directive (cpp_reader *pfile, int indented)
+_cpp_handle_directive (cpp_reader *pfile, bool indented)
 {
   const directive *dir = 0;
Index: libcpp/files.c
===================================================================
--- libcpp/files.c	(revision 274992)
+++ libcpp/files.c	(working copy)
@@ -99,17 +99,17 @@ struct _cpp_file
 
   /* If opened with #import or contains #pragma once.  */
-  bool once_only;
+  bool once_only : 1;
 
   /* If read() failed before.  */
-  bool dont_read;
+  bool dont_read : 1;
 
   /* If this file is the main file.  */
-  bool main_file;
+  bool main_file : 1;
 
   /* If BUFFER above contains the true contents of the file.  */
-  bool buffer_valid;
+  bool buffer_valid : 1;
 
   /* If this file is implicitly preincluded.  */
-  bool implicit_preinclude;
+  bool implicit_preinclude : 1;
 };
 
Index: libcpp/internal.h
===================================================================
--- libcpp/internal.h	(revision 274992)
+++ libcpp/internal.h	(working copy)
@@ -114,5 +114,15 @@ extern unsigned char *_cpp_unaligned_all
 
 /* #include types.  */
-enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE, IT_DEFAULT};
+enum include_type
+  {
+   /* Directive-based including mechanisms.  */
+   IT_INCLUDE,  /* #include */
+   IT_INCLUDE_NEXT,  /* #include_next */
+   IT_IMPORT,   /* #import  */
+
+   /* Non-directive including mechanisms.  */
+   IT_CMDLINE,  /* -include */
+   IT_DEFAULT,  /* forced header  */
+  };
 
 union utoken
@@ -328,5 +338,5 @@ struct cpp_buffer
 
   /* True if we need to get the next clean line.  */
-  bool need_line;
+  bool need_line : 1;
 
   /* True if we have already warned about C++ comments in this file.
@@ -334,15 +344,15 @@ struct cpp_buffer
      or for -Wtraditional, and only once per file (otherwise it would
      be far too noisy).  */
-  unsigned int warned_cplusplus_comments : 1;
+  bool warned_cplusplus_comments : 1;
 
   /* True if we don't process trigraphs and escaped newlines.  True
      for preprocessed input, command line directives, and _Pragma
      buffers.  */
-  unsigned int from_stage3 : 1;
+  bool from_stage3 : 1;
 
   /* At EOF, a buffer is automatically popped.  If RETURN_AT_EOF is
      true, a CPP_EOF token is then returned.  Otherwise, the next
      token from the enclosing buffer is returned.  */
-  unsigned int return_at_eof : 1;
+  bool return_at_eof : 1;
 
   /* One for a system header, two for a C system header file that therefore
@@ -420,5 +430,5 @@ struct cpp_reader
   /* This is the node representing the macro being expanded at
      top-level.  The value of this data member is valid iff
-     in_macro_expansion_p() returns TRUE.  */
+     cpp_in_macro_expansion_p() returns TRUE.  */
   cpp_hashnode *top_most_macro_node;
 
@@ -426,5 +436,5 @@ struct cpp_reader
      really expanding a macro, the function macro_of_context returns
      the macro being expanded and this flag is set to false.  Client
-     code should use the function in_macro_expansion_p to know if we
+     code should use the function cpp_in_macro_expansion_p to know if we
      are either about to expand a macro, or are actually expanding
      one.  */
@@ -712,5 +722,5 @@ extern const char *cpp_named_operator2na
 /* In directives.c */
 extern int _cpp_test_assertion (cpp_reader *, unsigned int *);
-extern int _cpp_handle_directive (cpp_reader *, int);
+extern int _cpp_handle_directive (cpp_reader *, bool);
 extern void _cpp_define_builtin (cpp_reader *, const char *);
 extern char ** _cpp_save_pragma_names (cpp_reader *);

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