~verterok/ubuntu/lucid/protobuf/2.4.0a-backport

« back to all changes in this revision

Viewing changes to src/google/protobuf/compiler/java/java_helpers.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-05-31 14:41:47 UTC
  • mfrom: (2.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110531144147-s41g5fozgvyo462l
Tags: 2.4.0a-2ubuntu1
* Merge with Debian; remaining changes:
  - Fix linking with -lpthread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
}
135
135
 
136
136
string FileJavaPackage(const FileDescriptor* file) {
 
137
  string result;
 
138
 
137
139
  if (file->options().has_java_package()) {
138
 
    return file->options().java_package();
 
140
    result = file->options().java_package();
139
141
  } else {
140
 
    string result = kDefaultPackage;
 
142
    result = kDefaultPackage;
141
143
    if (!file->package().empty()) {
142
144
      if (!result.empty()) result += '.';
143
145
      result += file->package();
144
146
    }
145
 
    return result;
146
147
  }
 
148
 
 
149
 
 
150
  return result;
 
151
}
 
152
 
 
153
string JavaPackageToDir(string package_name) {
 
154
  string package_dir =
 
155
    StringReplace(package_name, ".", "/", true);
 
156
  if (!package_dir.empty()) package_dir += "/";
 
157
  return package_dir;
147
158
}
148
159
 
149
160
string ToJavaName(const string& full_name, const FileDescriptor* file) {
335
346
  return "";
336
347
}
337
348
 
 
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;
 
367
 
 
368
    case FieldDescriptor::CPPTYPE_STRING:
 
369
    case FieldDescriptor::CPPTYPE_ENUM:
 
370
    case FieldDescriptor::CPPTYPE_MESSAGE:
 
371
      return false;
 
372
 
 
373
    // No default because we want the compiler to complain if any new
 
374
    // types are added.
 
375
  }
 
376
 
 
377
  GOOGLE_LOG(FATAL) << "Can't get here.";
 
378
  return false;
 
379
}
 
380
 
 
381
const char* bit_masks[] = {
 
382
  "0x00000001",
 
383
  "0x00000002",
 
384
  "0x00000004",
 
385
  "0x00000008",
 
386
  "0x00000010",
 
387
  "0x00000020",
 
388
  "0x00000040",
 
389
  "0x00000080",
 
390
 
 
391
  "0x00000100",
 
392
  "0x00000200",
 
393
  "0x00000400",
 
394
  "0x00000800",
 
395
  "0x00001000",
 
396
  "0x00002000",
 
397
  "0x00004000",
 
398
  "0x00008000",
 
399
 
 
400
  "0x00010000",
 
401
  "0x00020000",
 
402
  "0x00040000",
 
403
  "0x00080000",
 
404
  "0x00100000",
 
405
  "0x00200000",
 
406
  "0x00400000",
 
407
  "0x00800000",
 
408
 
 
409
  "0x01000000",
 
410
  "0x02000000",
 
411
  "0x04000000",
 
412
  "0x08000000",
 
413
  "0x10000000",
 
414
  "0x20000000",
 
415
  "0x40000000",
 
416
  "0x80000000",
 
417
};
 
418
 
 
419
string GetBitFieldName(int index) {
 
420
  string varName = "bitField";
 
421
  varName += SimpleItoa(index);
 
422
  varName += "_";
 
423
  return varName;
 
424
}
 
425
 
 
426
string GetBitFieldNameForBit(int bitIndex) {
 
427
  return GetBitFieldName(bitIndex / 32);
 
428
}
 
429
 
 
430
string GenerateGetBit(int bitIndex) {
 
431
  string varName = GetBitFieldNameForBit(bitIndex);
 
432
  int bitInVarIndex = bitIndex % 32;
 
433
 
 
434
  string mask = bit_masks[bitInVarIndex];
 
435
  string result = "((" + varName + " & " + mask + ") == " + mask + ")";
 
436
  return result;
 
437
}
 
438
 
 
439
string GenerateSetBit(int bitIndex) {
 
440
  string varName = GetBitFieldNameForBit(bitIndex);
 
441
  int bitInVarIndex = bitIndex % 32;
 
442
 
 
443
  string mask = bit_masks[bitInVarIndex];
 
444
  string result = varName + " |= " + mask;
 
445
  return result;
 
446
}
 
447
 
 
448
string GenerateClearBit(int bitIndex) {
 
449
  string varName = GetBitFieldNameForBit(bitIndex);
 
450
  int bitInVarIndex = bitIndex % 32;
 
451
 
 
452
  string mask = bit_masks[bitInVarIndex];
 
453
  string result = varName + " = (" + varName + " & ~" + mask + ")";
 
454
  return result;
 
455
}
 
456
 
 
457
string GenerateGetBitFromLocal(int bitIndex) {
 
458
  string varName = "from_" + GetBitFieldNameForBit(bitIndex);
 
459
  int bitInVarIndex = bitIndex % 32;
 
460
 
 
461
  string mask = bit_masks[bitInVarIndex];
 
462
  string result = "((" + varName + " & " + mask + ") == " + mask + ")";
 
463
  return result;
 
464
}
 
465
 
 
466
string GenerateSetBitToLocal(int bitIndex) {
 
467
  string varName = "to_" + GetBitFieldNameForBit(bitIndex);
 
468
  int bitInVarIndex = bitIndex % 32;
 
469
 
 
470
  string mask = bit_masks[bitInVarIndex];
 
471
  string result = varName + " |= " + mask;
 
472
  return result;
 
473
}
 
474
 
338
475
}  // namespace java
339
476
}  // namespace compiler
340
477
}  // namespace protobuf