コード例 #1
0
 protected override void visitUseClause(UseClause useClause)
 {
     writer.Append(KeywordEnum.USE.ToString()).Append(' ');
     writer.AppendStrings(useClause.getDeclarations(), ", ");
     writer.Append(';').NewLine();
 }
コード例 #2
0
        /// <summary>
        /// Проверка оператора use (поиск соответствующего пакета или элемента пакета)
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="useClause"></param>
        public bool CheckUseClause(ParserRuleContext tree, UseClause useClause)
        {
            List <string> declarations = useClause.getDeclarations();

            foreach (string declaration in declarations)
            {
                string[] elems = declaration.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if ((elems != null) && (elems.Length == 3))
                {
                    //Ищем библиотеку
                    string libraryName = elems[0];
                    IList <LibraryDeclarativeRegion> libraries = rootScope.Libraries;
                    foreach (LibraryDeclarativeRegion library in libraries)
                    {
                        if ((library != null) && (library.Identifier.EqualsIdentifier(libraryName)))
                        {
                            //Нашли необходимую библиотеку
                            //Ищем пакет
                            string packageName = elems[1];
                            foreach (VhdlFile file in library.Files)
                            {
                                foreach (LibraryUnit unit in file.Elements)
                                {
                                    if (unit is PackageDeclaration)
                                    {
                                        PackageDeclaration packege = unit as PackageDeclaration;
                                        if (packege.Identifier.EqualsIdentifier(packageName))
                                        {
                                            //Нашли необходимый пакет
                                            //Ищем нужный элемент
                                            string elemName = elems[2];
                                            if (elemName.EqualsIdentifier("all"))
                                            {
                                                if (useClause.LinkedElements.Contains(packege) == false)
                                                {
                                                    useClause.LinkedElements.Add(packege);
                                                }
                                                return(true);
                                            }
                                            object o = packege.Scope.resolveLocal(elemName);
                                            if ((o != null) && (o is INamedEntity))
                                            {
                                                INamedEntity el = o as INamedEntity;
                                                if (useClause.LinkedElements.Contains(el) == false)
                                                {
                                                    useClause.LinkedElements.Add(el);
                                                }
                                                return(true);
                                            }
                                            else
                                            {
                                                throw new VHDL.ParseError.vhdlUnknownUseClauseItemException(tree, FileName, elemName);
                                                return(false);
                                            }
                                        }
                                    }
                                }
                            }
                            throw new VHDL.ParseError.vhdlUnknownUseClausePrimaryUnitException(tree, FileName, packageName);
                            return(false);
                        }
                    }
                    throw new VHDL.ParseError.vhdlUnknownLibraryException(tree, FileName, libraryName);
                    return(false);
                }
                else
                {
                    throw new VHDL.ParseError.vhdlIllegalUseClauseException(tree, FileName);
                }
            }
            return(true);
        }