From 42dd0e69f99bf5c66c3ed4c62af20d0e34eb7839 Mon Sep 17 00:00:00 2001 From: Dieter Baron Date: Sat, 17 Aug 2024 16:19:26 +0200 Subject: [PATCH] Fix more warnings. --- src/AddressingModeMatcher.cc | 2 +- src/Assembler.cc | 8 +++---- src/BinaryExpression.cc | 1 + src/BodyParser.cc | 1 + src/CMakeLists.txt | 1 - src/CPU.h | 4 ++-- src/CPUParser.cc | 8 +++---- src/Callable.cc | 5 ++--- src/Callable.h | 4 ++-- src/Checksum.h | 2 -- src/ChecksumAlgorithm.cc | 1 + src/ChecksumBody.cc | 4 +--- src/ChecksumBody.h | 1 + src/Command.cc | 1 - src/Command.h | 2 ++ src/Commandline.cc | 3 +-- src/Commandline.h | 1 - src/DataBody.h | 2 +- src/EvaluationContext.cc | 1 + src/FileTokenizer.cc | 6 ++--- src/Function.h | 2 +- src/Instruction.h | 3 +-- src/InstructionEncoder.cc | 5 +++-- src/InstructionEncoder.h | 4 +--- src/IntegerEncoder.h | 1 - src/LabelBody.h | 3 +-- src/LabelExpression.cc | 6 ++--- src/LabelExpression.h | 8 +++---- src/Macro.cc | 3 --- src/Macro.h | 1 - src/MacroBody.cc | 3 +-- src/MacroBody.h | 2 +- src/Memory.cc | 3 +-- src/MemoryBody.cc | 5 +++-- src/MemoryBody.h | 1 - src/MemoryMap.cc | 2 +- src/Object.h | 1 - src/ObjectFile.cc | 35 +++++++++++++++-------------- src/ObjectFile.h | 6 ++--- src/ObjectFileParser.h | 2 -- src/ParseException.cc | 8 +++---- src/ParseException.h | 14 +++++------- src/ParsedValue.h | 5 +++-- src/Range.cc | 1 - src/SequenceTokenizer.cc | 2 +- src/SequenceTokenizer.h | 4 ++-- src/SizeRange.cc | 3 +-- src/StringEncoding.cc | 2 +- src/Symbol.cc | 7 ++---- src/TargetParser.cc | 5 ++--- src/TargetParser.h | 2 +- src/Token.cc | 2 ++ src/Token.h | 12 +++++----- src/TokenGroup.h | 2 +- src/Tokenizer.cc | 4 ++-- src/Tokenizer.h | 4 ++-- src/UnaryExpression.cc | 1 + src/Unresolved.cc | 2 +- src/Value.h | 1 - src/VariableEntity.cc | 32 --------------------------- src/VariableEntity.h | 43 ------------------------------------ src/xlr8.cc | 2 -- 62 files changed, 105 insertions(+), 207 deletions(-) delete mode 100644 src/VariableEntity.cc delete mode 100644 src/VariableEntity.h diff --git a/src/AddressingModeMatcher.cc b/src/AddressingModeMatcher.cc index 7d31e43..d2efc02 100644 --- a/src/AddressingModeMatcher.cc +++ b/src/AddressingModeMatcher.cc @@ -91,7 +91,7 @@ AddressingModeMatcherElement::elements_for(const AddressingMode::Notation::Eleme switch (element.type) { case AddressingMode::Notation::ARGUMENT: { - auto it = arguments.find(element.symbol); + const auto it = arguments.find(element.symbol); if (it == arguments.end()) { throw Exception("unknown argument '%s'", element.symbol.c_str()); } diff --git a/src/Assembler.cc b/src/Assembler.cc index 34fd2e6..2d34b72 100644 --- a/src/Assembler.cc +++ b/src/Assembler.cc @@ -171,10 +171,10 @@ void Assembler::parse_assignment(Visibility visibility, const Token& name, bool } void Assembler::parse_cpu() { - auto name = tokenizer.expect(Token::STRING, TokenGroup::newline); + const auto name = tokenizer.expect(Token::STRING, TokenGroup::newline); try { - auto new_cpu = &CPU::get(name.as_symbol(), tokenizer.current_file()); + const auto new_cpu = &CPU::get(name.as_symbol(), tokenizer.current_file()); if (target) { had_cpu = true; @@ -489,9 +489,7 @@ void Assembler::parse_visibility() { } void Assembler::set_target(const Target* new_target) { - if (target) { - // TODO: check that target and new_target are compatible - } + // TODO: check that target and new_target are compatible target = new_target; if (target) { tokenizer.set_target(target); diff --git a/src/BinaryExpression.cc b/src/BinaryExpression.cc index 3cb00f0..1a6d13b 100644 --- a/src/BinaryExpression.cc +++ b/src/BinaryExpression.cc @@ -31,6 +31,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "BinaryExpression.h" +#include "Exception.h" #include "VariableExpression.h" std::optional BinaryExpression::evaluated(const EvaluationContext& context) const { diff --git a/src/BodyParser.cc b/src/BodyParser.cc index 5dd53cb..e4f3b90 100644 --- a/src/BodyParser.cc +++ b/src/BodyParser.cc @@ -478,6 +478,7 @@ void BodyParser::parse_error() { else { tokenizer.unget(token); } + throw ParseException(location, message.as_string()); } void BodyParser::parse_unnamed_label() { current_body->append(Body(Symbol(), current_size())); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f6ac81..e799ff8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,7 +95,6 @@ add_library(xlr8-library STATIC Util.cc Value.cc ValueExpression.cc - VariableEntity.cc VariableExpression.cc Visibility.cc VoidExpression.cc) diff --git a/src/CPU.h b/src/CPU.h index 3f9b77d..12a3883 100644 --- a/src/CPU.h +++ b/src/CPU.h @@ -59,9 +59,9 @@ class CPU { void setup(FileTokenizer& tokenizer) const; - [[nodiscard]] bool uses_empty_mnemonic() const {return instructions.find(Symbol()) != instructions.end();} + [[nodiscard]] bool uses_empty_mnemonic() const {return instructions.contains(Symbol());} [[nodiscard]] bool uses_braces() const {return uses_punctuation(Symbol("("));} - [[nodiscard]] bool uses_punctuation(Symbol symbol) const {return punctuation.find(symbol) != punctuation.end();} + [[nodiscard]] bool uses_punctuation(Symbol symbol) const {return punctuation.contains(symbol);} private: std::unordered_map addressing_modes; diff --git a/src/CPUParser.cc b/src/CPUParser.cc index 44c2a03..ff44a2a 100644 --- a/src/CPUParser.cc +++ b/src/CPUParser.cc @@ -167,8 +167,7 @@ void CPUParser::parse_addressing_mode() { default_value = Value{default_value_token.as_value()}; } addressing_mode.arguments[pair.first.as_symbol()] = std::make_unique(argument_type, default_value); - auto encoding_argument_type = argument_type->as_encoding(); - if (encoding_argument_type) { + if (argument_type->is_encoding()) { auto argument_variable_name = pair.first.as_symbol(); unencoded_encoding_arguments.insert(argument_variable_name); } @@ -280,8 +279,7 @@ void CPUParser::parse_argument_type() { throw ParseException(type, "unknown argument type '%s'", type.as_string().c_str()); } argument_type = (this->*it->second)(name, parameters.get()); - auto encoding_type = argument_type->as_encoding(); - if (encoding_type) { + if (auto encoding_type = argument_type->as_encoding()) { auto range_name = Symbol(".range(" + name.as_string() + ")"); cpu.add_argument_type(range_name, encoding_type->range_type(range_name)); } @@ -321,7 +319,7 @@ void CPUParser::parse_instruction() { if (!pair.first.is_name()) { throw ParseException(pair.first, "addressing mode must be name"); } - if (addressing_mode_names.find(pair.first) == addressing_mode_names.end()) { + if (!addressing_mode_names.contains(pair.first)) { throw ParseException(pair.first, "unknown addressing mode"); } auto it = instruction.opcodes.find(pair.first.as_symbol()); diff --git a/src/Callable.cc b/src/Callable.cc index b894952..3a84341 100644 --- a/src/Callable.cc +++ b/src/Callable.cc @@ -48,7 +48,7 @@ void Callable::initialize() { } } -Callable::Callable(ObjectFile* owner, Token name_, const std::shared_ptr& definition): Entity(owner, name_, definition) { +Callable::Callable(ObjectFile* owner, const Token& name_, const std::shared_ptr& definition): Entity(owner, name_, definition) { initialize(); auto parameters = definition->as_dictionary(); @@ -88,8 +88,7 @@ void Callable::Arguments::serialize(std::ostream& stream) const { stream << ", "; } stream << name(index); - auto value = default_argument(index); - if (value) { + if (auto value = default_argument(index)) { stream << " = " << *value; } } diff --git a/src/Callable.h b/src/Callable.h index 9d06426..6dce6b7 100644 --- a/src/Callable.h +++ b/src/Callable.h @@ -55,8 +55,8 @@ class Callable: public Entity { std::vector default_arguments; }; - Callable(ObjectFile* owner, Token name, const std::shared_ptr& definition); - Callable(ObjectFile* owner, Token name, Visibility visibility, bool default_only, Arguments arguments): Entity(owner, name, visibility, default_only), arguments(std::move(arguments)) {} + Callable(ObjectFile* owner, const Token& name, const std::shared_ptr& definition); + Callable(ObjectFile* owner, const Token& name, Visibility visibility, bool default_only, Arguments arguments): Entity(owner, name, visibility, default_only), arguments(std::move(arguments)) {} [[nodiscard]] Symbol argument_name(size_t index) const {return arguments.name(index);} [[nodiscard]] std::optional default_argument(size_t index) const {return arguments.default_argument(index);} diff --git a/src/Checksum.h b/src/Checksum.h index dae507d..216a4f9 100644 --- a/src/Checksum.h +++ b/src/Checksum.h @@ -32,8 +32,6 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include - #include "Symbol.h" #include "Value.h" diff --git a/src/ChecksumAlgorithm.cc b/src/ChecksumAlgorithm.cc index bc9fbbd..f301393 100644 --- a/src/ChecksumAlgorithm.cc +++ b/src/ChecksumAlgorithm.cc @@ -32,6 +32,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ChecksumAlgorithm.h" #include "ChecksumAlgorithmXor.h" +#include "Exception.h" // clang-format off const std::unordered_map(*)(Symbol)> ChecksumAlgorithm::algorithms = { diff --git a/src/ChecksumBody.cc b/src/ChecksumBody.cc index e2c06ad..5e3c25a 100644 --- a/src/ChecksumBody.cc +++ b/src/ChecksumBody.cc @@ -33,7 +33,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Body.h" #include "ExpressionParser.h" #include "ParseException.h" -#include "VariableExpression.h" Body ChecksumBody::parse(Tokenizer& tokenizer) { auto algorithm_name = tokenizer.next(); @@ -79,8 +78,7 @@ std::optional ChecksumBody::evaluated(const EvaluationContext& context) co auto new_parameters = parameters; auto fully_evaluated = new_start.value_or(start).has_value() && new_end.value_or(end).has_value(); for (auto& [name, expression] : parameters) { - auto new_expression = expression.evaluated(context); - if (new_expression) { + if (auto new_expression = expression.evaluated(context)) { new_parameters[name] = *new_expression; if (!new_expression->has_value()) { fully_evaluated = false; diff --git a/src/ChecksumBody.h b/src/ChecksumBody.h index 777813c..4dd78c4 100644 --- a/src/ChecksumBody.h +++ b/src/ChecksumBody.h @@ -36,6 +36,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "BodyElement.h" #include "ChecksumAlgorithm.h" +#include "Exception.h" #include "Symbol.h" class ChecksumBody: public BodyElement { diff --git a/src/Command.cc b/src/Command.cc index ea1fe86..52c8330 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -35,7 +35,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include "config.h" diff --git a/src/Command.h b/src/Command.h index 718f8d8..f26a3ad 100644 --- a/src/Command.h +++ b/src/Command.h @@ -40,6 +40,8 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class Command { public: Command(const std::vector& options, std::string arguments, const std::string& name); + virtual ~Command() = default; + int run(int argc, char * const argv[]); std::string program_name; diff --git a/src/Commandline.cc b/src/Commandline.cc index 588b145..0db4e37 100644 --- a/src/Commandline.cc +++ b/src/Commandline.cc @@ -38,7 +38,6 @@ #include #include #include -#include Commandline::Commandline(std::vector