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

            lock (_symbolTable)
            {
                _maxId = _symbolTable.MaxId;
                _localSymbolsEnumerator = _symbolTable.GetDeclaredSymbolNames().GetEnumerator();
            }

            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);
            }
        }
        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>();

            using (var iter = table.GetDeclaredSymbolNames().GetEnumerator())
            {
                for (var i = 0; i < symbols.Count; i++)
                {
                    var sid  = i + 1;
                    var text = symbols[i];

                    Assert.IsTrue(iter.MoveNext());
                    Assert.AreEqual(text, iter.Current);

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

                Assert.IsFalse(iter.MoveNext());
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        /// <summary>
        /// this computes the actual move to the next state and
        /// update the current read value accordingly
        /// </summary>
        public IonType MoveNext()
        {
            if (!HasNext())
            {
                return(IonType.None);
            }
            var newState = _currentState;

            switch (_currentState)
            {
            default:
                ThrowUnrecognizedState(_currentState);
                newState = -1;
                break;

            case S_BOF:
                newState = S_STRUCT;
                break;

            case S_STRUCT:
                //jump to the end if next() is called at S_STRUCT
                //call stepin() to get into the struct
                newState = S_EOF;
                break;

            case S_IN_STRUCT:
                newState = StateFirstInStruct();
                LoadStateData(newState);
                break;

            case S_NAME:
                Debug.Assert(HasVersion());
                newState = S_VERSION;
                LoadStateData(newState);
                break;

            case S_VERSION:
                if (HasMaxId())
                {
                    newState = S_MAX_ID;
                    LoadStateData(newState);
                    break;
                }

                newState = StateFollowingMaxId();
                break;

            case S_MAX_ID:
                newState = StateFollowingMaxId();
                break;

            case S_IMPORT_LIST:
                newState = StateFollowingImportList(Op.Next);
                break;

            case S_IN_IMPORTS:
            case S_IMPORT_STRUCT:
                // we only need to get the import list once, which we
                // do as we step into the import list, so it should
                // be waiting for us here.
                newState = NextImport();
                break;

            case S_IN_IMPORT_STRUCT:
                // shared tables have to have a name
                newState = S_IMPORT_NAME;
                LoadStateData(newState);
                break;

            case S_IMPORT_NAME:
                // shared tables have to have a version
                newState = S_IMPORT_VERSION;
                LoadStateData(newState);
                break;

            case S_IMPORT_VERSION:
                // and they also always have a max id - so we set up
                // for it
                newState = S_IMPORT_MAX_ID;
                LoadStateData(newState);
                break;

            case S_IMPORT_MAX_ID:
                newState = S_IMPORT_STRUCT_CLOSE;
                break;

            case S_IMPORT_STRUCT_CLOSE:
            case S_IMPORT_LIST_CLOSE:
                // no change here - we just bump up against this local eof
                break;

            case S_AFTER_IMPORT_LIST:
                Debug.Assert(_symbolTable.GetImportedMaxId() < _maxId);
                newState = S_SYMBOL_LIST;
                break;

            case S_SYMBOL_LIST:
                Debug.Assert(_symbolTable.GetImportedMaxId() < _maxId);
                newState = StateFollowingLocalSymbols();
                break;

            case S_IN_SYMBOLS:
            // we have some symbols - so we'll set up to read them, which we *have* to do once and *need* to do only once.
            // since we only get into the symbol list if there are some symbols - our next state
            // is at the first symbol so we just fall through to and let the S_SYMBOL
            // state do it's thing (which it will do every time we move to the next symbol)
            case S_SYMBOL:
                Debug.Assert(_localSymbolsEnumerator != null);
                if (_localSymbolsEnumerator.MoveNext())
                {
                    _stringValue = _localSymbolsEnumerator.Current;
                    // null means this symbol isn't defined
                    newState = S_SYMBOL;
                    break;
                }

                newState = S_SYMBOL_LIST_CLOSE;
                break;

            case S_SYMBOL_LIST_CLOSE:
                // no change here - we just bump up against this local eof
                newState = S_SYMBOL_LIST_CLOSE;
                break;

            case S_STRUCT_CLOSE:
            case S_EOF:
                // no change here - we just bump up against this local eof
                break;
            }

            _currentState = newState;
            return(StateType(_currentState));
        }