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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, const Options* op
tions) : | 53 EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, const Options* op
tions) : |
54 SourceGeneratorBase(descriptor->file(), options), | 54 SourceGeneratorBase(descriptor->file(), options), |
55 descriptor_(descriptor) { | 55 descriptor_(descriptor) { |
56 } | 56 } |
57 | 57 |
58 EnumGenerator::~EnumGenerator() { | 58 EnumGenerator::~EnumGenerator() { |
59 } | 59 } |
60 | 60 |
61 void EnumGenerator::Generate(io::Printer* printer) { | 61 void EnumGenerator::Generate(io::Printer* printer) { |
62 WriteEnumDocComment(printer, descriptor_); | 62 WriteEnumDocComment(printer, descriptor_); |
63 WriteGeneratedCodeAttributes(printer); | |
64 printer->Print("$access_level$ enum $name$ {\n", | 63 printer->Print("$access_level$ enum $name$ {\n", |
65 "access_level", class_access_level(), | 64 "access_level", class_access_level(), |
66 "name", descriptor_->name()); | 65 "name", descriptor_->name()); |
67 printer->Indent(); | 66 printer->Indent(); |
68 std::set<string> used_names; | 67 std::set<string> used_names; |
69 for (int i = 0; i < descriptor_->value_count(); i++) { | 68 for (int i = 0; i < descriptor_->value_count(); i++) { |
70 WriteEnumValueDocComment(printer, descriptor_->value(i)); | 69 WriteEnumValueDocComment(printer, descriptor_->value(i)); |
71 string original_name = descriptor_->value(i)->name(); | 70 string original_name = descriptor_->value(i)->name(); |
72 string name = options()->legacy_enum_values | 71 string name = GetEnumValueName(descriptor_->name(), descriptor_->value(i)-
>name()); |
73 ? descriptor_->value(i)->name() | |
74 : GetEnumValueName(descriptor_->name(), descriptor_->value(i)->name())
; | |
75 // Make sure we don't get any duplicate names due to prefix removal. | 72 // Make sure we don't get any duplicate names due to prefix removal. |
76 while (!used_names.insert(name).second) { | 73 while (!used_names.insert(name).second) { |
77 // It's possible we'll end up giving this warning multiple times, but th
at's better than not at all. | 74 // It's possible we'll end up giving this warning multiple times, but th
at's better than not at all. |
78 GOOGLE_LOG(WARNING) << "Duplicate enum value " << name << " (originally
" << original_name | 75 GOOGLE_LOG(WARNING) << "Duplicate enum value " << name << " (originally
" << original_name |
79 << ") in " << descriptor_->name() << "; adding underscore to distingui
sh"; | 76 << ") in " << descriptor_->name() << "; adding underscore to distingui
sh"; |
80 name += "_"; | 77 name += "_"; |
81 } | 78 } |
82 printer->Print("[pbr::OriginalName(\"$original_name$\")] $name$ = $number$
,\n", | 79 printer->Print("[pbr::OriginalName(\"$original_name$\")] $name$ = $number$
,\n", |
83 "original_name", original_name, | 80 "original_name", original_name, |
84 "name", name, | 81 "name", name, |
85 "number", SimpleItoa(descriptor_->value(i)->number())); | 82 "number", SimpleItoa(descriptor_->value(i)->number())); |
86 } | 83 } |
87 printer->Outdent(); | 84 printer->Outdent(); |
88 printer->Print("}\n"); | 85 printer->Print("}\n"); |
89 printer->Print("\n"); | 86 printer->Print("\n"); |
90 } | 87 } |
91 | 88 |
92 } // namespace csharp | 89 } // namespace csharp |
93 } // namespace compiler | 90 } // namespace compiler |
94 } // namespace protobuf | 91 } // namespace protobuf |
95 } // namespace google | 92 } // namespace google |
OLD | NEW |