cc-langs.el 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240
  1. ;;; cc-langs.el --- language specific settings for CC Mode
  2. ;; Copyright (C) 1985, 1987, 1992-2012 Free Software Foundation, Inc.
  3. ;; Authors: 2002- Alan Mackenzie
  4. ;; 1998- Martin Stjernholm
  5. ;; 1992-1999 Barry A. Warsaw
  6. ;; 1987 Dave Detlefs
  7. ;; 1987 Stewart Clamen
  8. ;; 1985 Richard M. Stallman
  9. ;; Maintainer: bug-cc-mode@gnu.org
  10. ;; Created: 22-Apr-1997 (split from cc-mode.el)
  11. ;; Keywords: c languages
  12. ;; Package: cc-mode
  13. ;; This file is part of GNU Emacs.
  14. ;; GNU Emacs is free software: you can redistribute it and/or modify
  15. ;; it under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation, either version 3 of the License, or
  17. ;; (at your option) any later version.
  18. ;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  24. ;;; Commentary:
  25. ;; HACKERS NOTE: There's heavy macro magic here. If you need to make
  26. ;; changes in this or other files containing `c-lang-defconst' but
  27. ;; don't want to read through the longer discussion below then read
  28. ;; this:
  29. ;;
  30. ;; o A change in a `c-lang-defconst' or `c-lang-defvar' will not take
  31. ;; effect if the file containing the mode init function (typically
  32. ;; cc-mode.el) is byte compiled.
  33. ;; o To make changes show in font locking you need to reevaluate the
  34. ;; `*-font-lock-keywords-*' constants, which normally is easiest to
  35. ;; do with M-x eval-buffer in cc-fonts.el.
  36. ;; o In either case it's necessary to reinitialize the mode to make
  37. ;; the changes show in an existing buffer.
  38. ;;; Introduction to the language dependent variable system:
  39. ;;
  40. ;; This file contains all the language dependent variables, except
  41. ;; those specific for font locking which reside in cc-fonts.el. As
  42. ;; far as possible, all the differences between the languages that CC
  43. ;; Mode supports are described with these variables only, so that the
  44. ;; code can be shared.
  45. ;;
  46. ;; The language constant system (see cc-defs.el) is used to specify
  47. ;; various language dependent info at a high level, such as lists of
  48. ;; keywords, and then from them generate - at compile time - the
  49. ;; various regexps and other low-level structures actually employed in
  50. ;; the code at runtime.
  51. ;;
  52. ;; This system is also designed to make it easy for developers of
  53. ;; derived modes to customize the source constants for new language
  54. ;; variants, without having to keep up with the exact regexps etc that
  55. ;; are used in each CC Mode version. It's possible from an external
  56. ;; package to add a new language by inheriting an existing one, and
  57. ;; then change specific constants as necessary for the new language.
  58. ;; The old values for those constants (and the values of all the other
  59. ;; high-level constants) may be used to build the new ones, and those
  60. ;; new values will in turn be used by the low-level definitions here
  61. ;; to build the runtime constants appropriately for the new language
  62. ;; in the current version of CC Mode.
  63. ;;
  64. ;; Like elsewhere in CC Mode, the existence of a doc string signifies
  65. ;; that a language constant is part of the external API, and that it
  66. ;; therefore can be used with a high confidence that it will continue
  67. ;; to work with future versions of CC Mode. Even so, it's not
  68. ;; unlikely that such constants will change meaning slightly as this
  69. ;; system is refined further; a certain degree of dependence on the CC
  70. ;; Mode version is unavoidable when hooking in at this level. Also
  71. ;; note that there's still work to be done to actually use these
  72. ;; constants everywhere inside CC Mode; there are still hardcoded
  73. ;; values in many places in the code.
  74. ;;
  75. ;; Separate packages will also benefit from the compile time
  76. ;; evaluation; the byte compiled file(s) for them will contain the
  77. ;; compiled runtime constants ready for use by (the byte compiled) CC
  78. ;; Mode, and the source definitions in this file don't have to be
  79. ;; loaded then. However, if a byte compiled package is loaded that
  80. ;; has been compiled with a different version of CC Mode than the one
  81. ;; currently loaded, then the compiled-in values will be discarded and
  82. ;; new ones will be built when the mode is initialized. That will
  83. ;; automatically trig a load of the file(s) containing the source
  84. ;; definitions (i.e. this file and/or cc-fonts.el) if necessary.
  85. ;;
  86. ;; A small example of a derived mode is available at
  87. ;; <http://cc-mode.sourceforge.net/derived-mode-ex.el>. It also
  88. ;; contains some useful hints for derived mode developers.
  89. ;;; Using language variables:
  90. ;;
  91. ;; The `c-lang-defvar' forms in this file comprise the language
  92. ;; variables that CC Mode uses. It does not work to use
  93. ;; `c-lang-defvar' anywhere else (which isn't much of a limitation
  94. ;; since these variables sole purpose is to interface with the CC Mode
  95. ;; core functions). The values in these `c-lang-defvar's are not
  96. ;; evaluated right away but instead collected to a single large `setq'
  97. ;; that can be inserted for a particular language with the
  98. ;; `c-init-language-vars' macro.
  99. ;; This file is only required at compile time, or when not running
  100. ;; from byte compiled files, or when the source definitions for the
  101. ;; language constants are requested.
  102. ;;; Code:
  103. ;; For Emacs < 22.2.
  104. (eval-and-compile
  105. (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
  106. (eval-when-compile
  107. (let ((load-path
  108. (if (and (boundp 'byte-compile-dest-file)
  109. (stringp byte-compile-dest-file))
  110. (cons (file-name-directory byte-compile-dest-file) load-path)
  111. load-path)))
  112. (load "cc-bytecomp" nil t)))
  113. (cc-require 'cc-defs)
  114. (cc-require 'cc-vars)
  115. ;; This file is not always loaded. See note above.
  116. (cc-external-require 'cl)
  117. ;;; Setup for the `c-lang-defvar' system.
  118. (eval-and-compile
  119. ;; These are used to collect the init forms from the subsequent
  120. ;; `c-lang-defvar' and `c-lang-setvar'. They are used to build the
  121. ;; lambda in `c-make-init-lang-vars-fun' below, and to build `defvar's
  122. ;; and `make-variable-buffer-local's in cc-engine and
  123. ;; `make-local-variable's in `c-init-language-vars-for'.
  124. (defvar c-lang-variable-inits nil)
  125. (defvar c-lang-variable-inits-tail nil)
  126. (setq c-lang-variable-inits (list nil)
  127. c-lang-variable-inits-tail c-lang-variable-inits)
  128. (defvar c-emacs-variable-inits nil)
  129. (defvar c-emacs-variable-inits-tail nil)
  130. (setq c-emacs-variable-inits (list nil)
  131. c-emacs-variable-inits-tail c-emacs-variable-inits))
  132. (defmacro c-lang-defvar (var val &optional doc)
  133. "Declares the buffer local variable VAR to get the value VAL. VAL is
  134. evaluated and assigned at mode initialization. More precisely, VAL is
  135. evaluated and bound to VAR when the result from the macro
  136. `c-init-language-vars' is evaluated.
  137. `c-lang-const' is typically used in VAL to get the right value for the
  138. language being initialized, and such calls will be macro expanded to
  139. the evaluated constant value at compile time."
  140. (when (and (not doc)
  141. (eq (car-safe val) 'c-lang-const)
  142. (eq (nth 1 val) var)
  143. (not (nth 2 val)))
  144. ;; Special case: If there's no docstring and the value is a
  145. ;; simple (c-lang-const foo) where foo is the same name as VAR
  146. ;; then take the docstring from the language constant foo.
  147. (setq doc (get (intern (symbol-name (nth 1 val)) c-lang-constants)
  148. 'variable-documentation)))
  149. (or (stringp doc)
  150. (setq doc nil))
  151. (let ((elem (assq var (cdr c-lang-variable-inits))))
  152. (if elem
  153. (setcdr elem (list val doc))
  154. (setcdr c-lang-variable-inits-tail (list (list var val doc)))
  155. (setq c-lang-variable-inits-tail (cdr c-lang-variable-inits-tail))))
  156. ;; Return the symbol, like the other def* forms.
  157. `',var)
  158. (defmacro c-lang-setvar (var val)
  159. "Causes the variable VAR to be made buffer local and to get set to the
  160. value VAL. VAL is evaluated and assigned at mode initialization. More
  161. precisely, VAL is evaluated and bound to VAR when the result from the
  162. macro `c-init-language-vars' is evaluated. VAR is typically a standard
  163. Emacs variable like `comment-start'.
  164. `c-lang-const' is typically used in VAL to get the right value for the
  165. language being initialized, and such calls will be macro expanded to
  166. the evaluated constant value at compile time."
  167. (let ((elem (assq var (cdr c-emacs-variable-inits))))
  168. (if elem
  169. (setcdr elem (list val)) ; Maybe remove "list", sometime. 2006-07-19
  170. (setcdr c-emacs-variable-inits-tail (list (list var val)))
  171. (setq c-emacs-variable-inits-tail (cdr c-emacs-variable-inits-tail))))
  172. ;; Return the symbol, like the other def* forms.
  173. `',var)
  174. (put 'c-lang-defvar 'lisp-indent-function 'defun)
  175. ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
  176. ; '
  177. (def-edebug-spec c-lang-defvar
  178. (&define name def-form &optional stringp)) ;)
  179. ;; Suppress "might not be defined at runtime" warning.
  180. ;; This file is only used when compiling other cc files.
  181. (declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys))
  182. (declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest))
  183. (declare-function cl-macroexpand-all "cl-extra" (form &optional env))
  184. (eval-and-compile
  185. ;; Some helper functions used when building the language constants.
  186. (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
  187. ;; Extract a subset of the operators in the list OPS in a DWIM:ey
  188. ;; way. The return value is a plain list of operators:
  189. ;;
  190. ;; OPS either has the structure of `c-operators', is a single
  191. ;; group in `c-operators', or is a plain list of operators.
  192. ;;
  193. ;; OPGROUP-FILTER specifies how to select the operator groups. It
  194. ;; can be t to choose all groups, a list of group type symbols
  195. ;; (such as 'prefix) to accept, or a function which will be called
  196. ;; with the group symbol for each group and should return non-nil
  197. ;; if that group is to be included.
  198. ;;
  199. ;; If XLATE is given, it's a function which is called for each
  200. ;; matching operator and its return value is collected instead.
  201. ;; If it returns a list, the elements are spliced directly into
  202. ;; the final result, which is returned as a list with duplicates
  203. ;; removed using `equal'.
  204. ;;
  205. ;; `c-mode-syntax-table' for the current mode is in effect during
  206. ;; the whole procedure.
  207. (unless (listp (car-safe ops))
  208. (setq ops (list ops)))
  209. (cond ((eq opgroup-filter t)
  210. (setq opgroup-filter (lambda (opgroup) t)))
  211. ((not (functionp opgroup-filter))
  212. (setq opgroup-filter `(lambda (opgroup)
  213. (memq opgroup ',opgroup-filter)))))
  214. (cond ((eq op-filter t)
  215. (setq op-filter (lambda (op) t)))
  216. ((stringp op-filter)
  217. (setq op-filter `(lambda (op)
  218. (string-match ,op-filter op)))))
  219. (unless xlate
  220. (setq xlate 'identity))
  221. (c-with-syntax-table (c-lang-const c-mode-syntax-table)
  222. (delete-duplicates
  223. (mapcan (lambda (opgroup)
  224. (when (if (symbolp (car opgroup))
  225. (when (funcall opgroup-filter (car opgroup))
  226. (setq opgroup (cdr opgroup))
  227. t)
  228. t)
  229. (mapcan (lambda (op)
  230. (when (funcall op-filter op)
  231. (let ((res (funcall xlate op)))
  232. (if (listp res) res (list res)))))
  233. opgroup)))
  234. ops)
  235. :test 'equal))))
  236. ;;; Various mode specific values that aren't language related.
  237. (c-lang-defconst c-mode-menu
  238. ;; The definition for the mode menu. The menu title is prepended to
  239. ;; this before it's fed to `easy-menu-define'.
  240. t `(["Comment Out Region" comment-region
  241. (c-fn-region-is-active-p)]
  242. ["Uncomment Region" (comment-region (region-beginning)
  243. (region-end) '(4))
  244. (c-fn-region-is-active-p)]
  245. ["Indent Expression" c-indent-exp
  246. (memq (char-after) '(?\( ?\[ ?\{))]
  247. ["Indent Line or Region" c-indent-line-or-region t]
  248. ["Fill Comment Paragraph" c-fill-paragraph t]
  249. "----"
  250. ["Backward Statement" c-beginning-of-statement t]
  251. ["Forward Statement" c-end-of-statement t]
  252. ,@(when (c-lang-const c-opt-cpp-prefix)
  253. ;; Only applicable if there's a cpp preprocessor.
  254. `(["Up Conditional" c-up-conditional t]
  255. ["Backward Conditional" c-backward-conditional t]
  256. ["Forward Conditional" c-forward-conditional t]
  257. "----"
  258. ["Macro Expand Region" c-macro-expand
  259. (c-fn-region-is-active-p)]
  260. ["Backslashify" c-backslash-region
  261. (c-fn-region-is-active-p)]))
  262. "----"
  263. ("Style..."
  264. ["Set Style..." c-set-style t]
  265. ["Show Current Style Name" (message
  266. "Style Name: %s"
  267. c-indentation-style) t]
  268. ["Guess Style from this Buffer" c-guess-buffer-no-install t]
  269. ["Install the Last Guessed Style..." c-guess-install
  270. (and c-guess-guessed-offsets-alist
  271. c-guess-guessed-basic-offset) ]
  272. ["View the Last Guessed Style" c-guess-view
  273. (and c-guess-guessed-offsets-alist
  274. c-guess-guessed-basic-offset) ])
  275. "----"
  276. ("Toggle..."
  277. ["Syntactic indentation" c-toggle-syntactic-indentation
  278. :style toggle :selected c-syntactic-indentation]
  279. ["Electric mode" c-toggle-electric-state
  280. :style toggle :selected c-electric-flag]
  281. ["Auto newline" c-toggle-auto-newline
  282. :style toggle :selected c-auto-newline]
  283. ["Hungry delete" c-toggle-hungry-state
  284. :style toggle :selected c-hungry-delete-key]
  285. ["Subword mode" subword-mode
  286. :style toggle :selected (and (boundp 'subword-mode)
  287. subword-mode)])))
  288. ;;; Syntax tables.
  289. (defun c-populate-syntax-table (table)
  290. "Populate the given syntax table as necessary for a C-like language.
  291. This includes setting ' and \" as string delimiters, and setting up
  292. the comment syntax to handle both line style \"//\" and block style
  293. \"/*\" \"*/\" comments."
  294. (modify-syntax-entry ?_ "_" table)
  295. (modify-syntax-entry ?\\ "\\" table)
  296. (modify-syntax-entry ?+ "." table)
  297. (modify-syntax-entry ?- "." table)
  298. (modify-syntax-entry ?= "." table)
  299. (modify-syntax-entry ?% "." table)
  300. (modify-syntax-entry ?< "." table)
  301. (modify-syntax-entry ?> "." table)
  302. (modify-syntax-entry ?& "." table)
  303. (modify-syntax-entry ?| "." table)
  304. (modify-syntax-entry ?\' "\"" table)
  305. (modify-syntax-entry ?\240 "." table)
  306. ;; Set up block and line oriented comments. The new C
  307. ;; standard mandates both comment styles even in C, so since
  308. ;; all languages now require dual comments, we make this the
  309. ;; default.
  310. (cond
  311. ;; XEmacs
  312. ((memq '8-bit c-emacs-features)
  313. (modify-syntax-entry ?/ ". 1456" table)
  314. (modify-syntax-entry ?* ". 23" table))
  315. ;; Emacs
  316. ((memq '1-bit c-emacs-features)
  317. (modify-syntax-entry ?/ ". 124b" table)
  318. (modify-syntax-entry ?* ". 23" table))
  319. ;; incompatible
  320. (t (error "CC Mode is incompatible with this version of Emacs")))
  321. (modify-syntax-entry ?\n "> b" table)
  322. ;; Give CR the same syntax as newline, for selective-display
  323. (modify-syntax-entry ?\^m "> b" table))
  324. (c-lang-defconst c-make-mode-syntax-table
  325. "Functions that generates the mode specific syntax tables.
  326. The syntax tables aren't stored directly since they're quite large."
  327. t `(lambda ()
  328. (let ((table (make-syntax-table)))
  329. (c-populate-syntax-table table)
  330. ;; Mode specific syntaxes.
  331. ,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode))
  332. ;; Let '@' be part of symbols in ObjC to cope with
  333. ;; its compiler directives as single keyword tokens.
  334. ;; This is then necessary since it's assumed that
  335. ;; every keyword is a single symbol.
  336. `(modify-syntax-entry ?@ "_" table))
  337. ((c-major-mode-is 'pike-mode)
  338. `(modify-syntax-entry ?@ "." table)))
  339. table)))
  340. (c-lang-defconst c-mode-syntax-table
  341. ;; The syntax tables in evaluated form. Only used temporarily when
  342. ;; the constants in this file are evaluated.
  343. t (funcall (c-lang-const c-make-mode-syntax-table)))
  344. (c-lang-defconst c++-make-template-syntax-table
  345. ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
  346. ;; parenthesis characters. Used temporarily when template argument
  347. ;; lists are parsed. Note that this encourages incorrect parsing of
  348. ;; templates since they might contain normal operators that uses the
  349. ;; '<' and '>' characters. Therefore this syntax table might go
  350. ;; away when CC Mode handles templates correctly everywhere.
  351. t nil
  352. (java c++) `(lambda ()
  353. (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
  354. (modify-syntax-entry ?< "(>" table)
  355. (modify-syntax-entry ?> ")<" table)
  356. table)))
  357. (c-lang-defvar c++-template-syntax-table
  358. (and (c-lang-const c++-make-template-syntax-table)
  359. (funcall (c-lang-const c++-make-template-syntax-table))))
  360. (c-lang-defconst c-no-parens-syntax-table
  361. ;; A variant of the standard syntax table which is used to find matching
  362. ;; "<"s and ">"s which have been marked as parens using syntax table
  363. ;; properties. The other paren characters (e.g. "{", ")" "]") are given a
  364. ;; non-paren syntax here. so that the list commands will work on "< ... >"
  365. ;; even when there's unbalanced other parens inside them.
  366. ;;
  367. ;; This variable is nil for languages which don't have template stuff.
  368. t `(lambda ()
  369. (if (c-lang-const c-recognize-<>-arglists)
  370. (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
  371. (modify-syntax-entry ?\( "." table)
  372. (modify-syntax-entry ?\) "." table)
  373. (modify-syntax-entry ?\[ "." table)
  374. (modify-syntax-entry ?\] "." table)
  375. (modify-syntax-entry ?\{ "." table)
  376. (modify-syntax-entry ?\} "." table)
  377. table))))
  378. (c-lang-defvar c-no-parens-syntax-table
  379. (funcall (c-lang-const c-no-parens-syntax-table)))
  380. (c-lang-defconst c-identifier-syntax-modifications
  381. "A list that describes the modifications that should be done to the
  382. mode syntax table to get a syntax table that matches all identifiers
  383. and keywords as words.
  384. The list is just like the one used in `font-lock-defaults': Each
  385. element is a cons where the car is the character to modify and the cdr
  386. the new syntax, as accepted by `modify-syntax-entry'."
  387. ;; The $ character is not allowed in most languages (one exception
  388. ;; is Java which allows it for legacy reasons) but we still classify
  389. ;; it as an identifier character since it's often used in various
  390. ;; machine generated identifiers.
  391. t '((?_ . "w") (?$ . "w"))
  392. (objc java) (append '((?@ . "w"))
  393. (c-lang-const c-identifier-syntax-modifications))
  394. awk '((?_ . "w")))
  395. (c-lang-defvar c-identifier-syntax-modifications
  396. (c-lang-const c-identifier-syntax-modifications))
  397. (c-lang-defvar c-identifier-syntax-table
  398. (let ((table (copy-syntax-table (c-mode-var "mode-syntax-table")))
  399. (mods c-identifier-syntax-modifications)
  400. mod)
  401. (while mods
  402. (setq mod (car mods)
  403. mods (cdr mods))
  404. (modify-syntax-entry (car mod) (cdr mod) table))
  405. table)
  406. "Syntax table built on the mode syntax table but additionally
  407. classifies symbol constituents like '_' and '$' as word constituents,
  408. so that all identifiers are recognized as words.")
  409. (c-lang-defconst c-get-state-before-change-functions
  410. ;; For documentation see the following c-lang-defvar of the same name.
  411. ;; The value here may be a list of functions or a single function.
  412. t nil
  413. c++ '(c-extend-region-for-CPP
  414. c-before-change-check-<>-operators
  415. c-invalidate-macro-cache)
  416. (c objc) '(c-extend-region-for-CPP c-invalidate-macro-cache)
  417. ;; java 'c-before-change-check-<>-operators
  418. awk 'c-awk-record-region-clear-NL)
  419. (c-lang-defvar c-get-state-before-change-functions
  420. (let ((fs (c-lang-const c-get-state-before-change-functions)))
  421. (if (listp fs)
  422. fs
  423. (list fs)))
  424. "If non-nil, a list of functions called from c-before-change-hook.
  425. Typically these will record enough state to allow
  426. `c-before-font-lock-function' to extend the region to fontify,
  427. and may do such things as removing text-properties which must be
  428. recalculated.
  429. These functions will be run in the order given. Each of them
  430. takes 2 parameters, the BEG and END supplied to every
  431. before-change function; on entry, the buffer will have been
  432. widened and match-data will have been saved; point is undefined
  433. on both entry and exit; the return value is ignored.
  434. The functions are called even when font locking isn't enabled.
  435. When the mode is initialized, the functions are called with
  436. parameters \(point-min) and \(point-max).")
  437. (c-lang-defconst c-before-font-lock-functions
  438. ;; For documentation see the following c-lang-defvar of the same name.
  439. ;; The value here may be a list of functions or a single function.
  440. t 'c-change-set-fl-decl-start
  441. (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP
  442. c-change-set-fl-decl-start)
  443. awk 'c-awk-extend-and-syntax-tablify-region)
  444. (c-lang-defvar c-before-font-lock-functions
  445. (let ((fs (c-lang-const c-before-font-lock-functions)))
  446. (if (listp fs)
  447. fs
  448. (list fs)))
  449. "If non-nil, a list of functions called just before font locking.
  450. Typically they will extend the region about to be fontified \(see
  451. below) and will set `syntax-table' text properties on the region.
  452. These functions will be run in the order given. Each of them
  453. takes 3 parameters, the BEG, END, and OLD-LEN supplied to every
  454. after-change function; point is undefined on both entry and exit;
  455. on entry, the buffer will have been widened and match-data will
  456. have been saved; the return value is ignored.
  457. The functions may extend the region to be fontified by setting the
  458. buffer local variables c-new-BEG and c-new-END.
  459. The functions are called even when font locking is disabled.
  460. When the mode is initialized, these functions are called with
  461. parameters \(point-min), \(point-max) and <buffer size>.")
  462. (c-lang-defconst c-before-context-fontification-functions
  463. awk nil
  464. t 'c-context-set-fl-decl-start)
  465. ;; For documentation see the following c-lang-defvar of the same name.
  466. ;; The value here may be a list of functions or a single function.
  467. (c-lang-defvar c-before-context-fontification-functions
  468. (let ((fs (c-lang-const c-before-context-fontification-functions)))
  469. (if (listp fs)
  470. fs
  471. (list fs)))
  472. "If non-nil, a list of functions called just before context (or
  473. other non-change) fontification is done. Typically they will
  474. extend the region.
  475. These functions will be run in the order given. Each of them
  476. takes 2 parameters, the BEG and END of the region to be
  477. fontified. Point is undefined on both entry and exit. On entry,
  478. the buffer will have been widened and match-data will have been
  479. saved; the return value is a cons of the adjusted
  480. region, (NEW-BEG . NEW-END).")
  481. ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
  482. (c-lang-defconst c-at-vsemi-p-fn
  483. "Contains a function \"Is there a virtual semicolon at POS or point?\".
  484. Such a function takes one optional parameter, a buffer position (defaults to
  485. point), and returns nil or t. This variable contains nil for languages which
  486. don't have EOL terminated statements. "
  487. t nil
  488. (c c++ objc) 'c-at-macro-vsemi-p
  489. awk 'c-awk-at-vsemi-p)
  490. (c-lang-defvar c-at-vsemi-p-fn (c-lang-const c-at-vsemi-p-fn))
  491. (c-lang-defconst c-vsemi-status-unknown-p-fn
  492. "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
  493. The (admittedly kludgy) purpose of such a function is to prevent an infinite
  494. recursion in c-beginning-of-statement-1 when point starts at a `while' token.
  495. The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
  496. even indirectly. This variable contains nil for languages which don't have
  497. EOL terminated statements."
  498. t nil
  499. (c c++ objc) 'c-macro-vsemi-status-unknown-p
  500. awk 'c-awk-vsemi-status-unknown-p)
  501. (c-lang-defvar c-vsemi-status-unknown-p-fn
  502. (c-lang-const c-vsemi-status-unknown-p-fn))
  503. ;;; Lexer-level syntax (identifiers, tokens etc).
  504. (c-lang-defconst c-has-bitfields
  505. "Whether the language has bitfield declarations."
  506. t nil
  507. (c c++ objc) t)
  508. (c-lang-defvar c-has-bitfields (c-lang-const c-has-bitfields))
  509. (c-lang-defconst c-symbol-start
  510. "Regexp that matches the start of a symbol, i.e. any identifier or
  511. keyword. It's unspecified how far it matches. Does not contain a \\|
  512. operator at the top level."
  513. t (concat "[" c-alpha "_]")
  514. java (concat "[" c-alpha "_@]")
  515. objc (concat "[" c-alpha "_@]")
  516. pike (concat "[" c-alpha "_`]"))
  517. (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
  518. (c-lang-defconst c-symbol-chars
  519. "Set of characters that can be part of a symbol.
  520. This is of the form that fits inside [ ] in a regexp."
  521. ;; Pike note: With the backquote identifiers this would include most
  522. ;; operator chars too, but they are handled with other means instead.
  523. t (concat c-alnum "_$")
  524. objc (concat c-alnum "_$@"))
  525. (c-lang-defvar c-symbol-chars (c-lang-const c-symbol-chars))
  526. (c-lang-defconst c-symbol-key
  527. "Regexp matching identifiers and keywords (with submatch 0). Assumed
  528. to match if `c-symbol-start' matches on the same position."
  529. t (concat (c-lang-const c-symbol-start)
  530. "[" (c-lang-const c-symbol-chars) "]*")
  531. pike (concat
  532. ;; Use the value from C here since the operator backquote is
  533. ;; covered by the other alternative.
  534. (c-lang-const c-symbol-key c)
  535. "\\|"
  536. (c-make-keywords-re nil
  537. (c-lang-const c-overloadable-operators))))
  538. (c-lang-defvar c-symbol-key (c-lang-const c-symbol-key))
  539. (c-lang-defconst c-symbol-key-depth
  540. ;; Number of regexp grouping parens in `c-symbol-key'.
  541. t (regexp-opt-depth (c-lang-const c-symbol-key)))
  542. (c-lang-defconst c-nonsymbol-chars
  543. "This is the set of chars that can't be part of a symbol, i.e. the
  544. negation of `c-symbol-chars'."
  545. t (concat "^" (c-lang-const c-symbol-chars)))
  546. (c-lang-defvar c-nonsymbol-chars (c-lang-const c-nonsymbol-chars))
  547. (c-lang-defconst c-nonsymbol-key
  548. "Regexp that matches any character that can't be part of a symbol.
  549. It's usually appended to other regexps to avoid matching a prefix.
  550. It's assumed to not contain any submatchers."
  551. ;; The same thing regarding Unicode identifiers applies here as to
  552. ;; `c-symbol-key'.
  553. t (concat "[" (c-lang-const c-nonsymbol-chars) "]"))
  554. (c-lang-defconst c-identifier-ops
  555. "The operators that make up fully qualified identifiers. nil in
  556. languages that don't have such things. See `c-operators' for a
  557. description of the format. Binary operators can concatenate symbols,
  558. e.g. \"::\" in \"A::B::C\". Prefix operators can precede identifiers,
  559. e.g. \"~\" in \"~A::B\". Other types of operators aren't supported.
  560. This value is by default merged into `c-operators'."
  561. t nil
  562. c++ '((prefix "~" "??-" "compl")
  563. (right-assoc "::")
  564. (prefix "::"))
  565. ;; Java has "." to concatenate identifiers but it's also used for
  566. ;; normal indexing. There's special code in the Java font lock
  567. ;; rules to fontify qualified identifiers based on the standard
  568. ;; naming conventions. We still define "." here to make
  569. ;; `c-forward-name' move over as long names as possible which is
  570. ;; necessary to e.g. handle throws clauses correctly.
  571. java '((left-assoc "."))
  572. idl '((left-assoc "::")
  573. (prefix "::"))
  574. pike '((left-assoc "::")
  575. (prefix "::")
  576. (left-assoc ".")))
  577. (c-lang-defconst c-opt-identifier-concat-key
  578. ;; Appendable adorned regexp matching the operators that join
  579. ;; symbols to fully qualified identifiers, or nil in languages that
  580. ;; don't have such things.
  581. ;;
  582. ;; This was a docstring constant in 5.30. It still works but is now
  583. ;; considered internal - change `c-identifier-ops' instead.
  584. t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
  585. '(left-assoc right-assoc)
  586. t)))
  587. (when ops
  588. (c-make-keywords-re 'appendable ops))))
  589. (c-lang-defvar c-opt-identifier-concat-key
  590. (c-lang-const c-opt-identifier-concat-key)
  591. 'dont-doc)
  592. (c-lang-defconst c-opt-identifier-concat-key-depth
  593. ;; Number of regexp grouping parens in `c-opt-identifier-concat-key'.
  594. t (regexp-opt-depth (c-lang-const c-opt-identifier-concat-key)))
  595. (c-lang-defconst c-opt-identifier-prefix-key
  596. ;; Appendable adorned regexp matching operators that might precede
  597. ;; an identifier and that are part of the identifier in that case.
  598. ;; nil in languages without such things.
  599. t (let ((ops (c-filter-ops (c-lang-const c-identifier-ops)
  600. '(prefix)
  601. t)))
  602. (when ops
  603. (c-make-keywords-re 'appendable ops))))
  604. (c-lang-defconst c-after-id-concat-ops
  605. "Operators that can occur after a binary operator on `c-identifier-ops'
  606. in identifiers. nil in languages that don't have such things.
  607. Operators here should also have appropriate entries in `c-operators' -
  608. it's not taken care of by default."
  609. t nil
  610. ;; '~' for destructors in C++, '*' for member pointers.
  611. c++ '("~" "*")
  612. ;; In Java we recognize '*' to deal with "foo.bar.*" that can occur
  613. ;; in import declarations. (This will also match bogus things like
  614. ;; "foo.*bar" but we don't bother.)
  615. java '("*"))
  616. (c-lang-defconst c-opt-after-id-concat-key
  617. ;; Regexp that must match the token after
  618. ;; `c-opt-identifier-concat-key' for it to be considered an
  619. ;; identifier concatenation operator (which e.g. causes the
  620. ;; preceding identifier to be fontified as a reference). Assumed to
  621. ;; be a string if `c-opt-identifier-concat-key' is.
  622. ;;
  623. ;; This was a docstring constant in 5.30. It still works but is now
  624. ;; considered internal - change `c-after-id-concat-ops' instead.
  625. t (concat (c-lang-const c-symbol-start)
  626. (if (c-lang-const c-after-id-concat-ops)
  627. (concat "\\|" (c-make-keywords-re 'appendable
  628. (c-lang-const c-after-id-concat-ops)))
  629. "")))
  630. (c-lang-defconst c-identifier-start
  631. "Regexp that matches the start of an (optionally qualified) identifier.
  632. It should also match all keywords. It's unspecified how far it
  633. matches."
  634. t (concat (c-lang-const c-symbol-start)
  635. (if (c-lang-const c-opt-identifier-prefix-key)
  636. (concat "\\|"
  637. (c-lang-const c-opt-identifier-prefix-key))
  638. "")))
  639. (c-lang-defvar c-identifier-start (c-lang-const c-identifier-start))
  640. (c-lang-defconst c-identifier-key
  641. "Regexp matching a fully qualified identifier, like \"A::B::c\" in
  642. C++. It does not recognize the full range of syntactic whitespace
  643. between the tokens; `c-forward-name' has to be used for that. It
  644. should also not match identifiers containing parenthesis groupings,
  645. e.g. identifiers with template arguments such as \"A<X,Y>\" in C++."
  646. ;; This regexp is more complex than strictly necessary to ensure
  647. ;; that it can be matched with a minimum of backtracking.
  648. t (concat (if (c-lang-const c-opt-identifier-prefix-key)
  649. (concat
  650. "\\("
  651. (c-lang-const c-opt-identifier-prefix-key)
  652. (c-lang-const c-simple-ws) "*"
  653. "\\)?")
  654. "")
  655. "\\(" (c-lang-const c-symbol-key) "\\)"
  656. (if (c-lang-const c-opt-identifier-concat-key)
  657. (concat
  658. "\\("
  659. (c-lang-const c-simple-ws) "*"
  660. (c-lang-const c-opt-identifier-concat-key)
  661. (c-lang-const c-simple-ws) "*"
  662. (if (c-lang-const c-after-id-concat-ops)
  663. (concat
  664. "\\("
  665. (c-make-keywords-re 'appendable
  666. (c-lang-const c-after-id-concat-ops))
  667. (concat
  668. ;; For flexibility, consider the symbol match
  669. ;; optional if we've hit a
  670. ;; `c-after-id-concat-ops' operator. This is
  671. ;; also necessary to handle the "*" that can
  672. ;; end import declaration identifiers in Java.
  673. "\\("
  674. (c-lang-const c-simple-ws) "*"
  675. "\\(" (c-lang-const c-symbol-key) "\\)"
  676. "\\)?")
  677. "\\|"
  678. "\\(" (c-lang-const c-symbol-key) "\\)"
  679. "\\)")
  680. (concat "\\(" (c-lang-const c-symbol-key) "\\)"))
  681. "\\)*")
  682. "")))
  683. (c-lang-defvar c-identifier-key (c-lang-const c-identifier-key))
  684. (c-lang-defconst c-identifier-last-sym-match
  685. ;; This was a docstring constant in 5.30 but it's no longer used.
  686. ;; It's only kept to avoid breaking third party code.
  687. ;;
  688. ;; Used to identify the submatch in `c-identifier-key' that
  689. ;; surrounds the last symbol in the qualified identifier. It's a
  690. ;; list of submatch numbers, of which the first that has a match is
  691. ;; taken. It's assumed that at least one does when the regexp has
  692. ;; matched.
  693. t nil)
  694. (c-lang-defconst c-string-escaped-newlines
  695. "Set if the language support backslash escaped newlines inside string
  696. literals."
  697. t nil
  698. (c c++ objc pike) t)
  699. (c-lang-defvar c-string-escaped-newlines
  700. (c-lang-const c-string-escaped-newlines))
  701. (c-lang-defconst c-multiline-string-start-char
  702. "Set if the language supports multiline string literals without escaped
  703. newlines. If t, all string literals are multiline. If a character,
  704. only literals where the open quote is immediately preceded by that
  705. literal are multiline."
  706. t nil
  707. pike ?#)
  708. (c-lang-defvar c-multiline-string-start-char
  709. (c-lang-const c-multiline-string-start-char))
  710. (c-lang-defconst c-opt-cpp-symbol
  711. "The symbol which starts preprocessor constructs when in the margin."
  712. t "#"
  713. (java awk) nil)
  714. (c-lang-defvar c-opt-cpp-symbol (c-lang-const c-opt-cpp-symbol))
  715. (c-lang-defconst c-opt-cpp-prefix
  716. "Regexp matching the prefix of a cpp directive in the languages that
  717. normally use that macro preprocessor. Tested at bol or at boi.
  718. Assumed to not contain any submatches or \\| operators."
  719. ;; TODO (ACM, 2005-04-01). Amend the following to recognize escaped NLs;
  720. ;; amend all uses of c-opt-cpp-prefix which count regexp-depth.
  721. t "\\s *#\\s *"
  722. (java awk) nil)
  723. (c-lang-defvar c-opt-cpp-prefix (c-lang-const c-opt-cpp-prefix))
  724. (c-lang-defconst c-anchored-cpp-prefix
  725. "Regexp matching the prefix of a cpp directive anchored to BOL,
  726. in the languages that have a macro preprocessor."
  727. t (if (c-lang-const c-opt-cpp-prefix)
  728. (concat "^" (c-lang-const c-opt-cpp-prefix))))
  729. (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
  730. (c-lang-defconst c-opt-cpp-start
  731. "Regexp matching the prefix of a cpp directive including the directive
  732. name, or nil in languages without preprocessor support. The first
  733. submatch surrounds the directive name."
  734. t (if (c-lang-const c-opt-cpp-prefix)
  735. (concat (c-lang-const c-opt-cpp-prefix)
  736. "\\([" c-alnum "]+\\)"))
  737. ;; Pike, being a scripting language, recognizes hash-bangs too.
  738. pike (concat (c-lang-const c-opt-cpp-prefix)
  739. "\\([" c-alnum "]+\\|!\\)"))
  740. (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
  741. (c-lang-defconst c-cpp-message-directives
  742. "List of cpp directives (without the prefix) that are followed by a
  743. string message."
  744. t (if (c-lang-const c-opt-cpp-prefix)
  745. '("error"))
  746. (c c++ objc pike) '("error" "warning"))
  747. (c-lang-defconst c-cpp-include-directives
  748. "List of cpp directives (without the prefix) that are followed by a
  749. file name in angle brackets or quotes."
  750. t (if (c-lang-const c-opt-cpp-prefix)
  751. '("include"))
  752. objc '("include" "import"))
  753. (c-lang-defconst c-opt-cpp-macro-define
  754. "Cpp directive (without the prefix) that is followed by a macro
  755. definition, or nil if the language doesn't have any."
  756. t (if (c-lang-const c-opt-cpp-prefix)
  757. "define"))
  758. (c-lang-defvar c-opt-cpp-macro-define
  759. (c-lang-const c-opt-cpp-macro-define))
  760. (c-lang-defconst c-opt-cpp-macro-define-start
  761. ;; Regexp matching everything up to the macro body of a cpp define, or the
  762. ;; end of the logical line if there is none. Submatch 1 is the name of the
  763. ;; macro. Set if c-opt-cpp-macro-define is.
  764. t (if (c-lang-const c-opt-cpp-macro-define)
  765. (concat (c-lang-const c-opt-cpp-prefix)
  766. (c-lang-const c-opt-cpp-macro-define)
  767. "[ \t]+\\(\\(\\sw\\|_\\)+\\)\\(\([^\)]*\)\\)?"
  768. ;; ^ ^ #defined name
  769. "\\([ \t]\\|\\\\\n\\)*")))
  770. (c-lang-defvar c-opt-cpp-macro-define-start
  771. (c-lang-const c-opt-cpp-macro-define-start))
  772. (c-lang-defconst c-opt-cpp-macro-define-id
  773. ;; Regexp matching everything up to the end of the identifier defined
  774. ;; by a cpp define.
  775. t (if (c-lang-const c-opt-cpp-macro-define)
  776. (concat (c-lang-const c-opt-cpp-prefix) ; #
  777. (c-lang-const c-opt-cpp-macro-define) ; define
  778. "[ \t]+\\(\\sw\\|_\\)+")))
  779. (c-lang-defvar c-opt-cpp-macro-define-id
  780. (c-lang-const c-opt-cpp-macro-define-id))
  781. (c-lang-defconst c-cpp-expr-directives
  782. "List of cpp directives (without the prefix) that are followed by an
  783. expression."
  784. t (if (c-lang-const c-opt-cpp-prefix)
  785. '("if" "elif")))
  786. (c-lang-defconst c-cpp-expr-intro-re
  787. "Regexp which matches the start of a CPP directive which contains an
  788. expression, or nil if there aren't any in the language."
  789. t (if (c-lang-const c-cpp-expr-directives)
  790. (concat
  791. (c-lang-const c-opt-cpp-prefix)
  792. (c-make-keywords-re t (c-lang-const c-cpp-expr-directives)))))
  793. (c-lang-defvar c-cpp-expr-intro-re
  794. (c-lang-const c-cpp-expr-intro-re))
  795. (c-lang-defconst c-cpp-expr-functions
  796. "List of functions in cpp expressions."
  797. t (if (c-lang-const c-opt-cpp-prefix)
  798. '("defined"))
  799. pike '("defined" "efun" "constant"))
  800. (c-lang-defconst c-assignment-operators
  801. "List of all assignment operators."
  802. t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
  803. java (append (c-lang-const c-assignment-operators)
  804. '(">>>="))
  805. c++ (append (c-lang-const c-assignment-operators)
  806. '("and_eq" "or_eq" "xor_eq" "??!=" "??'="))
  807. idl nil)
  808. (c-lang-defconst c-operators
  809. "List describing all operators, along with their precedence and
  810. associativity. The order in the list corresponds to the precedence of
  811. the operators: The operators in each element are a group with the same
  812. precedence, and the group has higher precedence than the groups in all
  813. following elements. The car of each element describes the type of the
  814. operator group, and the cdr is a list of the operator tokens in it.
  815. The operator group types are:
  816. 'prefix Unary prefix operators.
  817. 'postfix Unary postfix operators.
  818. 'postfix-if-paren
  819. Unary postfix operators if and only if the chars have
  820. parenthesis syntax.
  821. 'left-assoc Binary left associative operators (i.e. a+b+c means (a+b)+c).
  822. 'right-assoc Binary right associative operators (i.e. a=b=c means a=(b=c)).
  823. 'right-assoc-sequence
  824. Right associative operator that constitutes of a
  825. sequence of tokens that separate expressions. All the
  826. tokens in the group are in this case taken as
  827. describing the sequence in one such operator, and the
  828. order between them is therefore significant.
  829. Operators containing a character with paren syntax are taken to match
  830. with a corresponding open/close paren somewhere else. A postfix
  831. operator with close paren syntax is taken to end a postfix expression
  832. started somewhere earlier, rather than start a new one at point. Vice
  833. versa for prefix operators with open paren syntax.
  834. Note that operators like \".\" and \"->\" which in language references
  835. often are described as postfix operators are considered binary here,
  836. since CC Mode treats every identifier as an expression."
  837. ;; There's currently no code in CC Mode that exploit all the info
  838. ;; in this variable; precedence, associativity etc are present as a
  839. ;; preparation for future work.
  840. t `(;; Preprocessor.
  841. ,@(when (c-lang-const c-opt-cpp-prefix)
  842. `((prefix "#"
  843. ,@(when (c-major-mode-is '(c-mode c++-mode))
  844. '("%:" "??=")))
  845. (left-assoc "##"
  846. ,@(when (c-major-mode-is '(c-mode c++-mode))
  847. '("%:%:" "??=??=")))))
  848. ;; Primary.
  849. ,@(c-lang-const c-identifier-ops)
  850. ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
  851. `((postfix-if-paren "<" ">"))) ; Templates.
  852. ((c-major-mode-is 'pike-mode)
  853. `((prefix "global" "predef")))
  854. ((c-major-mode-is 'java-mode)
  855. `((prefix "super"))))
  856. ;; Postfix.
  857. ,@(when (c-major-mode-is 'c++-mode)
  858. ;; The following need special treatment.
  859. `((prefix "dynamic_cast" "static_cast"
  860. "reinterpret_cast" "const_cast" "typeid")))
  861. (left-assoc "."
  862. ,@(unless (c-major-mode-is 'java-mode)
  863. '("->")))
  864. (postfix "++" "--" "[" "]" "(" ")"
  865. ,@(when (c-major-mode-is '(c-mode c++-mode))
  866. '("<:" ":>" "??(" "??)")))
  867. ;; Unary.
  868. (prefix "++" "--" "+" "-" "!" "~"
  869. ,@(when (c-major-mode-is 'c++-mode) '("not" "compl"))
  870. ,@(when (c-major-mode-is '(c-mode c++-mode))
  871. '("*" "&" "sizeof" "??-"))
  872. ,@(when (c-major-mode-is 'objc-mode)
  873. '("@selector" "@protocol" "@encode"))
  874. ;; The following need special treatment.
  875. ,@(cond ((c-major-mode-is 'c++-mode)
  876. '("new" "delete"))
  877. ((c-major-mode-is 'java-mode)
  878. '("new"))
  879. ((c-major-mode-is 'pike-mode)
  880. '("class" "lambda" "catch" "throw" "gauge")))
  881. "(" ")" ; Cast.
  882. ,@(when (c-major-mode-is 'pike-mode)
  883. '("[" "]"))) ; Type cast.
  884. ;; Member selection.
  885. ,@(when (c-major-mode-is 'c++-mode)
  886. `((left-assoc ".*" "->*")))
  887. ;; Multiplicative.
  888. (left-assoc "*" "/" "%")
  889. ;; Additive.
  890. (left-assoc "+" "-")
  891. ;; Shift.
  892. (left-assoc "<<" ">>"
  893. ,@(when (c-major-mode-is 'java-mode)
  894. '(">>>")))
  895. ;; Relational.
  896. (left-assoc "<" ">" "<=" ">="
  897. ,@(when (c-major-mode-is 'java-mode)
  898. '("instanceof")))
  899. ;; Equality.
  900. (left-assoc "==" "!="
  901. ,@(when (c-major-mode-is 'c++-mode) '("not_eq")))
  902. ;; Bitwise and.
  903. (left-assoc "&"
  904. ,@(when (c-major-mode-is 'c++-mode) '("bitand")))
  905. ;; Bitwise exclusive or.
  906. (left-assoc "^"
  907. ,@(when (c-major-mode-is '(c-mode c++-mode))
  908. '("??'"))
  909. ,@(when (c-major-mode-is 'c++-mode) '("xor")))
  910. ;; Bitwise or.
  911. (left-assoc "|"
  912. ,@(when (c-major-mode-is '(c-mode c++-mode))
  913. '("??!"))
  914. ,@(when (c-major-mode-is 'c++-mode) '("bitor")))
  915. ;; Logical and.
  916. (left-assoc "&&"
  917. ,@(when (c-major-mode-is 'c++-mode) '("and")))
  918. ;; Logical or.
  919. (left-assoc "||"
  920. ,@(when (c-major-mode-is '(c-mode c++-mode))
  921. '("??!??!"))
  922. ,@(when (c-major-mode-is 'c++-mode) '("or")))
  923. ;; Conditional.
  924. (right-assoc-sequence "?" ":")
  925. ;; Assignment.
  926. (right-assoc ,@(c-lang-const c-assignment-operators))
  927. ;; Exception.
  928. ,@(when (c-major-mode-is 'c++-mode)
  929. '((prefix "throw")))
  930. ;; Sequence.
  931. (left-assoc ","))
  932. ;; IDL got its own definition since it has a much smaller operator
  933. ;; set than the other languages.
  934. idl `(;; Preprocessor.
  935. (prefix "#")
  936. (left-assoc "##")
  937. ;; Primary.
  938. ,@(c-lang-const c-identifier-ops)
  939. ;; Unary.
  940. (prefix "+" "-" "~")
  941. ;; Multiplicative.
  942. (left-assoc "*" "/" "%")
  943. ;; Additive.
  944. (left-assoc "+" "-")
  945. ;; Shift.
  946. (left-assoc "<<" ">>")
  947. ;; And.
  948. (left-assoc "&")
  949. ;; Xor.
  950. (left-assoc "^")
  951. ;; Or.
  952. (left-assoc "|")))
  953. (c-lang-defconst c-operator-list
  954. ;; The operators as a flat list (without duplicates).
  955. t (c-filter-ops (c-lang-const c-operators) t t))
  956. (c-lang-defconst c-overloadable-operators
  957. "List of the operators that are overloadable, in their \"identifier
  958. form\". See also `c-op-identifier-prefix'."
  959. t nil
  960. c++ '("new" "delete" ;; Can be followed by "[]" but we ignore that.
  961. "+" "-" "*" "/" "%"
  962. "^" "??'" "xor" "&" "bitand" "|" "??!" "bitor" "~" "??-" "compl"
  963. "!" "=" "<" ">" "+=" "-=" "*=" "/=" "%=" "^="
  964. "??'=" "xor_eq" "&=" "and_eq" "|=" "??!=" "or_eq"
  965. "<<" ">>" ">>=" "<<=" "==" "!=" "not_eq" "<=" ">="
  966. "&&" "and" "||" "??!??!" "or" "++" "--" "," "->*" "->"
  967. "()" "[]" "<::>" "??(??)")
  968. ;; These work like identifiers in Pike.
  969. pike '("`+" "`-" "`&" "`|" "`^" "`<<" "`>>" "`*" "`/" "`%" "`~"
  970. "`==" "`<" "`>" "`!" "`[]" "`[]=" "`->" "`->=" "`()" "``+"
  971. "``-" "``&" "``|" "``^" "``<<" "``>>" "``*" "``/" "``%"
  972. "`+="))
  973. (c-lang-defconst c-overloadable-operators-regexp
  974. ;; Regexp tested after an "operator" token in C++.
  975. t nil
  976. c++ (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))
  977. (c-lang-defvar c-overloadable-operators-regexp
  978. (c-lang-const c-overloadable-operators-regexp))
  979. (c-lang-defconst c-opt-op-identifier-prefix
  980. "Regexp matching the token before the ones in
  981. `c-overloadable-operators' when operators are specified in their
  982. \"identifier form\". This typically matches \"operator\" in C++ where
  983. operator functions are specified as e.g. \"operator +\". It's nil in
  984. languages without operator functions or where the complete operator
  985. identifier is listed in `c-overloadable-operators'.
  986. This regexp is assumed to not match any non-operator identifier."
  987. t nil
  988. c++ (c-make-keywords-re t '("operator")))
  989. (c-lang-defvar c-opt-op-identifier-prefix
  990. (c-lang-const c-opt-op-identifier-prefix))
  991. ;; Note: the following alias is an old name which was a mis-spelling. It has
  992. ;; been corrected above and throughout cc-engine.el. It will be removed at
  993. ;; some release very shortly in the future. ACM, 2006-04-14.
  994. (defvaralias 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix)
  995. (make-obsolete-variable 'c-opt-op-identitier-prefix 'c-opt-op-identifier-prefix
  996. "CC Mode 5.31.4, 2006-04-14")
  997. (c-lang-defconst c-other-op-syntax-tokens
  998. "List of the tokens made up of characters in the punctuation or
  999. parenthesis syntax classes that have uses other than as expression
  1000. operators."
  1001. t '("{" "}" "(" ")" "[" "]" ";" ":" "," "=" "/*" "*/" "//")
  1002. (c c++ pike) (append '("#" "##" ; Used by cpp.
  1003. "::" "...")
  1004. (c-lang-const c-other-op-syntax-tokens))
  1005. (c c++) (append '("*") (c-lang-const c-other-op-syntax-tokens))
  1006. c++ (append '("&" "<%" "%>" "<:" ":>" "%:" "%:%:")
  1007. (c-lang-const c-other-op-syntax-tokens))
  1008. objc (append '("#" "##" ; Used by cpp.
  1009. "+" "-") (c-lang-const c-other-op-syntax-tokens))
  1010. idl (append '("#" "##") ; Used by cpp.
  1011. (c-lang-const c-other-op-syntax-tokens))
  1012. pike (append '("..")
  1013. (c-lang-const c-other-op-syntax-tokens)
  1014. (c-lang-const c-overloadable-operators))
  1015. awk '("{" "}" "(" ")" "[" "]" ";" "," "=" "/"))
  1016. (c-lang-defconst c-all-op-syntax-tokens
  1017. ;; List of all tokens in the punctuation and parenthesis syntax
  1018. ;; classes.
  1019. t (delete-duplicates (append (c-lang-const c-other-op-syntax-tokens)
  1020. (c-lang-const c-operator-list))
  1021. :test 'string-equal))
  1022. (c-lang-defconst c-nonsymbol-token-char-list
  1023. ;; List containing all chars not in the word, symbol or
  1024. ;; syntactically irrelevant syntax classes, i.e. all punctuation,
  1025. ;; parenthesis and string delimiter chars.
  1026. t (c-with-syntax-table (c-lang-const c-mode-syntax-table)
  1027. ;; Only go through the chars in the printable ASCII range. No
  1028. ;; language so far has 8-bit or widestring operators.
  1029. (let (list (char 32))
  1030. (while (< char 127)
  1031. (or (memq (char-syntax char) '(?w ?_ ?< ?> ?\ ))
  1032. (setq list (cons (c-int-to-char char) list)))
  1033. (setq char (1+ char)))
  1034. list)))
  1035. (c-lang-defconst c-nonsymbol-token-regexp
  1036. ;; Regexp matching all tokens in the punctuation and parenthesis
  1037. ;; syntax classes. Note that this also matches ".", which can start
  1038. ;; a float.
  1039. t (c-make-keywords-re nil
  1040. (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
  1041. t
  1042. "\\`\\(\\s.\\|\\s\(\\|\\s\)\\)+\\'")))
  1043. (c-lang-defvar c-nonsymbol-token-regexp
  1044. (c-lang-const c-nonsymbol-token-regexp))
  1045. (c-lang-defconst c-assignment-op-regexp
  1046. ;; Regexp matching all assignment operators and only them. The
  1047. ;; beginning of the first submatch is used to detect the end of the
  1048. ;; token, along with the end of the whole match.
  1049. t (if (c-lang-const c-assignment-operators)
  1050. (concat
  1051. ;; Need special case for "=" since it's a prefix of "==".
  1052. "=\\([^=]\\|$\\)"
  1053. "\\|"
  1054. (c-make-keywords-re nil
  1055. (set-difference (c-lang-const c-assignment-operators)
  1056. '("=")
  1057. :test 'string-equal)))
  1058. "\\<\\>"))
  1059. (c-lang-defvar c-assignment-op-regexp
  1060. (c-lang-const c-assignment-op-regexp))
  1061. (c-lang-defconst c-<>-multichar-token-regexp
  1062. ;; Regexp matching all tokens containing "<" or ">" which are longer
  1063. ;; than one char.
  1064. t (c-make-keywords-re nil
  1065. (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
  1066. t
  1067. ".[<>]\\|[<>].")))
  1068. (c-lang-defvar c-<>-multichar-token-regexp
  1069. (c-lang-const c-<>-multichar-token-regexp))
  1070. (c-lang-defconst c-<-op-cont-regexp
  1071. ;; Regexp matching the second and subsequent characters of all
  1072. ;; multicharacter tokens that begin with "<".
  1073. t (c-make-keywords-re nil
  1074. (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
  1075. t
  1076. "\\`<."
  1077. (lambda (op) (substring op 1)))))
  1078. (c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
  1079. (c-lang-defconst c->-op-cont-regexp
  1080. ;; Regexp matching the second and subsequent characters of all
  1081. ;; multicharacter tokens that begin with ">".
  1082. t (c-make-keywords-re nil
  1083. (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
  1084. t
  1085. "\\`>."
  1086. (lambda (op) (substring op 1))))
  1087. java (c-make-keywords-re nil
  1088. (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
  1089. t
  1090. "\\`>[^>]\\|\\`>>[^>]"
  1091. (lambda (op) (substring op 1)))))
  1092. (c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
  1093. (c-lang-defconst c-stmt-delim-chars
  1094. ;; The characters that should be considered to bound statements. To
  1095. ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to
  1096. ;; begin with "^" to negate the set. If ? : operators should be
  1097. ;; detected then the string must end with "?:".
  1098. t "^;{}?:")
  1099. (c-lang-defvar c-stmt-delim-chars (c-lang-const c-stmt-delim-chars))
  1100. (c-lang-defconst c-stmt-delim-chars-with-comma
  1101. ;; Variant of `c-stmt-delim-chars' that additionally contains ','.
  1102. t "^;,{}?:")
  1103. (c-lang-defvar c-stmt-delim-chars-with-comma
  1104. (c-lang-const c-stmt-delim-chars-with-comma))
  1105. ;;; Syntactic whitespace.
  1106. (c-lang-defconst c-simple-ws
  1107. "Regexp matching an ordinary whitespace character.
  1108. Does not contain a \\| operator at the top level."
  1109. ;; "\\s " is not enough since it doesn't match line breaks.
  1110. t "\\(\\s \\|[\n\r]\\)")
  1111. (c-lang-defconst c-simple-ws-depth
  1112. ;; Number of regexp grouping parens in `c-simple-ws'.
  1113. t (regexp-opt-depth (c-lang-const c-simple-ws)))
  1114. (c-lang-defconst c-line-comment-starter
  1115. "String that starts line comments, or nil if such don't exist.
  1116. Line comments are always terminated by newlines. At least one of
  1117. `c-block-comment-starter' and this one is assumed to be set.
  1118. Note that it's currently not enough to set this to support a new
  1119. comment style. Other stuff like the syntax table must also be set up
  1120. properly."
  1121. t "//"
  1122. awk "#")
  1123. (c-lang-defvar c-line-comment-starter (c-lang-const c-line-comment-starter))
  1124. (c-lang-defconst c-block-comment-starter
  1125. "String that starts block comments, or nil if such don't exist.
  1126. Block comments are ended by `c-block-comment-ender', which is assumed
  1127. to be set if this is. At least one of `c-line-comment-starter' and
  1128. this one is assumed to be set.
  1129. Note that it's currently not enough to set this to support a new
  1130. comment style. Other stuff like the syntax table must also be set up
  1131. properly."
  1132. t "/*"
  1133. awk nil)
  1134. (c-lang-defconst c-block-comment-ender
  1135. "String that ends block comments, or nil if such don't exist.
  1136. Note that it's currently not enough to set this to support a new
  1137. comment style. Other stuff like the syntax table must also be set up
  1138. properly."
  1139. t "*/"
  1140. awk nil)
  1141. (c-lang-defconst c-comment-start-regexp
  1142. ;; Regexp to match the start of any type of comment.
  1143. t (let ((re (c-make-keywords-re nil
  1144. (list (c-lang-const c-line-comment-starter)
  1145. (c-lang-const c-block-comment-starter)))))
  1146. (if (memq 'gen-comment-delim c-emacs-features)
  1147. (concat re "\\|\\s!")
  1148. re)))
  1149. (c-lang-defvar c-comment-start-regexp (c-lang-const c-comment-start-regexp))
  1150. (c-lang-defconst c-block-comment-start-regexp
  1151. ;; Regexp which matches the start of a block comment (if such exists in the
  1152. ;; language)
  1153. t (if (c-lang-const c-block-comment-starter)
  1154. (regexp-quote (c-lang-const c-block-comment-starter))
  1155. "\\<\\>"))
  1156. (c-lang-defvar c-block-comment-start-regexp
  1157. (c-lang-const c-block-comment-start-regexp))
  1158. (c-lang-defconst c-line-comment-start-regexp
  1159. ;; Regexp which matches the start of a line comment (if such exists in the
  1160. ;; language; it does in all 7 CC Mode languages).
  1161. t (if (c-lang-const c-line-comment-starter)
  1162. (regexp-quote (c-lang-const c-line-comment-starter))
  1163. "\\<\\>"))
  1164. (c-lang-defvar c-line-comment-start-regexp
  1165. (c-lang-const c-line-comment-start-regexp))
  1166. (c-lang-defconst c-literal-start-regexp
  1167. ;; Regexp to match the start of comments and string literals.
  1168. t (concat (c-lang-const c-comment-start-regexp)
  1169. "\\|"
  1170. (if (memq 'gen-string-delim c-emacs-features)
  1171. "\"|"
  1172. "\"")))
  1173. (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp))
  1174. (c-lang-defconst c-doc-comment-start-regexp
  1175. "Regexp to match the start of documentation comments."
  1176. t "\\<\\>"
  1177. ;; From font-lock.el: `doxygen' uses /*! while others use /**.
  1178. (c c++ objc) "/\\*[*!]"
  1179. java "/\\*\\*"
  1180. pike "/[/*]!")
  1181. (c-lang-defvar c-doc-comment-start-regexp
  1182. (c-lang-const c-doc-comment-start-regexp))
  1183. (c-lang-defconst comment-start
  1184. "String that starts comments inserted with M-; etc.
  1185. `comment-start' is initialized from this."
  1186. ;; Default: Prefer line comments to block comments, and pad with a space.
  1187. t (concat (or (c-lang-const c-line-comment-starter)
  1188. (c-lang-const c-block-comment-starter))
  1189. " ")
  1190. ;; In C we still default to the block comment style since line
  1191. ;; comments aren't entirely portable.
  1192. c "/* ")
  1193. (c-lang-setvar comment-start (c-lang-const comment-start))
  1194. (c-lang-defconst comment-end
  1195. "String that ends comments inserted with M-; etc.
  1196. `comment-end' is initialized from this."
  1197. ;; Default: Use block comment style if comment-start uses block
  1198. ;; comments, and pad with a space in that case.
  1199. t (if (string-match (concat "\\`\\("
  1200. (c-lang-const c-block-comment-start-regexp)
  1201. "\\)")
  1202. (c-lang-const comment-start))
  1203. (concat " " (c-lang-const c-block-comment-ender))
  1204. ""))
  1205. (c-lang-setvar comment-end (c-lang-const comment-end))
  1206. (c-lang-defconst comment-start-skip
  1207. "Regexp to match the start of a comment plus everything up to its body.
  1208. `comment-start-skip' is initialized from this."
  1209. ;; Default: Allow the last char of the comment starter(s) to be
  1210. ;; repeated, then allow any amount of horizontal whitespace.
  1211. t (concat "\\("
  1212. (c-concat-separated
  1213. (mapcar (lambda (cs)
  1214. (when cs
  1215. (concat (regexp-quote cs) "+")))
  1216. (list (c-lang-const c-line-comment-starter)
  1217. (c-lang-const c-block-comment-starter)))
  1218. "\\|")
  1219. "\\)\\s *"))
  1220. (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
  1221. (c-lang-defconst c-syntactic-ws-start
  1222. ;; Regexp matching any sequence that can start syntactic whitespace.
  1223. ;; The only uncertain case is '#' when there are cpp directives.
  1224. t (concat "\\s \\|"
  1225. (c-make-keywords-re nil
  1226. (append (list (c-lang-const c-line-comment-starter)
  1227. (c-lang-const c-block-comment-starter)
  1228. (when (c-lang-const c-opt-cpp-prefix)
  1229. "#"))
  1230. '("\n" "\r")))
  1231. "\\|\\\\[\n\r]"
  1232. (when (memq 'gen-comment-delim c-emacs-features)
  1233. "\\|\\s!")))
  1234. (c-lang-defvar c-syntactic-ws-start (c-lang-const c-syntactic-ws-start))
  1235. (c-lang-defconst c-syntactic-ws-end
  1236. ;; Regexp matching any single character that might end syntactic whitespace.
  1237. t (concat "\\s \\|"
  1238. (c-make-keywords-re nil
  1239. (append (when (c-lang-const c-block-comment-ender)
  1240. (list
  1241. (string
  1242. (elt (c-lang-const c-block-comment-ender)
  1243. (1- (length
  1244. (c-lang-const c-block-comment-ender)))))))
  1245. '("\n" "\r")))
  1246. (when (memq 'gen-comment-delim c-emacs-features)
  1247. "\\|\\s!")))
  1248. (c-lang-defvar c-syntactic-ws-end (c-lang-const c-syntactic-ws-end))
  1249. (c-lang-defconst c-unterminated-block-comment-regexp
  1250. ;; Regexp matching an unterminated block comment that doesn't
  1251. ;; contain line breaks, or nil in languages without block comments.
  1252. ;; Does not contain a \| operator at the top level.
  1253. t (when (c-lang-const c-block-comment-starter)
  1254. (concat
  1255. (regexp-quote (c-lang-const c-block-comment-starter))
  1256. ;; It's messy to cook together a regexp that matches anything
  1257. ;; but c-block-comment-ender.
  1258. (let ((end (c-lang-const c-block-comment-ender)))
  1259. (cond ((= (length end) 1)
  1260. (concat "[^" end "\n\r]*"))
  1261. ((= (length end) 2)
  1262. (concat "[^" (substring end 0 1) "\n\r]*"
  1263. "\\("
  1264. (regexp-quote (substring end 0 1)) "+"
  1265. "[^"
  1266. ;; The quoting rules inside char classes are silly. :P
  1267. (cond ((= (elt end 0) (elt end 1))
  1268. (concat (substring end 0 1) "\n\r"))
  1269. ((= (elt end 1) ?\])
  1270. (concat (substring end 1 2) "\n\r"
  1271. (substring end 0 1)))
  1272. (t
  1273. (concat (substring end 0 1) "\n\r"
  1274. (substring end 1 2))))
  1275. "]"
  1276. "[^" (substring end 0 1) "\n\r]*"
  1277. "\\)*"))
  1278. (t
  1279. (error "Can't handle a block comment ender of length %s"
  1280. (length end))))))))
  1281. (c-lang-defconst c-block-comment-regexp
  1282. ;; Regexp matching a block comment that doesn't contain line breaks,
  1283. ;; or nil in languages without block comments. The reason we don't
  1284. ;; allow line breaks is to avoid going very far and risk running out
  1285. ;; of regexp stack; this regexp is intended to handle only short
  1286. ;; comments that might be put in the middle of limited constructs
  1287. ;; like declarations. Does not contain a \| operator at the top
  1288. ;; level.
  1289. t (when (c-lang-const c-unterminated-block-comment-regexp)
  1290. (concat
  1291. (c-lang-const c-unterminated-block-comment-regexp)
  1292. (let ((end (c-lang-const c-block-comment-ender)))
  1293. (cond ((= (length end) 1)
  1294. (regexp-quote end))
  1295. ((= (length end) 2)
  1296. (concat (regexp-quote (substring end 0 1)) "+"
  1297. (regexp-quote (substring end 1 2))))
  1298. (t
  1299. (error "Can't handle a block comment ender of length %s"
  1300. (length end))))))))
  1301. (c-lang-defconst c-nonwhite-syntactic-ws
  1302. ;; Regexp matching a piece of syntactic whitespace that isn't a
  1303. ;; sequence of simple whitespace characters. As opposed to
  1304. ;; `c-(forward|backward)-syntactic-ws', this doesn't regard cpp
  1305. ;; directives as syntactic whitespace.
  1306. t (c-concat-separated
  1307. (list (when (c-lang-const c-line-comment-starter)
  1308. (concat (regexp-quote (c-lang-const c-line-comment-starter))
  1309. "[^\n\r]*[\n\r]"))
  1310. (c-lang-const c-block-comment-regexp)
  1311. "\\\\[\n\r]"
  1312. (when (memq 'gen-comment-delim c-emacs-features)
  1313. "\\s!\\S!*\\s!"))
  1314. "\\|"))
  1315. (c-lang-defconst c-syntactic-ws
  1316. ;; Regexp matching syntactic whitespace, including possibly the
  1317. ;; empty string. As opposed to `c-(forward|backward)-syntactic-ws',
  1318. ;; this doesn't regard cpp directives as syntactic whitespace. Does
  1319. ;; not contain a \| operator at the top level.
  1320. t (concat (c-lang-const c-simple-ws) "*"
  1321. "\\("
  1322. (concat "\\(" (c-lang-const c-nonwhite-syntactic-ws) "\\)"
  1323. (c-lang-const c-simple-ws) "*")
  1324. "\\)*"))
  1325. (c-lang-defconst c-syntactic-ws-depth
  1326. ;; Number of regexp grouping parens in `c-syntactic-ws'.
  1327. t (regexp-opt-depth (c-lang-const c-syntactic-ws)))
  1328. (c-lang-defconst c-nonempty-syntactic-ws
  1329. ;; Regexp matching syntactic whitespace, which is at least one
  1330. ;; character long. As opposed to `c-(forward|backward)-syntactic-ws',
  1331. ;; this doesn't regard cpp directives as syntactic whitespace. Does
  1332. ;; not contain a \| operator at the top level.
  1333. t (concat "\\("
  1334. (c-lang-const c-simple-ws)
  1335. "\\|"
  1336. (c-lang-const c-nonwhite-syntactic-ws)
  1337. "\\)+"))
  1338. (c-lang-defconst c-nonempty-syntactic-ws-depth
  1339. ;; Number of regexp grouping parens in `c-nonempty-syntactic-ws'.
  1340. t (regexp-opt-depth (c-lang-const c-nonempty-syntactic-ws)))
  1341. (c-lang-defconst c-single-line-syntactic-ws
  1342. ;; Regexp matching syntactic whitespace without any line breaks. As
  1343. ;; opposed to `c-(forward|backward)-syntactic-ws', this doesn't
  1344. ;; regard cpp directives as syntactic whitespace. Does not contain
  1345. ;; a \| operator at the top level.
  1346. t (if (c-lang-const c-block-comment-regexp)
  1347. (concat "\\s *\\("
  1348. (c-lang-const c-block-comment-regexp)
  1349. "\\s *\\)*")
  1350. "\\s *"))
  1351. (c-lang-defconst c-single-line-syntactic-ws-depth
  1352. ;; Number of regexp grouping parens in `c-single-line-syntactic-ws'.
  1353. t (regexp-opt-depth (c-lang-const c-single-line-syntactic-ws)))
  1354. (c-lang-defconst c-syntactic-eol
  1355. ;; Regexp that matches when there is no syntactically significant
  1356. ;; text before eol. Macros are regarded as syntactically
  1357. ;; significant text here.
  1358. t (concat (c-lang-const c-single-line-syntactic-ws)
  1359. ;; Match eol (possibly inside a block comment or preceded
  1360. ;; by a line continuation backslash), or the beginning of a
  1361. ;; line comment. Note: This has to be modified for awk
  1362. ;; where line comments start with '#'.
  1363. "\\("
  1364. (c-concat-separated
  1365. (list (when (c-lang-const c-line-comment-starter)
  1366. (regexp-quote (c-lang-const c-line-comment-starter)))
  1367. (when (c-lang-const c-unterminated-block-comment-regexp)
  1368. (concat (c-lang-const c-unterminated-block-comment-regexp)
  1369. "$"))
  1370. "\\\\$"
  1371. "$")
  1372. "\\|")
  1373. "\\)"))
  1374. (c-lang-defvar c-syntactic-eol (c-lang-const c-syntactic-eol))
  1375. ;;; Defun functions
  1376. ;; The Emacs variables beginning-of-defun-function and
  1377. ;; end-of-defun-function will be set so that commands like
  1378. ;; `mark-defun' and `narrow-to-defun' work right. The key sequences
  1379. ;; C-M-a and C-M-e are, however, bound directly to the CC Mode
  1380. ;; functions, allowing optimization for large n.
  1381. (c-lang-defconst beginning-of-defun-function
  1382. "Function to which beginning-of-defun-function will be set."
  1383. t 'c-beginning-of-defun
  1384. awk 'c-awk-beginning-of-defun)
  1385. (c-lang-setvar beginning-of-defun-function
  1386. (c-lang-const beginning-of-defun-function))
  1387. (c-lang-defconst end-of-defun-function
  1388. "Function to which end-of-defun-function will be set."
  1389. t 'c-end-of-defun
  1390. awk 'c-awk-end-of-defun)
  1391. (c-lang-setvar end-of-defun-function (c-lang-const end-of-defun-function))
  1392. ;;; In-comment text handling.
  1393. (c-lang-defconst c-paragraph-start
  1394. "Regexp to append to `paragraph-start'."
  1395. t "$"
  1396. java "\\(@[a-zA-Z]+\\>\\|$\\)" ; For Javadoc.
  1397. pike "\\(@[a-zA-Z_-]+\\>\\([^{]\\|$\\)\\|$\\)") ; For Pike refdoc.
  1398. (c-lang-defvar c-paragraph-start (c-lang-const c-paragraph-start))
  1399. (c-lang-defconst c-paragraph-separate
  1400. "Regexp to append to `paragraph-separate'."
  1401. t "$"
  1402. pike (c-lang-const c-paragraph-start))
  1403. (c-lang-defvar c-paragraph-separate (c-lang-const c-paragraph-separate))
  1404. ;;; Keyword lists.
  1405. ;; Note: All and only all language constants containing keyword lists
  1406. ;; should end with "-kwds"; they're automatically collected into the
  1407. ;; `c-kwds-lang-consts' list below and used to build `c-keywords' etc.
  1408. (c-lang-defconst c-primitive-type-kwds
  1409. "Primitive type keywords. As opposed to the other keyword lists, the
  1410. keywords listed here are fontified with the type face instead of the
  1411. keyword face.
  1412. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1413. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1414. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1415. will be handled.
  1416. Do not try to modify this list for end user customizations; the
  1417. `*-font-lock-extra-types' variable, where `*' is the mode prefix, is
  1418. the appropriate place for that."
  1419. t '("char" "double" "float" "int" "long" "short" "signed"
  1420. "unsigned" "void")
  1421. c (append
  1422. '("_Bool" "_Complex" "_Imaginary") ; Conditionally defined in C99.
  1423. (c-lang-const c-primitive-type-kwds))
  1424. c++ (append
  1425. '("bool" "wchar_t")
  1426. (c-lang-const c-primitive-type-kwds))
  1427. ;; Objective-C extends C, but probably not the new stuff in C99.
  1428. objc (append
  1429. '("id" "Class" "SEL" "IMP" "BOOL")
  1430. (c-lang-const c-primitive-type-kwds))
  1431. java '("boolean" "byte" "char" "double" "float" "int" "long" "short" "void")
  1432. idl '("Object" "ValueBase" "any" "boolean" "char" "double" "fixed" "float"
  1433. "long" "octet" "sequence" "short" "string" "void" "wchar" "wstring"
  1434. ;; In CORBA PSDL:
  1435. "ref"
  1436. ;; The following can't really end a type, but we have to specify them
  1437. ;; here due to the assumption in `c-primitive-type-prefix-kwds'. It
  1438. ;; doesn't matter that much.
  1439. "unsigned" "strong")
  1440. pike '(;; this_program isn't really a keyword, but it's practically
  1441. ;; used as a builtin type.
  1442. "array" "float" "function" "int" "mapping" "mixed" "multiset"
  1443. "object" "program" "string" "this_program" "void"))
  1444. (c-lang-defconst c-primitive-type-key
  1445. ;; An adorned regexp that matches `c-primitive-type-kwds'.
  1446. t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
  1447. (c-lang-defvar c-primitive-type-key (c-lang-const c-primitive-type-key))
  1448. (c-lang-defconst c-primitive-type-prefix-kwds
  1449. "Keywords that might act as prefixes for primitive types. Assumed to
  1450. be a subset of `c-primitive-type-kwds'."
  1451. t nil
  1452. (c c++) '("long" "short" "signed" "unsigned")
  1453. idl '("long" "unsigned"
  1454. ;; In CORBA PSDL:
  1455. "strong"))
  1456. (c-lang-defconst c-typedef-kwds
  1457. "Prefix keyword\(s\) like \"typedef\" which make a type declaration out
  1458. of a variable declaration."
  1459. t '("typedef")
  1460. (awk idl java) nil)
  1461. (c-lang-defconst c-typedef-key
  1462. ;; Adorned regexp matching `c-typedef-kwds'.
  1463. t (c-make-keywords-re t (c-lang-const c-typedef-kwds)))
  1464. (c-lang-defvar c-typedef-key (c-lang-const c-typedef-key))
  1465. (c-lang-defconst c-type-prefix-kwds
  1466. "Keywords where the following name - if any - is a type name, and
  1467. where the keyword together with the symbol works as a type in
  1468. declarations.
  1469. Note that an alternative if the second part doesn't hold is
  1470. `c-type-list-kwds'. Keywords on this list are typically also present
  1471. on one of the `*-decl-kwds' lists."
  1472. t nil
  1473. c '("struct" "union" "enum")
  1474. c++ (append '("class" "typename")
  1475. (c-lang-const c-type-prefix-kwds c)))
  1476. (c-lang-defconst c-type-prefix-key
  1477. ;; Adorned regexp matching `c-type-prefix-kwds'.
  1478. t (c-make-keywords-re t (c-lang-const c-type-prefix-kwds)))
  1479. (c-lang-defvar c-type-prefix-key (c-lang-const c-type-prefix-key))
  1480. (c-lang-defconst c-type-modifier-kwds
  1481. "Type modifier keywords. These can occur almost anywhere in types
  1482. but they don't build a type of themselves. Unlike the keywords on
  1483. `c-primitive-type-kwds', they are fontified with the keyword face and
  1484. not the type face."
  1485. t nil
  1486. c '("const" "restrict" "volatile")
  1487. c++ '("const" "volatile" "throw")
  1488. objc '("const" "volatile"))
  1489. (c-lang-defconst c-opt-type-modifier-key
  1490. ;; Adorned regexp matching `c-type-modifier-kwds', or nil in
  1491. ;; languages without such keywords.
  1492. t (and (c-lang-const c-type-modifier-kwds)
  1493. (c-make-keywords-re t (c-lang-const c-type-modifier-kwds))))
  1494. (c-lang-defvar c-opt-type-modifier-key (c-lang-const c-opt-type-modifier-key))
  1495. (c-lang-defconst c-opt-type-component-key
  1496. ;; An adorned regexp that matches `c-primitive-type-prefix-kwds' and
  1497. ;; `c-type-modifier-kwds', or nil in languages without any of them.
  1498. t (and (or (c-lang-const c-primitive-type-prefix-kwds)
  1499. (c-lang-const c-type-modifier-kwds))
  1500. (c-make-keywords-re t
  1501. (append (c-lang-const c-primitive-type-prefix-kwds)
  1502. (c-lang-const c-type-modifier-kwds)))))
  1503. (c-lang-defvar c-opt-type-component-key
  1504. (c-lang-const c-opt-type-component-key))
  1505. (c-lang-defconst c-type-start-kwds
  1506. ;; All keywords that can start a type (i.e. are either a type prefix
  1507. ;; or a complete type).
  1508. t (delete-duplicates (append (c-lang-const c-primitive-type-kwds)
  1509. (c-lang-const c-type-prefix-kwds)
  1510. (c-lang-const c-type-modifier-kwds))
  1511. :test 'string-equal))
  1512. (c-lang-defconst c-class-decl-kwds
  1513. "Keywords introducing declarations where the following block (if any)
  1514. contains another declaration level that should be considered a class.
  1515. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1516. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1517. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1518. will be handled.
  1519. Note that presence on this list does not automatically treat the
  1520. following identifier as a type; the keyword must also be present on
  1521. `c-type-prefix-kwds' or `c-type-list-kwds' to accomplish that."
  1522. t nil
  1523. c '("struct" "union")
  1524. c++ '("class" "struct" "union")
  1525. objc '("struct" "union"
  1526. "@interface" "@implementation" "@protocol")
  1527. java '("class" "@interface" "interface")
  1528. idl '("component" "eventtype" "exception" "home" "interface" "struct"
  1529. "union" "valuetype"
  1530. ;; In CORBA PSDL:
  1531. "storagehome" "storagetype"
  1532. ;; In CORBA CIDL:
  1533. "catalog" "executor" "manages" "segment")
  1534. pike '("class"))
  1535. (c-lang-defconst c-class-key
  1536. ;; Regexp matching the start of a class.
  1537. t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
  1538. (c-lang-defvar c-class-key (c-lang-const c-class-key))
  1539. (c-lang-defconst c-brace-list-decl-kwds
  1540. "Keywords introducing declarations where the following block (if
  1541. any) is a brace list.
  1542. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1543. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1544. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1545. will be handled."
  1546. t '("enum")
  1547. (awk) nil)
  1548. (c-lang-defconst c-brace-list-key
  1549. ;; Regexp matching the start of declarations where the following
  1550. ;; block is a brace list.
  1551. t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
  1552. (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
  1553. (c-lang-defconst c-other-block-decl-kwds
  1554. "Keywords where the following block (if any) contains another
  1555. declaration level that should not be considered a class. For every
  1556. keyword here, CC Mode will add a set of special syntactic symbols for
  1557. those blocks. E.g. if the keyword is \"foo\" then there will be
  1558. `foo-open', `foo-close', and `infoo' symbols.
  1559. The intention is that this category should be used for block
  1560. constructs that aren't related to object orientation concepts like
  1561. classes (which thus also include e.g. interfaces, templates,
  1562. contracts, structs, etc). The more pragmatic distinction is that
  1563. while most want some indentation inside classes, it's fairly common
  1564. that they don't want it in some of these constructs, so it should be
  1565. simple to configure that differently from classes. See also
  1566. `c-class-decl-kwds'.
  1567. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1568. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1569. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1570. will be handled."
  1571. t nil
  1572. (c objc) '("extern")
  1573. c++ '("namespace" "extern")
  1574. idl '("module"
  1575. ;; In CORBA CIDL:
  1576. "composition"))
  1577. (c-lang-defconst c-other-decl-block-key
  1578. ;; Regexp matching the start of blocks besides classes that contain
  1579. ;; another declaration level.
  1580. t (c-make-keywords-re t (c-lang-const c-other-block-decl-kwds)))
  1581. (c-lang-defvar c-other-decl-block-key (c-lang-const c-other-decl-block-key))
  1582. (c-lang-defvar c-other-decl-block-key-in-symbols-alist
  1583. (mapcar
  1584. (lambda (elt)
  1585. (cons elt
  1586. (if (string= elt "extern")
  1587. 'inextern-lang
  1588. (intern (concat "in" elt)))))
  1589. (c-lang-const c-other-block-decl-kwds))
  1590. "Alist associating keywords in c-other-decl-block-decl-kwds with
  1591. their matching \"in\" syntactic symbols.")
  1592. (c-lang-defconst c-typedef-decl-kwds
  1593. "Keywords introducing declarations where the identifier(s) being
  1594. declared are types.
  1595. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1596. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1597. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1598. will be handled."
  1599. ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
  1600. ;; (since e.g. "Foo" is a type that's being defined in "class Foo
  1601. ;; {...}").
  1602. t (append (c-lang-const c-class-decl-kwds)
  1603. (c-lang-const c-brace-list-decl-kwds))
  1604. ;; Languages that have a "typedef" construct.
  1605. (c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
  1606. '("typedef"))
  1607. ;; Unlike most other languages, exception names are not handled as
  1608. ;; types in IDL since they only can occur in "raises" specs.
  1609. idl (delete "exception" (append (c-lang-const c-typedef-decl-kwds) nil)))
  1610. (c-lang-defconst c-typedef-decl-key
  1611. t (c-make-keywords-re t (c-lang-const c-typedef-decl-kwds)))
  1612. (c-lang-defvar c-typedef-decl-key (c-lang-const c-typedef-decl-key))
  1613. (c-lang-defconst c-typeless-decl-kwds
  1614. "Keywords introducing declarations where the \(first) identifier
  1615. \(declarator) follows directly after the keyword, without any type.
  1616. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1617. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1618. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1619. will be handled."
  1620. ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
  1621. ;; (since e.g. "Foo" is the identifier being defined in "class Foo
  1622. ;; {...}").
  1623. t (append (c-lang-const c-class-decl-kwds)
  1624. (c-lang-const c-brace-list-decl-kwds))
  1625. ;; Note: "manages" for CORBA CIDL clashes with its presence on
  1626. ;; `c-type-list-kwds' for IDL.
  1627. idl (append (c-lang-const c-typeless-decl-kwds)
  1628. '("factory" "finder" "native"
  1629. ;; In CORBA PSDL:
  1630. "key" "stores"
  1631. ;; In CORBA CIDL:
  1632. "facet"))
  1633. pike (append (c-lang-const c-class-decl-kwds)
  1634. '("constant")))
  1635. (c-lang-defconst c-modifier-kwds
  1636. "Keywords that can prefix normal declarations of identifiers
  1637. \(and typically act as flags). Things like argument declarations
  1638. inside function headers are also considered declarations in this
  1639. sense.
  1640. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1641. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1642. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1643. will be handled."
  1644. t nil
  1645. (c c++) '("auto" "extern" "inline" "register" "static")
  1646. c++ (append '("explicit" "friend" "mutable" "template" "using" "virtual")
  1647. (c-lang-const c-modifier-kwds))
  1648. objc '("auto" "bycopy" "byref" "extern" "in" "inout" "oneway" "out" "static")
  1649. ;; FIXME: Some of those below ought to be on `c-other-decl-kwds' instead.
  1650. idl '("abstract" "attribute" "const" "consumes" "custom" "emits" "import"
  1651. "in" "inout" "local" "multiple" "oneway" "out" "private" "provides"
  1652. "public" "publishes" "readonly" "typeid" "typeprefix" "uses"
  1653. ;; In CORBA PSDL:
  1654. "primary" "state"
  1655. ;; In CORBA CIDL:
  1656. "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
  1657. ;; Note: "const" is not used in Java, but it's still a reserved keyword.
  1658. java '("abstract" "const" "final" "native" "private" "protected" "public"
  1659. "static" "strictfp" "synchronized" "transient" "volatile")
  1660. pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
  1661. "public" "static" "variant"))
  1662. (c-lang-defconst c-other-decl-kwds
  1663. "Keywords that can start or prefix any declaration level construct,
  1664. besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
  1665. `c-other-block-decl-kwds', `c-typedef-decl-kwds',
  1666. `c-typeless-decl-kwds' and `c-modifier-kwds'.
  1667. If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
  1668. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1669. `c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
  1670. will be handled."
  1671. t nil
  1672. objc '("@class" "@end" "@defs")
  1673. java '("import" "package")
  1674. pike '("import" "inherit"))
  1675. (c-lang-defconst c-decl-start-kwds
  1676. "Keywords that always start declarations, wherever they occur.
  1677. This can be used for declarations that aren't recognized by the normal
  1678. combination of `c-decl-prefix-re' and `c-decl-start-re'."
  1679. t nil
  1680. ;; Classes can be declared anywhere in a Pike expression.
  1681. pike '("class"))
  1682. (c-lang-defconst c-decl-hangon-kwds
  1683. "Keywords that can occur anywhere in a declaration level construct.
  1684. This is used for self-contained things that can be tacked on anywhere
  1685. on a declaration and that should be ignored to be able to recognize it
  1686. correctly. Typical cases are compiler extensions like
  1687. \"__attribute__\" or \"__declspec\":
  1688. __declspec(noreturn) void foo();
  1689. class __declspec(dllexport) classname {...};
  1690. void foo() __attribute__((noreturn));
  1691. Note that unrecognized plain symbols are skipped anyway if they occur
  1692. before the type, so such things are not necessary to mention here.
  1693. Mentioning them here is necessary only if they can occur in other
  1694. places, or if they are followed by a construct that must be skipped
  1695. over \(like the parens in the \"__attribute__\" and \"__declspec\"
  1696. examples above). In the last case, they alse need to be present on
  1697. one of `c-type-list-kwds', `c-ref-list-kwds',
  1698. `c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
  1699. `c-<>-type-kwds', or `c-<>-arglist-kwds'."
  1700. ;; NB: These are currently not recognized in all parts of a
  1701. ;; declaration. Specifically, they aren't recognized in the middle
  1702. ;; of multi-token types, inside declarators, and between the
  1703. ;; identifier and the arglist paren of a function declaration.
  1704. ;;
  1705. ;; FIXME: This ought to be user customizable since compiler stuff
  1706. ;; like this usually is wrapped in project specific macros. (It'd
  1707. ;; of course be even better if we could cope without knowing this.)
  1708. t nil
  1709. (c c++) '(;; GCC extension.
  1710. "__attribute__"
  1711. ;; MSVC extension.
  1712. "__declspec"))
  1713. (c-lang-defconst c-decl-hangon-key
  1714. ;; Adorned regexp matching `c-decl-hangon-kwds'.
  1715. t (c-make-keywords-re t (c-lang-const c-decl-hangon-kwds)))
  1716. (c-lang-defvar c-decl-hangon-key (c-lang-const c-decl-hangon-key))
  1717. (c-lang-defconst c-prefix-spec-kwds
  1718. ;; All keywords that can occur in the preamble of a declaration.
  1719. ;; They typically occur before the type, but they are also matched
  1720. ;; after presumptive types since we often can't be sure that
  1721. ;; something is a type or just some sort of macro in front of the
  1722. ;; declaration. They might be ambiguous with types or type
  1723. ;; prefixes.
  1724. t (delete-duplicates (append (c-lang-const c-class-decl-kwds)
  1725. (c-lang-const c-brace-list-decl-kwds)
  1726. (c-lang-const c-other-block-decl-kwds)
  1727. (c-lang-const c-typedef-decl-kwds)
  1728. (c-lang-const c-typeless-decl-kwds)
  1729. (c-lang-const c-modifier-kwds)
  1730. (c-lang-const c-other-decl-kwds)
  1731. (c-lang-const c-decl-start-kwds)
  1732. (c-lang-const c-decl-hangon-kwds))
  1733. :test 'string-equal))
  1734. (c-lang-defconst c-prefix-spec-kwds-re
  1735. ;; Adorned regexp of `c-prefix-spec-kwds'.
  1736. t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))
  1737. (c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
  1738. (c-lang-defconst c-specifier-key
  1739. ;; Adorned regexp of the keywords in `c-prefix-spec-kwds' that aren't
  1740. ;; ambiguous with types or type prefixes. These are the keywords (like
  1741. ;; extern, namespace, but NOT template) that can modify a declaration.
  1742. t (c-make-keywords-re t
  1743. (set-difference (c-lang-const c-prefix-spec-kwds)
  1744. (append (c-lang-const c-type-start-kwds)
  1745. (c-lang-const c-<>-arglist-kwds))
  1746. :test 'string-equal)))
  1747. (c-lang-defvar c-specifier-key (c-lang-const c-specifier-key))
  1748. (c-lang-defconst c-postfix-spec-kwds
  1749. ;; Keywords that can occur after argument list of a function header
  1750. ;; declaration, i.e. in the "K&R region".
  1751. t (append (c-lang-const c-postfix-decl-spec-kwds)
  1752. (c-lang-const c-decl-hangon-kwds)))
  1753. (c-lang-defconst c-not-decl-init-keywords
  1754. ;; Adorned regexp matching all keywords that can't appear at the
  1755. ;; start of a declaration.
  1756. t (c-make-keywords-re t
  1757. (set-difference (c-lang-const c-keywords)
  1758. (append (c-lang-const c-type-start-kwds)
  1759. (c-lang-const c-prefix-spec-kwds))
  1760. :test 'string-equal)))
  1761. (c-lang-defvar c-not-decl-init-keywords
  1762. (c-lang-const c-not-decl-init-keywords))
  1763. (c-lang-defconst c-not-primitive-type-keywords
  1764. "List of all keywords apart from primitive types (like \"int\")."
  1765. t (set-difference (c-lang-const c-keywords)
  1766. (c-lang-const c-primitive-type-kwds)
  1767. :test 'string-equal)
  1768. ;; The "more" for C++ is the QT keyword (as in "more slots:").
  1769. ;; This variable is intended for use in c-beginning-of-statement-1.
  1770. c++ (append (c-lang-const c-not-primitive-type-keywords) '("more")))
  1771. (c-lang-defconst c-not-primitive-type-keywords-regexp
  1772. t (c-make-keywords-re t
  1773. (c-lang-const c-not-primitive-type-keywords)))
  1774. (c-lang-defvar c-not-primitive-type-keywords-regexp
  1775. (c-lang-const c-not-primitive-type-keywords-regexp))
  1776. (c-lang-defconst c-protection-kwds
  1777. "Access protection label keywords in classes."
  1778. t nil
  1779. c++ '("private" "protected" "public")
  1780. objc '("@private" "@protected" "@public"))
  1781. (c-lang-defconst c-block-decls-with-vars
  1782. "Keywords introducing declarations that can contain a block which
  1783. might be followed by variable declarations, e.g. like \"foo\" in
  1784. \"class Foo { ... } foo;\". So if there is a block in a declaration
  1785. like that, it ends with the following ';' and not right away.
  1786. The keywords on list are assumed to also be present on one of the
  1787. `*-decl-kwds' lists."
  1788. t nil
  1789. (c objc) '("struct" "union" "enum" "typedef")
  1790. c++ '("class" "struct" "union" "enum" "typedef"))
  1791. (c-lang-defconst c-opt-block-decls-with-vars-key
  1792. ;; Regexp matching the `c-block-decls-with-vars' keywords, or nil in
  1793. ;; languages without such constructs.
  1794. t (and (c-lang-const c-block-decls-with-vars)
  1795. (c-make-keywords-re t (c-lang-const c-block-decls-with-vars))))
  1796. (c-lang-defvar c-opt-block-decls-with-vars-key
  1797. (c-lang-const c-opt-block-decls-with-vars-key))
  1798. (c-lang-defconst c-postfix-decl-spec-kwds
  1799. "Keywords introducing extra declaration specifiers in the region
  1800. between the header and the body \(i.e. the \"K&R-region\") in
  1801. declarations."
  1802. t nil
  1803. java '("extends" "implements" "throws")
  1804. idl '("context" "getraises" "manages" "primarykey" "raises" "setraises"
  1805. "supports"
  1806. ;; In CORBA PSDL:
  1807. "as" "const" "implements" "of" "ref"))
  1808. (c-lang-defconst c-nonsymbol-sexp-kwds
  1809. "Keywords that may be followed by a nonsymbol sexp before whatever
  1810. construct it's part of continues."
  1811. t nil
  1812. (c c++ objc) '("extern"))
  1813. (c-lang-defconst c-type-list-kwds
  1814. "Keywords that may be followed by a comma separated list of type
  1815. identifiers, where each optionally can be prefixed by keywords. (Can
  1816. also be used for the special case when the list can contain only one
  1817. element.)
  1818. Assumed to be mutually exclusive with `c-ref-list-kwds'. There's no
  1819. reason to put keywords on this list if they are on `c-type-prefix-kwds'.
  1820. There's also no reason to add keywords that prefixes a normal
  1821. declaration consisting of a type followed by a declarator (list), so
  1822. the keywords on `c-modifier-kwds' should normally not be listed here
  1823. either.
  1824. Note: Use `c-typeless-decl-kwds' for keywords followed by a function
  1825. or variable identifier (that's being defined)."
  1826. t nil
  1827. c++ '("operator")
  1828. objc '("@class")
  1829. java '("import" "new" "extends" "super" "implements" "throws")
  1830. idl '("manages" "native" "primarykey" "supports"
  1831. ;; In CORBA PSDL:
  1832. "as" "implements" "of" "scope")
  1833. pike '("inherit"))
  1834. (c-lang-defconst c-ref-list-kwds
  1835. "Keywords that may be followed by a comma separated list of
  1836. reference (i.e. namespace/scope/module) identifiers, where each
  1837. optionally can be prefixed by keywords. (Can also be used for the
  1838. special case when the list can contain only one element.) Assumed to
  1839. be mutually exclusive with `c-type-list-kwds'.
  1840. Note: Use `c-typeless-decl-kwds' for keywords followed by a function
  1841. or variable identifier (that's being defined)."
  1842. t nil
  1843. c++ '("namespace")
  1844. java '("package")
  1845. idl '("import" "module"
  1846. ;; In CORBA CIDL:
  1847. "composition")
  1848. pike '("import"))
  1849. (c-lang-defconst c-colon-type-list-kwds
  1850. "Keywords that may be followed (not necessarily directly) by a colon
  1851. and then a comma separated list of type identifiers, where each
  1852. optionally can be prefixed by keywords. (Can also be used for the
  1853. special case when the list can contain only one element.)"
  1854. t nil
  1855. c++ '("class" "struct")
  1856. idl '("component" "eventtype" "home" "interface" "valuetype"
  1857. ;; In CORBA PSDL:
  1858. "storagehome" "storagetype"))
  1859. (c-lang-defconst c-colon-type-list-re
  1860. "Regexp matched after the keywords in `c-colon-type-list-kwds' to skip
  1861. forward to the colon. The end of the match is assumed to be directly
  1862. after the colon, so the regexp should end with \":\". Must be a
  1863. regexp if `c-colon-type-list-kwds' isn't nil."
  1864. t (if (c-lang-const c-colon-type-list-kwds)
  1865. ;; Disallow various common punctuation chars that can't come
  1866. ;; before the ":" that starts the inherit list after "class"
  1867. ;; or "struct" in C++. (Also used as default for other
  1868. ;; languages.)
  1869. "[^\]\[{}();,/#=:]*:"))
  1870. (c-lang-defvar c-colon-type-list-re (c-lang-const c-colon-type-list-re))
  1871. (c-lang-defconst c-paren-nontype-kwds
  1872. "Keywords that may be followed by a parenthesis expression that doesn't
  1873. contain type identifiers."
  1874. t nil
  1875. (c c++) '(;; GCC extension.
  1876. "__attribute__"
  1877. ;; MSVC extension.
  1878. "__declspec"))
  1879. (c-lang-defconst c-paren-type-kwds
  1880. "Keywords that may be followed by a parenthesis expression containing
  1881. type identifiers separated by arbitrary tokens."
  1882. t nil
  1883. c++ '("throw")
  1884. objc '("@defs")
  1885. idl '("switch")
  1886. pike '("array" "function" "int" "mapping" "multiset" "object" "program"))
  1887. (c-lang-defconst c-paren-any-kwds
  1888. t (delete-duplicates (append (c-lang-const c-paren-nontype-kwds)
  1889. (c-lang-const c-paren-type-kwds))
  1890. :test 'string-equal))
  1891. (c-lang-defconst c-<>-type-kwds
  1892. "Keywords that may be followed by an angle bracket expression
  1893. containing type identifiers separated by \",\". The difference from
  1894. `c-<>-arglist-kwds' is that unknown names are taken to be types and
  1895. not other identifiers. `c-recognize-<>-arglists' is assumed to be set
  1896. if this isn't nil."
  1897. t nil
  1898. objc '("id")
  1899. idl '("sequence"
  1900. ;; In CORBA PSDL:
  1901. "ref"))
  1902. (c-lang-defconst c-<>-arglist-kwds
  1903. "Keywords that can be followed by a C++ style template arglist; see
  1904. `c-recognize-<>-arglists' for details. That language constant is
  1905. assumed to be set if this isn't nil."
  1906. t nil
  1907. c++ '("template")
  1908. idl '("fixed" "string" "wstring"))
  1909. (c-lang-defconst c-<>-sexp-kwds
  1910. ;; All keywords that can be followed by an angle bracket sexp.
  1911. t (delete-duplicates (append (c-lang-const c-<>-type-kwds)
  1912. (c-lang-const c-<>-arglist-kwds))
  1913. :test 'string-equal))
  1914. (c-lang-defconst c-opt-<>-sexp-key
  1915. ;; Adorned regexp matching keywords that can be followed by an angle
  1916. ;; bracket sexp. Always set when `c-recognize-<>-arglists' is.
  1917. t (if (c-lang-const c-recognize-<>-arglists)
  1918. (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
  1919. (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
  1920. (c-lang-defconst c-brace-id-list-kwds
  1921. "Keywords that may be followed by a brace block containing a comma
  1922. separated list of identifier definitions, i.e. like the list of
  1923. identifiers that follows the type in a normal declaration."
  1924. t (c-lang-const c-brace-list-decl-kwds))
  1925. (c-lang-defconst c-block-stmt-1-kwds
  1926. "Statement keywords followed directly by a substatement."
  1927. t '("do" "else")
  1928. c++ '("do" "else" "try")
  1929. objc '("do" "else" "@finally" "@try")
  1930. java '("do" "else" "finally" "try")
  1931. idl nil)
  1932. (c-lang-defconst c-block-stmt-1-key
  1933. ;; Regexp matching the start of any statement followed directly by a
  1934. ;; substatement (doesn't match a bare block, however).
  1935. t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
  1936. (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
  1937. (c-lang-defconst c-block-stmt-2-kwds
  1938. "Statement keywords followed by a paren sexp and then by a substatement."
  1939. t '("for" "if" "switch" "while")
  1940. c++ '("for" "if" "switch" "while" "catch")
  1941. objc '("for" "if" "switch" "while" "@catch" "@synchronized")
  1942. java '("for" "if" "switch" "while" "catch" "synchronized")
  1943. idl nil
  1944. pike '("for" "if" "switch" "while" "foreach")
  1945. awk '("for" "if" "while"))
  1946. (c-lang-defconst c-block-stmt-2-key
  1947. ;; Regexp matching the start of any statement followed by a paren sexp
  1948. ;; and then by a substatement.
  1949. t (c-make-keywords-re t (c-lang-const c-block-stmt-2-kwds)))
  1950. (c-lang-defvar c-block-stmt-2-key (c-lang-const c-block-stmt-2-key))
  1951. (c-lang-defconst c-block-stmt-kwds
  1952. ;; Union of `c-block-stmt-1-kwds' and `c-block-stmt-2-kwds'.
  1953. t (delete-duplicates (append (c-lang-const c-block-stmt-1-kwds)
  1954. (c-lang-const c-block-stmt-2-kwds))
  1955. :test 'string-equal))
  1956. (c-lang-defconst c-opt-block-stmt-key
  1957. ;; Regexp matching the start of any statement that has a
  1958. ;; substatement (except a bare block). Nil in languages that
  1959. ;; don't have such constructs.
  1960. t (if (or (c-lang-const c-block-stmt-1-kwds)
  1961. (c-lang-const c-block-stmt-2-kwds))
  1962. (c-make-keywords-re t
  1963. (append (c-lang-const c-block-stmt-1-kwds)
  1964. (c-lang-const c-block-stmt-2-kwds)))))
  1965. (c-lang-defvar c-opt-block-stmt-key (c-lang-const c-opt-block-stmt-key))
  1966. (c-lang-defconst c-simple-stmt-kwds
  1967. "Statement keywords followed by an expression or nothing."
  1968. t '("break" "continue" "goto" "return")
  1969. objc '("break" "continue" "goto" "return" "@throw")
  1970. ;; Note: `goto' is not valid in Java, but the keyword is still reserved.
  1971. java '("break" "continue" "goto" "return" "throw")
  1972. idl nil
  1973. pike '("break" "continue" "return")
  1974. awk '(;; Not sure about "delete", "exit", "getline", etc. ; ACM 2002/5/30
  1975. "break" "continue" "return" "delete" "exit" "getline" "next"
  1976. "nextfile" "print" "printf"))
  1977. (c-lang-defconst c-simple-stmt-key
  1978. ;; Adorned regexp matching `c-simple-stmt-kwds'.
  1979. t (c-make-keywords-re t (c-lang-const c-simple-stmt-kwds)))
  1980. (c-lang-defvar c-simple-stmt-key (c-lang-const c-simple-stmt-key))
  1981. (c-lang-defconst c-paren-stmt-kwds
  1982. "Statement keywords followed by a parenthesis expression that
  1983. nevertheless contains a list separated with ';' and not ','."
  1984. t '("for")
  1985. idl nil)
  1986. (c-lang-defconst c-paren-stmt-key
  1987. ;; Adorned regexp matching `c-paren-stmt-kwds'.
  1988. t (c-make-keywords-re t (c-lang-const c-paren-stmt-kwds)))
  1989. (c-lang-defvar c-paren-stmt-key (c-lang-const c-paren-stmt-key))
  1990. (c-lang-defconst c-asm-stmt-kwds
  1991. "Statement keywords followed by an assembler expression."
  1992. t nil
  1993. (c c++) '("asm" "__asm__")) ;; Not standard, but common.
  1994. (c-lang-defconst c-opt-asm-stmt-key
  1995. ;; Regexp matching the start of an assembler statement. Nil in
  1996. ;; languages that don't support that.
  1997. t (if (c-lang-const c-asm-stmt-kwds)
  1998. (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds))))
  1999. (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key))
  2000. (c-lang-defconst c-case-kwds
  2001. "The keyword\(s) which introduce a \"case\" like construct.
  2002. This construct is \"<keyword> <expression> :\"."
  2003. t '("case")
  2004. awk nil)
  2005. (c-lang-defconst c-case-kwds-regexp
  2006. ;; Adorned regexp matching any "case"-like keyword.
  2007. t (c-make-keywords-re t (c-lang-const c-case-kwds)))
  2008. (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp))
  2009. (c-lang-defconst c-label-kwds
  2010. "Keywords introducing colon terminated labels in blocks."
  2011. t '("case" "default"))
  2012. (c-lang-defconst c-label-kwds-regexp
  2013. ;; Adorned regexp matching any keyword that introduces a label.
  2014. t (c-make-keywords-re t (c-lang-const c-label-kwds)))
  2015. (c-lang-defvar c-label-kwds-regexp (c-lang-const c-label-kwds-regexp))
  2016. (c-lang-defconst c-before-label-kwds
  2017. "Keywords that might be followed by a label identifier."
  2018. t '("goto")
  2019. (java pike) (append '("break" "continue")
  2020. (c-lang-const c-before-label-kwds))
  2021. idl nil
  2022. awk nil)
  2023. (c-lang-defconst c-constant-kwds
  2024. "Keywords for constants."
  2025. t nil
  2026. (c c++) '("NULL" ;; Not a keyword, but practically works as one.
  2027. "false" "true") ; Defined in C99.
  2028. objc '("nil" "Nil" "YES" "NO" "NS_DURING" "NS_HANDLER" "NS_ENDHANDLER")
  2029. idl '("TRUE" "FALSE")
  2030. java '("true" "false" "null") ; technically "literals", not keywords
  2031. pike '("UNDEFINED")) ;; Not a keyword, but practically works as one.
  2032. (c-lang-defconst c-primary-expr-kwds
  2033. "Keywords besides constants and operators that start primary expressions."
  2034. t nil
  2035. c++ '("operator" "this")
  2036. objc '("super" "self")
  2037. java '("this")
  2038. pike '("this")) ;; Not really a keyword, but practically works as one.
  2039. (c-lang-defconst c-expr-kwds
  2040. ;; Keywords that can occur anywhere in expressions. Built from
  2041. ;; `c-primary-expr-kwds' and all keyword operators in `c-operators'.
  2042. t (delete-duplicates
  2043. (append (c-lang-const c-primary-expr-kwds)
  2044. (c-filter-ops (c-lang-const c-operator-list)
  2045. t
  2046. "\\`\\(\\w\\|\\s_\\)+\\'"))
  2047. :test 'string-equal))
  2048. (c-lang-defconst c-lambda-kwds
  2049. "Keywords that start lambda constructs, i.e. function definitions in
  2050. expressions."
  2051. t nil
  2052. pike '("lambda"))
  2053. (c-lang-defconst c-inexpr-block-kwds
  2054. "Keywords that start constructs followed by statement blocks which can
  2055. be used in expressions \(the gcc extension for this in C and C++ is
  2056. handled separately by `c-recognize-paren-inexpr-blocks')."
  2057. t nil
  2058. pike '("catch" "gauge"))
  2059. (c-lang-defconst c-inexpr-class-kwds
  2060. "Keywords that can start classes inside expressions."
  2061. t nil
  2062. java '("new")
  2063. pike '("class"))
  2064. (c-lang-defconst c-inexpr-brace-list-kwds
  2065. "Keywords that can start brace list blocks inside expressions.
  2066. Note that Java specific rules are currently applied to tell this from
  2067. `c-inexpr-class-kwds'."
  2068. t nil
  2069. java '("new"))
  2070. (c-lang-defconst c-opt-inexpr-brace-list-key
  2071. ;; Regexp matching the start of a brace list in an expression, or
  2072. ;; nil in languages that don't have such things. This should not
  2073. ;; match brace lists recognized through `c-special-brace-lists'.
  2074. t (and (c-lang-const c-inexpr-brace-list-kwds)
  2075. (c-make-keywords-re t (c-lang-const c-inexpr-brace-list-kwds))))
  2076. (c-lang-defvar c-opt-inexpr-brace-list-key
  2077. (c-lang-const c-opt-inexpr-brace-list-key))
  2078. (c-lang-defconst c-decl-block-key
  2079. ;; Regexp matching keywords in any construct that contain another
  2080. ;; declaration level, i.e. that isn't followed by a function block
  2081. ;; or brace list. When the first submatch matches, it's an
  2082. ;; unambiguous construct, otherwise it's an ambiguous match that
  2083. ;; might also be the return type of a function declaration.
  2084. t (let* ((decl-kwds (append (c-lang-const c-class-decl-kwds)
  2085. (c-lang-const c-other-block-decl-kwds)
  2086. (c-lang-const c-inexpr-class-kwds)))
  2087. (unambiguous (set-difference decl-kwds
  2088. (c-lang-const c-type-start-kwds)
  2089. :test 'string-equal))
  2090. (ambiguous (intersection decl-kwds
  2091. (c-lang-const c-type-start-kwds)
  2092. :test 'string-equal)))
  2093. (if ambiguous
  2094. (concat (c-make-keywords-re t unambiguous)
  2095. "\\|"
  2096. (c-make-keywords-re t ambiguous))
  2097. (c-make-keywords-re t unambiguous))))
  2098. (c-lang-defvar c-decl-block-key (c-lang-const c-decl-block-key))
  2099. (c-lang-defconst c-bitfield-kwds
  2100. "Keywords that can introduce bitfields."
  2101. t nil
  2102. (c c++ objc) '("char" "int" "long" "signed" "unsigned"))
  2103. (c-lang-defconst c-opt-bitfield-key
  2104. ;; Regexp matching the start of a bitfield (not uniquely), or nil in
  2105. ;; languages without bitfield support.
  2106. t nil
  2107. (c c++) (c-make-keywords-re t (c-lang-const c-bitfield-kwds)))
  2108. (c-lang-defvar c-opt-bitfield-key (c-lang-const c-opt-bitfield-key))
  2109. (c-lang-defconst c-other-kwds
  2110. "Keywords not accounted for by any other `*-kwds' language constant."
  2111. t nil
  2112. idl '("truncatable"
  2113. ;; In CORBA CIDL: (These are declaration keywords that never
  2114. ;; can start a declaration.)
  2115. "entity" "process" "service" "session" "storage"))
  2116. ;;; Constants built from keywords.
  2117. ;; Note: No `*-kwds' language constants may be defined below this point.
  2118. (eval-and-compile
  2119. (defconst c-kwds-lang-consts
  2120. ;; List of all the language constants that contain keyword lists.
  2121. (let (list)
  2122. (mapatoms (lambda (sym)
  2123. (when (and (boundp sym)
  2124. (string-match "-kwds\\'" (symbol-name sym)))
  2125. ;; Make the list of globally interned symbols
  2126. ;; instead of ones interned in `c-lang-constants'.
  2127. (setq list (cons (intern (symbol-name sym)) list))))
  2128. c-lang-constants)
  2129. list)))
  2130. (c-lang-defconst c-keywords
  2131. ;; All keywords as a list.
  2132. t (delete-duplicates
  2133. (c-lang-defconst-eval-immediately
  2134. `(append ,@(mapcar (lambda (kwds-lang-const)
  2135. `(c-lang-const ,kwds-lang-const))
  2136. c-kwds-lang-consts)
  2137. nil))
  2138. :test 'string-equal))
  2139. (c-lang-defconst c-keywords-regexp
  2140. ;; All keywords as an adorned regexp.
  2141. t (c-make-keywords-re t (c-lang-const c-keywords)))
  2142. (c-lang-defvar c-keywords-regexp (c-lang-const c-keywords-regexp))
  2143. (c-lang-defconst c-keyword-member-alist
  2144. ;; An alist with all the keywords in the cars. The cdr for each
  2145. ;; keyword is a list of the symbols for the `*-kwds' lists that
  2146. ;; contains it.
  2147. t (let ((kwd-list-alist
  2148. (c-lang-defconst-eval-immediately
  2149. `(list ,@(mapcar (lambda (kwds-lang-const)
  2150. `(cons ',kwds-lang-const
  2151. (c-lang-const ,kwds-lang-const)))
  2152. c-kwds-lang-consts))))
  2153. lang-const kwd-list kwd
  2154. result-alist elem)
  2155. (while kwd-list-alist
  2156. (setq lang-const (caar kwd-list-alist)
  2157. kwd-list (cdar kwd-list-alist)
  2158. kwd-list-alist (cdr kwd-list-alist))
  2159. (while kwd-list
  2160. (setq kwd (car kwd-list)
  2161. kwd-list (cdr kwd-list))
  2162. (unless (setq elem (assoc kwd result-alist))
  2163. (setq result-alist (cons (setq elem (list kwd)) result-alist)))
  2164. (unless (memq lang-const (cdr elem))
  2165. (setcdr elem (cons lang-const (cdr elem))))))
  2166. result-alist))
  2167. (c-lang-defvar c-keywords-obarray
  2168. ;; An obarray containing all keywords as symbols. The property list
  2169. ;; of each symbol has a non-nil entry for the specific `*-kwds'
  2170. ;; lists it's a member of.
  2171. ;;
  2172. ;; E.g. to see whether the string str contains a keyword on
  2173. ;; `c-class-decl-kwds', one can do like this:
  2174. ;; (get (intern-soft str c-keyword-obarray) 'c-class-decl-kwds)
  2175. ;; Which preferably is written using the associated functions in
  2176. ;; cc-engine:
  2177. ;; (c-keyword-member (c-keyword-sym str) 'c-class-decl-kwds)
  2178. ;; The obarray is not stored directly as a language constant since
  2179. ;; the printed representation for obarrays used in .elc files isn't
  2180. ;; complete.
  2181. (let* ((alist (c-lang-const c-keyword-member-alist))
  2182. kwd lang-const-list
  2183. (obarray (make-vector (* (length alist) 2) 0)))
  2184. (while alist
  2185. (setq kwd (caar alist)
  2186. lang-const-list (cdar alist)
  2187. alist (cdr alist))
  2188. (setplist (intern kwd obarray)
  2189. ;; Emacs has an odd bug that causes `mapcan' to fail
  2190. ;; with unintelligible errors. (XEmacs works.)
  2191. ;;(mapcan (lambda (lang-const)
  2192. ;; (list lang-const t))
  2193. ;; lang-const-list)
  2194. (apply 'nconc (mapcar (lambda (lang-const)
  2195. (list lang-const t))
  2196. lang-const-list))))
  2197. obarray))
  2198. (c-lang-defconst c-regular-keywords-regexp
  2199. ;; Adorned regexp matching all keywords that should be fontified
  2200. ;; with the keywords face. I.e. that aren't types or constants.
  2201. t (c-make-keywords-re t
  2202. (set-difference (c-lang-const c-keywords)
  2203. (append (c-lang-const c-primitive-type-kwds)
  2204. (c-lang-const c-constant-kwds))
  2205. :test 'string-equal)))
  2206. (c-lang-defvar c-regular-keywords-regexp
  2207. (c-lang-const c-regular-keywords-regexp))
  2208. (c-lang-defconst c-primary-expr-regexp
  2209. ;; Regexp matching the start of any primary expression, i.e. any
  2210. ;; literal, symbol, prefix operator, and '('. It doesn't need to
  2211. ;; exclude keywords; they are excluded afterwards unless the second
  2212. ;; submatch matches. If the first but not the second submatch
  2213. ;; matches then it is an ambiguous primary expression; it could also
  2214. ;; be a match of e.g. an infix operator. (The case with ambiguous
  2215. ;; keyword operators isn't handled.)
  2216. t (let* ((prefix-ops
  2217. (c-filter-ops (c-lang-const c-operators)
  2218. '(prefix)
  2219. (lambda (op)
  2220. ;; Filter out the special case prefix
  2221. ;; operators that are close parens.
  2222. (not (string-match "\\s)" op)))))
  2223. (nonkeyword-prefix-ops
  2224. (c-filter-ops prefix-ops
  2225. t
  2226. "\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
  2227. (in-or-postfix-ops
  2228. (c-filter-ops (c-lang-const c-operators)
  2229. '(postfix
  2230. postfix-if-paren
  2231. left-assoc
  2232. right-assoc
  2233. right-assoc-sequence)
  2234. t))
  2235. (unambiguous-prefix-ops (set-difference nonkeyword-prefix-ops
  2236. in-or-postfix-ops
  2237. :test 'string-equal))
  2238. (ambiguous-prefix-ops (intersection nonkeyword-prefix-ops
  2239. in-or-postfix-ops
  2240. :test 'string-equal)))
  2241. (concat
  2242. "\\("
  2243. ;; Take out all symbol class operators from `prefix-ops' and make the
  2244. ;; first submatch from them together with `c-primary-expr-kwds'.
  2245. (c-make-keywords-re t
  2246. (append (c-lang-const c-primary-expr-kwds)
  2247. (set-difference prefix-ops nonkeyword-prefix-ops
  2248. :test 'string-equal)))
  2249. "\\|"
  2250. ;; Match all ambiguous operators.
  2251. (c-make-keywords-re nil
  2252. (intersection nonkeyword-prefix-ops in-or-postfix-ops
  2253. :test 'string-equal))
  2254. "\\)"
  2255. "\\|"
  2256. ;; Now match all other symbols.
  2257. (c-lang-const c-symbol-start)
  2258. "\\|"
  2259. ;; The chars that can start integer and floating point
  2260. ;; constants.
  2261. "\\.?[0-9]"
  2262. "\\|"
  2263. ;; The unambiguous operators from `prefix-ops'.
  2264. (c-make-keywords-re nil
  2265. (set-difference nonkeyword-prefix-ops in-or-postfix-ops
  2266. :test 'string-equal))
  2267. "\\|"
  2268. ;; Match string and character literals.
  2269. "\\s\""
  2270. (if (memq 'gen-string-delim c-emacs-features)
  2271. "\\|\\s|"
  2272. ""))))
  2273. (c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
  2274. ;;; Additional constants for parser-level constructs.
  2275. (c-lang-defconst c-decl-prefix-re
  2276. "Regexp matching something that might precede a declaration, cast or
  2277. label, such as the last token of a preceding statement or declaration.
  2278. This is used in the common situation where a declaration or cast
  2279. doesn't start with any specific token that can be searched for.
  2280. The regexp should not match bob; that is done implicitly. It can't
  2281. require a match longer than one token. The end of the token is taken
  2282. to be at the end of the first submatch, which is assumed to always
  2283. match. It's undefined whether identifier syntax (see
  2284. `c-identifier-syntax-table') is in effect or not. This regexp is
  2285. assumed to be a superset of `c-label-prefix-re' if
  2286. `c-recognize-colon-labels' is set.
  2287. Besides this, `c-decl-start-kwds' is used to find declarations.
  2288. Note: This variable together with `c-decl-start-re' and
  2289. `c-decl-start-kwds' is only used to detect \"likely\"
  2290. declaration/cast/label starts. I.e. they might produce more matches
  2291. but should not miss anything (or else it's necessary to use text
  2292. properties - see the next note). Wherever they match, the following
  2293. construct is analyzed to see if it indeed is a declaration, cast or
  2294. label. That analysis is not cheap, so it's important that not too
  2295. many false matches are triggered.
  2296. Note: If a declaration/cast/label start can't be detected with this
  2297. variable, it's necessary to use the `c-type' text property with the
  2298. value `c-decl-end' on the last char of the last token preceding the
  2299. declaration. See the comment blurb at the start of cc-engine.el for
  2300. more info."
  2301. ;; We match a sequence of characters to skip over things like \"};\"
  2302. ;; more quickly. We match ")" in C for K&R region declarations, and
  2303. ;; in all languages except Java for when a cpp macro definition
  2304. ;; begins with a declaration.
  2305. t "\\([\{\}\(\);,]+\\)"
  2306. java "\\([\{\}\(;,<]+\\)"
  2307. ;; Match "<" in C++ to get the first argument in a template arglist.
  2308. ;; In that case there's an additional check in `c-find-decl-spots'
  2309. ;; that it got open paren syntax.
  2310. c++ "\\([\{\}\(\);,<]+\\)"
  2311. ;; Additionally match the protection directives in Objective-C.
  2312. ;; Note that this doesn't cope with the longer directives, which we
  2313. ;; would have to match from start to end since they don't end with
  2314. ;; any easily recognized characters.
  2315. objc (concat "\\([\{\}\(\);,]+\\|"
  2316. (c-make-keywords-re nil (c-lang-const c-protection-kwds))
  2317. "\\)")
  2318. ;; Pike is like C but we also match "[" for multiple value
  2319. ;; assignments and type casts.
  2320. pike "\\([\{\}\(\)\[;,]+\\)")
  2321. (c-lang-defvar c-decl-prefix-re (c-lang-const c-decl-prefix-re)
  2322. 'dont-doc)
  2323. (c-lang-defconst c-decl-start-re
  2324. "Regexp matching the start of any declaration, cast or label.
  2325. It's used on the token after the one `c-decl-prefix-re' matched. This
  2326. regexp should not try to match those constructs accurately as it's
  2327. only used as a sieve to avoid spending more time checking other
  2328. constructs."
  2329. t (c-lang-const c-identifier-start))
  2330. (c-lang-defvar c-decl-start-re (c-lang-const c-decl-start-re))
  2331. (c-lang-defconst c-decl-prefix-or-start-re
  2332. ;; Regexp matching something that might precede or start a
  2333. ;; declaration, cast or label.
  2334. ;;
  2335. ;; If the first submatch matches, it's taken to match the end of a
  2336. ;; token that might precede such a construct, e.g. ';', '}' or '{'.
  2337. ;; It's built from `c-decl-prefix-re'.
  2338. ;;
  2339. ;; If the first submatch did not match, the match of the whole
  2340. ;; regexp is taken to be at the first token in the declaration.
  2341. ;; `c-decl-start-re' is not checked in this case.
  2342. ;;
  2343. ;; Design note: The reason the same regexp is used to match both
  2344. ;; tokens that precede declarations and start them is to avoid an
  2345. ;; extra regexp search from the previous declaration spot in
  2346. ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on
  2347. ;; that it finds all declaration/cast/label starts in approximately
  2348. ;; linear order, so we can't do the searches in two separate passes.
  2349. t (if (c-lang-const c-decl-start-kwds)
  2350. (concat (c-lang-const c-decl-prefix-re)
  2351. "\\|"
  2352. (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))
  2353. (c-lang-const c-decl-prefix-re)))
  2354. (c-lang-defvar c-decl-prefix-or-start-re
  2355. (c-lang-const c-decl-prefix-or-start-re)
  2356. 'dont-doc)
  2357. (c-lang-defconst c-cast-parens
  2358. ;; List containing the paren characters that can open a cast, or nil in
  2359. ;; languages without casts.
  2360. t (c-filter-ops (c-lang-const c-operators)
  2361. '(prefix)
  2362. "\\`\\s\(\\'"
  2363. (lambda (op) (elt op 0))))
  2364. (c-lang-defvar c-cast-parens (c-lang-const c-cast-parens))
  2365. (c-lang-defconst c-block-prefix-disallowed-chars
  2366. "List of syntactically relevant characters that never can occur before
  2367. the open brace in any construct that contains a brace block, e.g. in
  2368. the \"class Foo: public Bar\" part of:
  2369. class Foo: public Bar {int x();} a, *b;
  2370. If parens can occur, the chars inside those aren't filtered with this
  2371. list.
  2372. '<' and '>' should be disallowed even if angle bracket arglists can
  2373. occur. That since the search function needs to stop at them anyway to
  2374. ensure they are given paren syntax.
  2375. This is used to skip backward from the open brace to find the region
  2376. in which to look for a construct like \"class\", \"enum\",
  2377. \"namespace\" or whatever. That skipping should be as tight as
  2378. possible for good performance."
  2379. ;; Default to all chars that only occurs in nonsymbol tokens outside
  2380. ;; identifiers.
  2381. t (set-difference
  2382. (c-lang-const c-nonsymbol-token-char-list)
  2383. (c-filter-ops (append (c-lang-const c-identifier-ops)
  2384. (list (cons nil
  2385. (c-lang-const c-after-id-concat-ops))))
  2386. t
  2387. t
  2388. (lambda (op)
  2389. (let ((pos 0) res)
  2390. (while (string-match "\\(\\s.\\|\\s(\\|\\s)\\)"
  2391. op pos)
  2392. (setq res (cons (aref op (match-beginning 1)) res)
  2393. pos (match-end 0)))
  2394. res))))
  2395. ;; Allow cpp operations (where applicable).
  2396. t (if (c-lang-const c-opt-cpp-prefix)
  2397. (set-difference (c-lang-const c-block-prefix-disallowed-chars)
  2398. '(?#))
  2399. (c-lang-const c-block-prefix-disallowed-chars))
  2400. ;; Allow ':' for inherit list starters.
  2401. (c++ objc idl) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
  2402. '(?:))
  2403. ;; Allow ',' for multiple inherits.
  2404. (c++ java) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
  2405. '(?,))
  2406. ;; Allow parentheses for anonymous inner classes in Java and class
  2407. ;; initializer lists in Pike.
  2408. (java pike) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
  2409. '(?\( ?\)))
  2410. ;; Allow '"' for extern clauses (e.g. extern "C" {...}).
  2411. (c c++ objc) (set-difference (c-lang-const c-block-prefix-disallowed-chars)
  2412. '(?\" ?')))
  2413. (c-lang-defconst c-block-prefix-charset
  2414. ;; `c-block-prefix-disallowed-chars' as an inverted charset suitable
  2415. ;; for `c-syntactic-skip-backward'.
  2416. t (c-make-bare-char-alt (c-lang-const c-block-prefix-disallowed-chars) t))
  2417. (c-lang-defvar c-block-prefix-charset (c-lang-const c-block-prefix-charset))
  2418. (c-lang-defconst c-type-decl-prefix-key
  2419. "Regexp matching the declarator operators that might precede the
  2420. identifier in a declaration, e.g. the \"*\" in \"char *argv\". This
  2421. regexp should match \"(\" if parentheses are valid in declarators.
  2422. The end of the first submatch is taken as the end of the operator.
  2423. Identifier syntax is in effect when this is matched \(see
  2424. `c-identifier-syntax-table')."
  2425. t (if (c-lang-const c-type-modifier-kwds)
  2426. (concat (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>")
  2427. ;; Default to a regexp that never matches.
  2428. "\\<\\>")
  2429. ;; Check that there's no "=" afterwards to avoid matching tokens
  2430. ;; like "*=".
  2431. (c objc) (concat "\\("
  2432. "[*\(]"
  2433. "\\|"
  2434. (c-lang-const c-type-decl-prefix-key)
  2435. "\\)"
  2436. "\\([^=]\\|$\\)")
  2437. c++ (concat "\\("
  2438. "[*\(&]"
  2439. "\\|"
  2440. (c-lang-const c-type-decl-prefix-key)
  2441. "\\|"
  2442. (concat "\\(" ; 3
  2443. ;; If this matches there's special treatment in
  2444. ;; `c-font-lock-declarators' and
  2445. ;; `c-font-lock-declarations' that check for a
  2446. ;; complete name followed by ":: *".
  2447. (c-lang-const c-identifier-start)
  2448. "\\)")
  2449. "\\)"
  2450. "\\([^=]\\|$\\)")
  2451. pike "\\(\\*\\)\\([^=]\\|$\\)")
  2452. (c-lang-defvar c-type-decl-prefix-key (c-lang-const c-type-decl-prefix-key)
  2453. 'dont-doc)
  2454. (c-lang-defconst c-type-decl-suffix-key
  2455. "Regexp matching the declarator operators that might follow after the
  2456. identifier in a declaration, e.g. the \"[\" in \"char argv[]\". This
  2457. regexp should match \")\" if parentheses are valid in declarators. If
  2458. it matches an open paren of some kind, the type declaration check
  2459. continues at the corresponding close paren, otherwise the end of the
  2460. first submatch is taken as the end of the operator. Identifier syntax
  2461. is in effect when this is matched (see `c-identifier-syntax-table')."
  2462. ;; Default to a regexp that matches `c-type-modifier-kwds' and a
  2463. ;; function argument list parenthesis.
  2464. t (if (c-lang-const c-type-modifier-kwds)
  2465. (concat "\\(\(\\|"
  2466. (regexp-opt (c-lang-const c-type-modifier-kwds) t) "\\>"
  2467. "\\)")
  2468. "\\(\(\\)")
  2469. (c c++ objc) (concat
  2470. "\\("
  2471. "[\)\[\(]"
  2472. (if (c-lang-const c-type-modifier-kwds)
  2473. (concat
  2474. "\\|"
  2475. ;; "throw" in `c-type-modifier-kwds' is followed
  2476. ;; by a parenthesis list, but no extra measures
  2477. ;; are necessary to handle that.
  2478. (regexp-opt (c-lang-const c-type-modifier-kwds) t)
  2479. "\\>")
  2480. "")
  2481. "\\)")
  2482. (java idl) "\\([\[\(]\\)")
  2483. (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
  2484. 'dont-doc)
  2485. (c-lang-defconst c-after-suffixed-type-decl-key
  2486. "This regexp is matched after a declarator expression where
  2487. `c-type-decl-suffix-key' has matched. If it matches then the
  2488. construct is taken as a declaration. It's typically used to match the
  2489. beginning of a function body or whatever might occur after the
  2490. function header in a function declaration or definition. It's
  2491. undefined whether identifier syntax (see `c-identifier-syntax-table')
  2492. is in effect or not.
  2493. Note that it's used in cases like after \"foo (bar)\" so it should
  2494. only match when it's certain that it's a declaration, e.g \"{\" but
  2495. not \",\" or \";\"."
  2496. t "{"
  2497. ;; If K&R style declarations should be recognized then one could
  2498. ;; consider to match the start of any symbol since we want to match
  2499. ;; the start of the first declaration in the "K&R region". That
  2500. ;; could however produce false matches on code like "FOO(bar) x"
  2501. ;; where FOO is a cpp macro, so it's better to leave it out and rely
  2502. ;; on the other heuristics in that case.
  2503. t (if (c-lang-const c-postfix-spec-kwds)
  2504. ;; Add on the keywords in `c-postfix-spec-kwds'.
  2505. (concat (c-lang-const c-after-suffixed-type-decl-key)
  2506. "\\|"
  2507. (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
  2508. (c-lang-const c-after-suffixed-type-decl-key))
  2509. ;; Also match the colon that starts a base class initializer list in
  2510. ;; C++. That can be confused with a function call before the colon
  2511. ;; in a ? : operator, but we count on that `c-decl-prefix-re' won't
  2512. ;; match before such a thing (as a declaration-level construct;
  2513. ;; matches inside arglist contexts are already excluded).
  2514. c++ "[{:]")
  2515. (c-lang-defvar c-after-suffixed-type-decl-key
  2516. (c-lang-const c-after-suffixed-type-decl-key)
  2517. 'dont-doc)
  2518. (c-lang-defconst c-after-suffixed-type-maybe-decl-key
  2519. ;; Regexp that in addition to `c-after-suffixed-type-decl-key'
  2520. ;; matches ";" and ",".
  2521. t (concat "\\(" (c-lang-const c-after-suffixed-type-decl-key) "\\)"
  2522. "\\|[;,]"))
  2523. (c-lang-defvar c-after-suffixed-type-maybe-decl-key
  2524. (c-lang-const c-after-suffixed-type-maybe-decl-key))
  2525. (c-lang-defconst c-opt-type-concat-key
  2526. "Regexp matching operators that concatenate types, e.g. the \"|\" in
  2527. \"int|string\" in Pike. The end of the first submatch is taken as the
  2528. end of the operator. nil in languages without such operators. It's
  2529. undefined whether identifier syntax (see `c-identifier-syntax-table')
  2530. is in effect or not."
  2531. t nil
  2532. pike "\\([|.&]\\)\\($\\|[^|.&]\\)")
  2533. (c-lang-defvar c-opt-type-concat-key (c-lang-const c-opt-type-concat-key)
  2534. 'dont-doc)
  2535. (c-lang-defconst c-opt-type-suffix-key
  2536. "Regexp matching operators that might follow after a type, or nil in
  2537. languages that don't have such operators. The end of the first
  2538. submatch is taken as the end of the operator. This should not match
  2539. things like C++ template arglists if `c-recognize-<>-arglists' is set.
  2540. It's undefined whether identifier syntax (see `c-identifier-syntax-table')
  2541. is in effect or not."
  2542. t nil
  2543. (c c++ objc pike) "\\(\\.\\.\\.\\)"
  2544. java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
  2545. (c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
  2546. (c-lang-defvar c-known-type-key
  2547. ;; Regexp matching the known type identifiers. This is initialized
  2548. ;; from the type keywords and `*-font-lock-extra-types'. The first
  2549. ;; submatch is the one that matches the type. Note that this regexp
  2550. ;; assumes that symbol constituents like '_' and '$' have word
  2551. ;; syntax.
  2552. (let* ((extra-types
  2553. (when (boundp (c-mode-symbol "font-lock-extra-types"))
  2554. (c-mode-var "font-lock-extra-types")))
  2555. (regexp-strings
  2556. (apply 'nconc
  2557. (mapcar (lambda (re)
  2558. (when (string-match "[][.*+?^$\\]" re)
  2559. (list re)))
  2560. extra-types)))
  2561. (plain-strings
  2562. (apply 'nconc
  2563. (mapcar (lambda (re)
  2564. (unless (string-match "[][.*+?^$\\]" re)
  2565. (list re)))
  2566. extra-types))))
  2567. (concat "\\<\\("
  2568. (c-concat-separated
  2569. (append (list (c-make-keywords-re nil
  2570. (append (c-lang-const c-primitive-type-kwds)
  2571. plain-strings)))
  2572. regexp-strings)
  2573. "\\|")
  2574. "\\)\\>")))
  2575. (c-lang-defconst c-special-brace-lists
  2576. "List of open- and close-chars that makes up a pike-style brace list,
  2577. i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
  2578. list."
  2579. t nil
  2580. pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
  2581. (c-lang-defvar c-special-brace-lists (c-lang-const c-special-brace-lists))
  2582. (c-lang-defconst c-recognize-knr-p
  2583. "Non-nil means K&R style argument declarations are valid."
  2584. t nil
  2585. c t)
  2586. (c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
  2587. (c-lang-defconst c-recognize-typeless-decls
  2588. "Non-nil means function declarations without return type should be
  2589. recognized. That can introduce an ambiguity with parenthesized macro
  2590. calls before a brace block. This setting does not affect declarations
  2591. that are preceded by a declaration starting keyword, so
  2592. e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
  2593. t nil
  2594. (c c++ objc) t)
  2595. (c-lang-defvar c-recognize-typeless-decls
  2596. (c-lang-const c-recognize-typeless-decls))
  2597. (c-lang-defconst c-recognize-<>-arglists
  2598. "Non-nil means C++ style template arglists should be handled. More
  2599. specifically, this means a comma separated list of types or
  2600. expressions surrounded by \"<\" and \">\". It's always preceded by an
  2601. identifier or one of the keywords on `c-<>-type-kwds' or
  2602. `c-<>-arglist-kwds'. If there's an identifier before then the whole
  2603. expression is considered to be a type."
  2604. t (or (consp (c-lang-const c-<>-type-kwds))
  2605. (consp (c-lang-const c-<>-arglist-kwds))))
  2606. (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
  2607. (c-lang-defconst c-enums-contain-decls
  2608. "Non-nil means that an enum structure can contain declarations."
  2609. t nil
  2610. java t)
  2611. (c-lang-defvar c-enums-contain-decls (c-lang-const c-enums-contain-decls))
  2612. (c-lang-defconst c-recognize-paren-inits
  2613. "Non-nil means that parenthesis style initializers exist,
  2614. i.e. constructs like
  2615. Foo bar (gnu);
  2616. in addition to the more classic
  2617. Foo bar = gnu;"
  2618. t nil
  2619. c++ t)
  2620. (c-lang-defvar c-recognize-paren-inits (c-lang-const c-recognize-paren-inits))
  2621. (c-lang-defconst c-recognize-paren-inexpr-blocks
  2622. "Non-nil to recognize gcc style in-expression blocks,
  2623. i.e. compound statements surrounded by parentheses inside expressions."
  2624. t nil
  2625. (c c++) t)
  2626. (c-lang-defvar c-recognize-paren-inexpr-blocks
  2627. (c-lang-const c-recognize-paren-inexpr-blocks))
  2628. (c-lang-defconst c-opt-<>-arglist-start
  2629. ;; Regexp matching the start of angle bracket arglists in languages
  2630. ;; where `c-recognize-<>-arglists' is set. Does not exclude
  2631. ;; keywords outside `c-<>-arglist-kwds'. The first submatch is
  2632. ;; assumed to surround the preceding symbol. The whole match is
  2633. ;; assumed to end directly after the opening "<".
  2634. t (if (c-lang-const c-recognize-<>-arglists)
  2635. (concat "\\("
  2636. (c-lang-const c-symbol-key)
  2637. "\\)"
  2638. (c-lang-const c-syntactic-ws)
  2639. "<")))
  2640. (c-lang-defvar c-opt-<>-arglist-start (c-lang-const c-opt-<>-arglist-start))
  2641. (c-lang-defconst c-opt-<>-arglist-start-in-paren
  2642. ;; Regexp that in addition to `c-opt-<>-arglist-start' matches close
  2643. ;; parens. The first submatch is assumed to surround
  2644. ;; `c-opt-<>-arglist-start'.
  2645. t (if (c-lang-const c-opt-<>-arglist-start)
  2646. (concat "\\("
  2647. (c-lang-const c-opt-<>-arglist-start)
  2648. "\\)\\|\\s\)")))
  2649. (c-lang-defvar c-opt-<>-arglist-start-in-paren
  2650. (c-lang-const c-opt-<>-arglist-start-in-paren))
  2651. (c-lang-defconst c-opt-postfix-decl-spec-key
  2652. ;; Regexp matching the beginning of a declaration specifier in the
  2653. ;; region between the header and the body of a declaration.
  2654. ;;
  2655. ;; TODO: This is currently not used uniformly; c++-mode and
  2656. ;; java-mode each have their own ways of using it.
  2657. t nil
  2658. c++ (concat ":?"
  2659. (c-lang-const c-simple-ws) "*"
  2660. "\\(virtual" (c-lang-const c-simple-ws) "+\\)?\\("
  2661. (c-make-keywords-re nil (c-lang-const c-protection-kwds))
  2662. "\\)" (c-lang-const c-simple-ws) "+"
  2663. "\\(" (c-lang-const c-symbol-key) "\\)")
  2664. java (c-make-keywords-re t (c-lang-const c-postfix-spec-kwds)))
  2665. (c-lang-defvar c-opt-postfix-decl-spec-key
  2666. (c-lang-const c-opt-postfix-decl-spec-key))
  2667. (c-lang-defconst c-recognize-colon-labels
  2668. "Non-nil if generic labels ending with \":\" should be recognized.
  2669. That includes labels in code and access keys in classes. This does
  2670. not apply to labels recognized by `c-label-kwds' and
  2671. `c-opt-extra-label-key'."
  2672. t nil
  2673. (c c++ objc java pike) t)
  2674. (c-lang-defvar c-recognize-colon-labels
  2675. (c-lang-const c-recognize-colon-labels))
  2676. (c-lang-defconst c-label-prefix-re
  2677. "Regexp like `c-decl-prefix-re' that matches any token that can precede
  2678. a generic colon label. Not used if `c-recognize-colon-labels' is
  2679. nil."
  2680. t "\\([{};]+\\)")
  2681. (c-lang-defvar c-label-prefix-re
  2682. (c-lang-const c-label-prefix-re))
  2683. (c-lang-defconst c-nonlabel-token-key
  2684. "Regexp matching things that can't occur in generic colon labels,
  2685. neither in a statement nor in a declaration context. The regexp is
  2686. tested at the beginning of every sexp in a suspected label,
  2687. i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
  2688. t (concat
  2689. ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
  2690. (c-make-keywords-re t
  2691. (set-difference (c-lang-const c-keywords)
  2692. (append (c-lang-const c-label-kwds)
  2693. (c-lang-const c-protection-kwds))
  2694. :test 'string-equal)))
  2695. ;; Don't allow string literals, except in AWK. Character constants are OK.
  2696. (c objc java pike idl) (concat "\"\\|"
  2697. (c-lang-const c-nonlabel-token-key))
  2698. ;; Also check for open parens in C++, to catch member init lists in
  2699. ;; constructors. We normally allow it so that macros with arguments
  2700. ;; work in labels.
  2701. c++ (concat "\\s\(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
  2702. (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
  2703. (c-lang-defconst c-nonlabel-token-2-key
  2704. "Regexp matching things that can't occur two symbols before a colon in
  2705. a label construct. This catches C++'s inheritance construct \"class foo
  2706. : bar\". Only used if `c-recognize-colon-labels' is set."
  2707. t "\\<\\>" ; matches nothing
  2708. c++ (c-make-keywords-re t '("class")))
  2709. (c-lang-defvar c-nonlabel-token-2-key (c-lang-const c-nonlabel-token-2-key))
  2710. (c-lang-defconst c-opt-extra-label-key
  2711. "Optional regexp matching labels.
  2712. Normally, labels are detected according to `c-nonlabel-token-key',
  2713. `c-decl-prefix-re' and `c-nonlabel-decl-prefix-re'. This regexp can
  2714. be used if there are additional labels that aren't recognized that
  2715. way."
  2716. t nil
  2717. objc (c-make-keywords-re t (c-lang-const c-protection-kwds)))
  2718. (c-lang-defvar c-opt-extra-label-key (c-lang-const c-opt-extra-label-key))
  2719. (c-lang-defconst c-opt-friend-key
  2720. ;; Regexp describing friend declarations classes, or nil in
  2721. ;; languages that don't have such things.
  2722. ;;
  2723. ;; TODO: Ought to use `c-prefix-spec-kwds-re' or similar, and the
  2724. ;; template skipping isn't done properly. This will disappear soon.
  2725. t nil
  2726. c++ (concat "friend" (c-lang-const c-simple-ws) "+"
  2727. "\\|"
  2728. (concat "template"
  2729. (c-lang-const c-simple-ws) "*"
  2730. "<.+>"
  2731. (c-lang-const c-simple-ws) "*"
  2732. "friend"
  2733. (c-lang-const c-simple-ws) "+")))
  2734. (c-lang-defvar c-opt-friend-key (c-lang-const c-opt-friend-key))
  2735. (c-lang-defconst c-opt-method-key
  2736. ;; Special regexp to match the start of Objective-C methods. The
  2737. ;; first submatch is assumed to end after the + or - key.
  2738. t nil
  2739. objc (concat
  2740. ;; TODO: Ought to use a better method than anchoring on bol.
  2741. "^\\s *"
  2742. "\\([+-]\\)"
  2743. (c-lang-const c-simple-ws) "*"
  2744. (concat "\\(" ; Return type.
  2745. "([^\)]*)"
  2746. (c-lang-const c-simple-ws) "*"
  2747. "\\)?")
  2748. "\\(" (c-lang-const c-symbol-key) "\\)"))
  2749. (c-lang-defvar c-opt-method-key (c-lang-const c-opt-method-key))
  2750. (c-lang-defconst c-type-decl-end-used
  2751. ;; Must be set in buffers where the `c-type' text property might be
  2752. ;; used with the value `c-decl-end'.
  2753. ;;
  2754. ;; `c-decl-end' is used to mark the ends of labels and access keys
  2755. ;; to make interactive refontification work better.
  2756. t (or (c-lang-const c-recognize-colon-labels)
  2757. (and (c-lang-const c-label-kwds) t))
  2758. ;; `c-decl-end' is used to mark the end of the @-style directives in
  2759. ;; Objective-C.
  2760. objc t)
  2761. (c-lang-defvar c-type-decl-end-used (c-lang-const c-type-decl-end-used))
  2762. ;;; Wrap up the `c-lang-defvar' system.
  2763. ;; Compile in the list of language variables that has been collected
  2764. ;; with the `c-lang-defvar' and `c-lang-setvar' macros. Note that the
  2765. ;; first element of each is nil.
  2766. (defconst c-lang-variable-inits (cc-eval-when-compile c-lang-variable-inits))
  2767. (defconst c-emacs-variable-inits (cc-eval-when-compile c-emacs-variable-inits))
  2768. ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
  2769. ;; These are typically standard emacs variables such as `comment-start'.
  2770. (defmacro c-make-emacs-variables-local ()
  2771. `(progn
  2772. ,@(mapcar (lambda (init)
  2773. `(make-local-variable ',(car init)))
  2774. (cdr c-emacs-variable-inits))))
  2775. (defun c-make-init-lang-vars-fun (mode)
  2776. "Create a function that initializes all the language dependent variables
  2777. for the given mode.
  2778. This function should be evaluated at compile time, so that the
  2779. function it returns is byte compiled with all the evaluated results
  2780. from the language constants. Use the `c-init-language-vars' macro to
  2781. accomplish that conveniently."
  2782. (if (and (not load-in-progress)
  2783. (boundp 'byte-compile-dest-file)
  2784. (stringp byte-compile-dest-file))
  2785. ;; No need to byte compile this lambda since the byte compiler is
  2786. ;; smart enough to detect the `funcall' construct in the
  2787. ;; `c-init-language-vars' macro below and compile it all straight
  2788. ;; into the function that contains `c-init-language-vars'.
  2789. `(lambda ()
  2790. ;; This let sets up the context for `c-mode-var' and similar
  2791. ;; that could be in the result from `cl-macroexpand-all'.
  2792. (let ((c-buffer-is-cc-mode ',mode)
  2793. current-var source-eval)
  2794. (c-make-emacs-variables-local)
  2795. (condition-case err
  2796. (if (eq c-version-sym ',c-version-sym)
  2797. (setq ,@(let ((c-buffer-is-cc-mode mode)
  2798. (c-lang-const-expansion 'immediate))
  2799. ;; `c-lang-const' will expand to the evaluated
  2800. ;; constant immediately in `cl-macroexpand-all'
  2801. ;; below.
  2802. (mapcan
  2803. (lambda (init)
  2804. `(current-var ',(car init)
  2805. ,(car init) ,(cl-macroexpand-all
  2806. (elt init 1))))
  2807. ;; Note: The following `append' copies the
  2808. ;; first argument. That list is small, so
  2809. ;; this doesn't matter too much.
  2810. (append (cdr c-emacs-variable-inits)
  2811. (cdr c-lang-variable-inits)))))
  2812. ;; This diagnostic message isn't useful for end
  2813. ;; users, so it's disabled.
  2814. ;;(unless (get ',mode 'c-has-warned-lang-consts)
  2815. ;; (message ,(concat "%s compiled with CC Mode %s "
  2816. ;; "but loaded with %s - evaluating "
  2817. ;; "language constants from source")
  2818. ;; ',mode ,c-version c-version)
  2819. ;; (put ',mode 'c-has-warned-lang-consts t))
  2820. (setq source-eval t)
  2821. (let ((init ',(append (cdr c-emacs-variable-inits)
  2822. (cdr c-lang-variable-inits))))
  2823. (while init
  2824. (setq current-var (caar init))
  2825. (set (caar init) (eval (cadar init)))
  2826. (setq init (cdr init)))))
  2827. (error
  2828. (if current-var
  2829. (message "Eval error in the `c-lang-defvar' or `c-lang-setvar' for `%s'%s: %S"
  2830. current-var
  2831. (if source-eval
  2832. (format "\
  2833. (fallback source eval - %s compiled with CC Mode %s but loaded with %s)"
  2834. ',mode ,c-version c-version)
  2835. "")
  2836. err)
  2837. (signal (car err) (cdr err)))))))
  2838. ;; Being evaluated from source. Always use the dynamic method to
  2839. ;; work well when `c-lang-defvar's in this file are reevaluated
  2840. ;; interactively.
  2841. `(lambda ()
  2842. (require 'cc-langs)
  2843. (let ((c-buffer-is-cc-mode ',mode)
  2844. (init (append (cdr c-emacs-variable-inits)
  2845. (cdr c-lang-variable-inits)))
  2846. current-var)
  2847. (c-make-emacs-variables-local)
  2848. (condition-case err
  2849. (while init
  2850. (setq current-var (caar init))
  2851. (set (caar init) (eval (cadar init)))
  2852. (setq init (cdr init)))
  2853. (error
  2854. (if current-var
  2855. (message
  2856. "Eval error in the `c-lang-defvar' or `c-lang-setver' for `%s' (source eval): %S"
  2857. current-var err)
  2858. (signal (car err) (cdr err)))))))
  2859. ))
  2860. (defmacro c-init-language-vars (mode)
  2861. "Initialize all the language dependent variables for the given mode.
  2862. This macro is expanded at compile time to a form tailored for the mode
  2863. in question, so MODE must be a constant. Therefore MODE is not
  2864. evaluated and should not be quoted."
  2865. `(funcall ,(c-make-init-lang-vars-fun mode)))
  2866. (cc-provide 'cc-langs)
  2867. ;;; cc-langs.el ends here