OGLPLUS_LIB_FUNC std::size_t BlendFileStructField::Size(void) const { bool is_ptr = IsPointer() || IsPointerToFunc(); if(IsArray()) { std::size_t ec = ElementCount(); if(is_ptr) return _sdna->_ptr_size * ec; else return BaseType().Size() * ec; } if(is_ptr) return _sdna->_ptr_size; return BaseType().Size(); }
void ImplAAFTypeDefString::internalize(const OMByte* externalBytes, OMUInt32 externalBytesSize, OMByte* internalBytes, OMUInt32 internalBytesSize, OMByteOrder byteOrder) const { ImplAAFTypeDefSP ptd = BaseType(); ASSERTU (ptd); ASSERTU (ptd->IsFixedSize ()); aafUInt32 extElemSize = ptd->PropValSize (); aafUInt32 intElemSize = ptd->ActualSize (); // aafUInt32 intElemSize = ptd->internalSize (0, 0); // aafUInt32 extElemSize = ptd->externalSize (0, 0); aafUInt32 numElems = externalBytesSize / extElemSize; aafInt32 intNumBytesLeft = internalBytesSize; aafInt32 extNumBytesLeft = externalBytesSize; aafUInt32 elem = 0; for (elem = 0; elem < numElems; elem++) { ptd->type()->internalize (externalBytes, extElemSize, internalBytes, intElemSize, byteOrder); internalBytes += intElemSize; externalBytes += extElemSize; intNumBytesLeft -= intElemSize; extNumBytesLeft -= extElemSize; ASSERTU (intNumBytesLeft >= 0); ASSERTU (extNumBytesLeft >= 0); } }
PRBool nsAttrValue::Equals(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const { if (aCaseSensitive != eCaseMatters) { // Need a better way to handle this! nsAutoString value; aValue->ToString(value); return Equals(value, aCaseSensitive); } switch (BaseType()) { case eStringBase: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { nsDependentString dep(static_cast<PRUnichar*>(str->Data()), str->StorageSize()/sizeof(PRUnichar) - 1); return aValue->Equals(dep); } return aValue == nsGkAtoms::_empty; } case eAtomBase: { return static_cast<nsIAtom*>(GetPtr()) == aValue; } default: break; } nsAutoString val; ToString(val); return aValue->Equals(val); }
void nsAttrValue::Reset() { switch(BaseType()) { case eStringBase: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { str->Release(); } break; } case eOtherBase: { EnsureEmptyMiscContainer(); delete GetMiscContainer(); break; } case eAtomBase: { nsIAtom* atom = GetAtomValue(); NS_RELEASE(atom); break; } case eIntegerBase: { break; } } mBits = 0; }
void nsAttrValue::GetEnumString(nsAString& aResult, PRBool aRealTag) const { NS_PRECONDITION(Type() == eEnum, "wrong type"); PRUint32 allEnumBits = (BaseType() == eIntegerBase) ? static_cast<PRUint32>(GetIntInternal()) : GetMiscContainer()->mEnumValue; PRInt16 val = allEnumBits >> NS_ATTRVALUE_ENUMTABLEINDEX_BITS; const EnumTable* table = sEnumTableArray-> ElementAt(allEnumBits & NS_ATTRVALUE_ENUMTABLEINDEX_MASK); while (table->tag) { if (table->value == val) { aResult.AssignASCII(table->tag); if (!aRealTag && allEnumBits & NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER) { ToUpperCase(aResult); } return; } table++; } NS_NOTREACHED("couldn't find value in EnumTable"); }
void RecType() { /* RecType -> RECORD [ '(' BaseType ')' ] [ FieldListSeq ] END */ if ( debugMode) printf( "In RecType\n"); accept( RECORD_SYM, 159); if ( sym == lparen) { writesym(); nextsym(); BaseType(); accept( rparen, 142); } if ( sym != END_SYM) { FieldListSeq(); } accept( END_SYM, 155); if ( debugMode) printf( "Out RecType\n"); }
PRBool nsAttrValue::Equals(const nsAString& aValue, nsCaseTreatment aCaseSensitive) const { switch (BaseType()) { case eStringBase: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { nsDependentString dep(static_cast<PRUnichar*>(str->Data()), str->StorageSize()/sizeof(PRUnichar) - 1); return aCaseSensitive == eCaseMatters ? aValue.Equals(dep) : aValue.Equals(dep, nsCaseInsensitiveStringComparator()); } return aValue.IsEmpty(); } case eAtomBase: if (aCaseSensitive == eCaseMatters) { return static_cast<nsIAtom*>(GetPtr())->Equals(aValue); } return nsDependentAtomString(static_cast<nsIAtom*>(GetPtr())). Equals(aValue, nsCaseInsensitiveStringComparator()); default: break; } nsAutoString val; ToString(val); return aCaseSensitive == eCaseMatters ? val.Equals(aValue) : val.Equals(aValue, nsCaseInsensitiveStringComparator()); }
OMType* ImplAAFTypeDefRename::renamedType(void) const { // Should be properly implemented ImplAAFTypeDef* type = BaseType(); return type->type(); }
PRUint32 nsAttrValue::HashValue() const { switch(BaseType()) { case eStringBase: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { PRUint32 len = str->StorageSize()/sizeof(PRUnichar) - 1; return nsCRT::BufferHashCode(static_cast<PRUnichar*>(str->Data()), len); } return 0; } case eOtherBase: { break; } case eAtomBase: case eIntegerBase: { // mBits and PRUint32 might have different size. This should silence // any warnings or compile-errors. This is what the implementation of // NS_PTR_TO_INT32 does to take care of the same problem. return mBits - 0; } } MiscContainer* cont = GetMiscContainer(); switch (cont->mType) { case eColor: { return cont->mColor; } case eCSSStyleRule: { return NS_PTR_TO_INT32(cont->mCSSStyleRule); } case eAtomArray: { PRUint32 retval = 0; PRInt32 i, count = cont->mAtomArray->Count(); for (i = 0; i < count; ++i) { retval ^= NS_PTR_TO_INT32(cont->mAtomArray->ObjectAt(i)); } return retval; } #ifdef MOZ_SVG case eSVGValue: { return NS_PTR_TO_INT32(cont->mSVGValue); } #endif default: { NS_NOTREACHED("unknown type stored in MiscContainer"); return 0; } } }
PRBool nsAttrValue::GetColorValue(nscolor& aColor) const { NS_PRECONDITION(Type() == eColor || Type() == eString, "wrong type"); switch (BaseType()) { case eString: { return GetPtr() && NS_ColorNameToRGB(GetStringValue(), &aColor); } case eOtherBase: { aColor = GetMiscContainer()->mColor; break; } case eIntegerBase: { aColor = static_cast<nscolor>(GetIntInternal()); break; } default: { NS_NOTREACHED("unexpected basetype"); break; } } return PR_TRUE; }
PRInt64 nsAttrValue::SizeOf() const { PRInt64 size = sizeof(*this); switch (BaseType()) { case eStringBase: { // TODO: we might be counting the string size more than once. // This should be fixed with bug 677487. nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); size += str ? str->StorageSize() : 0; break; } case eOtherBase: { MiscContainer* container = GetMiscContainer(); if (!container) { break; } size += sizeof(*container); void* otherPtr = MISC_STR_PTR(container); // We only count the size of the object pointed by otherPtr if it's a // string. When it's an atom, it's counted separatly. if (otherPtr && static_cast<ValueBaseType>(container->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) == eStringBase) { // TODO: we might be counting the string size more than once. // This should be fixed with bug 677487. nsStringBuffer* str = static_cast<nsStringBuffer*>(otherPtr); size += str ? str->StorageSize() : 0; } // TODO: mCSSStyleRule and mSVGValue might be owned by another object // which would make us count them twice, bug 677493. if (Type() == eCSSStyleRule && container->mCSSStyleRule) { // TODO: Add SizeOf() to StyleRule, bug 677503. size += sizeof(*container->mCSSStyleRule); } else if (Type() == eSVGValue && container->mSVGValue) { // TODO: Add SizeOf() to nsSVGValue, bug 677504. size += sizeof(*container->mSVGValue); } else if (Type() == eAtomArray && container->mAtomArray) { size += sizeof(container->mAtomArray) + sizeof(nsTArrayHeader); size += container->mAtomArray->Capacity() * sizeof(nsCOMPtr<nsIAtom>); // Don't count the size of each nsIAtom, they are counted separatly. } break; } case eAtomBase: // Atoms are counted separatly. case eIntegerBase: // The value is in mBits, nothing to do. break; } return size; }
nsAttrValue::ValueType nsAttrValue::Type() const { switch (BaseType()) { case eIntegerBase: { return static_cast<ValueType>(mBits & NS_ATTRVALUE_INTEGERTYPE_MASK); } case eOtherBase: { return GetMiscContainer()->mType; } default: { return static_cast<ValueType>(static_cast<PRUint16>(BaseType())); } } }
void ImplAAFTypeDefRename::internalize(const OMByte* externalBytes, OMUInt32 externalBytesSize, OMByte* internalBytes, OMUInt32 internalBytesSize, OMByteOrder byteOrder) const { BaseType()->type()->internalize (externalBytes, externalBytesSize, internalBytes, internalBytesSize, byteOrder); }
OMProperty * ImplAAFTypeDefString::pvtCreateOMProperty (OMPropertyId pid, const wchar_t * name) const { ASSERTU (name); ImplAAFTypeDefSP ptd = BaseType (); ASSERTU (ptd); OMProperty * result = 0; ImplAAFTypeDefCharacter * ptdCharacter = dynamic_cast<ImplAAFTypeDefCharacter*>((ImplAAFTypeDef*) ptd); if (ptdCharacter) { result = new OMWideStringProperty(pid, name); } else { ImplAAFTypeDefInt * ptdi = dynamic_cast<ImplAAFTypeDefInt*>((ImplAAFTypeDef*) ptd); ASSERTU (ptdi); if (ptdi) { // element is integral type aafUInt32 intSize; ptdi->GetSize (&intSize); switch (intSize) { case 1: result = new OMVariableSizeProperty<aafUInt8> (pid, name); break; case 2: result = new OMVariableSizeProperty<aafUInt16> (pid, name); break; case 4: result = new OMVariableSizeProperty<aafUInt32> (pid, name); break; case 8: result = new OMVariableSizeProperty<aafInt64> (pid, name); break; default: // We only support strings of those types. ASSERTU (0); } } } // If result wasn't set above, we don't support the type. ASSERTU (result); return result; }
nsIAtom* nsAttrValue::AtomAt(PRInt32 aIndex) const { NS_PRECONDITION(aIndex >= 0, "Index must not be negative"); NS_PRECONDITION(GetAtomCount() > PRUint32(aIndex), "aIndex out of range"); if (BaseType() == eAtomBase) { return GetAtomValue(); } NS_ASSERTION(Type() == eAtomArray, "GetAtomCount must be confused"); return GetAtomArrayValue()->ElementAt(aIndex); }
PRBool nsAttrValue::EnsureEmptyMiscContainer() { MiscContainer* cont; if (BaseType() == eOtherBase) { ResetMiscAtomOrString(); cont = GetMiscContainer(); switch (cont->mType) { case eCSSStyleRule: { NS_RELEASE(cont->mCSSStyleRule); break; } case eAtomArray: { delete cont->mAtomArray; break; } case eSVGValue: { NS_RELEASE(cont->mSVGValue); break; } case eIntMarginValue: { delete cont->mIntMargin; break; } default: { break; } } } else { ResetIfSet(); cont = new MiscContainer; NS_ENSURE_TRUE(cont, PR_FALSE); SetPtrValueAndType(cont, eOtherBase); } cont->mType = eColor; cont->mStringBits = 0; cont->mColor = 0; return PR_TRUE; }
OMUInt32 ImplAAFTypeDefString::internalSize(const OMByte* /*externalBytes*/, OMUInt32 externalBytesSize) const { ImplAAFTypeDefSP ptd = BaseType(); ASSERTU (ptd); ASSERTU (ptd->IsFixedSize ()); aafUInt32 extElemSize = ptd->PropValSize (); aafUInt32 intElemSize = ptd->ActualSize (); // aafUInt32 extElemSize = ptd->externalSize (0, 0); // aafUInt32 intElemSize = ptd->internalSize (0, 0); ASSERTU (intElemSize); aafUInt32 numElems = externalBytesSize / extElemSize; return numElems * intElemSize; }
PRBool nsAttrValue::Contains(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const { switch (BaseType()) { case eAtomBase: { nsIAtom* atom = GetAtomValue(); if (aCaseSensitive == eCaseMatters) { return aValue == atom; } // For performance reasons, don't do a full on unicode case insensitive // string comparison. This is only used for quirks mode anyway. return nsContentUtils::EqualsIgnoreASCIICase(nsDependentAtomString(aValue), nsDependentAtomString(atom)); } default: { if (Type() == eAtomArray) { AtomArray* array = GetAtomArrayValue(); if (aCaseSensitive == eCaseMatters) { return array->IndexOf(aValue) != AtomArray::NoIndex; } nsDependentAtomString val1(aValue); for (nsCOMPtr<nsIAtom> *cur = array->Elements(), *end = cur + array->Length(); cur != end; ++cur) { // For performance reasons, don't do a full on unicode case // insensitive string comparison. This is only used for quirks mode // anyway. if (nsContentUtils::EqualsIgnoreASCIICase(val1, nsDependentAtomString(*cur))) { return PR_TRUE; } } } } } return PR_FALSE; }
void ImplAAFTypeDefString::reorder(OMByte* externalBytes, OMUInt32 externalBytesSize) const { ImplAAFTypeDefSP ptd = BaseType(); ASSERTU (ptd); aafUInt32 extElemSize = ptd->PropValSize (); aafUInt32 numElems = externalBytesSize / extElemSize; aafInt32 numBytesLeft = externalBytesSize; aafUInt32 elem = 0; for (elem = 0; elem < numElems; elem++) { ptd->type()->reorder (externalBytes, extElemSize); externalBytes += extElemSize; numBytesLeft -= extElemSize; ASSERTU (numBytesLeft >= 0); } }
PRBool nsAttrValue::Contains(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const { switch (BaseType()) { case eAtomBase: { nsIAtom* atom = GetAtomValue(); if (aCaseSensitive == eCaseMatters) { return aValue == atom; } const char *val1, *val2; aValue->GetUTF8String(&val1); atom->GetUTF8String(&val2); return nsCRT::strcasecmp(val1, val2) == 0; } default: { if (Type() == eAtomArray) { nsCOMArray<nsIAtom>* array = GetAtomArrayValue(); if (aCaseSensitive == eCaseMatters) { return array->IndexOf(aValue) >= 0; } const char *val1, *val2; aValue->GetUTF8String(&val1); for (PRInt32 i = 0, count = array->Count(); i < count; ++i) { array->ObjectAt(i)->GetUTF8String(&val2); if (nsCRT::strcasecmp(val1, val2) == 0) { return PR_TRUE; } } } } } return PR_FALSE; }
void Type::set_base_types(const ArrayView<const BaseType> & i_base_types) { if (i_base_types.size() >= 1) { m_single_base = i_base_types[0]; #if REFLECTIVE_ENABLE_MULTIPLE_INHERITANCE m_other_base_types.resize(i_base_types.size() - 1); for (size_t base_type_index = 1; base_type_index < i_base_types.size(); base_type_index++) { m_other_base_types[base_type_index - 1] = i_base_types[base_type_index]; } #else REFLECTIVE_ASSERT(i_base_types.size() == 1, "More than one base type provided, but multiple inheritance is disabled (REFLECTIVE_ENABLE_MULTIPLE_INHERITANCE si false)"); #endif } else { m_single_base = BaseType(); #if REFLECTIVE_ENABLE_MULTIPLE_INHERITANCE m_other_base_types.clear(); #endif } }
status_t DwarfArrayType::ResolveElementLocation(const ArrayIndexPath& indexPath, const ValueLocation& parentLocation, ValueLocation*& _location) { if (indexPath.CountIndices() != CountDimensions()) return B_BAD_VALUE; DwarfTypeContext* typeContext = TypeContext(); // If the array entry has a bit stride, get it. Otherwise fall back to the // element type size. int64 bitStride; DIEArrayType* bitStrideOwnerEntry = NULL; if (fEntry != NULL && (bitStrideOwnerEntry = DwarfUtils::GetDIEByPredicate( fEntry, HasBitStridePredicate<DIEArrayType>()))) { BVariant value; status_t error = typeContext->File()->EvaluateDynamicValue( typeContext->GetCompilationUnit(), typeContext->AddressSize(), typeContext->SubprogramEntry(), bitStrideOwnerEntry->BitStride(), typeContext->TargetInterface(), typeContext->InstructionPointer(), typeContext->FramePointer(), value); if (error != B_OK) return error; if (!value.IsInteger()) return B_BAD_VALUE; bitStride = value.ToInt64(); } else bitStride = BaseType()->ByteSize() * 8; // Iterate backward through the dimensions and compute the total offset of // the element. int64 elementOffset = 0; DwarfArrayDimension* previousDimension = NULL; int64 previousDimensionStride = 0; for (int32 dimensionIndex = CountDimensions() - 1; dimensionIndex >= 0; dimensionIndex--) { DwarfArrayDimension* dimension = DwarfDimensionAt(dimensionIndex); int64 index = indexPath.IndexAt(dimensionIndex); // If the dimension has a special bit/byte stride, get it. int64 dimensionStride = 0; DwarfType* dimensionType = dimension->GetDwarfType(); DIEArrayIndexType* dimensionTypeEntry = dimensionType != NULL ? dynamic_cast<DIEArrayIndexType*>(dimensionType->GetDIEType()) : NULL; if (dimensionTypeEntry != NULL) { DIEArrayIndexType* bitStrideOwnerEntry = DwarfUtils::GetDIEByPredicate(dimensionTypeEntry, HasBitStridePredicate<DIEArrayIndexType>()); if (bitStrideOwnerEntry != NULL) { BVariant value; status_t error = typeContext->File()->EvaluateDynamicValue( typeContext->GetCompilationUnit(), typeContext->AddressSize(), typeContext->SubprogramEntry(), bitStrideOwnerEntry->BitStride(), typeContext->TargetInterface(), typeContext->InstructionPointer(), typeContext->FramePointer(), value); if (error != B_OK) return error; if (!value.IsInteger()) return B_BAD_VALUE; dimensionStride = value.ToInt64(); } else { DIEArrayIndexType* byteStrideOwnerEntry = DwarfUtils::GetDIEByPredicate(dimensionTypeEntry, HasByteStridePredicate<DIEArrayIndexType>()); if (byteStrideOwnerEntry != NULL) { BVariant value; status_t error = typeContext->File()->EvaluateDynamicValue( typeContext->GetCompilationUnit(), typeContext->AddressSize(), typeContext->SubprogramEntry(), byteStrideOwnerEntry->ByteStride(), typeContext->TargetInterface(), typeContext->InstructionPointer(), typeContext->FramePointer(), value); if (error != B_OK) return error; if (!value.IsInteger()) return B_BAD_VALUE; dimensionStride = value.ToInt64() * 8; } } } // If we don't have a stride for the dimension yet, use the stride of // the previous dimension multiplied by the size of the dimension. if (dimensionStride == 0) { if (previousDimension != NULL) { dimensionStride = previousDimensionStride * previousDimension->CountElements(); } else { // the last dimension -- use the element bit stride dimensionStride = bitStride; } } // If the dimension stride is still 0 (that can happen, if the dimension // doesn't have a stride and the previous dimension's element count is // not known), we can only resolve the first element. if (dimensionStride == 0 && index != 0) { WARNING("No dimension bit stride for dimension %" B_PRId32 " and " "element index is not 0.\n", dimensionIndex); return B_BAD_VALUE; } elementOffset += dimensionStride * index; previousDimension = dimension; previousDimensionStride = dimensionStride; } TRACE_LOCALS("total element bit offset: %" B_PRId64 "\n", elementOffset); // create the value location object for the element ValueLocation* location = new(std::nothrow) ValueLocation( parentLocation.IsBigEndian()); if (location == NULL) return B_NO_MEMORY; BReference<ValueLocation> locationReference(location, true); // If we have a single memory piece location for the array, we compute the // element's location by hand -- not uncommonly the array size isn't known. if (parentLocation.CountPieces() == 1) { ValuePieceLocation piece = parentLocation.PieceAt(0); if (piece.type == VALUE_PIECE_LOCATION_MEMORY) { int64 byteOffset = elementOffset >= 0 ? elementOffset / 8 : (elementOffset - 7) / 8; piece.SetToMemory(piece.address + byteOffset); piece.SetSize(BaseType()->ByteSize()); // TODO: Support bit offsets correctly! // TODO: Support bit fields (primitive types) correctly! if (!location->AddPiece(piece)) return B_NO_MEMORY; _location = locationReference.Detach(); return B_OK; } } // We can't deal with negative element offsets at this point. It doesn't // make a lot of sense anyway, if the array location consists of multiple // pieces or lives in a register. if (elementOffset < 0) { WARNING("Negative element offset unsupported for multiple location " "pieces or register pieces.\n"); return B_UNSUPPORTED; } if (!location->SetTo(parentLocation, elementOffset, BaseType()->ByteSize() * 8)) { return B_NO_MEMORY; } _location = locationReference.Detach(); return B_OK; }
bool ImplAAFTypeDefRename::IsVariableArrayable () const { return BaseType()->IsVariableArrayable(); }
bool ImplAAFTypeDefRename::IsStringable () const { return BaseType()->IsStringable(); }
PRBool nsAttrValue::Equals(const nsAttrValue& aOther) const { if (BaseType() != aOther.BaseType()) { return PR_FALSE; } switch(BaseType()) { case eStringBase: { return GetStringValue().Equals(aOther.GetStringValue()); } case eOtherBase: { break; } case eAtomBase: case eIntegerBase: { return mBits == aOther.mBits; } } MiscContainer* thisCont = GetMiscContainer(); MiscContainer* otherCont = aOther.GetMiscContainer(); if (thisCont->mType != otherCont->mType) { return PR_FALSE; } PRBool needsStringComparison = PR_FALSE; switch (thisCont->mType) { case eInteger: { if (thisCont->mInteger == otherCont->mInteger) { needsStringComparison = PR_TRUE; } break; } case eEnum: { if (thisCont->mEnumValue == otherCont->mEnumValue) { needsStringComparison = PR_TRUE; } break; } case ePercent: { if (thisCont->mPercent == otherCont->mPercent) { needsStringComparison = PR_TRUE; } break; } case eColor: { if (thisCont->mColor == otherCont->mColor) { needsStringComparison = PR_TRUE; } break; } case eCSSStyleRule: { return thisCont->mCSSStyleRule == otherCont->mCSSStyleRule; } case eAtomArray: { // For classlists we could be insensitive to order, however // classlists are never mapped attributes so they are never compared. if (!(*thisCont->mAtomArray == *otherCont->mAtomArray)) { return PR_FALSE; } needsStringComparison = PR_TRUE; break; } case eSVGValue: { return thisCont->mSVGValue == otherCont->mSVGValue; } case eDoubleValue: { return thisCont->mDoubleValue == otherCont->mDoubleValue; } case eIntMarginValue: { return thisCont->mIntMargin == otherCont->mIntMargin; } default: { NS_NOTREACHED("unknown type stored in MiscContainer"); return PR_FALSE; } } if (needsStringComparison) { if (thisCont->mStringBits == otherCont->mStringBits) { return PR_TRUE; } if ((static_cast<ValueBaseType>(thisCont->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) == eStringBase) && (static_cast<ValueBaseType>(otherCont->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) == eStringBase)) { return nsCheapString(reinterpret_cast<nsStringBuffer*>(thisCont->mStringBits)).Equals( nsCheapString(reinterpret_cast<nsStringBuffer*>(otherCont->mStringBits))); } } return PR_FALSE; }
PRUint32 nsAttrValue::HashValue() const { switch(BaseType()) { case eStringBase: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { PRUint32 len = str->StorageSize()/sizeof(PRUnichar) - 1; return nsCRT::HashCode(static_cast<PRUnichar*>(str->Data()), len); } return 0; } case eOtherBase: { break; } case eAtomBase: case eIntegerBase: { // mBits and PRUint32 might have different size. This should silence // any warnings or compile-errors. This is what the implementation of // NS_PTR_TO_INT32 does to take care of the same problem. return mBits - 0; } } MiscContainer* cont = GetMiscContainer(); if (static_cast<ValueBaseType>(cont->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) == eAtomBase) { return cont->mStringBits - 0; } switch (cont->mType) { case eInteger: { return cont->mInteger; } case eEnum: { return cont->mEnumValue; } case ePercent: { return cont->mPercent; } case eColor: { return cont->mColor; } case eCSSStyleRule: { return NS_PTR_TO_INT32(cont->mCSSStyleRule); } case eAtomArray: { PRUint32 retval = 0; PRUint32 count = cont->mAtomArray->Length(); for (nsCOMPtr<nsIAtom> *cur = cont->mAtomArray->Elements(), *end = cur + count; cur != end; ++cur) { retval ^= NS_PTR_TO_INT32(cur->get()); } return retval; } case eSVGValue: { return NS_PTR_TO_INT32(cont->mSVGValue); } case eDoubleValue: { // XXX this is crappy, but oh well return cont->mDoubleValue; } case eIntMarginValue: { return NS_PTR_TO_INT32(cont->mIntMargin); } default: { NS_NOTREACHED("unknown type stored in MiscContainer"); return 0; } } }
bool IsExportedStruct(Type *type) { return IsStruct(BaseType(type)) && type->sptr->exported; }
bool IsStruct(Type *type) { return IsStruct(BaseType(type)); }
void nsAttrValue::ToString(nsAString& aResult) const { MiscContainer* cont = nsnull; if (BaseType() == eOtherBase) { cont = GetMiscContainer(); void* ptr = MISC_STR_PTR(cont); if (ptr) { if (static_cast<ValueBaseType>(cont->mStringBits & NS_ATTRVALUE_BASETYPE_MASK) == eStringBase) { nsStringBuffer* str = static_cast<nsStringBuffer*>(ptr); if (str) { str->ToString(str->StorageSize()/sizeof(PRUnichar) - 1, aResult); return; } } else { nsIAtom *atom = static_cast<nsIAtom*>(ptr); atom->ToString(aResult); return; } } } switch(Type()) { case eString: { nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr()); if (str) { str->ToString(str->StorageSize()/sizeof(PRUnichar) - 1, aResult); } else { aResult.Truncate(); } break; } case eAtom: { nsIAtom *atom = static_cast<nsIAtom*>(GetPtr()); atom->ToString(aResult); break; } case eInteger: { nsAutoString intStr; intStr.AppendInt(GetIntegerValue()); aResult = intStr; break; } #ifdef DEBUG case eColor: { NS_NOTREACHED("color attribute without string data"); aResult.Truncate(); break; } #endif case eEnum: { GetEnumString(aResult, PR_FALSE); break; } case ePercent: { nsAutoString intStr; intStr.AppendInt(cont ? cont->mPercent : GetIntInternal()); aResult = intStr + NS_LITERAL_STRING("%"); break; } case eCSSStyleRule: { aResult.Truncate(); MiscContainer *container = GetMiscContainer(); css::Declaration *decl = container->mCSSStyleRule->GetDeclaration(); if (decl) { decl->ToString(aResult); } const_cast<nsAttrValue*>(this)->SetMiscAtomOrString(&aResult); break; } case eSVGValue: { GetMiscContainer()->mSVGValue->GetValueString(aResult); break; } case eDoubleValue: { aResult.Truncate(); aResult.AppendFloat(GetDoubleValue()); break; } default: { aResult.Truncate(); break; } } }
inline BaseType base(Type t) { return BaseType(toNative(t) & 0xFF00); }