示例#1
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();
        }
示例#2
0
        private static void WriteArrayCreate(LanguageWriter w, IArrayCreateExpression exp)
        {
            w.WriteKeyword("gcnew");
            w.Write(" ");
            w.WriteKeyword("array");
            w.Write("<");

            new TypeRef(exp.Type).WriteNameWithRef(w);
            if (exp.Dimensions != null && exp.Dimensions.Count > 1)
            {
                w.Write(", ");
                w.WriteAsLiteral(exp.Dimensions.Count);
            }
            w.Write(">");

            // 要素数の指定
            if (exp.Dimensions != null)
            {
                w.Write("(");
                w.WriteExpressionCollection(exp.Dimensions);
                w.Write(")");
            }

            // {a, b, ... 要素の指定}
            IBlockExpression initializer = exp.Initializer;

            if (initializer != null)
            {
                WriteBlock(w, initializer);
            }
        }
示例#3
0
 private static void WriteArrayIndexerExpression(LanguageWriter w, IArrayIndexerExpression exp)
 {
     w.WriteExpression(exp.Target);
     w.Write("[");
     w.WriteExpressionCollection(exp.Indices);
     w.Write("]");
 }
示例#4
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();
 }
示例#5
0
 private static void WriteMethodInvoke(LanguageWriter w, IMethodInvokeExpression exp)
 {
     WriteExpression(w, exp.Method, PREC_MEM_ACCESS > GetExpressionPrecedence(exp.Method));
     w.Write("(");
     w.WriteExpressionCollection(exp.Arguments);
     w.Write(")");
 }
示例#6
0
 private static void WriteStatementCollection(LanguageWriter w, IStatementCollection statementCollection)
 {
     foreach (IStatement current in StatementAnalyze.ModifyStatements(statementCollection))
     {
         WriteStatement(w, current);
     }
 }
示例#7
0
 private static void WriteLabeled(LanguageWriter w, ILabeledStatement state)
 {
     w.__WriteLabel(state.Name);
     if (state.Statement != null)
     {
         WriteStatement(w, state.Statement);
     }
 }
示例#8
0
 internal static void WriteBlock(LanguageWriter w, IBlockStatement blockStatement)
 {
     if (blockStatement.Statements.Count == 0)
     {
         return;
     }
     WriteStatementCollection(w, blockStatement.Statements);
 }
示例#9
0
 private static void WriteTypeReference(LanguageWriter w, ITypeReference type)
 {
     if (type.Name == "<Module>")
     {
         return;
     }
     new TypeRef(type).WriteName(w);
 }
示例#10
0
        //===========================================================
        //		書込
        //===========================================================

        #region 型の名前の書込
        /// <summary>
        /// 型名を書き込みます。参照型の場合には ^ を後に続けます。値型の場合には何も付けません。
        /// </summary>
        /// <param name="w">書き込みに使用する LanguageWriter を指定します。</param>
        public void WriteNameWithRef(LanguageWriter w)
        {
            this.WriteName(w);
            if (IsRefType)
            {
                w.Write("^");
            }
        }
示例#11
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();
 }
示例#12
0
 private static void WriteCondition(LanguageWriter w, IConditionExpression exp)
 {
     WriteExpression(w, exp.Condition, PREC_COND > GetExpressionPrecedence(exp.Condition));
     w.Write(" ? ");
     WriteExpression(w, exp.Then, false);
     w.Write(" : ");
     WriteExpression(w, exp.Else, false);
 }
示例#13
0
 private static void WriteDefaultConstruction(LanguageWriter w, DefaultConstructionStatement state)
 {
     new TypeRef(state.var_type).WriteName(w);
     w.Write(" ");
     w.WriteDeclaration(state.var_name);
     w.Write("; ");
     w.WriteComment("// 既定のコンストラクタ");
     w.WriteLine();
 }
示例#14
0
 private static void WriteTryCast(LanguageWriter w, ITryCastExpression exp)
 {
     w.WriteKeyword("dynamic_cast");
     w.Write("<");
     new TypeRef(exp.TargetType).WriteNameWithRef(w);
     w.Write(">(");
     WriteExpression(w, exp.Expression, false);
     w.Write(")");
 }
示例#15
0
 private static void WriteTypeReference(LanguageWriter w, ITypeReferenceExpression exp)
 {
     // if(exp.Type.Name=="UnmanagedType")return; // ←何故 UnmanagedType を略すのか不明
     if (exp.Type.Name == "<Module>")
     {
         return;
     }
     new TypeRef(exp.Type).WriteName(w);
 }
示例#16
0
        private static void WriteBinary(LanguageWriter w, IBinaryExpression exp)
        {
            WriteExpression(w, exp.Left, prec_binop[exp.Operator] > GetExpressionPrecedence(exp.Left));

            w.Write(" ");
            WriteBinaryOperator(w, exp.Operator);
            w.Write(" ");

            WriteExpression(w, exp.Right, prec_binop[exp.Operator] >= GetExpressionPrecedence(exp.Right));
        }
示例#17
0
        internal static void WriteVariableDeclaration(LanguageWriter w, IVariableDeclaration var_decl)
        {
            // local 変数の登録
            w.scope.RegisterVariable(var_decl, false);

#warning pinned の情報なども入れる様にする
            new TypeRef(var_decl.VariableType).WriteNameWithRef(w);
            w.Write(" ");
            w.WriteDeclaration(w.scope[var_decl.Name].disp_name);
        }
示例#18
0
        private static void WriteBinaryNullCoalescing(LanguageWriter w, INullCoalescingExpression exp)
        {
            const int PREC_NULL_COAL = 0;

            WriteExpression(w, exp.Condition, PREC_NULL_COAL > GetExpressionPrecedence(exp.Condition));

            w.Write(" ?? ");

            WriteExpression(w, exp.Expression, PREC_NULL_COAL >= GetExpressionPrecedence(exp.Expression));
        }
示例#19
0
        private static void WriteUnary(LanguageWriter w, IUnaryExpression exp)
        {
            bool   post = false;
            string opName;

            switch (exp.Operator)
            {
            case UnaryOperator.Negate:
                opName = "-";
                break;

            case UnaryOperator.BooleanNot:
                opName = "!";
                break;

            case UnaryOperator.BitwiseNot:
                opName = "~";
                break;

            case UnaryOperator.PreIncrement:
                opName = "++";
                break;

            case UnaryOperator.PreDecrement:
                opName = "--";
                break;

            case UnaryOperator.PostIncrement:
                opName = "++";
                post   = true;
                break;

            case UnaryOperator.PostDecrement:
                opName = "--";
                post   = true;
                break;

            default:
                throw new System.NotSupportedException(
                          "指定した種類の単項演算には対応していません: " + exp.Operator.ToString()
                          );
            }

            // 書込
            if (post)
            {
                WriteExpression(w, exp.Expression, PREC_POST > GetExpressionPrecedence(exp.Expression));
                w.Write(opName);
            }
            else
            {
                w.Write(opName);
                WriteExpression(w, exp.Expression, PREC_PRE > GetExpressionPrecedence(exp.Expression));
            }
        }
示例#20
0
        private static void WriteMemberAccess(LanguageWriter w, IExpression target)
        {
            if (target == null)
            {
                return;
            }

            bool           isref = true;
            ExpressionType xtype = GetExpressionType(target);
            TypeRef        type;

            switch (xtype)
            {
            case ExpressionType.TypeReference:
                WriteTypeReference(w, (ITypeReferenceExpression)target);
                w.Write("::");
                return;

            case ExpressionType.BaseReference:
                w.baseType.WriteName(w);
                w.Write("::");
                return;

            case ExpressionType.VariableReference:
                IVariableReference var_ref = ((IVariableReferenceExpression)target).Variable;
                if (var_ref == null)
                {
                    break;
                }
                IVariableDeclaration var_decl = var_ref.Resolve();
                if (var_decl == null)
                {
                    break;
                }
                if (w.scope[var_decl.Name].local_scope)
                {
                    isref = false;
                    break;
                }
                type = new TypeRef(var_decl.VariableType);
                goto fromtype;

            default:
                type = TypeRef.GetReturnType(target);
                goto fromtype;
fromtype:
//#warning Modifier や % や & が付いている場合に関しては未だ
                isref = type.IsEmpty || !type.IsValueType && !type.IsPrimitive;
                break;
            }


            WriteExpression(w, target, PREC_MEM_ACCESS > GetExpressionPrecedence(target));
            w.Write(isref?"->":".");
        }
示例#21
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();
 }
示例#22
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();
        }
示例#23
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();
 }
示例#24
0
 private static void WriteCanCast(LanguageWriter w, ICanCastExpression exp)
 {
     w.WriteKeyword("dynamic_cast");
     w.Write("<");
     new TypeRef(exp.TargetType).WriteNameWithRef(w);
     w.Write(">");
     w.Write("(");
     WriteExpression(w, exp.Expression, false);
     w.Write(")");
     w.Write(" != ");
     w.WriteLiteral("nullptr");
 }
示例#25
0
        private static void WriteExpression(LanguageWriter w, IExpressionStatement state)
        {
            w.WriteExpression(state.Expression);

            if (w.SkipWriteLine)
            {
                return;
            }

            w.Write(";");
            w.WriteLine();
        }
示例#26
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();
 }
示例#27
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();
 }
示例#28
0
 private static void WriteDelegateCreate(LanguageWriter w, IDelegateCreateExpression exp)
 {
     w.WriteKeyword("gcnew");
     w.Write(" ");
     new TypeRef(exp.DelegateType).WriteName(w);
     w.Write("(");
     WriteExpression(w, exp.Target, false);
     w.Write(", &");
     WriteTypeReference(w, (ITypeReference)exp.Method.DeclaringType);
     w.Write("::");
     w.WriteMethodReference(exp.Method);
     w.Write(")");
 }
示例#29
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();
        }
示例#30
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(";");
        }