コード例 #1
0
        private static void WriteAssign(LanguageWriter w, IAssignExpression exp)
        {
#if EXTRA_TEMP
            // 無駄な変数の除去
            //   之はその内に StatementAnalyze に引っ越した方が分かりやすいかも知れない
            //   但し、その場合には式内で代入を行う場合には対応出来ない (例: (i=j)==0 等)
            IVariableDeclarationExpression target  = exp.Target as IVariableDeclarationExpression;
            IVariableReferenceExpression   target2 = exp.Target as IVariableReferenceExpression;
            IVariableReferenceExpression   right   = exp.Expression as IVariableReferenceExpression;
            if (w.ExtraTemporaries != null)
            {
                // 無駄変数の宣言
                if (target != null)
                {
                    for (int i = 0; i < w.ExtraTemporaries.Length; i++)
                    {
                        if (!w.EssentialTemporaries[i] && target.Variable.Name == w.ExtraTemporaries[i])
                        {
                            return;
                        }
                    }
                }

                // 無駄変数から無駄変数への受け渡し
                if (target2 != null && right != null)
                {
                    int iTarget = -1;
                    int iRight  = -1;
                    for (int j = 0; j < w.ExtraTemporaries.Length; j++)
                    {
                        if (target2.Variable.ToString() == w.ExtraTemporaries[j])
                        {
                            iTarget = j;
                            w.VerifyCorrectBlock(j);
                        }
                        if (right.Variable.ToString() == w.ExtraTemporaries[j])
                        {
                            iRight = j;
                            w.VerifyCorrectBlock(j);
                        }
                    }
                    if (iTarget >= 0 && !w.EssentialTemporaries[iTarget])
                    {
                        string str;
                        if (iRight >= 0 && !w.EssentialTemporaries[iRight])
                        {
                            if (w.ExtraMappings[iRight] == null)
                            {
                                w.EssentialTemporaries[iRight] = true;
                                str = null;
                            }
                            else
                            {
                                str = w.ExtraMappings[iRight];
                            }
                        }
                        else
                        {
                            str = right.Variable.ToString();
                        }
                        if (str != null && target2.Variable.ToString()[0] == str[0])
                        {
                            w.ExtraMappings[iTarget] = str;
                            return;
                        }
                    }
                }
            }
#endif
            WriteExpression(w, exp.Target, false);
            w.Write(" = ");
            WriteExpression(w, exp.Expression, false);
        }