xpcom/reflect/xptinfo/public/xptinfo.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/reflect/xptinfo/public/xptinfo.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
    1.10 +
    1.11 +#ifndef xptiinfo_h___
    1.12 +#define xptiinfo_h___
    1.13 +
    1.14 +#include "nscore.h"
    1.15 +#include "xpt_struct.h"
    1.16 +
    1.17 +class nsIInterfaceInfoManager;
    1.18 +
    1.19 +// Flyweight wrapper classes for xpt_struct.h structs. 
    1.20 +// Everything here is dependent upon - and sensitive to changes in -
    1.21 +// xpcom/typelib/xpt/public/xpt_struct.h!
    1.22 +
    1.23 +class nsXPTType : public XPTTypeDescriptorPrefix
    1.24 +{
    1.25 +// NO DATA - this a flyweight wrapper
    1.26 +public:
    1.27 +    nsXPTType()
    1.28 +        {}    // random contents
    1.29 +    nsXPTType(const XPTTypeDescriptorPrefix& prefix)
    1.30 +        {*(XPTTypeDescriptorPrefix*)this = prefix;}
    1.31 +
    1.32 +    nsXPTType(const uint8_t& prefix)
    1.33 +        {*(uint8_t*)this = prefix;}
    1.34 +
    1.35 +    nsXPTType& operator=(uint8_t val)
    1.36 +        {flags = val; return *this;}
    1.37 +
    1.38 +    nsXPTType& operator=(const nsXPTType& other)
    1.39 +        {flags = other.flags; return *this;}
    1.40 +
    1.41 +    operator uint8_t() const
    1.42 +        {return flags;}
    1.43 +
    1.44 +    // 'Arithmetic' here roughly means that the value is self-contained and
    1.45 +    // doesn't depend on anything else in memory (ie: not a pointer, not an
    1.46 +    // XPCOM object, not a jsval, etc).
    1.47 +    //
    1.48 +    // Supposedly this terminology comes from Harbison/Steele, but it's still
    1.49 +    // a rather crappy name. We'd change it if it wasn't used all over the
    1.50 +    // place in xptcall. :-(
    1.51 +    bool IsArithmetic() const
    1.52 +        {return flags <= T_WCHAR;}
    1.53 +
    1.54 +    // We used to abuse 'pointer' flag bit in typelib format quite extensively.
    1.55 +    // We've gotten rid of most of the cases, but there's still a fair amount
    1.56 +    // of refactoring to be done in XPCWrappedJSClass before we can safely stop
    1.57 +    // asking about this. In the mean time, we've got a temporary version of
    1.58 +    // IsPointer() that should be equivalent to what's in the typelib.
    1.59 +    bool deprecated_IsPointer() const
    1.60 +        {return !IsArithmetic() && TagPart() != T_JSVAL;}
    1.61 +
    1.62 +    bool IsInterfacePointer() const
    1.63 +        {  switch (TagPart()) {
    1.64 +             default:
    1.65 +               return false;
    1.66 +             case T_INTERFACE:
    1.67 +             case T_INTERFACE_IS:
    1.68 +               return true;
    1.69 +           }
    1.70 +        }
    1.71 +
    1.72 +    bool IsArray() const
    1.73 +        {return TagPart() == T_ARRAY;}
    1.74 +
    1.75 +    // 'Dependent' means that params of this type are dependent upon other 
    1.76 +    // params. e.g. an T_INTERFACE_IS is dependent upon some other param at 
    1.77 +    // runtime to say what the interface type of this param really is.
    1.78 +    bool IsDependent() const
    1.79 +        {  switch (TagPart()) {
    1.80 +             default:
    1.81 +               return false;
    1.82 +             case T_INTERFACE_IS:
    1.83 +             case TD_ARRAY:
    1.84 +             case T_PSTRING_SIZE_IS:
    1.85 +             case T_PWSTRING_SIZE_IS:
    1.86 +               return true;
    1.87 +           }
    1.88 +        }
    1.89 +
    1.90 +    uint8_t TagPart() const
    1.91 +        {return (uint8_t) (flags & XPT_TDP_TAGMASK);}
    1.92 +
    1.93 +    enum
    1.94 +    {
    1.95 +        T_I8                = TD_INT8             ,
    1.96 +        T_I16               = TD_INT16            ,
    1.97 +        T_I32               = TD_INT32            ,
    1.98 +        T_I64               = TD_INT64            ,
    1.99 +        T_U8                = TD_UINT8            ,
   1.100 +        T_U16               = TD_UINT16           ,
   1.101 +        T_U32               = TD_UINT32           ,
   1.102 +        T_U64               = TD_UINT64           ,
   1.103 +        T_FLOAT             = TD_FLOAT            ,
   1.104 +        T_DOUBLE            = TD_DOUBLE           ,
   1.105 +        T_BOOL              = TD_BOOL             ,
   1.106 +        T_CHAR              = TD_CHAR             ,
   1.107 +        T_WCHAR             = TD_WCHAR            ,
   1.108 +        T_VOID              = TD_VOID             ,
   1.109 +        T_IID               = TD_PNSIID           ,
   1.110 +        T_DOMSTRING         = TD_DOMSTRING        ,
   1.111 +        T_CHAR_STR          = TD_PSTRING          ,
   1.112 +        T_WCHAR_STR         = TD_PWSTRING         ,
   1.113 +        T_INTERFACE         = TD_INTERFACE_TYPE   ,
   1.114 +        T_INTERFACE_IS      = TD_INTERFACE_IS_TYPE,
   1.115 +        T_ARRAY             = TD_ARRAY            ,
   1.116 +        T_PSTRING_SIZE_IS   = TD_PSTRING_SIZE_IS  ,
   1.117 +        T_PWSTRING_SIZE_IS  = TD_PWSTRING_SIZE_IS ,
   1.118 +        T_UTF8STRING        = TD_UTF8STRING       ,
   1.119 +        T_CSTRING           = TD_CSTRING          ,
   1.120 +        T_ASTRING           = TD_ASTRING          ,
   1.121 +        T_JSVAL             = TD_JSVAL
   1.122 +    };
   1.123 +// NO DATA - this a flyweight wrapper
   1.124 +};
   1.125 +
   1.126 +class nsXPTParamInfo : public XPTParamDescriptor
   1.127 +{
   1.128 +// NO DATA - this a flyweight wrapper
   1.129 +public:
   1.130 +    nsXPTParamInfo(const XPTParamDescriptor& desc)
   1.131 +        {*(XPTParamDescriptor*)this = desc;}
   1.132 +
   1.133 +
   1.134 +    bool IsIn()  const    {return 0 != (XPT_PD_IS_IN(flags));}
   1.135 +    bool IsOut() const    {return 0 != (XPT_PD_IS_OUT(flags));}
   1.136 +    bool IsRetval() const {return 0 != (XPT_PD_IS_RETVAL(flags));}
   1.137 +    bool IsShared() const {return 0 != (XPT_PD_IS_SHARED(flags));}
   1.138 +    bool IsDipper() const {return 0 != (XPT_PD_IS_DIPPER(flags));}
   1.139 +    bool IsOptional() const {return 0 != (XPT_PD_IS_OPTIONAL(flags));}
   1.140 +    const nsXPTType GetType() const {return type.prefix;}
   1.141 +
   1.142 +    // Whether this parameter is passed indirectly on the stack. This mainly
   1.143 +    // applies to out/inout params, but we use it unconditionally for certain
   1.144 +    // types.
   1.145 +    bool IsIndirect() const {return IsOut() ||
   1.146 +                               GetType().TagPart() == nsXPTType::T_JSVAL;}
   1.147 +
   1.148 +    // NOTE: other activities on types are done via methods on nsIInterfaceInfo
   1.149 +
   1.150 +private:
   1.151 +    nsXPTParamInfo();   // no implementation
   1.152 +// NO DATA - this a flyweight wrapper
   1.153 +};
   1.154 +
   1.155 +class nsXPTMethodInfo : public XPTMethodDescriptor
   1.156 +{
   1.157 +// NO DATA - this a flyweight wrapper
   1.158 +public:
   1.159 +    nsXPTMethodInfo(const XPTMethodDescriptor& desc)
   1.160 +        {*(XPTMethodDescriptor*)this = desc;}
   1.161 +
   1.162 +    bool IsGetter()      const {return 0 != (XPT_MD_IS_GETTER(flags) );}
   1.163 +    bool IsSetter()      const {return 0 != (XPT_MD_IS_SETTER(flags) );}
   1.164 +    bool IsNotXPCOM()    const {return 0 != (XPT_MD_IS_NOTXPCOM(flags));}
   1.165 +    bool IsConstructor() const {return 0 != (XPT_MD_IS_CTOR(flags)   );}
   1.166 +    bool IsHidden()      const {return 0 != (XPT_MD_IS_HIDDEN(flags) );}
   1.167 +    bool WantsOptArgc()  const {return 0 != (XPT_MD_WANTS_OPT_ARGC(flags));}
   1.168 +    bool WantsContext()  const {return 0 != (XPT_MD_WANTS_CONTEXT(flags));}
   1.169 +    const char* GetName()  const {return name;}
   1.170 +    uint8_t GetParamCount()  const {return num_args;}
   1.171 +    /* idx was index before I got _sick_ of the warnings on Unix, sorry jband */
   1.172 +    const nsXPTParamInfo GetParam(uint8_t idx) const
   1.173 +        {
   1.174 +            NS_PRECONDITION(idx < GetParamCount(),"bad arg");
   1.175 +            return params[idx];
   1.176 +        }
   1.177 +    const nsXPTParamInfo GetResult() const
   1.178 +        {return result;}
   1.179 +private:
   1.180 +    nsXPTMethodInfo();  // no implementation
   1.181 +// NO DATA - this a flyweight wrapper
   1.182 +};
   1.183 +
   1.184 +
   1.185 +// forward declaration
   1.186 +struct nsXPTCMiniVariant;
   1.187 +
   1.188 +class nsXPTConstant : public XPTConstDescriptor
   1.189 +{
   1.190 +// NO DATA - this a flyweight wrapper
   1.191 +public:
   1.192 +    nsXPTConstant(const XPTConstDescriptor& desc)
   1.193 +        {*(XPTConstDescriptor*)this = desc;}
   1.194 +
   1.195 +    const char* GetName() const
   1.196 +        {return name;}
   1.197 +
   1.198 +    const nsXPTType GetType() const
   1.199 +        {return type.prefix;}
   1.200 +
   1.201 +    // XXX this is ugly. But sometimes you gotta do what you gotta do.
   1.202 +    // A reinterpret_cast won't do the trick here. And this plain C cast
   1.203 +    // works correctly and is safe enough.
   1.204 +    // See http://bugzilla.mozilla.org/show_bug.cgi?id=49641
   1.205 +    const nsXPTCMiniVariant* GetValue() const
   1.206 +        {return (nsXPTCMiniVariant*) &value;}
   1.207 +private:
   1.208 +    nsXPTConstant();    // no implementation
   1.209 +// NO DATA - this a flyweight wrapper
   1.210 +};
   1.211 +
   1.212 +#endif /* xptiinfo_h___ */

mercurial