aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorPaul Eggert2011-06-15 11:52:30 -0700
committerPaul Eggert2011-06-15 11:52:30 -0700
commitdfc926249a7d14f037a01acba7a69339661e5107 (patch)
tree4c5eeba568589c013f3df53a779c2bd780cd0675 /lisp/progmodes
parentff672d2c8785de6faba84a400fb8153e9fa07cd2 (diff)
parent8c9b210626493dd93f236d7fb312c4f6dba62892 (diff)
downloademacs-dfc926249a7d14f037a01acba7a69339661e5107.tar.gz
emacs-dfc926249a7d14f037a01acba7a69339661e5107.zip
Merge from trunk.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cc-fonts.el204
1 files changed, 98 insertions, 106 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index c7bb93f73e7..600bbc76e9a 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1045,12 +1045,6 @@ casts and declarations are fontified. Used on level 2 and higher."
1045 ;; The position of the next token after the closing paren of 1045 ;; The position of the next token after the closing paren of
1046 ;; the last detected cast. 1046 ;; the last detected cast.
1047 last-cast-end 1047 last-cast-end
1048 ;; Start of containing declaration (if any); limit for searching
1049 ;; backwards for it.
1050 decl-start decl-search-lim
1051 ;; Start of containing declaration (if any); limit for searching
1052 ;; backwards for it.
1053 decl-start decl-search-lim
1054 ;; The result from `c-forward-decl-or-cast-1'. 1048 ;; The result from `c-forward-decl-or-cast-1'.
1055 decl-or-cast 1049 decl-or-cast
1056 ;; The maximum of the end positions of all the checked type 1050 ;; The maximum of the end positions of all the checked type
@@ -1188,109 +1182,107 @@ casts and declarations are fontified. Used on level 2 and higher."
1188 (setq decl-or-cast (c-forward-decl-or-cast-1 1182 (setq decl-or-cast (c-forward-decl-or-cast-1
1189 match-pos context last-cast-end)) 1183 match-pos context last-cast-end))
1190 1184
1191 (if (not decl-or-cast) 1185 (cond
1192 ;; Are we at a declarator? Try to go back to the declaration 1186 ((eq decl-or-cast 'cast)
1193 ;; to check this. Note that `c-beginning-of-decl-1' is slow, 1187 ;; Save the position after the previous cast so we can feed
1194 ;; so we cache its result between calls. 1188 ;; it to `c-forward-decl-or-cast-1' in the next round. That
1195 (let (paren-state bod-res encl-pos is-typedef) 1189 ;; helps it discover cast chains like "(a) (b) c".
1196 (goto-char start-pos) 1190 (setq last-cast-end (point))
1197 (save-excursion 1191 (c-fontify-recorded-types-and-refs)
1198 (unless (and decl-search-lim 1192 nil)
1199 (eq decl-search-lim
1200 (save-excursion
1201 (c-syntactic-skip-backward "^;" nil t)
1202 (point))))
1203 (setq decl-search-lim
1204 (and (c-syntactic-skip-backward "^;" nil t) (point)))
1205 (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim)))
1206 (if (and (eq bod-res 'same)
1207 (progn
1208 (c-backward-syntactic-ws)
1209 (eq (char-before) ?\})))
1210 (c-beginning-of-decl-1 decl-search-lim))
1211 (setq decl-start (point))))
1212 1193
1194 (decl-or-cast
1195 ;; We've found a declaration.
1196
1197 ;; Set `max-type-decl-end' or `max-type-decl-end-before-token'
1198 ;; under the assumption that we're after the first type decl
1199 ;; expression in the declaration now. That's not really true;
1200 ;; we could also be after a parenthesized initializer
1201 ;; expression in C++, but this is only used as a last resort
1202 ;; to slant ambiguous expression/declarations, and overall
1203 ;; it's worth the risk to occasionally fontify an expression
1204 ;; as a declaration in an initializer expression compared to
1205 ;; getting ambiguous things in normal function prototypes
1206 ;; fontified as expressions.
1207 (if inside-macro
1208 (when (> (point) max-type-decl-end-before-token)
1209 (setq max-type-decl-end-before-token (point)))
1210 (when (> (point) max-type-decl-end)
1211 (setq max-type-decl-end (point))))
1212
1213 ;; Back up to the type to fontify the declarator(s).
1214 (goto-char (car decl-or-cast))
1215
1216 (let ((decl-list
1217 (if context
1218 ;; Should normally not fontify a list of
1219 ;; declarators inside an arglist, but the first
1220 ;; argument in the ';' separated list of a "for"
1221 ;; statement is an exception.
1222 (when (eq (char-before match-pos) ?\()
1223 (save-excursion
1224 (goto-char (1- match-pos))
1225 (c-backward-syntactic-ws)
1226 (and (c-simple-skip-symbol-backward)
1227 (looking-at c-paren-stmt-key))))
1228 t)))
1229
1230 ;; Fix the `c-decl-id-start' or `c-decl-type-start' property
1231 ;; before the first declarator if it's a list.
1232 ;; `c-font-lock-declarators' handles the rest.
1233 (when decl-list
1213 (save-excursion 1234 (save-excursion
1214 (goto-char decl-start) 1235 (c-backward-syntactic-ws)
1215 ;; We're now putatively at the declaration. 1236 (unless (bobp)
1216 (setq paren-state (c-parse-state)) 1237 (c-put-char-property (1- (point)) 'c-type
1217 ;; At top level or inside a "{"? 1238 (if (cdr decl-or-cast)
1218 (if (or (not (setq encl-pos 1239 'c-decl-type-start
1219 (c-most-enclosing-brace paren-state))) 1240 'c-decl-id-start)))))
1220 (eq (char-after encl-pos) ?\{)) 1241
1221 (progn 1242 (c-font-lock-declarators
1222 (when (looking-at c-typedef-key) ; "typedef" 1243 (point-max) decl-list (cdr decl-or-cast)))
1223 (setq is-typedef t) 1244
1224 (goto-char (match-end 0)) 1245 ;; A declaration has been successfully identified, so do all the
1225 (c-forward-syntactic-ws)) 1246 ;; fontification of types and refs that've been recorded.
1226 ;; At a real declaration?
1227 (if (memq (c-forward-type t) '(t known found))
1228 (progn
1229 (c-font-lock-declarators limit t is-typedef)
1230 nil)
1231 ;; False alarm. Return t to go on to the next check.
1232 (goto-char start-pos)
1233 t))
1234 t)))
1235
1236 (if (eq decl-or-cast 'cast)
1237 ;; Save the position after the previous cast so we can feed
1238 ;; it to `c-forward-decl-or-cast-1' in the next round. That
1239 ;; helps it discover cast chains like "(a) (b) c".
1240 (setq last-cast-end (point))
1241
1242 ;; Set `max-type-decl-end' or `max-type-decl-end-before-token'
1243 ;; under the assumption that we're after the first type decl
1244 ;; expression in the declaration now. That's not really true;
1245 ;; we could also be after a parenthesized initializer
1246 ;; expression in C++, but this is only used as a last resort
1247 ;; to slant ambiguous expression/declarations, and overall
1248 ;; it's worth the risk to occasionally fontify an expression
1249 ;; as a declaration in an initializer expression compared to
1250 ;; getting ambiguous things in normal function prototypes
1251 ;; fontified as expressions.
1252 (if inside-macro
1253 (when (> (point) max-type-decl-end-before-token)
1254 (setq max-type-decl-end-before-token (point)))
1255 (when (> (point) max-type-decl-end)
1256 (setq max-type-decl-end (point))))
1257
1258 ;; Back up to the type to fontify the declarator(s).
1259 (goto-char (car decl-or-cast))
1260
1261 (let ((decl-list
1262 (if context
1263 ;; Should normally not fontify a list of
1264 ;; declarators inside an arglist, but the first
1265 ;; argument in the ';' separated list of a "for"
1266 ;; statement is an exception.
1267 (when (eq (char-before match-pos) ?\()
1268 (save-excursion
1269 (goto-char (1- match-pos))
1270 (c-backward-syntactic-ws)
1271 (and (c-simple-skip-symbol-backward)
1272 (looking-at c-paren-stmt-key))))
1273 t)))
1274
1275 ;; Fix the `c-decl-id-start' or `c-decl-type-start' property
1276 ;; before the first declarator if it's a list.
1277 ;; `c-font-lock-declarators' handles the rest.
1278 (when decl-list
1279 (save-excursion
1280 (c-backward-syntactic-ws)
1281 (unless (bobp)
1282 (c-put-char-property (1- (point)) 'c-type
1283 (if (cdr decl-or-cast)
1284 'c-decl-type-start
1285 'c-decl-id-start)))))
1286
1287 (c-font-lock-declarators
1288 (point-max) decl-list (cdr decl-or-cast))))
1289
1290 ;; A cast or declaration has been successfully identified, so do
1291 ;; all the fontification of types and refs that's been recorded.
1292 (c-fontify-recorded-types-and-refs) 1247 (c-fontify-recorded-types-and-refs)
1293 nil)) 1248 nil)
1249
1250 (t
1251 ;; Are we at a declarator? Try to go back to the declaration
1252 ;; to check this. If we get there, check whether a "typedef"
1253 ;; is there, then fontify the declarators accordingly.
1254 (let ((decl-search-lim (max (- (point) 50000) (point-min)))
1255 paren-state bod-res encl-pos is-typedef
1256 c-recognize-knr-p) ; Strictly speaking, bogus, but it
1257 ; speeds up lisp.h tremendously.
1258 (save-excursion
1259 (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim)))
1260 (if (and (eq bod-res 'same)
1261 (progn
1262 (c-backward-syntactic-ws)
1263 (eq (char-before) ?\})))
1264 (c-beginning-of-decl-1 decl-search-lim))
1265
1266 ;; We're now putatively at the declaration.
1267 (setq paren-state (c-parse-state))
1268 ;; At top level or inside a "{"?
1269 (if (or (not (setq encl-pos
1270 (c-most-enclosing-brace paren-state)))
1271 (eq (char-after encl-pos) ?\{))
1272 (progn
1273 (when (looking-at c-typedef-key) ; "typedef"
1274 (setq is-typedef t)
1275 (goto-char (match-end 0))
1276 (c-forward-syntactic-ws))
1277 ;; At a real declaration?
1278 (if (memq (c-forward-type t) '(t known found))
1279 (progn
1280 (c-font-lock-declarators limit t is-typedef)
1281 nil)
1282 ;; False alarm. Return t to go on to the next check.
1283 (goto-char start-pos)
1284 t))
1285 t))))))
1294 1286
1295 ;; It was a false alarm. Check if we're in a label (or other 1287 ;; It was a false alarm. Check if we're in a label (or other
1296 ;; construct with `:' except bitfield) instead. 1288 ;; construct with `:' except bitfield) instead.