xpcom/reflect/xptinfo/public/xptinfo.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:a0fa78aad99d
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 class nsIInterfaceInfoManager;
15
16 // Flyweight wrapper classes for xpt_struct.h structs.
17 // Everything here is dependent upon - and sensitive to changes in -
18 // xpcom/typelib/xpt/public/xpt_struct.h!
19
20 class nsXPTType : public XPTTypeDescriptorPrefix
21 {
22 // NO DATA - this a flyweight wrapper
23 public:
24 nsXPTType()
25 {} // random contents
26 nsXPTType(const XPTTypeDescriptorPrefix& prefix)
27 {*(XPTTypeDescriptorPrefix*)this = prefix;}
28
29 nsXPTType(const uint8_t& prefix)
30 {*(uint8_t*)this = prefix;}
31
32 nsXPTType& operator=(uint8_t val)
33 {flags = val; return *this;}
34
35 nsXPTType& operator=(const nsXPTType& other)
36 {flags = other.flags; return *this;}
37
38 operator uint8_t() const
39 {return flags;}
40
41 // 'Arithmetic' here roughly means that the value is self-contained and
42 // doesn't depend on anything else in memory (ie: not a pointer, not an
43 // XPCOM object, not a jsval, etc).
44 //
45 // Supposedly this terminology comes from Harbison/Steele, but it's still
46 // a rather crappy name. We'd change it if it wasn't used all over the
47 // place in xptcall. :-(
48 bool IsArithmetic() const
49 {return flags <= T_WCHAR;}
50
51 // We used to abuse 'pointer' flag bit in typelib format quite extensively.
52 // We've gotten rid of most of the cases, but there's still a fair amount
53 // of refactoring to be done in XPCWrappedJSClass before we can safely stop
54 // asking about this. In the mean time, we've got a temporary version of
55 // IsPointer() that should be equivalent to what's in the typelib.
56 bool deprecated_IsPointer() const
57 {return !IsArithmetic() && TagPart() != T_JSVAL;}
58
59 bool IsInterfacePointer() const
60 { switch (TagPart()) {
61 default:
62 return false;
63 case T_INTERFACE:
64 case T_INTERFACE_IS:
65 return true;
66 }
67 }
68
69 bool IsArray() const
70 {return TagPart() == T_ARRAY;}
71
72 // 'Dependent' means that params of this type are dependent upon other
73 // params. e.g. an T_INTERFACE_IS is dependent upon some other param at
74 // runtime to say what the interface type of this param really is.
75 bool IsDependent() const
76 { switch (TagPart()) {
77 default:
78 return false;
79 case T_INTERFACE_IS:
80 case TD_ARRAY:
81 case T_PSTRING_SIZE_IS:
82 case T_PWSTRING_SIZE_IS:
83 return true;
84 }
85 }
86
87 uint8_t TagPart() const
88 {return (uint8_t) (flags & XPT_TDP_TAGMASK);}
89
90 enum
91 {
92 T_I8 = TD_INT8 ,
93 T_I16 = TD_INT16 ,
94 T_I32 = TD_INT32 ,
95 T_I64 = TD_INT64 ,
96 T_U8 = TD_UINT8 ,
97 T_U16 = TD_UINT16 ,
98 T_U32 = TD_UINT32 ,
99 T_U64 = TD_UINT64 ,
100 T_FLOAT = TD_FLOAT ,
101 T_DOUBLE = TD_DOUBLE ,
102 T_BOOL = TD_BOOL ,
103 T_CHAR = TD_CHAR ,
104 T_WCHAR = TD_WCHAR ,
105 T_VOID = TD_VOID ,
106 T_IID = TD_PNSIID ,
107 T_DOMSTRING = TD_DOMSTRING ,
108 T_CHAR_STR = TD_PSTRING ,
109 T_WCHAR_STR = TD_PWSTRING ,
110 T_INTERFACE = TD_INTERFACE_TYPE ,
111 T_INTERFACE_IS = TD_INTERFACE_IS_TYPE,
112 T_ARRAY = TD_ARRAY ,
113 T_PSTRING_SIZE_IS = TD_PSTRING_SIZE_IS ,
114 T_PWSTRING_SIZE_IS = TD_PWSTRING_SIZE_IS ,
115 T_UTF8STRING = TD_UTF8STRING ,
116 T_CSTRING = TD_CSTRING ,
117 T_ASTRING = TD_ASTRING ,
118 T_JSVAL = TD_JSVAL
119 };
120 // NO DATA - this a flyweight wrapper
121 };
122
123 class nsXPTParamInfo : public XPTParamDescriptor
124 {
125 // NO DATA - this a flyweight wrapper
126 public:
127 nsXPTParamInfo(const XPTParamDescriptor& desc)
128 {*(XPTParamDescriptor*)this = desc;}
129
130
131 bool IsIn() const {return 0 != (XPT_PD_IS_IN(flags));}
132 bool IsOut() const {return 0 != (XPT_PD_IS_OUT(flags));}
133 bool IsRetval() const {return 0 != (XPT_PD_IS_RETVAL(flags));}
134 bool IsShared() const {return 0 != (XPT_PD_IS_SHARED(flags));}
135 bool IsDipper() const {return 0 != (XPT_PD_IS_DIPPER(flags));}
136 bool IsOptional() const {return 0 != (XPT_PD_IS_OPTIONAL(flags));}
137 const nsXPTType GetType() const {return type.prefix;}
138
139 // Whether this parameter is passed indirectly on the stack. This mainly
140 // applies to out/inout params, but we use it unconditionally for certain
141 // types.
142 bool IsIndirect() const {return IsOut() ||
143 GetType().TagPart() == nsXPTType::T_JSVAL;}
144
145 // NOTE: other activities on types are done via methods on nsIInterfaceInfo
146
147 private:
148 nsXPTParamInfo(); // no implementation
149 // NO DATA - this a flyweight wrapper
150 };
151
152 class nsXPTMethodInfo : public XPTMethodDescriptor
153 {
154 // NO DATA - this a flyweight wrapper
155 public:
156 nsXPTMethodInfo(const XPTMethodDescriptor& desc)
157 {*(XPTMethodDescriptor*)this = desc;}
158
159 bool IsGetter() const {return 0 != (XPT_MD_IS_GETTER(flags) );}
160 bool IsSetter() const {return 0 != (XPT_MD_IS_SETTER(flags) );}
161 bool IsNotXPCOM() const {return 0 != (XPT_MD_IS_NOTXPCOM(flags));}
162 bool IsConstructor() const {return 0 != (XPT_MD_IS_CTOR(flags) );}
163 bool IsHidden() const {return 0 != (XPT_MD_IS_HIDDEN(flags) );}
164 bool WantsOptArgc() const {return 0 != (XPT_MD_WANTS_OPT_ARGC(flags));}
165 bool WantsContext() const {return 0 != (XPT_MD_WANTS_CONTEXT(flags));}
166 const char* GetName() const {return name;}
167 uint8_t GetParamCount() const {return num_args;}
168 /* idx was index before I got _sick_ of the warnings on Unix, sorry jband */
169 const nsXPTParamInfo GetParam(uint8_t idx) const
170 {
171 NS_PRECONDITION(idx < GetParamCount(),"bad arg");
172 return params[idx];
173 }
174 const nsXPTParamInfo GetResult() const
175 {return result;}
176 private:
177 nsXPTMethodInfo(); // no implementation
178 // NO DATA - this a flyweight wrapper
179 };
180
181
182 // forward declaration
183 struct nsXPTCMiniVariant;
184
185 class nsXPTConstant : public XPTConstDescriptor
186 {
187 // NO DATA - this a flyweight wrapper
188 public:
189 nsXPTConstant(const XPTConstDescriptor& desc)
190 {*(XPTConstDescriptor*)this = desc;}
191
192 const char* GetName() const
193 {return name;}
194
195 const nsXPTType GetType() const
196 {return type.prefix;}
197
198 // XXX this is ugly. But sometimes you gotta do what you gotta do.
199 // A reinterpret_cast won't do the trick here. And this plain C cast
200 // works correctly and is safe enough.
201 // See http://bugzilla.mozilla.org/show_bug.cgi?id=49641
202 const nsXPTCMiniVariant* GetValue() const
203 {return (nsXPTCMiniVariant*) &value;}
204 private:
205 nsXPTConstant(); // no implementation
206 // NO DATA - this a flyweight wrapper
207 };
208
209 #endif /* xptiinfo_h___ */

mercurial