blob: 3b86826972405d3b89126d61e8a6575cf8b5a40a [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
Dmitri Gribenko0c4394c2013-02-02 00:02:12 +000036/// \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);
Ted Kremenekea834df2010-11-16 02:03:55 +000047
Ted Kremeneka60ed472010-11-16 08:15:36 +000048/// \brief Create a CXString object from a StringRef.
Chris Lattner686775d2011-07-20 06:58:45 +000049CXString createCXString(StringRef String, bool DupString = true);
Ted Kremeneka60ed472010-11-16 08:15:36 +000050
51/// \brief Create a CXString object that is backed by a string buffer.
52CXString createCXString(CXStringBuf *buf);
53
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000054/// \brief A string pool used for fast allocation/deallocation of strings.
55class CXStringPool {
56public:
57 ~CXStringPool();
Ted Kremeneka60ed472010-11-16 08:15:36 +000058
Dmitri Gribenko9c48d162013-01-26 22:44:19 +000059 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
Ted Kremeneka60ed472010-11-16 08:15:36 +000077CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
Ted Kremenekea834df2010-11-16 02:03:55 +000078
Ted Kremenekbaf82b02011-08-17 22:19:53 +000079/// \brief Returns true if the CXString data is managed by a pool.
80bool isManagedByPool(CXString str);
81
Ted Kremenekea834df2010-11-16 02:03:55 +000082}
83}
84
85#endif
86