public void ObjectToIntegerAddresses()
        {
            IDictionary <MiddleCode, int> addressMap =
                new Dictionary <MiddleCode, int>();

            for (int index = 0; index < m_middleCodeList.Count; ++index)
            {
                MiddleCode middleCode = m_middleCodeList[index];
                addressMap.Add(middleCode, index);
            }

            for (int index = 0; index < m_middleCodeList.Count; ++index)
            {
                MiddleCode sourceCode = m_middleCodeList[index];

                if (sourceCode.IsGoto() || sourceCode.IsCarry() ||
                    sourceCode.IsRelation())
                {
                    Debug.Assert(sourceCode[0] is MiddleCode);
                    MiddleCode targetCode = (MiddleCode)sourceCode[0];
                    Debug.Assert(addressMap.ContainsKey(targetCode));
                    sourceCode[0] = addressMap[targetCode];
                }
            }
        }
        private int TraceGoto(int target, ISet <int> sourceSet)
        {
            MiddleCode objectCode = m_middleCodeList[target];

            if (!sourceSet.Contains(target) && objectCode.IsGoto())
            {
                sourceSet.Add(target);
                int nextTarget = (int)objectCode[0];
                return(TraceGoto(nextTarget, sourceSet));
            }
            else
            {
                return(target);
            }
        }
        private void SearchReachableCode(int index, ISet <MiddleCode> visitedSet)
        {
            for (; index < m_middleCodeList.Count; ++index)
            {
                MiddleCode middleCode = m_middleCodeList[index];

                if (visitedSet.Contains(middleCode))
                {
                    return;
                }

                visitedSet.Add(middleCode);

                if (middleCode.IsRelation() || middleCode.IsCarry())
                {
                    int target = (int)middleCode[0];
                    SearchReachableCode(target, visitedSet);
                }
                else if (middleCode.IsGoto())
                {
                    int target = (int)middleCode[0];
                    SearchReachableCode(target, visitedSet);
                    return;
                }
                else if (middleCode.Operator == MiddleOperator.Return)
                {
                    if (m_middleCodeList[index + 1].Operator == MiddleOperator.Exit)
                    {
                        visitedSet.Add(m_middleCodeList[index + 1]);
                    }

                    return;
                }
                else if (middleCode.Operator == MiddleOperator.FunctionEnd)
                {
                    Symbol funcSymbol = (Symbol)middleCode[0];
                    Error.Check(funcSymbol.Type.ReturnType.IsVoid(),
                                funcSymbol.Name,
                                Message.Reached_the_end_of_a_non__void_function);
                    return;
                }
            }
        }
        private void ClearDoubleRelationStatements()
        {
            for (int index = 0; index < (m_middleCodeList.Count - 1); ++index)
            {
                MiddleCode thisCode = m_middleCodeList[index],
                           nextCode = m_middleCodeList[index + 1];

                if ((thisCode.IsRelation() || thisCode.IsCarry()) &&
                    nextCode.IsGoto())
                {
                    int target1 = (int)thisCode[0],
                        target2 = (int)nextCode[0];

                    if (target1 == (index + 2))
                    {
                        MiddleOperator operator1 = thisCode.Operator;
                        thisCode.Operator = m_inverseMap[operator1];
                        thisCode[0]       = target2;
                        nextCode.Clear();
                        m_update = true;
                    }
                }
            }
        }