示例#1
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(";");
        }
示例#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 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();
 }
示例#4
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);
        }
示例#5
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("}");
        }
示例#6
0
        private static void WriteTryCatchFinally_catch(LanguageWriter w, ICatchClause clause)
        {
            w.Write(" ");
            w.WriteKeyword("catch");

            // 特別な場合 catch(...) を検出
            // → clauseBody を改変
            //    clauseBody は StatementAnalyze の時点で改変する様にした
            bool catchAll = clause.Condition is StatementAnalyze.IsCatchAll;
            IStatementCollection clause_body = clause.Body == null?null:clause.Body.Statements;

            TypeRef var_type = new TypeRef(clause.Variable.VariableType);

            /*
             * if(var_type.IsObject&&clause.Condition!=null) {
             *      ISnippetExpression iSnippent=clause.Condition as ISnippetExpression;
             *      if(iSnippent!=null&&iSnippent.Value=="?"&&StatementAnalyze.IsCatchAllClause(ref clause_body)){
             *              catchAll=true;
             *      }
             * }
             * //*/

            if (catchAll)
            {
                w.Write(" (...)");
            }
            else
            {
                if (clause.Variable.Name.Length != 0 || !var_type.IsObject)
                {
                    w.scope.RegisterVariable(clause.Variable, false);
                    w.Write(" (");
                    var_type.WriteNameWithRef(w);
                    w.Write(" ");
                    w.WriteDeclaration(clause.Variable.Name);
                    w.Write(")");
                }

                if (clause.Condition != null)
                {
                    w.Write(" ");
                    w.WriteKeyword("when");
                    w.Write(" ");
                    w.Write("(");
                    w.WriteExpression(clause.Condition);
                    w.Write(")");
                }
            }

            w.Write(" {");
            w.WriteLine();
            w.WriteIndent();

            if (clause_body != null)
            {
                for (int num = 0; num < clause_body.Count; num++)
                {
                    IStatement statement3 = clause_body[num];

#if EXTRA_TEMP
#warning catch: "コンストラクタの中で、最後の一行で、throw" の場合は書き込まない?
                    // →之は、恐らく、 constructor に function-try-statement を適用した時の話である
                    // よって無視する
                    if (w.SomeConstructor && num + 1 >= clause_body.Count && statement3 is IThrowExceptionStatement)
                    {
                        break;
                    }
#endif

                    WriteStatement(w, statement3);
                }
            }

            w.WriteOutdent();
            w.Write("}");
        }
示例#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();
            }
            //*/
        }