brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1004 B · 266dd00 Raw
36 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "support/Context.h"10#include <cassert>11 12namespace clang {13namespace clangd {14 15Context Context::empty() { return Context(/*DataPtr=*/nullptr); }16 17Context::Context(std::shared_ptr<const Data> DataPtr)18    : DataPtr(std::move(DataPtr)) {}19 20Context Context::clone() const { return Context(DataPtr); }21 22static Context &currentContext() {23  static thread_local auto C = Context::empty();24  return C;25}26 27const Context &Context::current() { return currentContext(); }28 29Context Context::swapCurrent(Context Replacement) {30  std::swap(Replacement, currentContext());31  return Replacement;32}33 34} // namespace clangd35} // namespace clang36