clang-tools 10.0.0

Context.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8
9 #include "Context.h"
10 #include <cassert>
11
12 namespace clang {
13 namespace clangd {
14
15 Context Context::empty() { return Context(/*DataPtr=*/nullptr); }
16
17 Context::Context(std::shared_ptr<const Data> DataPtr)
18 : DataPtr(std::move(DataPtr)) {}
19
20 Context Context::clone() const { return Context(DataPtr); }
21
22 static Context &currentContext() {
23 static thread_local auto C = Context::empty();
24 return C;
25 }
26
27 const Context &Context::current() { return currentContext(); }
28
29 Context Context::swapCurrent(Context Replacement) {
30 std::swap(Replacement, currentContext());
31 return Replacement;
32 }
33
34 } // namespace clangd
35 } // namespace clang
Context.h
clang::clangd::currentContext
static Context & currentContext()
Definition: Context.cpp:22
clang::clangd::Context::swapCurrent
static Context swapCurrent(Context Replacement)
Definition: Context.cpp:29
clang::clangd::Context::clone
Context clone() const
Clone this context object.
Definition: Context.cpp:20
clang::clangd::Context::current
static const Context & current()
Returns the context for the current thread, creating it if needed.
Definition: Context.cpp:27
clang::clangd::Context
A context is an immutable container for per-request data that must be propagated through layers that ...
Definition: Context.h:69
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::Context::empty
static Context empty()
Returns an empty root context that contains no data.
Definition: Context.cpp:15
clang::clangd::Context::Context
Context()=default
Same as Context::empty(), please use Context::empty() instead.