Ejemplo n.º 1
0
 private static void WriteLabeled(LanguageWriter w, ILabeledStatement state)
 {
     w.__WriteLabel(state.Name);
     if (state.Statement != null)
     {
         WriteStatement(w, state.Statement);
     }
 }
Ejemplo n.º 2
0
        public void Write(LanguageWriter w)
        {
            w.PushScope();
            //---------------------------------------------
            if (!this.noblock)
            {
                w.Write("{");
                w.WriteLine();
                w.WriteIndent();
            }
            if (!w.SuppressOutput)
            {
                //*
#warning local-ref: 上層で無駄な宣言を取り除くべき
                if (w.scope.ContainsVariable(this.var_name))
                {
                    w.scope[this.var_name].local_scope = true;
                }
                else
                {
                    w.scope.RegisterVariable(this.var_name, true);
                }
                //*/
            }

            bool nohandle = this.exp is IObjectCreateExpression;           // ハンドル表記でなくても良いかどうか

            this.WriteVariableDecl(w, nohandle);

            // 後に続く内容
            w.WriteLine();
            StatementWriter.WriteBlock(w, this.block);

            // ハンドル表記で宣言した場合はちゃんと delete
            if (!nohandle)
            {
                StatementWriter.WriteStatement(w, new DeleteStatement(new VariableReferenceExpression(this.decl)));
            }

            if (!this.noblock)
            {
                w.WriteOutdent();
                w.Write("}");
                w.WriteLine();
            }
            if (this.labelname != null)
            {
                w.__WriteLabel(this.labelname);
                w.Write(";");
                w.WriteLine();
            }
            //---------------------------------------------
            w.PopScope();
        }
Ejemplo n.º 3
0
        private static void WriteLocalRefVariable(LanguageWriter w, LocalRefVariableStatement state)
        {
            state.Write(w);
            return;

            if (!state.noblock)
            {
                w.PushScope();
                //---------------------------------------------
                w.Write("{");
                w.WriteLine();
                w.WriteIndent();
            }
            if (!w.SuppressOutput)
            {
                //*
#warning local-ref: 上層で無駄な宣言を取り除くべき
                if (w.scope.ContainsVariable(state.var_name))
                {
                    w.scope[state.var_name].local_scope = true;
                }
                else
                {
                    w.scope.RegisterVariable(state.var_name, true);
                }
                //*/
            }

            IObjectCreateExpression exp_create = state.exp as IObjectCreateExpression;
            bool nohandle = exp_create != null;         // ハンドル表記でなくても良いかどうか
            if (nohandle)
            {
                // 変数型
                IOptionalModifier modopt = state.var_type as IOptionalModifier;
                if (modopt != null && modopt.Modifier.Namespace == "System.Runtime.CompilerServices" && modopt.Modifier.Name == "IsConst")
                {
                    state.var_type = modopt.ElementType;
                }
                new TypeRef(state.var_type).WriteName(w);

                // 変数名
                w.Write(" ");
                w.WriteDeclaration(state.var_name);

                // 初期化子
                if (exp_create.Arguments.Count == 0)
                {
                    w.WriteComment(" /* 既定のコンストラクタ */");
                }
                else
                {
                    w.Write("(");
                    w.WriteExpressionCollection(exp_create.Arguments);
                    w.Write(")");
                }
            }
            else
            {
                // = で代入の場合: ハンドル表記でないと、コンストラクタ呼び出しになってしまう

                // 変数型
                new TypeRef(state.var_type).WriteNameWithRef(w);

                // 変数名
                w.Write(" ");
                w.WriteDeclaration(state.var_name);

                // 代入する値
                w.Write("=");
                ExpressionWriter.WriteExpression(w, state.exp, false);
            }

            w.Write(";");

            // 後に続く内容
            w.WriteLine();
            WriteBlock(w, state.block);

            // ハンドル表記で宣言した場合はちゃんと delete
            if (!nohandle)
            {
                WriteStatement(w, new DeleteStatement(new VariableReferenceExpression(state.decl)));
            }

            w.WriteOutdent();
            w.Write("}");
            w.WriteLine();
            if (state.labelname != null)
            {
                w.__WriteLabel(state.labelname);
                w.Write(";");
                w.WriteLine();
            }
            if (!state.noblock)
            {
                //---------------------------------------------
                w.PopScope();
            }
            //*/
        }
Ejemplo n.º 4
0
        public static void WriteStatement(LanguageWriter w, IStatement state)
        {
            switch (GetExpressionType(state))
            {
            case StatementType.AttachEvent:
                WriteAttachEvent(w, (IAttachEventStatement)state);
                break;

            case StatementType.Block:
                WriteBlock(w, (IBlockStatement)state);
                break;

            case StatementType.Break:
                w.WriteKeyword("break");
                w.Write(";");
                w.WriteLine();
                break;

            case StatementType.Condition:
                WriteCondition(w, (IConditionStatement)state);
                break;

            case StatementType.Continue:
                w.WriteKeyword("continue");
                w.Write(";");
                w.WriteLine();
                break;

            case StatementType.DefaultConstruction:
                WriteDefaultConstruction(w, (DefaultConstructionStatement)state);
                break;

            case StatementType.Delete:
                w.WriteKeyword("delete");
                w.Write(" ");
                ExpressionWriter.WriteExpression(w, ((DeleteStatement)state).deleteTarget, false);
                w.Write(";");
                w.WriteLine();
                break;

            case StatementType.Do:
                WriteDo(w, (IDoStatement)state);
                break;

            case StatementType.Expression:
                WriteExpression(w, (IExpressionStatement)state);
                break;

            case StatementType.Fixed:
                WriteFixed(w, (IFixedStatement)state);
                break;

            case StatementType.For:
                WriteFor(w, (IForStatement)state);
                break;

            case StatementType.ForEach:
                WriteForEach(w, (IForEachStatement)state);
                break;

            case StatementType.Goto:
                w.WriteKeyword("goto");
                w.Write(" ");
                w.Write(((IGotoStatement)state).Name);
                w.Write(";");
                w.WriteLine();
                break;

            case StatementType.Label:
                w.__WriteLabel(((LabelStatement)state).label_name);
                break;

            case StatementType.Labeled:
                WriteLabeled(w, (ILabeledStatement)state);
                break;

            case StatementType.LocalRefVariable:
                WriteLocalRefVariable(w, (LocalRefVariableStatement)state);
                break;

            case StatementType.Lock:
                WriteLock(w, (ILockStatement)state);
                break;

            case StatementType.MemoryCopy:
                WriteMemoryCopy(w, (IMemoryCopyStatement)state);
                break;

            case StatementType.MemoryInitialize:
                WriteMemoryInitialize(w, (IMemoryInitializeStatement)state);
                break;

            case StatementType.MethodReturn:
                WriteMethodReturn(w, (IMethodReturnStatement)state);
                break;

            case StatementType.RemoveEvent:
                WriteRemoveEvent(w, (IRemoveEventStatement)state);
                break;

            case StatementType.Switch:
                WriteSwitch(w, (ISwitchStatement)state);
                break;

            case StatementType.ThrowException:
                WriteThrowException(w, (IThrowExceptionStatement)state);
                break;

            case StatementType.TryCatch:
                WriteTryCatchFinally(w, (ITryCatchFinallyStatement)state);
                break;

            //	case StatementType.Using:
            //		WriteUsing(w,(IUsingStatement)state);
            //		break;
            case StatementType.While:
                WriteWhile(w, (IWhileStatement)state);
                break;

            case StatementType.Comment:
            case StatementType.DebugBreak:
            case StatementType.Unknown:
            default:
                ThrowUnknownStatement(state);
                break;
            }
            w.SkipWriteLine = false;
        }