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 -*- */
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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
* 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.
* http://www.mozilla.org/scriptable/typelib_file.html
*/
#ifndef __xpt_struct_h__
#define __xpt_struct_h__
#ifndef xpt_struct_h
#define xpt_struct_h
#include "xpt_arena.h"
#include "nsID.h"
@ -40,17 +40,17 @@ struct XPTTypeDescriptorPrefix;
* Every XPCOM typelib file begins with a header.
*/
struct XPTHeader {
// 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
// variables).
// 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
// variables).
//uint8_t magic[16];
uint8_t major_version;
uint8_t minor_version;
uint16_t num_interfaces;
//uint32_t file_length;
XPTInterfaceDirectoryEntry *interface_directory;
//uint32_t data_pool;
//uint8_t magic[16];
uint8_t major_version;
uint8_t minor_version;
uint16_t num_interfaces;
//uint32_t file_length;
XPTInterfaceDirectoryEntry* interface_directory;
//uint32_t data_pool;
};
#define XPT_MAGIC "XPCOM\nTypeLib\r\n\032"
@ -59,7 +59,8 @@ struct XPTHeader {
#define XPT_MAJOR_VERSION 0x01
#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
* 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
@ -77,14 +78,14 @@ struct XPTHeader {
* using its IID. No interface should appear more than once in the array.
*/
struct XPTInterfaceDirectoryEntry {
nsID iid;
char *name;
nsID iid;
char* name;
// This field exists in the on-disk format. But it isn't used so we don't
// allocate space for it in memory.
//char *name_space;
// This field exists in the on-disk format. But it isn't used so we don't
// allocate space for it in memory.
//char* name_space;
XPTInterfaceDescriptor *interface_descriptor;
XPTInterfaceDescriptor* interface_descriptor;
};
/*
@ -92,41 +93,43 @@ struct XPTInterfaceDirectoryEntry {
* its methods.
*/
struct XPTInterfaceDescriptor {
/* This field ordering minimizes the size of this struct.
* The fields are serialized on disk in a different order.
* See DoInterfaceDescriptor().
*/
XPTMethodDescriptor *method_descriptors;
XPTConstDescriptor *const_descriptors;
XPTTypeDescriptor *additional_types;
uint16_t parent_interface;
uint16_t num_methods;
uint16_t num_constants;
uint8_t flags;
/*
* This field ordering minimizes the size of this struct.
* The fields are serialized on disk in a different order.
* See DoInterfaceDescriptor().
*/
XPTMethodDescriptor* method_descriptors;
XPTConstDescriptor* const_descriptors;
XPTTypeDescriptor* additional_types;
uint16_t parent_interface;
uint16_t num_methods;
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
* want to have a simple array of XPTMethodDescriptor (each with a single
* embedded XPTTypeDescriptor), a XPTTypeDescriptor can have a reference
* to an 'additional_type'. That reference is an index in this
* "additional_types" array. So a given XPTMethodDescriptor might have
* 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
* of varying sizes, where in XPT's in memory mapping of the data we want
* them to be of fixed size. This additional_types scheme is here to allow
* for that.
*/
uint8_t num_additional_types;
/*
* additional_types are used for arrays where we may need multiple
* XPTTypeDescriptors for a single XPTMethodDescriptor. Since we still
* want to have a simple array of XPTMethodDescriptor (each with a single
* embedded XPTTypeDescriptor), a XPTTypeDescriptor can have a reference
* to an 'additional_type'. That reference is an index in this
* "additional_types" array. So a given XPTMethodDescriptor might have
* 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
* of varying sizes, where in XPT's in memory mapping of the data we want
* them to be of fixed size. This additional_types scheme is here to allow
* for that.
*/
uint8_t num_additional_types;
};
#define XPT_ID_SCRIPTABLE 0x80
#define XPT_ID_FUNCTION 0x40
#define XPT_ID_BUILTINCLASS 0x20
#define XPT_ID_SCRIPTABLE 0x80
#define XPT_ID_FUNCTION 0x40
#define XPT_ID_BUILTINCLASS 0x20
#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_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 */
struct XPTTypeDescriptorPrefix {
uint8_t flags;
uint8_t flags;
};
/* flag bits */
#define XPT_TDP_FLAGMASK 0xe0
#define XPT_TDP_TAGMASK (~XPT_TDP_FLAGMASK)
#define XPT_TDP_TAG(tdp) ((tdp).flags & XPT_TDP_TAGMASK)
#define XPT_TDP_FLAGMASK 0xe0
#define XPT_TDP_TAGMASK (~XPT_TDP_FLAGMASK)
#define XPT_TDP_TAG(tdp) ((tdp).flags & XPT_TDP_TAGMASK)
/*
* The following enum maps mnemonic names to the different numeric values
* of XPTTypeDescriptor->tag.
*/
enum XPTTypeDescriptorTags {
TD_INT8 = 0,
TD_INT16 = 1,
TD_INT32 = 2,
TD_INT64 = 3,
TD_UINT8 = 4,
TD_UINT16 = 5,
TD_UINT32 = 6,
TD_UINT64 = 7,
TD_FLOAT = 8,
TD_DOUBLE = 9,
TD_BOOL = 10,
TD_CHAR = 11,
TD_WCHAR = 12,
TD_VOID = 13,
TD_PNSIID = 14,
TD_DOMSTRING = 15,
TD_PSTRING = 16,
TD_PWSTRING = 17,
TD_INTERFACE_TYPE = 18,
TD_INTERFACE_IS_TYPE = 19,
TD_ARRAY = 20,
TD_PSTRING_SIZE_IS = 21,
TD_PWSTRING_SIZE_IS = 22,
TD_UTF8STRING = 23,
TD_CSTRING = 24,
TD_ASTRING = 25,
TD_JSVAL = 26
TD_INT8 = 0,
TD_INT16 = 1,
TD_INT32 = 2,
TD_INT64 = 3,
TD_UINT8 = 4,
TD_UINT16 = 5,
TD_UINT32 = 6,
TD_UINT64 = 7,
TD_FLOAT = 8,
TD_DOUBLE = 9,
TD_BOOL = 10,
TD_CHAR = 11,
TD_WCHAR = 12,
TD_VOID = 13,
TD_PNSIID = 14,
TD_DOMSTRING = 15,
TD_PSTRING = 16,
TD_PWSTRING = 17,
TD_INTERFACE_TYPE = 18,
TD_INTERFACE_IS_TYPE = 19,
TD_ARRAY = 20,
TD_PSTRING_SIZE_IS = 21,
TD_PWSTRING_SIZE_IS = 22,
TD_UTF8STRING = 23,
TD_CSTRING = 24,
TD_ASTRING = 25,
TD_JSVAL = 26
};
struct XPTTypeDescriptor {
XPTTypeDescriptorPrefix prefix;
XPTTypeDescriptorPrefix prefix;
// The memory layout here doesn't exactly match (for the appropriate types)
// the on-disk format. This is to save memory.
union {
// Used for TD_INTERFACE_IS_TYPE.
struct {
uint8_t argnum;
} interface_is;
// The memory layout here doesn't exactly match (for the appropriate types)
// the on-disk format. This is to save memory.
union {
// Used for TD_INTERFACE_IS_TYPE.
struct {
uint8_t argnum;
} interface_is;
// Used for TD_PSTRING_SIZE_IS, TD_PWSTRING_SIZE_IS.
struct {
uint8_t argnum;
//uint8_t argnum2; // Present on disk, omitted here.
} pstring_is;
// Used for TD_PSTRING_SIZE_IS, TD_PWSTRING_SIZE_IS.
struct {
uint8_t argnum;
//uint8_t argnum2; // Present on disk, omitted here.
} pstring_is;
// Used for TD_ARRAY.
struct {
uint8_t argnum;
//uint8_t argnum2; // Present on disk, omitted here.
uint8_t additional_type; // uint16_t on disk, uint8_t here;
// in practice it never exceeds 20.
} array;
// Used for TD_ARRAY.
struct {
uint8_t argnum;
//uint8_t argnum2; // Present on disk, omitted here.
uint8_t additional_type; // uint16_t on disk, uint8_t here;
// in practice it never exceeds 20.
} array;
// Used for TD_INTERFACE_TYPE.
struct {
// We store the 16-bit iface value as two 8-bit values in order to
// avoid 16-bit alignment requirements for XPTTypeDescriptor, which
// reduces its size and also the size of XPTParamDescriptor.
uint8_t iface_hi8;
uint8_t iface_lo8;
} iface;
} u;
// Used for TD_INTERFACE_TYPE.
struct {
// We store the 16-bit iface value as two 8-bit values in order to
// avoid 16-bit alignment requirements for XPTTypeDescriptor, which
// reduces its size and also the size of XPTParamDescriptor.
uint8_t iface_hi8;
uint8_t iface_lo8;
} iface;
} u;
};
/*
@ -242,16 +245,16 @@ struct XPTTypeDescriptor {
* 16-bit signed integer.
*/
union XPTConstValue {
int16_t i16;
uint16_t ui16;
int32_t i32;
uint32_t ui32;
int16_t i16;
uint16_t ui16;
int32_t i32;
uint32_t ui32;
}; /* varies according to type */
struct XPTConstDescriptor {
char *name;
XPTTypeDescriptor type;
union XPTConstValue value;
char* name;
XPTTypeDescriptor type;
union XPTConstValue value;
};
/*
@ -259,8 +262,8 @@ struct XPTConstDescriptor {
* single argument to a method or a method's result.
*/
struct XPTParamDescriptor {
uint8_t flags;
XPTTypeDescriptor type;
uint8_t flags;
XPTTypeDescriptor type;
};
/* flag bits */
@ -272,8 +275,8 @@ struct XPTParamDescriptor {
#define XPT_PD_OPTIONAL 0x04
#define XPT_PD_FLAGMASK 0xfc
#define XPT_PD_IS_IN(flags) (flags & XPT_PD_IN)
#define XPT_PD_IS_OUT(flags) (flags & XPT_PD_OUT)
#define XPT_PD_IS_IN(flags) (flags & XPT_PD_IN)
#define XPT_PD_IS_OUT(flags) (flags & XPT_PD_OUT)
#define XPT_PD_IS_RETVAL(flags) (flags & XPT_PD_RETVAL)
#define XPT_PD_IS_SHARED(flags) (flags & XPT_PD_SHARED)
#define XPT_PD_IS_DIPPER(flags) (flags & XPT_PD_DIPPER)
@ -284,11 +287,11 @@ struct XPTParamDescriptor {
* interface method.
*/
struct XPTMethodDescriptor {
char *name;
XPTParamDescriptor *params;
//XPTParamDescriptor result; // Present on disk, omitted here.
uint8_t flags;
uint8_t num_args;
char* name;
XPTParamDescriptor* params;
//XPTParamDescriptor result; // Present on disk, omitted here.
uint8_t flags;
uint8_t num_args;
};
/* flag bits */
@ -300,12 +303,12 @@ struct XPTMethodDescriptor {
#define XPT_MD_CONTEXT 0x02
#define XPT_MD_FLAGMASK 0xfe
#define XPT_MD_IS_GETTER(flags) (flags & XPT_MD_GETTER)
#define XPT_MD_IS_SETTER(flags) (flags & XPT_MD_SETTER)
#define XPT_MD_IS_NOTXPCOM(flags) (flags & XPT_MD_NOTXPCOM)
#define XPT_MD_IS_HIDDEN(flags) (flags & XPT_MD_HIDDEN)
#define XPT_MD_IS_GETTER(flags) (flags & XPT_MD_GETTER)
#define XPT_MD_IS_SETTER(flags) (flags & XPT_MD_SETTER)
#define XPT_MD_IS_NOTXPCOM(flags) (flags & XPT_MD_NOTXPCOM)
#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_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
@ -329,9 +332,10 @@ struct XPTMethodDescriptor {
* present.
*/
#define XPT_ANN_LAST 0x80
#define XPT_ANN_IS_LAST(flags) (flags & XPT_ANN_LAST)
#define XPT_ANN_PRIVATE 0x40
#define XPT_ANN_IS_PRIVATE(flags) (flags & XPT_ANN_PRIVATE)
#define XPT_ANN_LAST 0x80
#define XPT_ANN_PRIVATE 0x40
#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 */