//===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===////// The LLVM Compiler Infrastructure//// This file is distributed under the University of Illinois Open Source// License. See LICENSE.TXT for details.////===----------------------------------------------------------------------===////// This file implements the main API hooks in the Clang-C Source Indexing// library.////===----------------------------------------------------------------------===//#include"CIndexer.h"#include"CXCursor.h"#include"clang/AST/DeclVisitor.h"#include"clang/AST/StmtVisitor.h"#include"clang/Lex/Lexer.h"#include"llvm/Support/MemoryBuffer.h"#include"llvm/System/Program.h"// Needed to define L_TMPNAM on some systems.#include<cstdio>usingnamespaceclang;usingnamespaceclang::cxcursor;usingnamespaceidx;//===----------------------------------------------------------------------===//// Crash Reporting.//===----------------------------------------------------------------------===//#ifdef __APPLE__#ifndef NDEBUG#define USE_CRASHTRACER#include"clang/Analysis/Support/SaveAndRestore.h"// Integrate with crash reporter.extern"C"constchar*__crashreporter_info__;#define NUM_CRASH_STRINGS 16staticunsignedcrashtracer_counter=0;staticunsignedcrashtracer_counter_id[NUM_CRASH_STRINGS]={0};staticconstchar*crashtracer_strings[NUM_CRASH_STRINGS]={0};staticconstchar*agg_crashtracer_strings[NUM_CRASH_STRINGS]={0};staticunsignedSetCrashTracerInfo(constchar*str,llvm::SmallString<1024>&AggStr){unsignedslot=0;while(crashtracer_strings[slot]){if(++slot==NUM_CRASH_STRINGS)slot=0;}crashtracer_strings[slot]=str;crashtracer_counter_id[slot]=++crashtracer_counter;// We need to create an aggregate string because multiple threads// may be in this method at one time. The crash reporter string// will attempt to overapproximate the set of in-flight invocations// of this function. Race conditions can still cause this goal// to not be achieved.{llvm::raw_svector_ostreamOut(AggStr);for(unsignedi=0;i<NUM_CRASH_STRINGS;++i)if(crashtracer_strings[i])Out<<crashtracer_strings[i]<<'\n';}__crashreporter_info__=agg_crashtracer_strings[slot]=AggStr.c_str();returnslot;}staticvoidResetCrashTracerInfo(unsignedslot){unsignedmax_slot=0;unsignedmax_value=0;crashtracer_strings[slot]