CXString.h revision 0c4394c7f63008fbf4d335710b34f71afab362a3
1//===- CXString.h - Routines for manipulating CXStrings -------------------===//
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 file defines routines for manipulating CXStrings.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_CXSTRING_H
15#define LLVM_CLANG_CXSTRING_H
16
17#include "clang-c/Index.h"
18#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/SmallString.h"
20#include "llvm/ADT/StringRef.h"
21#include <vector>
22
23namespace clang {
24namespace cxstring {
25
26struct CXStringBuf;
27
28/// \brief Create a CXString object for an empty "" string.
29CXString createEmpty();
30
31/// \brief Create a CXString object for an NULL string.
32///
33/// A NULL string should be used as an "invalid" value in case of errors.
34CXString createNull();
35
36/// \brief Create a CXString object from a nul-terminated C string.  New
37/// CXString may contain a pointer to \p String.
38///
39/// \p String should not be changed by the caller afterwards.
40CXString createRef(const char *String);
41
42/// \brief Create a CXString object from a nul-terminated C string.  New
43/// CXString will contain a copy of \p String.
44///
45/// \p String can be changed or freed by the caller.
46CXString createDup(const char *String);
47
48/// \brief Create a CXString object from a StringRef.
49CXString createCXString(StringRef String, bool DupString = true);
50
51/// \brief Create a CXString object that is backed by a string buffer.
52CXString createCXString(CXStringBuf *buf);
53
54/// \brief A string pool used for fast allocation/deallocation of strings.
55class CXStringPool {
56public:
57  ~CXStringPool();
58
59  CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
60
61private:
62  std::vector<CXStringBuf *> Pool;
63
64  friend struct CXStringBuf;
65};
66
67struct CXStringBuf {
68  SmallString<128> Data;
69  CXTranslationUnit TU;
70
71  CXStringBuf(CXTranslationUnit TU) : TU(TU) {}
72
73  /// \brief Return this buffer to the pool.
74  void dispose();
75};
76
77CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
78
79/// \brief Returns true if the CXString data is managed by a pool.
80bool isManagedByPool(CXString str);
81
82}
83}
84
85#endif
86
87