//===--- ConfigCompile.cpp - Translating Fragments into Config ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Fragments are applied to Configs in two steps: // // 1. (When the fragment is first loaded) // FragmentCompiler::compile() traverses the Fragment and creates // function objects that know how to apply the configuration. // 2. (Every time a config is required) // CompiledFragment() executes these functions to populate the Config. // // Work could be split between these steps in different ways. We try to // do as much work as possible in the first step. For example, regexes are // compiled in stage 1 and captured by the apply function. This is because: // // - it's more efficient, as the work done in stage 1 must only be done once // - problems can be reported in stage 1, in stage 2 we must silently recover // //===----------------------------------------------------------------------===// #include "CompileCommands.h" #include "Config.h" #include "ConfigFragment.h" #include "ConfigProvider.h" #include "Diagnostics.h" #include "Feature.h" #include "TidyProvider.h" #include "support/Logger.h" #include "support/Path.h" #include "support/Trace.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Path.h" #include "llvm/Support/Regex.h" #include "llvm/Support/SMLoc.h" #include "llvm/Support/SourceMgr.h" #include <algorithm> #include <memory> #include <optional> #include <string> #include <vector> namespace clang { namespace clangd { namespace config { namespace { // Returns an empty stringref if Path is not under FragmentDir. Returns Path // as-is when FragmentDir is empty. llvm::StringRef configRelative(llvm::StringRef Path, llvm::StringRef FragmentDir) { … } struct CompiledFragmentImpl { … }; // Wrapper around condition compile() functions to reduce arg-passing. struct FragmentCompiler { … }; } // namespace CompiledFragment Fragment::compile(DiagnosticCallback D) && { … } } // namespace config } // namespace clangd } // namespace clang