/// <summary> /// Добавление нового файла в проект /// </summary> /// <param name="filePath"></param> /// <returns></returns> public override CodeFile AddCodeFile(string filePath) { LibraryDeclarativeRegion lib = GetLibraryForFile(filePath); VHDL_CodeFile newCode = new VHDL_CodeFile(filePath, lib.Identifier, this); files.Add(newCode); return(newCode); }
public override void Update(string text) { if ((Compiler != null) && (Compiler is VHDLCompiler)) { VHDLCompiler compiler = Compiler as VHDLCompiler; ErrorList.Clear(); codeFile = compiler.GetFileByPath(extendedTextEditor.FilePath) as VHDL_CodeFile; if (codeFile == null) { codeFile = compiler.AddCodeFile(extendedTextEditor.FilePath) as VHDL_CodeFile; } if (codeFile != null) { codeFile.Text = text; compiler.ProcessCodeFile(codeFile); file = codeFile.File; tokenStream = codeFile.TokenStream; tree = codeFile.Tree; if (codeFile.ParseSyntaxException != null) { //foreach (RecognitionException err in codeFile.SyntaxErrors.Errors) //{ int offset = codeFile.ParseSyntaxException.OffendingSymbol.StartIndex; int length = codeFile.ParseSyntaxException.OffendingSymbol.StopIndex - offset + 1; Exception_Information inf = new Exception_Information(offset, length, codeFile.ParseSyntaxException.Message); ErrorList.Add(inf); //} } if (codeFile.ParseSemanticException != null) { //foreach (ParseError err in codeFile.SemanticErrors.Errors) //{ int offset = codeFile.ParseSemanticException.Context.Start.StartIndex; int length = codeFile.ParseSemanticException.Context.Start.StopIndex - offset + 1; Exception_Information inf = new Exception_Information(offset, length, codeFile.ParseSemanticException.Message); ErrorList.Add(inf); //} } } } }
public override SortedList <string, GHDLCompiledFile> ReparseLibrary() { SortedList <string, GHDLCompiledFile> library = new SortedList <string, GHDLCompiledFile>(); string head = string.Empty; foreach (CodeFile file in Files) { if (file is VHDL_CodeFile) { GHDLCompiledFile ghdlFile = new GHDLCompiledFile(); library.Add(file.FilePath, ghdlFile); head = file.FilePath; VHDL_CodeFile vhdlCode = file as VHDL_CodeFile; if (vhdlCode.File != null) { foreach (LibraryUnit unit in vhdlCode.File.Elements) { if (unit is Entity) { string tmp_entity_name = (unit as Entity).Identifier; if (!library[head].vhdlStruct.ContainsKey(tmp_entity_name)) { library[head].vhdlStruct.Add(tmp_entity_name, new List <string>()); } } if (unit is Architecture) { string tmp_arch_name = (unit as Architecture).Identifier; string tmp_entity_name = (unit as Architecture).Entity.Identifier; if (library[head].vhdlStruct.ContainsKey(tmp_entity_name)) { if (!library[head].vhdlStruct[tmp_entity_name].Contains(tmp_arch_name)) { library[head].vhdlStruct[tmp_entity_name].Add(tmp_arch_name); } } } } } } } return(library); }
/// <summary> /// Установление связей между файлами /// </summary> private void SetDependencies() { foreach (CodeFile f1 in Files) { f1.Dependencies.Clear(); } foreach (CodeFile f1 in Files) { foreach (CodeFile f2 in Files) { if ((f1 != f2) && (f1 is VHDL_CodeFile) && (f2 is VHDL_CodeFile)) { VHDL_CodeFile vf1 = (f1 as VHDL_CodeFile); VHDL_CodeFile vf2 = (f2 as VHDL_CodeFile); if ((vf1.LibraryFileInfo.IsDependedTo(vf2.LibraryFileInfo) == true)) { f1.Dependencies.Add(f2); } } } } }
/// <summary> /// Если обьект класса CodeFile является VHDL_CodeFile, /// то провести его обработку и встроить в общую библиотеку, /// новый поток не создается, /// ошибки выписываются в обьект file /// </summary> /// <param name="file"></param> public override void ProcessCodeFile(CodeFile file) { try { lock (this) { isBusy = true; if ((file is VHDL_CodeFile) && ((file as VHDL_CodeFile).LibraryName == "work")) { VHDL_CodeFile vhdlCode = (file as VHDL_CodeFile); vhdlCode.ParseException = null; vhdlCode.ParseSyntaxException = null; vhdlCode.ParseSemanticException = null; VhdlFile oldFile = null; foreach (VhdlFile f in currentLibrary.Files) { if (f.FilePath == file.FilePath) { oldFile = f; break; } } if (oldFile != null) { currentLibrary.Files.Remove(oldFile); } IParseTree tree; CommonTokenStream tokenStream; ICharStream stream = new CaseInsensitiveStringStream(file.Text, file.FilePath); VhdlFile ParsedFile = Parse(stream, currentLibrary, out tokenStream, out tree); if (ParsedFile != null) { ParsedFile.FilePath = file.FilePath; } vhdlCode.File = ParsedFile; vhdlCode.ParseSemanticException = parseSemanticException; vhdlCode.ParseSyntaxException = parseSyntaxException; vhdlCode.ParseException = parseException; vhdlCode.TokenStream = tokenStream; vhdlCode.Tree = tree; vhdlCode.LibraryFileInfo = LibraryFileInfo.AnalyseText(vhdlCode.Text, vhdlCode.FilePath, vhdlCode.LibraryName); foreach (CodeFile f in vhdlCode.Dependencies) { f.NeedForUpdate = true; } SetDependencies(); } base.ProcessCodeFile(file); isBusy = false; } } catch (Exception ex) { Messages.Add(new DiagnosticMessage(string.Format("Message: {0}\n Source: {1}\n StackTrace: {2}\n HelpLink: {3}", ex.Message, ex.Source, ex.StackTrace, ex.HelpLink))); NotifyCollectionChanged(); } }