Bug 1448454 - Make some fields in xpt_struct.h private. r=njn

Many of these fields have accessors, and can only be read indirectly
by going through the XPTHeader data structure anyways, so they should
be marked private. This makes the generated XPT data file noisier due
to the need for constexpr constructors.

I had to fix the ctors for the classes in xptinfo.h to be less weird
because there was a compiler error.

Members in two of the classes need to be marked protected because they
have subclasses in xptinfo.h. Ideally those classes would be merged
in.

MozReview-Commit-ID: 70IdFAhp5je

--HG--
extra : rebase_source : a2670a65ace291defc47845c4058477f0ae5360a
This commit is contained in:
Andrew McCreight 2018-03-26 14:06:01 -07:00
parent 3cd23bdc29
commit 7c9d910f6d
3 changed files with 100 additions and 26 deletions

View File

@ -119,9 +119,9 @@ class nsXPTParamInfo : public XPTParamDescriptor
{
// NO DATA - this a flyweight wrapper
public:
MOZ_IMPLICIT nsXPTParamInfo(const XPTParamDescriptor& desc)
{*(XPTParamDescriptor*)this = desc;}
MOZ_IMPLICIT nsXPTParamInfo(const XPTParamDescriptor& aDesc)
: XPTParamDescriptor(aDesc)
{}
bool IsIn() const {return !!(mFlags & kInMask);}
bool IsOut() const {return !!(mFlags & kOutMask);}
@ -185,8 +185,9 @@ class nsXPTMethodInfo : public XPTMethodDescriptor
{
// NO DATA - this a flyweight wrapper
public:
MOZ_IMPLICIT nsXPTMethodInfo(const XPTMethodDescriptor& desc)
{*(XPTMethodDescriptor*)this = desc;}
MOZ_IMPLICIT nsXPTMethodInfo(const XPTMethodDescriptor& aDesc)
: XPTMethodDescriptor(aDesc)
{}
bool IsGetter() const { return !!(mFlags & kGetterMask); }
bool IsSetter() const { return !!(mFlags & kSetterMask); }

View File

@ -436,7 +436,7 @@ class SimpleType(Type):
return s
def code_gen(self, typelib, cd):
return "{%s, 0, 0}" % self.typeDescriptorPrefixString()
return "XPTTypeDescriptor(%s)" % self.typeDescriptorPrefixString()
class InterfaceType(Type):
@ -497,7 +497,7 @@ class InterfaceType(Type):
index = typelib.interfaces.index(self.iface) + 1
hi = int(index / 256)
lo = index - (hi * 256)
return "{%s, %d, %d}" % (self.typeDescriptorPrefixString(), hi, lo)
return "XPTTypeDescriptor(%s, %d, %d)" % (self.typeDescriptorPrefixString(), hi, lo)
def __str__(self):
if self.iface:
@ -559,8 +559,8 @@ class InterfaceIsType(Type):
file.write(InterfaceIsType._descriptor.pack(self.param_index))
def code_gen(self, typelib, cd):
return "{%s, %d, 0}" % (self.typeDescriptorPrefixString(),
self.param_index)
return "XPTTypeDescriptor(%s, %d)" % (self.typeDescriptorPrefixString(),
self.param_index)
def __str__(self):
return "InterfaceIs *"
@ -624,9 +624,9 @@ class ArrayType(Type):
def code_gen(self, typelib, cd):
element_type_index = cd.add_type(self.element_type.code_gen(typelib, cd))
return "{%s, %d, %d}" % (self.typeDescriptorPrefixString(),
self.size_is_arg_num,
element_type_index)
return "XPTTypeDescriptor(%s, %d, %d)" % (self.typeDescriptorPrefixString(),
self.size_is_arg_num,
element_type_index)
def __str__(self):
return "%s []" % str(self.element_type)
@ -685,8 +685,8 @@ class StringWithSizeType(Type):
self.length_is_arg_num))
def code_gen(self, typelib, cd):
return "{%s, %d, 0}" % (self.typeDescriptorPrefixString(),
self.size_is_arg_num)
return "XPTTypeDescriptor(%s, %d)" % (self.typeDescriptorPrefixString(),
self.size_is_arg_num)
def __str__(self):
return "string_s"
@ -745,8 +745,8 @@ class WideStringWithSizeType(Type):
self.length_is_arg_num))
def code_gen(self, typelib, cd):
return "{%s, %d, 0}" % (self.typeDescriptorPrefixString(),
self.size_is_arg_num)
return "XPTTypeDescriptor(%s, %d)" % (self.typeDescriptorPrefixString(),
self.size_is_arg_num)
def __str__(self):
return "wstring_s"
@ -877,7 +877,7 @@ class Param(object):
self.type.write(typelib, file)
def code_gen(self, typelib, cd):
return "{0x%x, %s}" % (self.encodeflags(), self.type.code_gen(typelib, cd))
return "XPTParamDescriptor(0x%x, %s)" % (self.encodeflags(), self.type.code_gen(typelib, cd))
def prefix(self):
"""
@ -1070,10 +1070,10 @@ class Method(object):
param_index = cd.add_params([p.code_gen(typelib, cd) for p in self.params])
num_params = len(self.params)
return "{%d, %d, 0x%x, %d}" % (string_index,
param_index,
self.encodeflags(),
num_params)
return "XPTMethodDescriptor(%d, %d, 0x%x, %d)" % (string_index,
param_index,
self.encodeflags(),
num_params)
class Constant(object):
"""
@ -1153,10 +1153,10 @@ class Constant(object):
string_index = cd.add_string(self.name)
# The static cast is needed for disambiguation.
return "{%d, %s, XPTConstValue(static_cast<%s>(%d))}" % (string_index,
self.type.code_gen(typelib, cd),
Constant.memberTypeMap[self.type.tag],
self.value)
return "XPTConstDescriptor(%d, %s, XPTConstValue(static_cast<%s>(%d)))" % (string_index,
self.type.code_gen(typelib, cd),
Constant.memberTypeMap[self.type.tag],
self.value)
def __repr__(self):
return "Constant(%s, %s, %d)" % (self.name, str(self.type), self.value)
@ -1371,7 +1371,7 @@ class Interface(object):
assert len(self.constants) == 0
assert self.encodeflags() == 0
return "{%s, %s, %d, %d, %d, %d, %d, 0x%x} /* %s */" % (
return "XPTInterfaceDescriptor(%s, %s, %d, %d, %d, %d, %d, 0x%x) /* %s */" % (
iid,
string_index,
methods_index,

View File

@ -24,8 +24,15 @@ struct XPTTypeDescriptor;
struct XPTTypeDescriptorPrefix;
struct XPTHeader {
friend struct XPTInterfaceDescriptor;
friend struct XPTConstDescriptor;
friend struct XPTMethodDescriptor;
friend struct XPTTypeDescriptor;
static const uint16_t kNumInterfaces;
static const XPTInterfaceDescriptor kInterfaces[];
private:
static const XPTTypeDescriptor kTypes[];
static const XPTParamDescriptor kParams[];
static const XPTMethodDescriptor kMethods[];
@ -41,6 +48,24 @@ struct XPTHeader {
* its methods.
*/
struct XPTInterfaceDescriptor {
constexpr XPTInterfaceDescriptor(nsID aIID,
uint32_t aName,
uint16_t aMethodDescriptors,
uint16_t aConstDescriptors,
uint16_t aParentInterface,
uint16_t aNumMethods,
uint16_t aNumConstants,
uint8_t aFlags)
: mIID(aIID)
, mName(aName)
, mMethodDescriptors(aMethodDescriptors)
, mConstDescriptors(aConstDescriptors)
, mParentInterface(aParentInterface)
, mNumMethods(aNumMethods)
, mNumConstants(aNumConstants)
, mFlags(aFlags)
{}
static const uint8_t kScriptableMask = 0x80;
static const uint8_t kFunctionMask = 0x40;
static const uint8_t kBuiltinClassMask = 0x20;
@ -59,12 +84,18 @@ struct XPTInterfaceDescriptor {
* This field ordering minimizes the size of this struct.
*/
nsID mIID;
private:
uint32_t mName; // Index into XPTHeader::mStrings.
uint16_t mMethodDescriptors; // Index into XPTHeader::mMethods.
uint16_t mConstDescriptors; // Index into XPTHeader::mConsts.
public:
uint16_t mParentInterface;
uint16_t mNumMethods;
uint16_t mNumConstants;
private:
uint8_t mFlags;
};
@ -129,6 +160,14 @@ enum XPTTypeDescriptorTags {
};
struct XPTTypeDescriptor {
constexpr XPTTypeDescriptor(XPTTypeDescriptorPrefix aPrefix,
uint8_t aData1 = 0,
uint8_t aData2 = 0)
: mPrefix(aPrefix)
, mData1(aData1)
, mData2(aData2)
{}
uint8_t Tag() const {
return mPrefix.TagPart();
}
@ -156,6 +195,7 @@ struct XPTTypeDescriptor {
XPTTypeDescriptorPrefix mPrefix;
private:
// The data for the different variants is stored in these two data fields.
// These should only be accessed via the getter methods above, which will
// assert if the tag is invalid. The memory layout here doesn't exactly match
@ -190,11 +230,22 @@ union XPTConstValue {
};
struct XPTConstDescriptor {
constexpr XPTConstDescriptor(uint32_t aName,
const XPTTypeDescriptor& aType,
const XPTConstValue& aValue)
: mName(aName)
, mType(aType)
, mValue(aValue)
{}
const char* Name() const {
return &XPTHeader::kStrings[mName];
}
private:
uint32_t mName; // Index into XPTHeader::mStrings.
public:
XPTTypeDescriptor mType;
XPTConstValue mValue;
};
@ -204,7 +255,16 @@ struct XPTConstDescriptor {
* a method's result.
*/
struct XPTParamDescriptor {
constexpr XPTParamDescriptor(uint8_t aFlags,
const XPTTypeDescriptor& aType)
: mFlags(aFlags)
, mType(aType)
{}
protected:
uint8_t mFlags;
public:
XPTTypeDescriptor mType;
};
@ -212,6 +272,16 @@ struct XPTParamDescriptor {
* A MethodDescriptor is used to describe a single interface method.
*/
struct XPTMethodDescriptor {
constexpr XPTMethodDescriptor(uint32_t aName,
uint32_t aParams,
uint8_t aFlags,
uint8_t aNumArgs)
: mName(aName)
, mParams(aParams)
, mFlags(aFlags)
, mNumArgs(aNumArgs)
{}
const char* Name() const {
return &XPTHeader::kStrings[mName];
}
@ -219,8 +289,11 @@ struct XPTMethodDescriptor {
return XPTHeader::kParams[mParams + aIndex];
}
private:
uint32_t mName; // Index into XPTHeader::mStrings.
uint32_t mParams; // Index into XPTHeader::mParams.
protected:
uint8_t mFlags;
uint8_t mNumArgs;
};