• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3//
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file or at
6// https://developers.google.com/open-source/licenses/bsd
7
8// Author: kenton@google.com (Kenton Varda)
9//  Based on original Protocol Buffers design by
10//  Sanjay Ghemawat, Jeff Dean, and others.
11//
12// This file tests that various identifiers work as field and type names even
13// though the same identifiers are used internally by the C++ code generator.
14
15// LINT: LEGACY_NAMES
16
17syntax = "proto2";
18
19// Some generic_services option(s) added automatically.
20// See:  http://go/proto2-generic-services-default
21option cc_generic_services = true;  // auto-added
22
23// We don't put this in a package within proto2 because we need to make sure
24// that the generated code doesn't depend on being in the proto2 namespace.
25package protobuf_unittest;
26
27// Test that fields can have names like "input" and "i" which are also used
28// internally by the code generator for local variables.
29message TestConflictingSymbolNames {
30  message BuildDescriptors {}
31  message TypeTraits {}
32
33  optional int32 input = 1;
34  optional int32 output = 2;
35  optional string length = 3;
36  repeated int32 i = 4;
37  repeated string new_element = 5 [ctype = STRING_PIECE];
38  optional int32 total_size = 6;
39  optional int32 tag = 7;
40
41  enum TestEnum {
42    FOO = 0;
43  }
44  message Data1 {
45    repeated int32 data = 1;
46  }
47  message Data2 {
48    repeated TestEnum data = 1;
49  }
50  message Data3 {
51    repeated string data = 1;
52  }
53  message Data4 {
54    repeated Data4 data = 1;
55  }
56  message Data5 {
57    repeated string data = 1 [ctype = STRING_PIECE];
58  }
59  message Data6 {
60    repeated string data = 1 [ctype = CORD];
61  }
62
63  optional int32 source = 8;
64  optional int32 value = 9;
65  optional int32 file = 10;
66  optional int32 from = 11;
67  optional int32 handle_uninterpreted = 12;
68  repeated int32 index = 13;
69  optional int32 controller = 14;
70  optional int32 already_here = 15;
71
72  // Integral types
73  optional uint32 uint8 = 47;
74  optional uint32 uint8_t = 48;
75  optional uint32 uint16 = 49;
76  optional uint32 uint16_t = 50;
77  optional uint32 uint32 = 16;
78  optional uint32 uint32_t = 41;
79  optional uint64 uint64 = 17;
80  optional uint32 uint64_t = 42;
81  optional uint32 int8 = 51;
82  optional uint32 int8_t = 52;
83  optional uint32 int16 = 53;
84  optional uint32 int16_t = 54;
85  optional int32 int32 = 20;
86  optional int32 int32_t = 43;
87  optional int64 int64 = 21;
88  optional int64 int64_t = 44;
89  optional int64 size_t = 45;
90  optional int64 ssize_t = 55;
91  optional int64 intptr_t = 46;
92  optional int64 uintptr_t = 56;
93
94  optional string string = 18;
95  optional int32 memset = 19;
96
97  // Internal identifier
98  optional uint32 cached_size = 22;
99  optional uint32 extensions = 23;
100  optional uint32 bit = 24;
101  optional uint32 bits = 25;
102  optional uint32 offsets = 26;
103  optional uint32 reflection = 27;
104
105  message Cord {}
106  optional string some_cord = 28 [ctype = CORD];
107
108  message StringPiece {}
109  optional string some_string_piece = 29 [ctype = STRING_PIECE];
110
111  // Some keywords.
112  optional uint32 int = 30;
113  optional uint32 friend = 31;
114  optional uint32 class = 37;
115  optional uint32 typedecl = 39;
116  optional uint32 auto = 40;
117
118  // The generator used to #define a macro called "DO" inside the .cc file.
119  message DO {}
120  optional DO do = 32;
121
122  // Some template parameter names for extensions.
123  optional int32 field_type = 33;
124  optional bool is_packed = 34;
125
126  // test conflicting release_$name$. "length" and "do" field in this message
127  // must remain string or message fields to make the test valid.
128  optional string release_length = 35;
129  // A more extreme case, the field name "do" here is a keyword, which will be
130  // escaped to "do_" already. Test there is no conflict even with escaped field
131  // names.
132  optional DO release_do = 36;
133
134  // For clashing local variables in Serialize and ByteSize calculation.
135  optional string target = 38;
136
137  extensions 1000 to max [verification = UNVERIFIED];  // NO_PROTO3
138}
139
140message TestConflictingSymbolNamesExtension {                      // NO_PROTO3
141  extend TestConflictingSymbolNames {                              // NO_PROTO3
142    repeated int32 repeated_int32_ext = 20423638 [packed = true];  // NO_PROTO3
143  }  // NO_PROTO3
144}  // NO_PROTO3
145
146message TestConflictingEnumNames {  // NO_PROTO3
147  enum while {                      // NO_PROTO3
148    default = 0;                    // NO_PROTO3
149    and = 1;                        // NO_PROTO3
150    class = 2;                      // NO_PROTO3
151    int = 3;                        // NO_PROTO3
152    typedef = 4;                    // NO_PROTO3
153    XOR = 5;                        // NO_PROTO3
154  }  // NO_PROTO3
155
156  optional while conflicting_enum = 1;  // NO_PROTO3
157}  // NO_PROTO3
158
159enum bool {      // NO_PROTO3
160  default = 0;   // NO_PROTO3
161  NOT_EQ = 1;    // NO_PROTO3
162  volatile = 2;  // NO_PROTO3
163  return = 3;    // NO_PROTO3
164}  // NO_PROTO3
165
166message DummyMessage {}
167
168message NULL {
169  optional int32 int = 1;
170}
171
172extend TestConflictingSymbolNames {  // NO_PROTO3
173  optional int32 void = 314253;      // NO_PROTO3
174}  // NO_PROTO3
175
176// Message names that could conflict.
177message Shutdown {}
178message TableStruct {}
179
180service TestConflictingMethodNames {
181  rpc Closure(DummyMessage) returns (DummyMessage);
182}
183