Index.h 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756
  1. /*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
  2. |* *|
  3. |* The LLVM Compiler Infrastructure *|
  4. |* *|
  5. |* This file is distributed under the University of Illinois Open Source *|
  6. |* License. See LICENSE.TXT for details. *|
  7. |* *|
  8. |*===----------------------------------------------------------------------===*|
  9. |* *|
  10. |* This header provides a public inferface to a Clang library for extracting *|
  11. |* high-level symbol information from source files without exposing the full *|
  12. |* Clang C++ API. *|
  13. |* *|
  14. \*===----------------------------------------------------------------------===*/
  15. #ifndef LLVM_CLANG_C_INDEX_H
  16. #define LLVM_CLANG_C_INDEX_H
  17. #include <time.h>
  18. #include "clang-c/Platform.h"
  19. #include "clang-c/CXErrorCode.h"
  20. #include "clang-c/CXString.h"
  21. #include "clang-c/BuildSystem.h"
  22. /**
  23. * \brief The version constants for the libclang API.
  24. * CINDEX_VERSION_MINOR should increase when there are API additions.
  25. * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
  26. *
  27. * The policy about the libclang API was always to keep it source and ABI
  28. * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  29. */
  30. #define CINDEX_VERSION_MAJOR 0
  31. #define CINDEX_VERSION_MINOR 30
  32. #define CINDEX_VERSION_ENCODE(major, minor) ( \
  33. ((major) * 10000) \
  34. + ((minor) * 1))
  35. #define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
  36. CINDEX_VERSION_MAJOR, \
  37. CINDEX_VERSION_MINOR )
  38. #define CINDEX_VERSION_STRINGIZE_(major, minor) \
  39. #major"."#minor
  40. #define CINDEX_VERSION_STRINGIZE(major, minor) \
  41. CINDEX_VERSION_STRINGIZE_(major, minor)
  42. #define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
  43. CINDEX_VERSION_MAJOR, \
  44. CINDEX_VERSION_MINOR)
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /** \defgroup CINDEX libclang: C Interface to Clang
  49. *
  50. * The C Interface to Clang provides a relatively small API that exposes
  51. * facilities for parsing source code into an abstract syntax tree (AST),
  52. * loading already-parsed ASTs, traversing the AST, associating
  53. * physical source locations with elements within the AST, and other
  54. * facilities that support Clang-based development tools.
  55. *
  56. * This C interface to Clang will never provide all of the information
  57. * representation stored in Clang's C++ AST, nor should it: the intent is to
  58. * maintain an API that is relatively stable from one release to the next,
  59. * providing only the basic functionality needed to support development tools.
  60. *
  61. * To avoid namespace pollution, data types are prefixed with "CX" and
  62. * functions are prefixed with "clang_".
  63. *
  64. * @{
  65. */
  66. /**
  67. * \brief An "index" that consists of a set of translation units that would
  68. * typically be linked together into an executable or library.
  69. */
  70. typedef void *CXIndex;
  71. /**
  72. * \brief A single translation unit, which resides in an index.
  73. */
  74. typedef struct CXTranslationUnitImpl *CXTranslationUnit;
  75. /**
  76. * \brief Opaque pointer representing client data that will be passed through
  77. * to various callbacks and visitors.
  78. */
  79. typedef void *CXClientData;
  80. /**
  81. * \brief Provides the contents of a file that has not yet been saved to disk.
  82. *
  83. * Each CXUnsavedFile instance provides the name of a file on the
  84. * system along with the current contents of that file that have not
  85. * yet been saved to disk.
  86. */
  87. struct CXUnsavedFile {
  88. /**
  89. * \brief The file whose contents have not yet been saved.
  90. *
  91. * This file must already exist in the file system.
  92. */
  93. const char *Filename;
  94. /**
  95. * \brief A buffer containing the unsaved contents of this file.
  96. */
  97. const char *Contents;
  98. /**
  99. * \brief The length of the unsaved contents of this buffer.
  100. */
  101. unsigned long Length;
  102. };
  103. /**
  104. * \brief Describes the availability of a particular entity, which indicates
  105. * whether the use of this entity will result in a warning or error due to
  106. * it being deprecated or unavailable.
  107. */
  108. enum CXAvailabilityKind {
  109. /**
  110. * \brief The entity is available.
  111. */
  112. CXAvailability_Available,
  113. /**
  114. * \brief The entity is available, but has been deprecated (and its use is
  115. * not recommended).
  116. */
  117. CXAvailability_Deprecated,
  118. /**
  119. * \brief The entity is not available; any use of it will be an error.
  120. */
  121. CXAvailability_NotAvailable,
  122. /**
  123. * \brief The entity is available, but not accessible; any use of it will be
  124. * an error.
  125. */
  126. CXAvailability_NotAccessible
  127. };
  128. /**
  129. * \brief Describes a version number of the form major.minor.subminor.
  130. */
  131. typedef struct CXVersion {
  132. /**
  133. * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
  134. * value indicates that there is no version number at all.
  135. */
  136. int Major;
  137. /**
  138. * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
  139. * will be negative if no minor version number was provided, e.g., for
  140. * version '10'.
  141. */
  142. int Minor;
  143. /**
  144. * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
  145. * will be negative if no minor or subminor version number was provided,
  146. * e.g., in version '10' or '10.7'.
  147. */
  148. int Subminor;
  149. } CXVersion;
  150. /**
  151. * \brief Provides a shared context for creating translation units.
  152. *
  153. * It provides two options:
  154. *
  155. * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
  156. * declarations (when loading any new translation units). A "local" declaration
  157. * is one that belongs in the translation unit itself and not in a precompiled
  158. * header that was used by the translation unit. If zero, all declarations
  159. * will be enumerated.
  160. *
  161. * Here is an example:
  162. *
  163. * \code
  164. * // excludeDeclsFromPCH = 1, displayDiagnostics=1
  165. * Idx = clang_createIndex(1, 1);
  166. *
  167. * // IndexTest.pch was produced with the following command:
  168. * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
  169. * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
  170. *
  171. * // This will load all the symbols from 'IndexTest.pch'
  172. * clang_visitChildren(clang_getTranslationUnitCursor(TU),
  173. * TranslationUnitVisitor, 0);
  174. * clang_disposeTranslationUnit(TU);
  175. *
  176. * // This will load all the symbols from 'IndexTest.c', excluding symbols
  177. * // from 'IndexTest.pch'.
  178. * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
  179. * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
  180. * 0, 0);
  181. * clang_visitChildren(clang_getTranslationUnitCursor(TU),
  182. * TranslationUnitVisitor, 0);
  183. * clang_disposeTranslationUnit(TU);
  184. * \endcode
  185. *
  186. * This process of creating the 'pch', loading it separately, and using it (via
  187. * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
  188. * (which gives the indexer the same performance benefit as the compiler).
  189. */
  190. CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
  191. int displayDiagnostics);
  192. /**
  193. * \brief Destroy the given index.
  194. *
  195. * The index must not be destroyed until all of the translation units created
  196. * within that index have been destroyed.
  197. */
  198. CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
  199. typedef enum {
  200. /**
  201. * \brief Used to indicate that no special CXIndex options are needed.
  202. */
  203. CXGlobalOpt_None = 0x0,
  204. /**
  205. * \brief Used to indicate that threads that libclang creates for indexing
  206. * purposes should use background priority.
  207. *
  208. * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
  209. * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
  210. */
  211. CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
  212. /**
  213. * \brief Used to indicate that threads that libclang creates for editing
  214. * purposes should use background priority.
  215. *
  216. * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
  217. * #clang_annotateTokens
  218. */
  219. CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
  220. /**
  221. * \brief Used to indicate that all threads that libclang creates should use
  222. * background priority.
  223. */
  224. CXGlobalOpt_ThreadBackgroundPriorityForAll =
  225. CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
  226. CXGlobalOpt_ThreadBackgroundPriorityForEditing
  227. } CXGlobalOptFlags;
  228. /**
  229. * \brief Sets general options associated with a CXIndex.
  230. *
  231. * For example:
  232. * \code
  233. * CXIndex idx = ...;
  234. * clang_CXIndex_setGlobalOptions(idx,
  235. * clang_CXIndex_getGlobalOptions(idx) |
  236. * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
  237. * \endcode
  238. *
  239. * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
  240. */
  241. CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
  242. /**
  243. * \brief Gets the general options associated with a CXIndex.
  244. *
  245. * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
  246. * are associated with the given CXIndex object.
  247. */
  248. CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
  249. /**
  250. * \defgroup CINDEX_FILES File manipulation routines
  251. *
  252. * @{
  253. */
  254. /**
  255. * \brief A particular source file that is part of a translation unit.
  256. */
  257. typedef void *CXFile;
  258. /**
  259. * \brief Retrieve the complete file and path name of the given file.
  260. */
  261. CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
  262. /**
  263. * \brief Retrieve the last modification time of the given file.
  264. */
  265. CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
  266. /**
  267. * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
  268. * across an indexing session.
  269. */
  270. typedef struct {
  271. unsigned long long data[3];
  272. } CXFileUniqueID;
  273. /**
  274. * \brief Retrieve the unique ID for the given \c file.
  275. *
  276. * \param file the file to get the ID for.
  277. * \param outID stores the returned CXFileUniqueID.
  278. * \returns If there was a failure getting the unique ID, returns non-zero,
  279. * otherwise returns 0.
  280. */
  281. CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
  282. /**
  283. * \brief Determine whether the given header is guarded against
  284. * multiple inclusions, either with the conventional
  285. * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
  286. */
  287. CINDEX_LINKAGE unsigned
  288. clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
  289. /**
  290. * \brief Retrieve a file handle within the given translation unit.
  291. *
  292. * \param tu the translation unit
  293. *
  294. * \param file_name the name of the file.
  295. *
  296. * \returns the file handle for the named file in the translation unit \p tu,
  297. * or a NULL file handle if the file was not a part of this translation unit.
  298. */
  299. CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
  300. const char *file_name);
  301. /**
  302. * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
  303. * or they are both NULL.
  304. */
  305. CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
  306. /**
  307. * @}
  308. */
  309. /**
  310. * \defgroup CINDEX_LOCATIONS Physical source locations
  311. *
  312. * Clang represents physical source locations in its abstract syntax tree in
  313. * great detail, with file, line, and column information for the majority of
  314. * the tokens parsed in the source code. These data types and functions are
  315. * used to represent source location information, either for a particular
  316. * point in the program or for a range of points in the program, and extract
  317. * specific location information from those data types.
  318. *
  319. * @{
  320. */
  321. /**
  322. * \brief Identifies a specific source location within a translation
  323. * unit.
  324. *
  325. * Use clang_getExpansionLocation() or clang_getSpellingLocation()
  326. * to map a source location to a particular file, line, and column.
  327. */
  328. typedef struct {
  329. const void *ptr_data[2];
  330. unsigned int_data;
  331. } CXSourceLocation;
  332. /**
  333. * \brief Identifies a half-open character range in the source code.
  334. *
  335. * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
  336. * starting and end locations from a source range, respectively.
  337. */
  338. typedef struct {
  339. const void *ptr_data[2];
  340. unsigned begin_int_data;
  341. unsigned end_int_data;
  342. } CXSourceRange;
  343. /**
  344. * \brief Retrieve a NULL (invalid) source location.
  345. */
  346. CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
  347. /**
  348. * \brief Determine whether two source locations, which must refer into
  349. * the same translation unit, refer to exactly the same point in the source
  350. * code.
  351. *
  352. * \returns non-zero if the source locations refer to the same location, zero
  353. * if they refer to different locations.
  354. */
  355. CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
  356. CXSourceLocation loc2);
  357. /**
  358. * \brief Retrieves the source location associated with a given file/line/column
  359. * in a particular translation unit.
  360. */
  361. CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
  362. CXFile file,
  363. unsigned line,
  364. unsigned column);
  365. /**
  366. * \brief Retrieves the source location associated with a given character offset
  367. * in a particular translation unit.
  368. */
  369. CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
  370. CXFile file,
  371. unsigned offset);
  372. /**
  373. * \brief Returns non-zero if the given source location is in a system header.
  374. */
  375. CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
  376. /**
  377. * \brief Returns non-zero if the given source location is in the main file of
  378. * the corresponding translation unit.
  379. */
  380. CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
  381. /**
  382. * \brief Retrieve a NULL (invalid) source range.
  383. */
  384. CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
  385. /**
  386. * \brief Retrieve a source range given the beginning and ending source
  387. * locations.
  388. */
  389. CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
  390. CXSourceLocation end);
  391. /**
  392. * \brief Determine whether two ranges are equivalent.
  393. *
  394. * \returns non-zero if the ranges are the same, zero if they differ.
  395. */
  396. CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
  397. CXSourceRange range2);
  398. /**
  399. * \brief Returns non-zero if \p range is null.
  400. */
  401. CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
  402. /**
  403. * \brief Retrieve the file, line, column, and offset represented by
  404. * the given source location.
  405. *
  406. * If the location refers into a macro expansion, retrieves the
  407. * location of the macro expansion.
  408. *
  409. * \param location the location within a source file that will be decomposed
  410. * into its parts.
  411. *
  412. * \param file [out] if non-NULL, will be set to the file to which the given
  413. * source location points.
  414. *
  415. * \param line [out] if non-NULL, will be set to the line to which the given
  416. * source location points.
  417. *
  418. * \param column [out] if non-NULL, will be set to the column to which the given
  419. * source location points.
  420. *
  421. * \param offset [out] if non-NULL, will be set to the offset into the
  422. * buffer to which the given source location points.
  423. */
  424. CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
  425. CXFile *file,
  426. unsigned *line,
  427. unsigned *column,
  428. unsigned *offset);
  429. /**
  430. * \brief Retrieve the file, line, column, and offset represented by
  431. * the given source location, as specified in a # line directive.
  432. *
  433. * Example: given the following source code in a file somefile.c
  434. *
  435. * \code
  436. * #123 "dummy.c" 1
  437. *
  438. * static int func(void)
  439. * {
  440. * return 0;
  441. * }
  442. * \endcode
  443. *
  444. * the location information returned by this function would be
  445. *
  446. * File: dummy.c Line: 124 Column: 12
  447. *
  448. * whereas clang_getExpansionLocation would have returned
  449. *
  450. * File: somefile.c Line: 3 Column: 12
  451. *
  452. * \param location the location within a source file that will be decomposed
  453. * into its parts.
  454. *
  455. * \param filename [out] if non-NULL, will be set to the filename of the
  456. * source location. Note that filenames returned will be for "virtual" files,
  457. * which don't necessarily exist on the machine running clang - e.g. when
  458. * parsing preprocessed output obtained from a different environment. If
  459. * a non-NULL value is passed in, remember to dispose of the returned value
  460. * using \c clang_disposeString() once you've finished with it. For an invalid
  461. * source location, an empty string is returned.
  462. *
  463. * \param line [out] if non-NULL, will be set to the line number of the
  464. * source location. For an invalid source location, zero is returned.
  465. *
  466. * \param column [out] if non-NULL, will be set to the column number of the
  467. * source location. For an invalid source location, zero is returned.
  468. */
  469. CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
  470. CXString *filename,
  471. unsigned *line,
  472. unsigned *column);
  473. /**
  474. * \brief Legacy API to retrieve the file, line, column, and offset represented
  475. * by the given source location.
  476. *
  477. * This interface has been replaced by the newer interface
  478. * #clang_getExpansionLocation(). See that interface's documentation for
  479. * details.
  480. */
  481. CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
  482. CXFile *file,
  483. unsigned *line,
  484. unsigned *column,
  485. unsigned *offset);
  486. /**
  487. * \brief Retrieve the file, line, column, and offset represented by
  488. * the given source location.
  489. *
  490. * If the location refers into a macro instantiation, return where the
  491. * location was originally spelled in the source file.
  492. *
  493. * \param location the location within a source file that will be decomposed
  494. * into its parts.
  495. *
  496. * \param file [out] if non-NULL, will be set to the file to which the given
  497. * source location points.
  498. *
  499. * \param line [out] if non-NULL, will be set to the line to which the given
  500. * source location points.
  501. *
  502. * \param column [out] if non-NULL, will be set to the column to which the given
  503. * source location points.
  504. *
  505. * \param offset [out] if non-NULL, will be set to the offset into the
  506. * buffer to which the given source location points.
  507. */
  508. CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
  509. CXFile *file,
  510. unsigned *line,
  511. unsigned *column,
  512. unsigned *offset);
  513. /**
  514. * \brief Retrieve the file, line, column, and offset represented by
  515. * the given source location.
  516. *
  517. * If the location refers into a macro expansion, return where the macro was
  518. * expanded or where the macro argument was written, if the location points at
  519. * a macro argument.
  520. *
  521. * \param location the location within a source file that will be decomposed
  522. * into its parts.
  523. *
  524. * \param file [out] if non-NULL, will be set to the file to which the given
  525. * source location points.
  526. *
  527. * \param line [out] if non-NULL, will be set to the line to which the given
  528. * source location points.
  529. *
  530. * \param column [out] if non-NULL, will be set to the column to which the given
  531. * source location points.
  532. *
  533. * \param offset [out] if non-NULL, will be set to the offset into the
  534. * buffer to which the given source location points.
  535. */
  536. CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
  537. CXFile *file,
  538. unsigned *line,
  539. unsigned *column,
  540. unsigned *offset);
  541. /**
  542. * \brief Retrieve a source location representing the first character within a
  543. * source range.
  544. */
  545. CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
  546. /**
  547. * \brief Retrieve a source location representing the last character within a
  548. * source range.
  549. */
  550. CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
  551. /**
  552. * \brief Identifies an array of ranges.
  553. */
  554. typedef struct {
  555. /** \brief The number of ranges in the \c ranges array. */
  556. unsigned count;
  557. /**
  558. * \brief An array of \c CXSourceRanges.
  559. */
  560. CXSourceRange *ranges;
  561. } CXSourceRangeList;
  562. /**
  563. * \brief Retrieve all ranges that were skipped by the preprocessor.
  564. *
  565. * The preprocessor will skip lines when they are surrounded by an
  566. * if/ifdef/ifndef directive whose condition does not evaluate to true.
  567. */
  568. CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu,
  569. CXFile file);
  570. /**
  571. * \brief Destroy the given \c CXSourceRangeList.
  572. */
  573. CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
  574. /**
  575. * @}
  576. */
  577. /**
  578. * \defgroup CINDEX_DIAG Diagnostic reporting
  579. *
  580. * @{
  581. */
  582. /**
  583. * \brief Describes the severity of a particular diagnostic.
  584. */
  585. enum CXDiagnosticSeverity {
  586. /**
  587. * \brief A diagnostic that has been suppressed, e.g., by a command-line
  588. * option.
  589. */
  590. CXDiagnostic_Ignored = 0,
  591. /**
  592. * \brief This diagnostic is a note that should be attached to the
  593. * previous (non-note) diagnostic.
  594. */
  595. CXDiagnostic_Note = 1,
  596. /**
  597. * \brief This diagnostic indicates suspicious code that may not be
  598. * wrong.
  599. */
  600. CXDiagnostic_Warning = 2,
  601. /**
  602. * \brief This diagnostic indicates that the code is ill-formed.
  603. */
  604. CXDiagnostic_Error = 3,
  605. /**
  606. * \brief This diagnostic indicates that the code is ill-formed such
  607. * that future parser recovery is unlikely to produce useful
  608. * results.
  609. */
  610. CXDiagnostic_Fatal = 4
  611. };
  612. /**
  613. * \brief A single diagnostic, containing the diagnostic's severity,
  614. * location, text, source ranges, and fix-it hints.
  615. */
  616. typedef void *CXDiagnostic;
  617. /**
  618. * \brief A group of CXDiagnostics.
  619. */
  620. typedef void *CXDiagnosticSet;
  621. /**
  622. * \brief Determine the number of diagnostics in a CXDiagnosticSet.
  623. */
  624. CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
  625. /**
  626. * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
  627. *
  628. * \param Diags the CXDiagnosticSet to query.
  629. * \param Index the zero-based diagnostic number to retrieve.
  630. *
  631. * \returns the requested diagnostic. This diagnostic must be freed
  632. * via a call to \c clang_disposeDiagnostic().
  633. */
  634. CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
  635. unsigned Index);
  636. /**
  637. * \brief Describes the kind of error that occurred (if any) in a call to
  638. * \c clang_loadDiagnostics.
  639. */
  640. enum CXLoadDiag_Error {
  641. /**
  642. * \brief Indicates that no error occurred.
  643. */
  644. CXLoadDiag_None = 0,
  645. /**
  646. * \brief Indicates that an unknown error occurred while attempting to
  647. * deserialize diagnostics.
  648. */
  649. CXLoadDiag_Unknown = 1,
  650. /**
  651. * \brief Indicates that the file containing the serialized diagnostics
  652. * could not be opened.
  653. */
  654. CXLoadDiag_CannotLoad = 2,
  655. /**
  656. * \brief Indicates that the serialized diagnostics file is invalid or
  657. * corrupt.
  658. */
  659. CXLoadDiag_InvalidFile = 3
  660. };
  661. /**
  662. * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
  663. * file.
  664. *
  665. * \param file The name of the file to deserialize.
  666. * \param error A pointer to a enum value recording if there was a problem
  667. * deserializing the diagnostics.
  668. * \param errorString A pointer to a CXString for recording the error string
  669. * if the file was not successfully loaded.
  670. *
  671. * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
  672. * diagnostics should be released using clang_disposeDiagnosticSet().
  673. */
  674. CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
  675. enum CXLoadDiag_Error *error,
  676. CXString *errorString);
  677. /**
  678. * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
  679. */
  680. CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
  681. /**
  682. * \brief Retrieve the child diagnostics of a CXDiagnostic.
  683. *
  684. * This CXDiagnosticSet does not need to be released by
  685. * clang_disposeDiagnosticSet.
  686. */
  687. CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
  688. /**
  689. * \brief Determine the number of diagnostics produced for the given
  690. * translation unit.
  691. */
  692. CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
  693. /**
  694. * \brief Retrieve a diagnostic associated with the given translation unit.
  695. *
  696. * \param Unit the translation unit to query.
  697. * \param Index the zero-based diagnostic number to retrieve.
  698. *
  699. * \returns the requested diagnostic. This diagnostic must be freed
  700. * via a call to \c clang_disposeDiagnostic().
  701. */
  702. CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
  703. unsigned Index);
  704. /**
  705. * \brief Retrieve the complete set of diagnostics associated with a
  706. * translation unit.
  707. *
  708. * \param Unit the translation unit to query.
  709. */
  710. CINDEX_LINKAGE CXDiagnosticSet
  711. clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
  712. /**
  713. * \brief Destroy a diagnostic.
  714. */
  715. CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
  716. /**
  717. * \brief Options to control the display of diagnostics.
  718. *
  719. * The values in this enum are meant to be combined to customize the
  720. * behavior of \c clang_formatDiagnostic().
  721. */
  722. enum CXDiagnosticDisplayOptions {
  723. /**
  724. * \brief Display the source-location information where the
  725. * diagnostic was located.
  726. *
  727. * When set, diagnostics will be prefixed by the file, line, and
  728. * (optionally) column to which the diagnostic refers. For example,
  729. *
  730. * \code
  731. * test.c:28: warning: extra tokens at end of #endif directive
  732. * \endcode
  733. *
  734. * This option corresponds to the clang flag \c -fshow-source-location.
  735. */
  736. CXDiagnostic_DisplaySourceLocation = 0x01,
  737. /**
  738. * \brief If displaying the source-location information of the
  739. * diagnostic, also include the column number.
  740. *
  741. * This option corresponds to the clang flag \c -fshow-column.
  742. */
  743. CXDiagnostic_DisplayColumn = 0x02,
  744. /**
  745. * \brief If displaying the source-location information of the
  746. * diagnostic, also include information about source ranges in a
  747. * machine-parsable format.
  748. *
  749. * This option corresponds to the clang flag
  750. * \c -fdiagnostics-print-source-range-info.
  751. */
  752. CXDiagnostic_DisplaySourceRanges = 0x04,
  753. /**
  754. * \brief Display the option name associated with this diagnostic, if any.
  755. *
  756. * The option name displayed (e.g., -Wconversion) will be placed in brackets
  757. * after the diagnostic text. This option corresponds to the clang flag
  758. * \c -fdiagnostics-show-option.
  759. */
  760. CXDiagnostic_DisplayOption = 0x08,
  761. /**
  762. * \brief Display the category number associated with this diagnostic, if any.
  763. *
  764. * The category number is displayed within brackets after the diagnostic text.
  765. * This option corresponds to the clang flag
  766. * \c -fdiagnostics-show-category=id.
  767. */
  768. CXDiagnostic_DisplayCategoryId = 0x10,
  769. /**
  770. * \brief Display the category name associated with this diagnostic, if any.
  771. *
  772. * The category name is displayed within brackets after the diagnostic text.
  773. * This option corresponds to the clang flag
  774. * \c -fdiagnostics-show-category=name.
  775. */
  776. CXDiagnostic_DisplayCategoryName = 0x20
  777. };
  778. /**
  779. * \brief Format the given diagnostic in a manner that is suitable for display.
  780. *
  781. * This routine will format the given diagnostic to a string, rendering
  782. * the diagnostic according to the various options given. The
  783. * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
  784. * options that most closely mimics the behavior of the clang compiler.
  785. *
  786. * \param Diagnostic The diagnostic to print.
  787. *
  788. * \param Options A set of options that control the diagnostic display,
  789. * created by combining \c CXDiagnosticDisplayOptions values.
  790. *
  791. * \returns A new string containing for formatted diagnostic.
  792. */
  793. CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
  794. unsigned Options);
  795. /**
  796. * \brief Retrieve the set of display options most similar to the
  797. * default behavior of the clang compiler.
  798. *
  799. * \returns A set of display options suitable for use with \c
  800. * clang_formatDiagnostic().
  801. */
  802. CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
  803. /**
  804. * \brief Determine the severity of the given diagnostic.
  805. */
  806. CINDEX_LINKAGE enum CXDiagnosticSeverity
  807. clang_getDiagnosticSeverity(CXDiagnostic);
  808. /**
  809. * \brief Retrieve the source location of the given diagnostic.
  810. *
  811. * This location is where Clang would print the caret ('^') when
  812. * displaying the diagnostic on the command line.
  813. */
  814. CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
  815. /**
  816. * \brief Retrieve the text of the given diagnostic.
  817. */
  818. CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
  819. /**
  820. * \brief Retrieve the name of the command-line option that enabled this
  821. * diagnostic.
  822. *
  823. * \param Diag The diagnostic to be queried.
  824. *
  825. * \param Disable If non-NULL, will be set to the option that disables this
  826. * diagnostic (if any).
  827. *
  828. * \returns A string that contains the command-line option used to enable this
  829. * warning, such as "-Wconversion" or "-pedantic".
  830. */
  831. CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
  832. CXString *Disable);
  833. /**
  834. * \brief Retrieve the category number for this diagnostic.
  835. *
  836. * Diagnostics can be categorized into groups along with other, related
  837. * diagnostics (e.g., diagnostics under the same warning flag). This routine
  838. * retrieves the category number for the given diagnostic.
  839. *
  840. * \returns The number of the category that contains this diagnostic, or zero
  841. * if this diagnostic is uncategorized.
  842. */
  843. CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
  844. /**
  845. * \brief Retrieve the name of a particular diagnostic category. This
  846. * is now deprecated. Use clang_getDiagnosticCategoryText()
  847. * instead.
  848. *
  849. * \param Category A diagnostic category number, as returned by
  850. * \c clang_getDiagnosticCategory().
  851. *
  852. * \returns The name of the given diagnostic category.
  853. */
  854. CINDEX_DEPRECATED CINDEX_LINKAGE
  855. CXString clang_getDiagnosticCategoryName(unsigned Category);
  856. /**
  857. * \brief Retrieve the diagnostic category text for a given diagnostic.
  858. *
  859. * \returns The text of the given diagnostic category.
  860. */
  861. CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
  862. /**
  863. * \brief Determine the number of source ranges associated with the given
  864. * diagnostic.
  865. */
  866. CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
  867. /**
  868. * \brief Retrieve a source range associated with the diagnostic.
  869. *
  870. * A diagnostic's source ranges highlight important elements in the source
  871. * code. On the command line, Clang displays source ranges by
  872. * underlining them with '~' characters.
  873. *
  874. * \param Diagnostic the diagnostic whose range is being extracted.
  875. *
  876. * \param Range the zero-based index specifying which range to
  877. *
  878. * \returns the requested source range.
  879. */
  880. CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
  881. unsigned Range);
  882. /**
  883. * \brief Determine the number of fix-it hints associated with the
  884. * given diagnostic.
  885. */
  886. CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
  887. /**
  888. * \brief Retrieve the replacement information for a given fix-it.
  889. *
  890. * Fix-its are described in terms of a source range whose contents
  891. * should be replaced by a string. This approach generalizes over
  892. * three kinds of operations: removal of source code (the range covers
  893. * the code to be removed and the replacement string is empty),
  894. * replacement of source code (the range covers the code to be
  895. * replaced and the replacement string provides the new code), and
  896. * insertion (both the start and end of the range point at the
  897. * insertion location, and the replacement string provides the text to
  898. * insert).
  899. *
  900. * \param Diagnostic The diagnostic whose fix-its are being queried.
  901. *
  902. * \param FixIt The zero-based index of the fix-it.
  903. *
  904. * \param ReplacementRange The source range whose contents will be
  905. * replaced with the returned replacement string. Note that source
  906. * ranges are half-open ranges [a, b), so the source code should be
  907. * replaced from a and up to (but not including) b.
  908. *
  909. * \returns A string containing text that should be replace the source
  910. * code indicated by the \c ReplacementRange.
  911. */
  912. CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
  913. unsigned FixIt,
  914. CXSourceRange *ReplacementRange);
  915. /**
  916. * @}
  917. */
  918. /**
  919. * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
  920. *
  921. * The routines in this group provide the ability to create and destroy
  922. * translation units from files, either by parsing the contents of the files or
  923. * by reading in a serialized representation of a translation unit.
  924. *
  925. * @{
  926. */
  927. /**
  928. * \brief Get the original translation unit source file name.
  929. */
  930. CINDEX_LINKAGE CXString
  931. clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
  932. /**
  933. * \brief Return the CXTranslationUnit for a given source file and the provided
  934. * command line arguments one would pass to the compiler.
  935. *
  936. * Note: The 'source_filename' argument is optional. If the caller provides a
  937. * NULL pointer, the name of the source file is expected to reside in the
  938. * specified command line arguments.
  939. *
  940. * Note: When encountered in 'clang_command_line_args', the following options
  941. * are ignored:
  942. *
  943. * '-c'
  944. * '-emit-ast'
  945. * '-fsyntax-only'
  946. * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
  947. *
  948. * \param CIdx The index object with which the translation unit will be
  949. * associated.
  950. *
  951. * \param source_filename The name of the source file to load, or NULL if the
  952. * source file is included in \p clang_command_line_args.
  953. *
  954. * \param num_clang_command_line_args The number of command-line arguments in
  955. * \p clang_command_line_args.
  956. *
  957. * \param clang_command_line_args The command-line arguments that would be
  958. * passed to the \c clang executable if it were being invoked out-of-process.
  959. * These command-line options will be parsed and will affect how the translation
  960. * unit is parsed. Note that the following options are ignored: '-c',
  961. * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
  962. *
  963. * \param num_unsaved_files the number of unsaved file entries in \p
  964. * unsaved_files.
  965. *
  966. * \param unsaved_files the files that have not yet been saved to disk
  967. * but may be required for code completion, including the contents of
  968. * those files. The contents and name of these files (as specified by
  969. * CXUnsavedFile) are copied when necessary, so the client only needs to
  970. * guarantee their validity until the call to this function returns.
  971. */
  972. CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
  973. CXIndex CIdx,
  974. const char *source_filename,
  975. int num_clang_command_line_args,
  976. const char * const *clang_command_line_args,
  977. unsigned num_unsaved_files,
  978. struct CXUnsavedFile *unsaved_files);
  979. /**
  980. * \brief Same as \c clang_createTranslationUnit2, but returns
  981. * the \c CXTranslationUnit instead of an error code. In case of an error this
  982. * routine returns a \c NULL \c CXTranslationUnit, without further detailed
  983. * error codes.
  984. */
  985. CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
  986. CXIndex CIdx,
  987. const char *ast_filename);
  988. /**
  989. * \brief Create a translation unit from an AST file (\c -emit-ast).
  990. *
  991. * \param[out] out_TU A non-NULL pointer to store the created
  992. * \c CXTranslationUnit.
  993. *
  994. * \returns Zero on success, otherwise returns an error code.
  995. */
  996. CINDEX_LINKAGE enum CXErrorCode clang_createTranslationUnit2(
  997. CXIndex CIdx,
  998. const char *ast_filename,
  999. CXTranslationUnit *out_TU);
  1000. /**
  1001. * \brief Flags that control the creation of translation units.
  1002. *
  1003. * The enumerators in this enumeration type are meant to be bitwise
  1004. * ORed together to specify which options should be used when
  1005. * constructing the translation unit.
  1006. */
  1007. enum CXTranslationUnit_Flags {
  1008. /**
  1009. * \brief Used to indicate that no special translation-unit options are
  1010. * needed.
  1011. */
  1012. CXTranslationUnit_None = 0x0,
  1013. /**
  1014. * \brief Used to indicate that the parser should construct a "detailed"
  1015. * preprocessing record, including all macro definitions and instantiations.
  1016. *
  1017. * Constructing a detailed preprocessing record requires more memory
  1018. * and time to parse, since the information contained in the record
  1019. * is usually not retained. However, it can be useful for
  1020. * applications that require more detailed information about the
  1021. * behavior of the preprocessor.
  1022. */
  1023. CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
  1024. /**
  1025. * \brief Used to indicate that the translation unit is incomplete.
  1026. *
  1027. * When a translation unit is considered "incomplete", semantic
  1028. * analysis that is typically performed at the end of the
  1029. * translation unit will be suppressed. For example, this suppresses
  1030. * the completion of tentative declarations in C and of
  1031. * instantiation of implicitly-instantiation function templates in
  1032. * C++. This option is typically used when parsing a header with the
  1033. * intent of producing a precompiled header.
  1034. */
  1035. CXTranslationUnit_Incomplete = 0x02,
  1036. /**
  1037. * \brief Used to indicate that the translation unit should be built with an
  1038. * implicit precompiled header for the preamble.
  1039. *
  1040. * An implicit precompiled header is used as an optimization when a
  1041. * particular translation unit is likely to be reparsed many times
  1042. * when the sources aren't changing that often. In this case, an
  1043. * implicit precompiled header will be built containing all of the
  1044. * initial includes at the top of the main file (what we refer to as
  1045. * the "preamble" of the file). In subsequent parses, if the
  1046. * preamble or the files in it have not changed, \c
  1047. * clang_reparseTranslationUnit() will re-use the implicit
  1048. * precompiled header to improve parsing performance.
  1049. */
  1050. CXTranslationUnit_PrecompiledPreamble = 0x04,
  1051. /**
  1052. * \brief Used to indicate that the translation unit should cache some
  1053. * code-completion results with each reparse of the source file.
  1054. *
  1055. * Caching of code-completion results is a performance optimization that
  1056. * introduces some overhead to reparsing but improves the performance of
  1057. * code-completion operations.
  1058. */
  1059. CXTranslationUnit_CacheCompletionResults = 0x08,
  1060. /**
  1061. * \brief Used to indicate that the translation unit will be serialized with
  1062. * \c clang_saveTranslationUnit.
  1063. *
  1064. * This option is typically used when parsing a header with the intent of
  1065. * producing a precompiled header.
  1066. */
  1067. CXTranslationUnit_ForSerialization = 0x10,
  1068. /**
  1069. * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
  1070. *
  1071. * Note: this is a *temporary* option that is available only while
  1072. * we are testing C++ precompiled preamble support. It is deprecated.
  1073. */
  1074. CXTranslationUnit_CXXChainedPCH = 0x20,
  1075. /**
  1076. * \brief Used to indicate that function/method bodies should be skipped while
  1077. * parsing.
  1078. *
  1079. * This option can be used to search for declarations/definitions while
  1080. * ignoring the usages.
  1081. */
  1082. CXTranslationUnit_SkipFunctionBodies = 0x40,
  1083. /**
  1084. * \brief Used to indicate that brief documentation comments should be
  1085. * included into the set of code completions returned from this translation
  1086. * unit.
  1087. */
  1088. CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
  1089. };
  1090. /**
  1091. * \brief Returns the set of flags that is suitable for parsing a translation
  1092. * unit that is being edited.
  1093. *
  1094. * The set of flags returned provide options for \c clang_parseTranslationUnit()
  1095. * to indicate that the translation unit is likely to be reparsed many times,
  1096. * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
  1097. * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
  1098. * set contains an unspecified set of optimizations (e.g., the precompiled
  1099. * preamble) geared toward improving the performance of these routines. The
  1100. * set of optimizations enabled may change from one version to the next.
  1101. */
  1102. CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
  1103. /**
  1104. * \brief Same as \c clang_parseTranslationUnit2, but returns
  1105. * the \c CXTranslationUnit instead of an error code. In case of an error this
  1106. * routine returns a \c NULL \c CXTranslationUnit, without further detailed
  1107. * error codes.
  1108. */
  1109. CINDEX_LINKAGE CXTranslationUnit
  1110. clang_parseTranslationUnit(CXIndex CIdx,
  1111. const char *source_filename,
  1112. const char *const *command_line_args,
  1113. int num_command_line_args,
  1114. struct CXUnsavedFile *unsaved_files,
  1115. unsigned num_unsaved_files,
  1116. unsigned options);
  1117. /**
  1118. * \brief Parse the given source file and the translation unit corresponding
  1119. * to that file.
  1120. *
  1121. * This routine is the main entry point for the Clang C API, providing the
  1122. * ability to parse a source file into a translation unit that can then be
  1123. * queried by other functions in the API. This routine accepts a set of
  1124. * command-line arguments so that the compilation can be configured in the same
  1125. * way that the compiler is configured on the command line.
  1126. *
  1127. * \param CIdx The index object with which the translation unit will be
  1128. * associated.
  1129. *
  1130. * \param source_filename The name of the source file to load, or NULL if the
  1131. * source file is included in \c command_line_args.
  1132. *
  1133. * \param command_line_args The command-line arguments that would be
  1134. * passed to the \c clang executable if it were being invoked out-of-process.
  1135. * These command-line options will be parsed and will affect how the translation
  1136. * unit is parsed. Note that the following options are ignored: '-c',
  1137. * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
  1138. *
  1139. * \param num_command_line_args The number of command-line arguments in
  1140. * \c command_line_args.
  1141. *
  1142. * \param unsaved_files the files that have not yet been saved to disk
  1143. * but may be required for parsing, including the contents of
  1144. * those files. The contents and name of these files (as specified by
  1145. * CXUnsavedFile) are copied when necessary, so the client only needs to
  1146. * guarantee their validity until the call to this function returns.
  1147. *
  1148. * \param num_unsaved_files the number of unsaved file entries in \p
  1149. * unsaved_files.
  1150. *
  1151. * \param options A bitmask of options that affects how the translation unit
  1152. * is managed but not its compilation. This should be a bitwise OR of the
  1153. * CXTranslationUnit_XXX flags.
  1154. *
  1155. * \param[out] out_TU A non-NULL pointer to store the created
  1156. * \c CXTranslationUnit, describing the parsed code and containing any
  1157. * diagnostics produced by the compiler.
  1158. *
  1159. * \returns Zero on success, otherwise returns an error code.
  1160. */
  1161. CINDEX_LINKAGE enum CXErrorCode
  1162. clang_parseTranslationUnit2(CXIndex CIdx,
  1163. const char *source_filename,
  1164. const char *const *command_line_args,
  1165. int num_command_line_args,
  1166. struct CXUnsavedFile *unsaved_files,
  1167. unsigned num_unsaved_files,
  1168. unsigned options,
  1169. CXTranslationUnit *out_TU);
  1170. /**
  1171. * \brief Flags that control how translation units are saved.
  1172. *
  1173. * The enumerators in this enumeration type are meant to be bitwise
  1174. * ORed together to specify which options should be used when
  1175. * saving the translation unit.
  1176. */
  1177. enum CXSaveTranslationUnit_Flags {
  1178. /**
  1179. * \brief Used to indicate that no special saving options are needed.
  1180. */
  1181. CXSaveTranslationUnit_None = 0x0
  1182. };
  1183. /**
  1184. * \brief Returns the set of flags that is suitable for saving a translation
  1185. * unit.
  1186. *
  1187. * The set of flags returned provide options for
  1188. * \c clang_saveTranslationUnit() by default. The returned flag
  1189. * set contains an unspecified set of options that save translation units with
  1190. * the most commonly-requested data.
  1191. */
  1192. CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
  1193. /**
  1194. * \brief Describes the kind of error that occurred (if any) in a call to
  1195. * \c clang_saveTranslationUnit().
  1196. */
  1197. enum CXSaveError {
  1198. /**
  1199. * \brief Indicates that no error occurred while saving a translation unit.
  1200. */
  1201. CXSaveError_None = 0,
  1202. /**
  1203. * \brief Indicates that an unknown error occurred while attempting to save
  1204. * the file.
  1205. *
  1206. * This error typically indicates that file I/O failed when attempting to
  1207. * write the file.
  1208. */
  1209. CXSaveError_Unknown = 1,
  1210. /**
  1211. * \brief Indicates that errors during translation prevented this attempt
  1212. * to save the translation unit.
  1213. *
  1214. * Errors that prevent the translation unit from being saved can be
  1215. * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
  1216. */
  1217. CXSaveError_TranslationErrors = 2,
  1218. /**
  1219. * \brief Indicates that the translation unit to be saved was somehow
  1220. * invalid (e.g., NULL).
  1221. */
  1222. CXSaveError_InvalidTU = 3
  1223. };
  1224. /**
  1225. * \brief Saves a translation unit into a serialized representation of
  1226. * that translation unit on disk.
  1227. *
  1228. * Any translation unit that was parsed without error can be saved
  1229. * into a file. The translation unit can then be deserialized into a
  1230. * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
  1231. * if it is an incomplete translation unit that corresponds to a
  1232. * header, used as a precompiled header when parsing other translation
  1233. * units.
  1234. *
  1235. * \param TU The translation unit to save.
  1236. *
  1237. * \param FileName The file to which the translation unit will be saved.
  1238. *
  1239. * \param options A bitmask of options that affects how the translation unit
  1240. * is saved. This should be a bitwise OR of the
  1241. * CXSaveTranslationUnit_XXX flags.
  1242. *
  1243. * \returns A value that will match one of the enumerators of the CXSaveError
  1244. * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
  1245. * saved successfully, while a non-zero value indicates that a problem occurred.
  1246. */
  1247. CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
  1248. const char *FileName,
  1249. unsigned options);
  1250. /**
  1251. * \brief Destroy the specified CXTranslationUnit object.
  1252. */
  1253. CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
  1254. /**
  1255. * \brief Flags that control the reparsing of translation units.
  1256. *
  1257. * The enumerators in this enumeration type are meant to be bitwise
  1258. * ORed together to specify which options should be used when
  1259. * reparsing the translation unit.
  1260. */
  1261. enum CXReparse_Flags {
  1262. /**
  1263. * \brief Used to indicate that no special reparsing options are needed.
  1264. */
  1265. CXReparse_None = 0x0
  1266. };
  1267. /**
  1268. * \brief Returns the set of flags that is suitable for reparsing a translation
  1269. * unit.
  1270. *
  1271. * The set of flags returned provide options for
  1272. * \c clang_reparseTranslationUnit() by default. The returned flag
  1273. * set contains an unspecified set of optimizations geared toward common uses
  1274. * of reparsing. The set of optimizations enabled may change from one version
  1275. * to the next.
  1276. */
  1277. CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
  1278. /**
  1279. * \brief Reparse the source files that produced this translation unit.
  1280. *
  1281. * This routine can be used to re-parse the source files that originally
  1282. * created the given translation unit, for example because those source files
  1283. * have changed (either on disk or as passed via \p unsaved_files). The
  1284. * source code will be reparsed with the same command-line options as it
  1285. * was originally parsed.
  1286. *
  1287. * Reparsing a translation unit invalidates all cursors and source locations
  1288. * that refer into that translation unit. This makes reparsing a translation
  1289. * unit semantically equivalent to destroying the translation unit and then
  1290. * creating a new translation unit with the same command-line arguments.
  1291. * However, it may be more efficient to reparse a translation
  1292. * unit using this routine.
  1293. *
  1294. * \param TU The translation unit whose contents will be re-parsed. The
  1295. * translation unit must originally have been built with
  1296. * \c clang_createTranslationUnitFromSourceFile().
  1297. *
  1298. * \param num_unsaved_files The number of unsaved file entries in \p
  1299. * unsaved_files.
  1300. *
  1301. * \param unsaved_files The files that have not yet been saved to disk
  1302. * but may be required for parsing, including the contents of
  1303. * those files. The contents and name of these files (as specified by
  1304. * CXUnsavedFile) are copied when necessary, so the client only needs to
  1305. * guarantee their validity until the call to this function returns.
  1306. *
  1307. * \param options A bitset of options composed of the flags in CXReparse_Flags.
  1308. * The function \c clang_defaultReparseOptions() produces a default set of
  1309. * options recommended for most uses, based on the translation unit.
  1310. *
  1311. * \returns 0 if the sources could be reparsed. A non-zero error code will be
  1312. * returned if reparsing was impossible, such that the translation unit is
  1313. * invalid. In such cases, the only valid call for \c TU is
  1314. * \c clang_disposeTranslationUnit(TU). The error codes returned by this
  1315. * routine are described by the \c CXErrorCode enum.
  1316. */
  1317. CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
  1318. unsigned num_unsaved_files,
  1319. struct CXUnsavedFile *unsaved_files,
  1320. unsigned options);
  1321. /**
  1322. * \brief Categorizes how memory is being used by a translation unit.
  1323. */
  1324. enum CXTUResourceUsageKind {
  1325. CXTUResourceUsage_AST = 1,
  1326. CXTUResourceUsage_Identifiers = 2,
  1327. CXTUResourceUsage_Selectors = 3,
  1328. CXTUResourceUsage_GlobalCompletionResults = 4,
  1329. CXTUResourceUsage_SourceManagerContentCache = 5,
  1330. CXTUResourceUsage_AST_SideTables = 6,
  1331. CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
  1332. CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
  1333. CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
  1334. CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
  1335. CXTUResourceUsage_Preprocessor = 11,
  1336. CXTUResourceUsage_PreprocessingRecord = 12,
  1337. CXTUResourceUsage_SourceManager_DataStructures = 13,
  1338. CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
  1339. CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
  1340. CXTUResourceUsage_MEMORY_IN_BYTES_END =
  1341. CXTUResourceUsage_Preprocessor_HeaderSearch,
  1342. CXTUResourceUsage_First = CXTUResourceUsage_AST,
  1343. CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
  1344. };
  1345. /**
  1346. * \brief Returns the human-readable null-terminated C string that represents
  1347. * the name of the memory category. This string should never be freed.
  1348. */
  1349. CINDEX_LINKAGE
  1350. const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
  1351. typedef struct CXTUResourceUsageEntry {
  1352. /* \brief The memory usage category. */
  1353. enum CXTUResourceUsageKind kind;
  1354. /* \brief Amount of resources used.
  1355. The units will depend on the resource kind. */
  1356. unsigned long amount;
  1357. } CXTUResourceUsageEntry;
  1358. /**
  1359. * \brief The memory usage of a CXTranslationUnit, broken into categories.
  1360. */
  1361. typedef struct CXTUResourceUsage {
  1362. /* \brief Private data member, used for queries. */
  1363. void *data;
  1364. /* \brief The number of entries in the 'entries' array. */
  1365. unsigned numEntries;
  1366. /* \brief An array of key-value pairs, representing the breakdown of memory
  1367. usage. */
  1368. CXTUResourceUsageEntry *entries;
  1369. } CXTUResourceUsage;
  1370. /**
  1371. * \brief Return the memory usage of a translation unit. This object
  1372. * should be released with clang_disposeCXTUResourceUsage().
  1373. */
  1374. CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
  1375. CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
  1376. /**
  1377. * @}
  1378. */
  1379. /**
  1380. * \brief Describes the kind of entity that a cursor refers to.
  1381. */
  1382. enum CXCursorKind {
  1383. /* Declarations */
  1384. /**
  1385. * \brief A declaration whose specific kind is not exposed via this
  1386. * interface.
  1387. *
  1388. * Unexposed declarations have the same operations as any other kind
  1389. * of declaration; one can extract their location information,
  1390. * spelling, find their definitions, etc. However, the specific kind
  1391. * of the declaration is not reported.
  1392. */
  1393. CXCursor_UnexposedDecl = 1,
  1394. /** \brief A C or C++ struct. */
  1395. CXCursor_StructDecl = 2,
  1396. /** \brief A C or C++ union. */
  1397. CXCursor_UnionDecl = 3,
  1398. /** \brief A C++ class. */
  1399. CXCursor_ClassDecl = 4,
  1400. /** \brief An enumeration. */
  1401. CXCursor_EnumDecl = 5,
  1402. /**
  1403. * \brief A field (in C) or non-static data member (in C++) in a
  1404. * struct, union, or C++ class.
  1405. */
  1406. CXCursor_FieldDecl = 6,
  1407. /** \brief An enumerator constant. */
  1408. CXCursor_EnumConstantDecl = 7,
  1409. /** \brief A function. */
  1410. CXCursor_FunctionDecl = 8,
  1411. /** \brief A variable. */
  1412. CXCursor_VarDecl = 9,
  1413. /** \brief A function or method parameter. */
  1414. CXCursor_ParmDecl = 10,
  1415. /** \brief An Objective-C \@interface. */
  1416. CXCursor_ObjCInterfaceDecl = 11,
  1417. /** \brief An Objective-C \@interface for a category. */
  1418. CXCursor_ObjCCategoryDecl = 12,
  1419. /** \brief An Objective-C \@protocol declaration. */
  1420. CXCursor_ObjCProtocolDecl = 13,
  1421. /** \brief An Objective-C \@property declaration. */
  1422. CXCursor_ObjCPropertyDecl = 14,
  1423. /** \brief An Objective-C instance variable. */
  1424. CXCursor_ObjCIvarDecl = 15,
  1425. /** \brief An Objective-C instance method. */
  1426. CXCursor_ObjCInstanceMethodDecl = 16,
  1427. /** \brief An Objective-C class method. */
  1428. CXCursor_ObjCClassMethodDecl = 17,
  1429. /** \brief An Objective-C \@implementation. */
  1430. CXCursor_ObjCImplementationDecl = 18,
  1431. /** \brief An Objective-C \@implementation for a category. */
  1432. CXCursor_ObjCCategoryImplDecl = 19,
  1433. /** \brief A typedef */
  1434. CXCursor_TypedefDecl = 20,
  1435. /** \brief A C++ class method. */
  1436. CXCursor_CXXMethod = 21,
  1437. /** \brief A C++ namespace. */
  1438. CXCursor_Namespace = 22,
  1439. /** \brief A linkage specification, e.g. 'extern "C"'. */
  1440. CXCursor_LinkageSpec = 23,
  1441. /** \brief A C++ constructor. */
  1442. CXCursor_Constructor = 24,
  1443. /** \brief A C++ destructor. */
  1444. CXCursor_Destructor = 25,
  1445. /** \brief A C++ conversion function. */
  1446. CXCursor_ConversionFunction = 26,
  1447. /** \brief A C++ template type parameter. */
  1448. CXCursor_TemplateTypeParameter = 27,
  1449. /** \brief A C++ non-type template parameter. */
  1450. CXCursor_NonTypeTemplateParameter = 28,
  1451. /** \brief A C++ template template parameter. */
  1452. CXCursor_TemplateTemplateParameter = 29,
  1453. /** \brief A C++ function template. */
  1454. CXCursor_FunctionTemplate = 30,
  1455. /** \brief A C++ class template. */
  1456. CXCursor_ClassTemplate = 31,
  1457. /** \brief A C++ class template partial specialization. */
  1458. CXCursor_ClassTemplatePartialSpecialization = 32,
  1459. /** \brief A C++ namespace alias declaration. */
  1460. CXCursor_NamespaceAlias = 33,
  1461. /** \brief A C++ using directive. */
  1462. CXCursor_UsingDirective = 34,
  1463. /** \brief A C++ using declaration. */
  1464. CXCursor_UsingDeclaration = 35,
  1465. /** \brief A C++ alias declaration */
  1466. CXCursor_TypeAliasDecl = 36,
  1467. /** \brief An Objective-C \@synthesize definition. */
  1468. CXCursor_ObjCSynthesizeDecl = 37,
  1469. /** \brief An Objective-C \@dynamic definition. */
  1470. CXCursor_ObjCDynamicDecl = 38,
  1471. /** \brief An access specifier. */
  1472. CXCursor_CXXAccessSpecifier = 39,
  1473. CXCursor_FirstDecl = CXCursor_UnexposedDecl,
  1474. CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
  1475. /* References */
  1476. CXCursor_FirstRef = 40, /* Decl references */
  1477. CXCursor_ObjCSuperClassRef = 40,
  1478. CXCursor_ObjCProtocolRef = 41,
  1479. CXCursor_ObjCClassRef = 42,
  1480. /**
  1481. * \brief A reference to a type declaration.
  1482. *
  1483. * A type reference occurs anywhere where a type is named but not
  1484. * declared. For example, given:
  1485. *
  1486. * \code
  1487. * typedef unsigned size_type;
  1488. * size_type size;
  1489. * \endcode
  1490. *
  1491. * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
  1492. * while the type of the variable "size" is referenced. The cursor
  1493. * referenced by the type of size is the typedef for size_type.
  1494. */
  1495. CXCursor_TypeRef = 43,
  1496. CXCursor_CXXBaseSpecifier = 44,
  1497. /**
  1498. * \brief A reference to a class template, function template, template
  1499. * template parameter, or class template partial specialization.
  1500. */
  1501. CXCursor_TemplateRef = 45,
  1502. /**
  1503. * \brief A reference to a namespace or namespace alias.
  1504. */
  1505. CXCursor_NamespaceRef = 46,
  1506. /**
  1507. * \brief A reference to a member of a struct, union, or class that occurs in
  1508. * some non-expression context, e.g., a designated initializer.
  1509. */
  1510. CXCursor_MemberRef = 47,
  1511. /**
  1512. * \brief A reference to a labeled statement.
  1513. *
  1514. * This cursor kind is used to describe the jump to "start_over" in the
  1515. * goto statement in the following example:
  1516. *
  1517. * \code
  1518. * start_over:
  1519. * ++counter;
  1520. *
  1521. * goto start_over;
  1522. * \endcode
  1523. *
  1524. * A label reference cursor refers to a label statement.
  1525. */
  1526. CXCursor_LabelRef = 48,
  1527. /**
  1528. * \brief A reference to a set of overloaded functions or function templates
  1529. * that has not yet been resolved to a specific function or function template.
  1530. *
  1531. * An overloaded declaration reference cursor occurs in C++ templates where
  1532. * a dependent name refers to a function. For example:
  1533. *
  1534. * \code
  1535. * template<typename T> void swap(T&, T&);
  1536. *
  1537. * struct X { ... };
  1538. * void swap(X&, X&);
  1539. *
  1540. * template<typename T>
  1541. * void reverse(T* first, T* last) {
  1542. * while (first < last - 1) {
  1543. * swap(*first, *--last);
  1544. * ++first;
  1545. * }
  1546. * }
  1547. *
  1548. * struct Y { };
  1549. * void swap(Y&, Y&);
  1550. * \endcode
  1551. *
  1552. * Here, the identifier "swap" is associated with an overloaded declaration
  1553. * reference. In the template definition, "swap" refers to either of the two
  1554. * "swap" functions declared above, so both results will be available. At
  1555. * instantiation time, "swap" may also refer to other functions found via
  1556. * argument-dependent lookup (e.g., the "swap" function at the end of the
  1557. * example).
  1558. *
  1559. * The functions \c clang_getNumOverloadedDecls() and
  1560. * \c clang_getOverloadedDecl() can be used to retrieve the definitions
  1561. * referenced by this cursor.
  1562. */
  1563. CXCursor_OverloadedDeclRef = 49,
  1564. /**
  1565. * \brief A reference to a variable that occurs in some non-expression
  1566. * context, e.g., a C++ lambda capture list.
  1567. */
  1568. CXCursor_VariableRef = 50,
  1569. CXCursor_LastRef = CXCursor_VariableRef,
  1570. /* Error conditions */
  1571. CXCursor_FirstInvalid = 70,
  1572. CXCursor_InvalidFile = 70,
  1573. CXCursor_NoDeclFound = 71,
  1574. CXCursor_NotImplemented = 72,
  1575. CXCursor_InvalidCode = 73,
  1576. CXCursor_LastInvalid = CXCursor_InvalidCode,
  1577. /* Expressions */
  1578. CXCursor_FirstExpr = 100,
  1579. /**
  1580. * \brief An expression whose specific kind is not exposed via this
  1581. * interface.
  1582. *
  1583. * Unexposed expressions have the same operations as any other kind
  1584. * of expression; one can extract their location information,
  1585. * spelling, children, etc. However, the specific kind of the
  1586. * expression is not reported.
  1587. */
  1588. CXCursor_UnexposedExpr = 100,
  1589. /**
  1590. * \brief An expression that refers to some value declaration, such
  1591. * as a function, variable, or enumerator.
  1592. */
  1593. CXCursor_DeclRefExpr = 101,
  1594. /**
  1595. * \brief An expression that refers to a member of a struct, union,
  1596. * class, Objective-C class, etc.
  1597. */
  1598. CXCursor_MemberRefExpr = 102,
  1599. /** \brief An expression that calls a function. */
  1600. CXCursor_CallExpr = 103,
  1601. /** \brief An expression that sends a message to an Objective-C
  1602. object or class. */
  1603. CXCursor_ObjCMessageExpr = 104,
  1604. /** \brief An expression that represents a block literal. */
  1605. CXCursor_BlockExpr = 105,
  1606. /** \brief An integer literal.
  1607. */
  1608. CXCursor_IntegerLiteral = 106,
  1609. /** \brief A floating point number literal.
  1610. */
  1611. CXCursor_FloatingLiteral = 107,
  1612. /** \brief An imaginary number literal.
  1613. */
  1614. CXCursor_ImaginaryLiteral = 108,
  1615. /** \brief A string literal.
  1616. */
  1617. CXCursor_StringLiteral = 109,
  1618. /** \brief A character literal.
  1619. */
  1620. CXCursor_CharacterLiteral = 110,
  1621. /** \brief A parenthesized expression, e.g. "(1)".
  1622. *
  1623. * This AST node is only formed if full location information is requested.
  1624. */
  1625. CXCursor_ParenExpr = 111,
  1626. /** \brief This represents the unary-expression's (except sizeof and
  1627. * alignof).
  1628. */
  1629. CXCursor_UnaryOperator = 112,
  1630. /** \brief [C99 6.5.2.1] Array Subscripting.
  1631. */
  1632. CXCursor_ArraySubscriptExpr = 113,
  1633. /** \brief A builtin binary operation expression such as "x + y" or
  1634. * "x <= y".
  1635. */
  1636. CXCursor_BinaryOperator = 114,
  1637. /** \brief Compound assignment such as "+=".
  1638. */
  1639. CXCursor_CompoundAssignOperator = 115,
  1640. /** \brief The ?: ternary operator.
  1641. */
  1642. CXCursor_ConditionalOperator = 116,
  1643. /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
  1644. * (C++ [expr.cast]), which uses the syntax (Type)expr.
  1645. *
  1646. * For example: (int)f.
  1647. */
  1648. CXCursor_CStyleCastExpr = 117,
  1649. /** \brief [C99 6.5.2.5]
  1650. */
  1651. CXCursor_CompoundLiteralExpr = 118,
  1652. /** \brief Describes an C or C++ initializer list.
  1653. */
  1654. CXCursor_InitListExpr = 119,
  1655. /** \brief The GNU address of label extension, representing &&label.
  1656. */
  1657. CXCursor_AddrLabelExpr = 120,
  1658. /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
  1659. */
  1660. CXCursor_StmtExpr = 121,
  1661. /** \brief Represents a C11 generic selection.
  1662. */
  1663. CXCursor_GenericSelectionExpr = 122,
  1664. /** \brief Implements the GNU __null extension, which is a name for a null
  1665. * pointer constant that has integral type (e.g., int or long) and is the same
  1666. * size and alignment as a pointer.
  1667. *
  1668. * The __null extension is typically only used by system headers, which define
  1669. * NULL as __null in C++ rather than using 0 (which is an integer that may not
  1670. * match the size of a pointer).
  1671. */
  1672. CXCursor_GNUNullExpr = 123,
  1673. /** \brief C++'s static_cast<> expression.
  1674. */
  1675. CXCursor_CXXStaticCastExpr = 124,
  1676. /** \brief C++'s dynamic_cast<> expression.
  1677. */
  1678. CXCursor_CXXDynamicCastExpr = 125,
  1679. /** \brief C++'s reinterpret_cast<> expression.
  1680. */
  1681. CXCursor_CXXReinterpretCastExpr = 126,
  1682. /** \brief C++'s const_cast<> expression.
  1683. */
  1684. CXCursor_CXXConstCastExpr = 127,
  1685. /** \brief Represents an explicit C++ type conversion that uses "functional"
  1686. * notion (C++ [expr.type.conv]).
  1687. *
  1688. * Example:
  1689. * \code
  1690. * x = int(0.5);
  1691. * \endcode
  1692. */
  1693. CXCursor_CXXFunctionalCastExpr = 128,
  1694. /** \brief A C++ typeid expression (C++ [expr.typeid]).
  1695. */
  1696. CXCursor_CXXTypeidExpr = 129,
  1697. /** \brief [C++ 2.13.5] C++ Boolean Literal.
  1698. */
  1699. CXCursor_CXXBoolLiteralExpr = 130,
  1700. /** \brief [C++0x 2.14.7] C++ Pointer Literal.
  1701. */
  1702. CXCursor_CXXNullPtrLiteralExpr = 131,
  1703. /** \brief Represents the "this" expression in C++
  1704. */
  1705. CXCursor_CXXThisExpr = 132,
  1706. /** \brief [C++ 15] C++ Throw Expression.
  1707. *
  1708. * This handles 'throw' and 'throw' assignment-expression. When
  1709. * assignment-expression isn't present, Op will be null.
  1710. */
  1711. CXCursor_CXXThrowExpr = 133,
  1712. /** \brief A new expression for memory allocation and constructor calls, e.g:
  1713. * "new CXXNewExpr(foo)".
  1714. */
  1715. CXCursor_CXXNewExpr = 134,
  1716. /** \brief A delete expression for memory deallocation and destructor calls,
  1717. * e.g. "delete[] pArray".
  1718. */
  1719. CXCursor_CXXDeleteExpr = 135,
  1720. /** \brief A unary expression.
  1721. */
  1722. CXCursor_UnaryExpr = 136,
  1723. /** \brief An Objective-C string literal i.e. @"foo".
  1724. */
  1725. CXCursor_ObjCStringLiteral = 137,
  1726. /** \brief An Objective-C \@encode expression.
  1727. */
  1728. CXCursor_ObjCEncodeExpr = 138,
  1729. /** \brief An Objective-C \@selector expression.
  1730. */
  1731. CXCursor_ObjCSelectorExpr = 139,
  1732. /** \brief An Objective-C \@protocol expression.
  1733. */
  1734. CXCursor_ObjCProtocolExpr = 140,
  1735. /** \brief An Objective-C "bridged" cast expression, which casts between
  1736. * Objective-C pointers and C pointers, transferring ownership in the process.
  1737. *
  1738. * \code
  1739. * NSString *str = (__bridge_transfer NSString *)CFCreateString();
  1740. * \endcode
  1741. */
  1742. CXCursor_ObjCBridgedCastExpr = 141,
  1743. /** \brief Represents a C++0x pack expansion that produces a sequence of
  1744. * expressions.
  1745. *
  1746. * A pack expansion expression contains a pattern (which itself is an
  1747. * expression) followed by an ellipsis. For example:
  1748. *
  1749. * \code
  1750. * template<typename F, typename ...Types>
  1751. * void forward(F f, Types &&...args) {
  1752. * f(static_cast<Types&&>(args)...);
  1753. * }
  1754. * \endcode
  1755. */
  1756. CXCursor_PackExpansionExpr = 142,
  1757. /** \brief Represents an expression that computes the length of a parameter
  1758. * pack.
  1759. *
  1760. * \code
  1761. * template<typename ...Types>
  1762. * struct count {
  1763. * static const unsigned value = sizeof...(Types);
  1764. * };
  1765. * \endcode
  1766. */
  1767. CXCursor_SizeOfPackExpr = 143,
  1768. /* \brief Represents a C++ lambda expression that produces a local function
  1769. * object.
  1770. *
  1771. * \code
  1772. * void abssort(float *x, unsigned N) {
  1773. * std::sort(x, x + N,
  1774. * [](float a, float b) {
  1775. * return std::abs(a) < std::abs(b);
  1776. * });
  1777. * }
  1778. * \endcode
  1779. */
  1780. CXCursor_LambdaExpr = 144,
  1781. /** \brief Objective-c Boolean Literal.
  1782. */
  1783. CXCursor_ObjCBoolLiteralExpr = 145,
  1784. /** \brief Represents the "self" expression in an Objective-C method.
  1785. */
  1786. CXCursor_ObjCSelfExpr = 146,
  1787. CXCursor_LastExpr = CXCursor_ObjCSelfExpr,
  1788. /* Statements */
  1789. CXCursor_FirstStmt = 200,
  1790. /**
  1791. * \brief A statement whose specific kind is not exposed via this
  1792. * interface.
  1793. *
  1794. * Unexposed statements have the same operations as any other kind of
  1795. * statement; one can extract their location information, spelling,
  1796. * children, etc. However, the specific kind of the statement is not
  1797. * reported.
  1798. */
  1799. CXCursor_UnexposedStmt = 200,
  1800. /** \brief A labelled statement in a function.
  1801. *
  1802. * This cursor kind is used to describe the "start_over:" label statement in
  1803. * the following example:
  1804. *
  1805. * \code
  1806. * start_over:
  1807. * ++counter;
  1808. * \endcode
  1809. *
  1810. */
  1811. CXCursor_LabelStmt = 201,
  1812. /** \brief A group of statements like { stmt stmt }.
  1813. *
  1814. * This cursor kind is used to describe compound statements, e.g. function
  1815. * bodies.
  1816. */
  1817. CXCursor_CompoundStmt = 202,
  1818. /** \brief A case statement.
  1819. */
  1820. CXCursor_CaseStmt = 203,
  1821. /** \brief A default statement.
  1822. */
  1823. CXCursor_DefaultStmt = 204,
  1824. /** \brief An if statement
  1825. */
  1826. CXCursor_IfStmt = 205,
  1827. /** \brief A switch statement.
  1828. */
  1829. CXCursor_SwitchStmt = 206,
  1830. /** \brief A while statement.
  1831. */
  1832. CXCursor_WhileStmt = 207,
  1833. /** \brief A do statement.
  1834. */
  1835. CXCursor_DoStmt = 208,
  1836. /** \brief A for statement.
  1837. */
  1838. CXCursor_ForStmt = 209,
  1839. /** \brief A goto statement.
  1840. */
  1841. CXCursor_GotoStmt = 210,
  1842. /** \brief An indirect goto statement.
  1843. */
  1844. CXCursor_IndirectGotoStmt = 211,
  1845. /** \brief A continue statement.
  1846. */
  1847. CXCursor_ContinueStmt = 212,
  1848. /** \brief A break statement.
  1849. */
  1850. CXCursor_BreakStmt = 213,
  1851. /** \brief A return statement.
  1852. */
  1853. CXCursor_ReturnStmt = 214,
  1854. /** \brief A GCC inline assembly statement extension.
  1855. */
  1856. CXCursor_GCCAsmStmt = 215,
  1857. CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
  1858. /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
  1859. */
  1860. CXCursor_ObjCAtTryStmt = 216,
  1861. /** \brief Objective-C's \@catch statement.
  1862. */
  1863. CXCursor_ObjCAtCatchStmt = 217,
  1864. /** \brief Objective-C's \@finally statement.
  1865. */
  1866. CXCursor_ObjCAtFinallyStmt = 218,
  1867. /** \brief Objective-C's \@throw statement.
  1868. */
  1869. CXCursor_ObjCAtThrowStmt = 219,
  1870. /** \brief Objective-C's \@synchronized statement.
  1871. */
  1872. CXCursor_ObjCAtSynchronizedStmt = 220,
  1873. /** \brief Objective-C's autorelease pool statement.
  1874. */
  1875. CXCursor_ObjCAutoreleasePoolStmt = 221,
  1876. /** \brief Objective-C's collection statement.
  1877. */
  1878. CXCursor_ObjCForCollectionStmt = 222,
  1879. /** \brief C++'s catch statement.
  1880. */
  1881. CXCursor_CXXCatchStmt = 223,
  1882. /** \brief C++'s try statement.
  1883. */
  1884. CXCursor_CXXTryStmt = 224,
  1885. /** \brief C++'s for (* : *) statement.
  1886. */
  1887. CXCursor_CXXForRangeStmt = 225,
  1888. /** \brief Windows Structured Exception Handling's try statement.
  1889. */
  1890. CXCursor_SEHTryStmt = 226,
  1891. /** \brief Windows Structured Exception Handling's except statement.
  1892. */
  1893. CXCursor_SEHExceptStmt = 227,
  1894. /** \brief Windows Structured Exception Handling's finally statement.
  1895. */
  1896. CXCursor_SEHFinallyStmt = 228,
  1897. /** \brief A MS inline assembly statement extension.
  1898. */
  1899. CXCursor_MSAsmStmt = 229,
  1900. /** \brief The null statement ";": C99 6.8.3p3.
  1901. *
  1902. * This cursor kind is used to describe the null statement.
  1903. */
  1904. CXCursor_NullStmt = 230,
  1905. /** \brief Adaptor class for mixing declarations with statements and
  1906. * expressions.
  1907. */
  1908. CXCursor_DeclStmt = 231,
  1909. /** \brief OpenMP parallel directive.
  1910. */
  1911. CXCursor_OMPParallelDirective = 232,
  1912. /** \brief OpenMP SIMD directive.
  1913. */
  1914. CXCursor_OMPSimdDirective = 233,
  1915. /** \brief OpenMP for directive.
  1916. */
  1917. CXCursor_OMPForDirective = 234,
  1918. /** \brief OpenMP sections directive.
  1919. */
  1920. CXCursor_OMPSectionsDirective = 235,
  1921. /** \brief OpenMP section directive.
  1922. */
  1923. CXCursor_OMPSectionDirective = 236,
  1924. /** \brief OpenMP single directive.
  1925. */
  1926. CXCursor_OMPSingleDirective = 237,
  1927. /** \brief OpenMP parallel for directive.
  1928. */
  1929. CXCursor_OMPParallelForDirective = 238,
  1930. /** \brief OpenMP parallel sections directive.
  1931. */
  1932. CXCursor_OMPParallelSectionsDirective = 239,
  1933. /** \brief OpenMP task directive.
  1934. */
  1935. CXCursor_OMPTaskDirective = 240,
  1936. /** \brief OpenMP master directive.
  1937. */
  1938. CXCursor_OMPMasterDirective = 241,
  1939. /** \brief OpenMP critical directive.
  1940. */
  1941. CXCursor_OMPCriticalDirective = 242,
  1942. /** \brief OpenMP taskyield directive.
  1943. */
  1944. CXCursor_OMPTaskyieldDirective = 243,
  1945. /** \brief OpenMP barrier directive.
  1946. */
  1947. CXCursor_OMPBarrierDirective = 244,
  1948. /** \brief OpenMP taskwait directive.
  1949. */
  1950. CXCursor_OMPTaskwaitDirective = 245,
  1951. /** \brief OpenMP flush directive.
  1952. */
  1953. CXCursor_OMPFlushDirective = 246,
  1954. /** \brief Windows Structured Exception Handling's leave statement.
  1955. */
  1956. CXCursor_SEHLeaveStmt = 247,
  1957. /** \brief OpenMP ordered directive.
  1958. */
  1959. CXCursor_OMPOrderedDirective = 248,
  1960. /** \brief OpenMP atomic directive.
  1961. */
  1962. CXCursor_OMPAtomicDirective = 249,
  1963. /** \brief OpenMP for SIMD directive.
  1964. */
  1965. CXCursor_OMPForSimdDirective = 250,
  1966. /** \brief OpenMP parallel for SIMD directive.
  1967. */
  1968. CXCursor_OMPParallelForSimdDirective = 251,
  1969. /** \brief OpenMP target directive.
  1970. */
  1971. CXCursor_OMPTargetDirective = 252,
  1972. /** \brief OpenMP teams directive.
  1973. */
  1974. CXCursor_OMPTeamsDirective = 253,
  1975. /** \brief OpenMP taskgroup directive.
  1976. */
  1977. CXCursor_OMPTaskgroupDirective = 254,
  1978. /** \brief OpenMP cancellation point directive.
  1979. */
  1980. CXCursor_OMPCancellationPointDirective = 255,
  1981. /** \brief OpenMP cancel directive.
  1982. */
  1983. CXCursor_OMPCancelDirective = 256,
  1984. CXCursor_LastStmt = CXCursor_OMPCancelDirective,
  1985. /**
  1986. * \brief Cursor that represents the translation unit itself.
  1987. *
  1988. * The translation unit cursor exists primarily to act as the root
  1989. * cursor for traversing the contents of a translation unit.
  1990. */
  1991. CXCursor_TranslationUnit = 300,
  1992. /* Attributes */
  1993. CXCursor_FirstAttr = 400,
  1994. /**
  1995. * \brief An attribute whose specific kind is not exposed via this
  1996. * interface.
  1997. */
  1998. CXCursor_UnexposedAttr = 400,
  1999. CXCursor_IBActionAttr = 401,
  2000. CXCursor_IBOutletAttr = 402,
  2001. CXCursor_IBOutletCollectionAttr = 403,
  2002. CXCursor_CXXFinalAttr = 404,
  2003. CXCursor_CXXOverrideAttr = 405,
  2004. CXCursor_AnnotateAttr = 406,
  2005. CXCursor_AsmLabelAttr = 407,
  2006. CXCursor_PackedAttr = 408,
  2007. CXCursor_PureAttr = 409,
  2008. CXCursor_ConstAttr = 410,
  2009. CXCursor_NoDuplicateAttr = 411,
  2010. CXCursor_CUDAConstantAttr = 412,
  2011. CXCursor_CUDADeviceAttr = 413,
  2012. CXCursor_CUDAGlobalAttr = 414,
  2013. CXCursor_CUDAHostAttr = 415,
  2014. CXCursor_CUDASharedAttr = 416,
  2015. CXCursor_LastAttr = CXCursor_CUDASharedAttr,
  2016. /* Preprocessing */
  2017. CXCursor_PreprocessingDirective = 500,
  2018. CXCursor_MacroDefinition = 501,
  2019. CXCursor_MacroExpansion = 502,
  2020. CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
  2021. CXCursor_InclusionDirective = 503,
  2022. CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
  2023. CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
  2024. /* Extra Declarations */
  2025. /**
  2026. * \brief A module import declaration.
  2027. */
  2028. CXCursor_ModuleImportDecl = 600,
  2029. CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
  2030. CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl,
  2031. /**
  2032. * \brief A code completion overload candidate.
  2033. */
  2034. CXCursor_OverloadCandidate = 700
  2035. };
  2036. /**
  2037. * \brief A cursor representing some element in the abstract syntax tree for
  2038. * a translation unit.
  2039. *
  2040. * The cursor abstraction unifies the different kinds of entities in a
  2041. * program--declaration, statements, expressions, references to declarations,
  2042. * etc.--under a single "cursor" abstraction with a common set of operations.
  2043. * Common operation for a cursor include: getting the physical location in
  2044. * a source file where the cursor points, getting the name associated with a
  2045. * cursor, and retrieving cursors for any child nodes of a particular cursor.
  2046. *
  2047. * Cursors can be produced in two specific ways.
  2048. * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
  2049. * from which one can use clang_visitChildren() to explore the rest of the
  2050. * translation unit. clang_getCursor() maps from a physical source location
  2051. * to the entity that resides at that location, allowing one to map from the
  2052. * source code into the AST.
  2053. */
  2054. typedef struct {
  2055. enum CXCursorKind kind;
  2056. int xdata;
  2057. const void *data[3];
  2058. } CXCursor;
  2059. /**
  2060. * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
  2061. *
  2062. * @{
  2063. */
  2064. /**
  2065. * \brief Retrieve the NULL cursor, which represents no entity.
  2066. */
  2067. CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
  2068. /**
  2069. * \brief Retrieve the cursor that represents the given translation unit.
  2070. *
  2071. * The translation unit cursor can be used to start traversing the
  2072. * various declarations within the given translation unit.
  2073. */
  2074. CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
  2075. /**
  2076. * \brief Determine whether two cursors are equivalent.
  2077. */
  2078. CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
  2079. /**
  2080. * \brief Returns non-zero if \p cursor is null.
  2081. */
  2082. CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
  2083. /**
  2084. * \brief Compute a hash value for the given cursor.
  2085. */
  2086. CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
  2087. /**
  2088. * \brief Retrieve the kind of the given cursor.
  2089. */
  2090. CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
  2091. /**
  2092. * \brief Determine whether the given cursor kind represents a declaration.
  2093. */
  2094. CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
  2095. /**
  2096. * \brief Determine whether the given cursor kind represents a simple
  2097. * reference.
  2098. *
  2099. * Note that other kinds of cursors (such as expressions) can also refer to
  2100. * other cursors. Use clang_getCursorReferenced() to determine whether a
  2101. * particular cursor refers to another entity.
  2102. */
  2103. CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
  2104. /**
  2105. * \brief Determine whether the given cursor kind represents an expression.
  2106. */
  2107. CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
  2108. /**
  2109. * \brief Determine whether the given cursor kind represents a statement.
  2110. */
  2111. CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
  2112. /**
  2113. * \brief Determine whether the given cursor kind represents an attribute.
  2114. */
  2115. CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
  2116. /**
  2117. * \brief Determine whether the given cursor kind represents an invalid
  2118. * cursor.
  2119. */
  2120. CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
  2121. /**
  2122. * \brief Determine whether the given cursor kind represents a translation
  2123. * unit.
  2124. */
  2125. CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
  2126. /***
  2127. * \brief Determine whether the given cursor represents a preprocessing
  2128. * element, such as a preprocessor directive or macro instantiation.
  2129. */
  2130. CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
  2131. /***
  2132. * \brief Determine whether the given cursor represents a currently
  2133. * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
  2134. */
  2135. CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
  2136. /**
  2137. * \brief Describe the linkage of the entity referred to by a cursor.
  2138. */
  2139. enum CXLinkageKind {
  2140. /** \brief This value indicates that no linkage information is available
  2141. * for a provided CXCursor. */
  2142. CXLinkage_Invalid,
  2143. /**
  2144. * \brief This is the linkage for variables, parameters, and so on that
  2145. * have automatic storage. This covers normal (non-extern) local variables.
  2146. */
  2147. CXLinkage_NoLinkage,
  2148. /** \brief This is the linkage for static variables and static functions. */
  2149. CXLinkage_Internal,
  2150. /** \brief This is the linkage for entities with external linkage that live
  2151. * in C++ anonymous namespaces.*/
  2152. CXLinkage_UniqueExternal,
  2153. /** \brief This is the linkage for entities with true, external linkage. */
  2154. CXLinkage_External
  2155. };
  2156. /**
  2157. * \brief Determine the linkage of the entity referred to by a given cursor.
  2158. */
  2159. CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
  2160. /**
  2161. * \brief Determine the availability of the entity that this cursor refers to,
  2162. * taking the current target platform into account.
  2163. *
  2164. * \param cursor The cursor to query.
  2165. *
  2166. * \returns The availability of the cursor.
  2167. */
  2168. CINDEX_LINKAGE enum CXAvailabilityKind
  2169. clang_getCursorAvailability(CXCursor cursor);
  2170. /**
  2171. * Describes the availability of a given entity on a particular platform, e.g.,
  2172. * a particular class might only be available on Mac OS 10.7 or newer.
  2173. */
  2174. typedef struct CXPlatformAvailability {
  2175. /**
  2176. * \brief A string that describes the platform for which this structure
  2177. * provides availability information.
  2178. *
  2179. * Possible values are "ios" or "macosx".
  2180. */
  2181. CXString Platform;
  2182. /**
  2183. * \brief The version number in which this entity was introduced.
  2184. */
  2185. CXVersion Introduced;
  2186. /**
  2187. * \brief The version number in which this entity was deprecated (but is
  2188. * still available).
  2189. */
  2190. CXVersion Deprecated;
  2191. /**
  2192. * \brief The version number in which this entity was obsoleted, and therefore
  2193. * is no longer available.
  2194. */
  2195. CXVersion Obsoleted;
  2196. /**
  2197. * \brief Whether the entity is unconditionally unavailable on this platform.
  2198. */
  2199. int Unavailable;
  2200. /**
  2201. * \brief An optional message to provide to a user of this API, e.g., to
  2202. * suggest replacement APIs.
  2203. */
  2204. CXString Message;
  2205. } CXPlatformAvailability;
  2206. /**
  2207. * \brief Determine the availability of the entity that this cursor refers to
  2208. * on any platforms for which availability information is known.
  2209. *
  2210. * \param cursor The cursor to query.
  2211. *
  2212. * \param always_deprecated If non-NULL, will be set to indicate whether the
  2213. * entity is deprecated on all platforms.
  2214. *
  2215. * \param deprecated_message If non-NULL, will be set to the message text
  2216. * provided along with the unconditional deprecation of this entity. The client
  2217. * is responsible for deallocating this string.
  2218. *
  2219. * \param always_unavailable If non-NULL, will be set to indicate whether the
  2220. * entity is unavailable on all platforms.
  2221. *
  2222. * \param unavailable_message If non-NULL, will be set to the message text
  2223. * provided along with the unconditional unavailability of this entity. The
  2224. * client is responsible for deallocating this string.
  2225. *
  2226. * \param availability If non-NULL, an array of CXPlatformAvailability instances
  2227. * that will be populated with platform availability information, up to either
  2228. * the number of platforms for which availability information is available (as
  2229. * returned by this function) or \c availability_size, whichever is smaller.
  2230. *
  2231. * \param availability_size The number of elements available in the
  2232. * \c availability array.
  2233. *
  2234. * \returns The number of platforms (N) for which availability information is
  2235. * available (which is unrelated to \c availability_size).
  2236. *
  2237. * Note that the client is responsible for calling
  2238. * \c clang_disposeCXPlatformAvailability to free each of the
  2239. * platform-availability structures returned. There are
  2240. * \c min(N, availability_size) such structures.
  2241. */
  2242. CINDEX_LINKAGE int
  2243. clang_getCursorPlatformAvailability(CXCursor cursor,
  2244. int *always_deprecated,
  2245. CXString *deprecated_message,
  2246. int *always_unavailable,
  2247. CXString *unavailable_message,
  2248. CXPlatformAvailability *availability,
  2249. int availability_size);
  2250. /**
  2251. * \brief Free the memory associated with a \c CXPlatformAvailability structure.
  2252. */
  2253. CINDEX_LINKAGE void
  2254. clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
  2255. /**
  2256. * \brief Describe the "language" of the entity referred to by a cursor.
  2257. */
  2258. enum CXLanguageKind {
  2259. CXLanguage_Invalid = 0,
  2260. CXLanguage_C,
  2261. CXLanguage_ObjC,
  2262. CXLanguage_CPlusPlus
  2263. };
  2264. /**
  2265. * \brief Determine the "language" of the entity referred to by a given cursor.
  2266. */
  2267. CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
  2268. /**
  2269. * \brief Returns the translation unit that a cursor originated from.
  2270. */
  2271. CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
  2272. /**
  2273. * \brief A fast container representing a set of CXCursors.
  2274. */
  2275. typedef struct CXCursorSetImpl *CXCursorSet;
  2276. /**
  2277. * \brief Creates an empty CXCursorSet.
  2278. */
  2279. CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
  2280. /**
  2281. * \brief Disposes a CXCursorSet and releases its associated memory.
  2282. */
  2283. CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
  2284. /**
  2285. * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
  2286. *
  2287. * \returns non-zero if the set contains the specified cursor.
  2288. */
  2289. CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
  2290. CXCursor cursor);
  2291. /**
  2292. * \brief Inserts a CXCursor into a CXCursorSet.
  2293. *
  2294. * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
  2295. */
  2296. CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
  2297. CXCursor cursor);
  2298. /**
  2299. * \brief Determine the semantic parent of the given cursor.
  2300. *
  2301. * The semantic parent of a cursor is the cursor that semantically contains
  2302. * the given \p cursor. For many declarations, the lexical and semantic parents
  2303. * are equivalent (the lexical parent is returned by
  2304. * \c clang_getCursorLexicalParent()). They diverge when declarations or
  2305. * definitions are provided out-of-line. For example:
  2306. *
  2307. * \code
  2308. * class C {
  2309. * void f();
  2310. * };
  2311. *
  2312. * void C::f() { }
  2313. * \endcode
  2314. *
  2315. * In the out-of-line definition of \c C::f, the semantic parent is
  2316. * the class \c C, of which this function is a member. The lexical parent is
  2317. * the place where the declaration actually occurs in the source code; in this
  2318. * case, the definition occurs in the translation unit. In general, the
  2319. * lexical parent for a given entity can change without affecting the semantics
  2320. * of the program, and the lexical parent of different declarations of the
  2321. * same entity may be different. Changing the semantic parent of a declaration,
  2322. * on the other hand, can have a major impact on semantics, and redeclarations
  2323. * of a particular entity should all have the same semantic context.
  2324. *
  2325. * In the example above, both declarations of \c C::f have \c C as their
  2326. * semantic context, while the lexical context of the first \c C::f is \c C
  2327. * and the lexical context of the second \c C::f is the translation unit.
  2328. *
  2329. * For global declarations, the semantic parent is the translation unit.
  2330. */
  2331. CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
  2332. /**
  2333. * \brief Determine the lexical parent of the given cursor.
  2334. *
  2335. * The lexical parent of a cursor is the cursor in which the given \p cursor
  2336. * was actually written. For many declarations, the lexical and semantic parents
  2337. * are equivalent (the semantic parent is returned by
  2338. * \c clang_getCursorSemanticParent()). They diverge when declarations or
  2339. * definitions are provided out-of-line. For example:
  2340. *
  2341. * \code
  2342. * class C {
  2343. * void f();
  2344. * };
  2345. *
  2346. * void C::f() { }
  2347. * \endcode
  2348. *
  2349. * In the out-of-line definition of \c C::f, the semantic parent is
  2350. * the class \c C, of which this function is a member. The lexical parent is
  2351. * the place where the declaration actually occurs in the source code; in this
  2352. * case, the definition occurs in the translation unit. In general, the
  2353. * lexical parent for a given entity can change without affecting the semantics
  2354. * of the program, and the lexical parent of different declarations of the
  2355. * same entity may be different. Changing the semantic parent of a declaration,
  2356. * on the other hand, can have a major impact on semantics, and redeclarations
  2357. * of a particular entity should all have the same semantic context.
  2358. *
  2359. * In the example above, both declarations of \c C::f have \c C as their
  2360. * semantic context, while the lexical context of the first \c C::f is \c C
  2361. * and the lexical context of the second \c C::f is the translation unit.
  2362. *
  2363. * For declarations written in the global scope, the lexical parent is
  2364. * the translation unit.
  2365. */
  2366. CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
  2367. /**
  2368. * \brief Determine the set of methods that are overridden by the given
  2369. * method.
  2370. *
  2371. * In both Objective-C and C++, a method (aka virtual member function,
  2372. * in C++) can override a virtual method in a base class. For
  2373. * Objective-C, a method is said to override any method in the class's
  2374. * base class, its protocols, or its categories' protocols, that has the same
  2375. * selector and is of the same kind (class or instance).
  2376. * If no such method exists, the search continues to the class's superclass,
  2377. * its protocols, and its categories, and so on. A method from an Objective-C
  2378. * implementation is considered to override the same methods as its
  2379. * corresponding method in the interface.
  2380. *
  2381. * For C++, a virtual member function overrides any virtual member
  2382. * function with the same signature that occurs in its base
  2383. * classes. With multiple inheritance, a virtual member function can
  2384. * override several virtual member functions coming from different
  2385. * base classes.
  2386. *
  2387. * In all cases, this function determines the immediate overridden
  2388. * method, rather than all of the overridden methods. For example, if
  2389. * a method is originally declared in a class A, then overridden in B
  2390. * (which in inherits from A) and also in C (which inherited from B),
  2391. * then the only overridden method returned from this function when
  2392. * invoked on C's method will be B's method. The client may then
  2393. * invoke this function again, given the previously-found overridden
  2394. * methods, to map out the complete method-override set.
  2395. *
  2396. * \param cursor A cursor representing an Objective-C or C++
  2397. * method. This routine will compute the set of methods that this
  2398. * method overrides.
  2399. *
  2400. * \param overridden A pointer whose pointee will be replaced with a
  2401. * pointer to an array of cursors, representing the set of overridden
  2402. * methods. If there are no overridden methods, the pointee will be
  2403. * set to NULL. The pointee must be freed via a call to
  2404. * \c clang_disposeOverriddenCursors().
  2405. *
  2406. * \param num_overridden A pointer to the number of overridden
  2407. * functions, will be set to the number of overridden functions in the
  2408. * array pointed to by \p overridden.
  2409. */
  2410. CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
  2411. CXCursor **overridden,
  2412. unsigned *num_overridden);
  2413. /**
  2414. * \brief Free the set of overridden cursors returned by \c
  2415. * clang_getOverriddenCursors().
  2416. */
  2417. CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
  2418. /**
  2419. * \brief Retrieve the file that is included by the given inclusion directive
  2420. * cursor.
  2421. */
  2422. CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
  2423. /**
  2424. * @}
  2425. */
  2426. /**
  2427. * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
  2428. *
  2429. * Cursors represent a location within the Abstract Syntax Tree (AST). These
  2430. * routines help map between cursors and the physical locations where the
  2431. * described entities occur in the source code. The mapping is provided in
  2432. * both directions, so one can map from source code to the AST and back.
  2433. *
  2434. * @{
  2435. */
  2436. /**
  2437. * \brief Map a source location to the cursor that describes the entity at that
  2438. * location in the source code.
  2439. *
  2440. * clang_getCursor() maps an arbitrary source location within a translation
  2441. * unit down to the most specific cursor that describes the entity at that
  2442. * location. For example, given an expression \c x + y, invoking
  2443. * clang_getCursor() with a source location pointing to "x" will return the
  2444. * cursor for "x"; similarly for "y". If the cursor points anywhere between
  2445. * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
  2446. * will return a cursor referring to the "+" expression.
  2447. *
  2448. * \returns a cursor representing the entity at the given source location, or
  2449. * a NULL cursor if no such entity can be found.
  2450. */
  2451. CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
  2452. /**
  2453. * \brief Retrieve the physical location of the source constructor referenced
  2454. * by the given cursor.
  2455. *
  2456. * The location of a declaration is typically the location of the name of that
  2457. * declaration, where the name of that declaration would occur if it is
  2458. * unnamed, or some keyword that introduces that particular declaration.
  2459. * The location of a reference is where that reference occurs within the
  2460. * source code.
  2461. */
  2462. CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
  2463. /**
  2464. * \brief Retrieve the physical extent of the source construct referenced by
  2465. * the given cursor.
  2466. *
  2467. * The extent of a cursor starts with the file/line/column pointing at the
  2468. * first character within the source construct that the cursor refers to and
  2469. * ends with the last character within that source construct. For a
  2470. * declaration, the extent covers the declaration itself. For a reference,
  2471. * the extent covers the location of the reference (e.g., where the referenced
  2472. * entity was actually used).
  2473. */
  2474. CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
  2475. /**
  2476. * @}
  2477. */
  2478. /**
  2479. * \defgroup CINDEX_TYPES Type information for CXCursors
  2480. *
  2481. * @{
  2482. */
  2483. /**
  2484. * \brief Describes the kind of type
  2485. */
  2486. enum CXTypeKind {
  2487. /**
  2488. * \brief Represents an invalid type (e.g., where no type is available).
  2489. */
  2490. CXType_Invalid = 0,
  2491. /**
  2492. * \brief A type whose specific kind is not exposed via this
  2493. * interface.
  2494. */
  2495. CXType_Unexposed = 1,
  2496. /* Builtin types */
  2497. CXType_Void = 2,
  2498. CXType_Bool = 3,
  2499. CXType_Char_U = 4,
  2500. CXType_UChar = 5,
  2501. CXType_Char16 = 6,
  2502. CXType_Char32 = 7,
  2503. CXType_UShort = 8,
  2504. CXType_UInt = 9,
  2505. CXType_ULong = 10,
  2506. CXType_ULongLong = 11,
  2507. CXType_UInt128 = 12,
  2508. CXType_Char_S = 13,
  2509. CXType_SChar = 14,
  2510. CXType_WChar = 15,
  2511. CXType_Short = 16,
  2512. CXType_Int = 17,
  2513. CXType_Long = 18,
  2514. CXType_LongLong = 19,
  2515. CXType_Int128 = 20,
  2516. CXType_Float = 21,
  2517. CXType_Double = 22,
  2518. CXType_LongDouble = 23,
  2519. CXType_NullPtr = 24,
  2520. CXType_Overload = 25,
  2521. CXType_Dependent = 26,
  2522. CXType_ObjCId = 27,
  2523. CXType_ObjCClass = 28,
  2524. CXType_ObjCSel = 29,
  2525. CXType_FirstBuiltin = CXType_Void,
  2526. CXType_LastBuiltin = CXType_ObjCSel,
  2527. CXType_Complex = 100,
  2528. CXType_Pointer = 101,
  2529. CXType_BlockPointer = 102,
  2530. CXType_LValueReference = 103,
  2531. CXType_RValueReference = 104,
  2532. CXType_Record = 105,
  2533. CXType_Enum = 106,
  2534. CXType_Typedef = 107,
  2535. CXType_ObjCInterface = 108,
  2536. CXType_ObjCObjectPointer = 109,
  2537. CXType_FunctionNoProto = 110,
  2538. CXType_FunctionProto = 111,
  2539. CXType_ConstantArray = 112,
  2540. CXType_Vector = 113,
  2541. CXType_IncompleteArray = 114,
  2542. CXType_VariableArray = 115,
  2543. CXType_DependentSizedArray = 116,
  2544. CXType_MemberPointer = 117
  2545. };
  2546. /**
  2547. * \brief Describes the calling convention of a function type
  2548. */
  2549. enum CXCallingConv {
  2550. CXCallingConv_Default = 0,
  2551. CXCallingConv_C = 1,
  2552. CXCallingConv_X86StdCall = 2,
  2553. CXCallingConv_X86FastCall = 3,
  2554. CXCallingConv_X86ThisCall = 4,
  2555. CXCallingConv_X86Pascal = 5,
  2556. CXCallingConv_AAPCS = 6,
  2557. CXCallingConv_AAPCS_VFP = 7,
  2558. /* Value 8 was PnaclCall, but it was never used, so it could safely be re-used. */
  2559. CXCallingConv_IntelOclBicc = 9,
  2560. CXCallingConv_X86_64Win64 = 10,
  2561. CXCallingConv_X86_64SysV = 11,
  2562. CXCallingConv_X86VectorCall = 12,
  2563. CXCallingConv_Invalid = 100,
  2564. CXCallingConv_Unexposed = 200
  2565. };
  2566. /**
  2567. * \brief The type of an element in the abstract syntax tree.
  2568. *
  2569. */
  2570. typedef struct {
  2571. enum CXTypeKind kind;
  2572. void *data[2];
  2573. } CXType;
  2574. /**
  2575. * \brief Retrieve the type of a CXCursor (if any).
  2576. */
  2577. CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
  2578. /**
  2579. * \brief Pretty-print the underlying type using the rules of the
  2580. * language of the translation unit from which it came.
  2581. *
  2582. * If the type is invalid, an empty string is returned.
  2583. */
  2584. CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
  2585. /**
  2586. * \brief Retrieve the underlying type of a typedef declaration.
  2587. *
  2588. * If the cursor does not reference a typedef declaration, an invalid type is
  2589. * returned.
  2590. */
  2591. CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
  2592. /**
  2593. * \brief Retrieve the integer type of an enum declaration.
  2594. *
  2595. * If the cursor does not reference an enum declaration, an invalid type is
  2596. * returned.
  2597. */
  2598. CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
  2599. /**
  2600. * \brief Retrieve the integer value of an enum constant declaration as a signed
  2601. * long long.
  2602. *
  2603. * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
  2604. * Since this is also potentially a valid constant value, the kind of the cursor
  2605. * must be verified before calling this function.
  2606. */
  2607. CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
  2608. /**
  2609. * \brief Retrieve the integer value of an enum constant declaration as an unsigned
  2610. * long long.
  2611. *
  2612. * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
  2613. * Since this is also potentially a valid constant value, the kind of the cursor
  2614. * must be verified before calling this function.
  2615. */
  2616. CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
  2617. /**
  2618. * \brief Retrieve the bit width of a bit field declaration as an integer.
  2619. *
  2620. * If a cursor that is not a bit field declaration is passed in, -1 is returned.
  2621. */
  2622. CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
  2623. /**
  2624. * \brief Retrieve the number of non-variadic arguments associated with a given
  2625. * cursor.
  2626. *
  2627. * The number of arguments can be determined for calls as well as for
  2628. * declarations of functions or methods. For other cursors -1 is returned.
  2629. */
  2630. CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
  2631. /**
  2632. * \brief Retrieve the argument cursor of a function or method.
  2633. *
  2634. * The argument cursor can be determined for calls as well as for declarations
  2635. * of functions or methods. For other cursors and for invalid indices, an
  2636. * invalid cursor is returned.
  2637. */
  2638. CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
  2639. /**
  2640. * \brief Describes the kind of a template argument.
  2641. *
  2642. * See the definition of llvm::clang::TemplateArgument::ArgKind for full
  2643. * element descriptions.
  2644. */
  2645. enum CXTemplateArgumentKind {
  2646. CXTemplateArgumentKind_Null,
  2647. CXTemplateArgumentKind_Type,
  2648. CXTemplateArgumentKind_Declaration,
  2649. CXTemplateArgumentKind_NullPtr,
  2650. CXTemplateArgumentKind_Integral,
  2651. CXTemplateArgumentKind_Template,
  2652. CXTemplateArgumentKind_TemplateExpansion,
  2653. CXTemplateArgumentKind_Expression,
  2654. CXTemplateArgumentKind_Pack,
  2655. /* Indicates an error case, preventing the kind from being deduced. */
  2656. CXTemplateArgumentKind_Invalid
  2657. };
  2658. /**
  2659. *\brief Returns the number of template args of a function decl representing a
  2660. * template specialization.
  2661. *
  2662. * If the argument cursor cannot be converted into a template function
  2663. * declaration, -1 is returned.
  2664. *
  2665. * For example, for the following declaration and specialization:
  2666. * template <typename T, int kInt, bool kBool>
  2667. * void foo() { ... }
  2668. *
  2669. * template <>
  2670. * void foo<float, -7, true>();
  2671. *
  2672. * The value 3 would be returned from this call.
  2673. */
  2674. CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C);
  2675. /**
  2676. * \brief Retrieve the kind of the I'th template argument of the CXCursor C.
  2677. *
  2678. * If the argument CXCursor does not represent a FunctionDecl, an invalid
  2679. * template argument kind is returned.
  2680. *
  2681. * For example, for the following declaration and specialization:
  2682. * template <typename T, int kInt, bool kBool>
  2683. * void foo() { ... }
  2684. *
  2685. * template <>
  2686. * void foo<float, -7, true>();
  2687. *
  2688. * For I = 0, 1, and 2, Type, Integral, and Integral will be returned,
  2689. * respectively.
  2690. */
  2691. CINDEX_LINKAGE enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(
  2692. CXCursor C, unsigned I);
  2693. /**
  2694. * \brief Retrieve a CXType representing the type of a TemplateArgument of a
  2695. * function decl representing a template specialization.
  2696. *
  2697. * If the argument CXCursor does not represent a FunctionDecl whose I'th
  2698. * template argument has a kind of CXTemplateArgKind_Integral, an invalid type
  2699. * is returned.
  2700. *
  2701. * For example, for the following declaration and specialization:
  2702. * template <typename T, int kInt, bool kBool>
  2703. * void foo() { ... }
  2704. *
  2705. * template <>
  2706. * void foo<float, -7, true>();
  2707. *
  2708. * If called with I = 0, "float", will be returned.
  2709. * Invalid types will be returned for I == 1 or 2.
  2710. */
  2711. CINDEX_LINKAGE CXType clang_Cursor_getTemplateArgumentType(CXCursor C,
  2712. unsigned I);
  2713. /**
  2714. * \brief Retrieve the value of an Integral TemplateArgument (of a function
  2715. * decl representing a template specialization) as a signed long long.
  2716. *
  2717. * It is undefined to call this function on a CXCursor that does not represent a
  2718. * FunctionDecl or whose I'th template argument is not an integral value.
  2719. *
  2720. * For example, for the following declaration and specialization:
  2721. * template <typename T, int kInt, bool kBool>
  2722. * void foo() { ... }
  2723. *
  2724. * template <>
  2725. * void foo<float, -7, true>();
  2726. *
  2727. * If called with I = 1 or 2, -7 or true will be returned, respectively.
  2728. * For I == 0, this function's behavior is undefined.
  2729. */
  2730. CINDEX_LINKAGE long long clang_Cursor_getTemplateArgumentValue(CXCursor C,
  2731. unsigned I);
  2732. /**
  2733. * \brief Retrieve the value of an Integral TemplateArgument (of a function
  2734. * decl representing a template specialization) as an unsigned long long.
  2735. *
  2736. * It is undefined to call this function on a CXCursor that does not represent a
  2737. * FunctionDecl or whose I'th template argument is not an integral value.
  2738. *
  2739. * For example, for the following declaration and specialization:
  2740. * template <typename T, int kInt, bool kBool>
  2741. * void foo() { ... }
  2742. *
  2743. * template <>
  2744. * void foo<float, 2147483649, true>();
  2745. *
  2746. * If called with I = 1 or 2, 2147483649 or true will be returned, respectively.
  2747. * For I == 0, this function's behavior is undefined.
  2748. */
  2749. CINDEX_LINKAGE unsigned long long clang_Cursor_getTemplateArgumentUnsignedValue(
  2750. CXCursor C, unsigned I);
  2751. /**
  2752. * \brief Determine whether two CXTypes represent the same type.
  2753. *
  2754. * \returns non-zero if the CXTypes represent the same type and
  2755. * zero otherwise.
  2756. */
  2757. CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
  2758. /**
  2759. * \brief Return the canonical type for a CXType.
  2760. *
  2761. * Clang's type system explicitly models typedefs and all the ways
  2762. * a specific type can be represented. The canonical type is the underlying
  2763. * type with all the "sugar" removed. For example, if 'T' is a typedef
  2764. * for 'int', the canonical type for 'T' would be 'int'.
  2765. */
  2766. CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
  2767. /**
  2768. * \brief Determine whether a CXType has the "const" qualifier set,
  2769. * without looking through typedefs that may have added "const" at a
  2770. * different level.
  2771. */
  2772. CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
  2773. /**
  2774. * \brief Determine whether a CXType has the "volatile" qualifier set,
  2775. * without looking through typedefs that may have added "volatile" at
  2776. * a different level.
  2777. */
  2778. CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
  2779. /**
  2780. * \brief Determine whether a CXType has the "restrict" qualifier set,
  2781. * without looking through typedefs that may have added "restrict" at a
  2782. * different level.
  2783. */
  2784. CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
  2785. /**
  2786. * \brief For pointer types, returns the type of the pointee.
  2787. */
  2788. CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
  2789. /**
  2790. * \brief Return the cursor for the declaration of the given type.
  2791. */
  2792. CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
  2793. /**
  2794. * Returns the Objective-C type encoding for the specified declaration.
  2795. */
  2796. CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
  2797. /**
  2798. * \brief Retrieve the spelling of a given CXTypeKind.
  2799. */
  2800. CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
  2801. /**
  2802. * \brief Retrieve the calling convention associated with a function type.
  2803. *
  2804. * If a non-function type is passed in, CXCallingConv_Invalid is returned.
  2805. */
  2806. CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
  2807. /**
  2808. * \brief Retrieve the return type associated with a function type.
  2809. *
  2810. * If a non-function type is passed in, an invalid type is returned.
  2811. */
  2812. CINDEX_LINKAGE CXType clang_getResultType(CXType T);
  2813. /**
  2814. * \brief Retrieve the number of non-variadic parameters associated with a
  2815. * function type.
  2816. *
  2817. * If a non-function type is passed in, -1 is returned.
  2818. */
  2819. CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
  2820. /**
  2821. * \brief Retrieve the type of a parameter of a function type.
  2822. *
  2823. * If a non-function type is passed in or the function does not have enough
  2824. * parameters, an invalid type is returned.
  2825. */
  2826. CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
  2827. /**
  2828. * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
  2829. */
  2830. CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
  2831. /**
  2832. * \brief Retrieve the return type associated with a given cursor.
  2833. *
  2834. * This only returns a valid type if the cursor refers to a function or method.
  2835. */
  2836. CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
  2837. /**
  2838. * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
  2839. * otherwise.
  2840. */
  2841. CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
  2842. /**
  2843. * \brief Return the element type of an array, complex, or vector type.
  2844. *
  2845. * If a type is passed in that is not an array, complex, or vector type,
  2846. * an invalid type is returned.
  2847. */
  2848. CINDEX_LINKAGE CXType clang_getElementType(CXType T);
  2849. /**
  2850. * \brief Return the number of elements of an array or vector type.
  2851. *
  2852. * If a type is passed in that is not an array or vector type,
  2853. * -1 is returned.
  2854. */
  2855. CINDEX_LINKAGE long long clang_getNumElements(CXType T);
  2856. /**
  2857. * \brief Return the element type of an array type.
  2858. *
  2859. * If a non-array type is passed in, an invalid type is returned.
  2860. */
  2861. CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
  2862. /**
  2863. * \brief Return the array size of a constant array.
  2864. *
  2865. * If a non-array type is passed in, -1 is returned.
  2866. */
  2867. CINDEX_LINKAGE long long clang_getArraySize(CXType T);
  2868. /**
  2869. * \brief List the possible error codes for \c clang_Type_getSizeOf,
  2870. * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
  2871. * \c clang_Cursor_getOffsetOf.
  2872. *
  2873. * A value of this enumeration type can be returned if the target type is not
  2874. * a valid argument to sizeof, alignof or offsetof.
  2875. */
  2876. enum CXTypeLayoutError {
  2877. /**
  2878. * \brief Type is of kind CXType_Invalid.
  2879. */
  2880. CXTypeLayoutError_Invalid = -1,
  2881. /**
  2882. * \brief The type is an incomplete Type.
  2883. */
  2884. CXTypeLayoutError_Incomplete = -2,
  2885. /**
  2886. * \brief The type is a dependent Type.
  2887. */
  2888. CXTypeLayoutError_Dependent = -3,
  2889. /**
  2890. * \brief The type is not a constant size type.
  2891. */
  2892. CXTypeLayoutError_NotConstantSize = -4,
  2893. /**
  2894. * \brief The Field name is not valid for this record.
  2895. */
  2896. CXTypeLayoutError_InvalidFieldName = -5
  2897. };
  2898. /**
  2899. * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
  2900. * standard.
  2901. *
  2902. * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
  2903. * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
  2904. * is returned.
  2905. * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
  2906. * returned.
  2907. * If the type declaration is not a constant size type,
  2908. * CXTypeLayoutError_NotConstantSize is returned.
  2909. */
  2910. CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
  2911. /**
  2912. * \brief Return the class type of an member pointer type.
  2913. *
  2914. * If a non-member-pointer type is passed in, an invalid type is returned.
  2915. */
  2916. CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T);
  2917. /**
  2918. * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
  2919. *
  2920. * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
  2921. * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
  2922. * is returned.
  2923. * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
  2924. * returned.
  2925. */
  2926. CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
  2927. /**
  2928. * \brief Return the offset of a field named S in a record of type T in bits
  2929. * as it would be returned by __offsetof__ as per C++11[18.2p4]
  2930. *
  2931. * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
  2932. * is returned.
  2933. * If the field's type declaration is an incomplete type,
  2934. * CXTypeLayoutError_Incomplete is returned.
  2935. * If the field's type declaration is a dependent type,
  2936. * CXTypeLayoutError_Dependent is returned.
  2937. * If the field's name S is not found,
  2938. * CXTypeLayoutError_InvalidFieldName is returned.
  2939. */
  2940. CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
  2941. /**
  2942. * \brief Return the offset of the field represented by the Cursor.
  2943. *
  2944. * If the cursor is not a field declaration, -1 is returned.
  2945. * If the cursor semantic parent is not a record field declaration,
  2946. * CXTypeLayoutError_Invalid is returned.
  2947. * If the field's type declaration is an incomplete type,
  2948. * CXTypeLayoutError_Incomplete is returned.
  2949. * If the field's type declaration is a dependent type,
  2950. * CXTypeLayoutError_Dependent is returned.
  2951. * If the field's name S is not found,
  2952. * CXTypeLayoutError_InvalidFieldName is returned.
  2953. */
  2954. CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);
  2955. /**
  2956. * \brief Determine whether the given cursor represents an anonymous record
  2957. * declaration.
  2958. */
  2959. CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
  2960. enum CXRefQualifierKind {
  2961. /** \brief No ref-qualifier was provided. */
  2962. CXRefQualifier_None = 0,
  2963. /** \brief An lvalue ref-qualifier was provided (\c &). */
  2964. CXRefQualifier_LValue,
  2965. /** \brief An rvalue ref-qualifier was provided (\c &&). */
  2966. CXRefQualifier_RValue
  2967. };
  2968. /**
  2969. * \brief Returns the number of template arguments for given class template
  2970. * specialization, or -1 if type \c T is not a class template specialization.
  2971. *
  2972. * Variadic argument packs count as only one argument, and can not be inspected
  2973. * further.
  2974. */
  2975. CINDEX_LINKAGE int clang_Type_getNumTemplateArguments(CXType T);
  2976. /**
  2977. * \brief Returns the type template argument of a template class specialization
  2978. * at given index.
  2979. *
  2980. * This function only returns template type arguments and does not handle
  2981. * template template arguments or variadic packs.
  2982. */
  2983. CINDEX_LINKAGE CXType clang_Type_getTemplateArgumentAsType(CXType T, unsigned i);
  2984. /**
  2985. * \brief Retrieve the ref-qualifier kind of a function or method.
  2986. *
  2987. * The ref-qualifier is returned for C++ functions or methods. For other types
  2988. * or non-C++ declarations, CXRefQualifier_None is returned.
  2989. */
  2990. CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T);
  2991. /**
  2992. * \brief Returns non-zero if the cursor specifies a Record member that is a
  2993. * bitfield.
  2994. */
  2995. CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
  2996. /**
  2997. * \brief Returns 1 if the base class specified by the cursor with kind
  2998. * CX_CXXBaseSpecifier is virtual.
  2999. */
  3000. CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
  3001. /**
  3002. * \brief Represents the C++ access control level to a base class for a
  3003. * cursor with kind CX_CXXBaseSpecifier.
  3004. */
  3005. enum CX_CXXAccessSpecifier {
  3006. CX_CXXInvalidAccessSpecifier,
  3007. CX_CXXPublic,
  3008. CX_CXXProtected,
  3009. CX_CXXPrivate
  3010. };
  3011. /**
  3012. * \brief Returns the access control level for the referenced object.
  3013. *
  3014. * If the cursor refers to a C++ declaration, its access control level within its
  3015. * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
  3016. * access specifier, the specifier itself is returned.
  3017. */
  3018. CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
  3019. /**
  3020. * \brief Represents the storage classes as declared in the source. CX_SC_Invalid
  3021. * was added for the case that the passed cursor in not a declaration.
  3022. */
  3023. enum CX_StorageClass {
  3024. CX_SC_Invalid,
  3025. CX_SC_None,
  3026. CX_SC_Extern,
  3027. CX_SC_Static,
  3028. CX_SC_PrivateExtern,
  3029. CX_SC_OpenCLWorkGroupLocal,
  3030. CX_SC_Auto,
  3031. CX_SC_Register
  3032. };
  3033. /**
  3034. * \brief Returns the storage class for a function or variable declaration.
  3035. *
  3036. * If the passed in Cursor is not a function or variable declaration,
  3037. * CX_SC_Invalid is returned else the storage class.
  3038. */
  3039. CINDEX_LINKAGE enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor);
  3040. /**
  3041. * \brief Determine the number of overloaded declarations referenced by a
  3042. * \c CXCursor_OverloadedDeclRef cursor.
  3043. *
  3044. * \param cursor The cursor whose overloaded declarations are being queried.
  3045. *
  3046. * \returns The number of overloaded declarations referenced by \c cursor. If it
  3047. * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
  3048. */
  3049. CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
  3050. /**
  3051. * \brief Retrieve a cursor for one of the overloaded declarations referenced
  3052. * by a \c CXCursor_OverloadedDeclRef cursor.
  3053. *
  3054. * \param cursor The cursor whose overloaded declarations are being queried.
  3055. *
  3056. * \param index The zero-based index into the set of overloaded declarations in
  3057. * the cursor.
  3058. *
  3059. * \returns A cursor representing the declaration referenced by the given
  3060. * \c cursor at the specified \c index. If the cursor does not have an
  3061. * associated set of overloaded declarations, or if the index is out of bounds,
  3062. * returns \c clang_getNullCursor();
  3063. */
  3064. CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
  3065. unsigned index);
  3066. /**
  3067. * @}
  3068. */
  3069. /**
  3070. * \defgroup CINDEX_ATTRIBUTES Information for attributes
  3071. *
  3072. * @{
  3073. */
  3074. /**
  3075. * \brief For cursors representing an iboutletcollection attribute,
  3076. * this function returns the collection element type.
  3077. *
  3078. */
  3079. CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
  3080. /**
  3081. * @}
  3082. */
  3083. /**
  3084. * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
  3085. *
  3086. * These routines provide the ability to traverse the abstract syntax tree
  3087. * using cursors.
  3088. *
  3089. * @{
  3090. */
  3091. /**
  3092. * \brief Describes how the traversal of the children of a particular
  3093. * cursor should proceed after visiting a particular child cursor.
  3094. *
  3095. * A value of this enumeration type should be returned by each
  3096. * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
  3097. */
  3098. enum CXChildVisitResult {
  3099. /**
  3100. * \brief Terminates the cursor traversal.
  3101. */
  3102. CXChildVisit_Break,
  3103. /**
  3104. * \brief Continues the cursor traversal with the next sibling of
  3105. * the cursor just visited, without visiting its children.
  3106. */
  3107. CXChildVisit_Continue,
  3108. /**
  3109. * \brief Recursively traverse the children of this cursor, using
  3110. * the same visitor and client data.
  3111. */
  3112. CXChildVisit_Recurse
  3113. };
  3114. /**
  3115. * \brief Visitor invoked for each cursor found by a traversal.
  3116. *
  3117. * This visitor function will be invoked for each cursor found by
  3118. * clang_visitCursorChildren(). Its first argument is the cursor being
  3119. * visited, its second argument is the parent visitor for that cursor,
  3120. * and its third argument is the client data provided to
  3121. * clang_visitCursorChildren().
  3122. *
  3123. * The visitor should return one of the \c CXChildVisitResult values
  3124. * to direct clang_visitCursorChildren().
  3125. */
  3126. typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
  3127. CXCursor parent,
  3128. CXClientData client_data);
  3129. /**
  3130. * \brief Visit the children of a particular cursor.
  3131. *
  3132. * This function visits all the direct children of the given cursor,
  3133. * invoking the given \p visitor function with the cursors of each
  3134. * visited child. The traversal may be recursive, if the visitor returns
  3135. * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
  3136. * the visitor returns \c CXChildVisit_Break.
  3137. *
  3138. * \param parent the cursor whose child may be visited. All kinds of
  3139. * cursors can be visited, including invalid cursors (which, by
  3140. * definition, have no children).
  3141. *
  3142. * \param visitor the visitor function that will be invoked for each
  3143. * child of \p parent.
  3144. *
  3145. * \param client_data pointer data supplied by the client, which will
  3146. * be passed to the visitor each time it is invoked.
  3147. *
  3148. * \returns a non-zero value if the traversal was terminated
  3149. * prematurely by the visitor returning \c CXChildVisit_Break.
  3150. */
  3151. CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
  3152. CXCursorVisitor visitor,
  3153. CXClientData client_data);
  3154. #ifdef __has_feature
  3155. # if __has_feature(blocks)
  3156. /**
  3157. * \brief Visitor invoked for each cursor found by a traversal.
  3158. *
  3159. * This visitor block will be invoked for each cursor found by
  3160. * clang_visitChildrenWithBlock(). Its first argument is the cursor being
  3161. * visited, its second argument is the parent visitor for that cursor.
  3162. *
  3163. * The visitor should return one of the \c CXChildVisitResult values
  3164. * to direct clang_visitChildrenWithBlock().
  3165. */
  3166. typedef enum CXChildVisitResult
  3167. (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
  3168. /**
  3169. * Visits the children of a cursor using the specified block. Behaves
  3170. * identically to clang_visitChildren() in all other respects.
  3171. */
  3172. unsigned clang_visitChildrenWithBlock(CXCursor parent,
  3173. CXCursorVisitorBlock block);
  3174. # endif
  3175. #endif
  3176. /**
  3177. * @}
  3178. */
  3179. /**
  3180. * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
  3181. *
  3182. * These routines provide the ability to determine references within and
  3183. * across translation units, by providing the names of the entities referenced
  3184. * by cursors, follow reference cursors to the declarations they reference,
  3185. * and associate declarations with their definitions.
  3186. *
  3187. * @{
  3188. */
  3189. /**
  3190. * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
  3191. * by the given cursor.
  3192. *
  3193. * A Unified Symbol Resolution (USR) is a string that identifies a particular
  3194. * entity (function, class, variable, etc.) within a program. USRs can be
  3195. * compared across translation units to determine, e.g., when references in
  3196. * one translation refer to an entity defined in another translation unit.
  3197. */
  3198. CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
  3199. /**
  3200. * \brief Construct a USR for a specified Objective-C class.
  3201. */
  3202. CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
  3203. /**
  3204. * \brief Construct a USR for a specified Objective-C category.
  3205. */
  3206. CINDEX_LINKAGE CXString
  3207. clang_constructUSR_ObjCCategory(const char *class_name,
  3208. const char *category_name);
  3209. /**
  3210. * \brief Construct a USR for a specified Objective-C protocol.
  3211. */
  3212. CINDEX_LINKAGE CXString
  3213. clang_constructUSR_ObjCProtocol(const char *protocol_name);
  3214. /**
  3215. * \brief Construct a USR for a specified Objective-C instance variable and
  3216. * the USR for its containing class.
  3217. */
  3218. CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
  3219. CXString classUSR);
  3220. /**
  3221. * \brief Construct a USR for a specified Objective-C method and
  3222. * the USR for its containing class.
  3223. */
  3224. CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
  3225. unsigned isInstanceMethod,
  3226. CXString classUSR);
  3227. /**
  3228. * \brief Construct a USR for a specified Objective-C property and the USR
  3229. * for its containing class.
  3230. */
  3231. CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
  3232. CXString classUSR);
  3233. /**
  3234. * \brief Retrieve a name for the entity referenced by this cursor.
  3235. */
  3236. CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
  3237. /**
  3238. * \brief Retrieve a range for a piece that forms the cursors spelling name.
  3239. * Most of the times there is only one range for the complete spelling but for
  3240. * Objective-C methods and Objective-C message expressions, there are multiple
  3241. * pieces for each selector identifier.
  3242. *
  3243. * \param pieceIndex the index of the spelling name piece. If this is greater
  3244. * than the actual number of pieces, it will return a NULL (invalid) range.
  3245. *
  3246. * \param options Reserved.
  3247. */
  3248. CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
  3249. unsigned pieceIndex,
  3250. unsigned options);
  3251. /**
  3252. * \brief Retrieve the display name for the entity referenced by this cursor.
  3253. *
  3254. * The display name contains extra information that helps identify the cursor,
  3255. * such as the parameters of a function or template or the arguments of a
  3256. * class template specialization.
  3257. */
  3258. CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
  3259. /** \brief For a cursor that is a reference, retrieve a cursor representing the
  3260. * entity that it references.
  3261. *
  3262. * Reference cursors refer to other entities in the AST. For example, an
  3263. * Objective-C superclass reference cursor refers to an Objective-C class.
  3264. * This function produces the cursor for the Objective-C class from the
  3265. * cursor for the superclass reference. If the input cursor is a declaration or
  3266. * definition, it returns that declaration or definition unchanged.
  3267. * Otherwise, returns the NULL cursor.
  3268. */
  3269. CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
  3270. /**
  3271. * \brief For a cursor that is either a reference to or a declaration
  3272. * of some entity, retrieve a cursor that describes the definition of
  3273. * that entity.
  3274. *
  3275. * Some entities can be declared multiple times within a translation
  3276. * unit, but only one of those declarations can also be a
  3277. * definition. For example, given:
  3278. *
  3279. * \code
  3280. * int f(int, int);
  3281. * int g(int x, int y) { return f(x, y); }
  3282. * int f(int a, int b) { return a + b; }
  3283. * int f(int, int);
  3284. * \endcode
  3285. *
  3286. * there are three declarations of the function "f", but only the
  3287. * second one is a definition. The clang_getCursorDefinition()
  3288. * function will take any cursor pointing to a declaration of "f"
  3289. * (the first or fourth lines of the example) or a cursor referenced
  3290. * that uses "f" (the call to "f' inside "g") and will return a
  3291. * declaration cursor pointing to the definition (the second "f"
  3292. * declaration).
  3293. *
  3294. * If given a cursor for which there is no corresponding definition,
  3295. * e.g., because there is no definition of that entity within this
  3296. * translation unit, returns a NULL cursor.
  3297. */
  3298. CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
  3299. /**
  3300. * \brief Determine whether the declaration pointed to by this cursor
  3301. * is also a definition of that entity.
  3302. */
  3303. CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
  3304. /**
  3305. * \brief Retrieve the canonical cursor corresponding to the given cursor.
  3306. *
  3307. * In the C family of languages, many kinds of entities can be declared several
  3308. * times within a single translation unit. For example, a structure type can
  3309. * be forward-declared (possibly multiple times) and later defined:
  3310. *
  3311. * \code
  3312. * struct X;
  3313. * struct X;
  3314. * struct X {
  3315. * int member;
  3316. * };
  3317. * \endcode
  3318. *
  3319. * The declarations and the definition of \c X are represented by three
  3320. * different cursors, all of which are declarations of the same underlying
  3321. * entity. One of these cursor is considered the "canonical" cursor, which
  3322. * is effectively the representative for the underlying entity. One can
  3323. * determine if two cursors are declarations of the same underlying entity by
  3324. * comparing their canonical cursors.
  3325. *
  3326. * \returns The canonical cursor for the entity referred to by the given cursor.
  3327. */
  3328. CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
  3329. /**
  3330. * \brief If the cursor points to a selector identifier in an Objective-C
  3331. * method or message expression, this returns the selector index.
  3332. *
  3333. * After getting a cursor with #clang_getCursor, this can be called to
  3334. * determine if the location points to a selector identifier.
  3335. *
  3336. * \returns The selector index if the cursor is an Objective-C method or message
  3337. * expression and the cursor is pointing to a selector identifier, or -1
  3338. * otherwise.
  3339. */
  3340. CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
  3341. /**
  3342. * \brief Given a cursor pointing to a C++ method call or an Objective-C
  3343. * message, returns non-zero if the method/message is "dynamic", meaning:
  3344. *
  3345. * For a C++ method: the call is virtual.
  3346. * For an Objective-C message: the receiver is an object instance, not 'super'
  3347. * or a specific class.
  3348. *
  3349. * If the method/message is "static" or the cursor does not point to a
  3350. * method/message, it will return zero.
  3351. */
  3352. CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
  3353. /**
  3354. * \brief Given a cursor pointing to an Objective-C message, returns the CXType
  3355. * of the receiver.
  3356. */
  3357. CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
  3358. /**
  3359. * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
  3360. */
  3361. typedef enum {
  3362. CXObjCPropertyAttr_noattr = 0x00,
  3363. CXObjCPropertyAttr_readonly = 0x01,
  3364. CXObjCPropertyAttr_getter = 0x02,
  3365. CXObjCPropertyAttr_assign = 0x04,
  3366. CXObjCPropertyAttr_readwrite = 0x08,
  3367. CXObjCPropertyAttr_retain = 0x10,
  3368. CXObjCPropertyAttr_copy = 0x20,
  3369. CXObjCPropertyAttr_nonatomic = 0x40,
  3370. CXObjCPropertyAttr_setter = 0x80,
  3371. CXObjCPropertyAttr_atomic = 0x100,
  3372. CXObjCPropertyAttr_weak = 0x200,
  3373. CXObjCPropertyAttr_strong = 0x400,
  3374. CXObjCPropertyAttr_unsafe_unretained = 0x800
  3375. } CXObjCPropertyAttrKind;
  3376. /**
  3377. * \brief Given a cursor that represents a property declaration, return the
  3378. * associated property attributes. The bits are formed from
  3379. * \c CXObjCPropertyAttrKind.
  3380. *
  3381. * \param reserved Reserved for future use, pass 0.
  3382. */
  3383. CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
  3384. unsigned reserved);
  3385. /**
  3386. * \brief 'Qualifiers' written next to the return and parameter types in
  3387. * Objective-C method declarations.
  3388. */
  3389. typedef enum {
  3390. CXObjCDeclQualifier_None = 0x0,
  3391. CXObjCDeclQualifier_In = 0x1,
  3392. CXObjCDeclQualifier_Inout = 0x2,
  3393. CXObjCDeclQualifier_Out = 0x4,
  3394. CXObjCDeclQualifier_Bycopy = 0x8,
  3395. CXObjCDeclQualifier_Byref = 0x10,
  3396. CXObjCDeclQualifier_Oneway = 0x20
  3397. } CXObjCDeclQualifierKind;
  3398. /**
  3399. * \brief Given a cursor that represents an Objective-C method or parameter
  3400. * declaration, return the associated Objective-C qualifiers for the return
  3401. * type or the parameter respectively. The bits are formed from
  3402. * CXObjCDeclQualifierKind.
  3403. */
  3404. CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
  3405. /**
  3406. * \brief Given a cursor that represents an Objective-C method or property
  3407. * declaration, return non-zero if the declaration was affected by "@optional".
  3408. * Returns zero if the cursor is not such a declaration or it is "@required".
  3409. */
  3410. CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
  3411. /**
  3412. * \brief Returns non-zero if the given cursor is a variadic function or method.
  3413. */
  3414. CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
  3415. /**
  3416. * \brief Given a cursor that represents a declaration, return the associated
  3417. * comment's source range. The range may include multiple consecutive comments
  3418. * with whitespace in between.
  3419. */
  3420. CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
  3421. /**
  3422. * \brief Given a cursor that represents a declaration, return the associated
  3423. * comment text, including comment markers.
  3424. */
  3425. CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
  3426. /**
  3427. * \brief Given a cursor that represents a documentable entity (e.g.,
  3428. * declaration), return the associated \\brief paragraph; otherwise return the
  3429. * first paragraph.
  3430. */
  3431. CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
  3432. /**
  3433. * @}
  3434. */
  3435. /** \defgroup CINDEX_MANGLE Name Mangling API Functions
  3436. *
  3437. * @{
  3438. */
  3439. /**
  3440. * \brief Retrieve the CXString representing the mangled name of the cursor.
  3441. */
  3442. CINDEX_LINKAGE CXString clang_Cursor_getMangling(CXCursor);
  3443. /**
  3444. * @}
  3445. */
  3446. /**
  3447. * \defgroup CINDEX_MODULE Module introspection
  3448. *
  3449. * The functions in this group provide access to information about modules.
  3450. *
  3451. * @{
  3452. */
  3453. typedef void *CXModule;
  3454. /**
  3455. * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
  3456. */
  3457. CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
  3458. /**
  3459. * \brief Given a CXFile header file, return the module that contains it, if one
  3460. * exists.
  3461. */
  3462. CINDEX_LINKAGE CXModule clang_getModuleForFile(CXTranslationUnit, CXFile);
  3463. /**
  3464. * \param Module a module object.
  3465. *
  3466. * \returns the module file where the provided module object came from.
  3467. */
  3468. CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
  3469. /**
  3470. * \param Module a module object.
  3471. *
  3472. * \returns the parent of a sub-module or NULL if the given module is top-level,
  3473. * e.g. for 'std.vector' it will return the 'std' module.
  3474. */
  3475. CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
  3476. /**
  3477. * \param Module a module object.
  3478. *
  3479. * \returns the name of the module, e.g. for the 'std.vector' sub-module it
  3480. * will return "vector".
  3481. */
  3482. CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
  3483. /**
  3484. * \param Module a module object.
  3485. *
  3486. * \returns the full name of the module, e.g. "std.vector".
  3487. */
  3488. CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
  3489. /**
  3490. * \param Module a module object.
  3491. *
  3492. * \returns non-zero if the module is a system one.
  3493. */
  3494. CINDEX_LINKAGE int clang_Module_isSystem(CXModule Module);
  3495. /**
  3496. * \param Module a module object.
  3497. *
  3498. * \returns the number of top level headers associated with this module.
  3499. */
  3500. CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
  3501. CXModule Module);
  3502. /**
  3503. * \param Module a module object.
  3504. *
  3505. * \param Index top level header index (zero-based).
  3506. *
  3507. * \returns the specified top level header associated with the module.
  3508. */
  3509. CINDEX_LINKAGE
  3510. CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
  3511. CXModule Module, unsigned Index);
  3512. /**
  3513. * @}
  3514. */
  3515. /**
  3516. * \defgroup CINDEX_CPP C++ AST introspection
  3517. *
  3518. * The routines in this group provide access information in the ASTs specific
  3519. * to C++ language features.
  3520. *
  3521. * @{
  3522. */
  3523. /**
  3524. * \brief Determine if a C++ member function or member function template is
  3525. * pure virtual.
  3526. */
  3527. CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
  3528. /**
  3529. * \brief Determine if a C++ member function or member function template is
  3530. * declared 'static'.
  3531. */
  3532. CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
  3533. /**
  3534. * \brief Determine if a C++ member function or member function template is
  3535. * explicitly declared 'virtual' or if it overrides a virtual method from
  3536. * one of the base classes.
  3537. */
  3538. CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
  3539. /**
  3540. * \brief Determine if a C++ member function or member function template is
  3541. * declared 'const'.
  3542. */
  3543. CINDEX_LINKAGE unsigned clang_CXXMethod_isConst(CXCursor C);
  3544. /**
  3545. * \brief Given a cursor that represents a template, determine
  3546. * the cursor kind of the specializations would be generated by instantiating
  3547. * the template.
  3548. *
  3549. * This routine can be used to determine what flavor of function template,
  3550. * class template, or class template partial specialization is stored in the
  3551. * cursor. For example, it can describe whether a class template cursor is
  3552. * declared with "struct", "class" or "union".
  3553. *
  3554. * \param C The cursor to query. This cursor should represent a template
  3555. * declaration.
  3556. *
  3557. * \returns The cursor kind of the specializations that would be generated
  3558. * by instantiating the template \p C. If \p C is not a template, returns
  3559. * \c CXCursor_NoDeclFound.
  3560. */
  3561. CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
  3562. /**
  3563. * \brief Given a cursor that may represent a specialization or instantiation
  3564. * of a template, retrieve the cursor that represents the template that it
  3565. * specializes or from which it was instantiated.
  3566. *
  3567. * This routine determines the template involved both for explicit
  3568. * specializations of templates and for implicit instantiations of the template,
  3569. * both of which are referred to as "specializations". For a class template
  3570. * specialization (e.g., \c std::vector<bool>), this routine will return
  3571. * either the primary template (\c std::vector) or, if the specialization was
  3572. * instantiated from a class template partial specialization, the class template
  3573. * partial specialization. For a class template partial specialization and a
  3574. * function template specialization (including instantiations), this
  3575. * this routine will return the specialized template.
  3576. *
  3577. * For members of a class template (e.g., member functions, member classes, or
  3578. * static data members), returns the specialized or instantiated member.
  3579. * Although not strictly "templates" in the C++ language, members of class
  3580. * templates have the same notions of specializations and instantiations that
  3581. * templates do, so this routine treats them similarly.
  3582. *
  3583. * \param C A cursor that may be a specialization of a template or a member
  3584. * of a template.
  3585. *
  3586. * \returns If the given cursor is a specialization or instantiation of a
  3587. * template or a member thereof, the template or member that it specializes or
  3588. * from which it was instantiated. Otherwise, returns a NULL cursor.
  3589. */
  3590. CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
  3591. /**
  3592. * \brief Given a cursor that references something else, return the source range
  3593. * covering that reference.
  3594. *
  3595. * \param C A cursor pointing to a member reference, a declaration reference, or
  3596. * an operator call.
  3597. * \param NameFlags A bitset with three independent flags:
  3598. * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
  3599. * CXNameRange_WantSinglePiece.
  3600. * \param PieceIndex For contiguous names or when passing the flag
  3601. * CXNameRange_WantSinglePiece, only one piece with index 0 is
  3602. * available. When the CXNameRange_WantSinglePiece flag is not passed for a
  3603. * non-contiguous names, this index can be used to retrieve the individual
  3604. * pieces of the name. See also CXNameRange_WantSinglePiece.
  3605. *
  3606. * \returns The piece of the name pointed to by the given cursor. If there is no
  3607. * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
  3608. */
  3609. CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
  3610. unsigned NameFlags,
  3611. unsigned PieceIndex);
  3612. enum CXNameRefFlags {
  3613. /**
  3614. * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
  3615. * range.
  3616. */
  3617. CXNameRange_WantQualifier = 0x1,
  3618. /**
  3619. * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
  3620. * in the range.
  3621. */
  3622. CXNameRange_WantTemplateArgs = 0x2,
  3623. /**
  3624. * \brief If the name is non-contiguous, return the full spanning range.
  3625. *
  3626. * Non-contiguous names occur in Objective-C when a selector with two or more
  3627. * parameters is used, or in C++ when using an operator:
  3628. * \code
  3629. * [object doSomething:here withValue:there]; // Objective-C
  3630. * return some_vector[1]; // C++
  3631. * \endcode
  3632. */
  3633. CXNameRange_WantSinglePiece = 0x4
  3634. };
  3635. /**
  3636. * @}
  3637. */
  3638. /**
  3639. * \defgroup CINDEX_LEX Token extraction and manipulation
  3640. *
  3641. * The routines in this group provide access to the tokens within a
  3642. * translation unit, along with a semantic mapping of those tokens to
  3643. * their corresponding cursors.
  3644. *
  3645. * @{
  3646. */
  3647. /**
  3648. * \brief Describes a kind of token.
  3649. */
  3650. typedef enum CXTokenKind {
  3651. /**
  3652. * \brief A token that contains some kind of punctuation.
  3653. */
  3654. CXToken_Punctuation,
  3655. /**
  3656. * \brief A language keyword.
  3657. */
  3658. CXToken_Keyword,
  3659. /**
  3660. * \brief An identifier (that is not a keyword).
  3661. */
  3662. CXToken_Identifier,
  3663. /**
  3664. * \brief A numeric, string, or character literal.
  3665. */
  3666. CXToken_Literal,
  3667. /**
  3668. * \brief A comment.
  3669. */
  3670. CXToken_Comment
  3671. } CXTokenKind;
  3672. /**
  3673. * \brief Describes a single preprocessing token.
  3674. */
  3675. typedef struct {
  3676. unsigned int_data[4];
  3677. void *ptr_data;
  3678. } CXToken;
  3679. /**
  3680. * \brief Determine the kind of the given token.
  3681. */
  3682. CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
  3683. /**
  3684. * \brief Determine the spelling of the given token.
  3685. *
  3686. * The spelling of a token is the textual representation of that token, e.g.,
  3687. * the text of an identifier or keyword.
  3688. */
  3689. CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
  3690. /**
  3691. * \brief Retrieve the source location of the given token.
  3692. */
  3693. CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
  3694. CXToken);
  3695. /**
  3696. * \brief Retrieve a source range that covers the given token.
  3697. */
  3698. CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
  3699. /**
  3700. * \brief Tokenize the source code described by the given range into raw
  3701. * lexical tokens.
  3702. *
  3703. * \param TU the translation unit whose text is being tokenized.
  3704. *
  3705. * \param Range the source range in which text should be tokenized. All of the
  3706. * tokens produced by tokenization will fall within this source range,
  3707. *
  3708. * \param Tokens this pointer will be set to point to the array of tokens
  3709. * that occur within the given source range. The returned pointer must be
  3710. * freed with clang_disposeTokens() before the translation unit is destroyed.
  3711. *
  3712. * \param NumTokens will be set to the number of tokens in the \c *Tokens
  3713. * array.
  3714. *
  3715. */
  3716. CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
  3717. CXToken **Tokens, unsigned *NumTokens);
  3718. /**
  3719. * \brief Annotate the given set of tokens by providing cursors for each token
  3720. * that can be mapped to a specific entity within the abstract syntax tree.
  3721. *
  3722. * This token-annotation routine is equivalent to invoking
  3723. * clang_getCursor() for the source locations of each of the
  3724. * tokens. The cursors provided are filtered, so that only those
  3725. * cursors that have a direct correspondence to the token are
  3726. * accepted. For example, given a function call \c f(x),
  3727. * clang_getCursor() would provide the following cursors:
  3728. *
  3729. * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
  3730. * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
  3731. * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
  3732. *
  3733. * Only the first and last of these cursors will occur within the
  3734. * annotate, since the tokens "f" and "x' directly refer to a function
  3735. * and a variable, respectively, but the parentheses are just a small
  3736. * part of the full syntax of the function call expression, which is
  3737. * not provided as an annotation.
  3738. *
  3739. * \param TU the translation unit that owns the given tokens.
  3740. *
  3741. * \param Tokens the set of tokens to annotate.
  3742. *
  3743. * \param NumTokens the number of tokens in \p Tokens.
  3744. *
  3745. * \param Cursors an array of \p NumTokens cursors, whose contents will be
  3746. * replaced with the cursors corresponding to each token.
  3747. */
  3748. CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
  3749. CXToken *Tokens, unsigned NumTokens,
  3750. CXCursor *Cursors);
  3751. /**
  3752. * \brief Free the given set of tokens.
  3753. */
  3754. CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
  3755. CXToken *Tokens, unsigned NumTokens);
  3756. /**
  3757. * @}
  3758. */
  3759. /**
  3760. * \defgroup CINDEX_DEBUG Debugging facilities
  3761. *
  3762. * These routines are used for testing and debugging, only, and should not
  3763. * be relied upon.
  3764. *
  3765. * @{
  3766. */
  3767. /* for debug/testing */
  3768. CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
  3769. CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
  3770. const char **startBuf,
  3771. const char **endBuf,
  3772. unsigned *startLine,
  3773. unsigned *startColumn,
  3774. unsigned *endLine,
  3775. unsigned *endColumn);
  3776. CINDEX_LINKAGE void clang_enableStackTraces(void);
  3777. CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
  3778. unsigned stack_size);
  3779. /**
  3780. * @}
  3781. */
  3782. /**
  3783. * \defgroup CINDEX_CODE_COMPLET Code completion
  3784. *
  3785. * Code completion involves taking an (incomplete) source file, along with
  3786. * knowledge of where the user is actively editing that file, and suggesting
  3787. * syntactically- and semantically-valid constructs that the user might want to
  3788. * use at that particular point in the source code. These data structures and
  3789. * routines provide support for code completion.
  3790. *
  3791. * @{
  3792. */
  3793. /**
  3794. * \brief A semantic string that describes a code-completion result.
  3795. *
  3796. * A semantic string that describes the formatting of a code-completion
  3797. * result as a single "template" of text that should be inserted into the
  3798. * source buffer when a particular code-completion result is selected.
  3799. * Each semantic string is made up of some number of "chunks", each of which
  3800. * contains some text along with a description of what that text means, e.g.,
  3801. * the name of the entity being referenced, whether the text chunk is part of
  3802. * the template, or whether it is a "placeholder" that the user should replace
  3803. * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
  3804. * description of the different kinds of chunks.
  3805. */
  3806. typedef void *CXCompletionString;
  3807. /**
  3808. * \brief A single result of code completion.
  3809. */
  3810. typedef struct {
  3811. /**
  3812. * \brief The kind of entity that this completion refers to.
  3813. *
  3814. * The cursor kind will be a macro, keyword, or a declaration (one of the
  3815. * *Decl cursor kinds), describing the entity that the completion is
  3816. * referring to.
  3817. *
  3818. * \todo In the future, we would like to provide a full cursor, to allow
  3819. * the client to extract additional information from declaration.
  3820. */
  3821. enum CXCursorKind CursorKind;
  3822. /**
  3823. * \brief The code-completion string that describes how to insert this
  3824. * code-completion result into the editing buffer.
  3825. */
  3826. CXCompletionString CompletionString;
  3827. } CXCompletionResult;
  3828. /**
  3829. * \brief Describes a single piece of text within a code-completion string.
  3830. *
  3831. * Each "chunk" within a code-completion string (\c CXCompletionString) is
  3832. * either a piece of text with a specific "kind" that describes how that text
  3833. * should be interpreted by the client or is another completion string.
  3834. */
  3835. enum CXCompletionChunkKind {
  3836. /**
  3837. * \brief A code-completion string that describes "optional" text that
  3838. * could be a part of the template (but is not required).
  3839. *
  3840. * The Optional chunk is the only kind of chunk that has a code-completion
  3841. * string for its representation, which is accessible via
  3842. * \c clang_getCompletionChunkCompletionString(). The code-completion string
  3843. * describes an additional part of the template that is completely optional.
  3844. * For example, optional chunks can be used to describe the placeholders for
  3845. * arguments that match up with defaulted function parameters, e.g. given:
  3846. *
  3847. * \code
  3848. * void f(int x, float y = 3.14, double z = 2.71828);
  3849. * \endcode
  3850. *
  3851. * The code-completion string for this function would contain:
  3852. * - a TypedText chunk for "f".
  3853. * - a LeftParen chunk for "(".
  3854. * - a Placeholder chunk for "int x"
  3855. * - an Optional chunk containing the remaining defaulted arguments, e.g.,
  3856. * - a Comma chunk for ","
  3857. * - a Placeholder chunk for "float y"
  3858. * - an Optional chunk containing the last defaulted argument:
  3859. * - a Comma chunk for ","
  3860. * - a Placeholder chunk for "double z"
  3861. * - a RightParen chunk for ")"
  3862. *
  3863. * There are many ways to handle Optional chunks. Two simple approaches are:
  3864. * - Completely ignore optional chunks, in which case the template for the
  3865. * function "f" would only include the first parameter ("int x").
  3866. * - Fully expand all optional chunks, in which case the template for the
  3867. * function "f" would have all of the parameters.
  3868. */
  3869. CXCompletionChunk_Optional,
  3870. /**
  3871. * \brief Text that a user would be expected to type to get this
  3872. * code-completion result.
  3873. *
  3874. * There will be exactly one "typed text" chunk in a semantic string, which
  3875. * will typically provide the spelling of a keyword or the name of a
  3876. * declaration that could be used at the current code point. Clients are
  3877. * expected to filter the code-completion results based on the text in this
  3878. * chunk.
  3879. */
  3880. CXCompletionChunk_TypedText,
  3881. /**
  3882. * \brief Text that should be inserted as part of a code-completion result.
  3883. *
  3884. * A "text" chunk represents text that is part of the template to be
  3885. * inserted into user code should this particular code-completion result
  3886. * be selected.
  3887. */
  3888. CXCompletionChunk_Text,
  3889. /**
  3890. * \brief Placeholder text that should be replaced by the user.
  3891. *
  3892. * A "placeholder" chunk marks a place where the user should insert text
  3893. * into the code-completion template. For example, placeholders might mark
  3894. * the function parameters for a function declaration, to indicate that the
  3895. * user should provide arguments for each of those parameters. The actual
  3896. * text in a placeholder is a suggestion for the text to display before
  3897. * the user replaces the placeholder with real code.
  3898. */
  3899. CXCompletionChunk_Placeholder,
  3900. /**
  3901. * \brief Informative text that should be displayed but never inserted as
  3902. * part of the template.
  3903. *
  3904. * An "informative" chunk contains annotations that can be displayed to
  3905. * help the user decide whether a particular code-completion result is the
  3906. * right option, but which is not part of the actual template to be inserted
  3907. * by code completion.
  3908. */
  3909. CXCompletionChunk_Informative,
  3910. /**
  3911. * \brief Text that describes the current parameter when code-completion is
  3912. * referring to function call, message send, or template specialization.
  3913. *
  3914. * A "current parameter" chunk occurs when code-completion is providing
  3915. * information about a parameter corresponding to the argument at the
  3916. * code-completion point. For example, given a function
  3917. *
  3918. * \code
  3919. * int add(int x, int y);
  3920. * \endcode
  3921. *
  3922. * and the source code \c add(, where the code-completion point is after the
  3923. * "(", the code-completion string will contain a "current parameter" chunk
  3924. * for "int x", indicating that the current argument will initialize that
  3925. * parameter. After typing further, to \c add(17, (where the code-completion
  3926. * point is after the ","), the code-completion string will contain a
  3927. * "current paremeter" chunk to "int y".
  3928. */
  3929. CXCompletionChunk_CurrentParameter,
  3930. /**
  3931. * \brief A left parenthesis ('('), used to initiate a function call or
  3932. * signal the beginning of a function parameter list.
  3933. */
  3934. CXCompletionChunk_LeftParen,
  3935. /**
  3936. * \brief A right parenthesis (')'), used to finish a function call or
  3937. * signal the end of a function parameter list.
  3938. */
  3939. CXCompletionChunk_RightParen,
  3940. /**
  3941. * \brief A left bracket ('[').
  3942. */
  3943. CXCompletionChunk_LeftBracket,
  3944. /**
  3945. * \brief A right bracket (']').
  3946. */
  3947. CXCompletionChunk_RightBracket,
  3948. /**
  3949. * \brief A left brace ('{').
  3950. */
  3951. CXCompletionChunk_LeftBrace,
  3952. /**
  3953. * \brief A right brace ('}').
  3954. */
  3955. CXCompletionChunk_RightBrace,
  3956. /**
  3957. * \brief A left angle bracket ('<').
  3958. */
  3959. CXCompletionChunk_LeftAngle,
  3960. /**
  3961. * \brief A right angle bracket ('>').
  3962. */
  3963. CXCompletionChunk_RightAngle,
  3964. /**
  3965. * \brief A comma separator (',').
  3966. */
  3967. CXCompletionChunk_Comma,
  3968. /**
  3969. * \brief Text that specifies the result type of a given result.
  3970. *
  3971. * This special kind of informative chunk is not meant to be inserted into
  3972. * the text buffer. Rather, it is meant to illustrate the type that an
  3973. * expression using the given completion string would have.
  3974. */
  3975. CXCompletionChunk_ResultType,
  3976. /**
  3977. * \brief A colon (':').
  3978. */
  3979. CXCompletionChunk_Colon,
  3980. /**
  3981. * \brief A semicolon (';').
  3982. */
  3983. CXCompletionChunk_SemiColon,
  3984. /**
  3985. * \brief An '=' sign.
  3986. */
  3987. CXCompletionChunk_Equal,
  3988. /**
  3989. * Horizontal space (' ').
  3990. */
  3991. CXCompletionChunk_HorizontalSpace,
  3992. /**
  3993. * Vertical space ('\n'), after which it is generally a good idea to
  3994. * perform indentation.
  3995. */
  3996. CXCompletionChunk_VerticalSpace
  3997. };
  3998. /**
  3999. * \brief Determine the kind of a particular chunk within a completion string.
  4000. *
  4001. * \param completion_string the completion string to query.
  4002. *
  4003. * \param chunk_number the 0-based index of the chunk in the completion string.
  4004. *
  4005. * \returns the kind of the chunk at the index \c chunk_number.
  4006. */
  4007. CINDEX_LINKAGE enum CXCompletionChunkKind
  4008. clang_getCompletionChunkKind(CXCompletionString completion_string,
  4009. unsigned chunk_number);
  4010. /**
  4011. * \brief Retrieve the text associated with a particular chunk within a
  4012. * completion string.
  4013. *
  4014. * \param completion_string the completion string to query.
  4015. *
  4016. * \param chunk_number the 0-based index of the chunk in the completion string.
  4017. *
  4018. * \returns the text associated with the chunk at index \c chunk_number.
  4019. */
  4020. CINDEX_LINKAGE CXString
  4021. clang_getCompletionChunkText(CXCompletionString completion_string,
  4022. unsigned chunk_number);
  4023. /**
  4024. * \brief Retrieve the completion string associated with a particular chunk
  4025. * within a completion string.
  4026. *
  4027. * \param completion_string the completion string to query.
  4028. *
  4029. * \param chunk_number the 0-based index of the chunk in the completion string.
  4030. *
  4031. * \returns the completion string associated with the chunk at index
  4032. * \c chunk_number.
  4033. */
  4034. CINDEX_LINKAGE CXCompletionString
  4035. clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
  4036. unsigned chunk_number);
  4037. /**
  4038. * \brief Retrieve the number of chunks in the given code-completion string.
  4039. */
  4040. CINDEX_LINKAGE unsigned
  4041. clang_getNumCompletionChunks(CXCompletionString completion_string);
  4042. /**
  4043. * \brief Determine the priority of this code completion.
  4044. *
  4045. * The priority of a code completion indicates how likely it is that this
  4046. * particular completion is the completion that the user will select. The
  4047. * priority is selected by various internal heuristics.
  4048. *
  4049. * \param completion_string The completion string to query.
  4050. *
  4051. * \returns The priority of this completion string. Smaller values indicate
  4052. * higher-priority (more likely) completions.
  4053. */
  4054. CINDEX_LINKAGE unsigned
  4055. clang_getCompletionPriority(CXCompletionString completion_string);
  4056. /**
  4057. * \brief Determine the availability of the entity that this code-completion
  4058. * string refers to.
  4059. *
  4060. * \param completion_string The completion string to query.
  4061. *
  4062. * \returns The availability of the completion string.
  4063. */
  4064. CINDEX_LINKAGE enum CXAvailabilityKind
  4065. clang_getCompletionAvailability(CXCompletionString completion_string);
  4066. /**
  4067. * \brief Retrieve the number of annotations associated with the given
  4068. * completion string.
  4069. *
  4070. * \param completion_string the completion string to query.
  4071. *
  4072. * \returns the number of annotations associated with the given completion
  4073. * string.
  4074. */
  4075. CINDEX_LINKAGE unsigned
  4076. clang_getCompletionNumAnnotations(CXCompletionString completion_string);
  4077. /**
  4078. * \brief Retrieve the annotation associated with the given completion string.
  4079. *
  4080. * \param completion_string the completion string to query.
  4081. *
  4082. * \param annotation_number the 0-based index of the annotation of the
  4083. * completion string.
  4084. *
  4085. * \returns annotation string associated with the completion at index
  4086. * \c annotation_number, or a NULL string if that annotation is not available.
  4087. */
  4088. CINDEX_LINKAGE CXString
  4089. clang_getCompletionAnnotation(CXCompletionString completion_string,
  4090. unsigned annotation_number);
  4091. /**
  4092. * \brief Retrieve the parent context of the given completion string.
  4093. *
  4094. * The parent context of a completion string is the semantic parent of
  4095. * the declaration (if any) that the code completion represents. For example,
  4096. * a code completion for an Objective-C method would have the method's class
  4097. * or protocol as its context.
  4098. *
  4099. * \param completion_string The code completion string whose parent is
  4100. * being queried.
  4101. *
  4102. * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
  4103. *
  4104. * \returns The name of the completion parent, e.g., "NSObject" if
  4105. * the completion string represents a method in the NSObject class.
  4106. */
  4107. CINDEX_LINKAGE CXString
  4108. clang_getCompletionParent(CXCompletionString completion_string,
  4109. enum CXCursorKind *kind);
  4110. /**
  4111. * \brief Retrieve the brief documentation comment attached to the declaration
  4112. * that corresponds to the given completion string.
  4113. */
  4114. CINDEX_LINKAGE CXString
  4115. clang_getCompletionBriefComment(CXCompletionString completion_string);
  4116. /**
  4117. * \brief Retrieve a completion string for an arbitrary declaration or macro
  4118. * definition cursor.
  4119. *
  4120. * \param cursor The cursor to query.
  4121. *
  4122. * \returns A non-context-sensitive completion string for declaration and macro
  4123. * definition cursors, or NULL for other kinds of cursors.
  4124. */
  4125. CINDEX_LINKAGE CXCompletionString
  4126. clang_getCursorCompletionString(CXCursor cursor);
  4127. /**
  4128. * \brief Contains the results of code-completion.
  4129. *
  4130. * This data structure contains the results of code completion, as
  4131. * produced by \c clang_codeCompleteAt(). Its contents must be freed by
  4132. * \c clang_disposeCodeCompleteResults.
  4133. */
  4134. typedef struct {
  4135. /**
  4136. * \brief The code-completion results.
  4137. */
  4138. CXCompletionResult *Results;
  4139. /**
  4140. * \brief The number of code-completion results stored in the
  4141. * \c Results array.
  4142. */
  4143. unsigned NumResults;
  4144. } CXCodeCompleteResults;
  4145. /**
  4146. * \brief Flags that can be passed to \c clang_codeCompleteAt() to
  4147. * modify its behavior.
  4148. *
  4149. * The enumerators in this enumeration can be bitwise-OR'd together to
  4150. * provide multiple options to \c clang_codeCompleteAt().
  4151. */
  4152. enum CXCodeComplete_Flags {
  4153. /**
  4154. * \brief Whether to include macros within the set of code
  4155. * completions returned.
  4156. */
  4157. CXCodeComplete_IncludeMacros = 0x01,
  4158. /**
  4159. * \brief Whether to include code patterns for language constructs
  4160. * within the set of code completions, e.g., for loops.
  4161. */
  4162. CXCodeComplete_IncludeCodePatterns = 0x02,
  4163. /**
  4164. * \brief Whether to include brief documentation within the set of code
  4165. * completions returned.
  4166. */
  4167. CXCodeComplete_IncludeBriefComments = 0x04
  4168. };
  4169. /**
  4170. * \brief Bits that represent the context under which completion is occurring.
  4171. *
  4172. * The enumerators in this enumeration may be bitwise-OR'd together if multiple
  4173. * contexts are occurring simultaneously.
  4174. */
  4175. enum CXCompletionContext {
  4176. /**
  4177. * \brief The context for completions is unexposed, as only Clang results
  4178. * should be included. (This is equivalent to having no context bits set.)
  4179. */
  4180. CXCompletionContext_Unexposed = 0,
  4181. /**
  4182. * \brief Completions for any possible type should be included in the results.
  4183. */
  4184. CXCompletionContext_AnyType = 1 << 0,
  4185. /**
  4186. * \brief Completions for any possible value (variables, function calls, etc.)
  4187. * should be included in the results.
  4188. */
  4189. CXCompletionContext_AnyValue = 1 << 1,
  4190. /**
  4191. * \brief Completions for values that resolve to an Objective-C object should
  4192. * be included in the results.
  4193. */
  4194. CXCompletionContext_ObjCObjectValue = 1 << 2,
  4195. /**
  4196. * \brief Completions for values that resolve to an Objective-C selector
  4197. * should be included in the results.
  4198. */
  4199. CXCompletionContext_ObjCSelectorValue = 1 << 3,
  4200. /**
  4201. * \brief Completions for values that resolve to a C++ class type should be
  4202. * included in the results.
  4203. */
  4204. CXCompletionContext_CXXClassTypeValue = 1 << 4,
  4205. /**
  4206. * \brief Completions for fields of the member being accessed using the dot
  4207. * operator should be included in the results.
  4208. */
  4209. CXCompletionContext_DotMemberAccess = 1 << 5,
  4210. /**
  4211. * \brief Completions for fields of the member being accessed using the arrow
  4212. * operator should be included in the results.
  4213. */
  4214. CXCompletionContext_ArrowMemberAccess = 1 << 6,
  4215. /**
  4216. * \brief Completions for properties of the Objective-C object being accessed
  4217. * using the dot operator should be included in the results.
  4218. */
  4219. CXCompletionContext_ObjCPropertyAccess = 1 << 7,
  4220. /**
  4221. * \brief Completions for enum tags should be included in the results.
  4222. */
  4223. CXCompletionContext_EnumTag = 1 << 8,
  4224. /**
  4225. * \brief Completions for union tags should be included in the results.
  4226. */
  4227. CXCompletionContext_UnionTag = 1 << 9,
  4228. /**
  4229. * \brief Completions for struct tags should be included in the results.
  4230. */
  4231. CXCompletionContext_StructTag = 1 << 10,
  4232. /**
  4233. * \brief Completions for C++ class names should be included in the results.
  4234. */
  4235. CXCompletionContext_ClassTag = 1 << 11,
  4236. /**
  4237. * \brief Completions for C++ namespaces and namespace aliases should be
  4238. * included in the results.
  4239. */
  4240. CXCompletionContext_Namespace = 1 << 12,
  4241. /**
  4242. * \brief Completions for C++ nested name specifiers should be included in
  4243. * the results.
  4244. */
  4245. CXCompletionContext_NestedNameSpecifier = 1 << 13,
  4246. /**
  4247. * \brief Completions for Objective-C interfaces (classes) should be included
  4248. * in the results.
  4249. */
  4250. CXCompletionContext_ObjCInterface = 1 << 14,
  4251. /**
  4252. * \brief Completions for Objective-C protocols should be included in
  4253. * the results.
  4254. */
  4255. CXCompletionContext_ObjCProtocol = 1 << 15,
  4256. /**
  4257. * \brief Completions for Objective-C categories should be included in
  4258. * the results.
  4259. */
  4260. CXCompletionContext_ObjCCategory = 1 << 16,
  4261. /**
  4262. * \brief Completions for Objective-C instance messages should be included
  4263. * in the results.
  4264. */
  4265. CXCompletionContext_ObjCInstanceMessage = 1 << 17,
  4266. /**
  4267. * \brief Completions for Objective-C class messages should be included in
  4268. * the results.
  4269. */
  4270. CXCompletionContext_ObjCClassMessage = 1 << 18,
  4271. /**
  4272. * \brief Completions for Objective-C selector names should be included in
  4273. * the results.
  4274. */
  4275. CXCompletionContext_ObjCSelectorName = 1 << 19,
  4276. /**
  4277. * \brief Completions for preprocessor macro names should be included in
  4278. * the results.
  4279. */
  4280. CXCompletionContext_MacroName = 1 << 20,
  4281. /**
  4282. * \brief Natural language completions should be included in the results.
  4283. */
  4284. CXCompletionContext_NaturalLanguage = 1 << 21,
  4285. /**
  4286. * \brief The current context is unknown, so set all contexts.
  4287. */
  4288. CXCompletionContext_Unknown = ((1 << 22) - 1)
  4289. };
  4290. /**
  4291. * \brief Returns a default set of code-completion options that can be
  4292. * passed to\c clang_codeCompleteAt().
  4293. */
  4294. CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
  4295. /**
  4296. * \brief Perform code completion at a given location in a translation unit.
  4297. *
  4298. * This function performs code completion at a particular file, line, and
  4299. * column within source code, providing results that suggest potential
  4300. * code snippets based on the context of the completion. The basic model
  4301. * for code completion is that Clang will parse a complete source file,
  4302. * performing syntax checking up to the location where code-completion has
  4303. * been requested. At that point, a special code-completion token is passed
  4304. * to the parser, which recognizes this token and determines, based on the
  4305. * current location in the C/Objective-C/C++ grammar and the state of
  4306. * semantic analysis, what completions to provide. These completions are
  4307. * returned via a new \c CXCodeCompleteResults structure.
  4308. *
  4309. * Code completion itself is meant to be triggered by the client when the
  4310. * user types punctuation characters or whitespace, at which point the
  4311. * code-completion location will coincide with the cursor. For example, if \c p
  4312. * is a pointer, code-completion might be triggered after the "-" and then
  4313. * after the ">" in \c p->. When the code-completion location is afer the ">",
  4314. * the completion results will provide, e.g., the members of the struct that
  4315. * "p" points to. The client is responsible for placing the cursor at the
  4316. * beginning of the token currently being typed, then filtering the results
  4317. * based on the contents of the token. For example, when code-completing for
  4318. * the expression \c p->get, the client should provide the location just after
  4319. * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
  4320. * client can filter the results based on the current token text ("get"), only
  4321. * showing those results that start with "get". The intent of this interface
  4322. * is to separate the relatively high-latency acquisition of code-completion
  4323. * results from the filtering of results on a per-character basis, which must
  4324. * have a lower latency.
  4325. *
  4326. * \param TU The translation unit in which code-completion should
  4327. * occur. The source files for this translation unit need not be
  4328. * completely up-to-date (and the contents of those source files may
  4329. * be overridden via \p unsaved_files). Cursors referring into the
  4330. * translation unit may be invalidated by this invocation.
  4331. *
  4332. * \param complete_filename The name of the source file where code
  4333. * completion should be performed. This filename may be any file
  4334. * included in the translation unit.
  4335. *
  4336. * \param complete_line The line at which code-completion should occur.
  4337. *
  4338. * \param complete_column The column at which code-completion should occur.
  4339. * Note that the column should point just after the syntactic construct that
  4340. * initiated code completion, and not in the middle of a lexical token.
  4341. *
  4342. * \param unsaved_files the Tiles that have not yet been saved to disk
  4343. * but may be required for parsing or code completion, including the
  4344. * contents of those files. The contents and name of these files (as
  4345. * specified by CXUnsavedFile) are copied when necessary, so the
  4346. * client only needs to guarantee their validity until the call to
  4347. * this function returns.
  4348. *
  4349. * \param num_unsaved_files The number of unsaved file entries in \p
  4350. * unsaved_files.
  4351. *
  4352. * \param options Extra options that control the behavior of code
  4353. * completion, expressed as a bitwise OR of the enumerators of the
  4354. * CXCodeComplete_Flags enumeration. The
  4355. * \c clang_defaultCodeCompleteOptions() function returns a default set
  4356. * of code-completion options.
  4357. *
  4358. * \returns If successful, a new \c CXCodeCompleteResults structure
  4359. * containing code-completion results, which should eventually be
  4360. * freed with \c clang_disposeCodeCompleteResults(). If code
  4361. * completion fails, returns NULL.
  4362. */
  4363. CINDEX_LINKAGE
  4364. CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
  4365. const char *complete_filename,
  4366. unsigned complete_line,
  4367. unsigned complete_column,
  4368. struct CXUnsavedFile *unsaved_files,
  4369. unsigned num_unsaved_files,
  4370. unsigned options);
  4371. /**
  4372. * \brief Sort the code-completion results in case-insensitive alphabetical
  4373. * order.
  4374. *
  4375. * \param Results The set of results to sort.
  4376. * \param NumResults The number of results in \p Results.
  4377. */
  4378. CINDEX_LINKAGE
  4379. void clang_sortCodeCompletionResults(CXCompletionResult *Results,
  4380. unsigned NumResults);
  4381. /**
  4382. * \brief Free the given set of code-completion results.
  4383. */
  4384. CINDEX_LINKAGE
  4385. void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
  4386. /**
  4387. * \brief Determine the number of diagnostics produced prior to the
  4388. * location where code completion was performed.
  4389. */
  4390. CINDEX_LINKAGE
  4391. unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
  4392. /**
  4393. * \brief Retrieve a diagnostic associated with the given code completion.
  4394. *
  4395. * \param Results the code completion results to query.
  4396. * \param Index the zero-based diagnostic number to retrieve.
  4397. *
  4398. * \returns the requested diagnostic. This diagnostic must be freed
  4399. * via a call to \c clang_disposeDiagnostic().
  4400. */
  4401. CINDEX_LINKAGE
  4402. CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
  4403. unsigned Index);
  4404. /**
  4405. * \brief Determines what completions are appropriate for the context
  4406. * the given code completion.
  4407. *
  4408. * \param Results the code completion results to query
  4409. *
  4410. * \returns the kinds of completions that are appropriate for use
  4411. * along with the given code completion results.
  4412. */
  4413. CINDEX_LINKAGE
  4414. unsigned long long clang_codeCompleteGetContexts(
  4415. CXCodeCompleteResults *Results);
  4416. /**
  4417. * \brief Returns the cursor kind for the container for the current code
  4418. * completion context. The container is only guaranteed to be set for
  4419. * contexts where a container exists (i.e. member accesses or Objective-C
  4420. * message sends); if there is not a container, this function will return
  4421. * CXCursor_InvalidCode.
  4422. *
  4423. * \param Results the code completion results to query
  4424. *
  4425. * \param IsIncomplete on return, this value will be false if Clang has complete
  4426. * information about the container. If Clang does not have complete
  4427. * information, this value will be true.
  4428. *
  4429. * \returns the container kind, or CXCursor_InvalidCode if there is not a
  4430. * container
  4431. */
  4432. CINDEX_LINKAGE
  4433. enum CXCursorKind clang_codeCompleteGetContainerKind(
  4434. CXCodeCompleteResults *Results,
  4435. unsigned *IsIncomplete);
  4436. /**
  4437. * \brief Returns the USR for the container for the current code completion
  4438. * context. If there is not a container for the current context, this
  4439. * function will return the empty string.
  4440. *
  4441. * \param Results the code completion results to query
  4442. *
  4443. * \returns the USR for the container
  4444. */
  4445. CINDEX_LINKAGE
  4446. CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
  4447. /**
  4448. * \brief Returns the currently-entered selector for an Objective-C message
  4449. * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
  4450. * non-empty string for CXCompletionContext_ObjCInstanceMessage and
  4451. * CXCompletionContext_ObjCClassMessage.
  4452. *
  4453. * \param Results the code completion results to query
  4454. *
  4455. * \returns the selector (or partial selector) that has been entered thus far
  4456. * for an Objective-C message send.
  4457. */
  4458. CINDEX_LINKAGE
  4459. CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
  4460. /**
  4461. * @}
  4462. */
  4463. /**
  4464. * \defgroup CINDEX_MISC Miscellaneous utility functions
  4465. *
  4466. * @{
  4467. */
  4468. /**
  4469. * \brief Return a version string, suitable for showing to a user, but not
  4470. * intended to be parsed (the format is not guaranteed to be stable).
  4471. */
  4472. CINDEX_LINKAGE CXString clang_getClangVersion(void);
  4473. /**
  4474. * \brief Enable/disable crash recovery.
  4475. *
  4476. * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
  4477. * value enables crash recovery, while 0 disables it.
  4478. */
  4479. CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
  4480. /**
  4481. * \brief Visitor invoked for each file in a translation unit
  4482. * (used with clang_getInclusions()).
  4483. *
  4484. * This visitor function will be invoked by clang_getInclusions() for each
  4485. * file included (either at the top-level or by \#include directives) within
  4486. * a translation unit. The first argument is the file being included, and
  4487. * the second and third arguments provide the inclusion stack. The
  4488. * array is sorted in order of immediate inclusion. For example,
  4489. * the first element refers to the location that included 'included_file'.
  4490. */
  4491. typedef void (*CXInclusionVisitor)(CXFile included_file,
  4492. CXSourceLocation* inclusion_stack,
  4493. unsigned include_len,
  4494. CXClientData client_data);
  4495. /**
  4496. * \brief Visit the set of preprocessor inclusions in a translation unit.
  4497. * The visitor function is called with the provided data for every included
  4498. * file. This does not include headers included by the PCH file (unless one
  4499. * is inspecting the inclusions in the PCH file itself).
  4500. */
  4501. CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
  4502. CXInclusionVisitor visitor,
  4503. CXClientData client_data);
  4504. /**
  4505. * @}
  4506. */
  4507. /** \defgroup CINDEX_REMAPPING Remapping functions
  4508. *
  4509. * @{
  4510. */
  4511. /**
  4512. * \brief A remapping of original source files and their translated files.
  4513. */
  4514. typedef void *CXRemapping;
  4515. /**
  4516. * \brief Retrieve a remapping.
  4517. *
  4518. * \param path the path that contains metadata about remappings.
  4519. *
  4520. * \returns the requested remapping. This remapping must be freed
  4521. * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
  4522. */
  4523. CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
  4524. /**
  4525. * \brief Retrieve a remapping.
  4526. *
  4527. * \param filePaths pointer to an array of file paths containing remapping info.
  4528. *
  4529. * \param numFiles number of file paths.
  4530. *
  4531. * \returns the requested remapping. This remapping must be freed
  4532. * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
  4533. */
  4534. CINDEX_LINKAGE
  4535. CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
  4536. unsigned numFiles);
  4537. /**
  4538. * \brief Determine the number of remappings.
  4539. */
  4540. CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
  4541. /**
  4542. * \brief Get the original and the associated filename from the remapping.
  4543. *
  4544. * \param original If non-NULL, will be set to the original filename.
  4545. *
  4546. * \param transformed If non-NULL, will be set to the filename that the original
  4547. * is associated with.
  4548. */
  4549. CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
  4550. CXString *original, CXString *transformed);
  4551. /**
  4552. * \brief Dispose the remapping.
  4553. */
  4554. CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
  4555. /**
  4556. * @}
  4557. */
  4558. /** \defgroup CINDEX_HIGH Higher level API functions
  4559. *
  4560. * @{
  4561. */
  4562. enum CXVisitorResult {
  4563. CXVisit_Break,
  4564. CXVisit_Continue
  4565. };
  4566. typedef struct {
  4567. void *context;
  4568. enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
  4569. } CXCursorAndRangeVisitor;
  4570. typedef enum {
  4571. /**
  4572. * \brief Function returned successfully.
  4573. */
  4574. CXResult_Success = 0,
  4575. /**
  4576. * \brief One of the parameters was invalid for the function.
  4577. */
  4578. CXResult_Invalid = 1,
  4579. /**
  4580. * \brief The function was terminated by a callback (e.g. it returned
  4581. * CXVisit_Break)
  4582. */
  4583. CXResult_VisitBreak = 2
  4584. } CXResult;
  4585. /**
  4586. * \brief Find references of a declaration in a specific file.
  4587. *
  4588. * \param cursor pointing to a declaration or a reference of one.
  4589. *
  4590. * \param file to search for references.
  4591. *
  4592. * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
  4593. * each reference found.
  4594. * The CXSourceRange will point inside the file; if the reference is inside
  4595. * a macro (and not a macro argument) the CXSourceRange will be invalid.
  4596. *
  4597. * \returns one of the CXResult enumerators.
  4598. */
  4599. CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
  4600. CXCursorAndRangeVisitor visitor);
  4601. /**
  4602. * \brief Find #import/#include directives in a specific file.
  4603. *
  4604. * \param TU translation unit containing the file to query.
  4605. *
  4606. * \param file to search for #import/#include directives.
  4607. *
  4608. * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
  4609. * each directive found.
  4610. *
  4611. * \returns one of the CXResult enumerators.
  4612. */
  4613. CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
  4614. CXFile file,
  4615. CXCursorAndRangeVisitor visitor);
  4616. #ifdef __has_feature
  4617. # if __has_feature(blocks)
  4618. typedef enum CXVisitorResult
  4619. (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
  4620. CINDEX_LINKAGE
  4621. CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
  4622. CXCursorAndRangeVisitorBlock);
  4623. CINDEX_LINKAGE
  4624. CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
  4625. CXCursorAndRangeVisitorBlock);
  4626. # endif
  4627. #endif
  4628. /**
  4629. * \brief The client's data object that is associated with a CXFile.
  4630. */
  4631. typedef void *CXIdxClientFile;
  4632. /**
  4633. * \brief The client's data object that is associated with a semantic entity.
  4634. */
  4635. typedef void *CXIdxClientEntity;
  4636. /**
  4637. * \brief The client's data object that is associated with a semantic container
  4638. * of entities.
  4639. */
  4640. typedef void *CXIdxClientContainer;
  4641. /**
  4642. * \brief The client's data object that is associated with an AST file (PCH
  4643. * or module).
  4644. */
  4645. typedef void *CXIdxClientASTFile;
  4646. /**
  4647. * \brief Source location passed to index callbacks.
  4648. */
  4649. typedef struct {
  4650. void *ptr_data[2];
  4651. unsigned int_data;
  4652. } CXIdxLoc;
  4653. /**
  4654. * \brief Data for ppIncludedFile callback.
  4655. */
  4656. typedef struct {
  4657. /**
  4658. * \brief Location of '#' in the \#include/\#import directive.
  4659. */
  4660. CXIdxLoc hashLoc;
  4661. /**
  4662. * \brief Filename as written in the \#include/\#import directive.
  4663. */
  4664. const char *filename;
  4665. /**
  4666. * \brief The actual file that the \#include/\#import directive resolved to.
  4667. */
  4668. CXFile file;
  4669. int isImport;
  4670. int isAngled;
  4671. /**
  4672. * \brief Non-zero if the directive was automatically turned into a module
  4673. * import.
  4674. */
  4675. int isModuleImport;
  4676. } CXIdxIncludedFileInfo;
  4677. /**
  4678. * \brief Data for IndexerCallbacks#importedASTFile.
  4679. */
  4680. typedef struct {
  4681. /**
  4682. * \brief Top level AST file containing the imported PCH, module or submodule.
  4683. */
  4684. CXFile file;
  4685. /**
  4686. * \brief The imported module or NULL if the AST file is a PCH.
  4687. */
  4688. CXModule module;
  4689. /**
  4690. * \brief Location where the file is imported. Applicable only for modules.
  4691. */
  4692. CXIdxLoc loc;
  4693. /**
  4694. * \brief Non-zero if an inclusion directive was automatically turned into
  4695. * a module import. Applicable only for modules.
  4696. */
  4697. int isImplicit;
  4698. } CXIdxImportedASTFileInfo;
  4699. typedef enum {
  4700. CXIdxEntity_Unexposed = 0,
  4701. CXIdxEntity_Typedef = 1,
  4702. CXIdxEntity_Function = 2,
  4703. CXIdxEntity_Variable = 3,
  4704. CXIdxEntity_Field = 4,
  4705. CXIdxEntity_EnumConstant = 5,
  4706. CXIdxEntity_ObjCClass = 6,
  4707. CXIdxEntity_ObjCProtocol = 7,
  4708. CXIdxEntity_ObjCCategory = 8,
  4709. CXIdxEntity_ObjCInstanceMethod = 9,
  4710. CXIdxEntity_ObjCClassMethod = 10,
  4711. CXIdxEntity_ObjCProperty = 11,
  4712. CXIdxEntity_ObjCIvar = 12,
  4713. CXIdxEntity_Enum = 13,
  4714. CXIdxEntity_Struct = 14,
  4715. CXIdxEntity_Union = 15,
  4716. CXIdxEntity_CXXClass = 16,
  4717. CXIdxEntity_CXXNamespace = 17,
  4718. CXIdxEntity_CXXNamespaceAlias = 18,
  4719. CXIdxEntity_CXXStaticVariable = 19,
  4720. CXIdxEntity_CXXStaticMethod = 20,
  4721. CXIdxEntity_CXXInstanceMethod = 21,
  4722. CXIdxEntity_CXXConstructor = 22,
  4723. CXIdxEntity_CXXDestructor = 23,
  4724. CXIdxEntity_CXXConversionFunction = 24,
  4725. CXIdxEntity_CXXTypeAlias = 25,
  4726. CXIdxEntity_CXXInterface = 26
  4727. } CXIdxEntityKind;
  4728. typedef enum {
  4729. CXIdxEntityLang_None = 0,
  4730. CXIdxEntityLang_C = 1,
  4731. CXIdxEntityLang_ObjC = 2,
  4732. CXIdxEntityLang_CXX = 3
  4733. } CXIdxEntityLanguage;
  4734. /**
  4735. * \brief Extra C++ template information for an entity. This can apply to:
  4736. * CXIdxEntity_Function
  4737. * CXIdxEntity_CXXClass
  4738. * CXIdxEntity_CXXStaticMethod
  4739. * CXIdxEntity_CXXInstanceMethod
  4740. * CXIdxEntity_CXXConstructor
  4741. * CXIdxEntity_CXXConversionFunction
  4742. * CXIdxEntity_CXXTypeAlias
  4743. */
  4744. typedef enum {
  4745. CXIdxEntity_NonTemplate = 0,
  4746. CXIdxEntity_Template = 1,
  4747. CXIdxEntity_TemplatePartialSpecialization = 2,
  4748. CXIdxEntity_TemplateSpecialization = 3
  4749. } CXIdxEntityCXXTemplateKind;
  4750. typedef enum {
  4751. CXIdxAttr_Unexposed = 0,
  4752. CXIdxAttr_IBAction = 1,
  4753. CXIdxAttr_IBOutlet = 2,
  4754. CXIdxAttr_IBOutletCollection = 3
  4755. } CXIdxAttrKind;
  4756. typedef struct {
  4757. CXIdxAttrKind kind;
  4758. CXCursor cursor;
  4759. CXIdxLoc loc;
  4760. } CXIdxAttrInfo;
  4761. typedef struct {
  4762. CXIdxEntityKind kind;
  4763. CXIdxEntityCXXTemplateKind templateKind;
  4764. CXIdxEntityLanguage lang;
  4765. const char *name;
  4766. const char *USR;
  4767. CXCursor cursor;
  4768. const CXIdxAttrInfo *const *attributes;
  4769. unsigned numAttributes;
  4770. } CXIdxEntityInfo;
  4771. typedef struct {
  4772. CXCursor cursor;
  4773. } CXIdxContainerInfo;
  4774. typedef struct {
  4775. const CXIdxAttrInfo *attrInfo;
  4776. const CXIdxEntityInfo *objcClass;
  4777. CXCursor classCursor;
  4778. CXIdxLoc classLoc;
  4779. } CXIdxIBOutletCollectionAttrInfo;
  4780. typedef enum {
  4781. CXIdxDeclFlag_Skipped = 0x1
  4782. } CXIdxDeclInfoFlags;
  4783. typedef struct {
  4784. const CXIdxEntityInfo *entityInfo;
  4785. CXCursor cursor;
  4786. CXIdxLoc loc;
  4787. const CXIdxContainerInfo *semanticContainer;
  4788. /**
  4789. * \brief Generally same as #semanticContainer but can be different in
  4790. * cases like out-of-line C++ member functions.
  4791. */
  4792. const CXIdxContainerInfo *lexicalContainer;
  4793. int isRedeclaration;
  4794. int isDefinition;
  4795. int isContainer;
  4796. const CXIdxContainerInfo *declAsContainer;
  4797. /**
  4798. * \brief Whether the declaration exists in code or was created implicitly
  4799. * by the compiler, e.g. implicit Objective-C methods for properties.
  4800. */
  4801. int isImplicit;
  4802. const CXIdxAttrInfo *const *attributes;
  4803. unsigned numAttributes;
  4804. unsigned flags;
  4805. } CXIdxDeclInfo;
  4806. typedef enum {
  4807. CXIdxObjCContainer_ForwardRef = 0,
  4808. CXIdxObjCContainer_Interface = 1,
  4809. CXIdxObjCContainer_Implementation = 2
  4810. } CXIdxObjCContainerKind;
  4811. typedef struct {
  4812. const CXIdxDeclInfo *declInfo;
  4813. CXIdxObjCContainerKind kind;
  4814. } CXIdxObjCContainerDeclInfo;
  4815. typedef struct {
  4816. const CXIdxEntityInfo *base;
  4817. CXCursor cursor;
  4818. CXIdxLoc loc;
  4819. } CXIdxBaseClassInfo;
  4820. typedef struct {
  4821. const CXIdxEntityInfo *protocol;
  4822. CXCursor cursor;
  4823. CXIdxLoc loc;
  4824. } CXIdxObjCProtocolRefInfo;
  4825. typedef struct {
  4826. const CXIdxObjCProtocolRefInfo *const *protocols;
  4827. unsigned numProtocols;
  4828. } CXIdxObjCProtocolRefListInfo;
  4829. typedef struct {
  4830. const CXIdxObjCContainerDeclInfo *containerInfo;
  4831. const CXIdxBaseClassInfo *superInfo;
  4832. const CXIdxObjCProtocolRefListInfo *protocols;
  4833. } CXIdxObjCInterfaceDeclInfo;
  4834. typedef struct {
  4835. const CXIdxObjCContainerDeclInfo *containerInfo;
  4836. const CXIdxEntityInfo *objcClass;
  4837. CXCursor classCursor;
  4838. CXIdxLoc classLoc;
  4839. const CXIdxObjCProtocolRefListInfo *protocols;
  4840. } CXIdxObjCCategoryDeclInfo;
  4841. typedef struct {
  4842. const CXIdxDeclInfo *declInfo;
  4843. const CXIdxEntityInfo *getter;
  4844. const CXIdxEntityInfo *setter;
  4845. } CXIdxObjCPropertyDeclInfo;
  4846. typedef struct {
  4847. const CXIdxDeclInfo *declInfo;
  4848. const CXIdxBaseClassInfo *const *bases;
  4849. unsigned numBases;
  4850. } CXIdxCXXClassDeclInfo;
  4851. /**
  4852. * \brief Data for IndexerCallbacks#indexEntityReference.
  4853. */
  4854. typedef enum {
  4855. /**
  4856. * \brief The entity is referenced directly in user's code.
  4857. */
  4858. CXIdxEntityRef_Direct = 1,
  4859. /**
  4860. * \brief An implicit reference, e.g. a reference of an Objective-C method
  4861. * via the dot syntax.
  4862. */
  4863. CXIdxEntityRef_Implicit = 2
  4864. } CXIdxEntityRefKind;
  4865. /**
  4866. * \brief Data for IndexerCallbacks#indexEntityReference.
  4867. */
  4868. typedef struct {
  4869. CXIdxEntityRefKind kind;
  4870. /**
  4871. * \brief Reference cursor.
  4872. */
  4873. CXCursor cursor;
  4874. CXIdxLoc loc;
  4875. /**
  4876. * \brief The entity that gets referenced.
  4877. */
  4878. const CXIdxEntityInfo *referencedEntity;
  4879. /**
  4880. * \brief Immediate "parent" of the reference. For example:
  4881. *
  4882. * \code
  4883. * Foo *var;
  4884. * \endcode
  4885. *
  4886. * The parent of reference of type 'Foo' is the variable 'var'.
  4887. * For references inside statement bodies of functions/methods,
  4888. * the parentEntity will be the function/method.
  4889. */
  4890. const CXIdxEntityInfo *parentEntity;
  4891. /**
  4892. * \brief Lexical container context of the reference.
  4893. */
  4894. const CXIdxContainerInfo *container;
  4895. } CXIdxEntityRefInfo;
  4896. /**
  4897. * \brief A group of callbacks used by #clang_indexSourceFile and
  4898. * #clang_indexTranslationUnit.
  4899. */
  4900. typedef struct {
  4901. /**
  4902. * \brief Called periodically to check whether indexing should be aborted.
  4903. * Should return 0 to continue, and non-zero to abort.
  4904. */
  4905. int (*abortQuery)(CXClientData client_data, void *reserved);
  4906. /**
  4907. * \brief Called at the end of indexing; passes the complete diagnostic set.
  4908. */
  4909. void (*diagnostic)(CXClientData client_data,
  4910. CXDiagnosticSet, void *reserved);
  4911. CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
  4912. CXFile mainFile, void *reserved);
  4913. /**
  4914. * \brief Called when a file gets \#included/\#imported.
  4915. */
  4916. CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
  4917. const CXIdxIncludedFileInfo *);
  4918. /**
  4919. * \brief Called when a AST file (PCH or module) gets imported.
  4920. *
  4921. * AST files will not get indexed (there will not be callbacks to index all
  4922. * the entities in an AST file). The recommended action is that, if the AST
  4923. * file is not already indexed, to initiate a new indexing job specific to
  4924. * the AST file.
  4925. */
  4926. CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
  4927. const CXIdxImportedASTFileInfo *);
  4928. /**
  4929. * \brief Called at the beginning of indexing a translation unit.
  4930. */
  4931. CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
  4932. void *reserved);
  4933. void (*indexDeclaration)(CXClientData client_data,
  4934. const CXIdxDeclInfo *);
  4935. /**
  4936. * \brief Called to index a reference of an entity.
  4937. */
  4938. void (*indexEntityReference)(CXClientData client_data,
  4939. const CXIdxEntityRefInfo *);
  4940. } IndexerCallbacks;
  4941. CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
  4942. CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
  4943. clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
  4944. CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
  4945. clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
  4946. CINDEX_LINKAGE
  4947. const CXIdxObjCCategoryDeclInfo *
  4948. clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
  4949. CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
  4950. clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
  4951. CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
  4952. clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
  4953. CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
  4954. clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
  4955. CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
  4956. clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
  4957. /**
  4958. * \brief For retrieving a custom CXIdxClientContainer attached to a
  4959. * container.
  4960. */
  4961. CINDEX_LINKAGE CXIdxClientContainer
  4962. clang_index_getClientContainer(const CXIdxContainerInfo *);
  4963. /**
  4964. * \brief For setting a custom CXIdxClientContainer attached to a
  4965. * container.
  4966. */
  4967. CINDEX_LINKAGE void
  4968. clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
  4969. /**
  4970. * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
  4971. */
  4972. CINDEX_LINKAGE CXIdxClientEntity
  4973. clang_index_getClientEntity(const CXIdxEntityInfo *);
  4974. /**
  4975. * \brief For setting a custom CXIdxClientEntity attached to an entity.
  4976. */
  4977. CINDEX_LINKAGE void
  4978. clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
  4979. /**
  4980. * \brief An indexing action/session, to be applied to one or multiple
  4981. * translation units.
  4982. */
  4983. typedef void *CXIndexAction;
  4984. /**
  4985. * \brief An indexing action/session, to be applied to one or multiple
  4986. * translation units.
  4987. *
  4988. * \param CIdx The index object with which the index action will be associated.
  4989. */
  4990. CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
  4991. /**
  4992. * \brief Destroy the given index action.
  4993. *
  4994. * The index action must not be destroyed until all of the translation units
  4995. * created within that index action have been destroyed.
  4996. */
  4997. CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
  4998. typedef enum {
  4999. /**
  5000. * \brief Used to indicate that no special indexing options are needed.
  5001. */
  5002. CXIndexOpt_None = 0x0,
  5003. /**
  5004. * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
  5005. * be invoked for only one reference of an entity per source file that does
  5006. * not also include a declaration/definition of the entity.
  5007. */
  5008. CXIndexOpt_SuppressRedundantRefs = 0x1,
  5009. /**
  5010. * \brief Function-local symbols should be indexed. If this is not set
  5011. * function-local symbols will be ignored.
  5012. */
  5013. CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
  5014. /**
  5015. * \brief Implicit function/class template instantiations should be indexed.
  5016. * If this is not set, implicit instantiations will be ignored.
  5017. */
  5018. CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
  5019. /**
  5020. * \brief Suppress all compiler warnings when parsing for indexing.
  5021. */
  5022. CXIndexOpt_SuppressWarnings = 0x8,
  5023. /**
  5024. * \brief Skip a function/method body that was already parsed during an
  5025. * indexing session associated with a \c CXIndexAction object.
  5026. * Bodies in system headers are always skipped.
  5027. */
  5028. CXIndexOpt_SkipParsedBodiesInSession = 0x10
  5029. } CXIndexOptFlags;
  5030. /**
  5031. * \brief Index the given source file and the translation unit corresponding
  5032. * to that file via callbacks implemented through #IndexerCallbacks.
  5033. *
  5034. * \param client_data pointer data supplied by the client, which will
  5035. * be passed to the invoked callbacks.
  5036. *
  5037. * \param index_callbacks Pointer to indexing callbacks that the client
  5038. * implements.
  5039. *
  5040. * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
  5041. * passed in index_callbacks.
  5042. *
  5043. * \param index_options A bitmask of options that affects how indexing is
  5044. * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
  5045. *
  5046. * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be
  5047. * reused after indexing is finished. Set to \c NULL if you do not require it.
  5048. *
  5049. * \returns 0 on success or if there were errors from which the compiler could
  5050. * recover. If there is a failure from which there is no recovery, returns
  5051. * a non-zero \c CXErrorCode.
  5052. *
  5053. * The rest of the parameters are the same as #clang_parseTranslationUnit.
  5054. */
  5055. CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
  5056. CXClientData client_data,
  5057. IndexerCallbacks *index_callbacks,
  5058. unsigned index_callbacks_size,
  5059. unsigned index_options,
  5060. const char *source_filename,
  5061. const char * const *command_line_args,
  5062. int num_command_line_args,
  5063. struct CXUnsavedFile *unsaved_files,
  5064. unsigned num_unsaved_files,
  5065. CXTranslationUnit *out_TU,
  5066. unsigned TU_options);
  5067. /**
  5068. * \brief Index the given translation unit via callbacks implemented through
  5069. * #IndexerCallbacks.
  5070. *
  5071. * The order of callback invocations is not guaranteed to be the same as
  5072. * when indexing a source file. The high level order will be:
  5073. *
  5074. * -Preprocessor callbacks invocations
  5075. * -Declaration/reference callbacks invocations
  5076. * -Diagnostic callback invocations
  5077. *
  5078. * The parameters are the same as #clang_indexSourceFile.
  5079. *
  5080. * \returns If there is a failure from which there is no recovery, returns
  5081. * non-zero, otherwise returns 0.
  5082. */
  5083. CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
  5084. CXClientData client_data,
  5085. IndexerCallbacks *index_callbacks,
  5086. unsigned index_callbacks_size,
  5087. unsigned index_options,
  5088. CXTranslationUnit);
  5089. /**
  5090. * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
  5091. * the given CXIdxLoc.
  5092. *
  5093. * If the location refers into a macro expansion, retrieves the
  5094. * location of the macro expansion and if it refers into a macro argument
  5095. * retrieves the location of the argument.
  5096. */
  5097. CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
  5098. CXIdxClientFile *indexFile,
  5099. CXFile *file,
  5100. unsigned *line,
  5101. unsigned *column,
  5102. unsigned *offset);
  5103. /**
  5104. * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
  5105. */
  5106. CINDEX_LINKAGE
  5107. CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
  5108. /**
  5109. * \brief Visitor invoked for each field found by a traversal.
  5110. *
  5111. * This visitor function will be invoked for each field found by
  5112. * \c clang_Type_visitFields. Its first argument is the cursor being
  5113. * visited, its second argument is the client data provided to
  5114. * \c clang_Type_visitFields.
  5115. *
  5116. * The visitor should return one of the \c CXVisitorResult values
  5117. * to direct \c clang_Type_visitFields.
  5118. */
  5119. typedef enum CXVisitorResult (*CXFieldVisitor)(CXCursor C,
  5120. CXClientData client_data);
  5121. /**
  5122. * \brief Visit the fields of a particular type.
  5123. *
  5124. * This function visits all the direct fields of the given cursor,
  5125. * invoking the given \p visitor function with the cursors of each
  5126. * visited field. The traversal may be ended prematurely, if
  5127. * the visitor returns \c CXFieldVisit_Break.
  5128. *
  5129. * \param T the record type whose field may be visited.
  5130. *
  5131. * \param visitor the visitor function that will be invoked for each
  5132. * field of \p T.
  5133. *
  5134. * \param client_data pointer data supplied by the client, which will
  5135. * be passed to the visitor each time it is invoked.
  5136. *
  5137. * \returns a non-zero value if the traversal was terminated
  5138. * prematurely by the visitor returning \c CXFieldVisit_Break.
  5139. */
  5140. CINDEX_LINKAGE unsigned clang_Type_visitFields(CXType T,
  5141. CXFieldVisitor visitor,
  5142. CXClientData client_data);
  5143. /**
  5144. * @}
  5145. */
  5146. /**
  5147. * @}
  5148. */
  5149. #ifdef __cplusplus
  5150. }
  5151. #endif
  5152. #endif