Ejemplo n.º 1
0
        public SymbolTableReader(ISymbolTable symbolTable)
        {
            _symbolTable = symbolTable ?? throw new ArgumentNullException(nameof(symbolTable));

            lock (_symbolTable)
            {
                _maxId = _symbolTable.MaxId;
                _localSymbolsIterator = _symbolTable.IterateDeclaredSymbolNames();
            }

            if (!_symbolTable.IsLocal)
            {
                SetFlag(HAS_NAME, true);
                SetFlag(HAS_VERSION, true);
            }

            //what is this???
            if (_maxId > 0)
            {
                // FIXME: is this ever true?
                SetFlag(HAS_MAX_ID, true);
            }

            _importedTables = _symbolTable.GetImportedTables().ToArray();
            if (_importedTables != null && _importedTables.Length > 0)
            {
                SetFlag(HAS_IMPORT_LIST, true);
            }

            if (_symbolTable.GetImportedMaxId() < _maxId)
            {
                SetFlag(HAS_SYMBOL_LIST, true);
            }
        }
Ejemplo n.º 2
0
        private static void AssertTable(ISymbolTable table, string name, int version, IReadOnlyList <string> symbols)
        {
            Assert.IsTrue(table.IsShared);
            Assert.IsFalse(table.IsSystem);
            Assert.IsNull(table.GetSystemTable());
            Assert.IsTrue(table.IsReadOnly);
            Assert.AreEqual(name, table.Name);
            Assert.AreEqual(version, table.Version);
            Assert.AreEqual(0, table.GetImportedMaxId());
            Assert.AreEqual(symbols.Count, table.MaxId);

            var foundSymbols = new HashSet <string>();
            var iter         = table.IterateDeclaredSymbolNames();

            for (var i = 0; i < symbols.Count; i++)
            {
                var sid  = i + 1;
                var text = symbols[i];

                Assert.IsTrue(iter.HasNext());
                Assert.AreEqual(text, iter.Next());

                var duplicate = text != null && !foundSymbols.Add(text);
                SymTabUtils.AssertSymbolInTable(text, sid, duplicate, table);
            }

            Assert.IsFalse(iter.HasNext());
        }
Ejemplo n.º 3
0
        private static (List <string> symbolList, Dictionary <string, int> symbolMap) PrepSymbolListAndMap(
            ISymbolTable priorSymtab, IEnumerable <string> symbols)
        {
            var sid        = 1;
            var symbolList = new List <string>();
            var symbolMap  = new Dictionary <string, int>();

            if (priorSymtab != null)
            {
                var priorSymbols = priorSymtab.IterateDeclaredSymbolNames();
                while (priorSymbols.HasNext())
                {
                    var text = priorSymbols.Next();
                    if (text != null && !symbolMap.ContainsKey(text))
                    {
                        symbolMap[text] = sid;
                    }

                    symbolList.Add(text);
                    sid++;
                }
            }

            foreach (var symbol in symbols)
            {
                // TODO What about empty symbols?
                if (symbolMap.ContainsKey(symbol))
                {
                    continue;
                }
                symbolMap[symbol] = sid;
                symbolList.Add(symbol);
                sid++;
            }

            return(symbolList, symbolMap);
        }