mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 15:15:50 +01:00
This removes a lot of boilerplate `Print` functions in favor of a CRTP-based approach that uses a `Label` field as an automatic prefix. This `Label` is also made available for other purposes, particularly `IdKind` crash messages in this change. In particular, for `RequireIdKind` in node_stack.h from using numeric IdKinds (e.g., 5 and 24) to something that will print `IdKind(<label>)` (this came up recently on #toolchain). While I'm in here, also doing some other tinkering: - Moving operators to be `friend` members, to reduce the extra templating now that the base types are templated. - Adjusts IntId diagnostics from `int [...]` to `int(...)` for consistency with other id printing. - Changes InstBlockId's label from "block" to "inst_block", since we have multiple blocks now. - Fixes StructTypeFieldsId to use "struct_type_fields" instead of "type_block" (from `TypeBlockId`) - Does some more adjustments from camelCase to snake_case for consistency
32 lines
1.1 KiB
C++
32 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_TOOLCHAIN_CHECK_SCOPE_INDEX_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_SCOPE_INDEX_H_
|
|
|
|
#include "toolchain/base/index_base.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// An index for a pushed scope. This may correspond to a permanent scope with a
|
|
// corresponding `NameScope`, in which case a different index will be assigned
|
|
// each time the scope is entered. Alternatively, it may be a temporary scope
|
|
// such as is created for a block, and will only be entered once.
|
|
//
|
|
// `ScopeIndex` values are comparable. Lower `ScopeIndex` values correspond to
|
|
// scopes entered earlier in the file.
|
|
struct ScopeIndex : public IndexBase<ScopeIndex> {
|
|
static constexpr llvm::StringLiteral Label = "scope";
|
|
static const ScopeIndex Package;
|
|
|
|
using IndexBase::IndexBase;
|
|
};
|
|
|
|
constexpr ScopeIndex ScopeIndex::Package = ScopeIndex(0);
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_SCOPE_INDEX_H_
|