Format.h 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- Format.h - Format C++ code -----------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// Various functions to configurably format source code.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_FORMAT_FORMAT_H
  19. #define LLVM_CLANG_FORMAT_FORMAT_H
  20. #include "clang/Basic/LangOptions.h"
  21. #include "clang/Tooling/Core/Replacement.h"
  22. #include "clang/Tooling/Inclusions/IncludeStyle.h"
  23. #include "llvm/ADT/ArrayRef.h"
  24. #include "llvm/Support/Regex.h"
  25. #include "llvm/Support/SourceMgr.h"
  26. #include <optional>
  27. #include <system_error>
  28. namespace llvm {
  29. namespace vfs {
  30. class FileSystem;
  31. }
  32. } // namespace llvm
  33. namespace clang {
  34. namespace format {
  35. enum class ParseError {
  36. Success = 0,
  37. Error,
  38. Unsuitable,
  39. BinPackTrailingCommaConflict,
  40. InvalidQualifierSpecified,
  41. DuplicateQualifierSpecified,
  42. MissingQualifierType,
  43. MissingQualifierOrder
  44. };
  45. class ParseErrorCategory final : public std::error_category {
  46. public:
  47. const char *name() const noexcept override;
  48. std::string message(int EV) const override;
  49. };
  50. const std::error_category &getParseCategory();
  51. std::error_code make_error_code(ParseError e);
  52. /// The ``FormatStyle`` is used to configure the formatting to follow
  53. /// specific guidelines.
  54. struct FormatStyle {
  55. // If the BasedOn: was InheritParentConfig and this style needs the file from
  56. // the parent directories. It is not part of the actual style for formatting.
  57. // Thus the // instead of ///.
  58. bool InheritsParentConfig;
  59. /// The extra indent or outdent of access modifiers, e.g. ``public:``.
  60. /// \version 3.3
  61. int AccessModifierOffset;
  62. /// Different styles for aligning after open brackets.
  63. enum BracketAlignmentStyle : int8_t {
  64. /// Align parameters on the open bracket, e.g.:
  65. /// \code
  66. /// someLongFunction(argument1,
  67. /// argument2);
  68. /// \endcode
  69. BAS_Align,
  70. /// Don't align, instead use ``ContinuationIndentWidth``, e.g.:
  71. /// \code
  72. /// someLongFunction(argument1,
  73. /// argument2);
  74. /// \endcode
  75. BAS_DontAlign,
  76. /// Always break after an open bracket, if the parameters don't fit
  77. /// on a single line, e.g.:
  78. /// \code
  79. /// someLongFunction(
  80. /// argument1, argument2);
  81. /// \endcode
  82. BAS_AlwaysBreak,
  83. /// Always break after an open bracket, if the parameters don't fit
  84. /// on a single line. Closing brackets will be placed on a new line.
  85. /// E.g.:
  86. /// \code
  87. /// someLongFunction(
  88. /// argument1, argument2
  89. /// )
  90. /// \endcode
  91. ///
  92. /// \warning
  93. /// Note: This currently only applies to parentheses.
  94. /// \endwarning
  95. BAS_BlockIndent,
  96. };
  97. /// If ``true``, horizontally aligns arguments after an open bracket.
  98. ///
  99. /// This applies to round brackets (parentheses), angle brackets and square
  100. /// brackets.
  101. /// \version 3.8
  102. BracketAlignmentStyle AlignAfterOpenBracket;
  103. /// Different style for aligning array initializers.
  104. enum ArrayInitializerAlignmentStyle : int8_t {
  105. /// Align array column and left justify the columns e.g.:
  106. /// \code
  107. /// struct test demo[] =
  108. /// {
  109. /// {56, 23, "hello"},
  110. /// {-1, 93463, "world"},
  111. /// {7, 5, "!!" }
  112. /// };
  113. /// \endcode
  114. AIAS_Left,
  115. /// Align array column and right justify the columns e.g.:
  116. /// \code
  117. /// struct test demo[] =
  118. /// {
  119. /// {56, 23, "hello"},
  120. /// {-1, 93463, "world"},
  121. /// { 7, 5, "!!"}
  122. /// };
  123. /// \endcode
  124. AIAS_Right,
  125. /// Don't align array initializer columns.
  126. AIAS_None
  127. };
  128. /// if not ``None``, when using initialization for an array of structs
  129. /// aligns the fields into columns.
  130. ///
  131. /// NOTE: As of clang-format 15 this option only applied to arrays with equal
  132. /// number of columns per row.
  133. ///
  134. /// \version 13
  135. ArrayInitializerAlignmentStyle AlignArrayOfStructures;
  136. /// Alignment options.
  137. ///
  138. /// They can also be read as a whole for compatibility. The choices are:
  139. /// - None
  140. /// - Consecutive
  141. /// - AcrossEmptyLines
  142. /// - AcrossComments
  143. /// - AcrossEmptyLinesAndComments
  144. ///
  145. /// For example, to align across empty lines and not across comments, either
  146. /// of these work.
  147. /// \code
  148. /// AlignConsecutiveMacros: AcrossEmptyLines
  149. ///
  150. /// AlignConsecutiveMacros:
  151. /// Enabled: true
  152. /// AcrossEmptyLines: true
  153. /// AcrossComments: false
  154. /// \endcode
  155. struct AlignConsecutiveStyle {
  156. /// Whether aligning is enabled.
  157. /// \code
  158. /// #define SHORT_NAME 42
  159. /// #define LONGER_NAME 0x007f
  160. /// #define EVEN_LONGER_NAME (2)
  161. /// #define foo(x) (x * x)
  162. /// #define bar(y, z) (y + z)
  163. ///
  164. /// int a = 1;
  165. /// int somelongname = 2;
  166. /// double c = 3;
  167. ///
  168. /// int aaaa : 1;
  169. /// int b : 12;
  170. /// int ccc : 8;
  171. ///
  172. /// int aaaa = 12;
  173. /// float b = 23;
  174. /// std::string ccc;
  175. /// \endcode
  176. bool Enabled;
  177. /// Whether to align across empty lines.
  178. /// \code
  179. /// true:
  180. /// int a = 1;
  181. /// int somelongname = 2;
  182. /// double c = 3;
  183. ///
  184. /// int d = 3;
  185. ///
  186. /// false:
  187. /// int a = 1;
  188. /// int somelongname = 2;
  189. /// double c = 3;
  190. ///
  191. /// int d = 3;
  192. /// \endcode
  193. bool AcrossEmptyLines;
  194. /// Whether to align across comments.
  195. /// \code
  196. /// true:
  197. /// int d = 3;
  198. /// /* A comment. */
  199. /// double e = 4;
  200. ///
  201. /// false:
  202. /// int d = 3;
  203. /// /* A comment. */
  204. /// double e = 4;
  205. /// \endcode
  206. bool AcrossComments;
  207. /// Only for ``AlignConsecutiveAssignments``. Whether compound assignments
  208. /// like ``+=`` are aligned along with ``=``.
  209. /// \code
  210. /// true:
  211. /// a &= 2;
  212. /// bbb = 2;
  213. ///
  214. /// false:
  215. /// a &= 2;
  216. /// bbb = 2;
  217. /// \endcode
  218. bool AlignCompound;
  219. /// Only for ``AlignConsecutiveAssignments``. Whether short assignment
  220. /// operators are left-padded to the same length as long ones in order to
  221. /// put all assignment operators to the right of the left hand side.
  222. /// \code
  223. /// true:
  224. /// a >>= 2;
  225. /// bbb = 2;
  226. ///
  227. /// a = 2;
  228. /// bbb >>= 2;
  229. ///
  230. /// false:
  231. /// a >>= 2;
  232. /// bbb = 2;
  233. ///
  234. /// a = 2;
  235. /// bbb >>= 2;
  236. /// \endcode
  237. bool PadOperators;
  238. bool operator==(const AlignConsecutiveStyle &R) const {
  239. return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
  240. AcrossComments == R.AcrossComments &&
  241. AlignCompound == R.AlignCompound && PadOperators == R.PadOperators;
  242. }
  243. bool operator!=(const AlignConsecutiveStyle &R) const {
  244. return !(*this == R);
  245. }
  246. };
  247. /// Style of aligning consecutive macro definitions.
  248. ///
  249. /// ``Consecutive`` will result in formattings like:
  250. /// \code
  251. /// #define SHORT_NAME 42
  252. /// #define LONGER_NAME 0x007f
  253. /// #define EVEN_LONGER_NAME (2)
  254. /// #define foo(x) (x * x)
  255. /// #define bar(y, z) (y + z)
  256. /// \endcode
  257. /// \version 9
  258. AlignConsecutiveStyle AlignConsecutiveMacros;
  259. /// Style of aligning consecutive assignments.
  260. ///
  261. /// ``Consecutive`` will result in formattings like:
  262. /// \code
  263. /// int a = 1;
  264. /// int somelongname = 2;
  265. /// double c = 3;
  266. /// \endcode
  267. /// \version 3.8
  268. AlignConsecutiveStyle AlignConsecutiveAssignments;
  269. /// Style of aligning consecutive bit fields.
  270. ///
  271. /// ``Consecutive`` will align the bitfield separators of consecutive lines.
  272. /// This will result in formattings like:
  273. /// \code
  274. /// int aaaa : 1;
  275. /// int b : 12;
  276. /// int ccc : 8;
  277. /// \endcode
  278. /// \version 11
  279. AlignConsecutiveStyle AlignConsecutiveBitFields;
  280. /// Style of aligning consecutive declarations.
  281. ///
  282. /// ``Consecutive`` will align the declaration names of consecutive lines.
  283. /// This will result in formattings like:
  284. /// \code
  285. /// int aaaa = 12;
  286. /// float b = 23;
  287. /// std::string ccc;
  288. /// \endcode
  289. /// \version 3.8
  290. AlignConsecutiveStyle AlignConsecutiveDeclarations;
  291. /// Different styles for aligning escaped newlines.
  292. enum EscapedNewlineAlignmentStyle : int8_t {
  293. /// Don't align escaped newlines.
  294. /// \code
  295. /// #define A \
  296. /// int aaaa; \
  297. /// int b; \
  298. /// int dddddddddd;
  299. /// \endcode
  300. ENAS_DontAlign,
  301. /// Align escaped newlines as far left as possible.
  302. /// \code
  303. /// true:
  304. /// #define A \
  305. /// int aaaa; \
  306. /// int b; \
  307. /// int dddddddddd;
  308. ///
  309. /// false:
  310. /// \endcode
  311. ENAS_Left,
  312. /// Align escaped newlines in the right-most column.
  313. /// \code
  314. /// #define A \
  315. /// int aaaa; \
  316. /// int b; \
  317. /// int dddddddddd;
  318. /// \endcode
  319. ENAS_Right,
  320. };
  321. /// Options for aligning backslashes in escaped newlines.
  322. /// \version 5
  323. EscapedNewlineAlignmentStyle AlignEscapedNewlines;
  324. /// Different styles for aligning operands.
  325. enum OperandAlignmentStyle : int8_t {
  326. /// Do not align operands of binary and ternary expressions.
  327. /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
  328. /// the start of the line.
  329. OAS_DontAlign,
  330. /// Horizontally align operands of binary and ternary expressions.
  331. ///
  332. /// Specifically, this aligns operands of a single expression that needs
  333. /// to be split over multiple lines, e.g.:
  334. /// \code
  335. /// int aaa = bbbbbbbbbbbbbbb +
  336. /// ccccccccccccccc;
  337. /// \endcode
  338. ///
  339. /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
  340. /// aligned with the operand on the first line.
  341. /// \code
  342. /// int aaa = bbbbbbbbbbbbbbb
  343. /// + ccccccccccccccc;
  344. /// \endcode
  345. OAS_Align,
  346. /// Horizontally align operands of binary and ternary expressions.
  347. ///
  348. /// This is similar to ``AO_Align``, except when
  349. /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
  350. /// that the wrapped operand is aligned with the operand on the first line.
  351. /// \code
  352. /// int aaa = bbbbbbbbbbbbbbb
  353. /// + ccccccccccccccc;
  354. /// \endcode
  355. OAS_AlignAfterOperator,
  356. };
  357. /// If ``true``, horizontally align operands of binary and ternary
  358. /// expressions.
  359. /// \version 3.5
  360. OperandAlignmentStyle AlignOperands;
  361. /// Enums for AlignTrailingComments
  362. enum TrailingCommentsAlignmentKinds : int8_t {
  363. /// Leave trailing comments as they are.
  364. /// \code
  365. /// int a; // comment
  366. /// int ab; // comment
  367. ///
  368. /// int abc; // comment
  369. /// int abcd; // comment
  370. /// \endcode
  371. TCAS_Leave,
  372. /// Align trailing comments.
  373. /// \code
  374. /// int a; // comment
  375. /// int ab; // comment
  376. ///
  377. /// int abc; // comment
  378. /// int abcd; // comment
  379. /// \endcode
  380. TCAS_Always,
  381. /// Don't align trailing comments but other formatter applies.
  382. /// \code
  383. /// int a; // comment
  384. /// int ab; // comment
  385. ///
  386. /// int abc; // comment
  387. /// int abcd; // comment
  388. /// \endcode
  389. TCAS_Never,
  390. };
  391. /// Alignment options
  392. struct TrailingCommentsAlignmentStyle {
  393. /// Specifies the way to align trailing comments.
  394. TrailingCommentsAlignmentKinds Kind;
  395. /// How many empty lines to apply alignment.
  396. /// When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
  397. /// it formats like below.
  398. /// \code
  399. /// int a; // all these
  400. ///
  401. /// int ab; // comments are
  402. ///
  403. ///
  404. /// int abcdef; // aligned
  405. /// \endcode
  406. ///
  407. /// When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
  408. /// to 1, it formats like below.
  409. /// \code
  410. /// int a; // these are
  411. ///
  412. /// int ab; // aligned
  413. ///
  414. ///
  415. /// int abcdef; // but this isn't
  416. /// \endcode
  417. unsigned OverEmptyLines;
  418. bool operator==(const TrailingCommentsAlignmentStyle &R) const {
  419. return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines;
  420. }
  421. bool operator!=(const TrailingCommentsAlignmentStyle &R) const {
  422. return !(*this == R);
  423. }
  424. };
  425. /// Control of trailing comments.
  426. ///
  427. /// NOTE: As of clang-format 16 this option is not a bool but can be set
  428. /// to the options. Conventional bool options still can be parsed as before.
  429. ///
  430. /// \code{.yaml}
  431. /// # Example of usage:
  432. /// AlignTrailingComments:
  433. /// Kind: Always
  434. /// OverEmptyLines: 2
  435. /// \endcode
  436. /// \version 3.7
  437. TrailingCommentsAlignmentStyle AlignTrailingComments;
  438. /// \brief If a function call or braced initializer list doesn't fit on a
  439. /// line, allow putting all arguments onto the next line, even if
  440. /// ``BinPackArguments`` is ``false``.
  441. /// \code
  442. /// true:
  443. /// callFunction(
  444. /// a, b, c, d);
  445. ///
  446. /// false:
  447. /// callFunction(a,
  448. /// b,
  449. /// c,
  450. /// d);
  451. /// \endcode
  452. /// \version 9
  453. bool AllowAllArgumentsOnNextLine;
  454. /// This option is **deprecated**. See ``NextLine`` of
  455. /// ``PackConstructorInitializers``.
  456. /// \version 9
  457. // bool AllowAllConstructorInitializersOnNextLine;
  458. /// If the function declaration doesn't fit on a line,
  459. /// allow putting all parameters of a function declaration onto
  460. /// the next line even if ``BinPackParameters`` is ``false``.
  461. /// \code
  462. /// true:
  463. /// void myFunction(
  464. /// int a, int b, int c, int d, int e);
  465. ///
  466. /// false:
  467. /// void myFunction(int a,
  468. /// int b,
  469. /// int c,
  470. /// int d,
  471. /// int e);
  472. /// \endcode
  473. /// \version 3.3
  474. bool AllowAllParametersOfDeclarationOnNextLine;
  475. /// Different styles for merging short blocks containing at most one
  476. /// statement.
  477. enum ShortBlockStyle : int8_t {
  478. /// Never merge blocks into a single line.
  479. /// \code
  480. /// while (true) {
  481. /// }
  482. /// while (true) {
  483. /// continue;
  484. /// }
  485. /// \endcode
  486. SBS_Never,
  487. /// Only merge empty blocks.
  488. /// \code
  489. /// while (true) {}
  490. /// while (true) {
  491. /// continue;
  492. /// }
  493. /// \endcode
  494. SBS_Empty,
  495. /// Always merge short blocks into a single line.
  496. /// \code
  497. /// while (true) {}
  498. /// while (true) { continue; }
  499. /// \endcode
  500. SBS_Always,
  501. };
  502. /// Dependent on the value, ``while (true) { continue; }`` can be put on a
  503. /// single line.
  504. /// \version 3.5
  505. ShortBlockStyle AllowShortBlocksOnASingleLine;
  506. /// If ``true``, short case labels will be contracted to a single line.
  507. /// \code
  508. /// true: false:
  509. /// switch (a) { vs. switch (a) {
  510. /// case 1: x = 1; break; case 1:
  511. /// case 2: return; x = 1;
  512. /// } break;
  513. /// case 2:
  514. /// return;
  515. /// }
  516. /// \endcode
  517. /// \version 3.6
  518. bool AllowShortCaseLabelsOnASingleLine;
  519. /// Allow short enums on a single line.
  520. /// \code
  521. /// true:
  522. /// enum { A, B } myEnum;
  523. ///
  524. /// false:
  525. /// enum {
  526. /// A,
  527. /// B
  528. /// } myEnum;
  529. /// \endcode
  530. /// \version 11
  531. bool AllowShortEnumsOnASingleLine;
  532. /// Different styles for merging short functions containing at most one
  533. /// statement.
  534. enum ShortFunctionStyle : int8_t {
  535. /// Never merge functions into a single line.
  536. SFS_None,
  537. /// Only merge functions defined inside a class. Same as "inline",
  538. /// except it does not implies "empty": i.e. top level empty functions
  539. /// are not merged either.
  540. /// \code
  541. /// class Foo {
  542. /// void f() { foo(); }
  543. /// };
  544. /// void f() {
  545. /// foo();
  546. /// }
  547. /// void f() {
  548. /// }
  549. /// \endcode
  550. SFS_InlineOnly,
  551. /// Only merge empty functions.
  552. /// \code
  553. /// void f() {}
  554. /// void f2() {
  555. /// bar2();
  556. /// }
  557. /// \endcode
  558. SFS_Empty,
  559. /// Only merge functions defined inside a class. Implies "empty".
  560. /// \code
  561. /// class Foo {
  562. /// void f() { foo(); }
  563. /// };
  564. /// void f() {
  565. /// foo();
  566. /// }
  567. /// void f() {}
  568. /// \endcode
  569. SFS_Inline,
  570. /// Merge all functions fitting on a single line.
  571. /// \code
  572. /// class Foo {
  573. /// void f() { foo(); }
  574. /// };
  575. /// void f() { bar(); }
  576. /// \endcode
  577. SFS_All,
  578. };
  579. /// Dependent on the value, ``int f() { return 0; }`` can be put on a
  580. /// single line.
  581. /// \version 3.5
  582. ShortFunctionStyle AllowShortFunctionsOnASingleLine;
  583. /// Different styles for handling short if statements.
  584. enum ShortIfStyle : int8_t {
  585. /// Never put short ifs on the same line.
  586. /// \code
  587. /// if (a)
  588. /// return;
  589. ///
  590. /// if (b)
  591. /// return;
  592. /// else
  593. /// return;
  594. ///
  595. /// if (c)
  596. /// return;
  597. /// else {
  598. /// return;
  599. /// }
  600. /// \endcode
  601. SIS_Never,
  602. /// Put short ifs on the same line only if there is no else statement.
  603. /// \code
  604. /// if (a) return;
  605. ///
  606. /// if (b)
  607. /// return;
  608. /// else
  609. /// return;
  610. ///
  611. /// if (c)
  612. /// return;
  613. /// else {
  614. /// return;
  615. /// }
  616. /// \endcode
  617. SIS_WithoutElse,
  618. /// Put short ifs, but not else ifs nor else statements, on the same line.
  619. /// \code
  620. /// if (a) return;
  621. ///
  622. /// if (b) return;
  623. /// else if (b)
  624. /// return;
  625. /// else
  626. /// return;
  627. ///
  628. /// if (c) return;
  629. /// else {
  630. /// return;
  631. /// }
  632. /// \endcode
  633. SIS_OnlyFirstIf,
  634. /// Always put short ifs, else ifs and else statements on the same
  635. /// line.
  636. /// \code
  637. /// if (a) return;
  638. ///
  639. /// if (b) return;
  640. /// else return;
  641. ///
  642. /// if (c) return;
  643. /// else {
  644. /// return;
  645. /// }
  646. /// \endcode
  647. SIS_AllIfsAndElse,
  648. };
  649. /// Dependent on the value, ``if (a) return;`` can be put on a single line.
  650. /// \version 3.3
  651. ShortIfStyle AllowShortIfStatementsOnASingleLine;
  652. /// Different styles for merging short lambdas containing at most one
  653. /// statement.
  654. enum ShortLambdaStyle : int8_t {
  655. /// Never merge lambdas into a single line.
  656. SLS_None,
  657. /// Only merge empty lambdas.
  658. /// \code
  659. /// auto lambda = [](int a) {};
  660. /// auto lambda2 = [](int a) {
  661. /// return a;
  662. /// };
  663. /// \endcode
  664. SLS_Empty,
  665. /// Merge lambda into a single line if the lambda is argument of a function.
  666. /// \code
  667. /// auto lambda = [](int x, int y) {
  668. /// return x < y;
  669. /// };
  670. /// sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
  671. /// \endcode
  672. SLS_Inline,
  673. /// Merge all lambdas fitting on a single line.
  674. /// \code
  675. /// auto lambda = [](int a) {};
  676. /// auto lambda2 = [](int a) { return a; };
  677. /// \endcode
  678. SLS_All,
  679. };
  680. /// Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
  681. /// single line.
  682. /// \version 9
  683. ShortLambdaStyle AllowShortLambdasOnASingleLine;
  684. /// If ``true``, ``while (true) continue;`` can be put on a single
  685. /// line.
  686. /// \version 3.7
  687. bool AllowShortLoopsOnASingleLine;
  688. /// Different ways to break after the function definition return type.
  689. /// This option is **deprecated** and is retained for backwards compatibility.
  690. enum DefinitionReturnTypeBreakingStyle : int8_t {
  691. /// Break after return type automatically.
  692. /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
  693. DRTBS_None,
  694. /// Always break after the return type.
  695. DRTBS_All,
  696. /// Always break after the return types of top-level functions.
  697. DRTBS_TopLevel,
  698. };
  699. /// Different ways to break after the function definition or
  700. /// declaration return type.
  701. enum ReturnTypeBreakingStyle : int8_t {
  702. /// Break after return type automatically.
  703. /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
  704. /// \code
  705. /// class A {
  706. /// int f() { return 0; };
  707. /// };
  708. /// int f();
  709. /// int f() { return 1; }
  710. /// \endcode
  711. RTBS_None,
  712. /// Always break after the return type.
  713. /// \code
  714. /// class A {
  715. /// int
  716. /// f() {
  717. /// return 0;
  718. /// };
  719. /// };
  720. /// int
  721. /// f();
  722. /// int
  723. /// f() {
  724. /// return 1;
  725. /// }
  726. /// \endcode
  727. RTBS_All,
  728. /// Always break after the return types of top-level functions.
  729. /// \code
  730. /// class A {
  731. /// int f() { return 0; };
  732. /// };
  733. /// int
  734. /// f();
  735. /// int
  736. /// f() {
  737. /// return 1;
  738. /// }
  739. /// \endcode
  740. RTBS_TopLevel,
  741. /// Always break after the return type of function definitions.
  742. /// \code
  743. /// class A {
  744. /// int
  745. /// f() {
  746. /// return 0;
  747. /// };
  748. /// };
  749. /// int f();
  750. /// int
  751. /// f() {
  752. /// return 1;
  753. /// }
  754. /// \endcode
  755. RTBS_AllDefinitions,
  756. /// Always break after the return type of top-level definitions.
  757. /// \code
  758. /// class A {
  759. /// int f() { return 0; };
  760. /// };
  761. /// int f();
  762. /// int
  763. /// f() {
  764. /// return 1;
  765. /// }
  766. /// \endcode
  767. RTBS_TopLevelDefinitions,
  768. };
  769. /// The function definition return type breaking style to use. This
  770. /// option is **deprecated** and is retained for backwards compatibility.
  771. /// \version 3.7
  772. DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
  773. /// The function declaration return type breaking style to use.
  774. /// \version 3.8
  775. ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
  776. /// If ``true``, always break before multiline string literals.
  777. ///
  778. /// This flag is mean to make cases where there are multiple multiline strings
  779. /// in a file look more consistent. Thus, it will only take effect if wrapping
  780. /// the string at that point leads to it being indented
  781. /// ``ContinuationIndentWidth`` spaces from the start of the line.
  782. /// \code
  783. /// true: false:
  784. /// aaaa = vs. aaaa = "bbbb"
  785. /// "bbbb" "cccc";
  786. /// "cccc";
  787. /// \endcode
  788. /// \version 3.4
  789. bool AlwaysBreakBeforeMultilineStrings;
  790. /// Different ways to break after the template declaration.
  791. enum BreakTemplateDeclarationsStyle : int8_t {
  792. /// Do not force break before declaration.
  793. /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
  794. /// \code
  795. /// template <typename T> T foo() {
  796. /// }
  797. /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
  798. /// int bbbbbbbbbbbbbbbbbbbbb) {
  799. /// }
  800. /// \endcode
  801. BTDS_No,
  802. /// Force break after template declaration only when the following
  803. /// declaration spans multiple lines.
  804. /// \code
  805. /// template <typename T> T foo() {
  806. /// }
  807. /// template <typename T>
  808. /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
  809. /// int bbbbbbbbbbbbbbbbbbbbb) {
  810. /// }
  811. /// \endcode
  812. BTDS_MultiLine,
  813. /// Always break after template declaration.
  814. /// \code
  815. /// template <typename T>
  816. /// T foo() {
  817. /// }
  818. /// template <typename T>
  819. /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
  820. /// int bbbbbbbbbbbbbbbbbbbbb) {
  821. /// }
  822. /// \endcode
  823. BTDS_Yes
  824. };
  825. /// The template declaration breaking style to use.
  826. /// \version 3.4
  827. BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
  828. /// A vector of strings that should be interpreted as attributes/qualifiers
  829. /// instead of identifiers. This can be useful for language extensions or
  830. /// static analyzer annotations.
  831. ///
  832. /// For example:
  833. /// \code
  834. /// x = (char *__capability)&y;
  835. /// int function(void) __ununsed;
  836. /// void only_writes_to_buffer(char *__output buffer);
  837. /// \endcode
  838. ///
  839. /// In the .clang-format configuration file, this can be configured like:
  840. /// \code{.yaml}
  841. /// AttributeMacros: ['__capability', '__output', '__ununsed']
  842. /// \endcode
  843. ///
  844. /// \version 12
  845. std::vector<std::string> AttributeMacros;
  846. /// If ``false``, a function call's arguments will either be all on the
  847. /// same line or will have one line each.
  848. /// \code
  849. /// true:
  850. /// void f() {
  851. /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
  852. /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  853. /// }
  854. ///
  855. /// false:
  856. /// void f() {
  857. /// f(aaaaaaaaaaaaaaaaaaaa,
  858. /// aaaaaaaaaaaaaaaaaaaa,
  859. /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  860. /// }
  861. /// \endcode
  862. /// \version 3.7
  863. bool BinPackArguments;
  864. /// If ``false``, a function declaration's or function definition's
  865. /// parameters will either all be on the same line or will have one line each.
  866. /// \code
  867. /// true:
  868. /// void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
  869. /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
  870. ///
  871. /// false:
  872. /// void f(int aaaaaaaaaaaaaaaaaaaa,
  873. /// int aaaaaaaaaaaaaaaaaaaa,
  874. /// int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
  875. /// \endcode
  876. /// \version 3.7
  877. bool BinPackParameters;
  878. /// Styles for adding spacing around ``:`` in bitfield definitions.
  879. enum BitFieldColonSpacingStyle : int8_t {
  880. /// Add one space on each side of the ``:``
  881. /// \code
  882. /// unsigned bf : 2;
  883. /// \endcode
  884. BFCS_Both,
  885. /// Add no space around the ``:`` (except when needed for
  886. /// ``AlignConsecutiveBitFields``).
  887. /// \code
  888. /// unsigned bf:2;
  889. /// \endcode
  890. BFCS_None,
  891. /// Add space before the ``:`` only
  892. /// \code
  893. /// unsigned bf :2;
  894. /// \endcode
  895. BFCS_Before,
  896. /// Add space after the ``:`` only (space may be added before if
  897. /// needed for ``AlignConsecutiveBitFields``).
  898. /// \code
  899. /// unsigned bf: 2;
  900. /// \endcode
  901. BFCS_After
  902. };
  903. /// The BitFieldColonSpacingStyle to use for bitfields.
  904. /// \version 12
  905. BitFieldColonSpacingStyle BitFieldColonSpacing;
  906. /// Different ways to wrap braces after control statements.
  907. enum BraceWrappingAfterControlStatementStyle : int8_t {
  908. /// Never wrap braces after a control statement.
  909. /// \code
  910. /// if (foo()) {
  911. /// } else {
  912. /// }
  913. /// for (int i = 0; i < 10; ++i) {
  914. /// }
  915. /// \endcode
  916. BWACS_Never,
  917. /// Only wrap braces after a multi-line control statement.
  918. /// \code
  919. /// if (foo && bar &&
  920. /// baz)
  921. /// {
  922. /// quux();
  923. /// }
  924. /// while (foo || bar) {
  925. /// }
  926. /// \endcode
  927. BWACS_MultiLine,
  928. /// Always wrap braces after a control statement.
  929. /// \code
  930. /// if (foo())
  931. /// {
  932. /// } else
  933. /// {}
  934. /// for (int i = 0; i < 10; ++i)
  935. /// {}
  936. /// \endcode
  937. BWACS_Always
  938. };
  939. /// Precise control over the wrapping of braces.
  940. /// \code
  941. /// # Should be declared this way:
  942. /// BreakBeforeBraces: Custom
  943. /// BraceWrapping:
  944. /// AfterClass: true
  945. /// \endcode
  946. struct BraceWrappingFlags {
  947. /// Wrap case labels.
  948. /// \code
  949. /// false: true:
  950. /// switch (foo) { vs. switch (foo) {
  951. /// case 1: { case 1:
  952. /// bar(); {
  953. /// break; bar();
  954. /// } break;
  955. /// default: { }
  956. /// plop(); default:
  957. /// } {
  958. /// } plop();
  959. /// }
  960. /// }
  961. /// \endcode
  962. bool AfterCaseLabel;
  963. /// Wrap class definitions.
  964. /// \code
  965. /// true:
  966. /// class foo
  967. /// {};
  968. ///
  969. /// false:
  970. /// class foo {};
  971. /// \endcode
  972. bool AfterClass;
  973. /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
  974. BraceWrappingAfterControlStatementStyle AfterControlStatement;
  975. /// Wrap enum definitions.
  976. /// \code
  977. /// true:
  978. /// enum X : int
  979. /// {
  980. /// B
  981. /// };
  982. ///
  983. /// false:
  984. /// enum X : int { B };
  985. /// \endcode
  986. bool AfterEnum;
  987. /// Wrap function definitions.
  988. /// \code
  989. /// true:
  990. /// void foo()
  991. /// {
  992. /// bar();
  993. /// bar2();
  994. /// }
  995. ///
  996. /// false:
  997. /// void foo() {
  998. /// bar();
  999. /// bar2();
  1000. /// }
  1001. /// \endcode
  1002. bool AfterFunction;
  1003. /// Wrap namespace definitions.
  1004. /// \code
  1005. /// true:
  1006. /// namespace
  1007. /// {
  1008. /// int foo();
  1009. /// int bar();
  1010. /// }
  1011. ///
  1012. /// false:
  1013. /// namespace {
  1014. /// int foo();
  1015. /// int bar();
  1016. /// }
  1017. /// \endcode
  1018. bool AfterNamespace;
  1019. /// Wrap ObjC definitions (interfaces, implementations...).
  1020. /// \note @autoreleasepool and @synchronized blocks are wrapped
  1021. /// according to `AfterControlStatement` flag.
  1022. bool AfterObjCDeclaration;
  1023. /// Wrap struct definitions.
  1024. /// \code
  1025. /// true:
  1026. /// struct foo
  1027. /// {
  1028. /// int x;
  1029. /// };
  1030. ///
  1031. /// false:
  1032. /// struct foo {
  1033. /// int x;
  1034. /// };
  1035. /// \endcode
  1036. bool AfterStruct;
  1037. /// Wrap union definitions.
  1038. /// \code
  1039. /// true:
  1040. /// union foo
  1041. /// {
  1042. /// int x;
  1043. /// }
  1044. ///
  1045. /// false:
  1046. /// union foo {
  1047. /// int x;
  1048. /// }
  1049. /// \endcode
  1050. bool AfterUnion;
  1051. /// Wrap extern blocks.
  1052. /// \code
  1053. /// true:
  1054. /// extern "C"
  1055. /// {
  1056. /// int foo();
  1057. /// }
  1058. ///
  1059. /// false:
  1060. /// extern "C" {
  1061. /// int foo();
  1062. /// }
  1063. /// \endcode
  1064. bool AfterExternBlock; // Partially superseded by IndentExternBlock
  1065. /// Wrap before ``catch``.
  1066. /// \code
  1067. /// true:
  1068. /// try {
  1069. /// foo();
  1070. /// }
  1071. /// catch () {
  1072. /// }
  1073. ///
  1074. /// false:
  1075. /// try {
  1076. /// foo();
  1077. /// } catch () {
  1078. /// }
  1079. /// \endcode
  1080. bool BeforeCatch;
  1081. /// Wrap before ``else``.
  1082. /// \code
  1083. /// true:
  1084. /// if (foo()) {
  1085. /// }
  1086. /// else {
  1087. /// }
  1088. ///
  1089. /// false:
  1090. /// if (foo()) {
  1091. /// } else {
  1092. /// }
  1093. /// \endcode
  1094. bool BeforeElse;
  1095. /// Wrap lambda block.
  1096. /// \code
  1097. /// true:
  1098. /// connect(
  1099. /// []()
  1100. /// {
  1101. /// foo();
  1102. /// bar();
  1103. /// });
  1104. ///
  1105. /// false:
  1106. /// connect([]() {
  1107. /// foo();
  1108. /// bar();
  1109. /// });
  1110. /// \endcode
  1111. bool BeforeLambdaBody;
  1112. /// Wrap before ``while``.
  1113. /// \code
  1114. /// true:
  1115. /// do {
  1116. /// foo();
  1117. /// }
  1118. /// while (1);
  1119. ///
  1120. /// false:
  1121. /// do {
  1122. /// foo();
  1123. /// } while (1);
  1124. /// \endcode
  1125. bool BeforeWhile;
  1126. /// Indent the wrapped braces themselves.
  1127. bool IndentBraces;
  1128. /// If ``false``, empty function body can be put on a single line.
  1129. /// This option is used only if the opening brace of the function has
  1130. /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
  1131. /// set, and the function could/should not be put on a single line (as per
  1132. /// `AllowShortFunctionsOnASingleLine` and constructor formatting options).
  1133. /// \code
  1134. /// false: true:
  1135. /// int f() vs. int f()
  1136. /// {} {
  1137. /// }
  1138. /// \endcode
  1139. ///
  1140. bool SplitEmptyFunction;
  1141. /// If ``false``, empty record (e.g. class, struct or union) body
  1142. /// can be put on a single line. This option is used only if the opening
  1143. /// brace of the record has already been wrapped, i.e. the `AfterClass`
  1144. /// (for classes) brace wrapping mode is set.
  1145. /// \code
  1146. /// false: true:
  1147. /// class Foo vs. class Foo
  1148. /// {} {
  1149. /// }
  1150. /// \endcode
  1151. ///
  1152. bool SplitEmptyRecord;
  1153. /// If ``false``, empty namespace body can be put on a single line.
  1154. /// This option is used only if the opening brace of the namespace has
  1155. /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
  1156. /// set.
  1157. /// \code
  1158. /// false: true:
  1159. /// namespace Foo vs. namespace Foo
  1160. /// {} {
  1161. /// }
  1162. /// \endcode
  1163. ///
  1164. bool SplitEmptyNamespace;
  1165. };
  1166. /// Control of individual brace wrapping cases.
  1167. ///
  1168. /// If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
  1169. /// each individual brace case should be handled. Otherwise, this is ignored.
  1170. /// \code{.yaml}
  1171. /// # Example of usage:
  1172. /// BreakBeforeBraces: Custom
  1173. /// BraceWrapping:
  1174. /// AfterEnum: true
  1175. /// AfterStruct: false
  1176. /// SplitEmptyFunction: false
  1177. /// \endcode
  1178. /// \version 3.8
  1179. BraceWrappingFlags BraceWrapping;
  1180. /// Different ways to break after attributes.
  1181. enum AttributeBreakingStyle : int8_t {
  1182. /// Always break after attributes.
  1183. /// \code
  1184. /// [[nodiscard]]
  1185. /// inline int f();
  1186. /// [[gnu::const]] [[nodiscard]]
  1187. /// int g();
  1188. /// \endcode
  1189. ABS_Always,
  1190. /// Leave the line breaking after attributes as is.
  1191. /// \code
  1192. /// [[nodiscard]] inline int f();
  1193. /// [[gnu::const]] [[nodiscard]]
  1194. /// int g();
  1195. /// \endcode
  1196. ABS_Leave,
  1197. /// Never break after attributes.
  1198. /// \code
  1199. /// [[nodiscard]] inline int f();
  1200. /// [[gnu::const]] [[nodiscard]] int g();
  1201. /// \endcode
  1202. ABS_Never,
  1203. };
  1204. /// Break after a group of C++11 attributes before a function
  1205. /// declaration/definition name.
  1206. /// \version 16
  1207. AttributeBreakingStyle BreakAfterAttributes;
  1208. /// If ``true``, clang-format will always break after a Json array `[`
  1209. /// otherwise it will scan until the closing `]` to determine if it should add
  1210. /// newlines between elements (prettier compatible).
  1211. ///
  1212. /// NOTE: This is currently only for formatting JSON.
  1213. /// \code
  1214. /// true: false:
  1215. /// [ vs. [1, 2, 3, 4]
  1216. /// 1,
  1217. /// 2,
  1218. /// 3,
  1219. /// 4
  1220. /// ]
  1221. /// \endcode
  1222. /// \version 16
  1223. bool BreakArrays;
  1224. /// The style of wrapping parameters on the same line (bin-packed) or
  1225. /// on one line each.
  1226. enum BinPackStyle : int8_t {
  1227. /// Automatically determine parameter bin-packing behavior.
  1228. BPS_Auto,
  1229. /// Always bin-pack parameters.
  1230. BPS_Always,
  1231. /// Never bin-pack parameters.
  1232. BPS_Never,
  1233. };
  1234. /// The style of breaking before or after binary operators.
  1235. enum BinaryOperatorStyle : int8_t {
  1236. /// Break after operators.
  1237. /// \code
  1238. /// LooooooooooongType loooooooooooooooooooooongVariable =
  1239. /// someLooooooooooooooooongFunction();
  1240. ///
  1241. /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
  1242. /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
  1243. /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
  1244. /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
  1245. /// ccccccccccccccccccccccccccccccccccccccccc;
  1246. /// \endcode
  1247. BOS_None,
  1248. /// Break before operators that aren't assignments.
  1249. /// \code
  1250. /// LooooooooooongType loooooooooooooooooooooongVariable =
  1251. /// someLooooooooooooooooongFunction();
  1252. ///
  1253. /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1254. /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1255. /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1256. /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1257. /// > ccccccccccccccccccccccccccccccccccccccccc;
  1258. /// \endcode
  1259. BOS_NonAssignment,
  1260. /// Break before operators.
  1261. /// \code
  1262. /// LooooooooooongType loooooooooooooooooooooongVariable
  1263. /// = someLooooooooooooooooongFunction();
  1264. ///
  1265. /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1266. /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1267. /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1268. /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  1269. /// > ccccccccccccccccccccccccccccccccccccccccc;
  1270. /// \endcode
  1271. BOS_All,
  1272. };
  1273. /// The way to wrap binary operators.
  1274. /// \version 3.6
  1275. BinaryOperatorStyle BreakBeforeBinaryOperators;
  1276. /// Different ways to attach braces to their surrounding context.
  1277. enum BraceBreakingStyle : int8_t {
  1278. /// Always attach braces to surrounding context.
  1279. /// \code
  1280. /// namespace N {
  1281. /// enum E {
  1282. /// E1,
  1283. /// E2,
  1284. /// };
  1285. ///
  1286. /// class C {
  1287. /// public:
  1288. /// C();
  1289. /// };
  1290. ///
  1291. /// bool baz(int i) {
  1292. /// try {
  1293. /// do {
  1294. /// switch (i) {
  1295. /// case 1: {
  1296. /// foobar();
  1297. /// break;
  1298. /// }
  1299. /// default: {
  1300. /// break;
  1301. /// }
  1302. /// }
  1303. /// } while (--i);
  1304. /// return true;
  1305. /// } catch (...) {
  1306. /// handleError();
  1307. /// return false;
  1308. /// }
  1309. /// }
  1310. ///
  1311. /// void foo(bool b) {
  1312. /// if (b) {
  1313. /// baz(2);
  1314. /// } else {
  1315. /// baz(5);
  1316. /// }
  1317. /// }
  1318. ///
  1319. /// void bar() { foo(true); }
  1320. /// } // namespace N
  1321. /// \endcode
  1322. BS_Attach,
  1323. /// Like ``Attach``, but break before braces on function, namespace and
  1324. /// class definitions.
  1325. /// \code
  1326. /// namespace N
  1327. /// {
  1328. /// enum E {
  1329. /// E1,
  1330. /// E2,
  1331. /// };
  1332. ///
  1333. /// class C
  1334. /// {
  1335. /// public:
  1336. /// C();
  1337. /// };
  1338. ///
  1339. /// bool baz(int i)
  1340. /// {
  1341. /// try {
  1342. /// do {
  1343. /// switch (i) {
  1344. /// case 1: {
  1345. /// foobar();
  1346. /// break;
  1347. /// }
  1348. /// default: {
  1349. /// break;
  1350. /// }
  1351. /// }
  1352. /// } while (--i);
  1353. /// return true;
  1354. /// } catch (...) {
  1355. /// handleError();
  1356. /// return false;
  1357. /// }
  1358. /// }
  1359. ///
  1360. /// void foo(bool b)
  1361. /// {
  1362. /// if (b) {
  1363. /// baz(2);
  1364. /// } else {
  1365. /// baz(5);
  1366. /// }
  1367. /// }
  1368. ///
  1369. /// void bar() { foo(true); }
  1370. /// } // namespace N
  1371. /// \endcode
  1372. BS_Linux,
  1373. /// Like ``Attach``, but break before braces on enum, function, and record
  1374. /// definitions.
  1375. /// \code
  1376. /// namespace N {
  1377. /// enum E
  1378. /// {
  1379. /// E1,
  1380. /// E2,
  1381. /// };
  1382. ///
  1383. /// class C
  1384. /// {
  1385. /// public:
  1386. /// C();
  1387. /// };
  1388. ///
  1389. /// bool baz(int i)
  1390. /// {
  1391. /// try {
  1392. /// do {
  1393. /// switch (i) {
  1394. /// case 1: {
  1395. /// foobar();
  1396. /// break;
  1397. /// }
  1398. /// default: {
  1399. /// break;
  1400. /// }
  1401. /// }
  1402. /// } while (--i);
  1403. /// return true;
  1404. /// } catch (...) {
  1405. /// handleError();
  1406. /// return false;
  1407. /// }
  1408. /// }
  1409. ///
  1410. /// void foo(bool b)
  1411. /// {
  1412. /// if (b) {
  1413. /// baz(2);
  1414. /// } else {
  1415. /// baz(5);
  1416. /// }
  1417. /// }
  1418. ///
  1419. /// void bar() { foo(true); }
  1420. /// } // namespace N
  1421. /// \endcode
  1422. BS_Mozilla,
  1423. /// Like ``Attach``, but break before function definitions, ``catch``, and
  1424. /// ``else``.
  1425. /// \code
  1426. /// namespace N {
  1427. /// enum E {
  1428. /// E1,
  1429. /// E2,
  1430. /// };
  1431. ///
  1432. /// class C {
  1433. /// public:
  1434. /// C();
  1435. /// };
  1436. ///
  1437. /// bool baz(int i)
  1438. /// {
  1439. /// try {
  1440. /// do {
  1441. /// switch (i) {
  1442. /// case 1: {
  1443. /// foobar();
  1444. /// break;
  1445. /// }
  1446. /// default: {
  1447. /// break;
  1448. /// }
  1449. /// }
  1450. /// } while (--i);
  1451. /// return true;
  1452. /// }
  1453. /// catch (...) {
  1454. /// handleError();
  1455. /// return false;
  1456. /// }
  1457. /// }
  1458. ///
  1459. /// void foo(bool b)
  1460. /// {
  1461. /// if (b) {
  1462. /// baz(2);
  1463. /// }
  1464. /// else {
  1465. /// baz(5);
  1466. /// }
  1467. /// }
  1468. ///
  1469. /// void bar() { foo(true); }
  1470. /// } // namespace N
  1471. /// \endcode
  1472. BS_Stroustrup,
  1473. /// Always break before braces.
  1474. /// \code
  1475. /// namespace N
  1476. /// {
  1477. /// enum E
  1478. /// {
  1479. /// E1,
  1480. /// E2,
  1481. /// };
  1482. ///
  1483. /// class C
  1484. /// {
  1485. /// public:
  1486. /// C();
  1487. /// };
  1488. ///
  1489. /// bool baz(int i)
  1490. /// {
  1491. /// try
  1492. /// {
  1493. /// do
  1494. /// {
  1495. /// switch (i)
  1496. /// {
  1497. /// case 1:
  1498. /// {
  1499. /// foobar();
  1500. /// break;
  1501. /// }
  1502. /// default:
  1503. /// {
  1504. /// break;
  1505. /// }
  1506. /// }
  1507. /// } while (--i);
  1508. /// return true;
  1509. /// }
  1510. /// catch (...)
  1511. /// {
  1512. /// handleError();
  1513. /// return false;
  1514. /// }
  1515. /// }
  1516. ///
  1517. /// void foo(bool b)
  1518. /// {
  1519. /// if (b)
  1520. /// {
  1521. /// baz(2);
  1522. /// }
  1523. /// else
  1524. /// {
  1525. /// baz(5);
  1526. /// }
  1527. /// }
  1528. ///
  1529. /// void bar() { foo(true); }
  1530. /// } // namespace N
  1531. /// \endcode
  1532. BS_Allman,
  1533. /// Like ``Allman`` but always indent braces and line up code with braces.
  1534. /// \code
  1535. /// namespace N
  1536. /// {
  1537. /// enum E
  1538. /// {
  1539. /// E1,
  1540. /// E2,
  1541. /// };
  1542. ///
  1543. /// class C
  1544. /// {
  1545. /// public:
  1546. /// C();
  1547. /// };
  1548. ///
  1549. /// bool baz(int i)
  1550. /// {
  1551. /// try
  1552. /// {
  1553. /// do
  1554. /// {
  1555. /// switch (i)
  1556. /// {
  1557. /// case 1:
  1558. /// {
  1559. /// foobar();
  1560. /// break;
  1561. /// }
  1562. /// default:
  1563. /// {
  1564. /// break;
  1565. /// }
  1566. /// }
  1567. /// } while (--i);
  1568. /// return true;
  1569. /// }
  1570. /// catch (...)
  1571. /// {
  1572. /// handleError();
  1573. /// return false;
  1574. /// }
  1575. /// }
  1576. ///
  1577. /// void foo(bool b)
  1578. /// {
  1579. /// if (b)
  1580. /// {
  1581. /// baz(2);
  1582. /// }
  1583. /// else
  1584. /// {
  1585. /// baz(5);
  1586. /// }
  1587. /// }
  1588. ///
  1589. /// void bar() { foo(true); }
  1590. /// } // namespace N
  1591. /// \endcode
  1592. BS_Whitesmiths,
  1593. /// Always break before braces and add an extra level of indentation to
  1594. /// braces of control statements, not to those of class, function
  1595. /// or other definitions.
  1596. /// \code
  1597. /// namespace N
  1598. /// {
  1599. /// enum E
  1600. /// {
  1601. /// E1,
  1602. /// E2,
  1603. /// };
  1604. ///
  1605. /// class C
  1606. /// {
  1607. /// public:
  1608. /// C();
  1609. /// };
  1610. ///
  1611. /// bool baz(int i)
  1612. /// {
  1613. /// try
  1614. /// {
  1615. /// do
  1616. /// {
  1617. /// switch (i)
  1618. /// {
  1619. /// case 1:
  1620. /// {
  1621. /// foobar();
  1622. /// break;
  1623. /// }
  1624. /// default:
  1625. /// {
  1626. /// break;
  1627. /// }
  1628. /// }
  1629. /// }
  1630. /// while (--i);
  1631. /// return true;
  1632. /// }
  1633. /// catch (...)
  1634. /// {
  1635. /// handleError();
  1636. /// return false;
  1637. /// }
  1638. /// }
  1639. ///
  1640. /// void foo(bool b)
  1641. /// {
  1642. /// if (b)
  1643. /// {
  1644. /// baz(2);
  1645. /// }
  1646. /// else
  1647. /// {
  1648. /// baz(5);
  1649. /// }
  1650. /// }
  1651. ///
  1652. /// void bar() { foo(true); }
  1653. /// } // namespace N
  1654. /// \endcode
  1655. BS_GNU,
  1656. /// Like ``Attach``, but break before functions.
  1657. /// \code
  1658. /// namespace N {
  1659. /// enum E {
  1660. /// E1,
  1661. /// E2,
  1662. /// };
  1663. ///
  1664. /// class C {
  1665. /// public:
  1666. /// C();
  1667. /// };
  1668. ///
  1669. /// bool baz(int i)
  1670. /// {
  1671. /// try {
  1672. /// do {
  1673. /// switch (i) {
  1674. /// case 1: {
  1675. /// foobar();
  1676. /// break;
  1677. /// }
  1678. /// default: {
  1679. /// break;
  1680. /// }
  1681. /// }
  1682. /// } while (--i);
  1683. /// return true;
  1684. /// } catch (...) {
  1685. /// handleError();
  1686. /// return false;
  1687. /// }
  1688. /// }
  1689. ///
  1690. /// void foo(bool b)
  1691. /// {
  1692. /// if (b) {
  1693. /// baz(2);
  1694. /// } else {
  1695. /// baz(5);
  1696. /// }
  1697. /// }
  1698. ///
  1699. /// void bar() { foo(true); }
  1700. /// } // namespace N
  1701. /// \endcode
  1702. BS_WebKit,
  1703. /// Configure each individual brace in `BraceWrapping`.
  1704. BS_Custom
  1705. };
  1706. /// The brace breaking style to use.
  1707. /// \version 3.7
  1708. BraceBreakingStyle BreakBeforeBraces;
  1709. /// Different ways to break before concept declarations.
  1710. enum BreakBeforeConceptDeclarationsStyle : int8_t {
  1711. /// Keep the template declaration line together with ``concept``.
  1712. /// \code
  1713. /// template <typename T> concept C = ...;
  1714. /// \endcode
  1715. BBCDS_Never,
  1716. /// Breaking between template declaration and ``concept`` is allowed. The
  1717. /// actual behavior depends on the content and line breaking rules and
  1718. /// penalities.
  1719. BBCDS_Allowed,
  1720. /// Always break before ``concept``, putting it in the line after the
  1721. /// template declaration.
  1722. /// \code
  1723. /// template <typename T>
  1724. /// concept C = ...;
  1725. /// \endcode
  1726. BBCDS_Always,
  1727. };
  1728. /// The concept declaration style to use.
  1729. /// \version 12
  1730. BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations;
  1731. /// Different ways to break ASM parameters.
  1732. enum BreakBeforeInlineASMColonStyle : int8_t {
  1733. /// No break before inline ASM colon.
  1734. /// \code
  1735. /// asm volatile("string", : : val);
  1736. /// \endcode
  1737. BBIAS_Never,
  1738. /// Break before inline ASM colon if the line length is longer than column
  1739. /// limit.
  1740. /// \code
  1741. /// asm volatile("string", : : val);
  1742. /// asm("cmoveq %1, %2, %[result]"
  1743. /// : [result] "=r"(result)
  1744. /// : "r"(test), "r"(new), "[result]"(old));
  1745. /// \endcode
  1746. BBIAS_OnlyMultiline,
  1747. /// Always break before inline ASM colon.
  1748. /// \code
  1749. /// asm volatile("string",
  1750. /// :
  1751. /// : val);
  1752. /// \endcode
  1753. BBIAS_Always,
  1754. };
  1755. /// The inline ASM colon style to use.
  1756. /// \version 16
  1757. BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
  1758. /// If ``true``, ternary operators will be placed after line breaks.
  1759. /// \code
  1760. /// true:
  1761. /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
  1762. /// ? firstValue
  1763. /// : SecondValueVeryVeryVeryVeryLong;
  1764. ///
  1765. /// false:
  1766. /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
  1767. /// firstValue :
  1768. /// SecondValueVeryVeryVeryVeryLong;
  1769. /// \endcode
  1770. /// \version 3.7
  1771. bool BreakBeforeTernaryOperators;
  1772. /// Different ways to break initializers.
  1773. enum BreakConstructorInitializersStyle : int8_t {
  1774. /// Break constructor initializers before the colon and after the commas.
  1775. /// \code
  1776. /// Constructor()
  1777. /// : initializer1(),
  1778. /// initializer2()
  1779. /// \endcode
  1780. BCIS_BeforeColon,
  1781. /// Break constructor initializers before the colon and commas, and align
  1782. /// the commas with the colon.
  1783. /// \code
  1784. /// Constructor()
  1785. /// : initializer1()
  1786. /// , initializer2()
  1787. /// \endcode
  1788. BCIS_BeforeComma,
  1789. /// Break constructor initializers after the colon and commas.
  1790. /// \code
  1791. /// Constructor() :
  1792. /// initializer1(),
  1793. /// initializer2()
  1794. /// \endcode
  1795. BCIS_AfterColon
  1796. };
  1797. /// The break constructor initializers style to use.
  1798. /// \version 5
  1799. BreakConstructorInitializersStyle BreakConstructorInitializers;
  1800. /// Break after each annotation on a field in Java files.
  1801. /// \code{.java}
  1802. /// true: false:
  1803. /// @Partial vs. @Partial @Mock DataLoad loader;
  1804. /// @Mock
  1805. /// DataLoad loader;
  1806. /// \endcode
  1807. /// \version 3.8
  1808. bool BreakAfterJavaFieldAnnotations;
  1809. /// Allow breaking string literals when formatting.
  1810. /// \code
  1811. /// true:
  1812. /// const char* x = "veryVeryVeryVeryVeryVe"
  1813. /// "ryVeryVeryVeryVeryVery"
  1814. /// "VeryLongString";
  1815. ///
  1816. /// false:
  1817. /// const char* x =
  1818. /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
  1819. /// \endcode
  1820. /// \version 3.9
  1821. bool BreakStringLiterals;
  1822. /// The column limit.
  1823. ///
  1824. /// A column limit of ``0`` means that there is no column limit. In this case,
  1825. /// clang-format will respect the input's line breaking decisions within
  1826. /// statements unless they contradict other rules.
  1827. /// \version 3.7
  1828. unsigned ColumnLimit;
  1829. /// A regular expression that describes comments with special meaning,
  1830. /// which should not be split into lines or otherwise changed.
  1831. /// \code
  1832. /// // CommentPragmas: '^ FOOBAR pragma:'
  1833. /// // Will leave the following line unaffected
  1834. /// #include <vector> // FOOBAR pragma: keep
  1835. /// \endcode
  1836. /// \version 3.7
  1837. std::string CommentPragmas;
  1838. /// Different ways to break inheritance list.
  1839. enum BreakInheritanceListStyle : int8_t {
  1840. /// Break inheritance list before the colon and after the commas.
  1841. /// \code
  1842. /// class Foo
  1843. /// : Base1,
  1844. /// Base2
  1845. /// {};
  1846. /// \endcode
  1847. BILS_BeforeColon,
  1848. /// Break inheritance list before the colon and commas, and align
  1849. /// the commas with the colon.
  1850. /// \code
  1851. /// class Foo
  1852. /// : Base1
  1853. /// , Base2
  1854. /// {};
  1855. /// \endcode
  1856. BILS_BeforeComma,
  1857. /// Break inheritance list after the colon and commas.
  1858. /// \code
  1859. /// class Foo :
  1860. /// Base1,
  1861. /// Base2
  1862. /// {};
  1863. /// \endcode
  1864. BILS_AfterColon,
  1865. /// Break inheritance list only after the commas.
  1866. /// \code
  1867. /// class Foo : Base1,
  1868. /// Base2
  1869. /// {};
  1870. /// \endcode
  1871. BILS_AfterComma,
  1872. };
  1873. /// The inheritance list style to use.
  1874. /// \version 7
  1875. BreakInheritanceListStyle BreakInheritanceList;
  1876. /// If ``true``, consecutive namespace declarations will be on the same
  1877. /// line. If ``false``, each namespace is declared on a new line.
  1878. /// \code
  1879. /// true:
  1880. /// namespace Foo { namespace Bar {
  1881. /// }}
  1882. ///
  1883. /// false:
  1884. /// namespace Foo {
  1885. /// namespace Bar {
  1886. /// }
  1887. /// }
  1888. /// \endcode
  1889. ///
  1890. /// If it does not fit on a single line, the overflowing namespaces get
  1891. /// wrapped:
  1892. /// \code
  1893. /// namespace Foo { namespace Bar {
  1894. /// namespace Extra {
  1895. /// }}}
  1896. /// \endcode
  1897. /// \version 5
  1898. bool CompactNamespaces;
  1899. /// This option is **deprecated**. See ``CurrentLine`` of
  1900. /// ``PackConstructorInitializers``.
  1901. /// \version 3.7
  1902. // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
  1903. /// The number of characters to use for indentation of constructor
  1904. /// initializer lists as well as inheritance lists.
  1905. /// \version 3.7
  1906. unsigned ConstructorInitializerIndentWidth;
  1907. /// Indent width for line continuations.
  1908. /// \code
  1909. /// ContinuationIndentWidth: 2
  1910. ///
  1911. /// int i = // VeryVeryVeryVeryVeryLongComment
  1912. /// longFunction( // Again a long comment
  1913. /// arg);
  1914. /// \endcode
  1915. /// \version 3.7
  1916. unsigned ContinuationIndentWidth;
  1917. /// If ``true``, format braced lists as best suited for C++11 braced
  1918. /// lists.
  1919. ///
  1920. /// Important differences:
  1921. /// - No spaces inside the braced list.
  1922. /// - No line break before the closing brace.
  1923. /// - Indentation with the continuation indent, not with the block indent.
  1924. ///
  1925. /// Fundamentally, C++11 braced lists are formatted exactly like function
  1926. /// calls would be formatted in their place. If the braced list follows a name
  1927. /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
  1928. /// the parentheses of a function call with that name. If there is no name,
  1929. /// a zero-length name is assumed.
  1930. /// \code
  1931. /// true: false:
  1932. /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
  1933. /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
  1934. /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
  1935. /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
  1936. /// \endcode
  1937. /// \version 3.4
  1938. bool Cpp11BracedListStyle;
  1939. /// This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
  1940. /// ``LineEnding``.
  1941. /// \version 10
  1942. // bool DeriveLineEnding;
  1943. /// If ``true``, analyze the formatted file for the most common
  1944. /// alignment of ``&`` and ``*``.
  1945. /// Pointer and reference alignment styles are going to be updated according
  1946. /// to the preferences found in the file.
  1947. /// ``PointerAlignment`` is then used only as fallback.
  1948. /// \version 3.7
  1949. bool DerivePointerAlignment;
  1950. /// Disables formatting completely.
  1951. /// \version 3.7
  1952. bool DisableFormat;
  1953. /// Different styles for empty line after access modifiers.
  1954. /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
  1955. /// empty lines between two access modifiers.
  1956. enum EmptyLineAfterAccessModifierStyle : int8_t {
  1957. /// Remove all empty lines after access modifiers.
  1958. /// \code
  1959. /// struct foo {
  1960. /// private:
  1961. /// int i;
  1962. /// protected:
  1963. /// int j;
  1964. /// /* comment */
  1965. /// public:
  1966. /// foo() {}
  1967. /// private:
  1968. /// protected:
  1969. /// };
  1970. /// \endcode
  1971. ELAAMS_Never,
  1972. /// Keep existing empty lines after access modifiers.
  1973. /// MaxEmptyLinesToKeep is applied instead.
  1974. ELAAMS_Leave,
  1975. /// Always add empty line after access modifiers if there are none.
  1976. /// MaxEmptyLinesToKeep is applied also.
  1977. /// \code
  1978. /// struct foo {
  1979. /// private:
  1980. ///
  1981. /// int i;
  1982. /// protected:
  1983. ///
  1984. /// int j;
  1985. /// /* comment */
  1986. /// public:
  1987. ///
  1988. /// foo() {}
  1989. /// private:
  1990. ///
  1991. /// protected:
  1992. ///
  1993. /// };
  1994. /// \endcode
  1995. ELAAMS_Always,
  1996. };
  1997. /// Defines when to put an empty line after access modifiers.
  1998. /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
  1999. /// empty lines between two access modifiers.
  2000. /// \version 13
  2001. EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier;
  2002. /// Different styles for empty line before access modifiers.
  2003. enum EmptyLineBeforeAccessModifierStyle : int8_t {
  2004. /// Remove all empty lines before access modifiers.
  2005. /// \code
  2006. /// struct foo {
  2007. /// private:
  2008. /// int i;
  2009. /// protected:
  2010. /// int j;
  2011. /// /* comment */
  2012. /// public:
  2013. /// foo() {}
  2014. /// private:
  2015. /// protected:
  2016. /// };
  2017. /// \endcode
  2018. ELBAMS_Never,
  2019. /// Keep existing empty lines before access modifiers.
  2020. ELBAMS_Leave,
  2021. /// Add empty line only when access modifier starts a new logical block.
  2022. /// Logical block is a group of one or more member fields or functions.
  2023. /// \code
  2024. /// struct foo {
  2025. /// private:
  2026. /// int i;
  2027. ///
  2028. /// protected:
  2029. /// int j;
  2030. /// /* comment */
  2031. /// public:
  2032. /// foo() {}
  2033. ///
  2034. /// private:
  2035. /// protected:
  2036. /// };
  2037. /// \endcode
  2038. ELBAMS_LogicalBlock,
  2039. /// Always add empty line before access modifiers unless access modifier
  2040. /// is at the start of struct or class definition.
  2041. /// \code
  2042. /// struct foo {
  2043. /// private:
  2044. /// int i;
  2045. ///
  2046. /// protected:
  2047. /// int j;
  2048. /// /* comment */
  2049. ///
  2050. /// public:
  2051. /// foo() {}
  2052. ///
  2053. /// private:
  2054. ///
  2055. /// protected:
  2056. /// };
  2057. /// \endcode
  2058. ELBAMS_Always,
  2059. };
  2060. /// Defines in which cases to put empty line before access modifiers.
  2061. /// \version 12
  2062. EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
  2063. /// If ``true``, clang-format detects whether function calls and
  2064. /// definitions are formatted with one parameter per line.
  2065. ///
  2066. /// Each call can be bin-packed, one-per-line or inconclusive. If it is
  2067. /// inconclusive, e.g. completely on one line, but a decision needs to be
  2068. /// made, clang-format analyzes whether there are other bin-packed cases in
  2069. /// the input file and act accordingly.
  2070. ///
  2071. /// NOTE: This is an experimental flag, that might go away or be renamed. Do
  2072. /// not use this in config files, etc. Use at your own risk.
  2073. /// \version 3.7
  2074. bool ExperimentalAutoDetectBinPacking;
  2075. /// If ``true``, clang-format adds missing namespace end comments for
  2076. /// namespaces and fixes invalid existing ones. This doesn't affect short
  2077. /// namespaces, which are controlled by ``ShortNamespaceLines``.
  2078. /// \code
  2079. /// true: false:
  2080. /// namespace longNamespace { vs. namespace longNamespace {
  2081. /// void foo(); void foo();
  2082. /// void bar(); void bar();
  2083. /// } // namespace a }
  2084. /// namespace shortNamespace { namespace shortNamespace {
  2085. /// void baz(); void baz();
  2086. /// } }
  2087. /// \endcode
  2088. /// \version 5
  2089. bool FixNamespaceComments;
  2090. /// A vector of macros that should be interpreted as foreach loops
  2091. /// instead of as function calls.
  2092. ///
  2093. /// These are expected to be macros of the form:
  2094. /// \code
  2095. /// FOREACH(<variable-declaration>, ...)
  2096. /// <loop-body>
  2097. /// \endcode
  2098. ///
  2099. /// In the .clang-format configuration file, this can be configured like:
  2100. /// \code{.yaml}
  2101. /// ForEachMacros: ['RANGES_FOR', 'FOREACH']
  2102. /// \endcode
  2103. ///
  2104. /// For example: BOOST_FOREACH.
  2105. /// \version 3.7
  2106. std::vector<std::string> ForEachMacros;
  2107. tooling::IncludeStyle IncludeStyle;
  2108. /// A vector of macros that should be interpreted as conditionals
  2109. /// instead of as function calls.
  2110. ///
  2111. /// These are expected to be macros of the form:
  2112. /// \code
  2113. /// IF(...)
  2114. /// <conditional-body>
  2115. /// else IF(...)
  2116. /// <conditional-body>
  2117. /// \endcode
  2118. ///
  2119. /// In the .clang-format configuration file, this can be configured like:
  2120. /// \code{.yaml}
  2121. /// IfMacros: ['IF']
  2122. /// \endcode
  2123. ///
  2124. /// For example: `KJ_IF_MAYBE
  2125. /// <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
  2126. /// \version 13
  2127. std::vector<std::string> IfMacros;
  2128. /// Specify whether access modifiers should have their own indentation level.
  2129. ///
  2130. /// When ``false``, access modifiers are indented (or outdented) relative to
  2131. /// the record members, respecting the ``AccessModifierOffset``. Record
  2132. /// members are indented one level below the record.
  2133. /// When ``true``, access modifiers get their own indentation level. As a
  2134. /// consequence, record members are always indented 2 levels below the record,
  2135. /// regardless of the access modifier presence. Value of the
  2136. /// ``AccessModifierOffset`` is ignored.
  2137. /// \code
  2138. /// false: true:
  2139. /// class C { vs. class C {
  2140. /// class D { class D {
  2141. /// void bar(); void bar();
  2142. /// protected: protected:
  2143. /// D(); D();
  2144. /// }; };
  2145. /// public: public:
  2146. /// C(); C();
  2147. /// }; };
  2148. /// void foo() { void foo() {
  2149. /// return 1; return 1;
  2150. /// } }
  2151. /// \endcode
  2152. /// \version 13
  2153. bool IndentAccessModifiers;
  2154. /// Indent case label blocks one level from the case label.
  2155. ///
  2156. /// When ``false``, the block following the case label uses the same
  2157. /// indentation level as for the case label, treating the case label the same
  2158. /// as an if-statement.
  2159. /// When ``true``, the block gets indented as a scope block.
  2160. /// \code
  2161. /// false: true:
  2162. /// switch (fool) { vs. switch (fool) {
  2163. /// case 1: { case 1:
  2164. /// bar(); {
  2165. /// } break; bar();
  2166. /// default: { }
  2167. /// plop(); break;
  2168. /// } default:
  2169. /// } {
  2170. /// plop();
  2171. /// }
  2172. /// }
  2173. /// \endcode
  2174. /// \version 11
  2175. bool IndentCaseBlocks;
  2176. /// Indent case labels one level from the switch statement.
  2177. ///
  2178. /// When ``false``, use the same indentation level as for the switch
  2179. /// statement. Switch statement body is always indented one level more than
  2180. /// case labels (except the first block following the case label, which
  2181. /// itself indents the code - unless IndentCaseBlocks is enabled).
  2182. /// \code
  2183. /// false: true:
  2184. /// switch (fool) { vs. switch (fool) {
  2185. /// case 1: case 1:
  2186. /// bar(); bar();
  2187. /// break; break;
  2188. /// default: default:
  2189. /// plop(); plop();
  2190. /// } }
  2191. /// \endcode
  2192. /// \version 3.3
  2193. bool IndentCaseLabels;
  2194. /// Indent goto labels.
  2195. ///
  2196. /// When ``false``, goto labels are flushed left.
  2197. /// \code
  2198. /// true: false:
  2199. /// int f() { vs. int f() {
  2200. /// if (foo()) { if (foo()) {
  2201. /// label1: label1:
  2202. /// bar(); bar();
  2203. /// } }
  2204. /// label2: label2:
  2205. /// return 1; return 1;
  2206. /// } }
  2207. /// \endcode
  2208. /// \version 10
  2209. bool IndentGotoLabels;
  2210. /// Indents extern blocks
  2211. enum IndentExternBlockStyle : int8_t {
  2212. /// Backwards compatible with AfterExternBlock's indenting.
  2213. /// \code
  2214. /// IndentExternBlock: AfterExternBlock
  2215. /// BraceWrapping.AfterExternBlock: true
  2216. /// extern "C"
  2217. /// {
  2218. /// void foo();
  2219. /// }
  2220. /// \endcode
  2221. ///
  2222. /// \code
  2223. /// IndentExternBlock: AfterExternBlock
  2224. /// BraceWrapping.AfterExternBlock: false
  2225. /// extern "C" {
  2226. /// void foo();
  2227. /// }
  2228. /// \endcode
  2229. IEBS_AfterExternBlock,
  2230. /// Does not indent extern blocks.
  2231. /// \code
  2232. /// extern "C" {
  2233. /// void foo();
  2234. /// }
  2235. /// \endcode
  2236. IEBS_NoIndent,
  2237. /// Indents extern blocks.
  2238. /// \code
  2239. /// extern "C" {
  2240. /// void foo();
  2241. /// }
  2242. /// \endcode
  2243. IEBS_Indent,
  2244. };
  2245. /// IndentExternBlockStyle is the type of indenting of extern blocks.
  2246. /// \version 11
  2247. IndentExternBlockStyle IndentExternBlock;
  2248. /// Options for indenting preprocessor directives.
  2249. enum PPDirectiveIndentStyle : int8_t {
  2250. /// Does not indent any directives.
  2251. /// \code
  2252. /// #if FOO
  2253. /// #if BAR
  2254. /// #include <foo>
  2255. /// #endif
  2256. /// #endif
  2257. /// \endcode
  2258. PPDIS_None,
  2259. /// Indents directives after the hash.
  2260. /// \code
  2261. /// #if FOO
  2262. /// # if BAR
  2263. /// # include <foo>
  2264. /// # endif
  2265. /// #endif
  2266. /// \endcode
  2267. PPDIS_AfterHash,
  2268. /// Indents directives before the hash.
  2269. /// \code
  2270. /// #if FOO
  2271. /// #if BAR
  2272. /// #include <foo>
  2273. /// #endif
  2274. /// #endif
  2275. /// \endcode
  2276. PPDIS_BeforeHash
  2277. };
  2278. /// The preprocessor directive indenting style to use.
  2279. /// \version 6
  2280. PPDirectiveIndentStyle IndentPPDirectives;
  2281. /// Indent the requires clause in a template. This only applies when
  2282. /// ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
  2283. ///
  2284. /// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
  2285. /// \code
  2286. /// true:
  2287. /// template <typename It>
  2288. /// requires Iterator<It>
  2289. /// void sort(It begin, It end) {
  2290. /// //....
  2291. /// }
  2292. ///
  2293. /// false:
  2294. /// template <typename It>
  2295. /// requires Iterator<It>
  2296. /// void sort(It begin, It end) {
  2297. /// //....
  2298. /// }
  2299. /// \endcode
  2300. /// \version 15
  2301. bool IndentRequiresClause;
  2302. /// The number of columns to use for indentation.
  2303. /// \code
  2304. /// IndentWidth: 3
  2305. ///
  2306. /// void f() {
  2307. /// someFunction();
  2308. /// if (true, false) {
  2309. /// f();
  2310. /// }
  2311. /// }
  2312. /// \endcode
  2313. /// \version 3.7
  2314. unsigned IndentWidth;
  2315. /// Indent if a function definition or declaration is wrapped after the
  2316. /// type.
  2317. /// \code
  2318. /// true:
  2319. /// LoooooooooooooooooooooooooooooooooooooooongReturnType
  2320. /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
  2321. ///
  2322. /// false:
  2323. /// LoooooooooooooooooooooooooooooooooooooooongReturnType
  2324. /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
  2325. /// \endcode
  2326. /// \version 3.7
  2327. bool IndentWrappedFunctionNames;
  2328. /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
  2329. /// and ``while``) in C++ unless the control statements are inside macro
  2330. /// definitions or the braces would enclose preprocessor directives.
  2331. /// \warning
  2332. /// Setting this option to `true` could lead to incorrect code formatting due
  2333. /// to clang-format's lack of complete semantic information. As such, extra
  2334. /// care should be taken to review code changes made by this option.
  2335. /// \endwarning
  2336. /// \code
  2337. /// false: true:
  2338. ///
  2339. /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
  2340. /// handleFunctionDecl(D); handleFunctionDecl(D);
  2341. /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
  2342. /// handleVarDecl(D); handleVarDecl(D);
  2343. /// else } else {
  2344. /// return; return;
  2345. /// }
  2346. ///
  2347. /// while (i--) vs. while (i--) {
  2348. /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
  2349. /// handleAttr(A); handleAttr(A);
  2350. /// }
  2351. /// }
  2352. ///
  2353. /// do vs. do {
  2354. /// --i; --i;
  2355. /// while (i); } while (i);
  2356. /// \endcode
  2357. /// \version 15
  2358. bool InsertBraces;
  2359. /// Insert a newline at end of file if missing.
  2360. /// \version 16
  2361. bool InsertNewlineAtEOF;
  2362. /// The style of inserting trailing commas into container literals.
  2363. enum TrailingCommaStyle : int8_t {
  2364. /// Do not insert trailing commas.
  2365. TCS_None,
  2366. /// Insert trailing commas in container literals that were wrapped over
  2367. /// multiple lines. Note that this is conceptually incompatible with
  2368. /// bin-packing, because the trailing comma is used as an indicator
  2369. /// that a container should be formatted one-per-line (i.e. not bin-packed).
  2370. /// So inserting a trailing comma counteracts bin-packing.
  2371. TCS_Wrapped,
  2372. };
  2373. /// If set to ``TCS_Wrapped`` will insert trailing commas in container
  2374. /// literals (arrays and objects) that wrap across multiple lines.
  2375. /// It is currently only available for JavaScript
  2376. /// and disabled by default ``TCS_None``.
  2377. /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
  2378. /// as inserting the comma disables bin-packing.
  2379. /// \code
  2380. /// TSC_Wrapped:
  2381. /// const someArray = [
  2382. /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
  2383. /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
  2384. /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
  2385. /// // ^ inserted
  2386. /// ]
  2387. /// \endcode
  2388. /// \version 11
  2389. TrailingCommaStyle InsertTrailingCommas;
  2390. /// Separator format of integer literals of different bases.
  2391. ///
  2392. /// If negative, remove separators. If ``0``, leave the literal as is. If
  2393. /// positive, insert separators between digits starting from the rightmost
  2394. /// digit.
  2395. ///
  2396. /// For example, the config below will leave separators in binary literals
  2397. /// alone, insert separators in decimal literals to separate the digits into
  2398. /// groups of 3, and remove separators in hexadecimal literals.
  2399. /// \code
  2400. /// IntegerLiteralSeparator:
  2401. /// Binary: 0
  2402. /// Decimal: 3
  2403. /// Hex: -1
  2404. /// \endcode
  2405. struct IntegerLiteralSeparatorStyle {
  2406. /// Format separators in binary literals.
  2407. /// \code{.text}
  2408. /// /* -1: */ b = 0b100111101101;
  2409. /// /* 0: */ b = 0b10011'11'0110'1;
  2410. /// /* 3: */ b = 0b100'111'101'101;
  2411. /// /* 4: */ b = 0b1001'1110'1101;
  2412. /// \endcode
  2413. int8_t Binary;
  2414. /// Format separators in decimal literals.
  2415. /// \code{.text}
  2416. /// /* -1: */ d = 18446744073709550592ull;
  2417. /// /* 0: */ d = 184467'440737'0'95505'92ull;
  2418. /// /* 3: */ d = 18'446'744'073'709'550'592ull;
  2419. /// \endcode
  2420. int8_t Decimal;
  2421. /// Format separators in hexadecimal literals.
  2422. /// \code{.text}
  2423. /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
  2424. /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
  2425. /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
  2426. /// \endcode
  2427. int8_t Hex;
  2428. };
  2429. /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
  2430. /// and JavaScript).
  2431. /// \version 16
  2432. IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
  2433. /// A vector of prefixes ordered by the desired groups for Java imports.
  2434. ///
  2435. /// One group's prefix can be a subset of another - the longest prefix is
  2436. /// always matched. Within a group, the imports are ordered lexicographically.
  2437. /// Static imports are grouped separately and follow the same group rules.
  2438. /// By default, static imports are placed before non-static imports,
  2439. /// but this behavior is changed by another option,
  2440. /// ``SortJavaStaticImport``.
  2441. ///
  2442. /// In the .clang-format configuration file, this can be configured like
  2443. /// in the following yaml example. This will result in imports being
  2444. /// formatted as in the Java example below.
  2445. /// \code{.yaml}
  2446. /// JavaImportGroups: ['com.example', 'com', 'org']
  2447. /// \endcode
  2448. ///
  2449. /// \code{.java}
  2450. /// import static com.example.function1;
  2451. ///
  2452. /// import static com.test.function2;
  2453. ///
  2454. /// import static org.example.function3;
  2455. ///
  2456. /// import com.example.ClassA;
  2457. /// import com.example.Test;
  2458. /// import com.example.a.ClassB;
  2459. ///
  2460. /// import com.test.ClassC;
  2461. ///
  2462. /// import org.example.ClassD;
  2463. /// \endcode
  2464. /// \version 8
  2465. std::vector<std::string> JavaImportGroups;
  2466. /// Quotation styles for JavaScript strings. Does not affect template
  2467. /// strings.
  2468. enum JavaScriptQuoteStyle : int8_t {
  2469. /// Leave string quotes as they are.
  2470. /// \code{.js}
  2471. /// string1 = "foo";
  2472. /// string2 = 'bar';
  2473. /// \endcode
  2474. JSQS_Leave,
  2475. /// Always use single quotes.
  2476. /// \code{.js}
  2477. /// string1 = 'foo';
  2478. /// string2 = 'bar';
  2479. /// \endcode
  2480. JSQS_Single,
  2481. /// Always use double quotes.
  2482. /// \code{.js}
  2483. /// string1 = "foo";
  2484. /// string2 = "bar";
  2485. /// \endcode
  2486. JSQS_Double
  2487. };
  2488. /// The JavaScriptQuoteStyle to use for JavaScript strings.
  2489. /// \version 3.9
  2490. JavaScriptQuoteStyle JavaScriptQuotes;
  2491. // clang-format off
  2492. /// Whether to wrap JavaScript import/export statements.
  2493. /// \code{.js}
  2494. /// true:
  2495. /// import {
  2496. /// VeryLongImportsAreAnnoying,
  2497. /// VeryLongImportsAreAnnoying,
  2498. /// VeryLongImportsAreAnnoying,
  2499. /// } from 'some/module.js'
  2500. ///
  2501. /// false:
  2502. /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
  2503. /// \endcode
  2504. /// \version 3.9
  2505. bool JavaScriptWrapImports;
  2506. // clang-format on
  2507. /// If true, the empty line at the start of blocks is kept.
  2508. /// \code
  2509. /// true: false:
  2510. /// if (foo) { vs. if (foo) {
  2511. /// bar();
  2512. /// bar(); }
  2513. /// }
  2514. /// \endcode
  2515. /// \version 3.7
  2516. bool KeepEmptyLinesAtTheStartOfBlocks;
  2517. /// Indentation logic for lambda bodies.
  2518. enum LambdaBodyIndentationKind : int8_t {
  2519. /// Align lambda body relative to the lambda signature. This is the default.
  2520. /// \code
  2521. /// someMethod(
  2522. /// [](SomeReallyLongLambdaSignatureArgument foo) {
  2523. /// return;
  2524. /// });
  2525. /// \endcode
  2526. LBI_Signature,
  2527. /// Align lambda body relative to the indentation level of the outer scope
  2528. /// the lambda signature resides in.
  2529. /// \code
  2530. /// someMethod(
  2531. /// [](SomeReallyLongLambdaSignatureArgument foo) {
  2532. /// return;
  2533. /// });
  2534. /// \endcode
  2535. LBI_OuterScope,
  2536. };
  2537. /// The indentation style of lambda bodies. ``Signature`` (the default)
  2538. /// causes the lambda body to be indented one additional level relative to
  2539. /// the indentation level of the signature. ``OuterScope`` forces the lambda
  2540. /// body to be indented one additional level relative to the parent scope
  2541. /// containing the lambda signature. For callback-heavy code, it may improve
  2542. /// readability to have the signature indented two levels and to use
  2543. /// ``OuterScope``. The KJ style guide requires ``OuterScope``.
  2544. /// `KJ style guide
  2545. /// <https://github.com/capnproto/capnproto/blob/master/style-guide.md>`_
  2546. /// \version 13
  2547. LambdaBodyIndentationKind LambdaBodyIndentation;
  2548. /// Supported languages.
  2549. ///
  2550. /// When stored in a configuration file, specifies the language, that the
  2551. /// configuration targets. When passed to the ``reformat()`` function, enables
  2552. /// syntax features specific to the language.
  2553. enum LanguageKind : int8_t {
  2554. /// Do not use.
  2555. LK_None,
  2556. /// Should be used for C, C++.
  2557. LK_Cpp,
  2558. /// Should be used for C#.
  2559. LK_CSharp,
  2560. /// Should be used for Java.
  2561. LK_Java,
  2562. /// Should be used for JavaScript.
  2563. LK_JavaScript,
  2564. /// Should be used for JSON.
  2565. LK_Json,
  2566. /// Should be used for Objective-C, Objective-C++.
  2567. LK_ObjC,
  2568. /// Should be used for Protocol Buffers
  2569. /// (https://developers.google.com/protocol-buffers/).
  2570. LK_Proto,
  2571. /// Should be used for TableGen code.
  2572. LK_TableGen,
  2573. /// Should be used for Protocol Buffer messages in text format
  2574. /// (https://developers.google.com/protocol-buffers/).
  2575. LK_TextProto,
  2576. /// Should be used for Verilog and SystemVerilog.
  2577. /// https://standards.ieee.org/ieee/1800/6700/
  2578. /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
  2579. LK_Verilog
  2580. };
  2581. bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
  2582. bool isCSharp() const { return Language == LK_CSharp; }
  2583. bool isJson() const { return Language == LK_Json; }
  2584. bool isJavaScript() const { return Language == LK_JavaScript; }
  2585. bool isVerilog() const { return Language == LK_Verilog; }
  2586. bool isProto() const { return Language == LK_Proto; }
  2587. /// Language, this format style is targeted at.
  2588. /// \version 3.5
  2589. LanguageKind Language;
  2590. /// Line ending style.
  2591. enum LineEndingStyle : int8_t {
  2592. /// Use ``\n``.
  2593. LE_LF,
  2594. /// Use ``\r\n``.
  2595. LE_CRLF,
  2596. /// Use ``\n`` unless the input has more lines ending in ``\r\n``.
  2597. LE_DeriveLF,
  2598. /// Use ``\r\n`` unless the input has more lines ending in ``\n``.
  2599. LE_DeriveCRLF,
  2600. };
  2601. /// Line ending style (``\n`` or ``\r\n``) to use.
  2602. /// \version 16
  2603. LineEndingStyle LineEnding;
  2604. /// A regular expression matching macros that start a block.
  2605. /// \code
  2606. /// # With:
  2607. /// MacroBlockBegin: "^NS_MAP_BEGIN|\
  2608. /// NS_TABLE_HEAD$"
  2609. /// MacroBlockEnd: "^\
  2610. /// NS_MAP_END|\
  2611. /// NS_TABLE_.*_END$"
  2612. ///
  2613. /// NS_MAP_BEGIN
  2614. /// foo();
  2615. /// NS_MAP_END
  2616. ///
  2617. /// NS_TABLE_HEAD
  2618. /// bar();
  2619. /// NS_TABLE_FOO_END
  2620. ///
  2621. /// # Without:
  2622. /// NS_MAP_BEGIN
  2623. /// foo();
  2624. /// NS_MAP_END
  2625. ///
  2626. /// NS_TABLE_HEAD
  2627. /// bar();
  2628. /// NS_TABLE_FOO_END
  2629. /// \endcode
  2630. /// \version 3.7
  2631. std::string MacroBlockBegin;
  2632. /// A regular expression matching macros that end a block.
  2633. /// \version 3.7
  2634. std::string MacroBlockEnd;
  2635. /// The maximum number of consecutive empty lines to keep.
  2636. /// \code
  2637. /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
  2638. /// int f() { int f() {
  2639. /// int = 1; int i = 1;
  2640. /// i = foo();
  2641. /// i = foo(); return i;
  2642. /// }
  2643. /// return i;
  2644. /// }
  2645. /// \endcode
  2646. /// \version 3.7
  2647. unsigned MaxEmptyLinesToKeep;
  2648. /// Different ways to indent namespace contents.
  2649. enum NamespaceIndentationKind : int8_t {
  2650. /// Don't indent in namespaces.
  2651. /// \code
  2652. /// namespace out {
  2653. /// int i;
  2654. /// namespace in {
  2655. /// int i;
  2656. /// }
  2657. /// }
  2658. /// \endcode
  2659. NI_None,
  2660. /// Indent only in inner namespaces (nested in other namespaces).
  2661. /// \code
  2662. /// namespace out {
  2663. /// int i;
  2664. /// namespace in {
  2665. /// int i;
  2666. /// }
  2667. /// }
  2668. /// \endcode
  2669. NI_Inner,
  2670. /// Indent in all namespaces.
  2671. /// \code
  2672. /// namespace out {
  2673. /// int i;
  2674. /// namespace in {
  2675. /// int i;
  2676. /// }
  2677. /// }
  2678. /// \endcode
  2679. NI_All
  2680. };
  2681. /// The indentation used for namespaces.
  2682. /// \version 3.7
  2683. NamespaceIndentationKind NamespaceIndentation;
  2684. /// A vector of macros which are used to open namespace blocks.
  2685. ///
  2686. /// These are expected to be macros of the form:
  2687. /// \code
  2688. /// NAMESPACE(<namespace-name>, ...) {
  2689. /// <namespace-content>
  2690. /// }
  2691. /// \endcode
  2692. ///
  2693. /// For example: TESTSUITE
  2694. /// \version 9
  2695. std::vector<std::string> NamespaceMacros;
  2696. /// Controls bin-packing Objective-C protocol conformance list
  2697. /// items into as few lines as possible when they go over ``ColumnLimit``.
  2698. ///
  2699. /// If ``Auto`` (the default), delegates to the value in
  2700. /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
  2701. /// protocol conformance list items into as few lines as possible
  2702. /// whenever they go over ``ColumnLimit``.
  2703. ///
  2704. /// If ``Always``, always bin-packs Objective-C protocol conformance
  2705. /// list items into as few lines as possible whenever they go over
  2706. /// ``ColumnLimit``.
  2707. ///
  2708. /// If ``Never``, lays out Objective-C protocol conformance list items
  2709. /// onto individual lines whenever they go over ``ColumnLimit``.
  2710. ///
  2711. /// \code{.objc}
  2712. /// Always (or Auto, if BinPackParameters=true):
  2713. /// @interface ccccccccccccc () <
  2714. /// ccccccccccccc, ccccccccccccc,
  2715. /// ccccccccccccc, ccccccccccccc> {
  2716. /// }
  2717. ///
  2718. /// Never (or Auto, if BinPackParameters=false):
  2719. /// @interface ddddddddddddd () <
  2720. /// ddddddddddddd,
  2721. /// ddddddddddddd,
  2722. /// ddddddddddddd,
  2723. /// ddddddddddddd> {
  2724. /// }
  2725. /// \endcode
  2726. /// \version 7
  2727. BinPackStyle ObjCBinPackProtocolList;
  2728. /// The number of characters to use for indentation of ObjC blocks.
  2729. /// \code{.objc}
  2730. /// ObjCBlockIndentWidth: 4
  2731. ///
  2732. /// [operation setCompletionBlock:^{
  2733. /// [self onOperationDone];
  2734. /// }];
  2735. /// \endcode
  2736. /// \version 3.7
  2737. unsigned ObjCBlockIndentWidth;
  2738. /// Break parameters list into lines when there is nested block
  2739. /// parameters in a function call.
  2740. /// \code
  2741. /// false:
  2742. /// - (void)_aMethod
  2743. /// {
  2744. /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
  2745. /// *u, NSNumber *v) {
  2746. /// u = c;
  2747. /// }]
  2748. /// }
  2749. /// true:
  2750. /// - (void)_aMethod
  2751. /// {
  2752. /// [self.test1 t:self
  2753. /// w:self
  2754. /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
  2755. /// u = c;
  2756. /// }]
  2757. /// }
  2758. /// \endcode
  2759. /// \version 11
  2760. bool ObjCBreakBeforeNestedBlockParam;
  2761. /// Add a space after ``@property`` in Objective-C, i.e. use
  2762. /// ``@property (readonly)`` instead of ``@property(readonly)``.
  2763. /// \version 3.7
  2764. bool ObjCSpaceAfterProperty;
  2765. /// Add a space in front of an Objective-C protocol list, i.e. use
  2766. /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
  2767. /// \version 3.7
  2768. bool ObjCSpaceBeforeProtocolList;
  2769. /// Different ways to try to fit all constructor initializers on a line.
  2770. enum PackConstructorInitializersStyle : int8_t {
  2771. /// Always put each constructor initializer on its own line.
  2772. /// \code
  2773. /// Constructor()
  2774. /// : a(),
  2775. /// b()
  2776. /// \endcode
  2777. PCIS_Never,
  2778. /// Bin-pack constructor initializers.
  2779. /// \code
  2780. /// Constructor()
  2781. /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
  2782. /// cccccccccccccccccccc()
  2783. /// \endcode
  2784. PCIS_BinPack,
  2785. /// Put all constructor initializers on the current line if they fit.
  2786. /// Otherwise, put each one on its own line.
  2787. /// \code
  2788. /// Constructor() : a(), b()
  2789. ///
  2790. /// Constructor()
  2791. /// : aaaaaaaaaaaaaaaaaaaa(),
  2792. /// bbbbbbbbbbbbbbbbbbbb(),
  2793. /// ddddddddddddd()
  2794. /// \endcode
  2795. PCIS_CurrentLine,
  2796. /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers
  2797. /// do not fit on the current line, try to fit them on the next line.
  2798. /// \code
  2799. /// Constructor() : a(), b()
  2800. ///
  2801. /// Constructor()
  2802. /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
  2803. ///
  2804. /// Constructor()
  2805. /// : aaaaaaaaaaaaaaaaaaaa(),
  2806. /// bbbbbbbbbbbbbbbbbbbb(),
  2807. /// cccccccccccccccccccc()
  2808. /// \endcode
  2809. PCIS_NextLine,
  2810. };
  2811. /// The pack constructor initializers style to use.
  2812. /// \version 14
  2813. PackConstructorInitializersStyle PackConstructorInitializers;
  2814. /// The penalty for breaking around an assignment operator.
  2815. /// \version 5
  2816. unsigned PenaltyBreakAssignment;
  2817. /// The penalty for breaking a function call after ``call(``.
  2818. /// \version 3.7
  2819. unsigned PenaltyBreakBeforeFirstCallParameter;
  2820. /// The penalty for each line break introduced inside a comment.
  2821. /// \version 3.7
  2822. unsigned PenaltyBreakComment;
  2823. /// The penalty for breaking before the first ``<<``.
  2824. /// \version 3.7
  2825. unsigned PenaltyBreakFirstLessLess;
  2826. /// The penalty for breaking after ``(``.
  2827. /// \version 14
  2828. unsigned PenaltyBreakOpenParenthesis;
  2829. /// The penalty for each line break introduced inside a string literal.
  2830. /// \version 3.7
  2831. unsigned PenaltyBreakString;
  2832. /// The penalty for breaking after template declaration.
  2833. /// \version 7
  2834. unsigned PenaltyBreakTemplateDeclaration;
  2835. /// The penalty for each character outside of the column limit.
  2836. /// \version 3.7
  2837. unsigned PenaltyExcessCharacter;
  2838. /// Penalty for each character of whitespace indentation
  2839. /// (counted relative to leading non-whitespace column).
  2840. /// \version 12
  2841. unsigned PenaltyIndentedWhitespace;
  2842. /// Penalty for putting the return type of a function onto its own line.
  2843. /// \version 3.7
  2844. unsigned PenaltyReturnTypeOnItsOwnLine;
  2845. /// The ``&``, ``&&`` and ``*`` alignment style.
  2846. enum PointerAlignmentStyle : int8_t {
  2847. /// Align pointer to the left.
  2848. /// \code
  2849. /// int* a;
  2850. /// \endcode
  2851. PAS_Left,
  2852. /// Align pointer to the right.
  2853. /// \code
  2854. /// int *a;
  2855. /// \endcode
  2856. PAS_Right,
  2857. /// Align pointer in the middle.
  2858. /// \code
  2859. /// int * a;
  2860. /// \endcode
  2861. PAS_Middle
  2862. };
  2863. /// Pointer and reference alignment style.
  2864. /// \version 3.7
  2865. PointerAlignmentStyle PointerAlignment;
  2866. /// The number of columns to use for indentation of preprocessor statements.
  2867. /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor
  2868. /// statements.
  2869. /// \code
  2870. /// PPIndentWidth: 1
  2871. ///
  2872. /// #ifdef __linux__
  2873. /// # define FOO
  2874. /// #else
  2875. /// # define BAR
  2876. /// #endif
  2877. /// \endcode
  2878. /// \version 13
  2879. int PPIndentWidth;
  2880. /// Different specifiers and qualifiers alignment styles.
  2881. enum QualifierAlignmentStyle : int8_t {
  2882. /// Don't change specifiers/qualifiers to either Left or Right alignment
  2883. /// (default).
  2884. /// \code
  2885. /// int const a;
  2886. /// const int *a;
  2887. /// \endcode
  2888. QAS_Leave,
  2889. /// Change specifiers/qualifiers to be left-aligned.
  2890. /// \code
  2891. /// const int a;
  2892. /// const int *a;
  2893. /// \endcode
  2894. QAS_Left,
  2895. /// Change specifiers/qualifiers to be right-aligned.
  2896. /// \code
  2897. /// int const a;
  2898. /// int const *a;
  2899. /// \endcode
  2900. QAS_Right,
  2901. /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
  2902. /// With:
  2903. /// \code{.yaml}
  2904. /// QualifierOrder: ['inline', 'static', 'type', 'const']
  2905. /// \endcode
  2906. ///
  2907. /// \code
  2908. ///
  2909. /// int const a;
  2910. /// int const *a;
  2911. /// \endcode
  2912. QAS_Custom
  2913. };
  2914. /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
  2915. /// \warning
  2916. /// Setting ``QualifierAlignment`` to something other than `Leave`, COULD
  2917. /// lead to incorrect code formatting due to incorrect decisions made due to
  2918. /// clang-formats lack of complete semantic information.
  2919. /// As such extra care should be taken to review code changes made by the use
  2920. /// of this option.
  2921. /// \endwarning
  2922. /// \version 14
  2923. QualifierAlignmentStyle QualifierAlignment;
  2924. /// The order in which the qualifiers appear.
  2925. /// Order is an array that can contain any of the following:
  2926. ///
  2927. /// * const
  2928. /// * inline
  2929. /// * static
  2930. /// * friend
  2931. /// * constexpr
  2932. /// * volatile
  2933. /// * restrict
  2934. /// * type
  2935. ///
  2936. /// Note: it MUST contain 'type'.
  2937. /// Items to the left of 'type' will be placed to the left of the type and
  2938. /// aligned in the order supplied. Items to the right of 'type' will be placed
  2939. /// to the right of the type and aligned in the order supplied.
  2940. ///
  2941. /// \code{.yaml}
  2942. /// QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
  2943. /// \endcode
  2944. /// \version 14
  2945. std::vector<std::string> QualifierOrder;
  2946. /// See documentation of ``RawStringFormats``.
  2947. struct RawStringFormat {
  2948. /// The language of this raw string.
  2949. LanguageKind Language;
  2950. /// A list of raw string delimiters that match this language.
  2951. std::vector<std::string> Delimiters;
  2952. /// A list of enclosing function names that match this language.
  2953. std::vector<std::string> EnclosingFunctions;
  2954. /// The canonical delimiter for this language.
  2955. std::string CanonicalDelimiter;
  2956. /// The style name on which this raw string format is based on.
  2957. /// If not specified, the raw string format is based on the style that this
  2958. /// format is based on.
  2959. std::string BasedOnStyle;
  2960. bool operator==(const RawStringFormat &Other) const {
  2961. return Language == Other.Language && Delimiters == Other.Delimiters &&
  2962. EnclosingFunctions == Other.EnclosingFunctions &&
  2963. CanonicalDelimiter == Other.CanonicalDelimiter &&
  2964. BasedOnStyle == Other.BasedOnStyle;
  2965. }
  2966. };
  2967. /// Defines hints for detecting supported languages code blocks in raw
  2968. /// strings.
  2969. ///
  2970. /// A raw string with a matching delimiter or a matching enclosing function
  2971. /// name will be reformatted assuming the specified language based on the
  2972. /// style for that language defined in the .clang-format file. If no style has
  2973. /// been defined in the .clang-format file for the specific language, a
  2974. /// predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
  2975. /// found, the formatting is based on llvm style. A matching delimiter takes
  2976. /// precedence over a matching enclosing function name for determining the
  2977. /// language of the raw string contents.
  2978. ///
  2979. /// If a canonical delimiter is specified, occurrences of other delimiters for
  2980. /// the same language will be updated to the canonical if possible.
  2981. ///
  2982. /// There should be at most one specification per language and each delimiter
  2983. /// and enclosing function should not occur in multiple specifications.
  2984. ///
  2985. /// To configure this in the .clang-format file, use:
  2986. /// \code{.yaml}
  2987. /// RawStringFormats:
  2988. /// - Language: TextProto
  2989. /// Delimiters:
  2990. /// - 'pb'
  2991. /// - 'proto'
  2992. /// EnclosingFunctions:
  2993. /// - 'PARSE_TEXT_PROTO'
  2994. /// BasedOnStyle: google
  2995. /// - Language: Cpp
  2996. /// Delimiters:
  2997. /// - 'cc'
  2998. /// - 'cpp'
  2999. /// BasedOnStyle: llvm
  3000. /// CanonicalDelimiter: 'cc'
  3001. /// \endcode
  3002. /// \version 6
  3003. std::vector<RawStringFormat> RawStringFormats;
  3004. /// \brief The ``&`` and ``&&`` alignment style.
  3005. enum ReferenceAlignmentStyle : int8_t {
  3006. /// Align reference like ``PointerAlignment``.
  3007. RAS_Pointer,
  3008. /// Align reference to the left.
  3009. /// \code
  3010. /// int& a;
  3011. /// \endcode
  3012. RAS_Left,
  3013. /// Align reference to the right.
  3014. /// \code
  3015. /// int &a;
  3016. /// \endcode
  3017. RAS_Right,
  3018. /// Align reference in the middle.
  3019. /// \code
  3020. /// int & a;
  3021. /// \endcode
  3022. RAS_Middle
  3023. };
  3024. /// \brief Reference alignment style (overrides ``PointerAlignment`` for
  3025. /// references).
  3026. /// \version 13
  3027. ReferenceAlignmentStyle ReferenceAlignment;
  3028. // clang-format off
  3029. /// If ``true``, clang-format will attempt to re-flow comments. That is it
  3030. /// will touch a comment and *reflow* long comments into new lines, trying to
  3031. /// obey the ``ColumnLimit``.
  3032. /// \code
  3033. /// false:
  3034. /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
  3035. /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
  3036. ///
  3037. /// true:
  3038. /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
  3039. /// // information
  3040. /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
  3041. /// * information */
  3042. /// \endcode
  3043. /// \version 3.8
  3044. bool ReflowComments;
  3045. // clang-format on
  3046. /// Remove optional braces of control statements (``if``, ``else``, ``for``,
  3047. /// and ``while``) in C++ according to the LLVM coding style.
  3048. /// \warning
  3049. /// This option will be renamed and expanded to support other styles.
  3050. /// \endwarning
  3051. /// \warning
  3052. /// Setting this option to `true` could lead to incorrect code formatting due
  3053. /// to clang-format's lack of complete semantic information. As such, extra
  3054. /// care should be taken to review code changes made by this option.
  3055. /// \endwarning
  3056. /// \code
  3057. /// false: true:
  3058. ///
  3059. /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
  3060. /// handleFunctionDecl(D); handleFunctionDecl(D);
  3061. /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
  3062. /// handleVarDecl(D); handleVarDecl(D);
  3063. /// }
  3064. ///
  3065. /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
  3066. /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
  3067. /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
  3068. /// handleAttr(A); handleAttr(A);
  3069. /// } }
  3070. /// }
  3071. /// }
  3072. ///
  3073. /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
  3074. /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
  3075. /// handleAttr(A); handleAttr(A);
  3076. /// }
  3077. /// }
  3078. ///
  3079. /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
  3080. /// if (shouldProcess(D)) { if (shouldProcess(D))
  3081. /// handleVarDecl(D); handleVarDecl(D);
  3082. /// } else { else
  3083. /// markAsIgnored(D); markAsIgnored(D);
  3084. /// } }
  3085. /// }
  3086. ///
  3087. /// if (a) { vs. if (a)
  3088. /// b(); b();
  3089. /// } else { else if (c)
  3090. /// if (c) { d();
  3091. /// d(); else
  3092. /// } else { e();
  3093. /// e();
  3094. /// }
  3095. /// }
  3096. /// \endcode
  3097. /// \version 14
  3098. bool RemoveBracesLLVM;
  3099. /// Remove semicolons after the closing brace of a non-empty function.
  3100. /// \warning
  3101. /// Setting this option to `true` could lead to incorrect code formatting due
  3102. /// to clang-format's lack of complete semantic information. As such, extra
  3103. /// care should be taken to review code changes made by this option.
  3104. /// \endwarning
  3105. /// \code
  3106. /// false: true:
  3107. ///
  3108. /// int max(int a, int b) { int max(int a, int b) {
  3109. /// return a > b ? a : b; return a > b ? a : b;
  3110. /// }; }
  3111. ///
  3112. /// \endcode
  3113. /// \version 16
  3114. bool RemoveSemicolon;
  3115. /// \brief The possible positions for the requires clause. The
  3116. /// ``IndentRequires`` option is only used if the ``requires`` is put on the
  3117. /// start of a line.
  3118. enum RequiresClausePositionStyle : int8_t {
  3119. /// Always put the ``requires`` clause on its own line.
  3120. /// \code
  3121. /// template <typename T>
  3122. /// requires C<T>
  3123. /// struct Foo {...
  3124. ///
  3125. /// template <typename T>
  3126. /// requires C<T>
  3127. /// void bar(T t) {...
  3128. ///
  3129. /// template <typename T>
  3130. /// void baz(T t)
  3131. /// requires C<T>
  3132. /// {...
  3133. /// \endcode
  3134. RCPS_OwnLine,
  3135. /// Try to put the clause together with the preceding part of a declaration.
  3136. /// For class templates: stick to the template declaration.
  3137. /// For function templates: stick to the template declaration.
  3138. /// For function declaration followed by a requires clause: stick to the
  3139. /// parameter list.
  3140. /// \code
  3141. /// template <typename T> requires C<T>
  3142. /// struct Foo {...
  3143. ///
  3144. /// template <typename T> requires C<T>
  3145. /// void bar(T t) {...
  3146. ///
  3147. /// template <typename T>
  3148. /// void baz(T t) requires C<T>
  3149. /// {...
  3150. /// \endcode
  3151. RCPS_WithPreceding,
  3152. /// Try to put the ``requires`` clause together with the class or function
  3153. /// declaration.
  3154. /// \code
  3155. /// template <typename T>
  3156. /// requires C<T> struct Foo {...
  3157. ///
  3158. /// template <typename T>
  3159. /// requires C<T> void bar(T t) {...
  3160. ///
  3161. /// template <typename T>
  3162. /// void baz(T t)
  3163. /// requires C<T> {...
  3164. /// \endcode
  3165. RCPS_WithFollowing,
  3166. /// Try to put everything in the same line if possible. Otherwise normal
  3167. /// line breaking rules take over.
  3168. /// \code
  3169. /// // Fitting:
  3170. /// template <typename T> requires C<T> struct Foo {...
  3171. ///
  3172. /// template <typename T> requires C<T> void bar(T t) {...
  3173. ///
  3174. /// template <typename T> void bar(T t) requires C<T> {...
  3175. ///
  3176. /// // Not fitting, one possible example:
  3177. /// template <typename LongName>
  3178. /// requires C<LongName>
  3179. /// struct Foo {...
  3180. ///
  3181. /// template <typename LongName>
  3182. /// requires C<LongName>
  3183. /// void bar(LongName ln) {
  3184. ///
  3185. /// template <typename LongName>
  3186. /// void bar(LongName ln)
  3187. /// requires C<LongName> {
  3188. /// \endcode
  3189. RCPS_SingleLine,
  3190. };
  3191. /// \brief The position of the ``requires`` clause.
  3192. /// \version 15
  3193. RequiresClausePositionStyle RequiresClausePosition;
  3194. /// Indentation logic for requires expression bodies.
  3195. enum RequiresExpressionIndentationKind : int8_t {
  3196. /// Align requires expression body relative to the indentation level of the
  3197. /// outer scope the requires expression resides in.
  3198. /// This is the default.
  3199. /// \code
  3200. /// template <typename T>
  3201. /// concept C = requires(T t) {
  3202. /// ...
  3203. /// }
  3204. /// \endcode
  3205. REI_OuterScope,
  3206. /// Align requires expression body relative to the `requires` keyword.
  3207. /// \code
  3208. /// template <typename T>
  3209. /// concept C = requires(T t) {
  3210. /// ...
  3211. /// }
  3212. /// \endcode
  3213. REI_Keyword,
  3214. };
  3215. /// The indentation used for requires expression bodies.
  3216. /// \version 16
  3217. RequiresExpressionIndentationKind RequiresExpressionIndentation;
  3218. /// \brief The style if definition blocks should be separated.
  3219. enum SeparateDefinitionStyle : int8_t {
  3220. /// Leave definition blocks as they are.
  3221. SDS_Leave,
  3222. /// Insert an empty line between definition blocks.
  3223. SDS_Always,
  3224. /// Remove any empty line between definition blocks.
  3225. SDS_Never
  3226. };
  3227. /// Specifies the use of empty lines to separate definition blocks, including
  3228. /// classes, structs, enums, and functions.
  3229. /// \code
  3230. /// Never v.s. Always
  3231. /// #include <cstring> #include <cstring>
  3232. /// struct Foo {
  3233. /// int a, b, c; struct Foo {
  3234. /// }; int a, b, c;
  3235. /// namespace Ns { };
  3236. /// class Bar {
  3237. /// public: namespace Ns {
  3238. /// struct Foobar { class Bar {
  3239. /// int a; public:
  3240. /// int b; struct Foobar {
  3241. /// }; int a;
  3242. /// private: int b;
  3243. /// int t; };
  3244. /// int method1() {
  3245. /// // ... private:
  3246. /// } int t;
  3247. /// enum List {
  3248. /// ITEM1, int method1() {
  3249. /// ITEM2 // ...
  3250. /// }; }
  3251. /// template<typename T>
  3252. /// int method2(T x) { enum List {
  3253. /// // ... ITEM1,
  3254. /// } ITEM2
  3255. /// int i, j, k; };
  3256. /// int method3(int par) {
  3257. /// // ... template<typename T>
  3258. /// } int method2(T x) {
  3259. /// }; // ...
  3260. /// class C {}; }
  3261. /// }
  3262. /// int i, j, k;
  3263. ///
  3264. /// int method3(int par) {
  3265. /// // ...
  3266. /// }
  3267. /// };
  3268. ///
  3269. /// class C {};
  3270. /// }
  3271. /// \endcode
  3272. /// \version 14
  3273. SeparateDefinitionStyle SeparateDefinitionBlocks;
  3274. /// The maximal number of unwrapped lines that a short namespace spans.
  3275. /// Defaults to 1.
  3276. ///
  3277. /// This determines the maximum length of short namespaces by counting
  3278. /// unwrapped lines (i.e. containing neither opening nor closing
  3279. /// namespace brace) and makes "FixNamespaceComments" omit adding
  3280. /// end comments for those.
  3281. /// \code
  3282. /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
  3283. /// namespace a { namespace a {
  3284. /// int foo; int foo;
  3285. /// } } // namespace a
  3286. ///
  3287. /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
  3288. /// namespace b { namespace b {
  3289. /// int foo; int foo;
  3290. /// int bar; int bar;
  3291. /// } // namespace b } // namespace b
  3292. /// \endcode
  3293. /// \version 13
  3294. unsigned ShortNamespaceLines;
  3295. /// Include sorting options.
  3296. enum SortIncludesOptions : int8_t {
  3297. /// Includes are never sorted.
  3298. /// \code
  3299. /// #include "B/A.h"
  3300. /// #include "A/B.h"
  3301. /// #include "a/b.h"
  3302. /// #include "A/b.h"
  3303. /// #include "B/a.h"
  3304. /// \endcode
  3305. SI_Never,
  3306. /// Includes are sorted in an ASCIIbetical or case sensitive fashion.
  3307. /// \code
  3308. /// #include "A/B.h"
  3309. /// #include "A/b.h"
  3310. /// #include "B/A.h"
  3311. /// #include "B/a.h"
  3312. /// #include "a/b.h"
  3313. /// \endcode
  3314. SI_CaseSensitive,
  3315. /// Includes are sorted in an alphabetical or case insensitive fashion.
  3316. /// \code
  3317. /// #include "A/B.h"
  3318. /// #include "A/b.h"
  3319. /// #include "a/b.h"
  3320. /// #include "B/A.h"
  3321. /// #include "B/a.h"
  3322. /// \endcode
  3323. SI_CaseInsensitive,
  3324. };
  3325. /// Controls if and how clang-format will sort ``#includes``.
  3326. /// If ``Never``, includes are never sorted.
  3327. /// If ``CaseInsensitive``, includes are sorted in an ASCIIbetical or case
  3328. /// insensitive fashion.
  3329. /// If ``CaseSensitive``, includes are sorted in an alphabetical or case
  3330. /// sensitive fashion.
  3331. /// \version 3.8
  3332. SortIncludesOptions SortIncludes;
  3333. /// Position for Java Static imports.
  3334. enum SortJavaStaticImportOptions : int8_t {
  3335. /// Static imports are placed before non-static imports.
  3336. /// \code{.java}
  3337. /// import static org.example.function1;
  3338. ///
  3339. /// import org.example.ClassA;
  3340. /// \endcode
  3341. SJSIO_Before,
  3342. /// Static imports are placed after non-static imports.
  3343. /// \code{.java}
  3344. /// import org.example.ClassA;
  3345. ///
  3346. /// import static org.example.function1;
  3347. /// \endcode
  3348. SJSIO_After,
  3349. };
  3350. /// When sorting Java imports, by default static imports are placed before
  3351. /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
  3352. /// static imports are placed after non-static imports.
  3353. /// \version 12
  3354. SortJavaStaticImportOptions SortJavaStaticImport;
  3355. /// Using declaration sorting options.
  3356. enum SortUsingDeclarationsOptions : int8_t {
  3357. /// Using declarations are never sorted.
  3358. /// \code
  3359. /// using std::chrono::duration_cast;
  3360. /// using std::move;
  3361. /// using boost::regex;
  3362. /// using boost::regex_constants::icase;
  3363. /// using std::string;
  3364. /// \endcode
  3365. SUD_Never,
  3366. /// Using declarations are sorted in the order defined as follows:
  3367. /// Split the strings by "::" and discard any initial empty strings. Sort
  3368. /// the lists of names lexicographically, and within those groups, names are
  3369. /// in case-insensitive lexicographic order.
  3370. /// \code
  3371. /// using boost::regex;
  3372. /// using boost::regex_constants::icase;
  3373. /// using std::chrono::duration_cast;
  3374. /// using std::move;
  3375. /// using std::string;
  3376. /// \endcode
  3377. SUD_Lexicographic,
  3378. /// Using declarations are sorted in the order defined as follows:
  3379. /// Split the strings by "::" and discard any initial empty strings. The
  3380. /// last element of each list is a non-namespace name; all others are
  3381. /// namespace names. Sort the lists of names lexicographically, where the
  3382. /// sort order of individual names is that all non-namespace names come
  3383. /// before all namespace names, and within those groups, names are in
  3384. /// case-insensitive lexicographic order.
  3385. /// \code
  3386. /// using boost::regex;
  3387. /// using boost::regex_constants::icase;
  3388. /// using std::move;
  3389. /// using std::string;
  3390. /// using std::chrono::duration_cast;
  3391. /// \endcode
  3392. SUD_LexicographicNumeric,
  3393. };
  3394. /// Controls if and how clang-format will sort using declarations.
  3395. /// \version 5
  3396. SortUsingDeclarationsOptions SortUsingDeclarations;
  3397. /// If ``true``, a space is inserted after C style casts.
  3398. /// \code
  3399. /// true: false:
  3400. /// (int) i; vs. (int)i;
  3401. /// \endcode
  3402. /// \version 3.5
  3403. bool SpaceAfterCStyleCast;
  3404. /// If ``true``, a space is inserted after the logical not operator (``!``).
  3405. /// \code
  3406. /// true: false:
  3407. /// ! someExpression(); vs. !someExpression();
  3408. /// \endcode
  3409. /// \version 9
  3410. bool SpaceAfterLogicalNot;
  3411. /// If \c true, a space will be inserted after the 'template' keyword.
  3412. /// \code
  3413. /// true: false:
  3414. /// template <int> void foo(); vs. template<int> void foo();
  3415. /// \endcode
  3416. /// \version 4
  3417. bool SpaceAfterTemplateKeyword;
  3418. /// Different ways to put a space before opening parentheses.
  3419. enum SpaceAroundPointerQualifiersStyle : int8_t {
  3420. /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
  3421. /// instead.
  3422. /// \code
  3423. /// PointerAlignment: Left PointerAlignment: Right
  3424. /// void* const* x = NULL; vs. void *const *x = NULL;
  3425. /// \endcode
  3426. SAPQ_Default,
  3427. /// Ensure that there is a space before pointer qualifiers.
  3428. /// \code
  3429. /// PointerAlignment: Left PointerAlignment: Right
  3430. /// void* const* x = NULL; vs. void * const *x = NULL;
  3431. /// \endcode
  3432. SAPQ_Before,
  3433. /// Ensure that there is a space after pointer qualifiers.
  3434. /// \code
  3435. /// PointerAlignment: Left PointerAlignment: Right
  3436. /// void* const * x = NULL; vs. void *const *x = NULL;
  3437. /// \endcode
  3438. SAPQ_After,
  3439. /// Ensure that there is a space both before and after pointer qualifiers.
  3440. /// \code
  3441. /// PointerAlignment: Left PointerAlignment: Right
  3442. /// void* const * x = NULL; vs. void * const *x = NULL;
  3443. /// \endcode
  3444. SAPQ_Both,
  3445. };
  3446. /// Defines in which cases to put a space before or after pointer qualifiers
  3447. /// \version 12
  3448. SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers;
  3449. /// If ``false``, spaces will be removed before assignment operators.
  3450. /// \code
  3451. /// true: false:
  3452. /// int a = 5; vs. int a= 5;
  3453. /// a += 42; a+= 42;
  3454. /// \endcode
  3455. /// \version 3.7
  3456. bool SpaceBeforeAssignmentOperators;
  3457. /// If ``false``, spaces will be removed before case colon.
  3458. /// \code
  3459. /// true: false
  3460. /// switch (x) { vs. switch (x) {
  3461. /// case 1 : break; case 1: break;
  3462. /// } }
  3463. /// \endcode
  3464. /// \version 12
  3465. bool SpaceBeforeCaseColon;
  3466. /// If ``true``, a space will be inserted before a C++11 braced list
  3467. /// used to initialize an object (after the preceding identifier or type).
  3468. /// \code
  3469. /// true: false:
  3470. /// Foo foo { bar }; vs. Foo foo{ bar };
  3471. /// Foo {}; Foo{};
  3472. /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
  3473. /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
  3474. /// \endcode
  3475. /// \version 7
  3476. bool SpaceBeforeCpp11BracedList;
  3477. /// If ``false``, spaces will be removed before constructor initializer
  3478. /// colon.
  3479. /// \code
  3480. /// true: false:
  3481. /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
  3482. /// \endcode
  3483. /// \version 7
  3484. bool SpaceBeforeCtorInitializerColon;
  3485. /// If ``false``, spaces will be removed before inheritance colon.
  3486. /// \code
  3487. /// true: false:
  3488. /// class Foo : Bar {} vs. class Foo: Bar {}
  3489. /// \endcode
  3490. /// \version 7
  3491. bool SpaceBeforeInheritanceColon;
  3492. /// Different ways to put a space before opening parentheses.
  3493. enum SpaceBeforeParensStyle : int8_t {
  3494. /// Never put a space before opening parentheses.
  3495. /// \code
  3496. /// void f() {
  3497. /// if(true) {
  3498. /// f();
  3499. /// }
  3500. /// }
  3501. /// \endcode
  3502. SBPO_Never,
  3503. /// Put a space before opening parentheses only after control statement
  3504. /// keywords (``for/if/while...``).
  3505. /// \code
  3506. /// void f() {
  3507. /// if (true) {
  3508. /// f();
  3509. /// }
  3510. /// }
  3511. /// \endcode
  3512. SBPO_ControlStatements,
  3513. /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
  3514. /// ForEach and If macros. This is useful in projects where ForEach/If
  3515. /// macros are treated as function calls instead of control statements.
  3516. /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
  3517. /// backward compatibility.
  3518. /// \code
  3519. /// void f() {
  3520. /// Q_FOREACH(...) {
  3521. /// f();
  3522. /// }
  3523. /// }
  3524. /// \endcode
  3525. SBPO_ControlStatementsExceptControlMacros,
  3526. /// Put a space before opening parentheses only if the parentheses are not
  3527. /// empty i.e. '()'
  3528. /// \code
  3529. /// void() {
  3530. /// if (true) {
  3531. /// f();
  3532. /// g (x, y, z);
  3533. /// }
  3534. /// }
  3535. /// \endcode
  3536. SBPO_NonEmptyParentheses,
  3537. /// Always put a space before opening parentheses, except when it's
  3538. /// prohibited by the syntax rules (in function-like macro definitions) or
  3539. /// when determined by other style rules (after unary operators, opening
  3540. /// parentheses, etc.)
  3541. /// \code
  3542. /// void f () {
  3543. /// if (true) {
  3544. /// f ();
  3545. /// }
  3546. /// }
  3547. /// \endcode
  3548. SBPO_Always,
  3549. /// Configure each individual space before parentheses in
  3550. /// `SpaceBeforeParensOptions`.
  3551. SBPO_Custom,
  3552. };
  3553. /// Defines in which cases to put a space before opening parentheses.
  3554. /// \version 3.5
  3555. SpaceBeforeParensStyle SpaceBeforeParens;
  3556. /// Precise control over the spacing before parentheses.
  3557. /// \code
  3558. /// # Should be declared this way:
  3559. /// SpaceBeforeParens: Custom
  3560. /// SpaceBeforeParensOptions:
  3561. /// AfterControlStatements: true
  3562. /// AfterFunctionDefinitionName: true
  3563. /// \endcode
  3564. struct SpaceBeforeParensCustom {
  3565. /// If ``true``, put space betwee control statement keywords
  3566. /// (for/if/while...) and opening parentheses.
  3567. /// \code
  3568. /// true: false:
  3569. /// if (...) {} vs. if(...) {}
  3570. /// \endcode
  3571. bool AfterControlStatements;
  3572. /// If ``true``, put space between foreach macros and opening parentheses.
  3573. /// \code
  3574. /// true: false:
  3575. /// FOREACH (...) vs. FOREACH(...)
  3576. /// <loop-body> <loop-body>
  3577. /// \endcode
  3578. bool AfterForeachMacros;
  3579. /// If ``true``, put a space between function declaration name and opening
  3580. /// parentheses.
  3581. /// \code
  3582. /// true: false:
  3583. /// void f (); vs. void f();
  3584. /// \endcode
  3585. bool AfterFunctionDeclarationName;
  3586. /// If ``true``, put a space between function definition name and opening
  3587. /// parentheses.
  3588. /// \code
  3589. /// true: false:
  3590. /// void f () {} vs. void f() {}
  3591. /// \endcode
  3592. bool AfterFunctionDefinitionName;
  3593. /// If ``true``, put space between lambda capture list and and opening parentheses.
  3594. /// \code
  3595. /// true: false:
  3596. /// auto foo = [] () {}; vs. auto foo = []() {};
  3597. /// \endcode
  3598. bool AfterLambdaCaptureList;
  3599. /// If ``true``, put space between if macros and opening parentheses.
  3600. /// \code
  3601. /// true: false:
  3602. /// IF (...) vs. IF(...)
  3603. /// <conditional-body> <conditional-body>
  3604. /// \endcode
  3605. bool AfterIfMacros;
  3606. /// If ``true``, put a space between operator overloading and opening
  3607. /// parentheses.
  3608. /// \code
  3609. /// true: false:
  3610. /// void operator++ (int a); vs. void operator++(int a);
  3611. /// object.operator++ (10); object.operator++(10);
  3612. /// \endcode
  3613. bool AfterOverloadedOperator;
  3614. /// If ``true``, put space between requires keyword in a requires clause and
  3615. /// opening parentheses, if there is one.
  3616. /// \code
  3617. /// true: false:
  3618. /// template<typename T> vs. template<typename T>
  3619. /// requires (A<T> && B<T>) requires(A<T> && B<T>)
  3620. /// ... ...
  3621. /// \endcode
  3622. bool AfterRequiresInClause;
  3623. /// If ``true``, put space between requires keyword in a requires expression
  3624. /// and opening parentheses.
  3625. /// \code
  3626. /// true: false:
  3627. /// template<typename T> vs. template<typename T>
  3628. /// concept C = requires (T t) { concept C = requires(T t) {
  3629. /// ... ...
  3630. /// } }
  3631. /// \endcode
  3632. bool AfterRequiresInExpression;
  3633. /// If ``true``, put a space before opening parentheses only if the
  3634. /// parentheses are not empty.
  3635. /// \code
  3636. /// true: false:
  3637. /// void f (int a); vs. void f();
  3638. /// f (a); f();
  3639. /// \endcode
  3640. bool BeforeNonEmptyParentheses;
  3641. SpaceBeforeParensCustom()
  3642. : AfterControlStatements(false), AfterForeachMacros(false),
  3643. AfterFunctionDeclarationName(false),
  3644. AfterFunctionDefinitionName(false), AfterLambdaCaptureList(false), AfterIfMacros(false),
  3645. AfterOverloadedOperator(false), AfterRequiresInClause(false),
  3646. AfterRequiresInExpression(false), BeforeNonEmptyParentheses(false) {}
  3647. bool operator==(const SpaceBeforeParensCustom &Other) const {
  3648. return AfterControlStatements == Other.AfterControlStatements &&
  3649. AfterForeachMacros == Other.AfterForeachMacros &&
  3650. AfterFunctionDeclarationName ==
  3651. Other.AfterFunctionDeclarationName &&
  3652. AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
  3653. AfterLambdaCaptureList == Other.AfterLambdaCaptureList &&
  3654. AfterIfMacros == Other.AfterIfMacros &&
  3655. AfterOverloadedOperator == Other.AfterOverloadedOperator &&
  3656. AfterRequiresInClause == Other.AfterRequiresInClause &&
  3657. AfterRequiresInExpression == Other.AfterRequiresInExpression &&
  3658. BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
  3659. }
  3660. };
  3661. /// Control of individual space before parentheses.
  3662. ///
  3663. /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
  3664. /// how each individual space before parentheses case should be handled.
  3665. /// Otherwise, this is ignored.
  3666. /// \code{.yaml}
  3667. /// # Example of usage:
  3668. /// SpaceBeforeParens: Custom
  3669. /// SpaceBeforeParensOptions:
  3670. /// AfterControlStatements: true
  3671. /// AfterFunctionDefinitionName: true
  3672. /// \endcode
  3673. /// \version 14
  3674. SpaceBeforeParensCustom SpaceBeforeParensOptions;
  3675. /// If ``true``, spaces will be before ``[``.
  3676. /// Lambdas will not be affected. Only the first ``[`` will get a space added.
  3677. /// \code
  3678. /// true: false:
  3679. /// int a [5]; vs. int a[5];
  3680. /// int a [5][5]; vs. int a[5][5];
  3681. /// \endcode
  3682. /// \version 10
  3683. bool SpaceBeforeSquareBrackets;
  3684. /// If ``false``, spaces will be removed before range-based for loop
  3685. /// colon.
  3686. /// \code
  3687. /// true: false:
  3688. /// for (auto v : values) {} vs. for(auto v: values) {}
  3689. /// \endcode
  3690. /// \version 7
  3691. bool SpaceBeforeRangeBasedForLoopColon;
  3692. /// If ``true``, spaces will be inserted into ``{}``.
  3693. /// \code
  3694. /// true: false:
  3695. /// void f() { } vs. void f() {}
  3696. /// while (true) { } while (true) {}
  3697. /// \endcode
  3698. /// \version 10
  3699. bool SpaceInEmptyBlock;
  3700. /// If ``true``, spaces may be inserted into ``()``.
  3701. /// \code
  3702. /// true: false:
  3703. /// void f( ) { vs. void f() {
  3704. /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
  3705. /// if (true) { if (true) {
  3706. /// f( ); f();
  3707. /// } }
  3708. /// } }
  3709. /// \endcode
  3710. /// \version 3.7
  3711. bool SpaceInEmptyParentheses;
  3712. /// The number of spaces before trailing line comments
  3713. /// (``//`` - comments).
  3714. ///
  3715. /// This does not affect trailing block comments (``/*`` - comments) as
  3716. /// those commonly have different usage patterns and a number of special
  3717. /// cases.
  3718. /// \code
  3719. /// SpacesBeforeTrailingComments: 3
  3720. /// void f() {
  3721. /// if (true) { // foo1
  3722. /// f(); // bar
  3723. /// } // foo
  3724. /// }
  3725. /// \endcode
  3726. /// \version 3.7
  3727. unsigned SpacesBeforeTrailingComments;
  3728. /// Styles for adding spacing after ``<`` and before ``>`
  3729. /// in template argument lists.
  3730. enum SpacesInAnglesStyle : int8_t {
  3731. /// Remove spaces after ``<`` and before ``>``.
  3732. /// \code
  3733. /// static_cast<int>(arg);
  3734. /// std::function<void(int)> fct;
  3735. /// \endcode
  3736. SIAS_Never,
  3737. /// Add spaces after ``<`` and before ``>``.
  3738. /// \code
  3739. /// static_cast< int >(arg);
  3740. /// std::function< void(int) > fct;
  3741. /// \endcode
  3742. SIAS_Always,
  3743. /// Keep a single space after ``<`` and before ``>`` if any spaces were
  3744. /// present. Option ``Standard: Cpp03`` takes precedence.
  3745. SIAS_Leave
  3746. };
  3747. /// The SpacesInAnglesStyle to use for template argument lists.
  3748. /// \version 3.4
  3749. SpacesInAnglesStyle SpacesInAngles;
  3750. /// If ``true``, spaces will be inserted around if/for/switch/while
  3751. /// conditions.
  3752. /// \code
  3753. /// true: false:
  3754. /// if ( a ) { ... } vs. if (a) { ... }
  3755. /// while ( i < 5 ) { ... } while (i < 5) { ... }
  3756. /// \endcode
  3757. /// \version 10
  3758. bool SpacesInConditionalStatement;
  3759. /// If ``true``, spaces are inserted inside container literals (e.g.
  3760. /// ObjC and Javascript array and dict literals).
  3761. /// \code{.js}
  3762. /// true: false:
  3763. /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
  3764. /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
  3765. /// \endcode
  3766. /// \version 3.7
  3767. bool SpacesInContainerLiterals;
  3768. /// If ``true``, spaces may be inserted into C style casts.
  3769. /// \code
  3770. /// true: false:
  3771. /// x = ( int32 )y vs. x = (int32)y
  3772. /// \endcode
  3773. /// \version 3.7
  3774. bool SpacesInCStyleCastParentheses;
  3775. /// Control of spaces within a single line comment.
  3776. struct SpacesInLineComment {
  3777. /// The minimum number of spaces at the start of the comment.
  3778. unsigned Minimum;
  3779. /// The maximum number of spaces at the start of the comment.
  3780. unsigned Maximum;
  3781. };
  3782. /// How many spaces are allowed at the start of a line comment. To disable the
  3783. /// maximum set it to ``-1``, apart from that the maximum takes precedence
  3784. /// over the minimum.
  3785. /// \code
  3786. /// Minimum = 1
  3787. /// Maximum = -1
  3788. /// // One space is forced
  3789. ///
  3790. /// // but more spaces are possible
  3791. ///
  3792. /// Minimum = 0
  3793. /// Maximum = 0
  3794. /// //Forces to start every comment directly after the slashes
  3795. /// \endcode
  3796. ///
  3797. /// Note that in line comment sections the relative indent of the subsequent
  3798. /// lines is kept, that means the following:
  3799. /// \code
  3800. /// before: after:
  3801. /// Minimum: 1
  3802. /// //if (b) { // if (b) {
  3803. /// // return true; // return true;
  3804. /// //} // }
  3805. ///
  3806. /// Maximum: 0
  3807. /// /// List: ///List:
  3808. /// /// - Foo /// - Foo
  3809. /// /// - Bar /// - Bar
  3810. /// \endcode
  3811. ///
  3812. /// This option has only effect if ``ReflowComments`` is set to ``true``.
  3813. /// \version 13
  3814. SpacesInLineComment SpacesInLineCommentPrefix;
  3815. /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
  3816. /// \code
  3817. /// true: false:
  3818. /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
  3819. /// \endcode
  3820. /// \version 3.7
  3821. bool SpacesInParentheses;
  3822. /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
  3823. /// Lambdas without arguments or unspecified size array declarations will not
  3824. /// be affected.
  3825. /// \code
  3826. /// true: false:
  3827. /// int a[ 5 ]; vs. int a[5];
  3828. /// std::unique_ptr<int[]> foo() {} // Won't be affected
  3829. /// \endcode
  3830. /// \version 3.7
  3831. bool SpacesInSquareBrackets;
  3832. /// Supported language standards for parsing and formatting C++ constructs.
  3833. /// \code
  3834. /// Latest: vector<set<int>>
  3835. /// c++03 vs. vector<set<int> >
  3836. /// \endcode
  3837. ///
  3838. /// The correct way to spell a specific language version is e.g. ``c++11``.
  3839. /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
  3840. enum LanguageStandard : int8_t {
  3841. /// Parse and format as C++03.
  3842. /// ``Cpp03`` is a deprecated alias for ``c++03``
  3843. LS_Cpp03, // c++03
  3844. /// Parse and format as C++11.
  3845. LS_Cpp11, // c++11
  3846. /// Parse and format as C++14.
  3847. LS_Cpp14, // c++14
  3848. /// Parse and format as C++17.
  3849. LS_Cpp17, // c++17
  3850. /// Parse and format as C++20.
  3851. LS_Cpp20, // c++20
  3852. /// Parse and format using the latest supported language version.
  3853. /// ``Cpp11`` is a deprecated alias for ``Latest``
  3854. LS_Latest,
  3855. /// Automatic detection based on the input.
  3856. LS_Auto,
  3857. };
  3858. /// Parse and format C++ constructs compatible with this standard.
  3859. /// \code
  3860. /// c++03: latest:
  3861. /// vector<set<int> > x; vs. vector<set<int>> x;
  3862. /// \endcode
  3863. /// \version 3.7
  3864. LanguageStandard Standard;
  3865. /// Macros which are ignored in front of a statement, as if they were an
  3866. /// attribute. So that they are not parsed as identifier, for example for Qts
  3867. /// emit.
  3868. /// \code
  3869. /// AlignConsecutiveDeclarations: true
  3870. /// StatementAttributeLikeMacros: []
  3871. /// unsigned char data = 'x';
  3872. /// emit signal(data); // This is parsed as variable declaration.
  3873. ///
  3874. /// AlignConsecutiveDeclarations: true
  3875. /// StatementAttributeLikeMacros: [emit]
  3876. /// unsigned char data = 'x';
  3877. /// emit signal(data); // Now it's fine again.
  3878. /// \endcode
  3879. /// \version 12
  3880. std::vector<std::string> StatementAttributeLikeMacros;
  3881. /// A vector of macros that should be interpreted as complete
  3882. /// statements.
  3883. ///
  3884. /// Typical macros are expressions, and require a semi-colon to be
  3885. /// added; sometimes this is not the case, and this allows to make
  3886. /// clang-format aware of such cases.
  3887. ///
  3888. /// For example: Q_UNUSED
  3889. /// \version 8
  3890. std::vector<std::string> StatementMacros;
  3891. /// The number of columns used for tab stops.
  3892. /// \version 3.7
  3893. unsigned TabWidth;
  3894. /// \brief A vector of macros that should be interpreted as type declarations
  3895. /// instead of as function calls.
  3896. ///
  3897. /// These are expected to be macros of the form:
  3898. /// \code
  3899. /// STACK_OF(...)
  3900. /// \endcode
  3901. ///
  3902. /// In the .clang-format configuration file, this can be configured like:
  3903. /// \code{.yaml}
  3904. /// TypenameMacros: ['STACK_OF', 'LIST']
  3905. /// \endcode
  3906. ///
  3907. /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
  3908. /// \version 9
  3909. std::vector<std::string> TypenameMacros;
  3910. /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
  3911. /// \version 10
  3912. // bool UseCRLF;
  3913. /// Different ways to use tab in formatting.
  3914. enum UseTabStyle : int8_t {
  3915. /// Never use tab.
  3916. UT_Never,
  3917. /// Use tabs only for indentation.
  3918. UT_ForIndentation,
  3919. /// Fill all leading whitespace with tabs, and use spaces for alignment that
  3920. /// appears within a line (e.g. consecutive assignments and declarations).
  3921. UT_ForContinuationAndIndentation,
  3922. /// Use tabs for line continuation and indentation, and spaces for
  3923. /// alignment.
  3924. UT_AlignWithSpaces,
  3925. /// Use tabs whenever we need to fill whitespace that spans at least from
  3926. /// one tab stop to the next one.
  3927. UT_Always
  3928. };
  3929. /// The way to use tab characters in the resulting file.
  3930. /// \version 3.7
  3931. UseTabStyle UseTab;
  3932. /// A vector of macros which are whitespace-sensitive and should not
  3933. /// be touched.
  3934. ///
  3935. /// These are expected to be macros of the form:
  3936. /// \code
  3937. /// STRINGIZE(...)
  3938. /// \endcode
  3939. ///
  3940. /// In the .clang-format configuration file, this can be configured like:
  3941. /// \code{.yaml}
  3942. /// WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
  3943. /// \endcode
  3944. ///
  3945. /// For example: BOOST_PP_STRINGIZE
  3946. /// \version 11
  3947. std::vector<std::string> WhitespaceSensitiveMacros;
  3948. /// If ``true``, continuation indents do not depend on the previous line.
  3949. bool ContextIndependentContinuationIndent;
  3950. /// If ``true``, lambda capture lists may be split over multiple lines.
  3951. bool AllowMultilineLambdaCaptureList;
  3952. bool operator==(const FormatStyle &R) const {
  3953. return AccessModifierOffset == R.AccessModifierOffset &&
  3954. AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
  3955. AlignArrayOfStructures == R.AlignArrayOfStructures &&
  3956. AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
  3957. AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
  3958. AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
  3959. AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
  3960. AlignEscapedNewlines == R.AlignEscapedNewlines &&
  3961. AlignOperands == R.AlignOperands &&
  3962. AlignTrailingComments == R.AlignTrailingComments &&
  3963. AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
  3964. AllowAllParametersOfDeclarationOnNextLine ==
  3965. R.AllowAllParametersOfDeclarationOnNextLine &&
  3966. AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
  3967. AllowShortCaseLabelsOnASingleLine ==
  3968. R.AllowShortCaseLabelsOnASingleLine &&
  3969. AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
  3970. AllowShortFunctionsOnASingleLine ==
  3971. R.AllowShortFunctionsOnASingleLine &&
  3972. AllowShortIfStatementsOnASingleLine ==
  3973. R.AllowShortIfStatementsOnASingleLine &&
  3974. AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
  3975. AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
  3976. AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
  3977. AlwaysBreakBeforeMultilineStrings ==
  3978. R.AlwaysBreakBeforeMultilineStrings &&
  3979. AlwaysBreakTemplateDeclarations ==
  3980. R.AlwaysBreakTemplateDeclarations &&
  3981. AttributeMacros == R.AttributeMacros &&
  3982. BinPackArguments == R.BinPackArguments &&
  3983. BinPackParameters == R.BinPackParameters &&
  3984. BitFieldColonSpacing == R.BitFieldColonSpacing &&
  3985. BreakAfterAttributes == R.BreakAfterAttributes &&
  3986. BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
  3987. BreakArrays == R.BreakArrays &&
  3988. BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
  3989. BreakBeforeBraces == R.BreakBeforeBraces &&
  3990. BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
  3991. BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
  3992. BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
  3993. BreakConstructorInitializers == R.BreakConstructorInitializers &&
  3994. BreakInheritanceList == R.BreakInheritanceList &&
  3995. BreakStringLiterals == R.BreakStringLiterals &&
  3996. ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
  3997. CompactNamespaces == R.CompactNamespaces &&
  3998. ConstructorInitializerIndentWidth ==
  3999. R.ConstructorInitializerIndentWidth &&
  4000. ContinuationIndentWidth == R.ContinuationIndentWidth &&
  4001. Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
  4002. DerivePointerAlignment == R.DerivePointerAlignment &&
  4003. DisableFormat == R.DisableFormat &&
  4004. EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
  4005. EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
  4006. ExperimentalAutoDetectBinPacking ==
  4007. R.ExperimentalAutoDetectBinPacking &&
  4008. FixNamespaceComments == R.FixNamespaceComments &&
  4009. ForEachMacros == R.ForEachMacros &&
  4010. IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
  4011. IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
  4012. IncludeStyle.IncludeIsMainRegex ==
  4013. R.IncludeStyle.IncludeIsMainRegex &&
  4014. IncludeStyle.IncludeIsMainSourceRegex ==
  4015. R.IncludeStyle.IncludeIsMainSourceRegex &&
  4016. IndentAccessModifiers == R.IndentAccessModifiers &&
  4017. IndentCaseBlocks == R.IndentCaseBlocks &&
  4018. IndentCaseLabels == R.IndentCaseLabels &&
  4019. IndentExternBlock == R.IndentExternBlock &&
  4020. IndentGotoLabels == R.IndentGotoLabels &&
  4021. IndentPPDirectives == R.IndentPPDirectives &&
  4022. IndentRequiresClause == R.IndentRequiresClause &&
  4023. IndentWidth == R.IndentWidth &&
  4024. IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
  4025. InsertBraces == R.InsertBraces &&
  4026. InsertNewlineAtEOF == R.InsertNewlineAtEOF &&
  4027. IntegerLiteralSeparator.Binary == R.IntegerLiteralSeparator.Binary &&
  4028. IntegerLiteralSeparator.Decimal ==
  4029. R.IntegerLiteralSeparator.Decimal &&
  4030. IntegerLiteralSeparator.Hex == R.IntegerLiteralSeparator.Hex &&
  4031. JavaImportGroups == R.JavaImportGroups &&
  4032. JavaScriptQuotes == R.JavaScriptQuotes &&
  4033. JavaScriptWrapImports == R.JavaScriptWrapImports &&
  4034. KeepEmptyLinesAtTheStartOfBlocks ==
  4035. R.KeepEmptyLinesAtTheStartOfBlocks &&
  4036. Language == R.Language &&
  4037. LambdaBodyIndentation == R.LambdaBodyIndentation &&
  4038. LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
  4039. MacroBlockEnd == R.MacroBlockEnd &&
  4040. MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
  4041. NamespaceIndentation == R.NamespaceIndentation &&
  4042. NamespaceMacros == R.NamespaceMacros &&
  4043. ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
  4044. ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
  4045. ObjCBreakBeforeNestedBlockParam ==
  4046. R.ObjCBreakBeforeNestedBlockParam &&
  4047. ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
  4048. ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
  4049. PackConstructorInitializers == R.PackConstructorInitializers &&
  4050. PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
  4051. PenaltyBreakBeforeFirstCallParameter ==
  4052. R.PenaltyBreakBeforeFirstCallParameter &&
  4053. PenaltyBreakComment == R.PenaltyBreakComment &&
  4054. PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
  4055. PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
  4056. PenaltyBreakString == R.PenaltyBreakString &&
  4057. PenaltyBreakTemplateDeclaration ==
  4058. R.PenaltyBreakTemplateDeclaration &&
  4059. PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
  4060. PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
  4061. PointerAlignment == R.PointerAlignment &&
  4062. QualifierAlignment == R.QualifierAlignment &&
  4063. QualifierOrder == R.QualifierOrder &&
  4064. RawStringFormats == R.RawStringFormats &&
  4065. ReferenceAlignment == R.ReferenceAlignment &&
  4066. RemoveBracesLLVM == R.RemoveBracesLLVM &&
  4067. RemoveSemicolon == R.RemoveSemicolon &&
  4068. RequiresClausePosition == R.RequiresClausePosition &&
  4069. RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
  4070. SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
  4071. ShortNamespaceLines == R.ShortNamespaceLines &&
  4072. SortIncludes == R.SortIncludes &&
  4073. SortJavaStaticImport == R.SortJavaStaticImport &&
  4074. SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
  4075. SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
  4076. SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
  4077. SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
  4078. SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
  4079. SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
  4080. SpaceBeforeCtorInitializerColon ==
  4081. R.SpaceBeforeCtorInitializerColon &&
  4082. SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
  4083. SpaceBeforeParens == R.SpaceBeforeParens &&
  4084. SpaceBeforeParensOptions == R.SpaceBeforeParensOptions &&
  4085. SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers &&
  4086. SpaceBeforeRangeBasedForLoopColon ==
  4087. R.SpaceBeforeRangeBasedForLoopColon &&
  4088. SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
  4089. SpaceInEmptyBlock == R.SpaceInEmptyBlock &&
  4090. SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
  4091. SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
  4092. SpacesInAngles == R.SpacesInAngles &&
  4093. SpacesInConditionalStatement == R.SpacesInConditionalStatement &&
  4094. SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
  4095. SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
  4096. SpacesInLineCommentPrefix.Minimum ==
  4097. R.SpacesInLineCommentPrefix.Minimum &&
  4098. SpacesInLineCommentPrefix.Maximum ==
  4099. R.SpacesInLineCommentPrefix.Maximum &&
  4100. SpacesInParentheses == R.SpacesInParentheses &&
  4101. SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
  4102. Standard == R.Standard &&
  4103. StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
  4104. StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
  4105. TypenameMacros == R.TypenameMacros && UseTab == R.UseTab &&
  4106. WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
  4107. ContextIndependentContinuationIndent == R.ContextIndependentContinuationIndent &&
  4108. AllowMultilineLambdaCaptureList == R.AllowMultilineLambdaCaptureList;
  4109. }
  4110. std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
  4111. // Stores per-language styles. A FormatStyle instance inside has an empty
  4112. // StyleSet. A FormatStyle instance returned by the Get method has its
  4113. // StyleSet set to a copy of the originating StyleSet, effectively keeping the
  4114. // internal representation of that StyleSet alive.
  4115. //
  4116. // The memory management and ownership reminds of a birds nest: chicks
  4117. // leaving the nest take photos of the nest with them.
  4118. struct FormatStyleSet {
  4119. typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
  4120. std::optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const;
  4121. // Adds \p Style to this FormatStyleSet. Style must not have an associated
  4122. // FormatStyleSet.
  4123. // Style.Language should be different than LK_None. If this FormatStyleSet
  4124. // already contains an entry for Style.Language, that gets replaced with the
  4125. // passed Style.
  4126. void Add(FormatStyle Style);
  4127. // Clears this FormatStyleSet.
  4128. void Clear();
  4129. private:
  4130. std::shared_ptr<MapType> Styles;
  4131. };
  4132. static FormatStyleSet BuildStyleSetFromConfiguration(
  4133. const FormatStyle &MainStyle,
  4134. const std::vector<FormatStyle> &ConfigurationStyles);
  4135. private:
  4136. FormatStyleSet StyleSet;
  4137. friend std::error_code
  4138. parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
  4139. bool AllowUnknownOptions,
  4140. llvm::SourceMgr::DiagHandlerTy DiagHandler,
  4141. void *DiagHandlerCtxt);
  4142. };
  4143. /// Returns a format style complying with the LLVM coding standards:
  4144. /// http://llvm.org/docs/CodingStandards.html.
  4145. FormatStyle getLLVMStyle(
  4146. FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp);
  4147. /// Returns a format style complying with one of Google's style guides:
  4148. /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
  4149. /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
  4150. /// https://developers.google.com/protocol-buffers/docs/style.
  4151. FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
  4152. /// Returns a format style complying with Chromium's style guide:
  4153. /// http://www.chromium.org/developers/coding-style.
  4154. FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
  4155. /// Returns a format style complying with Mozilla's style guide:
  4156. /// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
  4157. FormatStyle getMozillaStyle();
  4158. /// Returns a format style complying with Webkit's style guide:
  4159. /// http://www.webkit.org/coding/coding-style.html
  4160. FormatStyle getWebKitStyle();
  4161. /// Returns a format style complying with GNU Coding Standards:
  4162. /// http://www.gnu.org/prep/standards/standards.html
  4163. FormatStyle getGNUStyle();
  4164. /// Returns a format style complying with Microsoft style guide:
  4165. /// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
  4166. FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language);
  4167. /// Returns style indicating formatting should be not applied at all.
  4168. FormatStyle getNoStyle();
  4169. /// Gets a predefined style for the specified language by name.
  4170. ///
  4171. /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
  4172. /// compared case-insensitively.
  4173. ///
  4174. /// Returns ``true`` if the Style has been set.
  4175. bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
  4176. FormatStyle *Style);
  4177. /// Parse configuration from YAML-formatted text.
  4178. ///
  4179. /// Style->Language is used to get the base style, if the ``BasedOnStyle``
  4180. /// option is present.
  4181. ///
  4182. /// The FormatStyleSet of Style is reset.
  4183. ///
  4184. /// When ``BasedOnStyle`` is not present, options not present in the YAML
  4185. /// document, are retained in \p Style.
  4186. ///
  4187. /// If AllowUnknownOptions is true, no errors are emitted if unknown
  4188. /// format options are occurred.
  4189. ///
  4190. /// If set all diagnostics are emitted through the DiagHandler.
  4191. std::error_code
  4192. parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
  4193. bool AllowUnknownOptions = false,
  4194. llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
  4195. void *DiagHandlerCtx = nullptr);
  4196. /// Like above but accepts an unnamed buffer.
  4197. inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
  4198. bool AllowUnknownOptions = false) {
  4199. return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
  4200. AllowUnknownOptions);
  4201. }
  4202. /// Gets configuration in a YAML string.
  4203. std::string configurationAsText(const FormatStyle &Style);
  4204. /// Returns the replacements necessary to sort all ``#include`` blocks
  4205. /// that are affected by ``Ranges``.
  4206. tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
  4207. ArrayRef<tooling::Range> Ranges,
  4208. StringRef FileName,
  4209. unsigned *Cursor = nullptr);
  4210. /// Returns the replacements corresponding to applying and formatting
  4211. /// \p Replaces on success; otheriwse, return an llvm::Error carrying
  4212. /// llvm::StringError.
  4213. llvm::Expected<tooling::Replacements>
  4214. formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
  4215. const FormatStyle &Style);
  4216. /// Returns the replacements corresponding to applying \p Replaces and
  4217. /// cleaning up the code after that on success; otherwise, return an llvm::Error
  4218. /// carrying llvm::StringError.
  4219. /// This also supports inserting/deleting C++ #include directives:
  4220. /// - If a replacement has offset UINT_MAX, length 0, and a replacement text
  4221. /// that is an #include directive, this will insert the #include into the
  4222. /// correct block in the \p Code.
  4223. /// - If a replacement has offset UINT_MAX, length 1, and a replacement text
  4224. /// that is the name of the header to be removed, the header will be removed
  4225. /// from \p Code if it exists.
  4226. /// The include manipulation is done via `tooling::HeaderInclude`, see its
  4227. /// documentation for more details on how include insertion points are found and
  4228. /// what edits are produced.
  4229. llvm::Expected<tooling::Replacements>
  4230. cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
  4231. const FormatStyle &Style);
  4232. /// Represents the status of a formatting attempt.
  4233. struct FormattingAttemptStatus {
  4234. /// A value of ``false`` means that any of the affected ranges were not
  4235. /// formatted due to a non-recoverable syntax error.
  4236. bool FormatComplete = true;
  4237. /// If ``FormatComplete`` is false, ``Line`` records a one-based
  4238. /// original line number at which a syntax error might have occurred. This is
  4239. /// based on a best-effort analysis and could be imprecise.
  4240. unsigned Line = 0;
  4241. };
  4242. /// Reformats the given \p Ranges in \p Code.
  4243. ///
  4244. /// Each range is extended on either end to its next bigger logic unit, i.e.
  4245. /// everything that might influence its formatting or might be influenced by its
  4246. /// formatting.
  4247. ///
  4248. /// Returns the ``Replacements`` necessary to make all \p Ranges comply with
  4249. /// \p Style.
  4250. ///
  4251. /// If ``Status`` is non-null, its value will be populated with the status of
  4252. /// this formatting attempt. See \c FormattingAttemptStatus.
  4253. tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
  4254. ArrayRef<tooling::Range> Ranges,
  4255. StringRef FileName = "<stdin>",
  4256. FormattingAttemptStatus *Status = nullptr);
  4257. /// Same as above, except if ``IncompleteFormat`` is non-null, its value
  4258. /// will be set to true if any of the affected ranges were not formatted due to
  4259. /// a non-recoverable syntax error.
  4260. tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
  4261. ArrayRef<tooling::Range> Ranges,
  4262. StringRef FileName, bool *IncompleteFormat);
  4263. /// Clean up any erroneous/redundant code in the given \p Ranges in \p
  4264. /// Code.
  4265. ///
  4266. /// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
  4267. tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
  4268. ArrayRef<tooling::Range> Ranges,
  4269. StringRef FileName = "<stdin>");
  4270. /// Fix namespace end comments in the given \p Ranges in \p Code.
  4271. ///
  4272. /// Returns the ``Replacements`` that fix the namespace comments in all
  4273. /// \p Ranges in \p Code.
  4274. tooling::Replacements fixNamespaceEndComments(const FormatStyle &Style,
  4275. StringRef Code,
  4276. ArrayRef<tooling::Range> Ranges,
  4277. StringRef FileName = "<stdin>");
  4278. /// Inserts or removes empty lines separating definition blocks including
  4279. /// classes, structs, functions, namespaces, and enums in the given \p Ranges in
  4280. /// \p Code.
  4281. ///
  4282. /// Returns the ``Replacements`` that inserts or removes empty lines separating
  4283. /// definition blocks in all \p Ranges in \p Code.
  4284. tooling::Replacements separateDefinitionBlocks(const FormatStyle &Style,
  4285. StringRef Code,
  4286. ArrayRef<tooling::Range> Ranges,
  4287. StringRef FileName = "<stdin>");
  4288. /// Sort consecutive using declarations in the given \p Ranges in
  4289. /// \p Code.
  4290. ///
  4291. /// Returns the ``Replacements`` that sort the using declarations in all
  4292. /// \p Ranges in \p Code.
  4293. tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
  4294. StringRef Code,
  4295. ArrayRef<tooling::Range> Ranges,
  4296. StringRef FileName = "<stdin>");
  4297. /// Returns the ``LangOpts`` that the formatter expects you to set.
  4298. ///
  4299. /// \param Style determines specific settings for lexing mode.
  4300. LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
  4301. /// Description to be used for help text for a ``llvm::cl`` option for
  4302. /// specifying format style. The description is closely related to the operation
  4303. /// of ``getStyle()``.
  4304. extern const char *StyleOptionHelpDescription;
  4305. /// The suggested format style to use by default. This allows tools using
  4306. /// `getStyle` to have a consistent default style.
  4307. /// Different builds can modify the value to the preferred styles.
  4308. extern const char *DefaultFormatStyle;
  4309. /// The suggested predefined style to use as the fallback style in `getStyle`.
  4310. /// Different builds can modify the value to the preferred styles.
  4311. extern const char *DefaultFallbackStyle;
  4312. /// Construct a FormatStyle based on ``StyleName``.
  4313. ///
  4314. /// ``StyleName`` can take several forms:
  4315. /// * "{<key>: <value>, ...}" - Set specic style parameters.
  4316. /// * "<style name>" - One of the style names supported by
  4317. /// getPredefinedStyle().
  4318. /// * "file" - Load style configuration from a file called ``.clang-format``
  4319. /// located in one of the parent directories of ``FileName`` or the current
  4320. /// directory if ``FileName`` is empty.
  4321. /// * "file:<format_file_path>" to explicitly specify the configuration file to
  4322. /// use.
  4323. ///
  4324. /// \param[in] StyleName Style name to interpret according to the description
  4325. /// above.
  4326. /// \param[in] FileName Path to start search for .clang-format if ``StyleName``
  4327. /// == "file".
  4328. /// \param[in] FallbackStyle The name of a predefined style used to fallback to
  4329. /// in case \p StyleName is "file" and no file can be found.
  4330. /// \param[in] Code The actual code to be formatted. Used to determine the
  4331. /// language if the filename isn't sufficient.
  4332. /// \param[in] FS The underlying file system, in which the file resides. By
  4333. /// default, the file system is the real file system.
  4334. /// \param[in] AllowUnknownOptions If true, unknown format options only
  4335. /// emit a warning. If false, errors are emitted on unknown format
  4336. /// options.
  4337. ///
  4338. /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
  4339. /// "file" and no file is found, returns ``FallbackStyle``. If no style could be
  4340. /// determined, returns an Error.
  4341. llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName,
  4342. StringRef FallbackStyle,
  4343. StringRef Code = "",
  4344. llvm::vfs::FileSystem *FS = nullptr,
  4345. bool AllowUnknownOptions = false);
  4346. // Guesses the language from the ``FileName`` and ``Code`` to be formatted.
  4347. // Defaults to FormatStyle::LK_Cpp.
  4348. FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
  4349. // Returns a string representation of ``Language``.
  4350. inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
  4351. switch (Language) {
  4352. case FormatStyle::LK_Cpp:
  4353. return "C++";
  4354. case FormatStyle::LK_CSharp:
  4355. return "CSharp";
  4356. case FormatStyle::LK_ObjC:
  4357. return "Objective-C";
  4358. case FormatStyle::LK_Java:
  4359. return "Java";
  4360. case FormatStyle::LK_JavaScript:
  4361. return "JavaScript";
  4362. case FormatStyle::LK_Json:
  4363. return "Json";
  4364. case FormatStyle::LK_Proto:
  4365. return "Proto";
  4366. case FormatStyle::LK_TableGen:
  4367. return "TableGen";
  4368. case FormatStyle::LK_TextProto:
  4369. return "TextProto";
  4370. case FormatStyle::LK_Verilog:
  4371. return "Verilog";
  4372. default:
  4373. return "Unknown";
  4374. }
  4375. }
  4376. } // end namespace format
  4377. } // end namespace clang
  4378. namespace std {
  4379. template <>
  4380. struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
  4381. } // namespace std
  4382. #endif // LLVM_CLANG_FORMAT_FORMAT_H
  4383. #ifdef __GNUC__
  4384. #pragma GCC diagnostic pop
  4385. #endif