Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / core / Multiname-inlines.h
blob4f1a391597aa45220fb0ed72dfb49793a71e3919
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2009
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 namespace avmplus
43 REALLY_INLINE Stringp Multiname::getName() const
45 AvmAssert(!isAnyName() && !isRtname());
46 return name;
49 REALLY_INLINE void Multiname::setName(Stringp _name)
51 AvmAssert(_name && _name->isInterned());
52 this->flags &= ~RTNAME;
53 this->name = _name;
56 REALLY_INLINE void Multiname::setName(const Multiname* other)
58 // copy name settings from other
59 flags &= ~RTNAME;
60 flags |= other->flags & RTNAME;
61 this->name = other->name;
64 REALLY_INLINE int32_t Multiname::namespaceCount() const
66 return (nsset && (flags & NSSET)) ? nsset->count() : 1;
69 REALLY_INLINE Namespacep Multiname::getNamespace() const
71 return getNamespace(0);
74 REALLY_INLINE void Multiname::setNamespace(Namespacep _ns)
76 flags &= ~(NSSET|RTNS);
77 AvmAssert(_ns != NULL);
78 this->ns = _ns;
81 REALLY_INLINE void Multiname::setNamespace(const Multiname* other)
83 // copy namespace settings from other
84 flags &= ~(NSSET|RTNS);
85 flags |= other->flags & (NSSET|RTNS);
86 this->ns = other->ns;
89 REALLY_INLINE NamespaceSetp Multiname::getNsset() const
91 AvmAssert(!isRtns() && (flags&NSSET));
92 return nsset;
95 REALLY_INLINE void Multiname::setNsset(NamespaceSetp _nsset)
97 flags &= ~RTNS;
98 flags |= NSSET;
99 AvmAssert(_nsset != NULL);
100 this->nsset = _nsset;
103 REALLY_INLINE uint32_t Multiname::getTypeParameter() const
105 AvmAssert(isParameterizedType());
106 return next_index;
109 REALLY_INLINE void Multiname::setTypeParameter(uint32_t index)
111 flags |= TYPEPARAM;
112 this->next_index = index;
115 REALLY_INLINE Multiname::Multiname()
117 this->name = NULL;
118 this->ns = NULL;
119 this->flags = 0;
120 this->next_index = 0;
123 REALLY_INLINE Multiname::Multiname(NamespaceSetp nsset)
125 this->name = NULL;
126 this->nsset = nsset;
127 this->flags = NSSET;
128 this->next_index = 0;
131 REALLY_INLINE Multiname::Multiname(const Multiname &other)
133 *this = other;
136 REALLY_INLINE Multiname::Multiname(Namespacep ns, Stringp name)
138 AvmAssert(name && name->isInterned());
139 this->name = name;
140 this->ns = ns;
141 this->flags = 0;
142 this->next_index = 0;
145 REALLY_INLINE Multiname::Multiname(Namespacep ns, Stringp name, bool qualified)
147 AvmAssert(name && name->isInterned());
148 this->name = name;
149 this->ns = ns;
150 this->flags = 0;
151 this->next_index = 0;
152 if (qualified)
153 setQName();
156 REALLY_INLINE Multiname::~Multiname()
158 name = NULL;
159 nsset = NULL;
160 flags = 0;
161 next_index = 0;
164 REALLY_INLINE void Multiname::gcTrace(MMgc::GC* gc)
166 gc->TraceLocation((const void**)&name);
167 gc->TraceLocation((const void**)&ns); // or nsset
170 REALLY_INLINE bool Multiname::containsAnyPublicNamespace() const
172 if (!nsset)
173 return false; // note, also handles this->ns == null
175 if (flags & NSSET)
177 return this->nsset->containsAnyPublicNamespace();
179 else
181 return this->ns->isPublic();
187 * return the flags we want to keep when copying a compile-time
188 * multiname into a runtime temporary multiname
190 REALLY_INLINE int32_t Multiname::ctFlags() const
192 return flags & ~(RTNS|RTNAME);
196 * returns true if this multiname could resolve to a binding. Attributes,
197 * wildcards, and runtime parts mean it can't match any binding.
199 REALLY_INLINE int32_t Multiname::isBinding() const
201 return !(flags & (ATTR|RTNS|RTNAME)) && name && ns;
204 REALLY_INLINE int32_t Multiname::isRuntime() const
206 return flags & (RTNS|RTNAME);
209 REALLY_INLINE int32_t Multiname::isRtns() const
211 return flags & RTNS;
214 REALLY_INLINE int32_t Multiname::isRtname() const
216 return flags & RTNAME;
219 REALLY_INLINE int32_t Multiname::isQName() const
221 return flags & QNAME;
224 REALLY_INLINE bool Multiname::isAttr() const
226 return (bool) (flags & ATTR);
229 REALLY_INLINE bool Multiname::isAnyName() const
231 return !isRtname() && !name;
234 REALLY_INLINE bool Multiname::isAnyNamespace() const
236 return !isRtns() && !(flags&NSSET) && ns == NULL;
239 REALLY_INLINE int32_t Multiname::isNsset() const
241 return flags & NSSET;
244 REALLY_INLINE bool Multiname::isValidDynamicName() const
246 // return !isAnyName() && !isAttr() && containsAnyPublicNamespace();
247 // consolidate the above to insure against compiler stupidity
248 return ((flags & (ATTR|RTNAME)) == 0) && name != NULL && containsAnyPublicNamespace();
251 REALLY_INLINE int32_t Multiname::isParameterizedType() const
253 return flags&TYPEPARAM;
256 REALLY_INLINE void Multiname::setAttr(bool b)
258 if (b)
259 flags |= ATTR;
260 else
261 flags &= ~ATTR;
264 REALLY_INLINE void Multiname::setQName()
266 AvmAssert(namespaceCount()==1 && !(flags&NSSET));
267 flags |= QNAME;
270 REALLY_INLINE void Multiname::setRtns()
272 flags |= RTNS;
273 flags &= ~NSSET;
274 ns = NULL;
277 REALLY_INLINE void Multiname::setRtname()
279 flags |= RTNAME;
280 name = NULL;
283 REALLY_INLINE void Multiname::setAnyName()
285 flags &= ~RTNAME;
286 name = NULL;
289 REALLY_INLINE void Multiname::setAnyNamespace()
291 flags &= ~(NSSET|RTNS);
292 ns = NULL;
295 REALLY_INLINE void Multiname::IncrementRef()
297 if (name != NULL)
298 name->IncrementRef();
299 if (ns != NULL && (flags & NSSET) == 0)
300 ns->IncrementRef();
303 REALLY_INLINE void Multiname::DecrementRef()
305 if (name != NULL)
306 name->DecrementRef();
307 if (ns != NULL && (flags & NSSET) == 0)
308 ns->DecrementRef();
311 REALLY_INLINE HeapMultiname::HeapMultiname()
312 { /* our embedded Multiname inits itself to all zero */ }
314 REALLY_INLINE HeapMultiname::HeapMultiname(const Multiname& other)
316 setMultiname(other);
319 REALLY_INLINE HeapMultiname::operator const Multiname* () const
321 return &name;
324 REALLY_INLINE HeapMultiname::operator const Multiname& () const
326 return name;
329 REALLY_INLINE const HeapMultiname& HeapMultiname::operator=(const HeapMultiname& that)
331 if (this != &that)
333 setMultiname(that.name);
335 return *this;
338 REALLY_INLINE const HeapMultiname& HeapMultiname::operator=(const Multiname& that)
340 setMultiname(that);
341 return *this;
344 REALLY_INLINE void HeapMultiname::gcTrace(MMgc::GC* gc)
346 name.gcTrace(gc);
349 REALLY_INLINE Stringp HeapMultiname::getName() const
351 return name.getName();
354 REALLY_INLINE int32_t HeapMultiname::namespaceCount() const
356 return name.namespaceCount();
359 REALLY_INLINE Namespacep HeapMultiname::getNamespace(int32_t i) const
361 return name.getNamespace(i);
364 REALLY_INLINE Namespacep HeapMultiname::getNamespace() const
366 return name.getNamespace();
369 REALLY_INLINE NamespaceSetp HeapMultiname::getNsset() const
371 return name.getNsset();
374 REALLY_INLINE bool HeapMultiname::contains(Namespacep ns) const
376 return name.contains(ns);
379 REALLY_INLINE int32_t HeapMultiname::ctFlags() const
381 return name.ctFlags();
384 REALLY_INLINE int32_t HeapMultiname::isBinding() const
386 return name.isBinding();
389 REALLY_INLINE int32_t HeapMultiname::isRuntime() const
391 return name.isRuntime();
394 REALLY_INLINE int32_t HeapMultiname::isRtns() const
396 return name.isRtns();
399 REALLY_INLINE int32_t HeapMultiname::isRtname() const
401 return name.isRtname();
404 REALLY_INLINE int32_t HeapMultiname::isQName() const
406 return name.isQName();
409 REALLY_INLINE bool HeapMultiname::isAttr() const
411 return name.isAttr();
414 REALLY_INLINE bool HeapMultiname::isAnyName() const
416 return name.isAnyName();
419 REALLY_INLINE bool HeapMultiname::isAnyNamespace() const
421 return name.isAnyNamespace();
424 REALLY_INLINE int32_t HeapMultiname::isNsset() const
426 return name.isNsset();
429 REALLY_INLINE bool HeapMultiname::matches(const Multiname *mn) const
431 return name.matches(mn);
434 REALLY_INLINE MMgc::GC* HeapMultiname::gc() const
436 return MMgc::GC::GetGC(this);
439 } // namespace avmplus