| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 all_values_.push_back(value); | 55 all_values_.push_back(value); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 EnumGenerator::~EnumGenerator() {} | 59 EnumGenerator::~EnumGenerator() {} |
| 60 | 60 |
| 61 void EnumGenerator::GenerateHeader(io::Printer* printer) { | 61 void EnumGenerator::GenerateHeader(io::Printer* printer) { |
| 62 string enum_comments; | 62 string enum_comments; |
| 63 SourceLocation location; | 63 SourceLocation location; |
| 64 if (descriptor_->GetSourceLocation(&location)) { | 64 if (descriptor_->GetSourceLocation(&location)) { |
| 65 enum_comments = BuildCommentsString(location); | 65 enum_comments = BuildCommentsString(location, true); |
| 66 } else { | 66 } else { |
| 67 enum_comments = ""; | 67 enum_comments = ""; |
| 68 } | 68 } |
| 69 | 69 |
| 70 printer->Print( | 70 printer->Print( |
| 71 "#pragma mark - Enum $name$\n" | 71 "#pragma mark - Enum $name$\n" |
| 72 "\n", | 72 "\n", |
| 73 "name", name_); | 73 "name", name_); |
| 74 | 74 |
| 75 printer->Print("$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n", | 75 printer->Print("$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n", |
| 76 "comments", enum_comments, | 76 "comments", enum_comments, |
| 77 "deprecated_attribute", GetOptionalDeprecatedAttribute(descript
or_), | 77 "deprecated_attribute", GetOptionalDeprecatedAttribute(descript
or_), |
| 78 "name", name_); | 78 "name", name_); |
| 79 printer->Indent(); | 79 printer->Indent(); |
| 80 | 80 |
| 81 if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { | 81 if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { |
| 82 // Include the unknown value. | 82 // Include the unknown value. |
| 83 printer->Print( | 83 printer->Print( |
| 84 "/// Value used if any message's field encounters a value that is not defi
ned\n" | 84 "/**\n" |
| 85 "/// by this enum. The message will also have C functions to get/set the r
awValue\n" | 85 " * Value used if any message's field encounters a value that is not defin
ed\n" |
| 86 "/// of the field.\n" | 86 " * by this enum. The message will also have C functions to get/set the ra
wValue\n" |
| 87 " * of the field.\n" |
| 88 " **/\n" |
| 87 "$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\
n", | 89 "$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\
n", |
| 88 "name", name_); | 90 "name", name_); |
| 89 } | 91 } |
| 90 for (int i = 0; i < all_values_.size(); i++) { | 92 for (int i = 0; i < all_values_.size(); i++) { |
| 91 SourceLocation location; | 93 SourceLocation location; |
| 92 if (all_values_[i]->GetSourceLocation(&location)) { | 94 if (all_values_[i]->GetSourceLocation(&location)) { |
| 93 string comments = BuildCommentsString(location).c_str(); | 95 string comments = BuildCommentsString(location, true).c_str(); |
| 94 if (comments.length() > 0) { | 96 if (comments.length() > 0) { |
| 95 if (i > 0) { | 97 if (i > 0) { |
| 96 printer->Print("\n"); | 98 printer->Print("\n"); |
| 97 } | 99 } |
| 98 printer->Print(comments.c_str()); | 100 printer->Print(comments.c_str()); |
| 99 } | 101 } |
| 100 } | 102 } |
| 101 | 103 |
| 102 printer->Print( | 104 printer->Print( |
| 103 "$name$$deprecated_attribute$ = $value$,\n", | 105 "$name$$deprecated_attribute$ = $value$,\n", |
| 104 "name", EnumValueName(all_values_[i]), | 106 "name", EnumValueName(all_values_[i]), |
| 105 "deprecated_attribute", GetOptionalDeprecatedAttribute(all_values_[i]), | 107 "deprecated_attribute", GetOptionalDeprecatedAttribute(all_values_[i]), |
| 106 "value", SimpleItoa(all_values_[i]->number())); | 108 "value", SimpleItoa(all_values_[i]->number())); |
| 107 } | 109 } |
| 108 printer->Outdent(); | 110 printer->Outdent(); |
| 109 printer->Print( | 111 printer->Print( |
| 110 "};\n" | 112 "};\n" |
| 111 "\n" | 113 "\n" |
| 112 "GPBEnumDescriptor *$name$_EnumDescriptor(void);\n" | 114 "GPBEnumDescriptor *$name$_EnumDescriptor(void);\n" |
| 113 "\n" | 115 "\n" |
| 114 "/// Checks to see if the given value is defined by the enum or was not kn
own at\n" | 116 "/**\n" |
| 115 "/// the time this source was generated.\n" | 117 " * Checks to see if the given value is defined by the enum or was not kno
wn at\n" |
| 118 " * the time this source was generated.\n" |
| 119 " **/\n" |
| 116 "BOOL $name$_IsValidValue(int32_t value);\n" | 120 "BOOL $name$_IsValidValue(int32_t value);\n" |
| 117 "\n", | 121 "\n", |
| 118 "name", name_); | 122 "name", name_); |
| 119 } | 123 } |
| 120 | 124 |
| 121 void EnumGenerator::GenerateSource(io::Printer* printer) { | 125 void EnumGenerator::GenerateSource(io::Printer* printer) { |
| 122 printer->Print( | 126 printer->Print( |
| 123 "#pragma mark - Enum $name$\n" | 127 "#pragma mark - Enum $name$\n" |
| 124 "\n", | 128 "\n", |
| 125 "name", name_); | 129 "name", name_); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 " return YES;\n" | 214 " return YES;\n" |
| 211 " default:\n" | 215 " default:\n" |
| 212 " return NO;\n" | 216 " return NO;\n" |
| 213 " }\n" | 217 " }\n" |
| 214 "}\n\n"); | 218 "}\n\n"); |
| 215 } | 219 } |
| 216 } // namespace objectivec | 220 } // namespace objectivec |
| 217 } // namespace compiler | 221 } // namespace compiler |
| 218 } // namespace protobuf | 222 } // namespace protobuf |
| 219 } // namespace google | 223 } // namespace google |
| OLD | NEW |