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