Fixed UTF-8 encoding issues on windows.
authorAndrew Woloszyn <awoloszyn@google.com>
Tue, 20 Oct 2015 13:12:32 +0000 (09:12 -0400)
committerDavid Neto <dneto@google.com>
Mon, 26 Oct 2015 16:55:33 +0000 (12:55 -0400)
Also cleaned up some warnings related to implicit size_t/uint64_t
conversions.

source/text_handler.cpp
source/validate_id.cpp
test/BinaryToText.Literal.cpp
test/TextLiteral.cpp
test/TextToBinary.Literal.cpp
test/UnitSPIRV.h

index 21308ae..c5ce633 100644 (file)
@@ -312,6 +312,7 @@ bool AssemblyContext::isStartOfNewInst() {
   if (::startsWithOp(text_, &startPosition)) return true;
   return false;
 }
+
 char AssemblyContext::peek() const {
   return text_->str[current_position_.index];
 }
@@ -319,8 +320,9 @@ char AssemblyContext::peek() const {
 bool AssemblyContext::hasText() const {
   return text_->length > current_position_.index;
 }
+
 std::string AssemblyContext::getWord() const {
-  size_t index = current_position_.index;
+  uint64_t index = current_position_.index;
   while (true) {
     switch (text_->str[index]) {
       case '\0':
index 83e19fa..b83abee 100644 (file)
@@ -238,7 +238,7 @@ bool idUsage::isValid<OpGroupDecorate>(const spv_instruction_t *inst,
                << inst->words[decorationGroupIndex]
                << "' is not a decoration group.";
            return false);
-  for (uint64_t targetIndex = 2; targetIndex < inst->words.size(); ++targetIndex) {
+  for (size_t targetIndex = 2; targetIndex < inst->words.size(); ++targetIndex) {
     auto target = find(inst->words[targetIndex]);
     spvCheck(!found(target), DIAG(targetIndex)
                                  << "OpGroupDecorate Target <id> '"
@@ -454,7 +454,7 @@ bool idUsage::isValid<OpTypeRuntimeArray>(const spv_instruction_t *inst,
 template <>
 bool idUsage::isValid<OpTypeStruct>(const spv_instruction_t *inst,
                                     const spv_opcode_desc) {
-  for (uint64_t memberTypeIndex = 2; memberTypeIndex < inst->words.size();
+  for (size_t memberTypeIndex = 2; memberTypeIndex < inst->words.size();
        ++memberTypeIndex) {
     auto memberType = find(inst->words[memberTypeIndex]);
     spvCheck(!found(memberType), DIAG(memberTypeIndex)
@@ -502,7 +502,7 @@ bool idUsage::isValid<OpTypeFunction>(const spv_instruction_t *inst,
                                  << inst->words[returnTypeIndex]
                                  << "' is not a type.";
            return false);
-  for (uint64_t paramTypeIndex = 3; paramTypeIndex < inst->words.size();
+  for (size_t paramTypeIndex = 3; paramTypeIndex < inst->words.size();
        ++paramTypeIndex) {
     auto paramType = find(inst->words[paramTypeIndex]);
     spvCheck(!found(paramType), DIAG(paramTypeIndex)
@@ -611,7 +611,7 @@ bool idUsage::isValid<OpConstantComposite>(const spv_instruction_t *inst,
           return false);
       auto componentType = find(resultType->second.inst->words[2]);
       spvCheck(!found(componentType), assert(0 && "Unreachable!"));
-      for (uint64_t constituentIndex = 3; constituentIndex < inst->words.size();
+      for (size_t constituentIndex = 3; constituentIndex < inst->words.size();
            constituentIndex++) {
         auto constituent = find(inst->words[constituentIndex]);
         spvCheck(!found(constituent), assert(0 && "Unreachable!"));
@@ -649,7 +649,7 @@ bool idUsage::isValid<OpConstantComposite>(const spv_instruction_t *inst,
       auto componentType = find(columnType->second.inst->words[2]);
       spvCheck(!found(componentType), assert(0 && "Unreachable!"));
 
-      for (uint64_t constituentIndex = 3; constituentIndex < inst->words.size();
+      for (size_t constituentIndex = 3; constituentIndex < inst->words.size();
            constituentIndex++) {
         auto constituent = find(inst->words[constituentIndex]);
         spvCheck(!found(constituent),
@@ -704,7 +704,7 @@ bool idUsage::isValid<OpConstantComposite>(const spv_instruction_t *inst,
                       "Result Type <id> '"
                    << resultType->second.id << "'s array length.";
                return false);
-      for (uint64_t constituentIndex = 3; constituentIndex < inst->words.size();
+      for (size_t constituentIndex = 3; constituentIndex < inst->words.size();
            constituentIndex++) {
         auto constituent = find(inst->words[constituentIndex]);
         spvCheck(!found(constituent),
@@ -841,7 +841,7 @@ bool idUsage::isValid<OpConstantNull>(const spv_instruction_t *inst,
                return false);
     } break;
     case OpTypeStruct: {
-      for (uint64_t elementIndex = 2;
+      for (size_t elementIndex = 2;
            elementIndex < resultType->second.inst->words.size(); ++elementIndex) {
         auto element = find(resultType->second.inst->words[elementIndex]);
         spvCheck(!found(element), assert(0 && "Unreachable!"));
@@ -1216,7 +1216,7 @@ bool idUsage::isValid<OpFunctionParameter>(const spv_instruction_t *inst,
            return false);
   auto function = inst - 1;
   // NOTE: Find OpFunction & ensure OpFunctionParameter is not out of place.
-  uint64_t paramIndex = 0;
+  size_t paramIndex = 0;
   while (firstInst != function) {
     spvCheck(OpFunction != function->opcode &&
                  OpFunctionParameter != function->opcode,
@@ -1284,7 +1284,7 @@ bool idUsage::isValid<OpFunctionCall>(const spv_instruction_t *inst,
           << "OpFunctionCall Function <id>'s parameter count does not match "
              "the argument count.";
       return false);
-  for (uint64_t argumentIndex = 4, paramIndex = 3;
+  for (size_t argumentIndex = 4, paramIndex = 3;
        argumentIndex < inst->words.size(); argumentIndex++, paramIndex++) {
     auto argument = find(inst->words[argumentIndex]);
     spvCheck(!found(argument), DIAG(argumentIndex)
index b876027..d2604f3 100644 (file)
@@ -59,7 +59,7 @@ INSTANTIATE_TEST_CASE_P(
         "OpName %1 \"\n\n\nfoo\nbar\"\n",         // multiple newlines
         "OpName %1 \"\\\"foo\nbar\\\"\"\n",       // escaped quote
         "OpName %1 \"\\\\foo\nbar\\\\\"\n",       // escaped backslash
-        "OpName %1 \"\U00E4BAB2\"\n",             // UTF-8
+        "OpName %1 \"xE4\xBA\xB2\"\n",             // UTF-8
     }));
 // clang-format on
 
@@ -79,7 +79,7 @@ INSTANTIATE_TEST_CASE_P(
     ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
       {"OpName %1 \"\\foo\"\n", "OpName %1 \"foo\"\n"}, // Escape f
       {"OpName %1 \"\\\nfoo\"\n", "OpName %1 \"\nfoo\"\n"}, // Escape newline
-      {"OpName %1 \"\\\U00E4BAB2\"\n", "OpName %1 \"\U00E4BAB2\"\n"}, // Escape utf-8
+      {"OpName %1 \"\\\xE4\xBA\xB2\"\n", "OpName %1 \"\xE4\xBA\xB2\"\n"}, // Escape utf-8
     }));
 // clang-format on
 
index de328bc..c833bfe 100644 (file)
@@ -128,10 +128,10 @@ INSTANTIATE_TEST_CASE_P(
       {R"("\\")", "\\"},
       {"\"\\foo\nbar\"", "foo\nbar"},
       {"\"\\foo\\\nbar\"", "foo\nbar"},
-      {"\"\U00E4BAB2\"", "\U00E4BAB2"},
-      {"\"\\\U00E4BAB2\"", "\U00E4BAB2"},
-      {"\"this \\\" and this \\\\ and \\\U00E4BAB2\"",
-        "this \" and this \\ and \U00E4BAB2"}
+      {"\"\xE4\xBA\xB2\"", "\xE4\xBA\xB2"},
+      {"\"\\\xE4\xBA\xB2\"", "\xE4\xBA\xB2"},
+      {"\"this \\\" and this \\\\ and \\\xE4\xBA\xB2\"",
+        "this \" and this \\ and \xE4\xBA\xB2"}
     }));
 
 TEST(TextLiteral, StringTooLong) {
index 2402a1f..9beaf79 100644 (file)
@@ -95,7 +95,7 @@ TEST_F(TextToBinaryTest, LiteralStringUTF8LongEncodings) {
       spvtest::MakeLongUTF8String(65533)
       // The following single character has a 3 byte encoding,
       // which fits snugly against the terminating null.
-      + "\u8000";
+      + "\xe8\x80\x80";
 
   // These strings will overflow any instruction with 0 or 1 other
   // arguments, respectively.
index 7180a3d..59f40cf 100644 (file)
@@ -196,7 +196,7 @@ class EnumCase {
 // each of which has a 4-byte UTF-8 encoding.
 inline std::string MakeLongUTF8String(size_t num_4_byte_chars) {
   // An example of a longest valid UTF-8 character.
-  const std::string earth_africa("\U0001F30D");
+  const std::string earth_africa("\xF0\x9F\x8C\x8D");
   EXPECT_EQ(4, earth_africa.size());
   std::string result;
   result.reserve(num_4_byte_chars * 4);