blob: 06887124fa5c7000fd296c6ce681037e032661e1 [file] [log] [blame]
Ted Kremenekea834df2010-11-16 02:03:55 +00001//===- 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"
Chris Lattner686775d2011-07-20 06:58:45 +000018#include "clang/Basic/LLVM.h"
Ted Kremeneka60ed472010-11-16 08:15:36 +000019#include "llvm/ADT/SmallString.h"
Chandler Carruthf59edb92012-12-04 09:25:21 +000020#include "llvm/ADT/StringRef.h"
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000021#include <vector>
Ted Kremenekea834df2010-11-16 02:03:55 +000022
23namespace clang {
24namespace cxstring {
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000025
26struct CXStringBuf;
Ted Kremenekea834df2010-11-16 02:03:55 +000027
Dmitri Gribenkodc66adb2013-02-01 14:21:22 +000028/// \brief Create a CXString object for an empty "" string.
29CXString createEmpty();
30
Dmitri Gribenkodad4c1a2013-02-01 14:13:32 +000031/// \brief Create a CXString object for an NULL string.
Dmitri Gribenko15a2aa02013-02-01 16:38:41 +000032///
33/// A NULL string should be used as an "invalid" value in case of errors.
Dmitri Gribenkodad4c1a2013-02-01 14:13:32 +000034CXString createNull();
35
Ted Kremenekea834df2010-11-16 02:03:55 +000036/// \brief Create a CXString object from a C string.
37CXString createCXString(const char *String, bool DupString = false);
38
Ted Kremeneka60ed472010-11-16 08:15:36 +000039/// \brief Create a CXString object from a StringRef.
Chris Lattner686775d2011-07-20 06:58:45 +000040CXString createCXString(StringRef String, bool DupString = true);
Ted Kremeneka60ed472010-11-16 08:15:36 +000041
42/// \brief Create a CXString object that is backed by a string buffer.
43CXString createCXString(CXStringBuf *buf);
44
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000045/// \brief A string pool used for fast allocation/deallocation of strings.
46class CXStringPool {
47public:
48 ~CXStringPool();
Ted Kremeneka60ed472010-11-16 08:15:36 +000049
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000050 CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
51
52private:
53 std::vector<CXStringBuf *> Pool;
54
55 friend struct CXStringBuf;
56};
57
58struct CXStringBuf {
59 SmallString<128> Data;
60 CXTranslationUnit TU;
61
62 CXStringBuf(CXTranslationUnit TU) : TU(TU) {}
63
64 /// \brief Return this buffer to the pool.
65 void dispose();
66};
67
Ted Kremeneka60ed472010-11-16 08:15:36 +000068CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
Ted Kremenekea834df2010-11-16 02:03:55 +000069
Ted Kremenekbaf82b02011-08-17 22:19:53 +000070/// \brief Returns true if the CXString data is managed by a pool.
71bool isManagedByPool(CXString str);
72
Ted Kremenekea834df2010-11-16 02:03:55 +000073}
74}
75
76#endif
77