1 ;;; cc-engine-2.el --- Extensuions to cc-engine.el
5 ;; Copyright (C) 2000 Stefan Bund
7 ;; cc-engine-2.el is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation; either version 2, or (at
10 ;; your option) any later version.
12 ;; cc-engine-2.el is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
26 (defconst c-template-arglist-syntax
27 (let ((table (copy-syntax-table c-mode-syntax-table)))
28 (modify-syntax-entry ?< "(" table)
29 (modify-syntax-entry ?> ")" table)
34 (concat (regexp-opt '("break" "continue" "do" "else" "for" "if"
35 "return" "switch" "while" "sizeof" "typedef"
36 "extern" "auto" "register" "static" "friend"
37 "volatile" "const" "restrict" "enum"
38 "struct" "union" "class" "char" "short"
39 "int" "long" "signed" "unsigned" "float"
40 "double" "void" "complex" "case" "goto"
41 "inline" "try" "catch" "throw" "inline_"
42 "throw_" "virtual" "new" "delete" "explicit"
43 "prefix_" "typename" "template") t)
46 (defconst c-blocking-key
48 (concat (regexp-opt '("if" "while" "for" "switch")) "\\b[^_]")))
50 (defconst c-class-scope-key "\\(class\\|struct\\|union\\)\\b[^_]")
51 (defconst c-namespace-scope-key "namespace\\b[^_]")
52 (defconst c-scope-key "\\(class\\|struct\\|union\\|namespace\\)");\\b[^_]")
53 (defconst c-struct-scope-key "struct\\b[^_]")
54 (defconst c-template-key "template\\b[^_]")
55 (defconst c-operator-key "operator\\b[^_]")
56 (defconst c-operator-operators nil)
57 (defconst c-typedef-key "typedef\\b[^_]")
58 (defconst c-friend-key "friend\\b[^_]")
59 (defconst c-access-key "\\(public\\|protected\\|private\\)\\s-*:")
60 (defconst c-access-keys
61 '(("public\\s-*:" . public)
62 ("protected\\s-*:" . protected)
63 ("private\\s-*:" . private)))
64 (defconst c-inheritance-spec-key "\\(public\\|protected\\|private\\|virtual\\)\\b[^_]")
66 (let ((assable '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" ">>" "<<"))
67 (others '("&&" "||" "++" "--" "->*" "," "->" "[]" "()" "new" "new[]"
68 "delete" "delete[]" "bool")))
69 (setq c-operator-operators
70 (regexp-opt (nconc (mapcar (function (lambda (x) (concat x "=")))
74 (defconst c-operator-word
75 (concat "operator\\s-*" c-operator-operators))
77 (defconst c-skip-syntaxes '(? ?. ?'))
86 (defmacro c-with-temporary-syntax-table (table &rest body)
87 ;; evaluate BODY temporarily binding the syntax table to TABLE
88 (let ((saved-syntax-table (make-symbol "saved-syntax-table")))
89 `(let ((,saved-syntax-table (syntax-table)))
92 (set-syntax-table ,table)
94 (set-syntax-table ,saved-syntax-table)))))
96 (def-edebug-spec c-with-temporary-syntax-table (sexp body))
97 (put 'c-with-temporary-syntax-table 'lisp-indent-function 1)
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100 ;; moving by syntactic entities
102 (defun c-skip-non-sexp-chars-forward ()
103 ;; skip char's not considered part of sexps forward
104 (c-forward-syntactic-ws)
105 (while (and (not (eq (following-char) ?<))
106 (memq (char-syntax (following-char)) c-skip-syntaxes)
109 (c-forward-syntactic-ws)))
111 (defun c-skip-non-sexp-chars-backward ()
112 ;; skip char's not considered part of sexps backward
113 (c-backward-syntactic-ws)
114 (while (and (not (eq (preceding-char) ?>))
115 (memq (char-syntax (preceding-char)) c-skip-syntaxes)
118 (c-backward-syntactic-ws)))
120 ;; support for teplate arglists
122 (defun c-forward-template-arglist ()
123 ;; skip forward over the <> delimited template arglist at
124 ;; point. This temporarily changes the syntax-table to include <> as
125 ;; matching delimiters and uses c-forward-sexp
126 (c-skip-non-sexp-chars-forward)
127 (if (not (eq (following-char) ?<))
131 (while (and (> level 0)
132 (re-search-forward "[[({<>]" nil t))
133 (if (not (c-in-literal))
134 (cond ((memq (preceding-char) '(?\[ ?\( ?{))
137 ((eq (preceding-char) ?<)
138 (setq level (1+ level)))
140 ((eq (preceding-char) ?>)
141 (setq level (1- level)))))))))
143 (defun c-backward-template-arglist ()
144 ;; reverse of c-forward-template-arglist
145 (c-skip-non-sexp-chars-backward)
146 (if (not (eq (preceding-char) ?>))
150 (while (and (> level 0)
151 (re-search-backward "[])}<>]" nil t))
152 (if (not (c-in-literal))
153 (cond ((memq (following-char) '(?\] ?\) ?}))
156 ((eq (following-char) ?>)
157 (setq level (1+ level)))
159 ((eq (following-char) ?<)
160 (setq level (1- level)))))))))
162 (defsubst c-at-symbol-p ()
163 (memq (char-syntax (following-char)) '(?w ?_)))
165 (defsubst c-after-symbol-p ()
166 (memq (char-syntax (preceding-char)) '(?w ?_)))
168 (defun c-forward-extended-sexp ()
169 ;; Move forward one sexp. This function tries to correctly skip
170 ;; template argument lists delimited by angle brackets.
171 (c-skip-non-sexp-chars-forward)
172 (if (and (eq (following-char) ?<)
174 (let ((start (point)))
175 (c-forward-template-arglist)
176 (if (or (not (eq (preceding-char) ?>))
177 (c-crosses-statement-barrier-p start (point)))
178 (progn (goto-char start) nil) t))
183 (defun c-backward-extended-sexp ()
184 ;; reverse of c-forward-extenden-sexp
185 (c-skip-non-sexp-chars-backward)
186 (if (and (eq (preceding-char) ?>)
188 (let ((start (point)))
189 (c-backward-template-arglist)
190 (if (or (not (eq (following-char) ?<))
191 (c-crosses-statement-barrier-p (point) start))
192 (progn (goto-char start) nil) t))
199 (defun c-forward-scoped-name ()
200 ;; skip forward over a possibly fully scoped name at point
201 ;; optionally containing template arglists. return list of scope
202 ;; separators in the name
203 (c-forward-syntactic-ws)
207 (setq points (cons (point) points))
208 (if (looking-at "::")
210 (c-forward-syntactic-ws)
211 (if (and (cond ((looking-at c-operator-word)
212 (goto-char (match-end 0)))
217 (c-forward-token-1)))
221 (c-forward-token-1))))
222 (eq (following-char) ?<))
224 (c-forward-template-arglist)
225 (c-forward-syntactic-ws)))
229 (defun c-backward-scoped-name ()
230 ;; reverse of c-forward-scoped-name
231 (c-backward-syntactic-ws)
234 (if (and (eq (preceding-char) ?>)
236 (re-search-backward (concat c-operator-word "\\=") nil t))))
237 (c-backward-template-arglist))
238 (c-backward-syntactic-ws)
239 (if (re-search-backward (concat c-operator-word "\\=") nil t)
240 (goto-char (match-beginning 0))
242 (if (and (c-at-symbol-p)
243 (eq (preceding-char) ?~))
245 (c-backward-syntactic-ws)
246 (if (eq (preceding-char) ?:)
249 (if (eq (preceding-char) ?:)
252 (c-backward-syntactic-ws)
256 (c-forward-syntactic-ws))
258 (defun c-forward-balanced-token ()
259 (c-forward-syntactic-ws)
260 (cond ((or (c-at-symbol-p)
261 (looking-at c-operator-word))
262 (c-forward-scoped-name))
263 ((memq (following-char) '(?\( ?{ ?<))
264 (c-forward-extended-sexp))
266 (c-forward-token-1))))
268 (defun c-backward-balanced-token ()
269 (c-backward-syntactic-ws)
270 (cond ((or (c-after-symbol-p)
271 (re-search-backward (concat c-operator-word "\\=") nil t))
272 (c-backward-scoped-name))
273 ((memq (preceding-char) '(?\) ?} ?>))
274 (c-backward-extended-sexp))
276 (c-backward-token-1))))
280 (defun c-move-to-start-of-defun (&optional limit)
281 ;; move point to start of current defun. point is left at the start
282 ;; of the function's name. Use (c-beginning-of-statement-1) to get
283 ;; to the start of the declaration. returns point of body's opening
284 ;; brace if defun found, otherwise nil. if LIMIT is non-nil, don't
285 ;; move farther back than that.
286 (let (new-point brace-point)
289 (and (c-save-uplist -1)
293 (if (and (eq (following-char) ?{)
294 (c-just-after-func-arglist-p))
296 (setq brace-point (point))
297 (c-beginning-of-statement-1)
298 (while (and (< (point) brace-point)
299 (not (eq (following-char) ?\()))
300 (c-forward-extended-sexp)
301 (c-forward-syntactic-ws))
302 (if (eq (following-char) ?\()
304 (c-backward-syntactic-ws)
305 (c-backward-scoped-name)
306 (if (not (looking-at c-conditional-key))
309 (goto-char new-point))
310 (and new-point brace-point)))
312 (defun c-beginning-of-defun-or-decl ()
313 (c-move-to-start-of-defun)
314 (let ((point (point)) beg)
315 (c-beginning-of-statement-1)
317 (c-end-of-statement-1)
318 (if (> (point) point)
321 (c-forward-syntactic-ws)))
323 (defun c-forward-out-of-comment ()
324 (while (memq (c-in-literal) '(c c++))
327 (defun c-beginning-of-statement-2 ()
328 ;; Move to the REAL beginning of the statement, ignoring all subexpressions
329 (let ((point (point))
330 (state (c-parse-state))
333 (not (consp (car state)))
335 (goto-char (car state))
337 (setq last (car state)
340 (not (consp (car state))))
342 (c-beginning-of-statement-1)
343 (while (and (< (point) point)
344 (or (c-crosses-statement-barrier-p (point) point)
345 (not (equal (c-parse-state) state))))
346 (c-end-of-statement-1))
347 (c-forward-syntactic-ws)
348 (while (looking-at c-any-key)
349 (if (looking-at c-blocking-key)
354 (c-forward-syntactic-ws))))
356 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
357 ;; information on scopes (nesting levels)
359 (defun c-aggressive-search-uplist-for-classkey ()
360 ;; like search-uplist-for-classkey but agressively retry at all
361 ;; scoping levels until classkey found
364 (loop for state = (c-parse-state)
366 thereis (loop for substate on state
367 thereis (c-search-uplist-for-classkey substate))
368 for elt = (car (last state))
369 do (goto-char (if (consp elt) (car elt) elt))))))
371 (defun c-search-uplist-for-scopekey (state)
372 (let ((c-class-key c-scope-key))
373 (c-search-uplist-for-classkey state)))
375 (defun c-aggressive-search-uplist-for-scopekey ()
376 (let ((c-class-key c-scope-key))
377 (c-aggressive-search-uplist-for-classkey)))
379 (defun c-save-uplist (arg)
380 ;; like up-list but return nil on error
387 (defun c-full-parse-state ()
388 ;; return the complete parse-state from the beginning of buffer up
392 (while (setq s (c-parse-state)
394 (goto-char (if (consp elt) (car elt) elt))
395 (setq state (nconc state s)))
398 (defun c-get-block-scope ()
399 ;; return a list of scoping levels for point. Every scoping level is
400 ;; identified by thier 'class for a class scope, or 'namespace for a
401 ;; namespace scope For 'class and 'struct scopes, optional template
402 ;; declarations are returned.
404 (let (key element keys)
405 (while (setq key (c-aggressive-search-uplist-for-scopekey))
406 (goto-char (aref key 0))
407 (setq element (vector nil
411 (cond ((looking-at c-class-scope-key)
412 (aset element 0 'class)
413 (c-backward-syntactic-ws)
414 (if (eq (preceding-char) ?>)
415 ;; this is a templated class/struct declaration
417 (c-backward-template-arglist)
419 (if (looking-at c-template-key)
420 (aset element 3 (point))))))
422 ((looking-at c-namespace-scope-key)
423 (aset element 0 'namespace)))
426 (setq keys (cons element keys))))
429 (defun c-get-scope ()
430 ;; This is like c-get-block-scope. Additionaly, if in a function
431 ;; declaration or definition this will add a 'defun entry at the
432 ;; end detailing the function information (and having an optional
433 ;; template spec). The start of the function entry is the first char
434 ;; of the functions typespec, the last char is just after the
435 ;; closing paren of the function defn or decl.
436 (let ((scope (c-get-block-scope)))
438 (if (c-move-to-start-of-defun (and scope (aref (car (last scope)) 1)))
439 (let ((element (vector 'defun (point) nil nil)))
440 (c-forward-scoped-name)
441 (aset element 2 (point))
442 (c-beginning-of-statement-1)
443 (if (looking-at c-template-key)
444 (aset element 3 (point)))
445 (nconc scope (list element)))
448 (defun c-scope-name (p &optional strip)
449 ;; return the name of the scope at P. if STRIP is non-nil, strip
450 ;; that many elements from the name
453 (if (looking-at c-scope-key)
455 (let ((points (c-forward-scoped-name)))
456 (c-backward-syntactic-ws)
457 (buffer-substring-no-properties (car points)
458 (or (and strip (> strip 0)
459 (or (and (<= strip (length points))
467 (defun c-get-class-at-point ()
468 ;; Return block scope for class at point.
470 (c-forward-syntactic-ws)
471 (while (looking-at c-template-key)
472 (goto-char (match-end 0))
473 (c-forward-extended-sexp)
474 (c-forward-syntactic-ws))
475 (and (looking-at c-class-scope-key)
476 (search-forward "{" nil t))
477 (last (c-get-block-scope))))
479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
480 ;; template functions
482 (defun c-parse-template-declaration ()
483 ;; parse the template declaration at point. return a list of
484 ;; cons'es of argument def ranges.
486 (if (looking-at c-template-key)
488 (c-forward-syntactic-ws))
489 (if (eq (following-char) ?<)
490 (c-parse-arglist (point)
491 (progn (c-forward-template-arglist) (point))))))
493 (defun c-parse-arglist (start end)
494 ;; parse arglist between START and END. The region between START end
495 ;; END must include the delimiteres (parens or angle brackets) even
496 ;; though theese delimiters are completely ignored
498 (let (args arg-start)
501 (while (and (not (eobp))
504 (c-forward-syntactic-ws)
505 (setq arg-start (point))
508 (c-forward-extended-sexp)
511 (not (eq (following-char) ?,)))))
514 (c-backward-syntactic-ws)
517 (if (> (point) arg-start)
518 (setq args (cons (cons arg-start (point))
522 (defun c-move-to-template-argument (start end)
523 ;; move to the template argument name within the template argument
524 ;; between START and END
525 (if (c-move-to-initializer start end)
528 (while (and (>= (point) start)
529 (not (c-at-symbol-p))
531 (c-backward-extended-sexp))
534 (defun c-get-template-argument-name (start end)
535 ;; get the argument name of the template argument defined between
538 (c-move-to-template-argument start end)
539 (buffer-substring-no-properties (point)
542 (c-backward-syntactic-ws)
545 (defun c-get-template-prefix (args)
546 ;; return the template prefix for the template declared with
549 (mapconcat (function (lambda (x)
550 (c-get-template-argument-name (car x) (cdr x))))
555 (defun c-is-template-id (p)
556 ;; return t if scoped name at P is a template_id
559 (if (looking-at c-scope-key)
561 (c-forward-scoped-name)
562 (c-backward-syntactic-ws)
563 (eq (preceding-char) ?>)))
565 (defun c-move-to-initializer (start end)
566 ;; move point to the initializer for the argument declared between
567 ;; START and END. return t if initializer found, otherwise nil. if
568 ;; no initializer is found, point is left at START
570 (search-forward "=" end t))
572 (defun c-get-templates (scope)
573 ;; return list of ranges of template specs in SCOPE
574 (loop for level in scope
577 (goto-char (aref level 3))
579 (c-forward-template-arglist)
580 (c-backward-syntactic-ws)
581 (cons (aref level 3) (point)))))
583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
584 ;; functions to parse defuns
586 (defun c-get-full-prefix (scope &optional strip)
587 ;; return the full prefix for scope. if STRIP is non-nil, strip the
588 ;; name of the current method, if any.
590 (loop with last-p = (last scope)
592 for elem = (car elem-p)
593 for next = nil then t
594 for last = (eq elem-p last-p)
595 if (and last strip (eq (aref elem 0) 'defun))
596 concat (let ((name (c-scope-name (aref elem 1) 1)))
597 (if (> (length name) 0)
598 (concat (if next "::" "") name) ""))
600 concat (concat (if next "::" "")
601 (c-scope-name (aref elem 1))
602 (if (and (aref elem 3)
603 (not (c-is-template-id (aref elem 1))))
605 (goto-char (aref elem 3))
606 (c-get-template-prefix
607 (c-parse-template-declaration)))
610 (defun c-parse-defun ()
611 ;; parse function definition or declaration at point. Returns a vector
612 ;; of positions: [template type name arglist modifiers initializers body end]
614 (c-beginning-of-defun-or-decl)
615 (let (template type name arglist modifiers initializers body end)
616 (if (looking-at c-template-key)
618 (setq template (point))
619 (while (looking-at c-template-key)
621 (c-forward-template-arglist)
622 (c-forward-syntactic-ws))))
624 (while (not (or (eq (following-char) ?\()
625 (c-crosses-statement-barrier-p type (point))))
626 (c-forward-balanced-token)
627 (c-forward-syntactic-ws))
629 (c-backward-scoped-name)
633 (setq arglist (point))
635 (c-forward-syntactic-ws)
636 (if (not (memq (following-char) '(?{ ?\; ?:)))
638 (setq modifiers (point))
639 (while (not (or (memq (following-char) '(?{ ?\; ?:))
640 (c-crosses-statement-barrier-p modifiers (point))
642 (c-forward-extended-sexp)
643 (c-forward-syntactic-ws))))
644 (if (eq (following-char) ?:)
646 (setq initializers (point))
647 (while (not (or (memq (following-char) '(?{ ?\;))
648 (c-crosses-statement-barrier-p modifiers (point))))
649 (c-forward-extended-sexp)
650 (c-forward-syntactic-ws))))
651 (if (eq (following-char) ?{)
656 (vector template type name arglist modifiers initializers body end))))
658 (defun c-get-defun-state ()
659 ;; this extends c-parse-defun. it returns a vector containing the
661 ;; o templates: a list of cons'es each containing the range of a
662 ;; template specification
663 ;; o type: a cons containing the range for the return type
664 ;; specification of the function
665 ;; o name: a cons containing the range for the functions name
666 ;; o args: a list of cons'es, each containing the range of a
668 ;; o modifiers: a cons containing the range of the modifiers
669 ;; o initializers: a list of cons'es each containing the range of
671 ;; o body: a cons containing the range for the body or nil, if no
673 ;; o prototype: nil, if body is non-nil, otherwise the end of the
675 ;; o scope: the scope structure (as returned by c-get-block-scope)
678 (let ((defun (c-parse-defun))
679 (scope (c-get-block-scope))
680 templates type name args modifiers initializers body prototype)
681 (setq templates (c-get-templates scope))
684 (goto-char (aref defun 0))
685 (while (looking-at c-template-key)
686 (setq templates (nconc templates
690 (c-forward-template-arglist)
691 (c-backward-syntactic-ws)
693 (c-forward-syntactic-ws))))
696 (goto-char (aref defun 2))
697 (c-backward-syntactic-ws)
698 (setq type (cons (aref defun 1) (point)))))
699 (goto-char (aref defun 3))
700 (c-backward-syntactic-ws)
701 (setq name (cons (aref defun 2) (point)))
702 (goto-char (aref defun 3))
703 (let ((start (point)))
705 (setq args (c-parse-arglist start (point))))
708 (goto-char (or (aref defun 5) (aref defun 6) (aref defun 7)))
709 (c-backward-syntactic-ws)
710 (setq modifiers (cons (aref defun 4) (point)))))
712 (setq initializers (c-parse-arglist (aref defun 5)
713 (1+ (or (aref defun 6)
716 (setq body (cons (aref defun 6) (aref defun 7))))
718 (setq prototype (1+ (aref defun 7))))
719 (vector templates type name args modifiers
720 initializers body prototype scope))))
722 (defun c-defun-full-name (state)
723 ;; return the full name of the defun in state
724 (string-replace "[ \t\n\r]+" ""
725 (concat (c-get-full-prefix (aref state 8))
726 (if (aref state 8) "::" "")
727 (buffer-substring-no-properties (car (aref state 2))
728 (cdr (aref state 2))))
731 (defun c-defun-short-name (state)
732 ;; return the short name of the defun in state. This is the name of the defun
733 ;; without template args or namespace/class prefix
736 (goto-char (cdr (aref state 2)))
737 (if (and (eq (preceding-char) ?>)
739 (re-search-forward (concat c-operator-word "\\=") nil t))))
740 (c-backward-template-arglist))
741 (c-backward-syntactic-ws)
743 (if (re-search-backward (concat c-operator-word "\\=") nil t)
744 (goto-char (match-beginning 0))
746 (if (and (c-at-symbol-p)
747 (eq (preceding-char) ?~))
749 (buffer-substring-no-properties p (point)))))
751 (defun c-goto-beginning-of-defun (defun)
752 (goto-char (or (car (aref defun 1))
753 (car (aref defun 2))))
754 (loop for point = (point)
755 for tmpl in (reverse (aref defun 0))
756 do (c-backward-syntactic-ws)
757 while (= (cdr tmpl) (point))
759 (goto-char (car tmpl))
760 (setq point (point)))
761 finally do (goto-char point)))
763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
764 ;; functions to parse classes
766 (defun c-parse-class (scope)
767 ;; parse class at point. returns vector of positions: [template
768 ;; class bases start ( members )] each member is a cons ( type
769 ;; . start ) where type is one of 'typedef 'class 'friend 'variable
770 ;; 'method or 'combo (combo is a combinded struct/class/union +
771 ;; variable declaration)
773 (let ((scope (car (last scope)))
774 end template class bases start members)
775 (if (not (eq (aref scope 0) 'class))
777 (setq template (aref scope 3))
778 (setq class (aref scope 1))
779 (setq start (aref scope 2))
781 (while (and (< (skip-chars-backward "^:" class) 0)
784 (and (eq (char-before) ?:) (progn (forward-char -1) t)))
786 (if (eq (following-char) ?:)
789 (c-forward-syntactic-ws)
790 (setq bases (point))))
796 (while (progn (c-end-of-statement-1)
798 (let ((bc (char-before))
804 (setq this (point))))
805 (if (or (eq bc ?\;) (eq bc ?{))
808 (if (re-search-backward "=\\s-*0\\s-*\\=" start t)
809 (goto-char (match-beginning 0)))
810 (if (c-just-after-func-arglist-p)
811 ;; OK. It's a method (defn or decl)
813 (c-beginning-of-statement-1)
814 (setq members (cons (cons 'method (point))
817 ;; this should be a class or struct decl. Maybe
821 (c-beginning-of-statement-1)
823 (if (looking-at c-class-scope-key)
824 ;; it really IS a class/struct/union
826 (goto-char (match-end 0))
827 (c-forward-syntactic-ws)
828 (setq decl (looking-at "[a-zA-Z_]"))
831 (c-forward-syntactic-ws)
832 (if (eq (following-char) ?\;)
835 (setq members (cons (cons 'class beg)
839 (c-end-of-statement-1)
841 (setq members (cons (cons (if decl 'combo 'variable)
844 ;; then it's a variable decl or typedef or friend
845 (c-beginning-of-statement-1)
846 (cond ((looking-at c-typedef-key)
847 (setq members (cons (cons 'typedef (point)) members)))
848 ((looking-at c-friend-key)
849 (setq members (cons (cons 'friend (point)) members)))
851 (setq members (cons (cons 'variable (point)) members))))
854 (vector template class bases start (nreverse members))))))
856 (defun c-current-access-level ()
857 ;; returm current access level: 'public, 'protected or 'private
859 (let ((scope (car (last (c-get-block-scope)))))
860 (while (and (re-search-backward c-access-key (aref scope 2) t)
862 (not (eq (aref (car (c-get-block-scope)) 1) (aref scope 1))))))
863 (loop for (re . sym) in c-access-keys
866 finally return (progn
867 (goto-char (aref scope 1))
868 (if (looking-at c-struct-scope-key)
872 (defun c-get-variable-members (class)
873 ;; return list of names of all variables of CLASS
875 (loop for (type . pos) in (aref class 4)
876 for end = (progn (goto-char pos) (c-end-of-statement-1) (1- (point)))
877 if (or (eq type 'variable) (eq type 'combo))
878 collect (c-get-template-argument-name pos end))))
880 (defun c-get-variable-members-with-type (class)
881 ;; return list of conses of (name . type) of all variables of CLASS
883 (loop for (type . pos) in (aref class 4)
884 for end = (progn (goto-char pos) (c-end-of-statement-1) (1- (point)))
885 if (eq type 'variable)
886 collect (c-get-variable-with-type pos end))))
888 (defun c-get-variable-with-type (start end)
889 (c-move-to-template-argument start end)
890 (let ((arg (save-excursion
891 (buffer-substring-no-properties (point)
894 (c-backward-syntactic-ws)
896 (c-backward-syntactic-ws)
897 (cons arg (buffer-substring-no-properties start (point)))))
899 (defun c-get-base-classes (class)
900 ;; return list of base class names (including template specs)
903 (goto-char (aref class 2))
904 (loop while (< (point) (aref class 3))
905 do (progn (c-forward-syntactic-ws)
906 (while (looking-at c-inheritance-spec-key)
908 (c-forward-syntactic-ws)))
910 do (progn (c-forward-scoped-name) (c-backward-syntactic-ws))
911 collect (buffer-substring-no-properties start (point))
913 (while (and (> (skip-chars-forward "^," (aref class 3)) 0)
916 (forward-char 1))))))
918 (provide 'cc-engine-2)
922 ;;; elisp-project-autoload-file-name: "cc-autoload.el"