Beispiel #1
0
        //------------------------------------------------------------
        // ERRLOC Constructor (3)
        //
        /// <para>Constructor.</para>
        /// <para>Get the current position from the BASENODE argument and
        /// mapping information from INFILESYM.SourceData of BSYMMGR.</para>
        /// <param name="symmgr"></param>
        /// <param name="node"></param>
        //------------------------------------------------------------
        internal ERRLOC(BSYMMGR symmgr, BASENODE node, bool fullPath)
        {
            if (node != null)
            {
                DebugUtil.Assert(symmgr != null);

                string    inputFileName = node.GetContainingFileName(fullPath);
                INFILESYM inputFile     = symmgr.FindInfileSym(inputFileName);

                sourceFileName    = inputFileName;
                sourceMapFileName = inputFileName;

                if (inputFile != null)
                {
                    sourceData = inputFile.SourceData;
                    SetLine(node);
                    SetStart(node);
                    SetEnd(node);
                    mapStartPos = (startPos != null ? startPos.Clone() : null);
                    mapEndPos   = (endPos != null ? endPos.Clone() : null);

                    string sd;
                    bool   bd1, bd2;
                    sourceData.Module.MapLocation(mapStartPos, out sourceMapFileName, out bd1, out bd2);
                    sourceData.Module.MapLocation(mapEndPos, out sd, out bd1, out bd2);
                    return;
                }
            }
        }
Beispiel #2
0
        //------------------------------------------------------------
        // AggIterator
        //------------------------------------------------------------
        internal AGGSYM Reset(INFILESYM infile)
        {
            DebugUtil.Assert(infile.RootNsDeclSym != null);

            aggCur = GetFirstInListNsDecl(infile.RootNsDeclSym.FirstChildSym);
            return(aggCur);
        }
Beispiel #3
0
        //------------------------------------------------------------
        // ERRLOC Constructor (2)
        //
        /// <summary>
        /// <para>Constructor.</para>
        /// <para>Get the current position from the BASENODE argument and
        /// mapping information from INFILESYM.SourceData.</para>
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="node"></param>
        //------------------------------------------------------------
        internal ERRLOC(INFILESYM inputFile, BASENODE node, bool fullPath)
        {
            DebugUtil.Assert(inputFile != null);

            sourceData = inputFile.SourceData;

            sourceFileName    = (fullPath ? inputFile.FullName : inputFile.Name);
            sourceMapFileName = inputFile.Name;

            if (node != null)
            {
                SetLine(node);
                SetStart(node);
                this.endPos = new POSDATA();    //endPos.SetUninitialized();
                SetEnd(node);
                mapStartPos = (startPos != null ? startPos.Clone() : null);
                mapEndPos   = (endPos != null ? endPos.Clone() : null);

                string sd;       // dummy
                bool   bd1, bd2; // dummy

                // mapStart、mapEnd の行番号をマップ先のもので置き換え、ファイル名を取得する。
                sourceData.Module.MapLocation(mapStartPos, out sourceMapFileName, out bd1, out bd2);
                sourceData.Module.MapLocation(mapEndPos, out sd, out bd1, out bd2);
            }
        }
Beispiel #4
0
        //------------------------------------------------------------
        // ERRLOC Constructor (4)
        //
        /// <summary></summary>
        /// <param name="sym"></param>
        //------------------------------------------------------------
        internal ERRLOC(INFILESYM sym, bool fullPath)
        {
            DebugUtil.Assert(sym != null);

            sourceData        = sym.SourceData;
            sourceFileName    = (fullPath ? sym.FullName : sym.Name);
            sourceMapFileName = sourceFileName;
        }
Beispiel #5
0
 //------------------------------------------------------------
 // InFileIteratorBase.Next
 //
 /// <summary>
 /// Find the next valid INFILESYM with AdvanceToValid method recursively.
 /// </summary>
 //------------------------------------------------------------
 public INFILESYM Next()
 {
     currentInFileSym = currentInFileSym.NextInFileSym();
     if (currentInFileSym == null)
     {
         return(null);
     }
     AdvanceToValid();
     return(Current);
 }
Beispiel #6
0
 //------------------------------------------------------------
 // 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);
 }
Beispiel #7
0
        //------------------------------------------------------------
        // CAsmLink.AddFile (sscli)
        //------------------------------------------------------------
        //virtual internal HRESULT AddFile(
        //    mdAssembly AssemblyID,
        //    LPCWSTR pszFilename,
        //    DWORD dwFlags,
        //    IMetaDataEmit *pEmitter,
        //    mdFile * pFileToken)
        //{
        //    ASSERT(m_bInited && !m_bAssemblyEmitted && !m_bPreClosed);
        //    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
        //
        //    // NULL filename means 'InMemory' module, but we need a filename so convert it to the
        //    // empty string.
        //    if (pszFilename == NULL)
        //        pszFilename = L"";
        //
        //    HRESULT hr = E_FAIL;
        //
        //    if (AssemblyID == AssemblyIsUBM) {
        //        if (m_pAssem == NULL) {
        //
        //            CComPtr<IMetaDataAssemblyEmit> pAEmitter;
        //            hr = pEmitter->QueryInterface(IID_IMetaDataAssemblyEmit, (void**)&pAEmitter);
        //            if (FAILED(hr)) {
        //                return hr;
        //            }
        //
        //            m_pAssem = new CAssembly();
        //            if (m_pAssem == NULL)
        //                return E_OUTOFMEMORY;
        //
        //            if (FAILED(hr = m_pAssem->Init(m_pError, this, pAEmitter))) {
        //                delete m_pAssem;
        //                m_pAssem = NULL;
        //                return hr;
        //            }
        //        }
        //    }
        //
        //    if (wcslen(pszFilename) > MAX_PATH)
        //        return FileNameTooLong(pszFilename); // File name too long
        //
        //    CFile *file = new CFile();
        //    if (file == NULL) {
        //        return E_OUTOFMEMORY;
        //    }
        //    if (FAILED(hr = file->Init(pszFilename, pEmitter, m_pError, this)) ||
        //        FAILED(hr = m_pAssem->AddFile(file, dwFlags, pFileToken)))
        //        delete file;
        //
        //    return hr;
        //}

        // virtual internal HRESULT  AddFile2(mdAssembly AssemblyID, LPCWSTR pszFilename, DWORD dwFlags,
        //     IMetaDataEmit2 *pEmitter, mdFile * pFileToken);

        //------------------------------------------------------------
        // CAsmLink.AddImport
        //
        /// <summary>
        /// Add module specified by infileSym to this.assemblyBuilder.
        /// </summary>
        /// <param name="infileSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        virtual internal bool AddImport(INFILESYM infileSym)
        {
            CModuleEx cmod = this.assemblyBuilderEx.AddModule(
                infileSym,
                null,
                null,
                false);

            return(!(cmod == null));
        }
Beispiel #8
0
 //------------------------------------------------------------
 // InFileIteratorBase Constructor
 //------------------------------------------------------------
 protected InFileIteratorBase()
 {
     currentInFileSym = null;
 }
Beispiel #9
0
        //------------------------------------------------------------
        // CAsmLink.SetNonAssemblyFlags
        //
        // If afNoRefHash is specified and this.m_bDontDoHashes is not set,
        // set m_bDoHash false for all CAssembly instants in m_pImports,
        // If failed to get a CFile instance of a CAssembly instant, return error code.
        //------------------------------------------------------------
        //virtual internal HRESULT SetNonAssemblyFlags(AssemblyFlags afFlags)
        //{
        //    ASSERT(m_bInited && !m_bAssemblyEmitted && !m_bPreClosed);
        //    HRESULT hr = S_FALSE;
        //
        //    if (afFlags & afNoRefHash) {
        //        if (!m_bDontDoHashes) {
        //            // This just changed, so tell all the previously imported assemblies
        //            DWORD cnt = m_pImports->CountFiles();
        //            for (DWORD d = 0; d < cnt; d++) {
        //                CAssembly *pFile = NULL;
        //                if (FAILED(hr = m_pImports->GetFile(d, (CFile**)&pFile)))
        //                    return hr;
        //                pFile->DontDoHash();
        //            }
        //        }
        //        m_bDontDoHashes = true;
        //    }
        //
        //    return hr;
        //}

        // Files and importing

        //------------------------------------------------------------
        // CAsmLink.ImportFile  (Do not use, call ImportFileEx2)
        //------------------------------------------------------------
        // virtual internal HRESULT  ImportFile(
        //    LPCWSTR pszFilename,
        //    LPCWSTR pszTargetName,
        //    BOOL fSmartImport,
        //    mdToken *pFileToken,
        //    IMetaDataAssemblyImport **ppAssemblyScope,
        //    DWORD *pdwCountOfScopes)
        //{
        //    return ImportFileEx2(
        //        pszFilename,
        //        pszTargetName,
        //        NULL,
        //        fSmartImport,
        //        ofReadOnly | ofNoTypeLib,
        //        pFileToken,
        //        ppAssemblyScope,
        //        pdwCountOfScopes);
        //}

        //------------------------------------------------------------
        // CAsmLink.ImportFile2 (Do not use, call ImportFileEx2)
        //------------------------------------------------------------
        // virtual internal HRESULT  ImportFile2(
        //    LPCWSTR pszFilename,
        //    LPCWSTR pszTargetName,
        //    IMetaDataAssemblyImport *pAssemblyScopeIn,
        //    BOOL fSmartImport,
        //    mdToken *pFileToken,
        //    IMetaDataAssemblyImport **ppAssemblyScope,
        //    DWORD *pdwCountOfScopes)
        //{
        //    return ImportFileEx2(
        //        pszFilename,
        //        pszTargetName,
        //        pAssemblyScopeIn,
        //        fSmartImport,
        //        ofReadOnly | ofNoTypeLib,
        //        pFileToken,
        //        ppAssemblyScope,
        //        pdwCountOfScopes);
        //}

        //------------------------------------------------------------
        // CAsmLink.ImportFileEx    (Do not use, call ImportFileEx2)
        //------------------------------------------------------------
        // virtual internal HRESULT  ImportFileEx(
        //    LPCWSTR pszFilename,
        //    LPCWSTR pszTargetName,
        //    BOOL fSmartImport,
        //    DWORD dwOpenFlags,
        //    mdToken *pFileToken,
        //    IMetaDataAssemblyImport **ppAssemblyScope,
        //    DWORD *pdwCountOfScopes)
        //{
        //    return ImportFileEx2(
        //        pszFilename,
        //        pszTargetName,
        //        NULL,
        //        fSmartImport,
        //        dwOpenFlags,
        //        pFileToken,
        //        ppAssemblyScope,
        //        pdwCountOfScopes);
        //}

        //------------------------------------------------------------
        // CAsmLink.ImportFileEx2
        //
        /// <summary>
        /// Create a CModuleEx instance or CAssemblyEx instance for a given INFILESYM.
        /// </summary>
        /// <param name="infileSym"></param>
        /// <param name="targetName"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal bool ImportFileEx2(INFILESYM infileSym, string targetName)
        {
            //DebugUtil.Assert(m_bInited);
            if (infileSym == null || infileSym.FileInfo == null)
            {
                return(false);
            }

            string    newTarget   = null;
            bool      isNewTarget = false;
            Exception excp        = null;

            //--------------------------------------------------
            // Check if pszFilename is valid.
            // Then, if pszTargetName is NULL, assign pszFilename to it.
            //--------------------------------------------------
            FileInfo fileInfo   = infileSym.FileInfo;
            FileInfo targetInfo = null;

            if (!String.IsNullOrEmpty(targetName))
            {
                if (!IOUtil.CreateFileInfo(targetName, out targetInfo, out excp))
                {
                    return(false);
                }
            }

            if (targetInfo == null || String.IsNullOrEmpty(targetInfo.Name))
            {
                newTarget   = infileSym.Name;
                isNewTarget = false;
            }
            else
            {
                newTarget   = targetName;
                isNewTarget = (String.Compare(infileSym.Name, newTarget, true) != 0);
            }

            // If cassembly is null, create from fileName.

            //--------------------------------------------------
            // Module
            //
            // If the file is a module, load it as a module of this.assemblyBuilder.
            // And create CModule instance, add to this.importedModuleDic
            //--------------------------------------------------
            if (infileSym.IsModule)
            {
                if (infileSym.IsModuleLoaded)
                {
                    return(true);
                }
                if (this.tempAssemblyBuilder == null)
                {
                    CreateTempAssemblyBuilder();
                }

                CModuleEx cmod = this.tempAssemblyBuilder.AddModule(
                    infileSym,
                    null,
                    targetName,
                    false);
                if (cmod == null)
                {
                    return(false);
                }
                if (!this.importedModuleDic.Add(cmod.Name, cmod))
                {
                    // If the name is already registered, CDictionary.Add returns false.
                    // Show warning and contiue processing.
                }
                return(true);
            }
            //--------------------------------------------------
            // Assembly
            //--------------------------------------------------
            else if (infileSym.IsAssembly)
            {
                if (infileSym.IsAssemblyLoaded)
                {
                    return(true);
                }

                CAssemblyEx casm = new CAssemblyEx(this.controller);
                if (!casm.Init(infileSym.FileInfo, this))
                {
                    return(false);
                }
                //if (this.m_bDontDoHashes == true) casm.DontDoHash();
                //casm.SetInMemory();
                if (casm.ImportAssembly(true))
                {
                    if (isNewTarget)
                    {
                        this.controller.ReportError(
                            ALERRID.ERR_CantRenameAssembly,
                            ERRORKIND.ERROR,
                            infileSym.Name);
                    }

                    if (!this.importedAssemblyDic.Add(casm.FileFullName, casm))
                    {
                        // Duplicate. Show warning.
                        infileSym.SetMetadataFile(importedAssemblyDic[casm.FileFullName]);
                    }
                    else
                    {
                        infileSym.SetMetadataFile(casm);
                        if (casm.IsStdLib)
                        {
                            this.msCorLib = casm;
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }