Skip to content

Commit

Permalink
Fix more warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Aug 17, 2024
1 parent d5584c5 commit 42dd0e6
Show file tree
Hide file tree
Showing 62 changed files with 105 additions and 207 deletions.
2 changes: 1 addition & 1 deletion src/AddressingModeMatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
8 changes: 3 additions & 5 deletions src/Assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/BinaryExpression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "BinaryExpression.h"

#include "Exception.h"
#include "VariableExpression.h"

std::optional<Expression> BinaryExpression::evaluated(const EvaluationContext& context) const {
Expand Down
1 change: 1 addition & 0 deletions src/BodyParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())); }
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ add_library(xlr8-library STATIC
Util.cc
Value.cc
ValueExpression.cc
VariableEntity.cc
VariableExpression.cc
Visibility.cc
VoidExpression.cc)
Expand Down
4 changes: 2 additions & 2 deletions src/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol, AddressingMode> addressing_modes;
Expand Down
8 changes: 3 additions & 5 deletions src/CPUParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<AddressingMode::Argument>(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);
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 2 additions & 3 deletions src/Callable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Callable::initialize() {
}
}

Callable::Callable(ObjectFile* owner, Token name_, const std::shared_ptr<ParsedValue>& definition): Entity(owner, name_, definition) {
Callable::Callable(ObjectFile* owner, const Token& name_, const std::shared_ptr<ParsedValue>& definition): Entity(owner, name_, definition) {
initialize();
auto parameters = definition->as_dictionary();

Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class Callable: public Entity {
std::vector<Expression> default_arguments;
};

Callable(ObjectFile* owner, Token name, const std::shared_ptr<ParsedValue>& 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<ParsedValue>& 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<Expression> default_argument(size_t index) const {return arguments.default_argument(index);}

Expand Down
2 changes: 0 additions & 2 deletions src/Checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdint>

#include "Symbol.h"
#include "Value.h"

Expand Down
1 change: 1 addition & 0 deletions src/ChecksumAlgorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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, std::shared_ptr<ChecksumAlgorithm>(*)(Symbol)> ChecksumAlgorithm::algorithms = {
Expand Down
4 changes: 1 addition & 3 deletions src/ChecksumBody.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -79,8 +78,7 @@ std::optional<Body> 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;
Expand Down
1 change: 1 addition & 0 deletions src/ChecksumBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/Command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <filesystem>
#include <fstream>
#include <iostream>
#include <utility>

#include "config.h"

Expand Down
2 changes: 2 additions & 0 deletions src/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class Command {
public:
Command(const std::vector<Commandline::Option>& options, std::string arguments, const std::string& name);
virtual ~Command() = default;

int run(int argc, char * const argv[]);

std::string program_name;
Expand Down
3 changes: 1 addition & 2 deletions src/Commandline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <sstream>
#include <iostream>
#include <unordered_map>
#include <utility>

Commandline::Commandline(std::vector<Option> options_, std::string arguments_, std::string header_, std::string footer_, std::string version_) : options(std::move(options_)), arguments(std::move(arguments_)), header(std::move(header_)), footer(std::move(footer_)), version(std::move(version_)), options_sorted(false) {
add_option(Option("help", 'h', "display this help message"));
Expand Down Expand Up @@ -166,7 +165,7 @@ std::optional<std::string> ParsedCommandline::find_first(const std::string &name
}

[[maybe_unused]] std::optional<std::string> ParsedCommandline::find_last(const std::string &name) const {
for (auto it = options.rbegin(); it != options.rend(); it++) {
for (auto it = options.rbegin(); it != options.rend(); ++it) {
const auto &option = *it;

if (option.name == name) {
Expand Down
1 change: 0 additions & 1 deletion src/Commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

#include <optional>
#include <string>
#include <utility>
#include <vector>

class ParsedCommandline {
Expand Down
2 changes: 1 addition & 1 deletion src/DataBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class DataBodyElement {
public:
DataBodyElement(Expression expression, std::optional<Encoder> encoding): expression(std::move(expression)), encoding(encoding) {}
DataBodyElement(Expression expression, std::optional<Encoder> encoding): expression(std::move(expression)), encoding(std::move(encoding)) {}

[[nodiscard]] std::optional<uint64_t> size() const {return size_range().size();}
[[nodiscard]] SizeRange size_range() const;
Expand Down
1 change: 1 addition & 0 deletions src/EvaluationContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "EvaluationContext.h"

#include "Entity.h"
#include "Exception.h"

EvaluationContext::EvaluationContext(EvaluationResult& result, EvaluationType type, std::shared_ptr<Environment> environment, std::unordered_set<Symbol> defines, const SizeRange& offset): type(type), environment(std::move(environment)), defines{std::move(defines)}, offset(offset), result(result) {
if (type == MACRO_EXPANSION) {
Expand Down
6 changes: 3 additions & 3 deletions src/FileTokenizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const std::unordered_map<Token, FileTokenizer::PreprocessorDirective> FileTokeni
};
// clang-format on

FileTokenizer::FileTokenizer(const Path& path, const Target* target, bool use_preprocessor, const std::unordered_set<Symbol>& defines) : path{path}, use_preprocessor{use_preprocessor}, defines{defines}, target{target} {
FileTokenizer::FileTokenizer(const Path& path, const Target* target, bool use_preprocessor, const std::unordered_set<Symbol>& defines) : defines{defines}, use_preprocessor{use_preprocessor}, path{path}, target{target} {
if (use_preprocessor) {
add_literal(token_define);
add_literal(token_include);
Expand Down Expand Up @@ -616,7 +616,7 @@ void FileTokenizer::Source::reset_to(const Location& new_location) {
column = new_location.start_column;
}

std::optional<Token::Type> FileTokenizer::MatcherNode::match(FileTokenizer::Source& source, std::string& name) {
std::optional<Token::Type> FileTokenizer::MatcherNode::match(FileTokenizer::Source& source, std::string& name) { // NOLINT(misc-no-recursion)
auto c = source.next();
if (c == EOF) {
if (name.empty()) {
Expand Down Expand Up @@ -665,7 +665,7 @@ std::optional<Token::Type> FileTokenizer::MatcherNode::match(FileTokenizer::Sour
return it->second->match(source, name);
}

void FileTokenizer::MatcherNode::add(const char* string, Token::Type type, const std::unordered_set<char>& new_suffix, bool match_in_word_) {
void FileTokenizer::MatcherNode::add(const char* string, Token::Type type, const std::unordered_set<char>& new_suffix, bool match_in_word_) { // NOLINT(misc-no-recursion)
if (string[0] == '\0') {
if (match_type.has_value() && (match_type.value() != type || match_in_word != match_in_word_)) {
throw Exception("literal already defined with different type"); // TODO: include more detail
Expand Down
2 changes: 1 addition & 1 deletion src/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class Function: public Callable {
public:
Function(ObjectFile* owner, const Token& name, const std::shared_ptr<ParsedValue>& definition);
Function(ObjectFile* owner, Token name, Visibility visibility, bool default_only, Arguments arguments, Expression definition): Callable(owner, name, visibility, default_only, std::move(arguments)), definition(definition) {}
Function(ObjectFile* owner, const Token& name, Visibility visibility, bool default_only, Arguments arguments, const Expression& definition): Callable(owner, name, visibility, default_only, std::move(arguments)), definition(definition) {}
Expression call(const Location& location, const std::vector<Expression>& arguments) const;
void serialize(std::ostream& stream) const;

Expand Down
3 changes: 1 addition & 2 deletions src/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <string>

#include "BaseExpression.h"
#include "Symbol.h"

class Instruction {
public:
bool has_addressing_mode(Symbol addressing_mode) const {return opcodes.find(addressing_mode) != opcodes.end();}
bool has_addressing_mode(Symbol addressing_mode) const {return opcodes.contains(addressing_mode);}
uint64_t opcode(Symbol addressing_mode) const;

std::unordered_map<Symbol, uint64_t> opcodes; // keys are addressing modes
Expand Down
5 changes: 3 additions & 2 deletions src/InstructionEncoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>

#include "Assembler.h"
#include "ExpressionNode.h"
#include "InRangeExpression.h"
#include "ParseException.h"
#include "TokenNode.h"
#include "ExpressionNode.h"
#include "Util.h"

Body InstructionEncoder::encode(const Token& name, const std::vector<std::shared_ptr<Node>>& arguments, const std::shared_ptr<Environment>& environment, const SizeRange& offset, bool& uses_pc) {
Body InstructionEncoder::encode(const Token& name, const std::vector<std::shared_ptr<Node>>& arguments, const std::shared_ptr<Environment>& environment, const SizeRange& offset, bool& uses_pc) const {
const auto instruction = cpu->instruction(name.as_symbol());
if (instruction == nullptr) {
throw ParseException(name, "unknown instruction '%s'", name.as_string().c_str());
Expand Down
4 changes: 1 addition & 3 deletions src/InstructionEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Target.h"
#include "IfBody.h"
#include "DataBody.h"
#include "InRangeExpression.h"
#include "ValueExpression.h"
#include "LabelBody.h"


class InstructionEncoder {
public:
explicit InstructionEncoder(const CPU* cpu): cpu(cpu) {}

[[nodiscard]] Body encode(const Token& name, const std::vector<std::shared_ptr<Node>>& arguments, const std::shared_ptr<Environment>& environment, const SizeRange& offset, bool& uses_pc);
[[nodiscard]] Body encode(const Token& name, const std::vector<std::shared_ptr<Node>>& arguments, const std::shared_ptr<Environment>& environment, const SizeRange& offset, bool& uses_pc) const;

private:
class Variant {
Expand Down
1 change: 0 additions & 1 deletion src/IntegerEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define INTEGER_ENCODER_H

#include "BaseEncoder.h"
#include "BaseExpression.h"
#include "Environment.h"
#include "Value.h"

Expand Down
3 changes: 1 addition & 2 deletions src/LabelBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define LABEL_BODY_H

#include "Body.h"
#include "Value.h"
#include "Exception.h"
#include "SizeRange.h"

class LabelBody: public BodyElement {
public:
explicit LabelBody(Symbol name): name(name) {}
LabelBody(Symbol name, SizeRange offset, bool added_to_environment, size_t unnamed_index): name(name), offset(offset), added_to_environment(added_to_environment), unnamed_index(unnamed_index) {}
LabelBody(Symbol name, const SizeRange& offset, bool added_to_environment, size_t unnamed_index): name(name), offset(offset), unnamed_index(unnamed_index), added_to_environment(added_to_environment) {}

void encode(std::string &bytes, const Memory* memory) const override {}
[[nodiscard]] bool empty() const override {return added_to_environment && offset.size();}
Expand Down
6 changes: 3 additions & 3 deletions src/LabelExpression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "VariableExpression.h"
#include <complex>

LabelExpression::LabelExpression(const Location& location, const Entity* object, Symbol label_name, SizeRange offset) : BaseExpression(location), label_type(LabelExpressionType::NAMED), object(object), object_name(object ? object->name.as_symbol() : Symbol()), label_name(label_name), offset(offset) {}
LabelExpression::LabelExpression(const Location& location, const Entity* object, Symbol label_name, const SizeRange& offset) : BaseExpression(location), label_type(LabelExpressionType::NAMED), object_name(object ? object->name.as_symbol() : Symbol()), label_name(label_name), object(object), offset(offset) {}

Expression LabelExpression::create(const Location& location, const std::vector<Expression>& arguments) {
if (arguments.size() == 1) {
Expand Down Expand Up @@ -70,7 +70,7 @@ Expression LabelExpression::create(const Location& location, const std::vector<E
else if (arguments.size() == 2) {
auto object_name = arguments[0].as_variable();
auto label_name = arguments[1].as_variable();
if (object_name || label_name) {
if (object_name && label_name) {
return Expression(std::make_shared<LabelExpression>(location, object_name->variable(), label_name->variable()));
}
else {
Expand All @@ -83,7 +83,7 @@ Expression LabelExpression::create(const Location& location, const std::vector<E

}

Expression LabelExpression::create(const Location& location, const Entity* object, Symbol label_name, SizeRange offset, SizeRange scope_offset, bool keep) {
Expression LabelExpression::create(const Location& location, const Entity* object, Symbol label_name, const SizeRange& offset, const SizeRange& scope_offset, bool keep) {
if (!keep && offset.has_size() && scope_offset.has_size()) {
return {location, Expression({}, *offset.size()), Expression::ADD, Expression({}, *scope_offset.size())};
}
Expand Down
8 changes: 4 additions & 4 deletions src/LabelExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class LabelExpression: public BaseExpression {
public:
LabelExpression(const Location& location, Symbol object_name, Symbol label_name): BaseExpression(location), label_type(LabelExpressionType::NAMED), object_name(object_name), label_name(label_name) {}
LabelExpression(const Location& location, Symbol object_name, Symbol label_name, SizeRange offset): BaseExpression(location), label_type(LabelExpressionType::NAMED), object_name(object_name), label_name(label_name), offset(offset) {}
LabelExpression(const Location& location, const Entity* object, Symbol label_name, SizeRange offset);
LabelExpression(const Location& location, LabelExpressionType type, size_t unnamed_index, SizeRange offset): BaseExpression(location), label_type(type), offset(offset), unnamed_index(unnamed_index) {}
LabelExpression(const Location& location, Symbol object_name, Symbol label_name, const SizeRange& offset): BaseExpression(location), label_type(LabelExpressionType::NAMED), object_name(object_name), label_name(label_name), offset(offset) {}
LabelExpression(const Location& location, const Entity* object, Symbol label_name, const SizeRange& offset);
LabelExpression(const Location& location, LabelExpressionType type, size_t unnamed_index, const SizeRange& offset): BaseExpression(location), label_type(type), offset(offset), unnamed_index(unnamed_index) {}

static Expression create(const Location& location, const Entity* object, Symbol label_name, SizeRange offset, SizeRange scope_offset = SizeRange(0), bool keep = false);
static Expression create(const Location& location, const Entity* object, Symbol label_name, const SizeRange& offset, const SizeRange& scope_offset = SizeRange(0), bool keep = false);
static Expression create(const Location& location, const std::vector<Expression>& arguments);
static Expression create(const Location& location, LabelExpressionType type, size_t unnamed_index = std::numeric_limits<size_t>::max(), SizeRange offset = SizeRange(0, {}));

Expand Down
3 changes: 0 additions & 3 deletions src/Macro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "Macro.h"

#include <utility>
#include "Exception.h"

bool Macro::initialized = false;
Token Macro::token_body;

Expand Down
Loading

0 comments on commit 42dd0e6

Please sign in to comment.