/// <summary> /// Outputs the VHDL representation of a <code>VhdlElement</code> to a <code>Writer</code> using a custom code format. /// </summary> /// <param name="element">the VHDL element</param> /// <param name="format">the custom code format</param> /// <param name="writer">the <code>Writer</code></param> public static void toWriter(VhdlElement element, IVhdlCodeFormat format, StreamWriter writer) { VhdlWriter vhdlWriter = new VhdlWriter(writer, format); OutputModule output = new VhdlOutputModule(vhdlWriter); output.writeVhdlElement(element); }
private List <object> GetContextListOfObjects(VhdlElement element) { List <object> res = new List <object>(); if (element == null) { return(res); } IDeclarativeRegion parent = element.Parent; IScope scope = null; if (element is IDeclarativeRegion) { scope = (element as IDeclarativeRegion).Scope; res.AddRange(scope.GetListOfObjects()); } else { if (parent != null) { scope = parent.Scope; res.AddRange(scope.GetListOfObjects()); } } return(res); }
/// <summary> /// Writes the VHDL representation of a <code>VhdlElement</code> to a file using a custom code format. /// </summary> /// <param name="element">the VHDL element</param> /// <param name="format">the custom code format</param> /// <param name="fileName">the name of the file</param> public static void toFile(VhdlElement element, IVhdlCodeFormat format, string fileName) { FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); toWriter(element, format, writer); writer.Close(); stream.Close(); }
public static Out Parse <In, Out>(In data_in, Func <In, VhdlElement> visit_function) where In : class where Out : class { if (data_in == null) { throw new ArgumentNullException(string.Format("Argument data_in is null")); } VhdlElement parsed_data = visit_function(data_in); Out res = CastExtention.Cast <VhdlElement, Out>(parsed_data); return(res); }
/// <summary> /// Writes a VhdlElement. /// </summary> /// <param name="element">the element</param> public virtual void writeVhdlElement(VhdlElement element) { if (element is VhdlFile) { writeLibraryUnits(((VhdlFile)element).Elements); } else if (element is ComponentSpecification) { writeComponentSpecification((ComponentSpecification)element); } else if (element is ConcurrentStatement) { writeConcurrentStatement((ConcurrentStatement)element); } else if (element is ConfigurationItem) { writeConfigurationItem((ConfigurationItem)element); } else if (element is DeclarativeItem) { writeDeclaration((DeclarativeItem)element); } else if (element is Expression) { writeExpression((Expression)element); } else if (element is LibraryUnit) { writeLibraryUnit((LibraryUnit)element); } else if (element is SequentialStatement) { writeSeqentialStatement((SequentialStatement)element); } else { throw new ArgumentException("cannot output this element"); } }
public static bool TryParse <In, Out>(In data_in, Func <In, VhdlElement> visit_function, out Out res) where In : class where Out : class { res = null; if (data_in == null) { return(false); } try { VhdlElement parsed_data = visit_function(data_in); bool successfull = CastExtention.TryCast <VhdlElement, Out>(parsed_data, out res); return(successfull); } catch { res = null; return(false); } }
/// <summary> /// Converts a <code>VhdlElement</code> to a string using a custom code format. /// </summary> /// <param name="element">the VHDL element</param> /// <param name="format">the custom code format</param> /// <returns>the converted string</returns> public static string toVhdlString(VhdlElement element, IVhdlCodeFormat format) { MemoryStream stream = new MemoryStream(); StreamWriter stringWriter = new StreamWriter(stream); try { toWriter(element, format, stringWriter); } catch (IOException ex) { //shouldn't happen for a string writer throw new ArgumentException(); } stringWriter.Close(); StreamReader reader = new StreamReader(stream); string res = reader.ReadToEnd(); reader.Close(); stream.Close(); return(res); }
public override void LoadData() { try { int cursor_offset = TextArea.Caret.Offset; VhdlElement element = lexter.GetElementByOffset(lexter.File, cursor_offset); List <object> obects = new List <object>(); obects.AddRange(GetContextListOfObjects(element).Distinct()); List <CompletionListItem> Data = LoadWordsFromObjects(obects); Data.AddRange(LoadReservedWords()); IList <ICompletionData> CompletionData = completionWindow.CompletionList.CompletionData; foreach (CompletionListItem item in Data) { CompletionData.Add(new MyCompletionData(item)); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Code completion Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification); } }
/// <summary> /// Writes the VHDL representation of a <code>VhdlElement</code> to a file. /// The default code format is used to convert the <code>VhdlElement</code> to VHDL code. /// </summary> /// <param name="element">the VHDL element</param> /// <param name="fileName">name of the file</param> public static void toFile(VhdlElement element, string fileName) { toFile(element, DEFAULTVhdlCodeFormat.DEFAULT, fileName); }
/// <summary> /// Converts a <code>VhdlElement</code> to a string using the default code format. /// </summary> /// <param name="element">the VHDL element</param> /// <returns>the converted string</returns> public static string toVhdlString(VhdlElement element) { return(toVhdlString(element, DEFAULTVhdlCodeFormat.DEFAULT)); }
/// <summary> /// Prints the VHDL representation of a <code>VhdlElement</code> to <code>System.out</code> using /// a custom code format. /// </summary> /// <param name="element">the VHDL element</param> /// <param name="format">the custom code format</param> public static void print(VhdlElement element, IVhdlCodeFormat format) { Console.WriteLine(toVhdlString(element, format)); }
/// <summary> /// Prints the VHDL representation of a <code>VhdlElement</code> to <code>System.out</code>. /// The default code format is used to convert the <code>VhdlElement</code> to the string that /// is printed. /// </summary> /// <param name="element"></param> public static void print(VhdlElement element) { Console.WriteLine(toVhdlString(element)); }
/// <summary> /// Outputs the VHDL representation of a <code>VhdlElement</code> to a <code>Writer</code>. /// The default code format is used to generate the VHDL output. /// </summary> /// <param name="element">the VHDL element</param> /// <param name="writer">the <code>Writer</code></param> public static void toWriter(VhdlElement element, StreamWriter writer) { toWriter(element, DEFAULTVhdlCodeFormat.DEFAULT, writer); }
/// <summary> /// Получение информации о позиции в коде элемента /// </summary> /// <param name="parent"></param> /// <returns></returns> public PositionInformation GetPositionInformation(VhdlElement parent) { return(Annotations.getAnnotation <PositionInformation>(parent)); }
/// <summary> /// Получение элемента семантического дерева по его смещению /// </summary> /// <param name="parent"></param> /// <param name="offset"></param> /// <returns></returns> public VhdlElement GetElementByOffset(VhdlElement parent, int offset) { if ((parent == null) || (file == null)) { return(null); } if (((parent is IDeclarativeRegion) == false) && ((parent is SequentialStatement) == false)) { return(parent); } if (parent is IDeclarativeRegion) { IDeclarativeRegion decl = parent as IDeclarativeRegion; List <object> objects = decl.Scope.GetLocalListOfObjects(); if (objects.Count >= 1) { foreach (object obj in objects) { if (parent == obj) { continue; } if (obj is VhdlElement) { PositionInformation pos = GetPositionInformation(obj as VhdlElement); if ((pos != null) && (pos.Begin.Index <= offset) && (pos.End.Index >= offset)) { (obj as VhdlElement).Parent = (parent as IDeclarativeRegion); return(GetElementByOffset(obj as VhdlElement, offset)); } if (pos == null) { (obj as VhdlElement).Parent = (parent as IDeclarativeRegion); return(obj as VhdlElement); } } } } } if (parent is SequentialStatement) { SequentialStatement stat = parent as SequentialStatement; List <VhdlElement> objects = stat.GetAllStatements(); if (objects.Count >= 1) { foreach (VhdlElement obj in objects) { if (parent == obj) { continue; } if (obj == null) { continue; } PositionInformation pos = GetPositionInformation(obj as VhdlElement); if ((pos != null) && (pos.Begin.Index <= offset) && (pos.End.Index >= offset)) { (obj as VhdlElement).Parent = ((parent as SequentialStatement).Parent); return(GetElementByOffset(obj as VhdlElement, offset)); } if (pos == null) { (obj as VhdlElement).Parent = (parent as IDeclarativeRegion); return(obj as VhdlElement); } } } } return(parent); }