[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang-tools-extra / clangd / support / Context.cpp
blob266dd003f8f6e110eb8606d7bf91dc2bb5b5cd02
1 //===--- Context.cpp ---------------------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "support/Context.h"
10 #include <cassert>
12 namespace clang {
13 namespace clangd {
15 Context Context::empty() { return Context(/*DataPtr=*/nullptr); }
17 Context::Context(std::shared_ptr<const Data> DataPtr)
18 : DataPtr(std::move(DataPtr)) {}
20 Context Context::clone() const { return Context(DataPtr); }
22 static Context &currentContext() {
23 static thread_local auto C = Context::empty();
24 return C;
27 const Context &Context::current() { return currentContext(); }
29 Context Context::swapCurrent(Context Replacement) {
30 std::swap(Replacement, currentContext());
31 return Replacement;
34 } // namespace clangd
35 } // namespace clang