136
136
string FileJavaPackage(const FileDescriptor* file) {
137
139
if (file->options().has_java_package()) {
138
return file->options().java_package();
140
result = file->options().java_package();
140
string result = kDefaultPackage;
142
result = kDefaultPackage;
141
143
if (!file->package().empty()) {
142
144
if (!result.empty()) result += '.';
143
145
result += file->package();
153
string JavaPackageToDir(string package_name) {
155
StringReplace(package_name, ".", "/", true);
156
if (!package_dir.empty()) package_dir += "/";
149
160
string ToJavaName(const string& full_name, const FileDescriptor* file) {
349
bool IsDefaultValueJavaDefault(const FieldDescriptor* field) {
350
// Switch on CppType since we need to know which default_value_* method
351
// of FieldDescriptor to call.
352
switch (field->cpp_type()) {
353
case FieldDescriptor::CPPTYPE_INT32:
354
return field->default_value_int32() == 0;
355
case FieldDescriptor::CPPTYPE_UINT32:
356
return field->default_value_uint32() == 0;
357
case FieldDescriptor::CPPTYPE_INT64:
358
return field->default_value_int64() == 0L;
359
case FieldDescriptor::CPPTYPE_UINT64:
360
return field->default_value_uint64() == 0L;
361
case FieldDescriptor::CPPTYPE_DOUBLE:
362
return field->default_value_double() == 0.0;
363
case FieldDescriptor::CPPTYPE_FLOAT:
364
return field->default_value_float() == 0.0;
365
case FieldDescriptor::CPPTYPE_BOOL:
366
return field->default_value_bool() == false;
368
case FieldDescriptor::CPPTYPE_STRING:
369
case FieldDescriptor::CPPTYPE_ENUM:
370
case FieldDescriptor::CPPTYPE_MESSAGE:
373
// No default because we want the compiler to complain if any new
377
GOOGLE_LOG(FATAL) << "Can't get here.";
381
const char* bit_masks[] = {
419
string GetBitFieldName(int index) {
420
string varName = "bitField";
421
varName += SimpleItoa(index);
426
string GetBitFieldNameForBit(int bitIndex) {
427
return GetBitFieldName(bitIndex / 32);
430
string GenerateGetBit(int bitIndex) {
431
string varName = GetBitFieldNameForBit(bitIndex);
432
int bitInVarIndex = bitIndex % 32;
434
string mask = bit_masks[bitInVarIndex];
435
string result = "((" + varName + " & " + mask + ") == " + mask + ")";
439
string GenerateSetBit(int bitIndex) {
440
string varName = GetBitFieldNameForBit(bitIndex);
441
int bitInVarIndex = bitIndex % 32;
443
string mask = bit_masks[bitInVarIndex];
444
string result = varName + " |= " + mask;
448
string GenerateClearBit(int bitIndex) {
449
string varName = GetBitFieldNameForBit(bitIndex);
450
int bitInVarIndex = bitIndex % 32;
452
string mask = bit_masks[bitInVarIndex];
453
string result = varName + " = (" + varName + " & ~" + mask + ")";
457
string GenerateGetBitFromLocal(int bitIndex) {
458
string varName = "from_" + GetBitFieldNameForBit(bitIndex);
459
int bitInVarIndex = bitIndex % 32;
461
string mask = bit_masks[bitInVarIndex];
462
string result = "((" + varName + " & " + mask + ") == " + mask + ")";
466
string GenerateSetBitToLocal(int bitIndex) {
467
string varName = "to_" + GetBitFieldNameForBit(bitIndex);
468
int bitInVarIndex = bitIndex % 32;
470
string mask = bit_masks[bitInVarIndex];
471
string result = varName + " |= " + mask;
338
475
} // namespace java
339
476
} // namespace compiler
340
477
} // namespace protobuf