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 // http://code.google.com/p/protobuf/ | 3 // http://code.google.com/p/protobuf/ |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // extends. This function is used in the Google-internal code to handle some | 50 // extends. This function is used in the Google-internal code to handle some |
51 // legacy cases. | 51 // legacy cases. |
52 string ExtendeeClassName(const FieldDescriptor* descriptor) { | 52 string ExtendeeClassName(const FieldDescriptor* descriptor) { |
53 const Descriptor* extendee = descriptor->containing_type(); | 53 const Descriptor* extendee = descriptor->containing_type(); |
54 return ClassName(extendee, true); | 54 return ClassName(extendee, true); |
55 } | 55 } |
56 | 56 |
57 } // anonymous namespace | 57 } // anonymous namespace |
58 | 58 |
59 ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, | 59 ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, |
60 const string& dllexport_decl) | 60 const Options& options) |
61 : descriptor_(descriptor), | 61 : descriptor_(descriptor), |
62 dllexport_decl_(dllexport_decl) { | 62 options_(options) { |
63 // Construct type_traits_. | 63 // Construct type_traits_. |
64 if (descriptor_->is_repeated()) { | 64 if (descriptor_->is_repeated()) { |
65 type_traits_ = "Repeated"; | 65 type_traits_ = "Repeated"; |
66 } | 66 } |
67 | 67 |
68 switch (descriptor_->cpp_type()) { | 68 switch (descriptor_->cpp_type()) { |
69 case FieldDescriptor::CPPTYPE_ENUM: | 69 case FieldDescriptor::CPPTYPE_ENUM: |
70 type_traits_.append("EnumTypeTraits< "); | 70 type_traits_.append("EnumTypeTraits< "); |
71 type_traits_.append(ClassName(descriptor_->enum_type(), true)); | 71 type_traits_.append(ClassName(descriptor_->enum_type(), true)); |
72 type_traits_.append(", "); | 72 type_traits_.append(", "); |
(...skipping 26 matching lines...) Expand all Loading... |
99 vars["name" ] = descriptor_->name(); | 99 vars["name" ] = descriptor_->name(); |
100 vars["field_type" ] = SimpleItoa(static_cast<int>(descriptor_->type())); | 100 vars["field_type" ] = SimpleItoa(static_cast<int>(descriptor_->type())); |
101 vars["packed" ] = descriptor_->options().packed() ? "true" : "false"; | 101 vars["packed" ] = descriptor_->options().packed() ? "true" : "false"; |
102 vars["constant_name"] = FieldConstantName(descriptor_); | 102 vars["constant_name"] = FieldConstantName(descriptor_); |
103 | 103 |
104 // If this is a class member, it needs to be declared "static". Otherwise, | 104 // If this is a class member, it needs to be declared "static". Otherwise, |
105 // it needs to be "extern". In the latter case, it also needs the DLL | 105 // it needs to be "extern". In the latter case, it also needs the DLL |
106 // export/import specifier. | 106 // export/import specifier. |
107 if (descriptor_->extension_scope() == NULL) { | 107 if (descriptor_->extension_scope() == NULL) { |
108 vars["qualifier"] = "extern"; | 108 vars["qualifier"] = "extern"; |
109 if (!dllexport_decl_.empty()) { | 109 if (!options_.dllexport_decl.empty()) { |
110 vars["qualifier"] = dllexport_decl_ + " " + vars["qualifier"]; | 110 vars["qualifier"] = options_.dllexport_decl + " " + vars["qualifier"]; |
111 } | 111 } |
112 } else { | 112 } else { |
113 vars["qualifier"] = "static"; | 113 vars["qualifier"] = "static"; |
114 } | 114 } |
115 | 115 |
116 printer->Print(vars, | 116 printer->Print(vars, |
117 "static const int $constant_name$ = $number$;\n" | 117 "static const int $constant_name$ = $number$;\n" |
118 "$qualifier$ ::google::protobuf::internal::ExtensionIdentifier< $extendee$,\
n" | 118 "$qualifier$ ::google::protobuf::internal::ExtensionIdentifier< $extendee$,\
n" |
119 " ::google::protobuf::internal::$type_traits$, $field_type$, $packed$ >\n
" | 119 " ::google::protobuf::internal::$type_traits$, $field_type$, $packed$ >\n
" |
120 " $name$;\n" | 120 " $name$;\n" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 " &$extendee$::default_instance(),\n" | 201 " &$extendee$::default_instance(),\n" |
202 " $number$, $field_type$, $is_repeated$, $is_packed$);\n"); | 202 " $number$, $field_type$, $is_repeated$, $is_packed$);\n"); |
203 break; | 203 break; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 } // namespace cpp | 207 } // namespace cpp |
208 } // namespace compiler | 208 } // namespace compiler |
209 } // namespace protobuf | 209 } // namespace protobuf |
210 } // namespace google | 210 } // namespace google |
OLD | NEW |