Skip to content

Commit

Permalink
chore: Silence warnings when mixing signed and unsigned integers
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoraggi committed Dec 13, 2024
1 parent 2464011 commit ccabd01
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 109 deletions.
4 changes: 2 additions & 2 deletions packages/cxx-gen-ast/src/gen_ast_decoder_cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function gen_ast_decoder_cc({
const className = makeClassName(m.type);
emit(` if (node->${snakeName}()) {`);
emit(` auto* inserter = &ast->${m.name};`);
emit(` for (std::size_t i = 0; i < node->${snakeName}()->size();`);
emit(` for (std::uint32_t i = 0; i < node->${snakeName}()->size();`);
emit(` ++i) {`);
emit(` *inserter = new (pool_) List(decode${className}(`);
emit(` node->${snakeName}()->Get(i),`);
Expand All @@ -100,7 +100,7 @@ export function gen_ast_decoder_cc({
const className = makeClassName(m.type);
emit(` if (node->${snakeName}()) {`);
emit(` auto* inserter = &ast->${m.name};`);
emit(` for (std::size_t i = 0; i < node->${snakeName}()->size();`);
emit(` for (std::uint32_t i = 0; i < node->${snakeName}()->size();`);
emit(` ++i) {`);
emit(` *inserter = new (pool_) List(decode${className}(`);
emit(` node->${snakeName}()->Get(i)));`);
Expand Down
8 changes: 4 additions & 4 deletions src/lsp/cxx/lsp/lsp_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ void Server::operator()(DidChangeTextDocumentNotification notification) {
} visit{text};

auto contentChanges = notification.params().contentChanges();
const auto contentChangeCount = contentChanges.size();
const auto contentChangeCount = int(contentChanges.size());

for (std::size_t i = 0; i < contentChangeCount; ++i) {
for (int i = 0; i < contentChangeCount; ++i) {
std::visit(visit, contentChanges.at(i));
}

Expand Down Expand Up @@ -508,8 +508,8 @@ void Server::operator()(CompletionRequest request) {
auto completionItems = response.result<Vector<CompletionItem>>();

// cxx expects 1-based line and column numbers
cxxDocument->codeCompletionAt(std::move(source), line + 1, column + 1,
completionItems);
cxxDocument->codeCompletionAt(std::move(source), std::uint32_t(line + 1),
std::uint32_t(column + 1), completionItems);

sendToClient(response);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/cxx/lsp/lsp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Server {
struct Text {
std::string value;
std::vector<std::size_t> lineStartOffsets;
int version = 0;
std::int64_t version = 0;

auto offsetAt(std::size_t line, std::size_t column) const -> std::size_t;

Expand Down
181 changes: 92 additions & 89 deletions src/parser/cxx/flatbuffers/ast_decoder.cc

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/parser/cxx/lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ auto Lexer::readToken() -> TokenKind {
const auto hasMoreChars = skipSpaces();

tokenIsClean_ = true;
tokenPos_ = pos_ - cbegin(source_);
tokenPos_ = int(pos_ - cbegin(source_));
text_.clear();

if (!hasMoreChars) return TokenKind::T_EOF_SYMBOL;
Expand Down Expand Up @@ -231,16 +231,16 @@ auto Lexer::readToken() -> TokenKind {

auto lookat_delimiter = [&]() -> bool {
if (LA() != ')') return false;
if (LA(delimiter.size() + 1) != '"') return false;
if (LA(int(delimiter.size() + 1)) != '"') return false;
for (std::size_t i = 0; i < delimiter.size(); ++i) {
if (LA(i + 1) != delimiter[i]) return false;
if (LA(int(i + 1)) != delimiter[i]) return false;
}
return true;
};

while (pos_ != end_) {
if (lookat_delimiter()) {
consume(delimiter.size() + 2);
consume(int(delimiter.size() + 2));
break;
}
consume();
Expand Down
2 changes: 1 addition & 1 deletion src/parser/cxx/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Lexer {
[[nodiscard]] auto tokenPos() const -> int { return tokenPos_; }

[[nodiscard]] auto tokenLength() const -> std::uint32_t {
return (pos_ - cbegin(source_)) - tokenPos_;
return std::uint32_t((pos_ - cbegin(source_)) - tokenPos_);
}

[[nodiscard]] auto tokenIsClean() const -> bool { return tokenIsClean_; }
Expand Down
14 changes: 7 additions & 7 deletions src/parser/cxx/preprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ struct Preprocessor::Private {
[[nodiscard]] auto unaryExpression(TokList *&ts) -> long;
[[nodiscard]] auto primaryExpression(TokList *&ts) -> long;

[[nodiscard]] auto parseArguments(TokList *ts, int formalCount,
[[nodiscard]] auto parseArguments(TokList *ts, std::size_t formalCount,
bool ignoreComma = false)
-> std::tuple<std::vector<TokRange>, TokList *, const Hideset *>;

Expand All @@ -1241,8 +1241,8 @@ struct Preprocessor::ParseArguments {
Private &d;

template <std::sentinel_for<TokIterator> S>
auto operator()(TokIterator it, S last, int formalCount, bool ignoreComma)
-> std::optional<Result> {
auto operator()(TokIterator it, S last, std::size_t formalCount,
bool ignoreComma) -> std::optional<Result> {
if (!cxx::lookat(it, last, TokenKind::T_LPAREN)) {
cxx_runtime_error("expected '('");
return std::nullopt;
Expand Down Expand Up @@ -1381,7 +1381,7 @@ void PendingFileContent::setContent(std::optional<std::string> content) const {
sourceFile->headerProtection = d->checkHeaderProtection(sourceFile->tokens);

if (sourceFile->headerProtection) {
sourceFile->headerProtectionLevel = d->evaluating_.size();
sourceFile->headerProtectionLevel = int(d->evaluating_.size());

d->ifndefProtectedFiles_.insert_or_assign(
sourceFile->fileName, sourceFile->headerProtection->tok->text);
Expand Down Expand Up @@ -1871,8 +1871,8 @@ auto Preprocessor::Private::parseDirective(SourceFile *source, TokList *start)

dependencies_.clear();

const auto directiveKind = classifyDirective(directive->tok->text.data(),
directive->tok->text.length());
const auto directiveKind = classifyDirective(
directive->tok->text.data(), int(directive->tok->text.length()));

TokList *ts = directive->next;

Expand Down Expand Up @@ -2706,7 +2706,7 @@ auto Preprocessor::Private::instantiate(TokList *ts, const Hideset *hideset)
return ts;
}

auto Preprocessor::Private::parseArguments(TokList *ts, int formalCount,
auto Preprocessor::Private::parseArguments(TokList *ts, std::size_t formalCount,
bool ignoreComma)
-> std::tuple<std::vector<TokRange>, TokList *, const Hideset *> {
assert(lookat(ts, TokenKind::T_IDENTIFIER, TokenKind::T_LPAREN));
Expand Down
2 changes: 1 addition & 1 deletion src/parser/cxx/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class ClassSymbol final : public ScopedSymbol {
std::vector<FunctionSymbol*> constructors_;
std::unique_ptr<TemplateInfo<ClassSymbol>> templateInfo_;
ClassSymbol* templateClass_ = nullptr;
int templateSepcializationIndex_ = 0;
std::size_t templateSepcializationIndex_ = 0;
std::size_t sizeInBytes_ = 0;
union {
std::uint32_t flags_{};
Expand Down

0 comments on commit ccabd01

Please sign in to comment.