| 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 |
| 104 string UnderscoresToCamelCase(const string& input, bool cap_next_letter) { | 118 string UnderscoresToCamelCase(const string& input, bool cap_next_letter) { |
| 105 string result; | 119 string result; |
| 106 // Note: I distrust ctype.h due to locales. | 120 // Note: I distrust ctype.h due to locales. |
| 107 for (int i = 0; i < input.size(); i++) { | 121 for (int i = 0; i < input.size(); i++) { |
| 108 if ('a' <= input[i] && input[i] <= 'z') { | 122 if ('a' <= input[i] && input[i] <= 'z') { |
| 109 if (cap_next_letter) { | 123 if (cap_next_letter) { |
| 110 result += input[i] + ('A' - 'a'); | 124 result += input[i] + ('A' - 'a'); |
| 111 } else { | 125 } else { |
| 112 result += input[i]; | 126 result += input[i]; |
| 113 } | 127 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 case JAVATYPE_MESSAGE: return NULL; | 353 case JAVATYPE_MESSAGE: return NULL; |
| 340 | 354 |
| 341 // No default because we want the compiler to complain if any new | 355 // No default because we want the compiler to complain if any new |
| 342 // JavaTypes are added. | 356 // JavaTypes are added. |
| 343 } | 357 } |
| 344 | 358 |
| 345 GOOGLE_LOG(FATAL) << "Can't get here."; | 359 GOOGLE_LOG(FATAL) << "Can't get here."; |
| 346 return NULL; | 360 return NULL; |
| 347 } | 361 } |
| 348 | 362 |
| 363 |
| 349 const char* FieldTypeName(FieldDescriptor::Type field_type) { | 364 const char* FieldTypeName(FieldDescriptor::Type field_type) { |
| 350 switch (field_type) { | 365 switch (field_type) { |
| 351 case FieldDescriptor::TYPE_INT32 : return "INT32"; | 366 case FieldDescriptor::TYPE_INT32 : return "INT32"; |
| 352 case FieldDescriptor::TYPE_UINT32 : return "UINT32"; | 367 case FieldDescriptor::TYPE_UINT32 : return "UINT32"; |
| 353 case FieldDescriptor::TYPE_SINT32 : return "SINT32"; | 368 case FieldDescriptor::TYPE_SINT32 : return "SINT32"; |
| 354 case FieldDescriptor::TYPE_FIXED32 : return "FIXED32"; | 369 case FieldDescriptor::TYPE_FIXED32 : return "FIXED32"; |
| 355 case FieldDescriptor::TYPE_SFIXED32: return "SFIXED32"; | 370 case FieldDescriptor::TYPE_SFIXED32: return "SFIXED32"; |
| 356 case FieldDescriptor::TYPE_INT64 : return "INT64"; | 371 case FieldDescriptor::TYPE_INT64 : return "INT64"; |
| 357 case FieldDescriptor::TYPE_UINT64 : return "UINT64"; | 372 case FieldDescriptor::TYPE_UINT64 : return "UINT64"; |
| 358 case FieldDescriptor::TYPE_SINT64 : return "SINT64"; | 373 case FieldDescriptor::TYPE_SINT64 : return "SINT64"; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 case FieldDescriptor::CPPTYPE_UINT32: | 409 case FieldDescriptor::CPPTYPE_UINT32: |
| 395 // Need to print as a signed int since Java has no unsigned. | 410 // Need to print as a signed int since Java has no unsigned. |
| 396 return SimpleItoa(static_cast<int32>(field->default_value_uint32())); | 411 return SimpleItoa(static_cast<int32>(field->default_value_uint32())); |
| 397 case FieldDescriptor::CPPTYPE_INT64: | 412 case FieldDescriptor::CPPTYPE_INT64: |
| 398 return SimpleItoa(field->default_value_int64()) + "L"; | 413 return SimpleItoa(field->default_value_int64()) + "L"; |
| 399 case FieldDescriptor::CPPTYPE_UINT64: | 414 case FieldDescriptor::CPPTYPE_UINT64: |
| 400 return SimpleItoa(static_cast<int64>(field->default_value_uint64())) + | 415 return SimpleItoa(static_cast<int64>(field->default_value_uint64())) + |
| 401 "L"; | 416 "L"; |
| 402 case FieldDescriptor::CPPTYPE_DOUBLE: { | 417 case FieldDescriptor::CPPTYPE_DOUBLE: { |
| 403 double value = field->default_value_double(); | 418 double value = field->default_value_double(); |
| 404 if (value == numeric_limits<double>::infinity()) { | 419 if (value == std::numeric_limits<double>::infinity()) { |
| 405 return "Double.POSITIVE_INFINITY"; | 420 return "Double.POSITIVE_INFINITY"; |
| 406 } else if (value == -numeric_limits<double>::infinity()) { | 421 } else if (value == -std::numeric_limits<double>::infinity()) { |
| 407 return "Double.NEGATIVE_INFINITY"; | 422 return "Double.NEGATIVE_INFINITY"; |
| 408 } else if (value != value) { | 423 } else if (value != value) { |
| 409 return "Double.NaN"; | 424 return "Double.NaN"; |
| 410 } else { | 425 } else { |
| 411 return SimpleDtoa(value) + "D"; | 426 return SimpleDtoa(value) + "D"; |
| 412 } | 427 } |
| 413 } | 428 } |
| 414 case FieldDescriptor::CPPTYPE_FLOAT: { | 429 case FieldDescriptor::CPPTYPE_FLOAT: { |
| 415 float value = field->default_value_float(); | 430 float value = field->default_value_float(); |
| 416 if (value == numeric_limits<float>::infinity()) { | 431 if (value == std::numeric_limits<float>::infinity()) { |
| 417 return "Float.POSITIVE_INFINITY"; | 432 return "Float.POSITIVE_INFINITY"; |
| 418 } else if (value == -numeric_limits<float>::infinity()) { | 433 } else if (value == -std::numeric_limits<float>::infinity()) { |
| 419 return "Float.NEGATIVE_INFINITY"; | 434 return "Float.NEGATIVE_INFINITY"; |
| 420 } else if (value != value) { | 435 } else if (value != value) { |
| 421 return "Float.NaN"; | 436 return "Float.NaN"; |
| 422 } else { | 437 } else { |
| 423 return SimpleFtoa(value) + "F"; | 438 return SimpleFtoa(value) + "F"; |
| 424 } | 439 } |
| 425 } | 440 } |
| 426 case FieldDescriptor::CPPTYPE_BOOL: | 441 case FieldDescriptor::CPPTYPE_BOOL: |
| 427 return field->default_value_bool() ? "true" : "false"; | 442 return field->default_value_bool() ? "true" : "false"; |
| 428 case FieldDescriptor::CPPTYPE_STRING: | 443 case FieldDescriptor::CPPTYPE_STRING: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 case FieldDescriptor::CPPTYPE_INT64: | 489 case FieldDescriptor::CPPTYPE_INT64: |
| 475 return field->default_value_int64() == 0L; | 490 return field->default_value_int64() == 0L; |
| 476 case FieldDescriptor::CPPTYPE_UINT64: | 491 case FieldDescriptor::CPPTYPE_UINT64: |
| 477 return field->default_value_uint64() == 0L; | 492 return field->default_value_uint64() == 0L; |
| 478 case FieldDescriptor::CPPTYPE_DOUBLE: | 493 case FieldDescriptor::CPPTYPE_DOUBLE: |
| 479 return field->default_value_double() == 0.0; | 494 return field->default_value_double() == 0.0; |
| 480 case FieldDescriptor::CPPTYPE_FLOAT: | 495 case FieldDescriptor::CPPTYPE_FLOAT: |
| 481 return field->default_value_float() == 0.0; | 496 return field->default_value_float() == 0.0; |
| 482 case FieldDescriptor::CPPTYPE_BOOL: | 497 case FieldDescriptor::CPPTYPE_BOOL: |
| 483 return field->default_value_bool() == false; | 498 return field->default_value_bool() == false; |
| 484 | 499 case FieldDescriptor::CPPTYPE_ENUM: |
| 500 return field->default_value_enum()->number() == 0; |
| 485 case FieldDescriptor::CPPTYPE_STRING: | 501 case FieldDescriptor::CPPTYPE_STRING: |
| 486 case FieldDescriptor::CPPTYPE_ENUM: | |
| 487 case FieldDescriptor::CPPTYPE_MESSAGE: | 502 case FieldDescriptor::CPPTYPE_MESSAGE: |
| 488 return false; | 503 return false; |
| 489 | 504 |
| 490 // No default because we want the compiler to complain if any new | 505 // No default because we want the compiler to complain if any new |
| 491 // types are added. | 506 // types are added. |
| 492 } | 507 } |
| 493 | 508 |
| 494 GOOGLE_LOG(FATAL) << "Can't get here."; | 509 GOOGLE_LOG(FATAL) << "Can't get here."; |
| 495 return false; | 510 return false; |
| 496 } | 511 } |
| 497 | 512 |
| 513 bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field) { |
| 514 return GetJavaType(field) == JAVATYPE_BYTES && |
| 515 field->default_value_string() != ""; |
| 516 } |
| 517 |
| 498 const char* bit_masks[] = { | 518 const char* bit_masks[] = { |
| 499 "0x00000001", | 519 "0x00000001", |
| 500 "0x00000002", | 520 "0x00000002", |
| 501 "0x00000004", | 521 "0x00000004", |
| 502 "0x00000008", | 522 "0x00000008", |
| 503 "0x00000010", | 523 "0x00000010", |
| 504 "0x00000020", | 524 "0x00000020", |
| 505 "0x00000040", | 525 "0x00000040", |
| 506 "0x00000080", | 526 "0x00000080", |
| 507 | 527 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 return true; | 768 return true; |
| 749 } | 769 } |
| 750 } | 770 } |
| 751 return false; | 771 return false; |
| 752 } | 772 } |
| 753 | 773 |
| 754 } // namespace java | 774 } // namespace java |
| 755 } // namespace compiler | 775 } // namespace compiler |
| 756 } // namespace protobuf | 776 } // namespace protobuf |
| 757 } // namespace google | 777 } // namespace google |
| OLD | NEW |