//------------------------------------------------------------ // CinputSet.SetWin32Icon // /// <summary></summary> /// <param name="fileName"></param> /// <returns></returns> //------------------------------------------------------------ virtual internal bool SetWin32Icon(string fileName) { if (String.IsNullOrEmpty(fileName)) { return(true); } if (this.Win32ResourceFileInfo != null) { return(false); } FileInfo fileInfo = null; Exception excp = null; if (IOUtil.CreateFileInfo(fileName, out fileInfo, out excp)) { return(SetWin32Icon(fileInfo)); } if (excp != null) { this.Controller.ReportError(ERRORKIND.ERROR, excp); } else { this.controller.ReportInternalCompilerError("CinputSet.SetWin32Icon"); } return(false); }
//------------------------------------------------------------ // CinputSet.FileNameToKeyString // /// <summary> /// Get FullName from fileName. FullName is used as key of CSourceFileInfoTable. /// (CSourceFileInfoTable ignores case of key.) /// </summary> /// <param name="fileName"></param> /// <param name="keyStr"></param> /// <returns></returns> //------------------------------------------------------------ private bool FileNameToKeyString(string fileName, out string keyStr) { keyStr = null; FileInfo finfo = null; Exception excp = null; if (!IOUtil.CreateFileInfo(fileName, out finfo, out excp) || finfo == null) { if (excp != null && this.Controller != null) { this.Controller.ReportError(ERRORKIND.ERROR, excp); } return(false); } keyStr = finfo.FullName.ToLower(); return(true); }
//------------------------------------------------------------ // IOUtil.GetCanonFileInfo // /// <summary> /// <para>Src and Dest may be the same buffer /// Returns 0 for error (check via GetLastError()) or count of characters /// (not including NULL) copied to Dest. /// if fPreserveSrcCasing is set, ignores on-disk casing of filename /// (but still gets on-disk casing of directories) /// if fPreserveSrcCasing is set and and existing file matches with different short/longness /// it will fail and set the error code to ERROR_FILE_EXISTS</para> /// </summary> /// <param name="srcFileName"></param> /// <returns></returns> //------------------------------------------------------------ static internal FileInfo GetCanonFileInfo(string srcFileName, out Exception excp) { FileInfo finfo = null; excp = null; // Remove quotes. replace \\ with \ unless \\ is not at the top of the string. NormalizeFilePath(ref srcFileName); // Create a FileInfo by srcFileName. if (!IOUtil.CreateFileInfo(srcFileName, out finfo, out excp)) { //throw new Exception(errorMessage); return(null); } return(finfo); }
//------------------------------------------------------------ // CinputSet.AddResourceFile (2) // /// <summary> /// <para>Regisger the pair of id and Info created by fileName.</para> /// <para>If id is already registerd, do not register.</para> /// </summary> /// <param name="fileName"></param> /// <param name="id"></param> /// <param name="embed"></param> /// <param name="vis"></param> //------------------------------------------------------------ virtual internal void AddResourceFile(string fileName, string id, bool embed, bool vis) { if (String.IsNullOrEmpty(fileName)) { return; } // Create a FileInfo instance by fileName. FileInfo fi; Exception excp = null; if (IOUtil.CreateFileInfo(fileName, out fi, out excp) && fi != null) { AddResourceFile(fi, id, embed, vis); } else if (excp != null && this.Controller != null) { this.Controller.ReportError(ERRORKIND.ERROR, excp); } }
//------------------------------------------------------------ // CinputSet.AddSourceFile (1) // /// <summary> /// <para>Create a CSourceFileInfo instance and register it.</para> /// <para>If its file name is already registerd, return false.</para> /// </summary> /// <param name="fileName"></param> /// <returns></returns> //------------------------------------------------------------ virtual internal bool AddSourceFile(string fileName) { FileInfo fi = null; Exception excp = null; if (!IOUtil.CreateFileInfo(fileName, out fi, out excp) || fi == null || String.IsNullOrEmpty(fi.FullName)) { if (excp != null) { this.Controller.ReportError(ERRORKIND.ERROR, excp); } return(false); } CSourceFileInfo si = new CSourceFileInfo(fi); return(sourceFileDictionary.Add(si.SearchName, si)); }
//------------------------------------------------------------ // CinputSet.SetPDBFile (2) // /// <summary></summary> /// <param name="fileName"></param> /// <returns></returns> //------------------------------------------------------------ virtual internal bool SetPDBFile(string fileName) { pdbFileInfo = null; if (String.IsNullOrEmpty(fileName)) { return(false); } FileInfo fileInfo = null; Exception excp = null; if (IOUtil.CreateFileInfo(fileName, out fileInfo, out excp)) { return(SetPDBFile(fileInfo)); } if (excp != null && this.Controller != null) { this.Controller.ReportError(ERRORKIND.ERROR, excp); } return(false); }
//------------------------------------------------------------ // CinputSet.SetOutputFile (2) // /// <summary></summary> /// <param name="fileName"></param> /// <returns></returns> //------------------------------------------------------------ virtual internal bool SetOutputFile(string fileName) { if (String.IsNullOrEmpty(fileName)) { this.outputFileInfo = null; this.target = TargetType.None; //noOutput = true; return(true); } //noOutput = false; Exception excp = null; if (IOUtil.CreateFileInfo(fileName, out outputFileInfo, out excp)) { return(true); } if (excp != null && this.Controller != null) { this.Controller.ReportError(ERRORKIND.ERROR, excp); } return(false); }
//------------------------------------------------------------ // CSConsoleArgs.wcstoul64 //------------------------------------------------------------ // to \Utilities //------------------------------------------------------------ // CSConsoleArgs.ExamineNoConfigOption // /// <summary> /// <para>(ConsoleArgs::ProcessAutoConfig in sscli)</para> /// <para>Process '/noconfig', and CSC.CFG, modifying the argument list</para> /// <para>Process Auto Config options: /// #1 search for '/noconfig' /// if not present and csc.cfg exists in EXE dir, inject after env var stuff</para> /// <para>/noconfig が指定されていなければ、 /// csc.rsp ファイルの内容をオプションリストに追加する。</para> /// </summary> //------------------------------------------------------------ private void ExamineNoConfigOption() { this.NoConfig = false; //-------------------------------------------------- // Scan the argument list for the "/noconfig" options. If present, just kill it and bail. // /noconfig または -noconfig が指定されていれば foundNoConfig に true をセットする。 //-------------------------------------------------- for (int i = 0; i < this.OptionList.Count; ++i) { string[] opt = this.OptionList[i]; // Skip everything except options if ((opt.Length < 3 || opt[1] != "/")) { continue; } if (String.Compare(opt[2], "noconfig", true) == 0) { this.NoConfig = true; // /noconfig オプションは引数リストから削除する。 // 複数回指定されている可能性もあるので break しない。 this.OptionList[i] = null; } } // /noconfig が指定されている場合は終了する。 if (this.NoConfig) { return; } //-------------------------------------------------- // 指定されていない場合は csc.rsp をレスポンスファイルとしてオプションに追加する。 // まずこのアセンブリと同じディレクトリに csc.rsp があるか調べる。 //-------------------------------------------------- string rspFullName = null; System.IO.FileInfo finfo = null; Exception excp = null; try { rspFullName = Path.Combine( Path.GetDirectoryName(Assembly.GetAssembly(typeof(Util)).Location), @"csc.rsp"); } catch (ArgumentException ex) { this.Controller.ReportError(ERRORKIND.ERROR, ex); return; } catch (PathTooLongException ex) { this.Controller.ReportError(ERRORKIND.ERROR, ex); return; } if (!IOUtil.CreateFileInfo(rspFullName, out finfo, out excp) || finfo == null) { if (excp != null) { this.Controller.ReportError(ERRORKIND.ERROR, excp); } else { this.Controller.ReportInternalCompilerError("ExamineNoConfigOption"); } return; } if (!finfo.Exists) { // In this project, mscorlib.dll and system.dll are always imported. // So, it is not an error that csc.rsp is not found. this.Controller.WriteLine("no csc.rsp"); return; } // If cannot open csc.rsp, show warning. if ((finfo.Attributes & ( System.IO.FileAttributes.Compressed | System.IO.FileAttributes.Directory | System.IO.FileAttributes.Encrypted)) != 0) { this.Controller.ReportError(ERRORKIND.WARNING, "csc.rsp could not be opened."); return; } //-------------------------------------------------- // この時点では実際に csc.rsp が存在し読み取り可能である。 // 先頭に @ をつけてオプションリストの先頭に追加する。 //-------------------------------------------------- this.OptionList.Insert(0, new string[3] { "@" + rspFullName, "@", rspFullName }); }
//------------------------------------------------------------ // 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); }