| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Append a trailing "#" to indicate that the name should be decorated to | 94 // Append a trailing "#" to indicate that the name should be decorated to |
| 95 // avoid collision with other names. | 95 // avoid collision with other names. |
| 96 field_name += "#"; | 96 field_name += "#"; |
| 97 } | 97 } |
| 98 return field_name; | 98 return field_name; |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 } // namespace | 102 } // namespace |
| 103 | 103 |
| 104 void PrintGeneratedAnnotation(io::Printer* printer, char delimiter, | |
| 105 const string& annotation_file) { | |
| 106 if (annotation_file.empty()) { | |
| 107 return; | |
| 108 } | |
| 109 string ptemplate = | |
| 110 "@javax.annotation.Generated(value=\"protoc\", comments=\"annotations:"; | |
| 111 ptemplate.push_back(delimiter); | |
| 112 ptemplate.append("annotation_file"); | |
| 113 ptemplate.push_back(delimiter); | |
| 114 ptemplate.append("\")\n"); | |
| 115 printer->Print(ptemplate.c_str(), "annotation_file", annotation_file); | |
| 116 } | |
| 117 | |
| 118 string UnderscoresToCamelCase(const string& input, bool cap_next_letter) { | 104 string UnderscoresToCamelCase(const string& input, bool cap_next_letter) { |
| 119 string result; | 105 string result; |
| 120 // Note: I distrust ctype.h due to locales. | 106 // Note: I distrust ctype.h due to locales. |
| 121 for (int i = 0; i < input.size(); i++) { | 107 for (int i = 0; i < input.size(); i++) { |
| 122 if ('a' <= input[i] && input[i] <= 'z') { | 108 if ('a' <= input[i] && input[i] <= 'z') { |
| 123 if (cap_next_letter) { | 109 if (cap_next_letter) { |
| 124 result += input[i] + ('A' - 'a'); | 110 result += input[i] + ('A' - 'a'); |
| 125 } else { | 111 } else { |
| 126 result += input[i]; | 112 result += input[i]; |
| 127 } | 113 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 case JAVATYPE_MESSAGE: return NULL; | 339 case JAVATYPE_MESSAGE: return NULL; |
| 354 | 340 |
| 355 // No default because we want the compiler to complain if any new | 341 // No default because we want the compiler to complain if any new |
| 356 // JavaTypes are added. | 342 // JavaTypes are added. |
| 357 } | 343 } |
| 358 | 344 |
| 359 GOOGLE_LOG(FATAL) << "Can't get here."; | 345 GOOGLE_LOG(FATAL) << "Can't get here."; |
| 360 return NULL; | 346 return NULL; |
| 361 } | 347 } |
| 362 | 348 |
| 363 | |
| 364 const char* FieldTypeName(FieldDescriptor::Type field_type) { | 349 const char* FieldTypeName(FieldDescriptor::Type field_type) { |
| 365 switch (field_type) { | 350 switch (field_type) { |
| 366 case FieldDescriptor::TYPE_INT32 : return "INT32"; | 351 case FieldDescriptor::TYPE_INT32 : return "INT32"; |
| 367 case FieldDescriptor::TYPE_UINT32 : return "UINT32"; | 352 case FieldDescriptor::TYPE_UINT32 : return "UINT32"; |
| 368 case FieldDescriptor::TYPE_SINT32 : return "SINT32"; | 353 case FieldDescriptor::TYPE_SINT32 : return "SINT32"; |
| 369 case FieldDescriptor::TYPE_FIXED32 : return "FIXED32"; | 354 case FieldDescriptor::TYPE_FIXED32 : return "FIXED32"; |
| 370 case FieldDescriptor::TYPE_SFIXED32: return "SFIXED32"; | 355 case FieldDescriptor::TYPE_SFIXED32: return "SFIXED32"; |
| 371 case FieldDescriptor::TYPE_INT64 : return "INT64"; | 356 case FieldDescriptor::TYPE_INT64 : return "INT64"; |
| 372 case FieldDescriptor::TYPE_UINT64 : return "UINT64"; | 357 case FieldDescriptor::TYPE_UINT64 : return "UINT64"; |
| 373 case FieldDescriptor::TYPE_SINT64 : return "SINT64"; | 358 case FieldDescriptor::TYPE_SINT64 : return "SINT64"; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 case FieldDescriptor::CPPTYPE_UINT32: | 394 case FieldDescriptor::CPPTYPE_UINT32: |
| 410 // Need to print as a signed int since Java has no unsigned. | 395 // Need to print as a signed int since Java has no unsigned. |
| 411 return SimpleItoa(static_cast<int32>(field->default_value_uint32())); | 396 return SimpleItoa(static_cast<int32>(field->default_value_uint32())); |
| 412 case FieldDescriptor::CPPTYPE_INT64: | 397 case FieldDescriptor::CPPTYPE_INT64: |
| 413 return SimpleItoa(field->default_value_int64()) + "L"; | 398 return SimpleItoa(field->default_value_int64()) + "L"; |
| 414 case FieldDescriptor::CPPTYPE_UINT64: | 399 case FieldDescriptor::CPPTYPE_UINT64: |
| 415 return SimpleItoa(static_cast<int64>(field->default_value_uint64())) + | 400 return SimpleItoa(static_cast<int64>(field->default_value_uint64())) + |
| 416 "L"; | 401 "L"; |
| 417 case FieldDescriptor::CPPTYPE_DOUBLE: { | 402 case FieldDescriptor::CPPTYPE_DOUBLE: { |
| 418 double value = field->default_value_double(); | 403 double value = field->default_value_double(); |
| 419 if (value == std::numeric_limits<double>::infinity()) { | 404 if (value == numeric_limits<double>::infinity()) { |
| 420 return "Double.POSITIVE_INFINITY"; | 405 return "Double.POSITIVE_INFINITY"; |
| 421 } else if (value == -std::numeric_limits<double>::infinity()) { | 406 } else if (value == -numeric_limits<double>::infinity()) { |
| 422 return "Double.NEGATIVE_INFINITY"; | 407 return "Double.NEGATIVE_INFINITY"; |
| 423 } else if (value != value) { | 408 } else if (value != value) { |
| 424 return "Double.NaN"; | 409 return "Double.NaN"; |
| 425 } else { | 410 } else { |
| 426 return SimpleDtoa(value) + "D"; | 411 return SimpleDtoa(value) + "D"; |
| 427 } | 412 } |
| 428 } | 413 } |
| 429 case FieldDescriptor::CPPTYPE_FLOAT: { | 414 case FieldDescriptor::CPPTYPE_FLOAT: { |
| 430 float value = field->default_value_float(); | 415 float value = field->default_value_float(); |
| 431 if (value == std::numeric_limits<float>::infinity()) { | 416 if (value == numeric_limits<float>::infinity()) { |
| 432 return "Float.POSITIVE_INFINITY"; | 417 return "Float.POSITIVE_INFINITY"; |
| 433 } else if (value == -std::numeric_limits<float>::infinity()) { | 418 } else if (value == -numeric_limits<float>::infinity()) { |
| 434 return "Float.NEGATIVE_INFINITY"; | 419 return "Float.NEGATIVE_INFINITY"; |
| 435 } else if (value != value) { | 420 } else if (value != value) { |
| 436 return "Float.NaN"; | 421 return "Float.NaN"; |
| 437 } else { | 422 } else { |
| 438 return SimpleFtoa(value) + "F"; | 423 return SimpleFtoa(value) + "F"; |
| 439 } | 424 } |
| 440 } | 425 } |
| 441 case FieldDescriptor::CPPTYPE_BOOL: | 426 case FieldDescriptor::CPPTYPE_BOOL: |
| 442 return field->default_value_bool() ? "true" : "false"; | 427 return field->default_value_bool() ? "true" : "false"; |
| 443 case FieldDescriptor::CPPTYPE_STRING: | 428 case FieldDescriptor::CPPTYPE_STRING: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 case FieldDescriptor::CPPTYPE_INT64: | 474 case FieldDescriptor::CPPTYPE_INT64: |
| 490 return field->default_value_int64() == 0L; | 475 return field->default_value_int64() == 0L; |
| 491 case FieldDescriptor::CPPTYPE_UINT64: | 476 case FieldDescriptor::CPPTYPE_UINT64: |
| 492 return field->default_value_uint64() == 0L; | 477 return field->default_value_uint64() == 0L; |
| 493 case FieldDescriptor::CPPTYPE_DOUBLE: | 478 case FieldDescriptor::CPPTYPE_DOUBLE: |
| 494 return field->default_value_double() == 0.0; | 479 return field->default_value_double() == 0.0; |
| 495 case FieldDescriptor::CPPTYPE_FLOAT: | 480 case FieldDescriptor::CPPTYPE_FLOAT: |
| 496 return field->default_value_float() == 0.0; | 481 return field->default_value_float() == 0.0; |
| 497 case FieldDescriptor::CPPTYPE_BOOL: | 482 case FieldDescriptor::CPPTYPE_BOOL: |
| 498 return field->default_value_bool() == false; | 483 return field->default_value_bool() == false; |
| 484 |
| 485 case FieldDescriptor::CPPTYPE_STRING: |
| 499 case FieldDescriptor::CPPTYPE_ENUM: | 486 case FieldDescriptor::CPPTYPE_ENUM: |
| 500 return field->default_value_enum()->number() == 0; | |
| 501 case FieldDescriptor::CPPTYPE_STRING: | |
| 502 case FieldDescriptor::CPPTYPE_MESSAGE: | 487 case FieldDescriptor::CPPTYPE_MESSAGE: |
| 503 return false; | 488 return false; |
| 504 | 489 |
| 505 // No default because we want the compiler to complain if any new | 490 // No default because we want the compiler to complain if any new |
| 506 // types are added. | 491 // types are added. |
| 507 } | 492 } |
| 508 | 493 |
| 509 GOOGLE_LOG(FATAL) << "Can't get here."; | 494 GOOGLE_LOG(FATAL) << "Can't get here."; |
| 510 return false; | 495 return false; |
| 511 } | 496 } |
| 512 | 497 |
| 513 bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field) { | |
| 514 return GetJavaType(field) == JAVATYPE_BYTES && | |
| 515 field->default_value_string() != ""; | |
| 516 } | |
| 517 | |
| 518 const char* bit_masks[] = { | 498 const char* bit_masks[] = { |
| 519 "0x00000001", | 499 "0x00000001", |
| 520 "0x00000002", | 500 "0x00000002", |
| 521 "0x00000004", | 501 "0x00000004", |
| 522 "0x00000008", | 502 "0x00000008", |
| 523 "0x00000010", | 503 "0x00000010", |
| 524 "0x00000020", | 504 "0x00000020", |
| 525 "0x00000040", | 505 "0x00000040", |
| 526 "0x00000080", | 506 "0x00000080", |
| 527 | 507 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 return true; | 748 return true; |
| 769 } | 749 } |
| 770 } | 750 } |
| 771 return false; | 751 return false; |
| 772 } | 752 } |
| 773 | 753 |
| 774 } // namespace java | 754 } // namespace java |
| 775 } // namespace compiler | 755 } // namespace compiler |
| 776 } // namespace protobuf | 756 } // namespace protobuf |
| 777 } // namespace google | 757 } // namespace google |
| OLD | NEW |