コード例 #1
0
        private IEnumerable <string> GetSymbolsAsList(string f)
        {
            var physFile = new PhysicalFile
            {
                Filepath   = f,
                Sourcecode = File.ReadAllText(f)
            };

            var dtu                    = new DafnyTranslationUnit(physFile);
            var dafnyProg              = dtu.Verify().DafnyProgram;
            ISymbolTableGenerator st   = new SymbolTableGenerator(dafnyProg);
            ISymbolInformation    root = st.GenerateSymbolTable();
            ISymbolTableManager   sm   = new SymbolTableManager(root);

            ISymbolNavigator          navigator = new SymbolNavigator();
            List <ISymbolInformation> symbols   = new List <ISymbolInformation>();

            foreach (var modul in root.Children)
            {
                symbols.AddRange(navigator.TopDownAll(modul));
            }

            var actual = symbols.Select(x => x.ToDebugString()).ToList();

            Console.WriteLine("SymboleTable for " + f);
            Console.Write(((SymbolTableManager)sm).CreateDebugReadOut());

            return(actual);
        }
コード例 #2
0
        /// <summary>
        /// Builds a short fake symbol table which can be used for testing.
        /// </summary>
        /// <returns>root symbol of the fake table</returns>
        /// <remarks>
        ///                     root
        ///           another          decl
        ///                         use1   use2
        /// </remarks>
        public ISymbolInformation GenerateSymbolTable()
        {
            ISymbolInformation root = SymbolTableGenerator.GetEmptySymbolTable();
            SymbolInformation  decl = new SymbolInformation
            {
                Position = new TokenPosition()
                {
                    Token = new Token(1, 11)
                },
                Name   = "barapapa",
                Parent = root
            };

            decl.DeclarationOrigin = decl;

            SymbolInformation use1 = new SymbolInformation
            {
                Position = new TokenPosition()
                {
                    Token = new Token(2, 22)
                },
                Name              = "barapapa",
                Parent            = root,
                DeclarationOrigin = decl
            };

            SymbolInformation use2 = new SymbolInformation
            {
                Position = new TokenPosition()
                {
                    Token = new Token(3, 33)
                },
                Name              = "barapapa",
                Parent            = root,
                DeclarationOrigin = decl
            };

            SymbolInformation anotherSymbol = new SymbolInformation
            {
                Position = new TokenPosition()
                {
                    Token = new Token(4, 443)
                },
                Name   = "bubu",
                Parent = root,
            };

            anotherSymbol.DeclarationOrigin = anotherSymbol;

            root.ChildrenHash = new Dictionary <string, ISymbolInformation>();
            root.ChildrenHash.Add("barapapa", decl);
            root.ChildrenHash.Add("bubu", anotherSymbol);
            decl.Usages = new List <ISymbolInformation> {
                use1, use2
            };

            return(root);
        }
コード例 #3
0
 /// <summary>
 /// Sets the SymbolTableManager Property.
 /// Makes use of the dafnyProgram inside the Result property.
 /// </summary>
 private void AddSymbolTable()
 {
     if (Result.TranslationStatus >= TranslationStatus.Resolved && Result.DafnyProgram != null)
     {
         SymbolTableGenerator s        = new SymbolTableGenerator(Result.DafnyProgram);
         ISymbolInformation   rootnode = s.GenerateSymbolTable();
         SymbolTableManager = new SymbolTableManager(rootnode);
     }
 }