Fix compiles on VS2017 and GCC
VS2017 took issue with treating size_t and uint32_t the same. It also
couldn't find various alphanumeric is* functions without the <cctype>
header. Gcc complainted about a variable potentially used uninitialized.
Change-Id: I452b68c6597bae254f32e5a350656e65c8934b6e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18901
Reviewed-by: dan sinclair <dsinclair@google.com>
diff --git a/src/ast/import.cc b/src/ast/import.cc
index aa7aff8..536a90a 100644
--- a/src/ast/import.cc
+++ b/src/ast/import.cc
@@ -14,6 +14,8 @@
#include "src/ast/import.h"
+#include <cctype>
+
namespace tint {
namespace ast {
diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc
index 903f9b1..1eec4e2 100644
--- a/src/reader/wgsl/lexer.cc
+++ b/src/reader/wgsl/lexer.cc
@@ -18,6 +18,7 @@
#include <errno.h>
#include <stdlib.h>
+#include <cctype>
#include <limits>
namespace tint {
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 61aeeab..5916e70 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -808,7 +808,7 @@
ast::type::Type* ParserImpl::type_decl_vector(Token t) {
next(); // Consume the peek
- size_t count = 2;
+ uint32_t count = 2;
if (t.IsVec3())
count = 3;
else if (t.IsVec4())
@@ -856,7 +856,7 @@
}
t = next();
- size_t size = 0;
+ uint32_t size = 0;
if (t.IsComma()) {
t = next();
if (!t.IsIntLiteral()) {
@@ -867,7 +867,7 @@
set_error(t, "invalid size for array declaration");
return nullptr;
}
- size = static_cast<size_t>(t.to_i32());
+ size = static_cast<uint32_t>(t.to_i32());
t = next();
}
if (!t.IsGreaterThan()) {
@@ -882,8 +882,8 @@
ast::type::Type* ParserImpl::type_decl_matrix(Token t) {
next(); // Consume the peek
- size_t rows = 2;
- size_t columns = 2;
+ uint32_t rows = 2;
+ uint32_t columns = 2;
if (t.IsMat3x2() || t.IsMat3x3() || t.IsMat3x4()) {
rows = 3;
} else if (t.IsMat4x2() || t.IsMat4x3() || t.IsMat4x4()) {
@@ -1181,8 +1181,7 @@
return nullptr;
}
- return std::make_unique<ast::StructMemberOffsetDecoration>(
- static_cast<size_t>(val));
+ return std::make_unique<ast::StructMemberOffsetDecoration>(val);
}
// function_decl
diff --git a/src/scope_stack_test.cc b/src/scope_stack_test.cc
index 303f7a3..2f31292 100644
--- a/src/scope_stack_test.cc
+++ b/src/scope_stack_test.cc
@@ -37,7 +37,7 @@
ScopeStack<ast::Variable*> s;
s.set_global("var", &v);
- ast::Variable* v2;
+ ast::Variable* v2 = nullptr;
EXPECT_TRUE(s.get("var", &v2));
EXPECT_EQ(v2->name(), "my_var");
}