Пример #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();
 }
Пример #2
0
        private static void WriteLock(LanguageWriter w, ILockStatement statement)
        {
            w.Write("{");
            w.WriteIndent();
            w.WriteLine();

            Scope.VariableData data = new Scope.VariableData("<lock_statement>" + WriteLock_counter++.ToString(), true);
            data.disp_name     = "lock";
            w.scope[data.name] = data;

            // msclr::lock を初期化
            w.WriteReference("msclr", "", null);
            w.Write("::");
            w.WriteReference("lock", "#include <msclr/lock.h> で使用して下さい", null);
            w.Write(" ");
            w.WriteDeclaration(data.disp_name);
            w.Write("(");
            ExpressionWriter.WriteExpression(w, statement.Expression, false);
            w.Write(");");
            w.WriteLine();

            // 中身を書込
            if (statement.Body != null)
            {
                WriteBlock(w, statement.Body);
            }

            w.WriteOutdent();
            w.Write("}");
            w.WriteLine();
        }
Пример #3
0
 private static void WriteRemoveEvent(LanguageWriter w, IRemoveEventStatement state)
 {
     ExpressionWriter.WriteEventReference(w, state.Event);
     w.Write(" -= ");
     ExpressionWriter.WriteExpression(w, state.Listener, false);
     w.Write(";");
     w.WriteLine();
 }
Пример #4
0
 private static void WriteMethodReturn(LanguageWriter w, IMethodReturnStatement state)
 {
     w.WriteKeyword("return");
     if (state.Expression != null)
     {
         w.Write(" ");
         ExpressionWriter.WriteExpression(w, state.Expression, false);
     }
     w.Write(";");
     w.WriteLine();
 }
Пример #5
0
 private static void WriteThrowException(LanguageWriter w, IThrowExceptionStatement state)
 {
     w.WriteKeyword("throw");
     if (state.Expression != null)
     {
         w.Write(" ");
         ExpressionWriter.WriteExpression(w, state.Expression, false);
     }
     w.Write(";");
     w.WriteLine();
 }
Пример #6
0
 private static void WriteMemoryInitialize(LanguageWriter w, IMemoryInitializeStatement state)
 {
     w.Write("::");
     w.WriteReference("memset", "Crt 関数 #include <memory.h>", null);
     w.Write("(");
     ExpressionWriter.WriteExpression(w, state.Offset, false);
     w.Write(", ");
     ExpressionWriter.WriteExpression(w, state.Value, false);
     w.Write(", ");
     ExpressionWriter.WriteExpression(w, state.Length, false);
     w.Write(");");
     w.WriteLine();
 }
Пример #7
0
 private static void WriteMemoryCopy(LanguageWriter w, IMemoryCopyStatement state)
 {
     w.Write("::");
     w.WriteReference("memcpy", "Crt 関数 #include <memory.h>", null);
     w.Write("(");
     ExpressionWriter.WriteExpression(w, state.Destination, false);
     w.Write(", ");
     ExpressionWriter.WriteExpression(w, state.Source, false);
     w.Write(", ");
     ExpressionWriter.WriteExpression(w, state.Length, false);
     w.Write(");");
     w.WriteLine();
 }
Пример #8
0
        private void WriteVariableDecl(LanguageWriter w, bool nohandle)
        {
            if (nohandle)
            {
                IObjectCreateExpression exp_create = (IObjectCreateExpression)this.exp;

                // 変数型
                IOptionalModifier modopt = this.var_type as IOptionalModifier;
                if (modopt != null && modopt.Modifier.Namespace == "System.Runtime.CompilerServices" && modopt.Modifier.Name == "IsConst")
                {
                    this.var_type = modopt.ElementType;
                }
                new TypeRef(this.var_type).WriteName(w);

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

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

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

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

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

            w.Write(";");
        }
Пример #9
0
        private static void WriteFixed(LanguageWriter w, IFixedStatement state)
        {
            w.Write("{");
            w.WriteIndent();
            w.WriteLine();

            w.scope.RegisterVariable(state.Variable, false);
            w.WriteKeyword("pin_ptr");
            w.Write("<");
            new TypeRef(((IPointerType)state.Variable.VariableType).ElementType).WriteNameWithRef(w);
            w.Write("> ");
            w.WriteDeclaration(state.Variable.Name);
            w.Write(" = ");
            ExpressionWriter.WriteExpression(w, state.Expression, false);

            WriteBlock(w, state.Body);
            w.WriteOutdent();
            w.Write("}");
        }
Пример #10
0
        private static void WriteCondition(LanguageWriter w, IConditionStatement state)
        {
#if EXTRA_TEMP
            using (NewBlock block3 = new NewBlock(w)) {
                w.WriteKeyword("if");
                w.Write(" ");
                w.Write("(");
                ExpressionWriter.WriteExpression(w, state.Condition, false);
                w.Write(") ");

                using (NewBlock block2 = new NewBlock(w)) {
                    WriteBracedStatement(w, state.Then);
                    if (!IsBlank(state.Else))
                    {
                        using (NewBlock block = new NewBlock(w)) {
                            w.Write(" ");
                            w.WriteKeyword("else");
                            w.Write(" ");
                            WriteBracedStatement(w, state.Else);
                        }
                    }
                    w.WriteLine();
                }
            }
#else
            w.WriteKeyword("if");
            w.Write(" ");
            w.Write("(");
            ExpressionWriter.WriteExpression(w, state.Condition, false);
            w.Write(") ");

            WriteBracedStatement(w, state.Then);
            if (!IsBlank(state.Else))
            {
                w.Write(" ");
                w.WriteKeyword("else");
                w.Write(" ");
                WriteBracedStatement(w, state.Else);
            }
            w.WriteLine();
#endif
        }
Пример #11
0
        private static void WriteSwitch_case(LanguageWriter w, IExpression con_case)
        {
            IBinaryExpression exp_bi = con_case as IBinaryExpression;

            if (exp_bi != null)
            {
                if (exp_bi.Operator == BinaryOperator.BooleanOr)
                {
                    WriteSwitch_case(w, exp_bi.Left);
                    WriteSwitch_case(w, exp_bi.Right);
                    return;
                }
            }

            w.WriteKeyword("case");
            w.Write(" ");
            ExpressionWriter.WriteExpression(w, con_case, false);
            w.Write(":");
            w.WriteLine();
        }
Пример #12
0
 private static void WriteSwitch(LanguageWriter w, ISwitchStatement state)
 {
     w.WriteKeyword("switch");
     w.Write(" (");
     ExpressionWriter.WriteExpression(w, state.Expression, false);
     w.Write(") {");
     w.WriteLine();
     w.WriteIndent();
     foreach (ISwitchCase _case in state.Cases)
     {
         IConditionCase case1 = _case as IConditionCase;
         if (case1 != null)
         {
             WriteSwitch_case(w, case1.Condition);
             w.WriteIndent();
             if (case1.Body != null)
             {
                 WriteStatement(w, case1.Body);
             }
             w.WriteOutdent();
         }
         IDefaultCase case2 = _case as IDefaultCase;
         if (case2 != null)
         {
             w.WriteKeyword("default");
             w.Write(":");
             w.WriteLine();
             w.WriteIndent();
             if (case2.Body != null)
             {
                 WriteStatement(w, case2.Body);
             }
             w.WriteOutdent();
             //this.Write("}");
             //this.WriteLine();
         }
     }
     w.WriteOutdent();
     w.Write("}");
     w.WriteLine();
 }
Пример #13
0
 private static void WriteWhile(LanguageWriter w, IWhileStatement state)
 {
     w.WriteKeyword("while");
     w.Write(" ");
     w.Write("(");
     if (state.Condition != null)
     {
         w.SkipWriteLine = true;
         ExpressionWriter.WriteExpression(w, state.Condition, false);
         w.SkipWriteLine = false;
     }
     w.Write(") {");
     w.WriteLine();
     w.WriteIndent();
     if (state.Body != null)
     {
         WriteStatement(w, state.Body);
     }
     w.WriteOutdent();
     w.Write("}");
     w.WriteLine();
 }
Пример #14
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();
 }
Пример #15
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();
 }
Пример #16
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;
        }
Пример #17
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();
            }
            //*/
        }