webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
java_field.h
Go to the documentation of this file.
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_JAVA_FIELD_H__
36 #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__
37 
38 #include <map>
39 #include <memory>
40 #ifndef _SHARED_PTR_H
42 #endif
43 #include <string>
44 
48 
49 namespace google {
50 namespace protobuf {
51  namespace compiler {
52  namespace java {
53  class Context; // context.h
54  class ClassNameResolver; // name_resolver.h
55  }
56  }
57  namespace io {
58  class Printer; // printer.h
59  }
60 }
61 
62 namespace protobuf {
63 namespace compiler {
64 namespace java {
65 
67  public:
69  virtual ~ImmutableFieldGenerator();
70 
71  virtual int GetNumBitsForMessage() const = 0;
72  virtual int GetNumBitsForBuilder() const = 0;
73  virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
74  virtual void GenerateMembers(io::Printer* printer) const = 0;
75  virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
76  virtual void GenerateInitializationCode(io::Printer* printer) const = 0;
77  virtual void GenerateBuilderClearCode(io::Printer* printer) const = 0;
78  virtual void GenerateMergingCode(io::Printer* printer) const = 0;
79  virtual void GenerateBuildingCode(io::Printer* printer) const = 0;
80  virtual void GenerateParsingCode(io::Printer* printer) const = 0;
81  virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const;
82  virtual void GenerateParsingDoneCode(io::Printer* printer) const = 0;
83  virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
84  virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
85  virtual void GenerateFieldBuilderInitializationCode(io::Printer* printer)
86  const = 0;
87 
88  virtual void GenerateEqualsCode(io::Printer* printer) const = 0;
89  virtual void GenerateHashCode(io::Printer* printer) const = 0;
90 
91  virtual string GetBoxedType() const = 0;
92 
93  private:
95 };
96 
98  public:
100  virtual ~ImmutableFieldLiteGenerator();
101 
102  virtual int GetNumBitsForMessage() const = 0;
103  virtual int GetNumBitsForBuilder() const = 0;
104  virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0;
105  virtual void GenerateMembers(io::Printer* printer) const = 0;
106  virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
107  virtual void GenerateInitializationCode(io::Printer* printer) const = 0;
108  virtual void GenerateVisitCode(io::Printer* printer) const = 0;
109  virtual void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer)
110  const = 0;
111  virtual void GenerateParsingCode(io::Printer* printer) const = 0;
112  virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const;
113  virtual void GenerateParsingDoneCode(io::Printer* printer) const = 0;
114  virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
115  virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
116  virtual void GenerateFieldBuilderInitializationCode(io::Printer* printer)
117  const = 0;
118 
119  virtual void GenerateEqualsCode(io::Printer* printer) const = 0;
120  virtual void GenerateHashCode(io::Printer* printer) const = 0;
121 
122  virtual string GetBoxedType() const = 0;
123 
124  private:
126 };
127 
128 
129 // Convenience class which constructs FieldGenerators for a Descriptor.
130 template<typename FieldGeneratorType>
132  public:
133  explicit FieldGeneratorMap(const Descriptor* descriptor,
134  Context* context);
136 
137  const FieldGeneratorType& get(const FieldDescriptor* field) const;
138 
139  private:
140  const Descriptor* descriptor_;
141  Context* context_;
142  ClassNameResolver* name_resolver_;
144 
146 };
147 
148 template<typename FieldGeneratorType>
149 inline const FieldGeneratorType&
152  return *field_generators_[field->index()];
153 }
154 
155 // Instantiate template for mutable and immutable maps.
156 template<>
159  Context* context);
160 
161 template<>
163 
164 
165 // Field information used in FieldGeneartors.
167  string name;
170 };
171 
172 // Oneof information used in OneofFieldGeneartors.
174  string name;
176 };
177 
178 // Set some common variables used in variable FieldGenerators.
179 void SetCommonFieldVariables(const FieldDescriptor* descriptor,
180  const FieldGeneratorInfo* info,
181  map<string, string>* variables);
182 
183 // Set some common oneof variables used in OneofFieldGenerators.
184 void SetCommonOneofVariables(const FieldDescriptor* descriptor,
185  const OneofGeneratorInfo* info,
186  map<string, string>* variables);
187 
188 // Print useful comments before a field's accessors.
189 void PrintExtraFieldInfo(const map<string, string>& variables,
190  io::Printer* printer);
191 
192 } // namespace java
193 } // namespace compiler
194 } // namespace protobuf
195 
196 } // namespace google
197 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__
Definition: upb.c:6604
Definition: printer.h:164
const FieldDescriptor * field
Definition: parser_unittest.cc:2279
#define GOOGLE_CHECK_EQ(A, B)
Definition: logging.h:154
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: macros.h:40
const Descriptor * descriptor_
Definition: field_comparator_test.cc:58
void * Context
Definition: platform_glx.h:177
string disambiguated_reason
Definition: java_field.h:169
const Descriptor * descriptor
Definition: descriptor.cc:271
def info(msg, args, kwargs)
Definition: __init__.py:1165
string name
Definition: java_field.h:167
Definition: descriptor.h:172
string name
Definition: java_field.h:174
Definition: descriptor.h:439
Definition: java_name_resolver.h:53
Definition: scoped_ptr.h:49
string capitalized_name
Definition: java_field.h:175
const FieldGeneratorType & get(const FieldDescriptor *field) const
Definition: java_field.h:150
string capitalized_name
Definition: java_field.h:168
void PrintExtraFieldInfo(const map< string, string > &variables, io::Printer *printer)
Definition: java_field.cc:317
FieldGeneratorMap(const Descriptor *descriptor, Context *context)
Definition: __init__.py:1
void SetCommonOneofVariables(const FieldDescriptor *descriptor, const OneofGeneratorInfo *info, map< string, string > *variables)
Definition: java_field.cc:302
Definition: java_context.h:65
Definition: gflags_completions.h:115
U_CDECL_BEGIN typedef void * context
Definition: ustring.h:1023
void SetCommonFieldVariables(const FieldDescriptor *descriptor, const FieldGeneratorInfo *info, map< string, string > *variables)
Definition: java_field.cc:291
const Descriptor * containing_type() const