mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:51:06 +01:00
Run clang-tidy on the interpreter directory (#885)
`// NOLINT` is added on type aliases in stack.h and dictionary.h to allow lower_snake_case naming -- this didn't feel like a check worth disabling in spite of false positives. Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
committed by
GitHub
co-authored by
Geoff Romer
parent
924259986a
commit
9007bfcb88
@@ -27,7 +27,7 @@ class Action {
|
||||
};
|
||||
|
||||
Action(const Value&) = delete;
|
||||
Action& operator=(const Value&) = delete;
|
||||
auto operator=(const Value&) -> Action& = delete;
|
||||
|
||||
void AddResult(Nonnull<const Value*> result) { results_.push_back(result); }
|
||||
|
||||
|
||||
@@ -27,33 +27,38 @@ class Dictionary {
|
||||
|
||||
// Node cells are part of a "persistent data structure" and are thus
|
||||
// immutable.
|
||||
Node& operator=(const Node&) = delete;
|
||||
Node& operator=(Node&&) = delete;
|
||||
auto operator=(const Node&) -> Node& = delete;
|
||||
auto operator=(Node&&) -> Node& = delete;
|
||||
};
|
||||
|
||||
// A forward iterator over elements of a `Node` list.
|
||||
struct Iterator {
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
using value_type = typename Node::ValueType;
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
using difference_type = std::ptrdiff_t;
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
using pointer = const value_type*;
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
using reference = const value_type&;
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
Iterator(std::optional<Nonnull<Node*>> x) : p(x) {}
|
||||
explicit Iterator(std::optional<Nonnull<Node*>> x) : p(x) {}
|
||||
Iterator(const Iterator& iter) : p(iter.p) {}
|
||||
Iterator& operator++() {
|
||||
auto operator++() -> Iterator& {
|
||||
p = (*p)->next;
|
||||
return *this;
|
||||
}
|
||||
Iterator operator++(int) {
|
||||
auto operator++(int) -> Iterator {
|
||||
Iterator tmp(*this);
|
||||
operator++();
|
||||
return tmp;
|
||||
}
|
||||
bool operator==(const Iterator& rhs) const { return p == rhs.p; }
|
||||
bool operator!=(const Iterator& rhs) const { return p != rhs.p; }
|
||||
const value_type& operator*() { return (*p)->curr; }
|
||||
const value_type* operator->() { return &(*p)->curr; }
|
||||
auto operator==(const Iterator& rhs) const -> bool { return p == rhs.p; }
|
||||
auto operator!=(const Iterator& rhs) const -> bool { return p != rhs.p; }
|
||||
auto operator*() -> const value_type& { return (*p)->curr; }
|
||||
auto operator->() -> const value_type* { return &(*p)->curr; }
|
||||
|
||||
private:
|
||||
std::optional<Nonnull<Node*>> p;
|
||||
@@ -80,7 +85,7 @@ class Dictionary {
|
||||
head = arena->New<Node>(std::make_pair(k, v), head);
|
||||
}
|
||||
|
||||
bool IsEmpty() { return !head; }
|
||||
auto IsEmpty() -> bool { return !head; }
|
||||
|
||||
// The position of the first element of the dictionary
|
||||
// or `end()` if the dictionary is empty.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#define EXECUTABLE_SEMANTICS_INTERPRETER_FRAME_H_
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "common/ostream.h"
|
||||
@@ -31,10 +32,13 @@ struct Scope {
|
||||
// A frame represents either a function call or a delimited continuation.
|
||||
struct Frame {
|
||||
Frame(const Frame&) = delete;
|
||||
Frame& operator=(const Frame&) = delete;
|
||||
auto operator=(const Frame&) -> Frame& = delete;
|
||||
|
||||
Frame(std::string n, Stack<Nonnull<Scope*>> s, Stack<Nonnull<Action*>> c)
|
||||
: name(std::move(std::move(n))), scopes(s), todo(c), continuation() {}
|
||||
: name(std::move(n)),
|
||||
scopes(std::move(s)),
|
||||
todo(std::move(c)),
|
||||
continuation() {}
|
||||
|
||||
void Print(llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
|
||||
@@ -21,7 +21,7 @@ class Heap {
|
||||
explicit Heap(Nonnull<Arena*> arena) : arena(arena){};
|
||||
|
||||
Heap(const Heap&) = delete;
|
||||
Heap& operator=(const Heap&) = delete;
|
||||
auto operator=(const Heap&) -> Heap& = delete;
|
||||
|
||||
// Returns the value at the given address in the heap after
|
||||
// checking that it is alive.
|
||||
|
||||
@@ -877,7 +877,7 @@ auto Interpreter::StepStmt() -> Transition {
|
||||
}
|
||||
case Statement::Kind::Block: {
|
||||
if (act->pos() == 0) {
|
||||
const Block& block = cast<Block>(*stmt);
|
||||
const auto& block = cast<Block>(*stmt);
|
||||
if (block.Stmt()) {
|
||||
frame->scopes.Push(arena->New<Scope>(CurrentEnv()));
|
||||
return Spawn{arena->New<StatementAction>(*block.Stmt())};
|
||||
@@ -977,7 +977,7 @@ auto Interpreter::StepStmt() -> Transition {
|
||||
case Statement::Kind::Sequence: {
|
||||
// { { (s1,s2) :: C, E, F} :: S, H}
|
||||
// -> { { s1 :: s2 :: C, E, F} :: S, H}
|
||||
const Sequence& seq = cast<Sequence>(*stmt);
|
||||
const auto& seq = cast<Sequence>(*stmt);
|
||||
if (act->pos() == 0) {
|
||||
return Spawn{arena->New<StatementAction>(seq.Stmt())};
|
||||
} else {
|
||||
@@ -1056,7 +1056,7 @@ auto Interpreter::StepStmt() -> Transition {
|
||||
class Interpreter::DoTransition {
|
||||
public:
|
||||
// Does not take ownership of interpreter.
|
||||
DoTransition(Interpreter* interpreter) : interpreter(interpreter) {}
|
||||
explicit DoTransition(Interpreter* interpreter) : interpreter(interpreter) {}
|
||||
|
||||
void operator()(const Done& done) {
|
||||
Nonnull<Frame*> frame = interpreter->stack.Top();
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Carbon {
|
||||
// A stack data structure.
|
||||
template <class T>
|
||||
struct Stack {
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
using const_iterator = typename std::vector<T>::const_reverse_iterator;
|
||||
|
||||
// Creates an empty instance.
|
||||
@@ -62,8 +63,8 @@ struct Stack {
|
||||
auto Count() const -> int { return elements.size(); }
|
||||
|
||||
// Iterates over the Stack from top to bottom.
|
||||
const_iterator begin() const { return elements.crbegin(); }
|
||||
const_iterator end() const { return elements.crend(); }
|
||||
auto begin() const -> const_iterator { return elements.crbegin(); }
|
||||
auto end() const -> const_iterator { return elements.crend(); }
|
||||
|
||||
private:
|
||||
std::vector<T> elements;
|
||||
|
||||
@@ -24,7 +24,8 @@ class TypeChecker {
|
||||
: arena(arena), interpreter(arena) {}
|
||||
|
||||
struct TypeCheckContext {
|
||||
TypeCheckContext(Nonnull<Arena*> arena) : types(arena), values(arena) {}
|
||||
explicit TypeCheckContext(Nonnull<Arena*> arena)
|
||||
: types(arena), values(arena) {}
|
||||
|
||||
// Symbol table mapping names of runtime entities to their type.
|
||||
TypeEnv types;
|
||||
|
||||
@@ -59,7 +59,7 @@ class Value {
|
||||
};
|
||||
|
||||
Value(const Value&) = delete;
|
||||
Value& operator=(const Value&) = delete;
|
||||
auto operator=(const Value&) -> Value& = delete;
|
||||
|
||||
void Print(llvm::raw_ostream& out) const;
|
||||
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
||||
@@ -277,7 +277,7 @@ class AlternativeValue : public Value {
|
||||
class TupleValue : public Value {
|
||||
public:
|
||||
// An empty tuple, also known as the unit type.
|
||||
static Nonnull<const TupleValue*> Empty() {
|
||||
static auto Empty() -> Nonnull<const TupleValue*> {
|
||||
static const TupleValue empty = TupleValue(std::vector<TupleElement>());
|
||||
return Nonnull<const TupleValue*>(&empty);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user