示例#1
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();
 }
示例#2
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(";");
        }
示例#3
0
        private static void WriteObjectCreate(LanguageWriter w, IObjectCreateExpression exp)
        {
            if (exp.Constructor == null)
            {
                // 構造体のデフォルトコンストラクタ (StatementAnalyze でフィルタリングされている筈だけれども)
                new TypeRef(exp.Type).WriteName(w);
#if FALSE
                w.Write("(");
#warning 構造体デフォルトコンストラクタ 対応漏れがあるかもしれないので保留
                w.WriteComment("/* C++/CLI では本来は T value; 等と書く筈です。*/");
                w.Write(") ");
#else
                w.Write("()");
#endif
            }
            else
            {
                ITypeReference declaringType = exp.Constructor.DeclaringType as ITypeReference;
                TypeRef        decl_type     = new TypeRef(exp.Constructor.DeclaringType);
                if (decl_type.IsRefType)
                {
                    w.WriteKeyword("gcnew");
                    w.Write(" ");
                }
                decl_type.WriteName(w);

                w.Write("(");
                w.WriteExpressionCollection(exp.Arguments);
                w.Write(")");
            }

            if (exp.Initializer != null)
            {
                WriteBlock(w, exp.Initializer);
            }
        }
示例#4
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();
            }
            //*/
        }