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>
This commit is contained in:
Greg Roth 2020-04-06 17:16:56 +00:00 committed by dan sinclair
parent 2c18339745
commit 8229360312
4 changed files with 10 additions and 8 deletions

View File

@ -14,6 +14,8 @@
#include "src/ast/import.h" #include "src/ast/import.h"
#include <cctype>
namespace tint { namespace tint {
namespace ast { namespace ast {

View File

@ -18,6 +18,7 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <cctype>
#include <limits> #include <limits>
namespace tint { namespace tint {

View File

@ -808,7 +808,7 @@ ast::type::Type* ParserImpl::type_decl_pointer(Token t) {
ast::type::Type* ParserImpl::type_decl_vector(Token t) { ast::type::Type* ParserImpl::type_decl_vector(Token t) {
next(); // Consume the peek next(); // Consume the peek
size_t count = 2; uint32_t count = 2;
if (t.IsVec3()) if (t.IsVec3())
count = 3; count = 3;
else if (t.IsVec4()) else if (t.IsVec4())
@ -856,7 +856,7 @@ ast::type::Type* ParserImpl::type_decl_array(Token t) {
} }
t = next(); t = next();
size_t size = 0; uint32_t size = 0;
if (t.IsComma()) { if (t.IsComma()) {
t = next(); t = next();
if (!t.IsIntLiteral()) { if (!t.IsIntLiteral()) {
@ -867,7 +867,7 @@ ast::type::Type* ParserImpl::type_decl_array(Token t) {
set_error(t, "invalid size for array declaration"); set_error(t, "invalid size for array declaration");
return nullptr; return nullptr;
} }
size = static_cast<size_t>(t.to_i32()); size = static_cast<uint32_t>(t.to_i32());
t = next(); t = next();
} }
if (!t.IsGreaterThan()) { if (!t.IsGreaterThan()) {
@ -882,8 +882,8 @@ ast::type::Type* ParserImpl::type_decl_array(Token t) {
ast::type::Type* ParserImpl::type_decl_matrix(Token t) { ast::type::Type* ParserImpl::type_decl_matrix(Token t) {
next(); // Consume the peek next(); // Consume the peek
size_t rows = 2; uint32_t rows = 2;
size_t columns = 2; uint32_t columns = 2;
if (t.IsMat3x2() || t.IsMat3x3() || t.IsMat3x4()) { if (t.IsMat3x2() || t.IsMat3x3() || t.IsMat3x4()) {
rows = 3; rows = 3;
} else if (t.IsMat4x2() || t.IsMat4x3() || t.IsMat4x4()) { } else if (t.IsMat4x2() || t.IsMat4x3() || t.IsMat4x4()) {
@ -1181,8 +1181,7 @@ ParserImpl::struct_member_decoration() {
return nullptr; return nullptr;
} }
return std::make_unique<ast::StructMemberOffsetDecoration>( return std::make_unique<ast::StructMemberOffsetDecoration>(val);
static_cast<size_t>(val));
} }
// function_decl // function_decl

View File

@ -37,7 +37,7 @@ TEST_F(ScopeStackTest, Global_SetWithPointer) {
ScopeStack<ast::Variable*> s; ScopeStack<ast::Variable*> s;
s.set_global("var", &v); s.set_global("var", &v);
ast::Variable* v2; ast::Variable* v2 = nullptr;
EXPECT_TRUE(s.get("var", &v2)); EXPECT_TRUE(s.get("var", &v2));
EXPECT_EQ(v2->name(), "my_var"); EXPECT_EQ(v2->name(), "my_var");
} }