mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-24 19:55:11 +00:00
The purpose of this change is to allow something such as a FunctionDecl instruction to note an imported instruction as the "loc_id". Note that doesn't occur here: this change is already very sweeping in edits. There is no testdata affected, intended to show equivalent behavior. We might want to consolidate NodeId references towards LocationId, but if that's preferred, I'd still like to split it out. A lot of this just piping through LocationId where it's a build error otherwise, enough that imports should be able to start using it for diagnostics. ValueStores are added but still unused -- just flushing out structure for review. Restructuring SemIRLocation is necessary to use LocationId this way. For TokenOnly, it's not getting used in Parse, so I migrated it to Check and it's now specific to SemIRLocation. I also considered making LocationId reference an InstId (which would need to be an ImportRef) instead of an ImportIRInstId. However, that would've required import.cpp to add instructions for decls which are reached during resolution -- we typically don't have an inst ready for use. An extra inst is essentially 16 bytes in InstId's ValueStore + 4 bytes in LocationId's ValueStore, whereas this is 8 bytes per.
63 lines
2.7 KiB
C++
63 lines
2.7 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_MODIFIERS_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_MODIFIERS_H_
|
|
|
|
#include "toolchain/check/context.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// Reports a diagnostic if access control modifiers on this are not allowed for
|
|
// a declaration in `target_scope_id`, and updates the declaration state in
|
|
// `context`.
|
|
//
|
|
// `target_scope_id` may be Invalid for a declaration in a block scope.
|
|
auto CheckAccessModifiersOnDecl(Context& context, Lex::TokenKind decl_kind,
|
|
SemIR::NameScopeId target_scope_id) -> void;
|
|
|
|
// Reports a diagnostic if the method function modifiers `abstract`, `virtual`,
|
|
// or `impl` are present but not permitted on a function declaration in
|
|
// `target_scope_id`.
|
|
//
|
|
// `target_scope_id` may be Invalid for a declaration in a block scope.
|
|
auto CheckMethodModifiersOnFunction(Context& context,
|
|
SemIR::NameScopeId target_scope_id) -> void;
|
|
|
|
// Like `LimitModifiersOnDecl`, except says which modifiers are forbidden, and a
|
|
// `context_string` (and optional `context_loc_id`) specifying the context in
|
|
// which those modifiers are forbidden.
|
|
// TODO: Take another look at diagnostic phrasing for callers.
|
|
auto ForbidModifiersOnDecl(
|
|
Context& context, KeywordModifierSet forbidden, Lex::TokenKind decl_kind,
|
|
llvm::StringRef context_string,
|
|
SemIR::LocationId context_loc_id = SemIR::LocationId::Invalid) -> void;
|
|
|
|
// Reports a diagnostic (using `decl_kind`) if modifiers on this declaration are
|
|
// not in `allowed`. Updates the declaration state in
|
|
// `context.decl_state_stack()`.
|
|
inline auto LimitModifiersOnDecl(Context& context, KeywordModifierSet allowed,
|
|
Lex::TokenKind decl_kind) -> void {
|
|
ForbidModifiersOnDecl(context, ~allowed, decl_kind, "");
|
|
}
|
|
|
|
// If the `extern` modifier is present, diagnoses and updates the declaration
|
|
// state to remove it. Only called for declarations with definitions.
|
|
auto ForbidExternModifierOnDefinition(Context& context,
|
|
Lex::TokenKind decl_kind) -> void;
|
|
|
|
// Report a diagonostic if `default` and `final` modifiers are used on
|
|
// declarations where they are not allowed. Right now they are only allowed
|
|
// inside interfaces.
|
|
//
|
|
// `target_scope_id` may be Invalid for a declaration in a block scope.
|
|
auto RequireDefaultFinalOnlyInInterfaces(Context& context,
|
|
Lex::TokenKind decl_kind,
|
|
SemIR::NameScopeId target_scope_id)
|
|
-> void;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_MODIFIERS_H_
|