123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- (require 'srecode)
- (require 'srecode/dictionary)
- (require 'srecode/semantic)
- (require 'semantic/tag)
- (defgroup srecode-cpp nil
- "C++-specific Semantic Recoder settings."
- :group 'srecode)
- (defcustom srecode-cpp-namespaces
- '("std" "boost")
- "List expansion candidates for the :using-namespaces argument.
- A dictionary entry of the named PREFIX_NAMESPACE with the value
- NAMESPACE:: is created for each namespace unless the current
- buffer contains a using NAMESPACE; statement "
- :group 'srecode-cpp
- :type '(repeat string))
- (defun srecode-semantic-handle-:cpp (dict)
- "Add macros into the dictionary DICT based on the current c++ file.
- Adds the following:
- FILENAME_SYMBOL - filename converted into a C compat symbol.
- HEADER - Shown section if in a header file."
-
- (let ((fsym (file-name-nondirectory (buffer-file-name)))
- (case-fold-search t))
-
- (if (string-match "\\.\\(h\\|hh\\|hpp\\|h\\+\\+\\)$" fsym)
- (srecode-dictionary-show-section dict "HEADER")
- (srecode-dictionary-show-section dict "NOTHEADER"))
-
- (while (string-match "\\.\\| " fsym)
- (setq fsym (replace-match "_" t t fsym)))
- (srecode-dictionary-set-value dict "FILENAME_SYMBOL" fsym)
- )
- )
- (defun srecode-semantic-handle-:using-namespaces (dict)
- "Add macros into the dictionary DICT based on used namespaces.
- Adds the following:
- PREFIX_NAMESPACE - for each NAMESPACE in `srecode-cpp-namespaces'."
- (let ((tags (semantic-find-tags-by-class
- 'using (semantic-fetch-tags))))
- (dolist (name srecode-cpp-namespaces)
- (let ((variable (format "PREFIX_%s" (upcase name)))
- (prefix (format "%s::" name)))
- (srecode-dictionary-set-value dict variable prefix)
- (dolist (tag tags)
- (when (and (eq (semantic-tag-get-attribute tag :kind)
- 'namespace)
- (string= (semantic-tag-name tag) name))
- (srecode-dictionary-set-value dict variable ""))))))
- )
- (define-mode-local-override srecode-semantic-apply-tag-to-dict
- c++-mode (tag-wrapper dict)
- "Apply C++ specific features from TAG-WRAPPER into DICT.
- Calls `srecode-semantic-apply-tag-to-dict-default' first. Adds
- special behavior for tag of classes include, using and function."
-
- (srecode-semantic-apply-tag-to-dict-default tag-wrapper dict)
-
- (let* ((tag (oref tag-wrapper :prime))
- (class (semantic-tag-class tag)))
-
- (cond
-
-
-
- ((eq class 'include)
-
-
- (if (semantic-tag-include-system-p tag)
- (srecode-dictionary-show-section dict "SYSTEM")
- (srecode-dictionary-show-section dict "LOCAL")))
-
-
-
- ((eq class 'using)
-
-
- (let ((value-tag (semantic-tag-get-attribute tag :value))
- (value-dict (srecode-dictionary-add-section-dictionary
- dict "VALUE")))
- (srecode-semantic-apply-tag-to-dict
- (srecode-semantic-tag (semantic-tag-name value-tag)
- :prime value-tag)
- value-dict))
-
-
- (when (eq (semantic-tag-get-attribute tag :kind) 'namespace)
- (srecode-dictionary-show-section dict "NAMESPACE")))
-
-
-
- ((eq class 'function)
-
-
-
-
-
- (let ((member t)
- (templates (semantic-tag-get-attribute tag :template))
- (modifiers (semantic-tag-modifiers tag)))
-
- (dolist (modifier modifiers)
- (let ((modifier-dict (srecode-dictionary-add-section-dictionary
- dict "MODIFIERS")))
- (srecode-dictionary-set-value modifier-dict "NAME" modifier)))
-
- (srecode-cpp-apply-templates dict templates)
-
-
- (when member
-
-
- (when (semantic-tag-get-attribute tag :methodconst-flag)
- (srecode-dictionary-show-section dict "CONST"))
-
-
- (when (semantic-tag-get-attribute tag :pure-virtual-flag)
- (srecode-dictionary-show-section dict "PURE"))
- )))
-
-
-
- ((eq class 'type)
-
- (when (or (semantic-tag-of-type-p tag "class")
- (semantic-tag-of-type-p tag "struct"))
-
- (let ((templates (semantic-tag-get-attribute tag :template)))
- (srecode-cpp-apply-templates dict templates))))
- ))
- )
- (defun srecode-cpp-apply-templates (dict templates)
- "Add section dictionaries for TEMPLATES to DICT."
- (when templates
- (let ((templates-dict (srecode-dictionary-add-section-dictionary
- dict "TEMPLATES")))
- (dolist (template templates)
- (let ((template-dict (srecode-dictionary-add-section-dictionary
- templates-dict "ARGS")))
- (srecode-semantic-apply-tag-to-dict
- (srecode-semantic-tag (semantic-tag-name template)
- :prime template)
- template-dict)))))
- )
- (provide 'srecode/cpp)
|