Line data Source code
1 : // Protocol Buffers - Google's data interchange format
2 : // Copyright 2008 Google Inc. All rights reserved.
3 : // https://developers.google.com/protocol-buffers/
4 : //
5 : // Redistribution and use in source and binary forms, with or without
6 : // modification, are permitted provided that the following conditions are
7 : // met:
8 : //
9 : // * Redistributions of source code must retain the above copyright
10 : // notice, this list of conditions and the following disclaimer.
11 : // * Redistributions in binary form must reproduce the above
12 : // copyright notice, this list of conditions and the following disclaimer
13 : // in the documentation and/or other materials provided with the
14 : // distribution.
15 : // * Neither the name of Google Inc. nor the names of its
16 : // contributors may be used to endorse or promote products derived from
17 : // this software without specific prior written permission.
18 : //
19 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 :
31 : // Author: kenton@google.com (Kenton Varda)
32 : // Based on original Protocol Buffers design by
33 : // Sanjay Ghemawat, Jeff Dean, and others.
34 :
35 : #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__
36 : #define GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__
37 :
38 : #include <string>
39 : #include <google/protobuf/descriptor.pb.h>
40 : #include <google/protobuf/descriptor.h>
41 : #include <google/protobuf/compiler/code_generator.h>
42 : #include <google/protobuf/io/printer.h>
43 :
44 : namespace google {
45 : namespace protobuf {
46 : namespace compiler {
47 : namespace csharp {
48 :
49 : class FieldGeneratorBase;
50 :
51 : // TODO: start using this enum.
52 : enum CSharpType {
53 : CSHARPTYPE_INT32 = 1,
54 : CSHARPTYPE_INT64 = 2,
55 : CSHARPTYPE_UINT32 = 3,
56 : CSHARPTYPE_UINT64 = 4,
57 : CSHARPTYPE_FLOAT = 5,
58 : CSHARPTYPE_DOUBLE = 6,
59 : CSHARPTYPE_BOOL = 7,
60 : CSHARPTYPE_STRING = 8,
61 : CSHARPTYPE_BYTESTRING = 9,
62 : CSHARPTYPE_MESSAGE = 10,
63 : CSHARPTYPE_ENUM = 11,
64 : MAX_CSHARPTYPE = 11
65 : };
66 :
67 : // Converts field type to corresponding C# type.
68 : CSharpType GetCSharpType(FieldDescriptor::Type type);
69 :
70 : std::string StripDotProto(const std::string& proto_file);
71 :
72 : // Gets unqualified name of the umbrella class
73 : std::string GetUmbrellaClassUnqualifiedName(const FileDescriptor* descriptor);
74 :
75 : // Gets name of the nested for umbrella class (just the nested part,
76 : // not including the GetFileNamespace part).
77 : std::string GetUmbrellaClassNestedNamespace(const FileDescriptor* descriptor);
78 :
79 : std::string GetClassName(const Descriptor* descriptor);
80 :
81 : std::string GetClassName(const EnumDescriptor* descriptor);
82 :
83 : std::string GetFieldName(const FieldDescriptor* descriptor);
84 :
85 : std::string GetFieldConstantName(const FieldDescriptor* field);
86 :
87 : std::string GetPropertyName(const FieldDescriptor* descriptor);
88 :
89 : int GetFixedSize(FieldDescriptor::Type type);
90 :
91 : std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter, bool preserve_period);
92 :
93 : inline std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter) {
94 0 : return UnderscoresToCamelCase(input, cap_next_letter, false);
95 : }
96 :
97 : std::string UnderscoresToPascalCase(const std::string& input);
98 :
99 : // TODO(jtattermusch): perhaps we could move this to strutil
100 : std::string StringToBase64(const std::string& input);
101 :
102 : std::string FileDescriptorToBase64(const FileDescriptor* descriptor);
103 :
104 : uint FixedMakeTag(const FieldDescriptor* descriptor);
105 :
106 : FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
107 :
108 : // Determines whether the given message is a map entry message, i.e. one implicitly created
109 : // by protoc due to a map<key, value> field.
110 0 : inline bool IsMapEntryMessage(const Descriptor* descriptor) {
111 0 : return descriptor->options().map_entry();
112 : }
113 :
114 : // Determines whether we're generating code for the proto representation of descriptors etc,
115 : // for use in the runtime. This is the only type which is allowed to use proto2 syntax,
116 : // and it generates internal classes.
117 0 : inline bool IsDescriptorProto(const FileDescriptor* descriptor) {
118 0 : return descriptor->name() == "google/protobuf/descriptor.proto";
119 : }
120 :
121 0 : inline bool IsWrapperType(const FieldDescriptor* descriptor) {
122 0 : return descriptor->type() == FieldDescriptor::TYPE_MESSAGE &&
123 0 : descriptor->message_type()->file()->name() == "google/protobuf/wrappers.proto";
124 : }
125 :
126 : } // namespace csharp
127 : } // namespace compiler
128 : } // namespace protobuf
129 : } // namespace google
130 : #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__
|