Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : /* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
7 :
8 : #ifndef xptiinfo_h___
9 : #define xptiinfo_h___
10 :
11 : #include "nscore.h"
12 : #include "xpt_struct.h"
13 :
14 : // Flyweight wrapper classes for xpt_struct.h structs.
15 : // Everything here is dependent upon - and sensitive to changes in -
16 : // xpcom/typelib/xpt/xpt_struct.h!
17 :
18 : class nsXPTType : public XPTTypeDescriptorPrefix
19 : {
20 : // NO DATA - this a flyweight wrapper
21 : public:
22 38412 : nsXPTType()
23 38412 : {} // random contents
24 151299 : MOZ_IMPLICIT nsXPTType(const XPTTypeDescriptorPrefix& prefix)
25 151299 : {*(XPTTypeDescriptorPrefix*)this = prefix;}
26 :
27 142 : MOZ_IMPLICIT nsXPTType(const uint8_t& prefix)
28 142 : {*(uint8_t*)this = prefix;}
29 :
30 3401 : nsXPTType& operator=(uint8_t val)
31 3401 : {flags = val; return *this;}
32 :
33 35034 : nsXPTType& operator=(const nsXPTType& other)
34 35034 : {flags = other.flags; return *this;}
35 :
36 53422 : operator uint8_t() const
37 53422 : {return flags;}
38 :
39 : // 'Arithmetic' here roughly means that the value is self-contained and
40 : // doesn't depend on anything else in memory (ie: not a pointer, not an
41 : // XPCOM object, not a jsval, etc).
42 : //
43 : // Supposedly this terminology comes from Harbison/Steele, but it's still
44 : // a rather crappy name. We'd change it if it wasn't used all over the
45 : // place in xptcall. :-(
46 34288 : bool IsArithmetic() const
47 34288 : {return flags <= T_WCHAR;}
48 :
49 : // We used to abuse 'pointer' flag bit in typelib format quite extensively.
50 : // We've gotten rid of most of the cases, but there's still a fair amount
51 : // of refactoring to be done in XPCWrappedJSClass before we can safely stop
52 : // asking about this. In the mean time, we've got a temporary version of
53 : // IsPointer() that should be equivalent to what's in the typelib.
54 234 : bool deprecated_IsPointer() const
55 234 : {return !IsArithmetic() && TagPart() != T_JSVAL;}
56 :
57 9968 : bool IsInterfacePointer() const
58 9968 : { switch (TagPart()) {
59 : default:
60 7192 : return false;
61 : case T_INTERFACE:
62 : case T_INTERFACE_IS:
63 2776 : return true;
64 : }
65 : }
66 :
67 34984 : bool IsArray() const
68 34984 : {return TagPart() == T_ARRAY;}
69 :
70 : // 'Dependent' means that params of this type are dependent upon other
71 : // params. e.g. an T_INTERFACE_IS is dependent upon some other param at
72 : // runtime to say what the interface type of this param really is.
73 25631 : bool IsDependent() const
74 25631 : { switch (TagPart()) {
75 : default:
76 25347 : return false;
77 : case T_INTERFACE_IS:
78 : case TD_ARRAY:
79 : case T_PSTRING_SIZE_IS:
80 : case T_PWSTRING_SIZE_IS:
81 284 : return true;
82 : }
83 : }
84 :
85 266098 : uint8_t TagPart() const
86 266098 : {return (uint8_t) (flags & XPT_TDP_TAGMASK);}
87 :
88 : enum
89 : {
90 : T_I8 = TD_INT8 ,
91 : T_I16 = TD_INT16 ,
92 : T_I32 = TD_INT32 ,
93 : T_I64 = TD_INT64 ,
94 : T_U8 = TD_UINT8 ,
95 : T_U16 = TD_UINT16 ,
96 : T_U32 = TD_UINT32 ,
97 : T_U64 = TD_UINT64 ,
98 : T_FLOAT = TD_FLOAT ,
99 : T_DOUBLE = TD_DOUBLE ,
100 : T_BOOL = TD_BOOL ,
101 : T_CHAR = TD_CHAR ,
102 : T_WCHAR = TD_WCHAR ,
103 : T_VOID = TD_VOID ,
104 : T_IID = TD_PNSIID ,
105 : T_DOMSTRING = TD_DOMSTRING ,
106 : T_CHAR_STR = TD_PSTRING ,
107 : T_WCHAR_STR = TD_PWSTRING ,
108 : T_INTERFACE = TD_INTERFACE_TYPE ,
109 : T_INTERFACE_IS = TD_INTERFACE_IS_TYPE,
110 : T_ARRAY = TD_ARRAY ,
111 : T_PSTRING_SIZE_IS = TD_PSTRING_SIZE_IS ,
112 : T_PWSTRING_SIZE_IS = TD_PWSTRING_SIZE_IS ,
113 : T_UTF8STRING = TD_UTF8STRING ,
114 : T_CSTRING = TD_CSTRING ,
115 : T_ASTRING = TD_ASTRING ,
116 : T_JSVAL = TD_JSVAL
117 : };
118 : // NO DATA - this a flyweight wrapper
119 : };
120 :
121 : class nsXPTParamInfo : public XPTParamDescriptor
122 : {
123 : // NO DATA - this a flyweight wrapper
124 : public:
125 167000 : MOZ_IMPLICIT nsXPTParamInfo(const XPTParamDescriptor& desc)
126 167000 : {*(XPTParamDescriptor*)this = desc;}
127 :
128 :
129 26206 : bool IsIn() const {return 0 != (XPT_PD_IS_IN(flags));}
130 95197 : bool IsOut() const {return 0 != (XPT_PD_IS_OUT(flags));}
131 32058 : bool IsRetval() const {return 0 != (XPT_PD_IS_RETVAL(flags));}
132 26512 : bool IsShared() const {return 0 != (XPT_PD_IS_SHARED(flags));}
133 :
134 : // Dipper types are one of the more inscrutable aspects of xpidl. In a
135 : // nutshell, dippers are empty container objects, created and passed by
136 : // the caller, and filled by the callee. The callee receives a fully-
137 : // formed object, and thus does not have to construct anything. But
138 : // the object is functionally empty, and the callee is responsible for
139 : // putting something useful inside of it.
140 : //
141 : // XPIDL decides which types to make dippers. The list of these types
142 : // is given in the isDipperType() function in typelib.py, and is currently
143 : // limited to 4 string types.
144 : //
145 : // When a dipper type is declared as an 'out' parameter, xpidl internally
146 : // converts it to an 'in', and sets the XPT_PD_DIPPER flag on it. For this
147 : // reason, dipper types are sometimes referred to as 'out parameters
148 : // masquerading as in'. The burden of maintaining this illusion falls mostly
149 : // on XPConnect, which creates the empty containers, and harvest the results
150 : // after the call.
151 41054 : bool IsDipper() const {return 0 != (XPT_PD_IS_DIPPER(flags));}
152 7671 : bool IsOptional() const {return 0 != (XPT_PD_IS_OPTIONAL(flags));}
153 151209 : const nsXPTType GetType() const {return type.prefix;}
154 :
155 24941 : bool IsStringClass() const {
156 24941 : switch (GetType().TagPart()) {
157 : case nsXPTType::T_ASTRING:
158 : case nsXPTType::T_DOMSTRING:
159 : case nsXPTType::T_UTF8STRING:
160 : case nsXPTType::T_CSTRING:
161 2481 : return true;
162 : default:
163 22460 : return false;
164 : }
165 : }
166 :
167 : // Whether this parameter is passed indirectly on the stack. This mainly
168 : // applies to out/inout params, but we use it unconditionally for certain
169 : // types.
170 57897 : bool IsIndirect() const {return IsOut() ||
171 57897 : GetType().TagPart() == nsXPTType::T_JSVAL;}
172 :
173 : // NOTE: other activities on types are done via methods on nsIInterfaceInfo
174 :
175 : private:
176 : nsXPTParamInfo(); // no implementation
177 : // NO DATA - this a flyweight wrapper
178 : };
179 :
180 : class nsXPTMethodInfo : public XPTMethodDescriptor
181 : {
182 : // NO DATA - this a flyweight wrapper
183 : public:
184 : MOZ_IMPLICIT nsXPTMethodInfo(const XPTMethodDescriptor& desc)
185 : {*(XPTMethodDescriptor*)this = desc;}
186 :
187 9599 : bool IsGetter() const {return 0 != (XPT_MD_IS_GETTER(flags) );}
188 10149 : bool IsSetter() const {return 0 != (XPT_MD_IS_SETTER(flags) );}
189 3486 : bool IsNotXPCOM() const {return 0 != (XPT_MD_IS_NOTXPCOM(flags));}
190 0 : bool IsHidden() const {return 0 != (XPT_MD_IS_HIDDEN(flags) );}
191 12546 : bool WantsOptArgc() const {return 0 != (XPT_MD_WANTS_OPT_ARGC(flags));}
192 12546 : bool WantsContext() const {return 0 != (XPT_MD_WANTS_CONTEXT(flags));}
193 10018 : const char* GetName() const {return name;}
194 189734 : uint8_t GetParamCount() const {return num_args;}
195 : /* idx was index before I got _sick_ of the warnings on Unix, sorry jband */
196 141945 : const nsXPTParamInfo GetParam(uint8_t idx) const
197 : {
198 141945 : NS_PRECONDITION(idx < GetParamCount(),"bad arg");
199 141945 : return params[idx];
200 : }
201 : const nsXPTParamInfo GetResult() const
202 : {return result;}
203 : private:
204 : nsXPTMethodInfo(); // no implementation
205 : // NO DATA - this a flyweight wrapper
206 : };
207 :
208 :
209 : // forward declaration
210 : struct nsXPTCMiniVariant;
211 :
212 : class nsXPTConstant : public XPTConstDescriptor
213 : {
214 : // NO DATA - this a flyweight wrapper
215 : public:
216 : MOZ_IMPLICIT nsXPTConstant(const XPTConstDescriptor& desc)
217 : {*(XPTConstDescriptor*)this = desc;}
218 :
219 : const char* GetName() const
220 : {return name;}
221 :
222 : const nsXPTType GetType() const
223 : {return type.prefix;}
224 :
225 : // XXX this is ugly. But sometimes you gotta do what you gotta do.
226 : // A reinterpret_cast won't do the trick here. And this plain C cast
227 : // works correctly and is safe enough.
228 : // See http://bugzilla.mozilla.org/show_bug.cgi?id=49641
229 : const nsXPTCMiniVariant* GetValue() const
230 : {return (nsXPTCMiniVariant*) &value;}
231 : private:
232 : nsXPTConstant(); // no implementation
233 : // NO DATA - this a flyweight wrapper
234 : };
235 :
236 : #endif /* xptiinfo_h___ */
|