mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:40:12 +01:00
Most of these are places where we failed to include a header file and simply never got an error about this. The fix is to include the header file. Most other cases are functions that should have been marked `static` but were not. Finding all of these was a main motivation for me enabling the warning despite how much work it is. One complicating factor was that we weren't including the `handle.h` for all the state-based handler functions. While this isn't a tiny amount of code, it is just declarations and doesn't add any extra dependencies. It also lets us have the checking for which functions need to be `static` and which don't. For the `parse` library I had to add the `handle.h` header as well, I tried to match the design of it in `check`. I have also had to work around a bug in the warning, but given the value it seems to be providing, that seems reasonable. I've filed the bug upstream: https://github.com/llvm/llvm-project/issues/94138 I also had to use some hacks to work around limitations of Bazel rules that wrap `cc_library` rules and don't expose `copts`. I filed a bug for `cc_proto_library` specifically: ~https://github.com/bazelbuild/bazel/issues/22610~ https://github.com/bazelbuild/bazel/issues/4446
80 lines
3.0 KiB
C++
80 lines
3.0 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
|
|
|
|
#include "toolchain/parse/context.h"
|
|
#include "toolchain/parse/handle.h"
|
|
|
|
namespace Carbon::Parse {
|
|
|
|
// Handles processing after params, deciding whether it's a declaration or
|
|
// definition.
|
|
static auto HandleDeclOrDefinition(Context& context, NodeKind decl_kind,
|
|
NodeKind definition_start_kind,
|
|
State definition_finish_state) -> void {
|
|
auto state = context.PopState();
|
|
|
|
if (state.has_error || !context.PositionIs(Lex::TokenKind::OpenCurlyBrace)) {
|
|
context.AddNodeExpectingDeclSemi(state, decl_kind,
|
|
context.tokens().GetKind(state.token),
|
|
/*is_def_allowed=*/true);
|
|
return;
|
|
}
|
|
|
|
context.PushState(state, definition_finish_state);
|
|
context.PushState(State::DeclScopeLoop);
|
|
context.AddNode(definition_start_kind, context.Consume(), state.subtree_start,
|
|
state.has_error);
|
|
}
|
|
|
|
auto HandleDeclOrDefinitionAsClass(Context& context) -> void {
|
|
HandleDeclOrDefinition(context, NodeKind::ClassDecl,
|
|
NodeKind::ClassDefinitionStart,
|
|
State::DeclDefinitionFinishAsClass);
|
|
}
|
|
|
|
auto HandleDeclOrDefinitionAsImpl(Context& context) -> void {
|
|
HandleDeclOrDefinition(context, NodeKind::ImplDecl,
|
|
NodeKind::ImplDefinitionStart,
|
|
State::DeclDefinitionFinishAsImpl);
|
|
}
|
|
|
|
auto HandleDeclOrDefinitionAsInterface(Context& context) -> void {
|
|
HandleDeclOrDefinition(context, NodeKind::InterfaceDecl,
|
|
NodeKind::InterfaceDefinitionStart,
|
|
State::DeclDefinitionFinishAsInterface);
|
|
}
|
|
|
|
auto HandleDeclOrDefinitionAsNamedConstraint(Context& context) -> void {
|
|
HandleDeclOrDefinition(context, NodeKind::NamedConstraintDecl,
|
|
NodeKind::NamedConstraintDefinitionStart,
|
|
State::DeclDefinitionFinishAsNamedConstraint);
|
|
}
|
|
|
|
// Handles parsing after the declaration scope of a type.
|
|
static auto HandleDeclDefinitionFinish(Context& context,
|
|
NodeKind definition_kind) -> void {
|
|
auto state = context.PopState();
|
|
|
|
context.AddNode(definition_kind, context.Consume(), state.subtree_start,
|
|
state.has_error);
|
|
}
|
|
|
|
auto HandleDeclDefinitionFinishAsClass(Context& context) -> void {
|
|
HandleDeclDefinitionFinish(context, NodeKind::ClassDefinition);
|
|
}
|
|
|
|
auto HandleDeclDefinitionFinishAsImpl(Context& context) -> void {
|
|
HandleDeclDefinitionFinish(context, NodeKind::ImplDefinition);
|
|
}
|
|
|
|
auto HandleDeclDefinitionFinishAsInterface(Context& context) -> void {
|
|
HandleDeclDefinitionFinish(context, NodeKind::InterfaceDefinition);
|
|
}
|
|
|
|
auto HandleDeclDefinitionFinishAsNamedConstraint(Context& context) -> void {
|
|
HandleDeclDefinitionFinish(context, NodeKind::NamedConstraintDefinition);
|
|
}
|
|
|
|
} // namespace Carbon::Parse
|