Skip to content

Commit

Permalink
refactor: remove unnecessary noexcept
Browse files Browse the repository at this point in the history
We compile our code with exceptions disabled, so (I think) noexcept has
no effect. Remove this noise.
  • Loading branch information
strager committed Jul 27, 2023
1 parent 53052e8 commit 210f327
Show file tree
Hide file tree
Showing 152 changed files with 1,050 additions and 1,236 deletions.
4 changes: 1 addition & 3 deletions plugin/vscode/quick-lint-js/vscode/qljs-document.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ class QLJS_Document_Base {
}
}

Padded_String_View document_string() noexcept {
return this->document_.string();
}
Padded_String_View document_string() { return this->document_.string(); }

virtual void after_modification(::Napi::Env, QLJS_Workspace&,
VSCode_Diagnostic_Collection) = 0;
Expand Down
4 changes: 2 additions & 2 deletions plugin/vscode/quick-lint-js/vscode/qljs-workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ struct VSCode_Language {
this->language_id_size = static_cast<unsigned char>(language_id.size());
}

std::string_view language_id() const noexcept {
std::string_view language_id() const {
return std::string_view(this->raw_language_id, this->language_id_size);
}

// Returns nullptr if the language does not exist.
static const VSCode_Language* find(std::string_view language_id,
bool allow_typescript) noexcept {
bool allow_typescript) {
static constexpr Linter_Options jsx = {
.jsx = true,
.typescript = false,
Expand Down
2 changes: 1 addition & 1 deletion plugin/vscode/quick-lint-js/vscode/qljs-workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class QLJS_Workspace : public ::Napi::ObjectWrap<QLJS_Workspace> {
#endif
;

Thread_Safe_Configuration_Filesystem<Underlying_FS_Type>* fs() noexcept {
Thread_Safe_Configuration_Filesystem<Underlying_FS_Type>* fs() {
return &this->fs_;
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/vscode/quick-lint-js/vscode/vscode-diag-reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class VSCode_Diag_Reporter final : public Diag_Reporter {
public:
explicit VSCode_Diag_Reporter(VSCode_Module* vscode, ::Napi::Env env,
const LSP_Locator* locator,
::Napi::Value document_uri) noexcept
::Napi::Value document_uri)
: vscode_(vscode),
env_(env),
diagnostics_(::Napi::Array::New(env)),
Expand Down
7 changes: 3 additions & 4 deletions plugin/vscode/quick-lint-js/vscode/vscode-tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NAPI_String_Writer {
public:
explicit NAPI_String_Writer(::Napi::Env env) : env_(env) {}

std::size_t string_size(void* string) const noexcept {
std::size_t string_size(void* string) const {
std::size_t size;
::napi_status status =
::napi_get_value_string_utf16(this->env_, this->get(string),
Expand All @@ -32,8 +32,7 @@ class NAPI_String_Writer {
return size;
}

void copy_string(void* string, char16_t* out, std::size_t capacity) const
noexcept {
void copy_string(void* string, char16_t* out, std::size_t capacity) const {
std::size_t length;
::napi_status status =
::napi_get_value_string_utf16(this->env_, this->get(string),
Expand All @@ -47,7 +46,7 @@ class NAPI_String_Writer {
}

private:
static ::napi_value get(void* string) noexcept {
static ::napi_value get(void* string) {
return reinterpret_cast<::napi_value>(string);
}

Expand Down
31 changes: 14 additions & 17 deletions src/quick-lint-js/cli/arg-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
using namespace std::literals::string_view_literals;

namespace quick_lint_js {
Arg_Parser::Arg_Parser(int argc, char** argv) noexcept
: argc_(argc), argv_(argv) {
Arg_Parser::Arg_Parser(int argc, char** argv) : argc_(argc), argv_(argv) {
this->parse_current_arg();
}

const char* Arg_Parser::match_option_with_value(
std::string_view option_name) noexcept {
const char* Arg_Parser::match_option_with_value(std::string_view option_name) {
if (!this->option_.has_value() || !this->option_->arg_value) {
return nullptr;
}
Expand All @@ -29,7 +27,7 @@ const char* Arg_Parser::match_option_with_value(
return arg_value;
}

bool Arg_Parser::match_flag_shorthand(char option_shorthand) noexcept {
bool Arg_Parser::match_flag_shorthand(char option_shorthand) {
if (!this->option_.has_value()) {
return false;
}
Expand All @@ -41,9 +39,8 @@ bool Arg_Parser::match_flag_shorthand(char option_shorthand) noexcept {
return matches;
}

bool Arg_Parser::match_flag_option(
std::string_view full_option_name,
std::string_view partial_option_name) noexcept {
bool Arg_Parser::match_flag_option(std::string_view full_option_name,
std::string_view partial_option_name) {
if (!this->option_.has_value()) {
return false;
}
Expand All @@ -55,31 +52,31 @@ bool Arg_Parser::match_flag_option(
return matches;
}

bool Arg_Parser::match_flag_option(
char option_shorthand, std::string_view full_option_name,
std::string_view partial_option_name) noexcept {
bool Arg_Parser::match_flag_option(char option_shorthand,
std::string_view full_option_name,
std::string_view partial_option_name) {
return this->match_flag_option(full_option_name, partial_option_name) ||
this->match_flag_shorthand(option_shorthand);
}

const char* Arg_Parser::match_argument() noexcept {
const char* Arg_Parser::match_argument() {
if (this->option_.has_value()) {
return nullptr;
}
return this->match_anything();
}

const char* Arg_Parser::match_anything() noexcept {
const char* Arg_Parser::match_anything() {
const char* anything = this->current_arg();
this->advance(1);
return anything;
}

bool Arg_Parser::done() const noexcept {
bool Arg_Parser::done() const {
return this->current_arg_index_ >= this->argc_;
}

void Arg_Parser::parse_current_arg() noexcept {
void Arg_Parser::parse_current_arg() {
if (this->done()) {
return;
}
Expand Down Expand Up @@ -113,12 +110,12 @@ void Arg_Parser::parse_current_arg() noexcept {
}
}

void Arg_Parser::advance(int count) noexcept {
void Arg_Parser::advance(int count) {
this->current_arg_index_ += count;
this->parse_current_arg();
}

const char* Arg_Parser::current_arg() noexcept {
const char* Arg_Parser::current_arg() {
QLJS_ASSERT(this->current_arg_index_ < this->argc_);
return this->argv_[this->current_arg_index_];
}
Expand Down
22 changes: 11 additions & 11 deletions src/quick-lint-js/cli/arg-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,38 @@ namespace quick_lint_js {

class Arg_Parser {
public:
explicit Arg_Parser(int argc, char** argv) noexcept;
explicit Arg_Parser(int argc, char** argv);

Arg_Parser(const Arg_Parser&) = delete;
Arg_Parser& operator=(const Arg_Parser&) = delete;

const char* match_option_with_value(std::string_view option_name) noexcept;
const char* match_option_with_value(std::string_view option_name);

bool match_flag_shorthand(char option_shorthand) noexcept;
bool match_flag_shorthand(char option_shorthand);

bool match_flag_option(std::string_view full_option_name,
std::string_view partial_option_name) noexcept;
std::string_view partial_option_name);

// Equivalent to:
//
// this->match_flag_option(full_option_name, partial_option_name)
// || this->match_flag_shorthand(option_shorthand)
bool match_flag_option(char option_shorthand,
std::string_view full_option_name,
std::string_view partial_option_name) noexcept;
std::string_view partial_option_name);

const char* match_argument() noexcept;
const char* match_argument();

const char* match_anything() noexcept;
const char* match_anything();

bool done() const noexcept;
bool done() const;

private:
void parse_current_arg() noexcept;
void parse_current_arg();

void advance(int count) noexcept;
void advance(int count);

const char* current_arg() noexcept;
const char* current_arg();

struct Option {
std::string_view arg_key;
Expand Down
18 changes: 7 additions & 11 deletions src/quick-lint-js/cli/cli-location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@
#include <quick-lint-js/util/narrow-cast.h>

namespace quick_lint_js {
CLI_Source_Position CLI_Source_Range::begin() const noexcept {
return this->begin_;
}
CLI_Source_Position CLI_Source_Range::begin() const { return this->begin_; }

CLI_Source_Position CLI_Source_Range::end() const noexcept {
return this->end_;
}
CLI_Source_Position CLI_Source_Range::end() const { return this->end_; }

CLI_Locator::CLI_Locator(Padded_String_View input) noexcept : input_(input) {}
CLI_Locator::CLI_Locator(Padded_String_View input) : input_(input) {}

CLI_Source_Range CLI_Locator::range(Source_Code_Span span) const {
CLI_Source_Position begin = this->position(span.begin());
CLI_Source_Position end = this->position(span.end());
return CLI_Source_Range(begin, end);
}

CLI_Source_Position CLI_Locator::position(const Char8 *source) const noexcept {
CLI_Source_Position CLI_Locator::position(const Char8 *source) const {
CLI_Source_Position::Offset_Type offset = this->offset(source);
CLI_Source_Position::Line_Number_Type line_number =
this->find_line_at_offset(offset);
Expand Down Expand Up @@ -79,15 +75,15 @@ CLI_Source_Position::Line_Number_Type CLI_Locator::find_line_at_offset(
1;
}

CLI_Source_Position::Offset_Type CLI_Locator::offset(const Char8 *source) const
noexcept {
CLI_Source_Position::Offset_Type CLI_Locator::offset(
const Char8 *source) const {
return narrow_cast<CLI_Source_Position::Offset_Type>(source -
this->input_.data());
}

CLI_Source_Position CLI_Locator::position(
CLI_Source_Position::Line_Number_Type line_number,
CLI_Source_Position::Offset_Type offset) const noexcept {
CLI_Source_Position::Offset_Type offset) const {
CLI_Source_Position::Offset_Type beginning_of_line_offset =
this->offset_of_lines_[narrow_cast<std::size_t>(line_number - 1)];
int column_number = narrow_cast<int>(offset - beginning_of_line_offset) + 1;
Expand Down
23 changes: 11 additions & 12 deletions src/quick-lint-js/cli/cli-location.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ struct CLI_Source_Position {
int column_number;
Offset_Type offset;

bool operator==(const CLI_Source_Position& other) const noexcept {
bool operator==(const CLI_Source_Position& other) const {
return this->line_number == other.line_number &&
this->column_number == other.column_number &&
this->offset == other.offset;
}

bool operator!=(const CLI_Source_Position& other) const noexcept {
bool operator!=(const CLI_Source_Position& other) const {
return !(*this == other);
}
};
Expand All @@ -37,15 +37,14 @@ class CLI_Source_Range {
public:
using Offset = CLI_Source_Position::Offset_Type;

explicit CLI_Source_Range(CLI_Source_Position begin,
CLI_Source_Position end) noexcept
explicit CLI_Source_Range(CLI_Source_Position begin, CLI_Source_Position end)
: begin_(begin), end_(end) {}

Offset begin_offset() const noexcept { return this->begin_.offset; }
CLI_Source_Position begin() const noexcept;
Offset begin_offset() const { return this->begin_.offset; }
CLI_Source_Position begin() const;

Offset end_offset() const noexcept { return this->end_.offset; }
CLI_Source_Position end() const noexcept;
Offset end_offset() const { return this->end_.offset; }
CLI_Source_Position end() const;

private:
CLI_Source_Position begin_;
Expand All @@ -54,22 +53,22 @@ class CLI_Source_Range {

class CLI_Locator {
public:
explicit CLI_Locator(Padded_String_View input) noexcept;
explicit CLI_Locator(Padded_String_View input);

CLI_Source_Range range(Source_Code_Span) const;
CLI_Source_Position position(const Char8*) const noexcept;
CLI_Source_Position position(const Char8*) const;

private:
void cache_offsets_of_lines() const;

CLI_Source_Position::Line_Number_Type find_line_at_offset(
CLI_Source_Position::Offset_Type offset) const;

CLI_Source_Position::Offset_Type offset(const Char8*) const noexcept;
CLI_Source_Position::Offset_Type offset(const Char8*) const;

CLI_Source_Position position(
CLI_Source_Position::Line_Number_Type line_number,
CLI_Source_Position::Offset_Type offset) const noexcept;
CLI_Source_Position::Offset_Type offset) const;

Padded_String_View input_;
mutable std::vector<CLI_Source_Position::Offset_Type> offset_of_lines_;
Expand Down
18 changes: 6 additions & 12 deletions src/quick-lint-js/cli/emacs-location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,33 @@
#include <quick-lint-js/util/utf-8.h>

namespace quick_lint_js {
Emacs_Source_Position Emacs_Source_Range::begin() const noexcept {
return this->begin_;
}
Emacs_Source_Position Emacs_Source_Range::begin() const { return this->begin_; }

Emacs_Source_Position Emacs_Source_Range::end() const noexcept {
return this->end_;
}
Emacs_Source_Position Emacs_Source_Range::end() const { return this->end_; }

Emacs_Locator::Emacs_Locator(Padded_String_View input) noexcept
: input_(input) {}
Emacs_Locator::Emacs_Locator(Padded_String_View input) : input_(input) {}

Emacs_Source_Range Emacs_Locator::range(Source_Code_Span span) const {
Emacs_Source_Position begin = this->position(span.begin());
Emacs_Source_Position end = this->position(span.end());
return Emacs_Source_Range(begin, end);
}

Emacs_Source_Position Emacs_Locator::position(const Char8 *source) const
noexcept {
Emacs_Source_Position Emacs_Locator::position(const Char8 *source) const {
Emacs_Source_Position::Offset_Type offset = this->offset(source);
// Emacs point starts at 1
return this->position(offset + 1);
}

Emacs_Source_Position::Offset_Type Emacs_Locator::offset(
const Char8 *source) const noexcept {
const Char8 *source) const {
std::size_t offset = narrow_cast<std::size_t>(source - this->input_.data());
return narrow_cast<Emacs_Source_Position::Offset_Type>(
count_utf_8_characters(this->input_, offset));
}

Emacs_Source_Position Emacs_Locator::position(
Emacs_Source_Position::Offset_Type offset) const noexcept {
Emacs_Source_Position::Offset_Type offset) const {
return Emacs_Source_Position{offset};
}
}
Expand Down
Loading

0 comments on commit 210f327

Please sign in to comment.