This file is indexed.

/usr/share/emacs/site-lisp/cocci.el is in coccinelle 1.0.4.deb-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
;;; cocci.el --- a major mode for editing semantic patches

;; Copyright (C) 2010      Nicolas Palix <npalix@diku.dk>
;; Copyright (C) 2006-2007 Yoann Padioleau

;; Please imagine a long and boring gnu-style copyright notice
;; appearing just here.


;; Emacs Lisp Archive Entry
;; Author: Padioleau Yoann <yoann.padioleau@gmail.com>,
;; Version: 0.2
;; Keywords: coccinelle patch refactoring program transformation
;; URL: http://coccinelle.lip6.fr/


;;; Usage

;; Copy this file in your ~/.emacs.d directory
;;
;; Add the following lines to your ~/.emacs or equivalent:
;;  (load "~/.emacs.d/cocci.el")
;;  (setq auto-mode-alist
;;          (cons '("\\.cocci$" . cocci-mode) auto-mode-alist))
;;  (autoload 'cocci-mode "cocci"
;;          "Major mode for editing cocci code." t)
;;
;; You can also use cocci-mode to edit the files containing the
;; isomorphisms with:
;;  (setq auto-mode-alist
;;           (cons '("\\.iso$" . cocci-mode) auto-mode-alist))
;;

;;; History

;; 2010-04-02 Nico: Fix 'script' with 'depends on'. Add 'when forall', 'when any'
;; 2010-02-01 Nico: Add support for 'disable', 'using', scripting, 'virtual' rules
;; 2009-11-05 Nico: Cleanups, Change shortcut % to C-M-% (% is used in Python rule)
;; Some cleanups done by Rene Rydhof Hansen

;;; Utilities

(defun join-sep (sep xs)
  (mapconcat 'identity xs sep))


;;; Variables

(defvar cocci-menu)


;; new (color) faces

(defface cocci-number-face
  '((((background light)) (:foreground "black"))
    (((background dark)) (:foreground "yellow3")))
  "Used for Cocci numbers")

(defface cocci-punctuation-face
  '((((background light)) (:foreground "black"))
    (((background dark)) (:foreground "cyan")))
  "Used for punctuation")

(defface cocci-problem-face
  '((((background light)) (:background "deep pink"))
    (((background dark)) (:background "deep pink")))
  "Highlighting potential problems")

(defface cocci-special-face
  '((((background light)) (:foreground "blue"))
    (((background dark)) (:foreground "red")))
  "")

(defface cocci-rulename-face
  '((((background light)) (:foreground "DarkSlateGray"))
    (((background dark)) (:foreground "DarkSlateGray4")))
  "Highlighting the rule names")

(defface cocci-minus-face
  '((((background light)) (:foreground "red"))
    (((background dark)) (:foreground "SeaGreen3")))
  "Highlighting lines to be removed")

(defface cocci-plus-face
  '((((background light)) (:foreground "dark green"))
    (((background dark)) (:foreground "salmon")))
  "Highlighting lines to be added")

(defface cocci-match-face
  '((((background light)) (:foreground "violet red"))
    (((background dark)) (:foreground "purple")))
  "Highlighting lines to be matched (sgrep)")

(defface cocci-script-face
  '((((background light)) (:foreground "red"))
    (((background dark)) (:foreground "SeaGreen3")))
  "Highlighting script language name")


;; can look in lexer_cocci.mll for new identifiers

(defconst cocci-c-keywords-list
  '("if" "else" "while" "do" "for" "return"
    "sizeof"
    "struct" "union"
    "static" "extern" "const" "volatile"
    "break" "continue"
    "switch" "case"
    ))

(defconst cocci-declaration-keywords-list
  '("identifier" "type" "parameter" "constant" "expression" "statement"
    "function" "local" "list"
    "fresh"
    "position"
    "idexpression"

    "context"

    "typedef"
    "declarer" "iterator"
    "pure"
    ;"error" "words"

    "char" "short" "int" "float" "double" "long"
    "void"
    "signed" "unsigned"
    ))

(defconst cocci-iso-keywords-list
  '("Expression" "Statement" "Type"
    "Declaration" "TopLevel" "ArgExpression"
    ))



(defconst c-preprocessor-directives-list
  '("define" "undef"
    "if" "ifdef" "elif" "else" "endif" "ifndef"
    "include"
    "error" "pragma"
    "file" "line"
    ))

(setq cocci-font-lock-keywords
 `(
   ; For virtual rule declarations
   ("^[ \t]*\\(virtual\\)\\b\\(.*\\)"
    (1 'cocci-special-face)
    (2 'cocci-rulename-face)
    )

   ; blink possible errors, when - or + is not in first column
   ("^[ \t]+[-+]" . 'cocci-problem-face)

   ; modifiers
   ("^\\??\\+.*" . 'cocci-plus-face)
   ("^\\??-.*"   . 'cocci-minus-face)

   ("^\\*.*"   . 'cocci-match-face)
   ;("^\\??\\+.*?//" . 'cocci-plus-face)
   ; ! \\+

   ; --- +++

   ; #cpp
   ("#\\(include\\) *\\(.*\\)"
    (1 'font-lock-builtin-face)
    (2 'font-lock-string-face)
    )

   ; comments
   ("//.*" . 'font-lock-comment-face)

   ; strings
   ("\"[^\"]*\"" . 'font-lock-string-face)

   ; rule header
   ("@[ \t]*@" . 'cocci-special-face)
   ; this rule may seems redundant with the following one, but
   ; without it, @@ int x; @@ would color the int x with rulename-face.
   ; by using this rule, we color the @@ and so prevent the
   ; next rule to be applied (cf font-lock semantic when have not the
   ; OVERRIDE flag).

   ("\\(@\\)\\(.*\\)\\(@\\)"
    (1 'cocci-special-face)
    (2 'cocci-rulename-face)
    (3 'cocci-special-face)
    )

   ("@.*\\b\\(extends\\|\\(depends[ \t]*on\\)\\)\\b.*@"
    (1 'cocci-special-face t))

   ("@.*\\b\\(disable\\)\\b.*@"
    (1 'cocci-special-face t))

   ("@.*\\b\\(using\\)\\b.*@"
    (1 'cocci-special-face t))

   ("@.*\\b\\(initialize\\)[ \t]*:[ \t]*\\(.*\\)[ \t]*@"
    (1 'cocci-special-face t)
    (2 'cocci-script-face t)
    )

   ("@.*\\b\\(script\\)[ \t]*:[ \t]*\\([^ ]*\\)[ \t]*.*@"
    (1 'cocci-special-face t)
    (2 'cocci-script-face t)
    )

   ("@.*\\b\\(finalize\\)[ \t]*:[ \t]*\\(.*\\)[ \t]*@"
    (1 'cocci-special-face t)
    (2 'cocci-script-face t)
    )

   ;old: does not work, not easy to handle the   rule1, rule2, rule3  list.
   ;   ("@[ \t]*\\(\\(\\w+\\)[ \t,]*\\)*[ \t]*@"
   ;   ("\\(@\\)[ \t]*\\(\\w+\\)[ \t]*\\(@\\)"
   ;   ("\\(@\\)[ \t]*\\(\\w+\\)[ \t]+\\(extends\\)[ \t]+\\(\\w+\\)[ \t]*\\(@\\)"
   ;   ("\\(@\\)[ \t]*\\(\\w+\\)[ \t]+\\(depends\\)[ \t]+\\(on\\)[ \t]+\\(\\(\\w+\\)[ ,\t]*\\)+\\(@\\)"


   ; inherited variable, fontifying rulename
   (,(concat "^"
      "\\b\\(" (regexp-opt cocci-declaration-keywords-list) "\\)\\b"
      ".*?\\(\\w+\\)\\.")
    (2 'cocci-rulename-face))

   ;rule1.T *a;
   ("^\\(\\w+\\)\\."
    (1 'cocci-rulename-face))

   ; just for pad, metavariables in maj
   ("\\b[A-Z][0-9]?\\b" . font-lock-variable-name-face)

   ; todo: do also for other variable, do as in font-lock.el
   ; with font-lock-match-c-style-declaration-item-and-skip-to-next

   ; special cocci operators
   ("\\.\\.\\." . 'font-lock-keyword-face)
   ("^[()|]" . 'font-lock-keyword-face)

   ; escaped version of cocci operators
   ("\\\\[()|]" . 'font-lock-keyword-face)

   ("\\bwhen[ \t]+!=" . 'font-lock-keyword-face)
   ("\\bWHEN[ \t]+!=" . 'font-lock-keyword-face)
   ("\\bwhen[ \t]+=" . 'font-lock-keyword-face)
   ("\\bWHEN[ \t]+=" . 'font-lock-keyword-face)
   ("\\bwhen[ \t]+forall" . 'font-lock-keyword-face)
   ("\\bWHEN[ \t]+forall" . 'font-lock-keyword-face)
   ("\\bwhen[ \t]+any" . 'font-lock-keyword-face)
   ("\\bWHEN[ \t]+any" . 'font-lock-keyword-face)

   ; used in iso files
   ("<=>" . 'font-lock-keyword-face)
   ("=>" . 'font-lock-keyword-face)

   (,(concat "\\b\\(" (regexp-opt cocci-iso-keywords-list) "\\)\\b") .
     'cocci-special-face)

   ("\\<[0-9]+\\>" . 'cocci-number-face)

   (,(join-sep "\\|"
        (list "(" ")" ";" "," "{" "}" "\\[" "\\]")) .  'cocci-punctuation-face)
   ; . ->   * + etc

   ; c keywords
   (,(concat "\\b\\(" (regexp-opt cocci-c-keywords-list) "\\)\\b") .
     'font-lock-keyword-face)

   ; cocci declaration keywords
   (,(concat "\\b\\(" (regexp-opt cocci-declaration-keywords-list) "\\)\\b") .
      'font-lock-type-face)

   ; cpp directives
   (,(concat "^#[ \t]*\\(" (regexp-opt c-preprocessor-directives-list)
	    "\\)\\>[ \t!]*\\(\\sw+\\)?")
    (1 'font-lock-builtin-face))

  ))
;  "Expressions to highlight in cocci-mode.")


;; define a mode-specific abbrev table for those who use such things
(defvar cocci-mode-abbrev-table nil
  "Abbrev table used while in cocci mode.")
(define-abbrev-table 'cocci-mode-abbrev-table nil)


(defvar cocci-mode-map nil
  "Keymap used in `cocci-mode'.")
(unless cocci-mode-map
  (setq cocci-mode-map (make-sparse-keymap))
  (define-key cocci-mode-map [(meta control *)] 'switch-between-cocci-c)
  (define-key cocci-mode-map "%" 'cocci-replace-modifiers)

  ;(define-key cocci-mode-map "\C-c" 'compile)
  )


(defvar cocci-mode-syntax-table nil
  "Syntax table used while in cocci mode.")
(unless cocci-mode-syntax-table
  (setq cocci-mode-syntax-table (make-syntax-table))

  ; _ is part of a word.
  (modify-syntax-entry ?\_ "w"  cocci-mode-syntax-table)

  ; change mode for ", bad interaction with font-lock
  (modify-syntax-entry ?\" "w"  cocci-mode-syntax-table)
  )


;;; Code

;; helper functions for the cocci programmer

(defun cocci-replace-modifiers (beg end str)
  "TODO"
  (interactive
   (let ((str (read-string "New modifier string (+, -, space): "
                           nil 'my-history)))
     (list (region-beginning) (region-end) str)))

  ;(interactive "rsNew modifier string (+, -, space): ")
  (replace-regexp "^[-+]?" str nil beg end)
  )

;Used internally while developping coccinelle.
;Allow to switch between the corresponding SP and C file.
;todo: handle the _verxxx naming convention.
(defun switch-between-cocci-c ()
  (interactive)
  (let ((target
         (cond ((string-match ".c$" (buffer-name))
                (replace-match ".cocci" t t (buffer-name)))
               ((string-match ".cocci$" (buffer-name))
                (replace-match ".c" t t (buffer-name)))
               (t
                "none"))))
    (if (get-buffer target)
	(switch-to-buffer target)
      (find-file
       (read-file-name "file: " nil nil t target)))))

(eval-after-load "cc-mode"
  '(progn
     (define-key c-mode-map [(meta control *)] 'switch-between-cocci-c))
  )



(defvar cocci-mode-hook nil
  "Hook called by  `cocci-mode'")

;;;###autoload
(defun cocci-mode ()
  "Major mode for editing cocci code.
Special commands: \\{cocci-mode-map}
Turning on cocci-mode runs the hook `cocci-mode-hook'."
  (interactive)
  (kill-all-local-variables)
  (make-local-variable 'font-lock-defaults)
  (make-local-variable 'comment-start)
  (make-local-variable 'comment-end)
  (make-local-variable 'compile-command)

  (use-local-map cocci-mode-map)
  (set-syntax-table cocci-mode-syntax-table)
  (setq mode-name                "cocci"
        major-mode               'cocci-mode
        local-abbrev-table       cocci-mode-abbrev-table
	font-lock-defaults     '(cocci-font-lock-keywords)
	comment-start          "//"
	comment-end            ""
   )
  (easy-menu-add cocci-menu)

  (run-hooks 'cocci-mode-hook)
)


;; Menu

(easy-menu-define cocci-menu cocci-mode-map "Cocci menu"
  '("Cocci"
    ["Switch to corresponding C file" switch-between-cocci-c t]
    ["Replace modifiers" cocci-replace-modifiers t]
    ))



; put cursor before a parse error coccinelle message and it will
; open the corresponding file and go to corresponding line.
(fset 'cocci-goto-next-error
   [?\C-s ?F ?i ?l ?e right right ?\C-  ?\C-s ?" left ?\M-w ?\C-x ?\C-f S-insert return ?\C-\M-l C-right right C-S-right C-insert ?\C-\M-l ?\M-g S-insert return])
;"

;; Provide
(provide 'cocci-mode)

;;; cocci.el ends here