コード例 #1
0
ファイル: ReflectionUtil.cs プロジェクト: lesterbogran/uncs
        //------------------------------------------------------------
        // NestedTypeResolver.ResolveType
        //
        /// <summary>
        /// Find the class specified in args and create its Type.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal Assembly ResolveType(object sender, ResolveEventArgs args)
        {
            if (args == null || String.IsNullOrEmpty(args.Name))
            {
                return(null);
            }

            string[]  names     = args.Name.Split('.');
            AGGSYM    aggSym    = null;
            AGGSYM    parentSym = this.EnclosingAggSym;
            Exception excp      = null;

            for (int i = 0; i < names.Length; ++i)
            {
                aggSym = compiler.LookupGlobalSym(names[i], parentSym, SYMBMASK.AGGSYM) as AGGSYM;
                if (aggSym == null)
                {
                    return(null);
                }
                parentSym = aggSym;
            }

            aggSym.CreateType(out excp);
            OUTFILESYM outfileSym = aggSym.GetOutputFile();

            if (outfileSym != null && outfileSym.AssemblyBuilderEx != null)
            {
                return(outfileSym.AssemblyBuilderEx.AssemblyBuilder);
            }
            return(null);
        }
コード例 #2
0
ファイル: FileIter.cs プロジェクト: lesterbogran/uncs
 //------------------------------------------------------------
 // InFileIteratorBase.Reset
 //
 /// <summary>
 /// <para>Set the first valid INFILESYM of the child list
 /// of outfile to currentInFileSym.</para>
 /// </summary>
 //------------------------------------------------------------
 internal INFILESYM Reset(OUTFILESYM outfile)
 {
     currentInFileSym = outfile.FirstInFileSym();
     if (currentInFileSym == null)
     {
         return(null);
     }
     AdvanceToValid();
     return(Current);
 }
コード例 #3
0
ファイル: FileIter.cs プロジェクト: lesterbogran/uncs
 //------------------------------------------------------------
 // OutFileIteratorBase.Next
 //
 /// <summary>
 /// (R) Find the next valid OUTFILESYM with AdvanceToValid method recursively.
 /// </summary>
 //------------------------------------------------------------
 virtual internal OUTFILESYM Next()
 {
     if (currentOutFileSym == null)
     {
         return(null);
     }
     currentOutFileSym = currentOutFileSym.NextOutputFile();
     AdvanceToValid();
     return(Current);
 }
コード例 #4
0
ファイル: FileIter.cs プロジェクト: lesterbogran/uncs
        //------------------------------------------------------------
        // OutFileIteratorBase.Reset
        //
        /// <summary>
        /// OUTFILESYMs are elements of the child list
        /// of compiler.MainSymbolManager.FileRootSym.
        /// Search the first valid OUTFILESYM in the list
        /// and set it currentOutFileSym.
        /// </summary>
        /// <param name="compiler"></param>
        //------------------------------------------------------------
        virtual internal OUTFILESYM Reset(COMPILER compiler)
        {
            currentOutFileSym = compiler.GetFirstOutFile();
            if (currentOutFileSym == null)
            {
                return(null);
            }

            AdvanceToValid();
            return(Current);
        }
コード例 #5
0
        //------------------------------------------------------------
        // CAsmLink::ImportFileEx2 (sscli)
        //------------------------------------------------------------
        //virtual internal HRESULT  ImportFileEx2(
        //    LPCWSTR pszFilename,
        //    LPCWSTR pszTargetName,
        //    IMetaDataAssemblyImport *pAssemblyScopeIn,
        //    BOOL fSmartImport,
        //    DWORD dwOpenFlags,
        //    mdToken *pFileToken,
        //    IMetaDataAssemblyImport **ppAssemblyScope,
        //    DWORD *pdwCountOfScopes)
        //{
        //    ASSERT(m_bInited);
        //    LPWSTR newTarget = NULL;
        //    bool bNewTarget = false;
        //    bool fIsInMemory = (pAssemblyScopeIn != NULL);
        //
        //    IMetaDataAssemblyImport *pAImport = NULL;
        //    IMetaDataImport *pImport = NULL;
        //    mdAssembly tkAssembly;
        //
        //    //--------------------------------------------------
        //    // Check if pszFilename is valid.
        //    // If pszTargetName is NULL, assign pszFilename to it.
        //    //--------------------------------------------------
        //    if (pszFilename == NULL)
        //        return E_INVALIDARG;
        //    if (wcslen(pszFilename) > MAX_PATH)
        //        return FileNameTooLong(pszFilename);
        //    if (pszTargetName && wcslen(pszTargetName) > MAX_PATH)
        //        return FileNameTooLong(pszTargetName); // File name too long
        //
        //    if (pszTargetName == NULL)
        //        newTarget = VSAllocStr(pszFilename);
        //    else
        //        newTarget = VSAllocStr(pszTargetName);
        //    if (newTarget == NULL)
        //        return E_OUTOFMEMORY;
        //
        //    if (_wcsicmp(newTarget, pszFilename) == 0) {
        //    } else {
        //        bNewTarget = true;
        //    }
        //
        //    //--------------------------------------------------
        //    // If pAssemblyScopeIn is valid, use it.
        //    //--------------------------------------------------
        //    if ((pAImport = pAssemblyScopeIn) != NULL)
        //    {
        //        //EDMAURER If bNewTarget is true and the source file is not an assembly, then pAImport
        //        //must be an object from which one can QI for IID_IMetaDataEmit. And it may not be
        //        //depending on the openflags used when it was created.
        //        //Becomes an issue with UpdateModuleName () below.
        //        pAImport->AddRef();
        //    }
        //    //--------------------------------------------------
        //    // If pAssemblyScopeIn is null, search the RegMeta instance by pszFilename,
        //    // if not found, create a RegMeta instace, and use it as pAImport.
        //    //--------------------------------------------------
        //    else
        //    {
        //        if (bNewTarget && IsOfReadOnly (dwOpenFlags)) {
        //            //EDMAURER would like to also check for !IsAssembly (pszFilename) in this IF.
        //            //Massage OpenFlags such that ofReadOnly is not used. Fall back on ofRead
        //            //which was used before the introduction of ofReadOnly. That permits QI for IMetadataEmit.
        //            //This is done to satisfy the UpdateModuleName () call below.
        //            dwOpenFlags &= ~ofReadOnly;
        //            dwOpenFlags |= ofRead;
        //        }
        //
        //        // Search or create the RegMeta instance.
        //        // The metadata section is opened in the RegMeta instance.
        //        HRESULT hr = m_pDisp->OpenScope(pszFilename, dwOpenFlags, IID_IMetaDataAssemblyImport, (IUnknown**)&pAImport);
        //        if (FAILED(hr)) {
        //            *pFileToken = 0;
        //            if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //            if (pdwCountOfScopes) *pdwCountOfScopes = 0;
        //            delete [] newTarget;
        //            return hr;
        //        }
        //    }
        //
        //    HRESULT hr;
        //    if (FAILED(hr = pAImport->QueryInterface( IID_IMetaDataImport, (void**)&pImport))) {
        //        *pFileToken = 0;
        //        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //        if (pdwCountOfScopes) *pdwCountOfScopes = 0;
        //        delete [] newTarget;
        //        return hr;
        //    }
        //
        //    //--------------------------------------------------
        //    // this file is not an assembly (does not have a manifest).
        //    //--------------------------------------------------
        //    if (FAILED(hr = pAImport->GetAssemblyFromScope( &tkAssembly))) {
        //
        //        hr = S_FALSE;
        //        // This is NOT an assembly
        //        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //        if (pdwCountOfScopes) *pdwCountOfScopes = 1;
        //        *pFileToken = mdTokenNil;
        //        CFile* file = new CFile();
        //        if (file == NULL) {
        //            hr = E_OUTOFMEMORY;
        //        } else if (SUCCEEDED(hr = file->Init(newTarget, pImport, m_pError, this))) {
        //            if (bNewTarget) {
        //                if (SUCCEEDED(hr = file->SetSource(pszFilename)))
        //                    hr = file->UpdateModuleName();
        //            }
        //        } else {
        //            delete file;
        //            file = NULL;
        //        }
        //        pAImport->Release();
        //        pImport->Release();
        //
        //        if (SUCCEEDED(hr) && SUCCEEDED(hr = m_pModules->AddFile( file, 0, pFileToken))) {
        //            if (fSmartImport)
        //                hr = file->ImportFile( NULL, NULL);
        //            *pFileToken = TokenFromRid(RidFromToken(*pFileToken), mdtModule);
        //        } else if (file != NULL) {
        //            delete file;
        //            file = NULL;
        //        }
        //        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //        if (SUCCEEDED(hr) && pdwCountOfScopes) *pdwCountOfScopes = 1;
        //        delete [] newTarget;
        //        return hr == S_OK ? S_FALSE : hr;
        //    }
        //    //--------------------------------------------------
        //    // this file is an assembly (has a manifest).
        //    //--------------------------------------------------
        //    else {
        //        // It is an Assembly
        //        CAssembly* assembly = new CAssembly();
        //        if (assembly == NULL) {
        //            hr = E_OUTOFMEMORY;
        //        } else if (SUCCEEDED(hr = assembly->Init( pszFilename, pAImport, pImport, m_pError, this))){
        //            if (ppAssemblyScope)
        //                *ppAssemblyScope = pAImport;
        //            else
        //                pAImport->Release();
        //            if (m_bDontDoHashes)
        //                assembly->DontDoHash();
        //            if (fIsInMemory)
        //                assembly->SetInMemory();
        //            // Get the informations of assembly, custum attributes, types.
        //            hr = assembly->ImportAssembly(pdwCountOfScopes, fSmartImport, dwOpenFlags, m_pDisp);
        //        } else {
        //            delete assembly;
        //            assembly = NULL;
        //        }
        //        pImport->Release();
        //
        //        if (SUCCEEDED(hr) && bNewTarget)
        //            hr = assembly->ReportError( ERR_CantRenameAssembly, mdTokenNil, NULL, pszFilename);
        //
        //        if (SUCCEEDED(hr) && m_pAssem != NULL)
        //            hr = m_pAssem->ComparePEKind( assembly, false);
        //
        //        delete [] newTarget;
        //        if (FAILED(hr)) {
        //            delete assembly;
        //            assembly = NULL;
        //            return hr;
        //        }
        //
        //        if (FAILED(hr = m_pImports->AddFile( assembly, 0, pFileToken)))
        //            delete assembly;
        //        return SUCCEEDED(hr) ? S_OK : hr;
        //    }
        //}

        //------------------------------------------------------------
        // CAsmLink.AddFile
        //------------------------------------------------------------
        virtual internal bool AddFile(
            OUTFILESYM outfileSym)
        {
            DebugUtil.Assert(this.inited && !this.assemblyEmitted && !this.preClosed);

            if (outfileSym.AssemblyBuilderEx != null)
            {
                this.assemblyBuilderEx = outfileSym.AssemblyBuilderEx;
                return(true);
            }
            this.assemblyBuilderEx = null;
            return(false);
        }
コード例 #6
0
ファイル: FileIter.cs プロジェクト: lesterbogran/uncs
 //------------------------------------------------------------
 // OutFileIteratorBase Constructor
 //------------------------------------------------------------
 protected OutFileIteratorBase()
 {
     currentOutFileSym = null;
 }