aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/javanano/javanano_helpers.h
diff options
context:
space:
mode:
authorGravatar Brian Duff <bduff@google.com>2013-10-15 18:35:44 -0700
committerGravatar Max Cai <maxtroy@google.com>2013-10-25 16:06:21 +0100
commit56a37328ae568225a672a4ba2654710caa0b8e59 (patch)
tree3201f50635c71bc298c1aef45d23106f3e06cee3 /src/google/protobuf/compiler/javanano/javanano_helpers.h
parent461d4ac87a5a6dee584da0c8451cdaae253f3873 (diff)
Implement hashCode() and equals() behind a generator option.
The option is only called 'generate_equals' because: - equals() is the main thing; hashCode() is there only to complement equals(); - it's shorter; - toString() should not be included in this option because it's more for debugging and it's more likely to stop ProGuard from working well. Also shortened the "has bit" expression; was ((bitField & mask) == mask), now ((bitField & mask) != 0). Both the Java code and the bytecode are slightly shorter. Change-Id: Ic309a08a60883bf454eb6612679aa99611620e76
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_helpers.h')
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_helpers.h31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.h b/src/google/protobuf/compiler/javanano/javanano_helpers.h
index cddc0777..753a4bd4 100644
--- a/src/google/protobuf/compiler/javanano/javanano_helpers.h
+++ b/src/google/protobuf/compiler/javanano/javanano_helpers.h
@@ -141,30 +141,37 @@ string DefaultValue(const Params& params, const FieldDescriptor* field);
// Methods for shared bitfields.
-// Gets the name of the shared bitfield for the given index.
+// Gets the name of the shared bitfield for the given field index.
string GetBitFieldName(int index);
// Gets the name of the shared bitfield for the given bit index.
// Effectively, GetBitFieldName(bit_index / 32)
string GetBitFieldNameForBit(int bit_index);
-// Generates the java code for the expression that returns the boolean value
-// of the bit of the shared bitfields for the given bit index.
-// Example: "((bitField1_ & 0x04) == 0x04)"
+// Generates the java code for the expression that returns whether the bit at
+// the given bit index is set.
+// Example: "((bitField1_ & 0x04000000) != 0)"
string GenerateGetBit(int bit_index);
-// Generates the java code for the expression that sets the bit of the shared
-// bitfields for the given bit index.
-// Example: "bitField1_ = (bitField1_ | 0x04)"
+// Generates the java code for the expression that sets the bit at the given
+// bit index.
+// Example: "bitField1_ |= 0x04000000"
string GenerateSetBit(int bit_index);
-// Generates the java code for the expression that clears the bit of the shared
-// bitfields for the given bit index.
-// Example: "bitField1_ = (bitField1_ & ~0x04)"
+// Generates the java code for the expression that clears the bit at the given
+// bit index.
+// Example: "bitField1_ = (bitField1_ & ~0x04000000)"
string GenerateClearBit(int bit_index);
-// Sets the 'get_*', 'set_*' and 'clear_*' variables, where * is the given bit
-// field name, to the appropriate Java expressions for the given bit index.
+// Generates the java code for the expression that returns whether the bit at
+// the given bit index contains different values in the current object and
+// another object accessible via the variable 'other'.
+// Example: "((bitField1_ & 0x04000000) != (other.bitField1_ & 0x04000000))"
+string GenerateDifferentBit(int bit_index);
+
+// Sets the 'get_*', 'set_*', 'clear_*' and 'different_*' variables, where * is
+// the given name of the bit, to the appropriate Java expressions for the given
+// bit index.
void SetBitOperationVariables(const string name,
int bitIndex, map<string, string>* variables);