Example #1
0
 private static void WriteDo(LanguageWriter w, IDoStatement state)
 {
     w.WriteKeyword("do");
     w.PushScope();
     w.Write(" {");
     w.WriteLine();
     w.WriteIndent();
     if (state.Body != null)
     {
         WriteBlock(w, state.Body);
     }
     w.WriteOutdent();
     w.Write("} ");
     w.PopScope();
     w.WriteKeyword("while");
     w.Write("(");
     if (state.Condition != null)
     {
         w.SkipWriteLine = true;
         ExpressionWriter.WriteExpression(w, state.Condition, false);
         w.SkipWriteLine = false;
     }
     w.Write(");");
     w.WriteLine();
 }
        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();
        }
Example #3
0
        private static void WriteBracedStatement(LanguageWriter w, IStatement statement)
        {
            w.PushScope();

            w.Write("{");
            w.WriteLine();
            w.WriteIndent();
            WriteStatement(w, statement);
            w.WriteOutdent();
            w.Write("}");

            w.PopScope();
        }
Example #4
0
 private static void WriteFor(LanguageWriter w, IForStatement state)
 {
     w.PushScope();
     w.WriteKeyword("for");
     w.Write(" ");
     w.Write("(");
     if (state.Initializer != null)
     {
         w.SkipWriteLine = true;
         WriteStatement(w, state.Initializer);
         w.SkipWriteLine = false;
         w.Write(" ");
     }
     w.Write("; ");
     if (state.Condition != null)
     {
         w.SkipWriteLine = true;
         ExpressionWriter.WriteExpression(w, state.Condition, false);
         w.SkipWriteLine = false;
     }
     w.Write("; ");
     if (state.Increment != null)
     {
         w.SkipWriteLine = true;
         WriteStatement(w, state.Increment);
         w.SkipWriteLine = false;
     }
     w.Write(") {");
     w.WriteLine();
     w.WriteIndent();
     if (state.Body != null)
     {
         WriteStatement(w, state.Body);
     }
     w.WriteOutdent();
     w.Write("}");
     w.WriteLine();
     w.PopScope();
 }
        // 匿名メソッドは、ラムダ式文法で代替する事にする。
        // 実際には、変数のキャプチャなどを行うと C++/CLI ではコンパイル出来ない。
        private static void WriteAnonymousMethod(LanguageWriter w, IAnonymousMethodExpression exp)
        {
            w.Write("[&]");
            w.WriteMethodParameterCollection(exp.Parameters);

            // 戻り型
            TypeRef return_type = new TypeRef(exp.ReturnType.Type);

            if (!return_type.IsVoid)
            {
                w.Write(" -> ");
                return_type.WriteNameWithRef(w);
            }

            // 中身
            w.PushScope();
            w.Write(" {");
            w.WriteLine();
            w.WriteIndent();
            w.WriteStatement(exp.Body);
            w.WriteOutdent();
            w.Write("}");
            w.PopScope();
        }
Example #6
0
 private static void WriteForEach(LanguageWriter w, IForEachStatement state)
 {
     w.PushScope();
     w.WriteKeyword("for each");
     w.Write(" (");
     ExpressionWriter.WriteVariableDeclaration(w, state.Variable);
     w.Write(" ");
     w.WriteKeyword("in");
     w.Write(" ");
     w.SkipWriteLine = true;
     ExpressionWriter.WriteExpression(w, state.Expression, false);
     w.SkipWriteLine = false;
     w.Write(") {");
     w.WriteLine();
     w.WriteIndent();
     if (state.Body != null)
     {
         WriteBlock(w, state.Body);
     }
     w.WriteOutdent();
     w.Write("}");
     w.WriteLine();
     w.PopScope();
 }
Example #7
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();
            }
            //*/
        }