2010-11-16 10:03:55 +08:00
|
|
|
//===- CXString.h - Routines for manipulating CXStrings -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines routines for manipulating CXStrings.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXSTRING_H
|
|
|
|
#define LLVM_CLANG_TOOLS_LIBCLANG_CXSTRING_H
|
2010-11-16 10:03:55 +08:00
|
|
|
|
|
|
|
#include "clang-c/Index.h"
|
2011-07-20 14:58:45 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2010-11-16 16:15:36 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2013-02-02 10:19:29 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include <string>
|
2014-01-07 19:51:46 +08:00
|
|
|
#include <vector>
|
2010-11-16 10:03:55 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace cxstring {
|
2013-01-27 06:44:19 +08:00
|
|
|
|
|
|
|
struct CXStringBuf;
|
2010-11-16 10:03:55 +08:00
|
|
|
|
2013-02-01 22:21:22 +08:00
|
|
|
/// \brief Create a CXString object for an empty "" string.
|
|
|
|
CXString createEmpty();
|
|
|
|
|
2013-02-01 22:13:32 +08:00
|
|
|
/// \brief Create a CXString object for an NULL string.
|
2013-02-02 00:38:41 +08:00
|
|
|
///
|
|
|
|
/// A NULL string should be used as an "invalid" value in case of errors.
|
2013-02-01 22:13:32 +08:00
|
|
|
CXString createNull();
|
|
|
|
|
2013-02-02 08:02:12 +08:00
|
|
|
/// \brief Create a CXString object from a nul-terminated C string. New
|
|
|
|
/// CXString may contain a pointer to \p String.
|
|
|
|
///
|
|
|
|
/// \p String should not be changed by the caller afterwards.
|
|
|
|
CXString createRef(const char *String);
|
|
|
|
|
|
|
|
/// \brief Create a CXString object from a nul-terminated C string. New
|
|
|
|
/// CXString will contain a copy of \p String.
|
|
|
|
///
|
|
|
|
/// \p String can be changed or freed by the caller.
|
|
|
|
CXString createDup(const char *String);
|
2010-11-16 10:03:55 +08:00
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
/// \brief Create a CXString object from a StringRef. New CXString may
|
|
|
|
/// contain a pointer to the undrelying data of \p String.
|
|
|
|
///
|
|
|
|
/// \p String should not be changed by the caller afterwards.
|
|
|
|
CXString createRef(StringRef String);
|
|
|
|
|
|
|
|
/// \brief Create a CXString object from a StringRef. New CXString will
|
|
|
|
/// contain a copy of \p String.
|
|
|
|
///
|
|
|
|
/// \p String can be changed or freed by the caller.
|
|
|
|
CXString createDup(StringRef String);
|
|
|
|
|
|
|
|
// Usually std::string is intended to be used as backing storage for CXString.
|
|
|
|
// In this case, call \c createRef(String.c_str()).
|
|
|
|
//
|
|
|
|
// If you need to make a copy, call \c createDup(StringRef(String)).
|
|
|
|
CXString createRef(std::string String) LLVM_DELETED_FUNCTION;
|
2010-11-16 16:15:36 +08:00
|
|
|
|
|
|
|
/// \brief Create a CXString object that is backed by a string buffer.
|
|
|
|
CXString createCXString(CXStringBuf *buf);
|
|
|
|
|
2013-01-27 06:44:19 +08:00
|
|
|
/// \brief A string pool used for fast allocation/deallocation of strings.
|
|
|
|
class CXStringPool {
|
|
|
|
public:
|
|
|
|
~CXStringPool();
|
|
|
|
|
|
|
|
CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<CXStringBuf *> Pool;
|
|
|
|
|
|
|
|
friend struct CXStringBuf;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CXStringBuf {
|
|
|
|
SmallString<128> Data;
|
|
|
|
CXTranslationUnit TU;
|
|
|
|
|
|
|
|
CXStringBuf(CXTranslationUnit TU) : TU(TU) {}
|
|
|
|
|
|
|
|
/// \brief Return this buffer to the pool.
|
|
|
|
void dispose();
|
|
|
|
};
|
2010-11-16 16:15:36 +08:00
|
|
|
|
|
|
|
CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
|
2010-11-16 10:03:55 +08:00
|
|
|
|
2011-08-18 06:19:53 +08:00
|
|
|
/// \brief Returns true if the CXString data is managed by a pool.
|
|
|
|
bool isManagedByPool(CXString str);
|
|
|
|
|
2010-11-16 10:03:55 +08:00
|
|
|
}
|
2014-07-07 09:23:14 +08:00
|
|
|
|
|
|
|
static inline StringRef getContents(const CXUnsavedFile &UF) {
|
|
|
|
return StringRef(UF.Contents, UF.Length);
|
|
|
|
}
|
2010-11-16 10:03:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|