annotate src/syntax.h @ 5602:c9e5612f5424

Support the MP library on recent FreeBSD, have it pass relevant tests. src/ChangeLog addition: 2011-11-26 Aidan Kehoe <kehoea@parhasard.net> * number-mp.c (bignum_to_string): Don't overwrite the accumulator we've just set up for this function. * number-mp.c (BIGNUM_TO_TYPE): mp_itom() doesn't necessarily do what this code used to think with negative numbers, it can treat them as unsigned ints. Subtract numbers from bignum_zero instead of multiplying them by -1 to convert them to their negative equivalents. * number-mp.c (bignum_to_int): * number-mp.c (bignum_to_uint): * number-mp.c (bignum_to_long): * number-mp.c (bignum_to_ulong): * number-mp.c (bignum_to_double): Use the changed BIGNUM_TO_TYPE() in these functions. * number-mp.c (bignum_ceil): * number-mp.c (bignum_floor): In these functions, be more careful about rounding to positive and negative infinity, respectively. Don't use the sign of QUOTIENT when working out out whether to add or subtract one, rather use the sign QUOTIENT would have if arbitrary-precision division were done. * number-mp.h: * number-mp.h (MP_GCD): Wrap #include <mp.h> in BEGIN_C_DECLS/END_C_DECLS. * number.c (Fbigfloat_get_precision): * number.c (Fbigfloat_set_precision): Don't attempt to call XBIGFLOAT_GET_PREC if this build doesn't support big floats.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 26 Nov 2011 17:59:14 +0000
parents 56144c8593a8
children 2dc8711af537
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Declarations having to do with XEmacs syntax tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1992, 1993 Free Software Foundation, Inc.
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
3 Copyright (C) 2002, 2003 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5127
diff changeset
7 XEmacs is free software: you can redistribute it and/or modify it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5127
diff changeset
9 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5127
diff changeset
10 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5127
diff changeset
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 /* Synched up with: FSF 19.28. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
22 #ifndef INCLUDED_syntax_h_
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
23 #define INCLUDED_syntax_h_
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "chartab.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 /* A syntax table is a type of char table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 The values in a syntax table are either integers or conses of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 integers and chars. The lowest 7 bits of the integer are the syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 class. If this is Sinherit, then the actual syntax value needs to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 be retrieved from the standard syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
34 It turns out to be worth optimizing lookups of character syntax in two
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
35 ways. First, although the logic involved in finding the actual integer
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
36 isn't complex, the syntax value is accessed in functions such as
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
37 scan_lists() many times for each character scanned. A "mirror syntax
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
38 table" that contains the actual integers speeds this up.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
39
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
40 Second, due to the syntax-table text property, the table for looking up
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
41 syntax may change from character to character. Since looking up properties
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
42 is expensive, a "syntax cache" which contains the current syntax table and
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
43 the region where it is valid can speed up linear scans dramatically.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
44
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
45 The low 7 bits of the integer is a code, as follows. The 8th bit is
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
46 used as the prefix bit flag (see below).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 enum syntaxcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 Swhitespace, /* whitespace character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 Spunct, /* random punctuation character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 Sword, /* word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 Ssymbol, /* symbol constituent but not word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 Sopen, /* a beginning delimiter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Sclose, /* an ending delimiter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 Squote, /* a prefix character like Lisp ' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Sstring, /* a string-grouping character like Lisp " */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 Smath, /* delimiters like $ in TeX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 Sescape, /* a character that begins a C-style escape */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 Scharquote, /* a character that quotes the following character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Scomment, /* a comment-starting character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 Sendcomment, /* a comment-ending character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 Sinherit, /* use the standard syntax table for this character */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
65 Scomment_fence, /* Starts/ends comment which is delimited on the
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
66 other side by a char with the same syntaxcode. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
67 Sstring_fence, /* Starts/ends string which is delimited on the
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
68 other side by a char with the same syntaxcode. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Smax /* Upper bound on codes that are meaningful */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 int *multi_p_out);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
75 void update_syntax_table (Lisp_Object table);
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
76
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
77 DECLARE_INLINE_HEADER (
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
78 void
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
79 update_mirror_syntax_if_dirty (Lisp_Object table)
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
80 )
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
81 {
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
82 if (XCHAR_TABLE (table)->dirty)
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
83 update_syntax_table (table);
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
84 }
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
85
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 /* Return the syntax code for a particular character and mirror table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
88 DECLARE_INLINE_HEADER (
1315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
89 int
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
90 SYNTAX_CODE (Lisp_Object table, Ichar c)
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
91 )
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
92 {
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
93 type_checking_assert (XCHAR_TABLE (table)->mirror_table_p);
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
94 update_mirror_syntax_if_dirty (table);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5552
diff changeset
95 return XFIXNUM (get_char_table_1 (c, table));
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
96 }
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
97
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
98 #ifdef NOT_WORTH_THE_EFFORT
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
99
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
100 /* Same but skip the dirty check. */
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
101
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
102 DECLARE_INLINE_HEADER (
1315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
103 int
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
104 SYNTAX_CODE_1 (Lisp_Object table, Ichar c)
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
105 )
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
106 {
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
107 type_checking_assert (XCHAR_TABLE (table)->mirror_table_p);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5552
diff changeset
108 return (enum syntaxcode) XFIXNUM (get_char_table_1 (c, table));
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
109 }
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
110
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
111 #endif /* NOT_WORTH_THE_EFFORT */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
114
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
117 DECLARE_INLINE_HEADER (
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
118 int
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
119 WORD_SYNTAX_P (Lisp_Object table, Ichar c)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
120 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 return SYNTAX (table, c) == Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
125 /* OK, here's a graphic diagram of the format of the syntax values.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
126 Here, the value has already been extracted from the Lisp integer,
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
127 so there are no tag bits to worry about.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 Bit number:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 [ 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 [ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 ]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
134 | <-----------> <-------------> <-------------> ^ <----------->
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
135 | unused |comment bits | unused | syntax code
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
136 v | | | | | | | | |
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
137 unusable | | | | | | | | |
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
138 due to | | | | | | | | |
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
139 type tag | | | | | | | | `--> prefix flag
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
140 in Lisp | | | | | | | |
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
141 integer | | | | | | | `--> comment end style B, second char
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 | | | | | | `----> comment end style A, second char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 | | | | | `------> comment end style B, first char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 | | | | `--------> comment end style A, first char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 | | | `----------> comment start style B, second char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 | | `------------> comment start style A, second char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 | `--------------> comment start style B, first char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 `----------------> comment start style A, first char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 In a 64-bit integer, there would be 32 more unused bits between
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
151 the unusable bit and the comment bits.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
153 In older versions of XEmacs, bits 8-14 contained the matching
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
154 character for parentheses. Such a scheme will not work for Mule,
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
155 because the matching parenthesis could be any character and
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
156 requires 21 bits, which we don't have on a 32-bit platform.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
158 What we do is use another char table for the matching parenthesis
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 and store a pointer to it in the first char table. (This frees
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 code from having to worry about passing two tables around.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
164 /* The prefix flag bit for backward-prefix-chars is in bit 7. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 #define SYNTAX_PREFIX(table, c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ((SYNTAX_CODE (table, c) >> 7) & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 /* Bits 23-16 are used to implement up to two comment styles
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 in a single buffer. They have the following meanings:
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
171 bit
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
172 23 first of a one or two character comment-start sequence of style a.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
173 22 first of a one or two character comment-start sequence of style b.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
174 21 second of a two-character comment-start sequence of style a.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
175 20 second of a two-character comment-start sequence of style b.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
176 19 first of a one or two character comment-end sequence of style a.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
177 18 first of a one or two character comment-end sequence of style b.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
178 17 second of a two-character comment-end sequence of style a.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
179 16 second of a two-character comment-end sequence of style b.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 #define SYNTAX_COMMENT_BITS(table, c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ((SYNTAX_CODE (table, c) >> 16) &0xff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 #define SYNTAX_FIRST_OF_START_A 0x80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 #define SYNTAX_FIRST_OF_START_B 0x40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 #define SYNTAX_SECOND_OF_START_A 0x20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 #define SYNTAX_SECOND_OF_START_B 0x10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 #define SYNTAX_FIRST_OF_END_A 0x08
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 #define SYNTAX_FIRST_OF_END_B 0x04
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 #define SYNTAX_SECOND_OF_END_A 0x02
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 #define SYNTAX_SECOND_OF_END_B 0x01
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 #define SYNTAX_COMMENT_STYLE_A 0xaa
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 #define SYNTAX_COMMENT_STYLE_B 0x55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 #define SYNTAX_FIRST_CHAR_START 0xc0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 #define SYNTAX_FIRST_CHAR_END 0x0c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 #define SYNTAX_FIRST_CHAR 0xcc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 #define SYNTAX_SECOND_CHAR_START 0x30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 #define SYNTAX_SECOND_CHAR_END 0x03
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 #define SYNTAX_SECOND_CHAR 0x33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
203 /* Array of syntax codes, indexed by characters which designate them.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
204 Designators must be ASCII characters (ie, in the range 0x00-0x7F).
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
205 Bounds checking is the responsibility of calling code. */
5542
dab422055bab Correct array bound for syntax_code_spec.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
206 extern const unsigned char syntax_spec_code[0200];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
208 /* Array of designators indexed by syntax code.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
209 Indicies should be of type enum syntaxcode. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
210 extern const unsigned char syntax_code_spec[];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 460
diff changeset
212 Lisp_Object scan_lists (struct buffer *buf, Charbpos from, int count,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 int depth, int sexpflag, int no_error);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 460
diff changeset
214 int char_quoted (struct buffer *buf, Charbpos pos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
216 /* TABLE is a syntax table, not the mirror table. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
217 Lisp_Object syntax_match (Lisp_Object table, Ichar ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 extern int no_quit_in_re_search;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
220
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
221
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
222 /****************************** syntax caches ********************************/
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
223
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
224 extern int lookup_syntax_properties;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
225
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
226 /* The `syntax-table' property overrides the syntax table or directly
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
227 specifies the syntax. Since looking up properties is expensive, we cache
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
228 the information about the syntax-table property. When moving linearly
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
229 through text (e.g. in the regex routines or the scanning routines in
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
230 syntax.c), recalculation is needed only when the syntax-table property
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
231 changes (i.e. not every position).
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
232 When we do need to recalculate, we can update the info from the previous
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
233 info faster than if we did the whole calculation from scratch.
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
234 #### sjt sez: I'm not sure I believe that last claim. That seems to
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
235 require that we use directional information, etc, but that is ignored in
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
236 the current implementation. */
5552
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
237
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
238 enum syntax_source { syntax_source_property_code = 0,
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
239 syntax_source_property_table = 1,
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
240 syntax_source_buffer_table = 2 };
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
241 #define SOURCE_IS_TABLE(source) (source)
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
242
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
243 struct syntax_cache
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
244 {
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
245 #ifdef NEW_GC
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5120
diff changeset
246 NORMAL_LISP_OBJECT_HEADER header;
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
247 #endif /* NEW_GC */
5552
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
248 enum syntax_source source; /* Source of syntax information: the buffer's
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
249 syntax table, a syntax table specified by
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
250 a syntax-table property, or a syntax code
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
251 specified by a syntax-table property. */
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
252 Lisp_Object object; /* The buffer or string the current syntax
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
253 cache applies to, or Qnil for a string of
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
254 text not coming from a buffer or string. */
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
255 struct buffer *buffer; /* The buffer that supplies the syntax tables,
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
256 or NULL for the standard syntax table. If
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
257 OBJECT is a buffer, this will always be
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
258 the same buffer. */
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
259 int syntax_code; /* Syntax code of current char. */
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
260 Lisp_Object syntax_table; /* Syntax table for current pos. */
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
261 Lisp_Object mirror_table; /* Mirror table for this table. */
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
262 Lisp_Object start, end; /* Markers to keep track of the known region
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
263 in a buffer.
5552
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
264 Both are Qnil if object is a string.
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
265 Normally these correspond to prev_change
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
266 and next_change, respectively, except when
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
267 insertions and deletions occur. Then
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
268 prev_change and next change will be
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
269 refreshed from these markers. See
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
270 signal_syntax_cache_extent_adjust().
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
271 We'd like to use an extent, but it seems
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
272 that having an extent over the entire
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
273 buffer causes serious slowdowns in extent
5552
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
274 operations! Yuck!
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
275 #### May not be true any more. */
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
276 Charxpos next_change; /* Position of the next extent change. */
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
277 Charxpos prev_change; /* Position of the previous extent change. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
278 };
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
279
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
280 #ifdef NEW_GC
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
281 typedef struct syntax_cache Lisp_Syntax_Cache;
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
282
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 3498
diff changeset
283 DECLARE_LISP_OBJECT (syntax_cache, Lisp_Syntax_Cache);
3092
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
284
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
285 #define XSYNTAX_CACHE(x) \
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
286 XRECORD (x, syntax_cache, Lisp_Syntax_Cache)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
287 #define wrap_syntax_cache(p) wrap_record (p, syntax_cache)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
288 #define SYNTAX_CACHE_P(x) RECORDP (x, syntax_cache)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
289 #define CHECK_SYNTAX_CACHE(x) CHECK_RECORD (x, syntax_cache)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
290 #define CONCHECK_SYNTAX_CACHE(x) CONCHECK_RECORD (x, syntax_cache)
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
291 #endif /* NEW_GC */
141c2920ea48 [xemacs-hg @ 2005-11-25 01:41:31 by crestani]
crestani
parents: 1315
diff changeset
292
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
293 extern const struct sized_memory_description syntax_cache_description;
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
294
5544
c2301b2c88c8 Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5542
diff changeset
295 /* Note that the external interface to the syntax cache uses charpos's, but
3250
2b8bb4938bb4 [xemacs-hg @ 2006-02-21 11:33:41 by stephent]
stephent
parents: 3092
diff changeset
296 internally we use bytepos's, for speed. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
297 void update_syntax_cache (struct syntax_cache *cache, Charxpos pos, int count);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
298 struct syntax_cache *setup_syntax_cache (struct syntax_cache *cache,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
299 Lisp_Object object,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
300 struct buffer *buffer,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
301 Charxpos from, int count);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
302 struct syntax_cache *setup_buffer_syntax_cache (struct buffer *buffer,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
303 Charxpos from, int count);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
304
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
305 /* Make syntax cache state good for CHARPOS, assuming it is
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
306 currently good for a position before CHARPOS. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
307 DECLARE_INLINE_HEADER (
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
308 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
309 UPDATE_SYNTAX_CACHE_FORWARD (struct syntax_cache *cache, Charxpos pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
310 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
311 {
1315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
312 /* #### Formerly this function, and the next one, had
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
313
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
314 if (pos < cache->prev_change || pos >= cache->next_change)
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
316 just like for plain UPDATE_SYNTAX_CACHE. However, sometimes the
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
317 value of POS may be invalid (particularly, it may be 0 for a buffer).
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
318 FSF has the check at only one end, so let's try the same. */
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
319 if (pos >= cache->next_change)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
320 update_syntax_cache (cache, pos, 1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
321 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
322
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
323 /* Make syntax cache state good for CHARPOS, assuming it is
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
324 currently good for a position after CHARPOS. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
325 DECLARE_INLINE_HEADER (
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
326 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
327 UPDATE_SYNTAX_CACHE_BACKWARD (struct syntax_cache *cache, Charxpos pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
328 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
329 {
1315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
330 if (pos < cache->prev_change)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
331 update_syntax_cache (cache, pos, -1);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
332 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
333
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
334 /* Make syntax cache state good for CHARPOS */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
335 DECLARE_INLINE_HEADER (
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
336 void
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
337 UPDATE_SYNTAX_CACHE (struct syntax_cache *cache, Charxpos pos)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
338 )
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
339 {
1315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1296
diff changeset
340 if (pos < cache->prev_change || pos >= cache->next_change)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
341 update_syntax_cache (cache, pos, 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
342 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
343
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
344 #define SYNTAX_FROM_CACHE(cache, c) \
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
345 SYNTAX_FROM_CODE (SYNTAX_CODE_FROM_CACHE (cache, c))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
346
5552
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
347 #define SYNTAX_CODE_FROM_CACHE(cache, c) \
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
348 (SOURCE_IS_TABLE ((cache)->source) \
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
349 ? SYNTAX_CODE ((cache)->mirror_table, c) \
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
350 : (cache)->syntax_code)
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
351
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
352 #ifdef NOT_WORTH_THE_EFFORT
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
353 /* If we really cared about the theoretical performance hit of the dirty
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
354 check in SYNTAX_CODE, we could use SYNTAX_CODE_1 and endeavor to always
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
355 keep the mirror table clean, e.g. by checking for dirtiness at the time
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
356 we set up the syntax cache. There are lots of potential problems, of
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
357 course -- incomplete understanding of the possible pathways into the
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
358 code, with some that are bypassing the setups, Lisp code being executed
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
359 in the meantime that could change things (e.g. QUIT is called in many
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
360 functions and could execute arbitrary Lisp very easily), etc. The QUIT
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
361 problem is the biggest one, probably, and one of the main reasons it's
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
362 probably just not worth it. */
5552
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
363 #define SYNTAX_CODE_FROM_CACHE(cache, c) \
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
364 (SOURCE_IS_TABLE ((cache)->source) \
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
365 ? SYNTAX_CODE_1 ((cache)->mirror_table, c) \
85210c453a97 Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5544
diff changeset
366 : (cache)->syntax_code)
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
367 #endif
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
368
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
369
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 793
diff changeset
370 /***************************** syntax code macros ****************************/
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
371
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
372 #define SYNTAX_CODE_PREFIX(c) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
373 ((c >> 7) & 1)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
374
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
375 #define SYNTAX_CODE_COMMENT_BITS(c) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
376 ((c >> 16) &0xff)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
377
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
378 #define SYNTAX_CODES_START_P(a, b) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
379 (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START) >> 2) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
380 & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_START))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
381
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
382 #define SYNTAX_CODES_END_P(a, b) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
383 (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END) >> 2) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
384 & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
385
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
386 #define SYNTAX_CODES_COMMENT_MASK_START(a, b) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
387 (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_A) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
388 ? SYNTAX_COMMENT_STYLE_A \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
389 : (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_B) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
390 ? SYNTAX_COMMENT_STYLE_B \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
391 : 0))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
392 #define SYNTAX_CODES_COMMENT_MASK_END(a, b) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
393 (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_A) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
394 ? SYNTAX_COMMENT_STYLE_A \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
395 : (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_B) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
396 ? SYNTAX_COMMENT_STYLE_B \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
397 : 0))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
398
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
399 #define SYNTAX_CODE_START_FIRST_P(a) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
400 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
401
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
402 #define SYNTAX_CODE_START_SECOND_P(a) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
403 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_START)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
404
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
405 #define SYNTAX_CODE_END_FIRST_P(a) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
406 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
407
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
408 #define SYNTAX_CODE_END_SECOND_P(a) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
409 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_END)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
410
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
411
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
412 #define SYNTAX_CODES_MATCH_START_P(a, b, mask) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
413 ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START & (mask)) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
414 && (SYNTAX_CODE_COMMENT_BITS (b) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
415 & SYNTAX_SECOND_CHAR_START & (mask)))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
416
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
417 #define SYNTAX_CODES_MATCH_END_P(a, b, mask) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
418 ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END & (mask)) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
419 && (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END & (mask)))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
420
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
421 #define SYNTAX_CODE_MATCHES_1CHAR_P(a, mask) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
422 ((SYNTAX_CODE_COMMENT_BITS (a) & (mask)))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
423
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
424 #define SYNTAX_CODE_COMMENT_1CHAR_MASK(a) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
425 ((SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_A) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
426 ? SYNTAX_COMMENT_STYLE_A \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
427 : (SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_B) \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
428 ? SYNTAX_COMMENT_STYLE_B \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
429 : 0)))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
430
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
431
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
432 #endif /* INCLUDED_syntax_h_ */