/// <summary> /// Сериализация декларации в файл /// </summary> /// <param name="declarationLibPath"></param> /// <param name="declaration"></param> private static void SaveDeclaration(string declarationLibPath, PackageDeclaration declaration) { Stream stream = new FileStream(declarationLibPath, FileMode.Create); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(stream, declaration); stream.Close(); }
/// <summary> /// Creates a package body. /// </summary> /// <param name="pack">the associated package</param> public PackageBody(PackageDeclaration pack) : base(pack) { declarations = VhdlCollections.CreateDeclarationList <PackageBodyDeclarativeItem>(); resolvable = new ResolvableImpl(this); scope = Scopes.createScope(this, declarations, resolvable, new LibraryUnitResolvable(this)); this.pack = pack; pack.PackageBody = this; }
/// <summary> /// Получение тела пакета по его декларации /// </summary> /// <param name="packDecl"></param> /// <returns></returns> public PackageBody GetPackageBody(PackageDeclaration packDecl) { foreach (LibraryInfo lib in Libraries) { foreach (PackageInfo pack in lib.Packages) { if (pack.Declaration.Equals(packDecl)) { return(pack.Body); } } } return(null); }
protected override void visitPackageDeclaration(PackageDeclaration packageDeclaration) { writer.Append(KeywordEnum.PACKAGE.ToString()).Append(' '); writer.AppendIdentifier(packageDeclaration).Append(' '); writer.Append(KeywordEnum.IS.ToString()).NewLine(); writer.Indent(); output.writeDeclarationMarkers(packageDeclaration.Declarations); writer.Dedent(); writer.Append(KeywordEnum.END.ToString()); if (writer.Format.RepeatLabels) { writer.Append(' ').Append(KeywordEnum.PACKAGE.ToString()); writer.Append(' ').AppendIdentifier(packageDeclaration); } writer.Append(";").NewLine(); }
private OrdinaryCompilationUnit ReadOrdinaryCompilationUnit() { PackageDeclaration packageDecl = null; List <ImportDeclaration> importDecls = new List <ImportDeclaration>(); List <TypeDeclaration> typeDecls = new List <TypeDeclaration>(); // Check for package declaration if (HasMoreTokens()) { Action action = () => { }; // Do nothing by default LookAhead(() => { DiscardAnnotationsCompilationUnit(); if (IsSymbol(PeekToken(), "package")) { action = () => { packageDecl = ReadPackageDeclaration(); }; } }); action(); } // Check for import declarations while (HasMoreTokens()) { if (IsSymbol(PeekToken(), "import")) { importDecls.Add(ReadImportDeclaration()); } } // Check for type declarations while (HasMoreTokens()) { if (IsSymbol(PeekToken(), ";")) { ReadSymbol(";"); } else { typeDecls.Add(ReadTypeDeclaration()); } } return(new OrdinaryCompilationUnit(packageDecl, importDecls, typeDecls)); }
/// <summary> /// Статическая функция для загрузки декларации пакета /// </summary> /// <param name="declarationLibPath"></param> /// <returns></returns> private static PackageDeclaration LoadDeclaration(string declarationLibPath) { if (File.Exists(declarationLibPath)) { try { Stream stream = new FileStream(declarationLibPath, FileMode.Open); BinaryFormatter deserializer = new BinaryFormatter(); PackageDeclaration res = (PackageDeclaration)deserializer.Deserialize(stream); stream.Close(); return(res); } catch (Exception ex) { return(null); } } else { return(null); } }
public CompilationUnit(PackageDeclaration packageDeclaration, List <ImportDeclaration> importDeclarations, List <TypeDeclaration> typeDeclarations) { this.packageDeclaration = packageDeclaration; this.importDeclarations = importDeclarations; this.typeDeclarations = typeDeclarations; }
public void performAction( PackageDeclaration pPackageDecl) { // Nothing to do. }
public void actionPerformed( PackageDeclaration pPackageDeclaration) { // Nothing to do. }
// * // * Visits a package declaration. // * @param packageDeclaration the pacakge declaration // protected internal virtual void visitPackageDeclaration(PackageDeclaration packageDeclaration) { }
public CompilationUnit(ClassDeclaration classDeclaration, PackageDeclaration packageDecalration, ImportDeclaration importDecalration) { this.classDeclaration = classDeclaration; this.packageDeclaration = null; this.importDeclaration = null; }
private void AnalysePackageDeclaration(PackageDeclaration decl) { //PackageBody packBody = VHDL_Library_Manager.GetPackageBody(decl); //AnalyseUnits(packBody.Scope.GetListOfObjects<FunctionBody>()); }
public void TestPackageDeclaration() { PackageDeclaration node = new PackageDeclaration(GetSymbolAtom(), GetExpressionList(), DefaultLineInfo); CheckSerializationRoundTrip(node); }
public CompilationUnit(PackageDeclaration packageDeclaration, ImportDeclaration importDeclaration, List <TypeDeclaration> typeDeclaration) { this.packageDeclaration = packageDeclaration; this.importDeclaration = importDeclaration; this.typeDeclaration = typeDeclaration; }
/// <nodoc /> public virtual void Visit(PackageDeclaration packageDeclaration) { }
/// <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); }
public CompilationUnit(PackageDeclaration packagedeclaration, List <ImportDeclaration> importdeclation, TypeDeclaration typedeclaration) { this.packageDeclaration = packagedeclaration; this.importDeclaration = importdeclation; this.typeDeclaration = typedeclaration; }
/** * Returns the qualified identifier of the namespace declaration. * * @return The qualified identifier of the namespace declaration or <code> * null</code> if there is no namespace declaration. */ //public QualifiedIdentifier getPackageDeclaration() { // if (mPackageDeclTree == null) { // return null; // There's no namespace declaration. // } // if (mPackageDecl == null) { // mPackageDecl = new AST2QualifiedIdentifier((AST2JSOMTree) // mPackageDeclTree.GetChild(0), getTokenRewriteStream()); // } // return mPackageDecl; //} public PackageDeclaration getPackageDeclaration() { if (mPackageDeclTree == null) { return null; // There's no namespace declaration. } if (mPackageDecl == null) { mPackageDecl = new AST2PackageDeclaration((AST2JSOMTree) mPackageDeclTree.GetChild(0), getTokenRewriteStream()); } return mPackageDecl; }
/// <summary> /// Компиляция файла /// </summary> /// <param name="file"></param> private void CompileFile(LibraryFileInfo file, VhdlParserSettings settings, RootDeclarativeRegion rootScope) { LibraryInfo currentLibrary = null; foreach (LibraryInfo inf in parsedLibraries) { if (inf.Name.EqualsIgnoreCase(file.LibraryName)) { currentLibrary = inf; break; } } if (currentLibrary == null) { currentLibrary = new LibraryInfo(file.LibraryName); parsedLibraries.Add(currentLibrary); rootScope.Libraries.Add(currentLibrary.LibraryScope); } try { Console.WriteLine("parsing file {0} ", file.Path); VhdlFile vhdfile = VhdlParserWrapper.parseFile(file.Path, settings, rootScope, currentLibrary.LibraryScope, libraryManager); foreach (LibraryUnit unit in vhdfile.Elements) { if (unit is PackageDeclaration) { PackageDeclaration pd = unit as PackageDeclaration; pd.Parent = null; bool foundPackage = false; foreach (PackageInfo inf in currentLibrary.Packages) { if (inf.Name.EqualsIdentifier(pd.Identifier)) { inf.DeclarationPath = file.Path; string path = FormCompilePath(file.Path, "decl"); inf.DeclarationLibPath = path; inf.Declaration = pd; foundPackage = true; break; } } if (foundPackage == false) { PackageInfo pi = new PackageInfo(pd.Identifier, currentLibrary.Name, file.Path); pi.DeclarationPath = file.Path; string path = FormCompilePath(file.Path, "decl"); pi.DeclarationLibPath = path; pi.BodyLibPath = path; pi.Declaration = pd; currentLibrary.Packages.Add(pi); } } if (unit is PackageBody) { PackageBody pb = unit as PackageBody; pb.Parent = null; bool foundPackage = false; foreach (PackageInfo inf in currentLibrary.Packages) { if (inf.Name.EqualsIdentifier(pb.Package.Identifier)) { inf.BodyPath = file.Path; string path = FormCompilePath(file.Path, "body"); inf.BodyLibPath = path; inf.Body = pb; foundPackage = true; break; } } if (foundPackage == false) { PackageInfo pi = new PackageInfo(pb.Package.Identifier, currentLibrary.Name, file.Path); pi.BodyPath = file.Path; string path = FormCompilePath(file.Path, "body"); pi.BodyLibPath = path; pi.Body = pb; currentLibrary.Packages.Add(pi); } } } } catch (Exception ex) { logger.WriteLineFormat("parsing {0} failed", file.Path); logger.WriteLine(ex.Message); logger.WriteLine(LoggerMessageVerbosity.Error, ex.Message); } }
private void resolvePackageDeclaration() { mPackageDecl = new AST2PackageDeclaration(mPackageDeclTree, getTokenRewriteStream()); }