Exemple #1
0
        /// <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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        /// <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();
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 /// <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");
     }
 }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
        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);
            }
        }
Exemple #9
0
 /// <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);
 }
Exemple #10
0
 /// <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));
 }
Exemple #11
0
 /// <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));
 }
Exemple #12
0
 /// <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));
 }
Exemple #13
0
 /// <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);
 }
Exemple #14
0
 /// <summary>
 /// Получение информации о позиции в коде элемента
 /// </summary>
 /// <param name="parent"></param>
 /// <returns></returns>
 public PositionInformation GetPositionInformation(VhdlElement parent)
 {
     return(Annotations.getAnnotation <PositionInformation>(parent));
 }
Exemple #15
0
        /// <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);
        }