1/****************************************************************************
2 * Copyright (C) 2013-2016 Woboq GmbH
3 * Olivier Goffart <contact at woboq.com>
4 * https://woboq.com/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <clang/Basic/SourceLocation.h>
23#include <clang/Basic/Version.h>
24#include <memory>
25
26namespace clang {
27 class Preprocessor;
28}
29namespace llvm {
30 class MemoryBuffer;
31}
32
33// Abstract the API changes in clang
34
35clang::FileID CreateFileIDForMemBuffer(clang::Preprocessor &PP, llvm::MemoryBuffer *Buf, clang::SourceLocation Loc);
36
37// clang 3.6 uses unique_ptr in many places that was not using it before
38template<typename T> struct MaybeUnique {
39 T *val;
40 operator T*() { return val; }
41 template <typename X> operator std::unique_ptr<X> () && { return std::unique_ptr<X>(val); }
42};
43template<typename T> MaybeUnique<T> maybe_unique(T* val) { return {val}; }
44template<typename T> MaybeUnique<T> maybe_unique(std::unique_ptr<T> val) { return {val.release()}; }
45
46#ifndef LLVM_FALLTHROUGH
47#define LLVM_FALLTHROUGH
48#endif
49