From 9007bfcb88d91e8e8fe701e2a2e2b886cf448c60 Mon Sep 17 00:00:00 2001 From: Jon Meow <46229924+jonmeow@users.noreply.github.com> Date: Fri, 15 Oct 2021 08:54:53 -0700 Subject: [PATCH] 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 --- executable_semantics/interpreter/action.h | 2 +- executable_semantics/interpreter/dictionary.h | 25 +++++++++++-------- executable_semantics/interpreter/frame.h | 8 ++++-- executable_semantics/interpreter/heap.h | 2 +- .../interpreter/interpreter.cpp | 6 ++--- executable_semantics/interpreter/stack.h | 5 ++-- .../interpreter/type_checker.h | 3 ++- executable_semantics/interpreter/value.h | 4 +-- 8 files changed, 33 insertions(+), 22 deletions(-) diff --git a/executable_semantics/interpreter/action.h b/executable_semantics/interpreter/action.h index f5737b63f586..dda6f60ae689 100644 --- a/executable_semantics/interpreter/action.h +++ b/executable_semantics/interpreter/action.h @@ -27,7 +27,7 @@ class Action { }; Action(const Value&) = delete; - Action& operator=(const Value&) = delete; + auto operator=(const Value&) -> Action& = delete; void AddResult(Nonnull result) { results_.push_back(result); } diff --git a/executable_semantics/interpreter/dictionary.h b/executable_semantics/interpreter/dictionary.h index 7d7c20165eb7..c9a90b3775d2 100644 --- a/executable_semantics/interpreter/dictionary.h +++ b/executable_semantics/interpreter/dictionary.h @@ -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> x) : p(x) {} + explicit Iterator(std::optional> 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> p; @@ -80,7 +85,7 @@ class Dictionary { head = arena->New(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. diff --git a/executable_semantics/interpreter/frame.h b/executable_semantics/interpreter/frame.h index 35291bd47cce..97b4473df0b1 100644 --- a/executable_semantics/interpreter/frame.h +++ b/executable_semantics/interpreter/frame.h @@ -6,6 +6,7 @@ #define EXECUTABLE_SEMANTICS_INTERPRETER_FRAME_H_ #include +#include #include #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> s, Stack> 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()); } diff --git a/executable_semantics/interpreter/heap.h b/executable_semantics/interpreter/heap.h index 52af9f90701a..1ccd38a85c04 100644 --- a/executable_semantics/interpreter/heap.h +++ b/executable_semantics/interpreter/heap.h @@ -21,7 +21,7 @@ class Heap { explicit Heap(Nonnull 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. diff --git a/executable_semantics/interpreter/interpreter.cpp b/executable_semantics/interpreter/interpreter.cpp index c01338121137..e933decc5a0a 100644 --- a/executable_semantics/interpreter/interpreter.cpp +++ b/executable_semantics/interpreter/interpreter.cpp @@ -877,7 +877,7 @@ auto Interpreter::StepStmt() -> Transition { } case Statement::Kind::Block: { if (act->pos() == 0) { - const Block& block = cast(*stmt); + const auto& block = cast(*stmt); if (block.Stmt()) { frame->scopes.Push(arena->New(CurrentEnv())); return Spawn{arena->New(*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(*stmt); + const auto& seq = cast(*stmt); if (act->pos() == 0) { return Spawn{arena->New(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 = interpreter->stack.Top(); diff --git a/executable_semantics/interpreter/stack.h b/executable_semantics/interpreter/stack.h index 2ed05db79fa0..7924445c5768 100644 --- a/executable_semantics/interpreter/stack.h +++ b/executable_semantics/interpreter/stack.h @@ -16,6 +16,7 @@ namespace Carbon { // A stack data structure. template struct Stack { + // NOLINTNEXTLINE(readability-identifier-naming) using const_iterator = typename std::vector::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 elements; diff --git a/executable_semantics/interpreter/type_checker.h b/executable_semantics/interpreter/type_checker.h index 103cea610a12..ace4ec7a21dc 100644 --- a/executable_semantics/interpreter/type_checker.h +++ b/executable_semantics/interpreter/type_checker.h @@ -24,7 +24,8 @@ class TypeChecker { : arena(arena), interpreter(arena) {} struct TypeCheckContext { - TypeCheckContext(Nonnull arena) : types(arena), values(arena) {} + explicit TypeCheckContext(Nonnull arena) + : types(arena), values(arena) {} // Symbol table mapping names of runtime entities to their type. TypeEnv types; diff --git a/executable_semantics/interpreter/value.h b/executable_semantics/interpreter/value.h index be87d8aed1a1..85fde17342dd 100644 --- a/executable_semantics/interpreter/value.h +++ b/executable_semantics/interpreter/value.h @@ -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 Empty() { + static auto Empty() -> Nonnull { static const TupleValue empty = TupleValue(std::vector()); return Nonnull(&empty); }