Skip to content

Commit ccabd01

Browse files
committed
chore: Silence warnings when mixing signed and unsigned integers
1 parent 2464011 commit ccabd01

File tree

8 files changed

+112
-109
lines changed

8 files changed

+112
-109
lines changed

packages/cxx-gen-ast/src/gen_ast_decoder_cc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function gen_ast_decoder_cc({
8888
const className = makeClassName(m.type);
8989
emit(` if (node->${snakeName}()) {`);
9090
emit(` auto* inserter = &ast->${m.name};`);
91-
emit(` for (std::size_t i = 0; i < node->${snakeName}()->size();`);
91+
emit(` for (std::uint32_t i = 0; i < node->${snakeName}()->size();`);
9292
emit(` ++i) {`);
9393
emit(` *inserter = new (pool_) List(decode${className}(`);
9494
emit(` node->${snakeName}()->Get(i),`);
@@ -100,7 +100,7 @@ export function gen_ast_decoder_cc({
100100
const className = makeClassName(m.type);
101101
emit(` if (node->${snakeName}()) {`);
102102
emit(` auto* inserter = &ast->${m.name};`);
103-
emit(` for (std::size_t i = 0; i < node->${snakeName}()->size();`);
103+
emit(` for (std::uint32_t i = 0; i < node->${snakeName}()->size();`);
104104
emit(` ++i) {`);
105105
emit(` *inserter = new (pool_) List(decode${className}(`);
106106
emit(` node->${snakeName}()->Get(i)));`);

src/lsp/cxx/lsp/lsp_server.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@ void Server::operator()(DidChangeTextDocumentNotification notification) {
444444
} visit{text};
445445

446446
auto contentChanges = notification.params().contentChanges();
447-
const auto contentChangeCount = contentChanges.size();
447+
const auto contentChangeCount = int(contentChanges.size());
448448

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

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

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

514514
sendToClient(response);
515515
});

src/lsp/cxx/lsp/lsp_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Server {
9494
struct Text {
9595
std::string value;
9696
std::vector<std::size_t> lineStartOffsets;
97-
int version = 0;
97+
std::int64_t version = 0;
9898

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

src/parser/cxx/flatbuffers/ast_decoder.cc

Lines changed: 92 additions & 89 deletions
Large diffs are not rendered by default.

src/parser/cxx/lexer.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ auto Lexer::readToken() -> TokenKind {
142142
const auto hasMoreChars = skipSpaces();
143143

144144
tokenIsClean_ = true;
145-
tokenPos_ = pos_ - cbegin(source_);
145+
tokenPos_ = int(pos_ - cbegin(source_));
146146
text_.clear();
147147

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

232232
auto lookat_delimiter = [&]() -> bool {
233233
if (LA() != ')') return false;
234-
if (LA(delimiter.size() + 1) != '"') return false;
234+
if (LA(int(delimiter.size() + 1)) != '"') return false;
235235
for (std::size_t i = 0; i < delimiter.size(); ++i) {
236-
if (LA(i + 1) != delimiter[i]) return false;
236+
if (LA(int(i + 1)) != delimiter[i]) return false;
237237
}
238238
return true;
239239
};
240240

241241
while (pos_ != end_) {
242242
if (lookat_delimiter()) {
243-
consume(delimiter.size() + 2);
243+
consume(int(delimiter.size() + 2));
244244
break;
245245
}
246246
consume();

src/parser/cxx/lexer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Lexer {
6060
[[nodiscard]] auto tokenPos() const -> int { return tokenPos_; }
6161

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

6666
[[nodiscard]] auto tokenIsClean() const -> bool { return tokenIsClean_; }

src/parser/cxx/preprocessor.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ struct Preprocessor::Private {
12181218
[[nodiscard]] auto unaryExpression(TokList *&ts) -> long;
12191219
[[nodiscard]] auto primaryExpression(TokList *&ts) -> long;
12201220

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

@@ -1241,8 +1241,8 @@ struct Preprocessor::ParseArguments {
12411241
Private &d;
12421242

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

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

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

18721872
dependencies_.clear();
18731873

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

18771877
TokList *ts = directive->next;
18781878

@@ -2706,7 +2706,7 @@ auto Preprocessor::Private::instantiate(TokList *ts, const Hideset *hideset)
27062706
return ts;
27072707
}
27082708

2709-
auto Preprocessor::Private::parseArguments(TokList *ts, int formalCount,
2709+
auto Preprocessor::Private::parseArguments(TokList *ts, std::size_t formalCount,
27102710
bool ignoreComma)
27112711
-> std::tuple<std::vector<TokRange>, TokList *, const Hideset *> {
27122712
assert(lookat(ts, TokenKind::T_IDENTIFIER, TokenKind::T_LPAREN));

src/parser/cxx/symbols.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class ClassSymbol final : public ScopedSymbol {
304304
std::vector<FunctionSymbol*> constructors_;
305305
std::unique_ptr<TemplateInfo<ClassSymbol>> templateInfo_;
306306
ClassSymbol* templateClass_ = nullptr;
307-
int templateSepcializationIndex_ = 0;
307+
std::size_t templateSepcializationIndex_ = 0;
308308
std::size_t sizeInBytes_ = 0;
309309
union {
310310
std::uint32_t flags_{};

0 commit comments

Comments
 (0)