mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
In parse, form a list of methods that are defined inline, tracking where they start, where they end, and which other inline methods are nested within them. In check, when we reach an inline method body, skip it and add it to a worklist to be processed later. We also track when we reach the start and end of a context in which inline method bodies are deferred, so that we know when to replay the bodies. When suspending a function definition to be processed later, the `DeclNameStack` entry is moved to separate storage, including popping the corresponding scopes from the scope stack and removing the corresponding lexical names from lexical lookup. Later, when we return to the function and parse its definition, the `DeclNameStack` entry is restored. The same is done when we reach the end of a nested context that can have inline methods, so that we can reenter the nested scope before processing its members. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_COMMON_VARIANT_HELPERS_H_
|
|
#define CARBON_COMMON_VARIANT_HELPERS_H_
|
|
|
|
#include <variant>
|
|
|
|
#include "common/error.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
namespace Carbon {
|
|
|
|
namespace Internal {
|
|
|
|
// Form an overload set from a list of functions. For example:
|
|
//
|
|
// ```
|
|
// auto overloaded = Overload{[] (int) {}, [] (float) {}};
|
|
// ```
|
|
template <typename... Fs>
|
|
struct Overload : Fs... {
|
|
using Fs::operator()...;
|
|
};
|
|
template <typename... Fs>
|
|
Overload(Fs...) -> Overload<Fs...>;
|
|
|
|
} // namespace Internal
|
|
|
|
// Pattern-match against the type of the value stored in the variant `V`. Each
|
|
// element of `fs` should be a function that takes one or more of the variant
|
|
// values in `V`.
|
|
template <typename V, typename... Fs>
|
|
auto VariantMatch(V&& v, Fs&&... fs) -> decltype(auto) {
|
|
return std::visit(Internal::Overload{std::forward<Fs&&>(fs)...},
|
|
std::forward<V&&>(v));
|
|
}
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_COMMON_VARIANT_HELPERS_H_
|