Exemple #1
0
//*****************************************************************************
// cascading Mark of an TypeDef token
//*****************************************************************************
HRESULT FilterManager::MarkTypeDef(
    mdTypeDef   td)
{
    HRESULT         hr = NOERROR;
    TypeDefRec      *pRec;
    IHostFilter     *pFilter = m_pMiniMd->GetHostFilter();
    DWORD           dwFlags;
    RID             iNester;

    // We know that the filter table is not null here.  Tell PREFIX that we know it.
    PREFIX_ASSUME(m_pMiniMd->GetFilterTable() != NULL);

    // if TypeDef is already marked, just return
    if (m_pMiniMd->GetFilterTable()->IsTypeDefMarked(td))
        goto ErrExit;

    // Mark the TypeDef first to avoid duplicate marking
    IfFailGo( m_pMiniMd->GetFilterTable()->MarkTypeDef(td) );
    if (pFilter)
        pFilter->MarkToken(td);

    // We don't need to mark InterfaceImpl but we need to mark the
    // TypeDef/TypeRef associated with InterfaceImpl.
    IfFailGo( MarkInterfaceImpls(td) );

    // mark the base class
    IfFailGo(m_pMiniMd->GetTypeDefRecord(RidFromToken(td), &pRec));
    IfFailGo( Mark(m_pMiniMd->getExtendsOfTypeDef(pRec)) );

    // mark all of the children of this TypeDef
    IfFailGo( MarkMethodsWithParentToken(td) );
    IfFailGo( MarkMethodImplsWithParentToken(td) );
    IfFailGo( MarkFieldsWithParentToken(td) );
    IfFailGo( MarkEventsWithParentToken(td) );
    IfFailGo( MarkPropertiesWithParentToken(td) );

    // mark any GenericParam of this TypeDef
    IfFailGo( MarkGenericParamWithParentToken(td) );

    // mark custom value and permission
    IfFailGo( MarkCustomAttributesWithParentToken(td) );
    IfFailGo( MarkDeclSecuritiesWithParentToken(td) );

    // If the class is a Nested class mark the parent, recursively.
    dwFlags = m_pMiniMd->getFlagsOfTypeDef(pRec);
    if (IsTdNested(dwFlags))
    {
        NestedClassRec      *pNestClassRec;
        IfFailGo(m_pMiniMd->FindNestedClassHelper(td, &iNester));
        if (InvalidRid(iNester))
            IfFailGo(CLDB_E_RECORD_NOTFOUND);
        IfFailGo(m_pMiniMd->GetNestedClassRecord(iNester, &pNestClassRec));
        IfFailGo(MarkTypeDef(m_pMiniMd->getEnclosingClassOfNestedClass(pNestClassRec)));
    }

ErrExit:
    return hr;
} // HRESULT FilterManager::MarkTypeDef()
Exemple #2
0
HRESULT CAsmLink::ExportNestedType(mdAssembly AssemblyID, mdToken FileToken, mdTypeDef TypeToken, 
                            mdExportedType ParentType, LPCWSTR pszTypename, DWORD dwFlags, mdExportedType* pType)
{
    ASSERT(m_bInited && !m_bPreClosed);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT(AssemblyID == FileToken || (RidFromToken(FileToken) < m_pAssem->CountFiles() && TypeFromToken(FileToken) == mdtFile));
    ASSERT(IsTdNested(dwFlags));
    if (AssemblyID == AssemblyIsUBM || FileToken == AssemblyID)
        return S_FALSE;

    return m_pAssem->AddExportType( ParentType, TypeToken, pszTypename, dwFlags, pType);
}
Exemple #3
0
void    AsmMan::EndComType()
{
    if(m_pCurComType)
    {
        if(m_pAssembler)
        { 
            Class* pClass =((Assembler*)m_pAssembler)->m_pCurClass;
            if(pClass)
            {
                m_pCurComType->tkClass = pClass->m_cl;
                if(pClass->m_pEncloser)
                {
                    mdTypeDef tkEncloser = pClass->m_pEncloser->m_cl;
                    AsmManComType* pCT;
                    for(unsigned i=0; (pCT=m_ComTypeLst.PEEK(i)); i++)
                    {
                        if(pCT->tkClass == tkEncloser)
                        {
                            m_pCurComType->szComTypeName = pCT->szName;
                            break;
                        }
                    }
                }
            }
        }

        if (IsTdNested(m_pCurComType->dwAttr) && GetComTypeByName(m_pCurComType->szName, m_pCurComType->szComTypeName) != NULL)
        {
            report->error("Invalid TypeDefID of exported type\n");
            delete m_pCurComType;
        }
        else
        {
            m_ComTypeLst.PUSH(m_pCurComType);
        }

        m_pCurComType = NULL;
        ((Assembler*)m_pAssembler)->m_tkCurrentCVOwner = 0;
        ((Assembler*)m_pAssembler)->m_pCustomDescrList = ((Assembler*)m_pAssembler)->m_CustomDescrListStack.POP();
    }
}
std::wstring SignatureReader::Parse(FunctionID functionID)
{
	mdToken funcToken;

	HRESULT hr = S_OK;
	PCCOR_SIGNATURE signature = 0;
	ULONG sigLength = 0;

	this->output.str(L"");
	this->className.str(L"");

	// get the token for the function which we will use to get its name
	hr = profilerInfo->GetTokenAndMetaDataFromFunction(functionID, IID_IMetaDataImport, (LPUNKNOWN *) &metaData, &funcToken);
	if(SUCCEEDED(hr))
	{
		mdTypeDef classTypeDef;
		ULONG cchFunction;
		ULONG cchClass;

		// retrieve the function properties based on the token
		hr = metaData->GetMethodProps(funcToken, &classTypeDef, szFunction, NAME_BUFFER_SIZE, &cchFunction, 0, &signature, &sigLength, 0, 0);
		if (SUCCEEDED(hr))
		{
			DWORD classFlags;
			std::stack<std::wstring> classStack;
			for (;;)
			{
				// get the class name
				hr = metaData->GetTypeDefProps(classTypeDef, szClass, NAME_BUFFER_SIZE, &cchClass, &classFlags, 0);
				if (!SUCCEEDED(hr))
					break;

				classStack.push(std::wstring(szClass));

				if (!IsTdNested(classFlags))
					break;

				hr = metaData->GetNestedClassProps(classTypeDef, &classTypeDef);

				if (!SUCCEEDED(hr))
					break;
			}

			while (!classStack.empty()) {
				this->className << classStack.top();
				classStack.pop();
				if (!classStack.empty())
					this->className << L"+";
			}

			std::wstring name = className.str();
			AppendEscapedString(name);
			this->output << L".";
			AppendEscapedString(szFunction);

			this->fullName = this->output.str();

			this->output.str(L"");

			if (SUCCEEDED(hr)) {
				this->data = (unsigned char *)signature;
				this->dataLength = sigLength;
				this->startPosition = this->data;
				this->endPosition = this->data + sigLength;
				this->methodDefiniton = funcToken;

				this->Parse();
			}
		}
		// release our reference to the metadata
		metaData->Release();
	}

	return this->output.str();
}