mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 22:02:33 +01:00
Disables three new warnings because they lean more towards style conflicts than fixes. I've brought these up on #style. Other than that, mostly fixing basic issues, and things that clang-tidy-20 seems to fire where clang-tiday-16 didn't. One particular curious case is `llvm::StringLiteral::data()` uses, which are flagged as not strictly null-terminated; I'm switching to `const char*` in those spots which matches `llvm::formatv`'s format argument, but feels worse. I'm removing `run_clang_tidy.py` here because I'm observing it give fewer warnings than `bazel build --config=clang-tidy -k //toolchain/...`. The latter matches how we enforce in GitHub actions (and also caches results, and suppresses output for files that have no issues), so I'm dropping the bespoke script.
90 lines
3.4 KiB
C++
90 lines
3.4 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_PARAM_AND_ARG_REFS_STACK_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_PARAM_AND_ARG_REFS_STACK_H_
|
|
|
|
#include "common/check.h"
|
|
#include "toolchain/check/inst_block_stack.h"
|
|
#include "toolchain/check/node_stack.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// The stack of instruction blocks being used for per-element tracking of
|
|
// instructions in parameter and argument instruction blocks. Versus
|
|
// InstBlockStack, an element will have 1 or more instructions in blocks in
|
|
// InstBlockStack, but only ever 1 instruction in blocks here. The result is
|
|
// typically referred to as "param_refs" or "arg_refs".
|
|
class ParamAndArgRefsStack {
|
|
public:
|
|
explicit ParamAndArgRefsStack(SemIR::File& sem_ir,
|
|
llvm::raw_ostream* vlog_stream,
|
|
NodeStack& node_stack)
|
|
: node_stack_(&node_stack),
|
|
stack_("param_and_arg_refs_stack", sem_ir, vlog_stream) {}
|
|
|
|
// Starts handling parameters or arguments.
|
|
auto Push() -> void { stack_.Push(); }
|
|
|
|
// On a comma, pushes the most recent instruction, becoming param or arg ref.
|
|
// This also pops the NodeStack, meaning its top will remain start_kind.
|
|
auto ApplyComma() -> void {
|
|
// Support expressions, parameters, and other nodes like
|
|
// `StructLiteralField` that produce InstIds.
|
|
stack_.AddInstId(node_stack_->Pop<SemIR::InstId>());
|
|
}
|
|
|
|
// Detects whether there's an entry to push from the end of a parameter or
|
|
// argument list, and if so, moves it to the current parameter or argument
|
|
// list. Does not pop the list. `start_kind` is the node kind at the start
|
|
// of the parameter or argument list, and will be at the top of the parse node
|
|
// stack when this function returns.
|
|
auto EndNoPop(Parse::NodeKind start_kind) -> void {
|
|
if (!node_stack_->PeekIs(start_kind)) {
|
|
// Support expressions, parameters, and other nodes like
|
|
// `StructLiteralField` that produce InstIds.
|
|
stack_.AddInstId(node_stack_->Pop<SemIR::InstId>());
|
|
}
|
|
}
|
|
|
|
// Pops the current parameter or argument list. Should only be called after
|
|
// `EndNoPop`.
|
|
auto Pop() -> SemIR::InstBlockId { return stack_.Pop(); }
|
|
|
|
// Detects whether there's an entry to push. Pops and returns the argument
|
|
// list. This is the same as `EndNoPop` followed by `Pop`.
|
|
auto EndAndPop(Parse::NodeKind start_kind) -> SemIR::InstBlockId {
|
|
EndNoPop(start_kind);
|
|
return Pop();
|
|
}
|
|
|
|
// Pops the top instruction block, and discards it if it hasn't had an ID
|
|
// allocated.
|
|
auto PopAndDiscard() -> void { stack_.PopAndDiscard(); }
|
|
|
|
// Returns a view of the contents of the top instruction block on the stack.
|
|
auto PeekCurrentBlockContents() -> llvm::ArrayRef<SemIR::InstId> {
|
|
return stack_.PeekCurrentBlockContents();
|
|
}
|
|
|
|
// Runs verification that the processing cleanly finished.
|
|
auto VerifyOnFinish() -> void { stack_.VerifyOnFinish(); }
|
|
|
|
// Prints the stack for a stack dump.
|
|
auto PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void {
|
|
stack_.PrintForStackDump(indent, output);
|
|
}
|
|
|
|
private:
|
|
// The node stack is manipulated when adding refs.
|
|
NodeStack* node_stack_;
|
|
|
|
// The refs stack.
|
|
InstBlockStack stack_;
|
|
};
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_PARAM_AND_ARG_REFS_STACK_H_
|