Пример #1
0
        /// <summary>
        /// Identifies all label reference pairs that cross the specified global label.  When
        /// a matching pair is found, the pair's destination label is marked as global and
        /// added to the global label list.
        /// </summary>
        /// <param name="glabel">Global label of interest.</param>
        private void FindIntersectingPairs(OffsetLabel glabel)
        {
            Debug.Assert(mGlobalFlags[glabel.Offset]);

            int globOffset = glabel.Offset;

            for (int i = 0; i < mOffsetPairs.Count; i++)
            {
                OffsetPair pair = mOffsetPairs[i];

                // If the destination was marked global earlier, remove and ignore this entry.
                // Note this also means that pair.DstOffset != label.Offset.
                if (mGlobalFlags[pair.DstOffset])
                {
                    mOffsetPairs.RemoveAt(i);
                    i--;
                    continue;
                }

                // Check to see if the global label falls between the source and destination
                // offsets.
                //
                // If the reference source is itself a global label, it can reference local
                // labels forward, but not backward.  We need to take that into account for
                // the case where label.Offset==pair.SrcOffset.
                bool intersect;
                if (pair.SrcOffset < pair.DstOffset)
                {
                    // Forward reference.  src==glob is ok
                    intersect = pair.SrcOffset < globOffset && pair.DstOffset >= globOffset;
                }
                else
                {
                    // Backward reference.  src==glob is bad
                    intersect = pair.SrcOffset >= globOffset && pair.DstOffset <= globOffset;
                }

                if (intersect)
                {
                    //Debug.WriteLine("Global " + glabel + " btwn " + pair + " (" +
                    //    mProject.GetAnattrib(pair.DstOffset).Symbol.Label + ")");

                    // Change the destination label to global.
                    mGlobalFlags[pair.DstOffset] = true;
                    mGlobalLabels.Add(new OffsetLabel(pair.DstOffset,
                                                      mProject.GetAnattrib(pair.DstOffset).Symbol.Label));

                    // Carefully remove it from the list we're iterating through.
                    mOffsetPairs.RemoveAt(i);
                    i--;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Pushes a new entry onto the stack at the cursor.  If there were additional
        /// entries past the cursor, they will be discarded.
        ///
        /// If the same entry is already at the top of the stack, the entry will not be added.
        /// </summary>
        /// <param name="fromOffset">File offset associated with line we are moving from.
        ///   This may be negative if we're moving from a header comment or .EQ directive.</param>
        /// <param name="toOffset">File offset associated with line we are moving to.  This
        ///   may be negative if we're moving to the header comment or a .EQ directive.</param>
        public void Push(int fromOffset, int toOffset)
        {
            if (mStack.Count > mCursor)
            {
                mStack.RemoveRange(mCursor, mStack.Count - mCursor);
            }
            OffsetPair newPair = new OffsetPair(fromOffset, toOffset);

            mStack.Add(newPair);
            mCursor++;
            //Debug.WriteLine("NavStack pushed +" + newPair + " -- " + this);
        }
        public override void OnPopulate()
        {
            VoidPtr baseAddress = WorkingUncompressed.Address + sizeof(Common2TblHeader);

            int               dataLength  = Header->_DataLength;
            VoidPtr           offsetTable = baseAddress + dataLength + Header->_OffCount * 4;
            VoidPtr           stringList  = offsetTable + Header->_DataTable * 8;
            List <OffsetPair> offsets     = new List <OffsetPair>();

            bint *ptr = (bint *)offsetTable;

            for (int i = 0; i < Header->_DataTable; i++)
            {
                OffsetPair o = new OffsetPair
                {
                    dataOffset = *ptr++,
                    nameOffset = *ptr++
                };
                offsets.Add(o);
            }

            offsets = offsets.OrderBy(o => o.dataOffset).ToList();
            for (int i = 1; i < offsets.Count; i++)
            {
                offsets[i - 1].dataEnd = offsets[i].dataOffset;
            }

            offsets[offsets.Count - 1].dataEnd = dataLength;

            foreach (OffsetPair o in offsets)
            {
                if (o.dataEnd <= o.dataOffset)
                {
                    throw new Exception("Invalid data length (less than data offset) in common2 data");
                }

                DataSource   source = new DataSource(baseAddress + o.dataOffset, o.dataEnd - o.dataOffset);
                string       name   = new string((sbyte *)stringList + o.nameOffset);
                ResourceNode node   =
                    name.StartsWith("eventStage") ? new EventMatchNode()
                    : name.StartsWith("allstar") ? new AllstarStageTblNode()
                    : name.StartsWith("simpleStage") ? new ClassicStageTblNode()
                    : name == "sndBgmTitleData" ? new SndBgmTitleDataNode()
                    : (ResourceNode) new ClassicStageTblSizeTblNode();
                node.Initialize(this, source);
                node.Name       = name;
                node.HasChanged = false;
            }
        }
Пример #4
0
        private OffsetPair[] Get4ISDSSpeech(string beginAttributeName, string endAttributeName)
        {
            var begin = _Sent.DescendantsAndSelfWithExistsAttribute(beginAttributeName).ToArray();
            var end   = _Sent.DescendantsAndSelfWithExistsAttribute(endAttributeName).ToArray();

            var list = new Lazy <List <OffsetPair> >(LazyThreadSafetyMode.None);

            for (int i = 0, count = Math.Min(begin.Length, end.Length); i < count; i++)
            {
                #region [.begin.]
                var begin_ = begin[i];

                var begin_off = getOffsetPair4Element(begin_);
                if (begin_off.IsNull())
                {
                    foreach (var a in begin_.ElementsAfterSelf())
                    {
                        begin_off = getOffsetPair4Element(a);
                        if (begin_off.IsNotNull())
                        {
                            break;
                        }
                    }

                    if (begin_off.IsNull())
                    {
                        continue;
                    }
                }
                #endregion

                #region [.end.]
                var end_ = end[i];

                var end_off = getOffsetPair4Element(end_);
                if (end_off.IsNull())
                {
                    foreach (var b in end_.ElementsBeforeSelf().Reverse())
                    {
                        end_off = getOffsetPair4Element(b);
                        if (end_off.IsNotNull())
                        {
                            break;
                        }
                    }

                    if (end_off.IsNull())
                    {
                        continue;
                    }
                }
                #endregion

                #region [.add 2 list.]
                var len = end_off.BeginIndex - begin_off.BeginIndex + end_off.Length;
                if (len <= 0)
                {
                    continue;
                }

                list.Value.Add(OffsetPair.Create(begin_off.BeginIndex, len));
                #endregion
            }
            return(list.IsValueCreated ? list.Value.ToArray() : null);
        }