michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */ michael@0: michael@0: #ifndef xptiinfo_h___ michael@0: #define xptiinfo_h___ michael@0: michael@0: #include "nscore.h" michael@0: #include "xpt_struct.h" michael@0: michael@0: class nsIInterfaceInfoManager; michael@0: michael@0: // Flyweight wrapper classes for xpt_struct.h structs. michael@0: // Everything here is dependent upon - and sensitive to changes in - michael@0: // xpcom/typelib/xpt/public/xpt_struct.h! michael@0: michael@0: class nsXPTType : public XPTTypeDescriptorPrefix michael@0: { michael@0: // NO DATA - this a flyweight wrapper michael@0: public: michael@0: nsXPTType() michael@0: {} // random contents michael@0: nsXPTType(const XPTTypeDescriptorPrefix& prefix) michael@0: {*(XPTTypeDescriptorPrefix*)this = prefix;} michael@0: michael@0: nsXPTType(const uint8_t& prefix) michael@0: {*(uint8_t*)this = prefix;} michael@0: michael@0: nsXPTType& operator=(uint8_t val) michael@0: {flags = val; return *this;} michael@0: michael@0: nsXPTType& operator=(const nsXPTType& other) michael@0: {flags = other.flags; return *this;} michael@0: michael@0: operator uint8_t() const michael@0: {return flags;} michael@0: michael@0: // 'Arithmetic' here roughly means that the value is self-contained and michael@0: // doesn't depend on anything else in memory (ie: not a pointer, not an michael@0: // XPCOM object, not a jsval, etc). michael@0: // michael@0: // Supposedly this terminology comes from Harbison/Steele, but it's still michael@0: // a rather crappy name. We'd change it if it wasn't used all over the michael@0: // place in xptcall. :-( michael@0: bool IsArithmetic() const michael@0: {return flags <= T_WCHAR;} michael@0: michael@0: // We used to abuse 'pointer' flag bit in typelib format quite extensively. michael@0: // We've gotten rid of most of the cases, but there's still a fair amount michael@0: // of refactoring to be done in XPCWrappedJSClass before we can safely stop michael@0: // asking about this. In the mean time, we've got a temporary version of michael@0: // IsPointer() that should be equivalent to what's in the typelib. michael@0: bool deprecated_IsPointer() const michael@0: {return !IsArithmetic() && TagPart() != T_JSVAL;} michael@0: michael@0: bool IsInterfacePointer() const michael@0: { switch (TagPart()) { michael@0: default: michael@0: return false; michael@0: case T_INTERFACE: michael@0: case T_INTERFACE_IS: michael@0: return true; michael@0: } michael@0: } michael@0: michael@0: bool IsArray() const michael@0: {return TagPart() == T_ARRAY;} michael@0: michael@0: // 'Dependent' means that params of this type are dependent upon other michael@0: // params. e.g. an T_INTERFACE_IS is dependent upon some other param at michael@0: // runtime to say what the interface type of this param really is. michael@0: bool IsDependent() const michael@0: { switch (TagPart()) { michael@0: default: michael@0: return false; michael@0: case T_INTERFACE_IS: michael@0: case TD_ARRAY: michael@0: case T_PSTRING_SIZE_IS: michael@0: case T_PWSTRING_SIZE_IS: michael@0: return true; michael@0: } michael@0: } michael@0: michael@0: uint8_t TagPart() const michael@0: {return (uint8_t) (flags & XPT_TDP_TAGMASK);} michael@0: michael@0: enum michael@0: { michael@0: T_I8 = TD_INT8 , michael@0: T_I16 = TD_INT16 , michael@0: T_I32 = TD_INT32 , michael@0: T_I64 = TD_INT64 , michael@0: T_U8 = TD_UINT8 , michael@0: T_U16 = TD_UINT16 , michael@0: T_U32 = TD_UINT32 , michael@0: T_U64 = TD_UINT64 , michael@0: T_FLOAT = TD_FLOAT , michael@0: T_DOUBLE = TD_DOUBLE , michael@0: T_BOOL = TD_BOOL , michael@0: T_CHAR = TD_CHAR , michael@0: T_WCHAR = TD_WCHAR , michael@0: T_VOID = TD_VOID , michael@0: T_IID = TD_PNSIID , michael@0: T_DOMSTRING = TD_DOMSTRING , michael@0: T_CHAR_STR = TD_PSTRING , michael@0: T_WCHAR_STR = TD_PWSTRING , michael@0: T_INTERFACE = TD_INTERFACE_TYPE , michael@0: T_INTERFACE_IS = TD_INTERFACE_IS_TYPE, michael@0: T_ARRAY = TD_ARRAY , michael@0: T_PSTRING_SIZE_IS = TD_PSTRING_SIZE_IS , michael@0: T_PWSTRING_SIZE_IS = TD_PWSTRING_SIZE_IS , michael@0: T_UTF8STRING = TD_UTF8STRING , michael@0: T_CSTRING = TD_CSTRING , michael@0: T_ASTRING = TD_ASTRING , michael@0: T_JSVAL = TD_JSVAL michael@0: }; michael@0: // NO DATA - this a flyweight wrapper michael@0: }; michael@0: michael@0: class nsXPTParamInfo : public XPTParamDescriptor michael@0: { michael@0: // NO DATA - this a flyweight wrapper michael@0: public: michael@0: nsXPTParamInfo(const XPTParamDescriptor& desc) michael@0: {*(XPTParamDescriptor*)this = desc;} michael@0: michael@0: michael@0: bool IsIn() const {return 0 != (XPT_PD_IS_IN(flags));} michael@0: bool IsOut() const {return 0 != (XPT_PD_IS_OUT(flags));} michael@0: bool IsRetval() const {return 0 != (XPT_PD_IS_RETVAL(flags));} michael@0: bool IsShared() const {return 0 != (XPT_PD_IS_SHARED(flags));} michael@0: bool IsDipper() const {return 0 != (XPT_PD_IS_DIPPER(flags));} michael@0: bool IsOptional() const {return 0 != (XPT_PD_IS_OPTIONAL(flags));} michael@0: const nsXPTType GetType() const {return type.prefix;} michael@0: michael@0: // Whether this parameter is passed indirectly on the stack. This mainly michael@0: // applies to out/inout params, but we use it unconditionally for certain michael@0: // types. michael@0: bool IsIndirect() const {return IsOut() || michael@0: GetType().TagPart() == nsXPTType::T_JSVAL;} michael@0: michael@0: // NOTE: other activities on types are done via methods on nsIInterfaceInfo michael@0: michael@0: private: michael@0: nsXPTParamInfo(); // no implementation michael@0: // NO DATA - this a flyweight wrapper michael@0: }; michael@0: michael@0: class nsXPTMethodInfo : public XPTMethodDescriptor michael@0: { michael@0: // NO DATA - this a flyweight wrapper michael@0: public: michael@0: nsXPTMethodInfo(const XPTMethodDescriptor& desc) michael@0: {*(XPTMethodDescriptor*)this = desc;} michael@0: michael@0: bool IsGetter() const {return 0 != (XPT_MD_IS_GETTER(flags) );} michael@0: bool IsSetter() const {return 0 != (XPT_MD_IS_SETTER(flags) );} michael@0: bool IsNotXPCOM() const {return 0 != (XPT_MD_IS_NOTXPCOM(flags));} michael@0: bool IsConstructor() const {return 0 != (XPT_MD_IS_CTOR(flags) );} michael@0: bool IsHidden() const {return 0 != (XPT_MD_IS_HIDDEN(flags) );} michael@0: bool WantsOptArgc() const {return 0 != (XPT_MD_WANTS_OPT_ARGC(flags));} michael@0: bool WantsContext() const {return 0 != (XPT_MD_WANTS_CONTEXT(flags));} michael@0: const char* GetName() const {return name;} michael@0: uint8_t GetParamCount() const {return num_args;} michael@0: /* idx was index before I got _sick_ of the warnings on Unix, sorry jband */ michael@0: const nsXPTParamInfo GetParam(uint8_t idx) const michael@0: { michael@0: NS_PRECONDITION(idx < GetParamCount(),"bad arg"); michael@0: return params[idx]; michael@0: } michael@0: const nsXPTParamInfo GetResult() const michael@0: {return result;} michael@0: private: michael@0: nsXPTMethodInfo(); // no implementation michael@0: // NO DATA - this a flyweight wrapper michael@0: }; michael@0: michael@0: michael@0: // forward declaration michael@0: struct nsXPTCMiniVariant; michael@0: michael@0: class nsXPTConstant : public XPTConstDescriptor michael@0: { michael@0: // NO DATA - this a flyweight wrapper michael@0: public: michael@0: nsXPTConstant(const XPTConstDescriptor& desc) michael@0: {*(XPTConstDescriptor*)this = desc;} michael@0: michael@0: const char* GetName() const michael@0: {return name;} michael@0: michael@0: const nsXPTType GetType() const michael@0: {return type.prefix;} michael@0: michael@0: // XXX this is ugly. But sometimes you gotta do what you gotta do. michael@0: // A reinterpret_cast won't do the trick here. And this plain C cast michael@0: // works correctly and is safe enough. michael@0: // See http://bugzilla.mozilla.org/show_bug.cgi?id=49641 michael@0: const nsXPTCMiniVariant* GetValue() const michael@0: {return (nsXPTCMiniVariant*) &value;} michael@0: private: michael@0: nsXPTConstant(); // no implementation michael@0: // NO DATA - this a flyweight wrapper michael@0: }; michael@0: michael@0: #endif /* xptiinfo_h___ */