From: Paul Eggert Date: Thu, 20 Jun 2013 18:59:08 +0000 (-0700) Subject: * syntax.c: Integer cleanups. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2016^2~21 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1fc7100890ced39f81a822661439b1f7030df5a1;p=emacs.git * syntax.c: Integer cleanups. (SYNTAX_FLAGS_COMMENT_STYLEC): Return a boolean, not 0-or-2. All uses that need 0-or-2 changed to: (SYNTAX_FLAGS_COMMENT_STYLEC2): New macro, with the same semantics as the old SYNTAX_FLAGS_COMMENT_STYLEC. (struct lisp_parse_state, syntax_prefix_flag_p, update_syntax_table) (char_quoted, prev_char_comend_first, back_comment) (Finternal_describe_syntax_value, skip_chars, skip_syntaxes) (in_classes, forw_comment, scan_lists, scan_sexps_forward): Use bool for boolean. (update_syntax_table, skip_chars, skip_syntaxes): Prefer int to unsigned when either will do. (back_comment): Return boolean success flag, like forw_comment, instead of positive-or-minus-1 (which might have overflowed int anyway). Don't stuff ptrdiff_t into int. (syntax_spec_code, syntax_code_spec): Now const. (Fmatching_paren, scan_lists, scan_sexps_forward): Use enum syntaxcode for syntax code. (Fmatching_paren): Check that arg is a character, not just an integer. (Fstring_to_syntax): Don't assume 0377 fits in enum syntaxcode. (Finternal_describe_syntax_value): Omit no-longer-needed comparison to 0. (skip_chars): Use char, not unsigned char, when the distinction doesn't matter. (forw_comment, scan_lists): Prefer A |= B to A = A || B when B's cheap. * bytecode.c (exec_byte_code): * syntax.c (syntax_spec_code, Fchar_syntax) (Finternal_describe_syntax_value, skip_chars, skip_syntaxes) (init_syntax_once): * syntax.h (SYNTAX_WITH_FLAGS): Omit unnecessary casts. --- diff --git a/src/ChangeLog b/src/ChangeLog index 2aeccc222cf..4e52f5b2818 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,37 @@ +2013-06-20 Paul Eggert + + * syntax.c: Integer cleanups. + (SYNTAX_FLAGS_COMMENT_STYLEC): Return a boolean, not 0-or-2. + All uses that need 0-or-2 changed to: + (SYNTAX_FLAGS_COMMENT_STYLEC2): New macro, with the same semantics + as the old SYNTAX_FLAGS_COMMENT_STYLEC. + (struct lisp_parse_state, syntax_prefix_flag_p, update_syntax_table) + (char_quoted, prev_char_comend_first, back_comment) + (Finternal_describe_syntax_value, skip_chars, skip_syntaxes) + (in_classes, forw_comment, scan_lists, scan_sexps_forward): + Use bool for boolean. + (update_syntax_table, skip_chars, skip_syntaxes): + Prefer int to unsigned when either will do. + (back_comment): Return boolean success flag, like forw_comment, + instead of positive-or-minus-1 (which might have overflowed int anyway). + Don't stuff ptrdiff_t into int. + (syntax_spec_code, syntax_code_spec): Now const. + (Fmatching_paren, scan_lists, scan_sexps_forward): + Use enum syntaxcode for syntax code. + (Fmatching_paren): Check that arg is a character, not just an integer. + (Fstring_to_syntax): Don't assume 0377 fits in enum syntaxcode. + (Finternal_describe_syntax_value): Omit no-longer-needed + comparison to 0. + (skip_chars): Use char, not unsigned char, when the distinction + doesn't matter. + (forw_comment, scan_lists): Prefer A |= B to A = A || B when B's cheap. + * bytecode.c (exec_byte_code): + * syntax.c (syntax_spec_code, Fchar_syntax) + (Finternal_describe_syntax_value, skip_chars, skip_syntaxes) + (init_syntax_once): + * syntax.h (SYNTAX_WITH_FLAGS): + Omit unnecessary casts. + 2013-06-20 Eli Zaretskii * w32fns.c (w32_wnd_proc): Don't compute the header line and mode diff --git a/src/bytecode.c b/src/bytecode.c index 4940fd5c182..d95c53bf055 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -1636,7 +1636,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, c = XFASTINT (TOP); if (NILP (BVAR (current_buffer, enable_multibyte_characters))) MAKE_CHAR_MULTIBYTE (c); - XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (c)]); + XSETFASTINT (TOP, syntax_code_spec[SYNTAX (c)]); } NEXT; diff --git a/src/syntax.c b/src/syntax.c index 1b76f56dea6..ea15cf68c43 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -36,7 +36,7 @@ along with GNU Emacs. If not, see . */ #include "intervals.h" #include "category.h" -/* Then there are seven single-bit flags that have the following meanings: +/* Eight single-bit flags have the following meanings: 1. This character is the first of a two-character comment-start sequence. 2. This character is the second of a two-character comment-start sequence. 3. This character is the first of a two-character comment-end sequence. @@ -48,16 +48,15 @@ along with GNU Emacs. If not, see . */ Note that any two-character sequence whose first character has flag 1 and whose second character has flag 2 will be interpreted as a comment start. - bit 6 and 8 are used to discriminate between different comment styles. + Bits 6 and 8 discriminate among different comment styles. Languages such as C++ allow two orthogonal syntax start/end pairs - and bit 6 is used to determine whether a comment-end or Scommentend + and bit 6 determines whether a comment-end or Scommentend ends style a or b. Comment markers can start style a, b, c, or bc. Style a is always the default. - For 2-char comment markers, the style b flag is only looked up on the second + For 2-char comment markers, the style b flag is looked up only on the second char of the comment marker and on the first char of the comment ender. - For style c (like to for the nested flag), the flag can be placed on any - one of the chars. - */ + For style c (like the nested flag), the flag can be placed on any of + the chars. */ /* These macros extract specific flags from an integer that holds the syntax code and the flags. */ @@ -73,13 +72,14 @@ along with GNU Emacs. If not, see . */ #define SYNTAX_FLAGS_PREFIX(flags) (((flags) >> 20) & 1) #define SYNTAX_FLAGS_COMMENT_STYLEB(flags) (((flags) >> 21) & 1) -#define SYNTAX_FLAGS_COMMENT_STYLEC(flags) (((flags) >> 22) & 2) +#define SYNTAX_FLAGS_COMMENT_STYLEC(flags) (((flags) >> 23) & 1) +#define SYNTAX_FLAGS_COMMENT_STYLEC2(flags) (((flags) >> 22) & 2) /* C * 2 */ /* FLAGS should be the flags of the main char of the comment marker, e.g. the second for comstart and the first for comend. */ #define SYNTAX_FLAGS_COMMENT_STYLE(flags, other_flags) \ (SYNTAX_FLAGS_COMMENT_STYLEB (flags) \ - | SYNTAX_FLAGS_COMMENT_STYLEC (flags) \ - | SYNTAX_FLAGS_COMMENT_STYLEC (other_flags)) + | SYNTAX_FLAGS_COMMENT_STYLEC2 (flags) \ + | SYNTAX_FLAGS_COMMENT_STYLEC2 (other_flags)) #define SYNTAX_FLAGS_COMMENT_NESTED(flags) (((flags) >> 22) & 1) @@ -114,7 +114,7 @@ struct lisp_parse_state int instring; /* -1 if not within string, else desired terminator. */ EMACS_INT incomment; /* -1 if in unnestable comment else comment nesting */ int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */ - int quoted; /* Nonzero if just after an escape char at end of parsing */ + bool quoted; /* True if just after an escape char at end of parsing. */ EMACS_INT mindepth; /* Minimum depth seen while scanning. */ /* Char number of most recent start-of-expression at current level */ ptrdiff_t thislevelstart; @@ -143,13 +143,13 @@ static ptrdiff_t find_start_begv; static EMACS_INT find_start_modiff; -static Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int); -static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object); -static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int); +static Lisp_Object skip_chars (bool, Lisp_Object, Lisp_Object, bool); +static Lisp_Object skip_syntaxes (bool, Lisp_Object, Lisp_Object); +static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, bool); static void scan_sexps_forward (struct lisp_parse_state *, ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT, - int, Lisp_Object, int); -static int in_classes (int, Lisp_Object); + bool, Lisp_Object, int); +static bool in_classes (int, Lisp_Object); /* This setter is used only in this file, so it can be private. */ static void @@ -159,7 +159,8 @@ bset_syntax_table (struct buffer *b, Lisp_Object val) } /* Whether the syntax of the character C has the prefix flag set. */ -int syntax_prefix_flag_p (int c) +bool +syntax_prefix_flag_p (int c) { return SYNTAX_PREFIX (c); } @@ -183,12 +184,12 @@ struct gl_state_s gl_state; /* Global state of syntax parser. */ start/end of OBJECT. */ void -update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, +update_syntax_table (ptrdiff_t charpos, EMACS_INT count, bool init, Lisp_Object object) { Lisp_Object tmp_table; - unsigned cnt = 0; - int invalidate = 1; + int cnt = 0; + bool invalidate = 1; INTERVAL i; if (init) @@ -340,16 +341,16 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, int init, gl_state.b_property = gl_state.start; } -/* Returns TRUE if char at CHARPOS is quoted. +/* Returns true if char at CHARPOS is quoted. Global syntax-table data should be set up already to be good at CHARPOS or after. On return global syntax data is good for lookup at CHARPOS. */ -static int +static bool char_quoted (ptrdiff_t charpos, ptrdiff_t bytepos) { - register enum syntaxcode code; - register ptrdiff_t beg = BEGV; - register int quoted = 0; + enum syntaxcode code; + ptrdiff_t beg = BEGV; + bool quoted = 0; ptrdiff_t orig = charpos; while (charpos > beg) @@ -466,10 +467,11 @@ find_defun_start (ptrdiff_t pos, ptrdiff_t pos_byte) /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */ -static int +static bool prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte) { - int c, val; + int c; + bool val; DEC_BOTH (pos, pos_byte); UPDATE_SYNTAX_TABLE_BACKWARD (pos); @@ -479,28 +481,11 @@ prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte) return val; } -/* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */ - -/* static int - * prev_char_comstart_first (pos, pos_byte) - * int pos, pos_byte; - * { - * int c, val; - * - * DEC_BOTH (pos, pos_byte); - * UPDATE_SYNTAX_TABLE_BACKWARD (pos); - * c = FETCH_CHAR (pos_byte); - * val = SYNTAX_COMSTART_FIRST (c); - * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1); - * return val; - * } */ - -/* Checks whether charpos FROM is at the end of a comment. +/* Check whether charpos FROM is at the end of a comment. FROM_BYTE is the bytepos corresponding to FROM. Do not move back before STOP. - Return a positive value if we find a comment ending at FROM/FROM_BYTE; - return -1 otherwise. + Return true if we find a comment ending at FROM/FROM_BYTE. If successful, store the charpos of the comment's beginning into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR. @@ -508,8 +493,10 @@ prev_char_comend_first (ptrdiff_t pos, ptrdiff_t pos_byte) Global syntax data remains valid for backward search starting at the returned value (or at FROM, if the search was not successful). */ -static int -back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested, int comstyle, ptrdiff_t *charpos_ptr, ptrdiff_t *bytepos_ptr) +static bool +back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, + bool comnested, int comstyle, ptrdiff_t *charpos_ptr, + ptrdiff_t *bytepos_ptr) { /* Look back, counting the parity of string-quotes, and recording the comment-starters seen. @@ -521,13 +508,13 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested which is I+2X quotes from the comment-end. PARITY is current parity of quotes from the comment end. */ int string_style = -1; /* Presumed outside of any string. */ - int string_lossage = 0; + bool string_lossage = 0; /* Not a real lossage: indicates that we have passed a matching comment starter plus a non-matching comment-ender, meaning that any matching comment-starter we might see later could be a false positive (hidden inside another comment). Test case: { a (* b } c (* d *) */ - int comment_lossage = 0; + bool comment_lossage = 0; ptrdiff_t comment_end = from; ptrdiff_t comment_end_byte = from_byte; ptrdiff_t comstart_pos = 0; @@ -536,8 +523,8 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested or 0 if we didn't come across it yet. */ ptrdiff_t defun_start = 0; ptrdiff_t defun_start_byte = 0; - register enum syntaxcode code; - int nesting = 1; /* current comment nesting */ + enum syntaxcode code; + ptrdiff_t nesting = 1; /* current comment nesting */ int c; int syntax = 0; @@ -550,8 +537,8 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested while (from != stop) { ptrdiff_t temp_byte; - int prev_syntax, com2start, com2end; - int comstart; + int prev_syntax; + bool com2start, com2end, comstart; /* Move back and examine a character. */ DEC_BOTH (from, from_byte); @@ -772,7 +759,7 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, int comnested *charpos_ptr = from; *bytepos_ptr = from_byte; - return (from == comment_end) ? -1 : from; + return from != comment_end; } DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, @@ -854,31 +841,28 @@ One argument, a syntax table. */) into the code it signifies. This is used by modify-syntax-entry, and other things. */ -unsigned char syntax_spec_code[0400] = +unsigned char const syntax_spec_code[0400] = { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, - (char) Swhitespace, (char) Scomment_fence, (char) Sstring, 0377, - (char) Smath, 0377, 0377, (char) Squote, - (char) Sopen, (char) Sclose, 0377, 0377, - 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote, + Swhitespace, Scomment_fence, Sstring, 0377, Smath, 0377, 0377, Squote, + Sopen, Sclose, 0377, 0377, 0377, Swhitespace, Spunct, Scharquote, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, - 0377, 0377, 0377, 0377, - (char) Scomment, 0377, (char) Sendcomment, 0377, - (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */ + 0377, 0377, 0377, 0377, Scomment, 0377, Sendcomment, 0377, + Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */ 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, - 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword, - 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol, + 0377, 0377, 0377, 0377, 0377, 0377, 0377, Sword, + 0377, 0377, 0377, 0377, Sescape, 0377, 0377, Ssymbol, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */ 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, - 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword, - 0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377 + 0377, 0377, 0377, 0377, 0377, 0377, 0377, Sword, + 0377, 0377, 0377, 0377, Sstring_fence, 0377, 0377, 0377 }; /* Indexed by syntax code, give the letter that describes it. */ -char syntax_code_spec[16] = +char const syntax_code_spec[16] = { ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@', '!', '|' @@ -904,15 +888,16 @@ are listed in the documentation of `modify-syntax-entry'. */) CHECK_CHARACTER (character); char_int = XINT (character); SETUP_BUFFER_SYNTAX_TABLE (); - return make_number (syntax_code_spec[(int) SYNTAX (char_int)]); + return make_number (syntax_code_spec[SYNTAX (char_int)]); } DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0, doc: /* Return the matching parenthesis of CHARACTER, or nil if none. */) (Lisp_Object character) { - int char_int, code; - CHECK_NUMBER (character); + int char_int; + enum syntaxcode code; + CHECK_CHARACTER (character); char_int = XINT (character); SETUP_BUFFER_SYNTAX_TABLE (); code = SYNTAX (char_int); @@ -929,19 +914,18 @@ cons cell \(CODE . MATCHING-CHAR) which can be used, for example, as the value of a `syntax-table' text property. */) (Lisp_Object string) { - register const unsigned char *p; - register enum syntaxcode code; + const unsigned char *p; int val; Lisp_Object match; CHECK_STRING (string); p = SDATA (string); - code = (enum syntaxcode) syntax_spec_code[*p++]; - if (((int) code & 0377) == 0377) + val = syntax_spec_code[*p++]; + if (val == 0377) error ("Invalid syntax description letter: %c", p[-1]); - if (code == Sinherit) + if (val == Sinherit) return Qnil; if (*p) @@ -956,7 +940,6 @@ the value of a `syntax-table' text property. */) else match = Qnil; - val = (int) code; while (*p) switch (*p++) { @@ -1078,10 +1061,8 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, doc: /* Insert a description of the internal syntax description SYNTAX at point. */) (Lisp_Object syntax) { - register enum syntaxcode code; - int syntax_code; - char desc, start1, start2, end1, end2, prefix, - comstyleb, comstylec, comnested; + int code, syntax_code; + bool start1, start2, end1, end2, prefix, comstyleb, comstylec, comnested; char str[2]; Lisp_Object first, match_lisp, value = syntax; @@ -1113,7 +1094,7 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, } syntax_code = XINT (first) & INT_MAX; - code = (enum syntaxcode) (syntax_code & 0377); + code = syntax_code & 0377; start1 = SYNTAX_FLAGS_COMSTART_FIRST (syntax_code); start2 = SYNTAX_FLAGS_COMSTART_SECOND (syntax_code);; end1 = SYNTAX_FLAGS_COMEND_FIRST (syntax_code); @@ -1123,14 +1104,13 @@ DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value, comstylec = SYNTAX_FLAGS_COMMENT_STYLEC (syntax_code); comnested = SYNTAX_FLAGS_COMMENT_NESTED (syntax_code); - if ((int) code < 0 || (int) code >= (int) Smax) + if (Smax <= code) { insert_string ("invalid"); return syntax; } - desc = syntax_code_spec[(int) code]; - str[0] = desc, str[1] = 0; + str[0] = syntax_code_spec[code], str[1] = 0; insert (str, 1); if (NILP (match_lisp)) @@ -1431,21 +1411,21 @@ This function returns the distance traveled, either zero or negative. */) } static Lisp_Object -skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_classes) +skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, + bool handle_iso_classes) { - register unsigned int c; - unsigned char fastmap[0400]; + int c; + char fastmap[0400]; /* Store the ranges of non-ASCII characters. */ int *char_ranges IF_LINT (= NULL); int n_char_ranges = 0; - int negate = 0; - register ptrdiff_t i, i_byte; - /* Set to 1 if the current buffer is multibyte and the region - contains non-ASCII chars. */ - int multibyte; - /* Set to 1 if STRING is multibyte and it contains non-ASCII - chars. */ - int string_multibyte; + bool negate = 0; + ptrdiff_t i, i_byte; + /* True if the current buffer is multibyte and the region contains + non-ASCII chars. */ + bool multibyte; + /* True if STRING is multibyte and it contains non-ASCII chars. */ + bool string_multibyte; ptrdiff_t size_byte; const unsigned char *str; int len; @@ -1489,7 +1469,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl if (! string_multibyte) { - int string_has_eight_bit = 0; + bool string_has_eight_bit = 0; /* At first setup fastmap. */ while (i_byte < size_byte) @@ -1544,7 +1524,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl if (i_byte + 1 < size_byte && str[i_byte] == '-') { - unsigned int c2; + int c2; /* Skip over the dash. */ i_byte++; @@ -1557,7 +1537,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl if (c <= c2) { - unsigned lim2 = c2 + 1; + int lim2 = c2 + 1; while (c < lim2) fastmap[c++] = 1; if (! ASCII_CHAR_P (c2)) @@ -1610,9 +1590,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl while (i_byte < size_byte) { - unsigned char leading_code; - - leading_code = str[i_byte]; + int leading_code = str[i_byte]; c = STRING_CHAR_AND_LENGTH (str + i_byte, len); i_byte += len; @@ -1666,8 +1644,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl if (i_byte + 1 < size_byte && str[i_byte] == '-') { - unsigned int c2; - unsigned char leading_code2; + int c2, leading_code2; /* Skip over the dash. */ i_byte++; @@ -1681,7 +1658,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl && i_byte < size_byte) { leading_code2 = str[i_byte]; - c2 =STRING_CHAR_AND_LENGTH (str + i_byte, len); + c2 = STRING_CHAR_AND_LENGTH (str + i_byte, len); i_byte += len; } @@ -1695,7 +1672,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl } if (! ASCII_CHAR_P (c)) { - unsigned lim2 = leading_code2 + 1; + int lim2 = leading_code2 + 1; while (leading_code < lim2) fastmap[leading_code++] = 1; if (c <= c2) @@ -1728,7 +1705,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl for (i = 0; i < n_char_ranges; i += 2) { int c1 = char_ranges[i]; - unsigned lim2 = char_ranges[i + 1] + 1; + int lim2 = char_ranges[i + 1] + 1; for (; c1 < lim2; c1++) { @@ -1924,13 +1901,13 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl static Lisp_Object -skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) +skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim) { - register unsigned int c; + int c; unsigned char fastmap[0400]; - int negate = 0; - register ptrdiff_t i, i_byte; - int multibyte; + bool negate = 0; + ptrdiff_t i, i_byte; + bool multibyte; ptrdiff_t size_byte; unsigned char *str; @@ -2018,7 +1995,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) stop = endp; } c = STRING_CHAR_AND_LENGTH (p, nbytes); - if (! fastmap[(int) SYNTAX (c)]) + if (! fastmap[SYNTAX (c)]) break; p += nbytes, pos++, pos_byte += nbytes; UPDATE_SYNTAX_TABLE_FORWARD (pos); @@ -2035,7 +2012,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) p = GAP_END_ADDR; stop = endp; } - if (! fastmap[(int) SYNTAX (*p)]) + if (! fastmap[SYNTAX (*p)]) break; p++, pos++, pos_byte++; UPDATE_SYNTAX_TABLE_FORWARD (pos); @@ -2061,7 +2038,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) prev_p = p; while (--p >= stop && ! CHAR_HEAD_P (*p)); c = STRING_CHAR (p); - if (! fastmap[(int) SYNTAX (c)]) + if (! fastmap[SYNTAX (c)]) break; pos--, pos_byte -= prev_p - p; } @@ -2078,7 +2055,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) stop = endp; } UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); - if (! fastmap[(int) SYNTAX (p[-1])]) + if (! fastmap[SYNTAX (p[-1])]) break; p--, pos--, pos_byte--; } @@ -2092,14 +2069,14 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim) } } -/* Return 1 if character C belongs to one of the ISO classes +/* Return true if character C belongs to one of the ISO classes in the list ISO_CLASSES. Each class is represented by an integer which is its type according to re_wctype. */ -static int +static bool in_classes (int c, Lisp_Object iso_classes) { - int fits_class = 0; + bool fits_class = 0; while (CONSP (iso_classes)) { @@ -2119,26 +2096,26 @@ in_classes (int c, Lisp_Object iso_classes) FROM_BYTE is the bytepos corresponding to FROM. Do not move past STOP (a charpos). The comment over which we have to jump is of style STYLE - (either SYNTAX_FLAGS_COMMENT_STYLE(foo) or ST_COMMENT_STYLE). + (either SYNTAX_FLAGS_COMMENT_STYLE (foo) or ST_COMMENT_STYLE). NESTING should be positive to indicate the nesting at the beginning for nested comments and should be zero or negative else. ST_COMMENT_STYLE cannot be nested. PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character (or 0 If the search cannot start in the middle of a two-character). - If successful, return 1 and store the charpos of the comment's end + If successful, return true and store the charpos of the comment's end into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR. - Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the + Else, return false and store the charpos STOP into *CHARPOS_PTR, the corresponding bytepos into *BYTEPOS_PTR and the current nesting (as defined for state.incomment) in *INCOMMENT_PTR. The comment end is the last character of the comment rather than the - character just after the comment. + character just after the comment. Global syntax data is assumed to initially be valid for FROM and remains valid for forward search starting at the returned position. */ -static int +static bool forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, EMACS_INT nesting, int style, int prev_syntax, ptrdiff_t *charpos_ptr, ptrdiff_t *bytepos_ptr, @@ -2244,14 +2221,12 @@ If COUNT comments are found as expected, with nothing except whitespace between them, return t; otherwise return nil. */) (Lisp_Object count) { - register ptrdiff_t from; - ptrdiff_t from_byte; - register ptrdiff_t stop; - register int c, c1; - register enum syntaxcode code; + ptrdiff_t from, from_byte, stop; + int c, c1; + enum syntaxcode code; int comstyle = 0; /* style of comment encountered */ - int comnested = 0; /* whether the comment is nestable or not */ - int found; + bool comnested = 0; /* whether the comment is nestable or not */ + bool found; EMACS_INT count1; ptrdiff_t out_charpos, out_bytepos; EMACS_INT dummy; @@ -2271,7 +2246,8 @@ between them, return t; otherwise return nil. */) { do { - int comstart_first, syntax, other_syntax; + bool comstart_first; + int syntax, other_syntax; if (from == stop) { @@ -2299,8 +2275,7 @@ between them, return t; otherwise return nil. */) the comment section. */ code = Scomment; comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); - comnested - = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); + comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); INC_BOTH (from, from_byte); UPDATE_SYNTAX_TABLE_FORWARD (from); } @@ -2336,7 +2311,8 @@ between them, return t; otherwise return nil. */) { while (1) { - int quoted, syntax; + bool quoted; + int syntax; if (from <= stop) { @@ -2370,14 +2346,13 @@ between them, return t; otherwise return nil. */) c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); other_syntax = SYNTAX_WITH_FLAGS (c1); comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); - comnested - = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); + comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); } if (code == Scomment_fence) { /* Skip until first preceding unquoted comment_fence. */ - int fence_found = 0; + bool fence_found = 0; ptrdiff_t ini = from, ini_byte = from_byte; while (1) @@ -2408,7 +2383,7 @@ between them, return t; otherwise return nil. */) { found = back_comment (from, from_byte, stop, comnested, comstyle, &out_charpos, &out_bytepos); - if (found == -1) + if (!found) { if (c == '\n') /* This end-of-line is not an end-of-comment. @@ -2458,26 +2433,25 @@ between them, return t; otherwise return nil. */) ? SYNTAX (c) : Ssymbol) static Lisp_Object -scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpflag) +scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag) { Lisp_Object val; - register ptrdiff_t stop = count > 0 ? ZV : BEGV; - register int c, c1; + ptrdiff_t stop = count > 0 ? ZV : BEGV; + int c, c1; int stringterm; - int quoted; - int mathexit = 0; - register enum syntaxcode code, temp_code; + bool quoted; + bool mathexit = 0; + enum syntaxcode code, temp_code, c_code; EMACS_INT min_depth = depth; /* Err out if depth gets less than this. */ int comstyle = 0; /* style of comment encountered */ - int comnested = 0; /* whether the comment is nestable or not */ + bool comnested = 0; /* whether the comment is nestable or not */ ptrdiff_t temp_pos; EMACS_INT last_good = from; - int found; + bool found; ptrdiff_t from_byte; ptrdiff_t out_bytepos, out_charpos; - int temp; EMACS_INT dummy; - int multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol; + bool multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol; if (depth > 0) min_depth = 0; @@ -2494,7 +2468,8 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf { while (from < stop) { - int comstart_first, prefix, syntax, other_syntax; + bool comstart_first, prefix; + int syntax, other_syntax; UPDATE_SYNTAX_TABLE_FORWARD (from); c = FETCH_CHAR_AS_MULTIBYTE (from_byte); syntax = SYNTAX_WITH_FLAGS (c); @@ -2520,8 +2495,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf the comment section */ code = Scomment; comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); - comnested - = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); + comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); INC_BOTH (from, from_byte); UPDATE_SYNTAX_TABLE_FORWARD (from); } @@ -2547,8 +2521,8 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf /* Some compilers can't handle this inside the switch. */ c = FETCH_CHAR_AS_MULTIBYTE (from_byte); - temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); - switch (temp) + c_code = SYNTAX_WITH_MULTIBYTE_CHECK (c); + switch (c_code) { case Scharquote: case Sescape: @@ -2631,8 +2605,8 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf break; /* Some compilers can't handle this inside the switch. */ - temp = SYNTAX_WITH_MULTIBYTE_CHECK (c); - switch (temp) + c_code = SYNTAX_WITH_MULTIBYTE_CHECK (c); + switch (c_code) { case Scharquote: case Sescape: @@ -2691,8 +2665,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf c2 = FETCH_CHAR_AS_MULTIBYTE (from_byte); other_syntax = SYNTAX_WITH_FLAGS (c2); comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); - comnested - = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); + comnested |= SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); } /* Quoting turns anything except a comment-ender @@ -2777,13 +2750,13 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf break; found = back_comment (from, from_byte, stop, comnested, comstyle, &out_charpos, &out_bytepos); - /* FIXME: if found == -1, then it really wasn't a comment-end. + /* FIXME: if !found, it really wasn't a comment-end. For single-char Sendcomment, we can't do much about it apart from skipping the char. For 2-char endcomments, we could try again, taking both chars as separate entities, but it's a lot of trouble for very little gain, so we don't bother either. -sm */ - if (found != -1) + if (found) from = out_charpos, from_byte = out_bytepos; break; @@ -2938,7 +2911,7 @@ This includes chars with "quote" or "prefix" syntax (' or p). */) /* Parse forward from FROM / FROM_BYTE to END, assuming that FROM has state OLDSTATE (nil means FROM is start of function), and return a description of the state of the parse at END. - If STOPBEFORE is nonzero, stop at the start of an atom. + If STOPBEFORE, stop at the start of an atom. If COMMENTSTOP is 1, stop at the start of a comment. If COMMENTSTOP is -1, stop at the start or end of a comment, after the beginning of a string, or after the end of a string. */ @@ -2946,30 +2919,29 @@ This includes chars with "quote" or "prefix" syntax (' or p). */) static void scan_sexps_forward (struct lisp_parse_state *stateptr, ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t end, - EMACS_INT targetdepth, int stopbefore, + EMACS_INT targetdepth, bool stopbefore, Lisp_Object oldstate, int commentstop) { struct lisp_parse_state state; - - register enum syntaxcode code; + enum syntaxcode code; int c1; - int comnested; + bool comnested; struct level { ptrdiff_t last, prev; }; struct level levelstart[100]; - register struct level *curlevel = levelstart; + struct level *curlevel = levelstart; struct level *endlevel = levelstart + 100; - register EMACS_INT depth; /* Paren depth of current scanning location. + EMACS_INT depth; /* Paren depth of current scanning location. level - levelstart equals this except when the depth becomes negative. */ EMACS_INT mindepth; /* Lowest DEPTH value seen. */ - int start_quoted = 0; /* Nonzero means starting after a char quote */ + bool start_quoted = 0; /* True means starting after a char quote. */ Lisp_Object tem; ptrdiff_t prev_from; /* Keep one character before FROM. */ ptrdiff_t prev_from_byte; int prev_from_syntax; - int boundary_stop = commentstop == -1; - int nofence; - int found; + bool boundary_stop = commentstop == -1; + bool nofence; + bool found; ptrdiff_t out_bytepos, out_charpos; int temp; @@ -3100,8 +3072,8 @@ do { prev_from = from; \ terminates the comment section. */ state.comstyle = SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_from_syntax); - comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax); - comnested = comnested || SYNTAX_FLAGS_COMMENT_NESTED (syntax); + comnested = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) + | SYNTAX_FLAGS_COMMENT_NESTED (syntax)); state.incomment = comnested ? 1 : -1; state.comstr_start = prev_from; INC_FROM; @@ -3146,9 +3118,9 @@ do { prev_from = from; \ while (from < end) { /* Some compilers can't handle this inside the switch. */ - temp = FETCH_CHAR_AS_MULTIBYTE (from_byte); - temp = SYNTAX (temp); - switch (temp) + int symchar = FETCH_CHAR_AS_MULTIBYTE (from_byte); + enum syntaxcode symcharcode = SYNTAX (symchar); + switch (symcharcode) { case Scharquote: case Sescape: @@ -3230,19 +3202,20 @@ do { prev_from = from; \ while (1) { int c; + enum syntaxcode c_code; if (from >= end) goto done; c = FETCH_CHAR_AS_MULTIBYTE (from_byte); /* Some compilers can't handle this inside the switch. */ - temp = SYNTAX (c); + c_code = SYNTAX (c); - /* Check TEMP here so that if the char has + /* Check C_CODE here so that if the char has a syntax-table property which says it is NOT a string character, it does not end the string. */ - if (nofence && c == state.instring && temp == Sstring) + if (nofence && c == state.instring && c_code == Sstring) break; - switch (temp) + switch (c_code) { case Sstring_fence: if (!nofence) goto string_end; @@ -3398,25 +3371,25 @@ init_syntax_once (void) create syntax tables. */ Fput (Qsyntax_table, Qchar_table_extra_slots, make_number (0)); - temp = AREF (Vsyntax_code_object, (int) Swhitespace); + temp = AREF (Vsyntax_code_object, Swhitespace); Vstandard_syntax_table = Fmake_char_table (Qsyntax_table, temp); /* Control characters should not be whitespace. */ - temp = AREF (Vsyntax_code_object, (int) Spunct); + temp = AREF (Vsyntax_code_object, Spunct); for (i = 0; i <= ' ' - 1; i++) SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 0177, temp); /* Except that a few really are whitespace. */ - temp = AREF (Vsyntax_code_object, (int) Swhitespace); + temp = AREF (Vsyntax_code_object, Swhitespace); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ' ', temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\t', temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\n', temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 015, temp); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 014, temp); - temp = AREF (Vsyntax_code_object, (int) Sword); + temp = AREF (Vsyntax_code_object, Sword); for (i = 'a'; i <= 'z'; i++) SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp); for (i = 'A'; i <= 'Z'; i++) @@ -3440,18 +3413,18 @@ init_syntax_once (void) SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '}', Fcons (make_number (Sclose), make_number ('{'))); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '"', - Fcons (make_number ((int) Sstring), Qnil)); + Fcons (make_number (Sstring), Qnil)); SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\\', - Fcons (make_number ((int) Sescape), Qnil)); + Fcons (make_number (Sescape), Qnil)); - temp = AREF (Vsyntax_code_object, (int) Ssymbol); + temp = AREF (Vsyntax_code_object, Ssymbol); for (i = 0; i < 10; i++) { c = "_-+*/&|<>="[i]; SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp); } - temp = AREF (Vsyntax_code_object, (int) Spunct); + temp = AREF (Vsyntax_code_object, Spunct); for (i = 0; i < 12; i++) { c = ".,;:?!#@~^'`"[i]; @@ -3459,7 +3432,7 @@ init_syntax_once (void) } /* All multibyte characters have syntax `word' by default. */ - temp = AREF (Vsyntax_code_object, (int) Sword); + temp = AREF (Vsyntax_code_object, Sword); char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp); } diff --git a/src/syntax.h b/src/syntax.h index c9af240df0c..58d39b9059c 100644 --- a/src/syntax.h +++ b/src/syntax.h @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ -extern void update_syntax_table (ptrdiff_t, EMACS_INT, int, Lisp_Object); +extern void update_syntax_table (ptrdiff_t, EMACS_INT, bool, Lisp_Object); /* The standard syntax table is stored where it will automatically be used in all new buffers. */ @@ -99,7 +99,7 @@ enum syntaxcode _syntax_temp = SYNTAX_ENTRY (c); \ (CONSP (_syntax_temp) \ ? XINT (XCAR (_syntax_temp)) \ - : (int) Swhitespace); }) + : Swhitespace); }) #define SYNTAX_MATCH(c) \ ({ Lisp_Object _syntax_temp; \ @@ -112,14 +112,14 @@ extern Lisp_Object syntax_temp; #define SYNTAX(c) \ (syntax_temp = SYNTAX_ENTRY ((c)), \ (CONSP (syntax_temp) \ - ? (enum syntaxcode) (XINT (XCAR (syntax_temp)) & 0xff) \ + ? (enum syntaxcode) (XINT (XCAR (syntax_temp)) & 0xff) \ : Swhitespace)) #define SYNTAX_WITH_FLAGS(c) \ (syntax_temp = SYNTAX_ENTRY ((c)), \ (CONSP (syntax_temp) \ - ? XINT (XCAR (syntax_temp)) \ - : (int) Swhitespace)) + ? XINT (XCAR (syntax_temp)) \ + : Swhitespace)) #define SYNTAX_MATCH(c) \ (syntax_temp = SYNTAX_ENTRY ((c)), \ @@ -130,17 +130,17 @@ extern Lisp_Object syntax_temp; /* Whether the syntax of the character C has the prefix flag set. */ -extern int syntax_prefix_flag_p (int c); +extern bool syntax_prefix_flag_p (int c); -/* This array, indexed by a character, contains the syntax code which that - character signifies (as a char). For example, - (enum syntaxcode) syntax_spec_code['w'] is Sword. */ +/* This array, indexed by a character less than 256, contains the + syntax code which that character signifies (as an unsigned char). + For example, syntax_spec_code['w'] == Sword. */ -extern unsigned char syntax_spec_code[0400]; +extern unsigned char const syntax_spec_code[0400]; /* Indexed by syntax code, give the letter that describes it. */ -extern char syntax_code_spec[16]; +extern char const syntax_code_spec[16]; /* Convert the byte offset BYTEPOS into a character position, for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT.