Bug 1441677, part 1 - Fix spacing in xpt_struct.h. r=njn

This makes the file 2-space indented, gets rid of padding between
types and members, moves the * to the left, fixes the mode line,
license and include guards, and fixes up the first line of some of the
multiline comments. I also reordered the XPT_ANN macros to be more
consistent.

I left the padding alone for the enum-like bit flag values, as I think
it makes sense to line those up.

MozReview-Commit-ID: 877aP5eGIFm

--HG--
extra : rebase_source : 6d47ce05b47248c285597454af528ca1ae2cc830
This commit is contained in:
Andrew McCreight 2018-02-27 08:32:57 -08:00
Родитель f1a425d86c
Коммит e5a771106e
1 изменённых файлов: 143 добавлений и 139 удалений

Просмотреть файл

@ -1,16 +1,16 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=4 et sw=4 tw=80: */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/* /*
* Structures matching the in-memory representation of typelib structures. * Structures matching the in-memory representation of typelib structures.
* http://www.mozilla.org/scriptable/typelib_file.html * http://www.mozilla.org/scriptable/typelib_file.html
*/ */
#ifndef __xpt_struct_h__ #ifndef xpt_struct_h
#define __xpt_struct_h__ #define xpt_struct_h
#include "xpt_arena.h" #include "xpt_arena.h"
#include "nsID.h" #include "nsID.h"
@ -40,17 +40,17 @@ struct XPTTypeDescriptorPrefix;
* Every XPCOM typelib file begins with a header. * Every XPCOM typelib file begins with a header.
*/ */
struct XPTHeader { struct XPTHeader {
// Some of these fields exists in the on-disk format but don't need to be // Some of these fields exists in the on-disk format but don't need to be
// stored in memory (other than very briefly, which can be done with local // stored in memory (other than very briefly, which can be done with local
// variables). // variables).
//uint8_t magic[16]; //uint8_t magic[16];
uint8_t major_version; uint8_t major_version;
uint8_t minor_version; uint8_t minor_version;
uint16_t num_interfaces; uint16_t num_interfaces;
//uint32_t file_length; //uint32_t file_length;
XPTInterfaceDirectoryEntry *interface_directory; XPTInterfaceDirectoryEntry* interface_directory;
//uint32_t data_pool; //uint32_t data_pool;
}; };
#define XPT_MAGIC "XPCOM\nTypeLib\r\n\032" #define XPT_MAGIC "XPCOM\nTypeLib\r\n\032"
@ -59,7 +59,8 @@ struct XPTHeader {
#define XPT_MAJOR_VERSION 0x01 #define XPT_MAJOR_VERSION 0x01
#define XPT_MINOR_VERSION 0x02 #define XPT_MINOR_VERSION 0x02
/* Any file with a major version number of XPT_MAJOR_INCOMPATIBLE_VERSION /*
* Any file with a major version number of XPT_MAJOR_INCOMPATIBLE_VERSION
* or higher is to be considered incompatible by this version of xpt and * or higher is to be considered incompatible by this version of xpt and
* we will refuse to read it. We will return a header with magic, major and * we will refuse to read it. We will return a header with magic, major and
* minor versions set from the file. num_interfaces will be set to zero to * minor versions set from the file. num_interfaces will be set to zero to
@ -77,14 +78,14 @@ struct XPTHeader {
* using its IID. No interface should appear more than once in the array. * using its IID. No interface should appear more than once in the array.
*/ */
struct XPTInterfaceDirectoryEntry { struct XPTInterfaceDirectoryEntry {
nsID iid; nsID iid;
char *name; char* name;
// This field exists in the on-disk format. But it isn't used so we don't // This field exists in the on-disk format. But it isn't used so we don't
// allocate space for it in memory. // allocate space for it in memory.
//char *name_space; //char* name_space;
XPTInterfaceDescriptor *interface_descriptor; XPTInterfaceDescriptor* interface_descriptor;
}; };
/* /*
@ -92,41 +93,43 @@ struct XPTInterfaceDirectoryEntry {
* its methods. * its methods.
*/ */
struct XPTInterfaceDescriptor { struct XPTInterfaceDescriptor {
/* This field ordering minimizes the size of this struct. /*
* The fields are serialized on disk in a different order. * This field ordering minimizes the size of this struct.
* See DoInterfaceDescriptor(). * The fields are serialized on disk in a different order.
*/ * See DoInterfaceDescriptor().
XPTMethodDescriptor *method_descriptors; */
XPTConstDescriptor *const_descriptors; XPTMethodDescriptor* method_descriptors;
XPTTypeDescriptor *additional_types; XPTConstDescriptor* const_descriptors;
uint16_t parent_interface; XPTTypeDescriptor* additional_types;
uint16_t num_methods; uint16_t parent_interface;
uint16_t num_constants; uint16_t num_methods;
uint8_t flags; uint16_t num_constants;
uint8_t flags;
/* additional_types are used for arrays where we may need multiple /*
* XPTTypeDescriptors for a single XPTMethodDescriptor. Since we still * additional_types are used for arrays where we may need multiple
* want to have a simple array of XPTMethodDescriptor (each with a single * XPTTypeDescriptors for a single XPTMethodDescriptor. Since we still
* embedded XPTTypeDescriptor), a XPTTypeDescriptor can have a reference * want to have a simple array of XPTMethodDescriptor (each with a single
* to an 'additional_type'. That reference is an index in this * embedded XPTTypeDescriptor), a XPTTypeDescriptor can have a reference
* "additional_types" array. So a given XPTMethodDescriptor might have * to an 'additional_type'. That reference is an index in this
* a whole chain of these XPTTypeDescriptors to represent, say, a multi * "additional_types" array. So a given XPTMethodDescriptor might have
* dimensional array. * a whole chain of these XPTTypeDescriptors to represent, say, a multi
* * dimensional array.
* Note that in the typelib file these additional types are stored 'inline' *
* in the MethodDescriptor. But, in the typelib MethodDescriptors can be * Note that in the typelib file these additional types are stored 'inline'
* of varying sizes, where in XPT's in memory mapping of the data we want * in the MethodDescriptor. But, in the typelib MethodDescriptors can be
* them to be of fixed size. This additional_types scheme is here to allow * of varying sizes, where in XPT's in memory mapping of the data we want
* for that. * them to be of fixed size. This additional_types scheme is here to allow
*/ * for that.
uint8_t num_additional_types; */
uint8_t num_additional_types;
}; };
#define XPT_ID_SCRIPTABLE 0x80 #define XPT_ID_SCRIPTABLE 0x80
#define XPT_ID_FUNCTION 0x40 #define XPT_ID_FUNCTION 0x40
#define XPT_ID_BUILTINCLASS 0x20 #define XPT_ID_BUILTINCLASS 0x20
#define XPT_ID_MAIN_PROCESS_SCRIPTABLE_ONLY 0x10 #define XPT_ID_MAIN_PROCESS_SCRIPTABLE_ONLY 0x10
#define XPT_ID_FLAGMASK 0xf0 #define XPT_ID_FLAGMASK 0xf0
#define XPT_ID_IS_SCRIPTABLE(flags) (!!(flags & XPT_ID_SCRIPTABLE)) #define XPT_ID_IS_SCRIPTABLE(flags) (!!(flags & XPT_ID_SCRIPTABLE))
#define XPT_ID_IS_FUNCTION(flags) (!!(flags & XPT_ID_FUNCTION)) #define XPT_ID_IS_FUNCTION(flags) (!!(flags & XPT_ID_FUNCTION))
@ -152,83 +155,83 @@ struct XPTInterfaceDescriptor {
/* why bother with a struct? - other code relies on this being a struct */ /* why bother with a struct? - other code relies on this being a struct */
struct XPTTypeDescriptorPrefix { struct XPTTypeDescriptorPrefix {
uint8_t flags; uint8_t flags;
}; };
/* flag bits */ /* flag bits */
#define XPT_TDP_FLAGMASK 0xe0 #define XPT_TDP_FLAGMASK 0xe0
#define XPT_TDP_TAGMASK (~XPT_TDP_FLAGMASK) #define XPT_TDP_TAGMASK (~XPT_TDP_FLAGMASK)
#define XPT_TDP_TAG(tdp) ((tdp).flags & XPT_TDP_TAGMASK) #define XPT_TDP_TAG(tdp) ((tdp).flags & XPT_TDP_TAGMASK)
/* /*
* The following enum maps mnemonic names to the different numeric values * The following enum maps mnemonic names to the different numeric values
* of XPTTypeDescriptor->tag. * of XPTTypeDescriptor->tag.
*/ */
enum XPTTypeDescriptorTags { enum XPTTypeDescriptorTags {
TD_INT8 = 0, TD_INT8 = 0,
TD_INT16 = 1, TD_INT16 = 1,
TD_INT32 = 2, TD_INT32 = 2,
TD_INT64 = 3, TD_INT64 = 3,
TD_UINT8 = 4, TD_UINT8 = 4,
TD_UINT16 = 5, TD_UINT16 = 5,
TD_UINT32 = 6, TD_UINT32 = 6,
TD_UINT64 = 7, TD_UINT64 = 7,
TD_FLOAT = 8, TD_FLOAT = 8,
TD_DOUBLE = 9, TD_DOUBLE = 9,
TD_BOOL = 10, TD_BOOL = 10,
TD_CHAR = 11, TD_CHAR = 11,
TD_WCHAR = 12, TD_WCHAR = 12,
TD_VOID = 13, TD_VOID = 13,
TD_PNSIID = 14, TD_PNSIID = 14,
TD_DOMSTRING = 15, TD_DOMSTRING = 15,
TD_PSTRING = 16, TD_PSTRING = 16,
TD_PWSTRING = 17, TD_PWSTRING = 17,
TD_INTERFACE_TYPE = 18, TD_INTERFACE_TYPE = 18,
TD_INTERFACE_IS_TYPE = 19, TD_INTERFACE_IS_TYPE = 19,
TD_ARRAY = 20, TD_ARRAY = 20,
TD_PSTRING_SIZE_IS = 21, TD_PSTRING_SIZE_IS = 21,
TD_PWSTRING_SIZE_IS = 22, TD_PWSTRING_SIZE_IS = 22,
TD_UTF8STRING = 23, TD_UTF8STRING = 23,
TD_CSTRING = 24, TD_CSTRING = 24,
TD_ASTRING = 25, TD_ASTRING = 25,
TD_JSVAL = 26 TD_JSVAL = 26
}; };
struct XPTTypeDescriptor { struct XPTTypeDescriptor {
XPTTypeDescriptorPrefix prefix; XPTTypeDescriptorPrefix prefix;
// The memory layout here doesn't exactly match (for the appropriate types) // The memory layout here doesn't exactly match (for the appropriate types)
// the on-disk format. This is to save memory. // the on-disk format. This is to save memory.
union { union {
// Used for TD_INTERFACE_IS_TYPE. // Used for TD_INTERFACE_IS_TYPE.
struct { struct {
uint8_t argnum; uint8_t argnum;
} interface_is; } interface_is;
// Used for TD_PSTRING_SIZE_IS, TD_PWSTRING_SIZE_IS. // Used for TD_PSTRING_SIZE_IS, TD_PWSTRING_SIZE_IS.
struct { struct {
uint8_t argnum; uint8_t argnum;
//uint8_t argnum2; // Present on disk, omitted here. //uint8_t argnum2; // Present on disk, omitted here.
} pstring_is; } pstring_is;
// Used for TD_ARRAY. // Used for TD_ARRAY.
struct { struct {
uint8_t argnum; uint8_t argnum;
//uint8_t argnum2; // Present on disk, omitted here. //uint8_t argnum2; // Present on disk, omitted here.
uint8_t additional_type; // uint16_t on disk, uint8_t here; uint8_t additional_type; // uint16_t on disk, uint8_t here;
// in practice it never exceeds 20. // in practice it never exceeds 20.
} array; } array;
// Used for TD_INTERFACE_TYPE. // Used for TD_INTERFACE_TYPE.
struct { struct {
// We store the 16-bit iface value as two 8-bit values in order to // We store the 16-bit iface value as two 8-bit values in order to
// avoid 16-bit alignment requirements for XPTTypeDescriptor, which // avoid 16-bit alignment requirements for XPTTypeDescriptor, which
// reduces its size and also the size of XPTParamDescriptor. // reduces its size and also the size of XPTParamDescriptor.
uint8_t iface_hi8; uint8_t iface_hi8;
uint8_t iface_lo8; uint8_t iface_lo8;
} iface; } iface;
} u; } u;
}; };
/* /*
@ -242,16 +245,16 @@ struct XPTTypeDescriptor {
* 16-bit signed integer. * 16-bit signed integer.
*/ */
union XPTConstValue { union XPTConstValue {
int16_t i16; int16_t i16;
uint16_t ui16; uint16_t ui16;
int32_t i32; int32_t i32;
uint32_t ui32; uint32_t ui32;
}; /* varies according to type */ }; /* varies according to type */
struct XPTConstDescriptor { struct XPTConstDescriptor {
char *name; char* name;
XPTTypeDescriptor type; XPTTypeDescriptor type;
union XPTConstValue value; union XPTConstValue value;
}; };
/* /*
@ -259,8 +262,8 @@ struct XPTConstDescriptor {
* single argument to a method or a method's result. * single argument to a method or a method's result.
*/ */
struct XPTParamDescriptor { struct XPTParamDescriptor {
uint8_t flags; uint8_t flags;
XPTTypeDescriptor type; XPTTypeDescriptor type;
}; };
/* flag bits */ /* flag bits */
@ -272,8 +275,8 @@ struct XPTParamDescriptor {
#define XPT_PD_OPTIONAL 0x04 #define XPT_PD_OPTIONAL 0x04
#define XPT_PD_FLAGMASK 0xfc #define XPT_PD_FLAGMASK 0xfc
#define XPT_PD_IS_IN(flags) (flags & XPT_PD_IN) #define XPT_PD_IS_IN(flags) (flags & XPT_PD_IN)
#define XPT_PD_IS_OUT(flags) (flags & XPT_PD_OUT) #define XPT_PD_IS_OUT(flags) (flags & XPT_PD_OUT)
#define XPT_PD_IS_RETVAL(flags) (flags & XPT_PD_RETVAL) #define XPT_PD_IS_RETVAL(flags) (flags & XPT_PD_RETVAL)
#define XPT_PD_IS_SHARED(flags) (flags & XPT_PD_SHARED) #define XPT_PD_IS_SHARED(flags) (flags & XPT_PD_SHARED)
#define XPT_PD_IS_DIPPER(flags) (flags & XPT_PD_DIPPER) #define XPT_PD_IS_DIPPER(flags) (flags & XPT_PD_DIPPER)
@ -284,11 +287,11 @@ struct XPTParamDescriptor {
* interface method. * interface method.
*/ */
struct XPTMethodDescriptor { struct XPTMethodDescriptor {
char *name; char* name;
XPTParamDescriptor *params; XPTParamDescriptor* params;
//XPTParamDescriptor result; // Present on disk, omitted here. //XPTParamDescriptor result; // Present on disk, omitted here.
uint8_t flags; uint8_t flags;
uint8_t num_args; uint8_t num_args;
}; };
/* flag bits */ /* flag bits */
@ -300,12 +303,12 @@ struct XPTMethodDescriptor {
#define XPT_MD_CONTEXT 0x02 #define XPT_MD_CONTEXT 0x02
#define XPT_MD_FLAGMASK 0xfe #define XPT_MD_FLAGMASK 0xfe
#define XPT_MD_IS_GETTER(flags) (flags & XPT_MD_GETTER) #define XPT_MD_IS_GETTER(flags) (flags & XPT_MD_GETTER)
#define XPT_MD_IS_SETTER(flags) (flags & XPT_MD_SETTER) #define XPT_MD_IS_SETTER(flags) (flags & XPT_MD_SETTER)
#define XPT_MD_IS_NOTXPCOM(flags) (flags & XPT_MD_NOTXPCOM) #define XPT_MD_IS_NOTXPCOM(flags) (flags & XPT_MD_NOTXPCOM)
#define XPT_MD_IS_HIDDEN(flags) (flags & XPT_MD_HIDDEN) #define XPT_MD_IS_HIDDEN(flags) (flags & XPT_MD_HIDDEN)
#define XPT_MD_WANTS_OPT_ARGC(flags) (flags & XPT_MD_OPT_ARGC) #define XPT_MD_WANTS_OPT_ARGC(flags) (flags & XPT_MD_OPT_ARGC)
#define XPT_MD_WANTS_CONTEXT(flags) (flags & XPT_MD_CONTEXT) #define XPT_MD_WANTS_CONTEXT(flags) (flags & XPT_MD_CONTEXT)
/* /*
* Annotation records are variable-size records used to store secondary * Annotation records are variable-size records used to store secondary
@ -329,9 +332,10 @@ struct XPTMethodDescriptor {
* present. * present.
*/ */
#define XPT_ANN_LAST 0x80 #define XPT_ANN_LAST 0x80
#define XPT_ANN_IS_LAST(flags) (flags & XPT_ANN_LAST) #define XPT_ANN_PRIVATE 0x40
#define XPT_ANN_PRIVATE 0x40
#define XPT_ANN_IS_PRIVATE(flags) (flags & XPT_ANN_PRIVATE)
#endif /* __xpt_struct_h__ */ #define XPT_ANN_IS_LAST(flags) (flags & XPT_ANN_LAST)
#define XPT_ANN_IS_PRIVATE(flags)(flags & XPT_ANN_PRIVATE)
#endif /* xpt_struct_h */