aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2019-07-26 17:48:45 +0000
committerAlan Mackenzie2019-07-26 17:48:45 +0000
commitaabb844e45642d6bf80673159dae18f4ea3693e4 (patch)
treec376994d217785cb6e1739c72c2393c4dcad0172
parent2260483560963fa490ae5ce55ff55f0ceaae379d (diff)
downloademacs-aabb844e45642d6bf80673159dae18f4ea3693e4.tar.gz
emacs-aabb844e45642d6bf80673159dae18f4ea3693e4.zip
CC Mode. Create lang vars for certain skipping expressions at compile time
This saves repeated calculations at run time. * lisp/progmodes/cc-langs.el (c-stmt-boundary-skip-chars) (c-stmt-boundary-skip-list, c-stmt-boundary-skip-chars-with-comma) (c-stmt-boundary-skip-list-with-comma): New lang constants/variables. * lisp/progmodes/cc-engine.el (c-commas-bound-stmts): New variable (c-beginning-of-statement-1): Set c-commas-bound-stmts rather than c-stmt-delim-chars. (c-crosses-statement-barrier-p): Remove the now unneeded calculations of c-stmt-delim-chars. Set skip chars to one of the new lang variables, and later to a substring of it. (c-at-statement-start-p): Set c-syntactic-skip-backward from the new variables. (c-at-expression-start-p): Bind c-commas-bound-stmts. Use c-stmt-delim-chars-with-comma rather than c-stmt-delim-chars in a backward scan. (c-guess-basic-syntax): Bind c-commas-bound-stmts rather than c-stmt-delim-chars to itself. Bind c-commas-bound-stmts to t at another place rather than setting c-stmt-delim-chars to c-stmt-delim-chars-with-comma.
-rw-r--r--lisp/progmodes/cc-engine.el52
-rw-r--r--lisp/progmodes/cc-langs.el44
2 files changed, 72 insertions, 24 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index a89528d033c..1ebacb58c7f 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -713,6 +713,10 @@ comment at the start of cc-engine.el for more info."
713;; the byte compiler. 713;; the byte compiler.
714(defvar c-maybe-labelp) 714(defvar c-maybe-labelp)
715 715
716(defvar c-commas-bound-stmts nil)
717 ;; Set to non-nil when `c-beginning-of-statement-1' is to regard a comma as
718 ;; a statement terminator.
719
716;; New awk-compatible version of c-beginning-of-statement-1, ACM 2002/6/22 720;; New awk-compatible version of c-beginning-of-statement-1, ACM 2002/6/22
717 721
718;; Macros used internally in c-beginning-of-statement-1 for the 722;; Macros used internally in c-beginning-of-statement-1 for the
@@ -897,9 +901,7 @@ comment at the start of cc-engine.el for more info."
897 (start (point)) 901 (start (point))
898 macro-start 902 macro-start
899 (delims (if comma-delim '(?\; ?,) '(?\;))) 903 (delims (if comma-delim '(?\; ?,) '(?\;)))
900 (c-stmt-delim-chars (if comma-delim 904 (c-commas-bound-stmts (or c-commas-bound-stmts comma-delim))
901 c-stmt-delim-chars-with-comma
902 c-stmt-delim-chars))
903 c-maybe-labelp after-case:-pos saved 905 c-maybe-labelp after-case:-pos saved
904 ;; Current position. 906 ;; Current position.
905 pos 907 pos
@@ -1422,21 +1424,12 @@ the line. If this virtual semicolon is _at_ from, the function recognizes it.
1422 1424
1423Note that this function might do hidden buffer changes. See the 1425Note that this function might do hidden buffer changes. See the
1424comment at the start of cc-engine.el for more info." 1426comment at the start of cc-engine.el for more info."
1425 (let* ((skip-chars 1427 (let* ((skip-chars (if c-commas-bound-stmts
1426 ;; If the current language has CPP macros, insert # into skip-chars. 1428 c-stmt-boundary-skip-chars-with-comma
1427 (if c-opt-cpp-symbol 1429 c-stmt-boundary-skip-chars)) ; e.g. "^#;{}?:"
1428 (concat (substring c-stmt-delim-chars 0 1) ; "^" 1430 (non-skip-list (if c-commas-bound-stmts
1429 c-opt-cpp-symbol ; usually "#" 1431 c-stmt-boundary-skip-list-with-comma
1430 (substring c-stmt-delim-chars 1)) ; e.g. ";{}?:" 1432 c-stmt-boundary-skip-list)) ; e.g. (?# ?\; ?{ ?} ?? ?:)
1431 c-stmt-delim-chars))
1432 (skip-chars
1433 (if (c-major-mode-is 'c++-mode)
1434 (concat (substring skip-chars 0 1) ; "^"
1435 "[" ; to catch C++ attributes
1436 (substring skip-chars 1)) ; e.g. "#;{}?:"
1437 skip-chars))
1438 (non-skip-list
1439 (append (substring skip-chars 1) nil)) ; e.g. (?# ?\; ?{ ?} ?? ?:)
1440 lit-range lit-start vsemi-pos attr-end) 1433 lit-range lit-start vsemi-pos attr-end)
1441 (save-restriction 1434 (save-restriction
1442 (widen) 1435 (widen)
@@ -1477,7 +1470,11 @@ comment at the start of cc-engine.el for more info."
1477 ;; A question mark. Can't be a label, so stop 1470 ;; A question mark. Can't be a label, so stop
1478 ;; looking for more : and ?. 1471 ;; looking for more : and ?.
1479 (setq c-maybe-labelp nil 1472 (setq c-maybe-labelp nil
1480 skip-chars (substring c-stmt-delim-chars 0 -2))) 1473 skip-chars
1474 (substring (if c-commas-bound-stmts
1475 c-stmt-delim-chars-with-comma
1476 c-stmt-delim-chars)
1477 0 -2)))
1481 ;; At a CPP construct or a "#" or "##" operator? 1478 ;; At a CPP construct or a "#" or "##" operator?
1482 ((and c-opt-cpp-symbol (looking-at c-opt-cpp-symbol)) 1479 ((and c-opt-cpp-symbol (looking-at c-opt-cpp-symbol))
1483 (if (save-excursion 1480 (if (save-excursion
@@ -1513,7 +1510,13 @@ comment at the start of cc-engine.el for more info."
1513 (save-excursion 1510 (save-excursion
1514 (let ((end (point)) 1511 (let ((end (point))
1515 c-maybe-labelp) 1512 c-maybe-labelp)
1516 (c-syntactic-skip-backward (substring c-stmt-delim-chars 1) nil t) 1513 (c-syntactic-skip-backward
1514 (substring
1515 (if c-commas-bound-stmts
1516 c-stmt-delim-chars-with-comma
1517 c-stmt-delim-chars)
1518 1)
1519 nil t)
1517 (or (bobp) 1520 (or (bobp)
1518 (eq (char-before) ?}) 1521 (eq (char-before) ?})
1519 (and (eq (char-before) ?{) 1522 (and (eq (char-before) ?{)
@@ -1540,9 +1543,10 @@ comment at the start of cc-engine.el for more info."
1540 1543
1541 (save-excursion 1544 (save-excursion
1542 (let ((end (point)) 1545 (let ((end (point))
1543 (c-stmt-delim-chars c-stmt-delim-chars-with-comma) 1546 (c-commas-bound-stmts t)
1544 c-maybe-labelp) 1547 c-maybe-labelp)
1545 (c-syntactic-skip-backward (substring c-stmt-delim-chars 1) nil t) 1548 (c-syntactic-skip-backward (substring c-stmt-delim-chars-with-comma 1)
1549 nil t)
1546 (or (bobp) 1550 (or (bobp)
1547 (memq (char-before) '(?{ ?})) 1551 (memq (char-before) '(?{ ?}))
1548 (save-excursion (backward-char) 1552 (save-excursion (backward-char)
@@ -12587,7 +12591,7 @@ comment at the start of cc-engine.el for more info."
12587 ;; There's always at most one syntactic element which got 12591 ;; There's always at most one syntactic element which got
12588 ;; an anchor pos. It's stored in syntactic-relpos. 12592 ;; an anchor pos. It's stored in syntactic-relpos.
12589 syntactic-relpos 12593 syntactic-relpos
12590 (c-stmt-delim-chars c-stmt-delim-chars)) 12594 (c-commas-bound-stmts c-commas-bound-stmts))
12591 12595
12592 ;; Check if we're directly inside an enclosing declaration 12596 ;; Check if we're directly inside an enclosing declaration
12593 ;; level block. 12597 ;; level block.
@@ -12639,7 +12643,7 @@ comment at the start of cc-engine.el for more info."
12639 ;; arglists. 12643 ;; arglists.
12640 (when (and containing-sexp 12644 (when (and containing-sexp
12641 (eq (char-after containing-sexp) ?\()) 12645 (eq (char-after containing-sexp) ?\())
12642 (setq c-stmt-delim-chars c-stmt-delim-chars-with-comma)) 12646 (setq c-commas-bound-stmts t))
12643 ;; cache char before and after indent point, and move point to 12647 ;; cache char before and after indent point, and move point to
12644 ;; the most likely position to perform the majority of tests 12648 ;; the most likely position to perform the majority of tests
12645 (goto-char indent-point) 12649 (goto-char indent-point)
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index a0d4559c207..8a4f8f59515 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1442,12 +1442,56 @@ operators."
1442 t "^;{}?:") 1442 t "^;{}?:")
1443(c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars)) 1443(c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
1444 1444
1445(c-lang-defconst c-stmt-boundary-skip-chars
1446 ;; Like `c-stmt-delim-chars', but augmented by "#" for languages with CPP
1447 ;; constructs, and for C++ Mode, also by "[", to help deal with C++
1448 ;; attributes.
1449 t (if (c-lang-const c-opt-cpp-symbol)
1450 (concat (substring (c-lang-const c-stmt-delim-chars) 0 1) ; "^"
1451 (c-lang-const c-opt-cpp-symbol) ; usually #
1452 (substring (c-lang-const c-stmt-delim-chars) 1)) ; ";{}?:"
1453 (c-lang-const c-stmt-delim-chars))
1454 c++ (concat (substring (c-lang-const c-stmt-boundary-skip-chars) 0 1) ; "^"
1455 "["
1456 (substring (c-lang-const c-stmt-boundary-skip-chars) 1))) ; ";{}?:"
1457(c-lang-defvar c-stmt-boundary-skip-chars
1458 (c-lang-const c-stmt-boundary-skip-chars))
1459
1460(c-lang-defconst c-stmt-boundary-skip-list
1461 ;; The characters (apart from the initial ^) in `c-stmt-boundary-skip-chars'
1462 ;; as a list of characters.
1463 t (append (substring (c-lang-const c-stmt-boundary-skip-chars) 1) nil))
1464(c-lang-defvar c-stmt-boundary-skip-list
1465 (c-lang-const c-stmt-boundary-skip-list))
1466
1445(c-lang-defconst c-stmt-delim-chars-with-comma 1467(c-lang-defconst c-stmt-delim-chars-with-comma
1446 ;; Variant of `c-stmt-delim-chars' that additionally contains ','. 1468 ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
1447 t "^;,{}?:") 1469 t "^;,{}?:")
1448(c-lang-defvar c-stmt-delim-chars-with-comma 1470(c-lang-defvar c-stmt-delim-chars-with-comma
1449 (c-lang-const c-stmt-delim-chars-with-comma)) 1471 (c-lang-const c-stmt-delim-chars-with-comma))
1450 1472
1473(c-lang-defconst c-stmt-boundary-skip-chars-with-comma
1474 ;; Variant of `c-stmt-boundary-skip-chars' also containing ','.
1475 t (if (c-lang-const c-opt-cpp-symbol)
1476 (concat (substring (c-lang-const c-stmt-delim-chars-with-comma) 0 1)
1477 (c-lang-const c-opt-cpp-symbol) ; usually #
1478 (substring (c-lang-const c-stmt-delim-chars-with-comma) 1))
1479 (c-lang-const c-stmt-delim-chars-with-comma))
1480 c++ (concat
1481 (substring (c-lang-const c-stmt-boundary-skip-chars-with-comma) 0 1) ; "^"
1482 "["
1483 (substring (c-lang-const c-stmt-boundary-skip-chars-with-comma) 1))) ; ";,{}?:"
1484(c-lang-defvar c-stmt-boundary-skip-chars-with-comma
1485 (c-lang-const c-stmt-boundary-skip-chars-with-comma))
1486
1487(c-lang-defconst c-stmt-boundary-skip-list-with-comma
1488 ;; Variant of `c-stmt-boundary-skip-list' also including a comma.
1489 t (append (substring (c-lang-const c-stmt-boundary-skip-chars-with-comma)
1490 1)
1491 nil))
1492(c-lang-defvar c-stmt-boundary-skip-list-with-comma
1493 (c-lang-const c-stmt-boundary-skip-list-with-comma))
1494
1451(c-lang-defconst c-pack-ops 1495(c-lang-defconst c-pack-ops
1452 "Ops which signal C++11's \"parameter pack\"" 1496 "Ops which signal C++11's \"parameter pack\""
1453 t nil 1497 t nil