示例#1
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);
            }
        }
示例#2
0
        public static void WriteExpression(LanguageWriter w, IExpression exp, bool paren)
        {
            if (paren)
            {
                w.Write("(");
            }
            switch (GetExpressionType(exp))
            {
            case ExpressionType.AddressDereference:
                WriteAddressDereference(w, (IAddressDereferenceExpression)exp);
                break;

            case ExpressionType.AddressOf:
                w.Write("&");
                WriteExpression(w, ((IAddressOfExpression)exp).Expression, false);
                break;

            case ExpressionType.AddressOut:                                     // 引数 out 渡し
                WriteExpression(w, ((IAddressOutExpression)exp).Expression, false);
                break;

            case ExpressionType.AddressReference:                       // 引数 ref 渡し
                WriteExpression(w, ((IAddressReferenceExpression)exp).Expression, false);
                break;

            case ExpressionType.ArgumentList:
                w.WriteKeyword("__arglist");
                break;

            case ExpressionType.ArgumentReference:
                w.WriteParameterReference(((IArgumentReferenceExpression)exp).Parameter);
                break;

            case ExpressionType.ArrayCreate:
                WriteArrayCreate(w, (IArrayCreateExpression)exp);
                break;

            case ExpressionType.ArrayIndexer:
                WriteArrayIndexerExpression(w, (IArrayIndexerExpression)exp);
                break;

            case ExpressionType.Assign:
                WriteAssign(w, (IAssignExpression)exp);
                break;

            case ExpressionType.BaseReference:
                w.baseType.WriteName(w);
                break;

            case ExpressionType.Binary:
                WriteBinary(w, (IBinaryExpression)exp);
                break;

            case ExpressionType.Block:
                WriteBlock(w, (IBlockExpression)exp);
                break;

            case ExpressionType.CanCast:
                WriteCanCast(w, (ICanCastExpression)exp);
                break;

            case ExpressionType.Cast:
                WriteCast(w, (ICastExpression)exp);
                break;

            case ExpressionType.Condition:
                WriteCondition(w, (IConditionExpression)exp);
                break;

            case ExpressionType.DelegateCreate:
                WriteDelegateCreate(w, (IDelegateCreateExpression)exp);
                break;

            case ExpressionType.Literal:
                w.WriteAsLiteral(((ILiteralExpression)exp).Value);
                break;

            case ExpressionType.MethodInvoke:
                WriteMethodInvoke(w, (IMethodInvokeExpression)exp);
                break;

            case ExpressionType.ObjectCreate:
                WriteObjectCreate(w, (IObjectCreateExpression)exp);
                break;

            case ExpressionType.SizeOf:
                w.WriteKeyword("sizeof");
                w.Write("(");
                new TypeRef(((ISizeOfExpression)exp).Type).WriteName(w);
                w.Write(")");
                break;

            case ExpressionType.Snippet:
                w.WriteAsLiteral(((ISnippetExpression)exp).Value);
                break;

            case ExpressionType.ThisReference:
                w.WriteKeyword("this");
                break;

            case ExpressionType.TryCast:
                WriteTryCast(w, (ITryCastExpression)exp);
                break;

            case ExpressionType.TypeOf:
                new TypeRef(((ITypeOfExpression)exp).Type).WriteName(w);
                w.Write("::");
                w.WriteKeyword("typeid");
                break;

            case ExpressionType.TypeReference:
                WriteTypeReference(w, (ITypeReferenceExpression)exp);
                break;

            case ExpressionType.Unary:
                WriteUnary(w, (IUnaryExpression)exp);
                break;

            case ExpressionType.VariableDeclaration:
                WriteVariableDeclaration(w, ((IVariableDeclarationExpression)exp).Variable);
                break;

            case ExpressionType.VariableReference:
                w.WriteVariableReference(((IVariableReferenceExpression)exp).Variable);
                break;

            case ExpressionType.MemberInitializer:                     // 属性の初期化の際のメンバ指定
                WriteMemberInitializer(w, (IMemberInitializerExpression)exp);
                break;

            //---------------------------------------------------
            // メンバアクセス
            //---------------------------------------------------
            case ExpressionType.EventReference:
                WriteEventReference(w, (IEventReferenceExpression)exp);
                break;

            case ExpressionType.FieldReference:
                IFieldReferenceExpression exp_fld = (IFieldReferenceExpression)exp;
                WriteMemberAccess(w, exp_fld.Target);
                w.WriteFieldReference(exp_fld.Field);
                break;

            case ExpressionType.PropertyReference:
                WritePropertyReference(w, (IPropertyReferenceExpression)exp);
                break;

            case ExpressionType.PropertyIndexer:
                IPropertyIndexerExpression exp_pind = (IPropertyIndexerExpression)exp;
                WritePropertyReference(w, exp_pind.Target);
                w.Write("[");
                w.WriteExpressionCollection(exp_pind.Indices);
                w.Write("]");
                break;

            case ExpressionType.MethodReference:
                IMethodReferenceExpression exp_meth = (IMethodReferenceExpression)exp;
                WriteMemberAccess(w, exp_meth.Target);
                w.WriteMethodReference(exp_meth.Method);
                break;

            //---------------------------------------------------
            //	代替
            //---------------------------------------------------
            case ExpressionType.StackAlloc:
                WriteStackAllocate(w, (IStackAllocateExpression)exp);
                break;

            case ExpressionType.AnonymousMethod:
                WriteAnonymousMethod(w, (IAnonymousMethodExpression)exp);
                break;

            //---------------------------------------------------
            //	以下未対応
            //---------------------------------------------------
            case ExpressionType.NullCoalescing:
                WriteBinaryNullCoalescing(w, (INullCoalescingExpression)exp);
                break;

            case ExpressionType.DelegateInvoke:
            case ExpressionType.FieldOf:
            case ExpressionType.GenericDefault:
            case ExpressionType.Lambda:
            case ExpressionType.MethodOf:
            case ExpressionType.Query:
                goto default;

            case ExpressionType.TypedReferenceCreate:
            case ExpressionType.TypeOfTypedReference:
            case ExpressionType.ValueOfTypedReference:
                //throw new System.NotImplementedException("未だ実装していません\r\n");
                goto default;

            case ExpressionType.Unknown:
            default:
                ThrowUnknownExpression(exp);
                break;
            }
            if (paren)
            {
                w.Write(")");
            }
        }
示例#3
0
        public string WriteName(LanguageWriter w)
        {
            if (tref != null)
            {
                string name = tref.Name.Replace(".", "::").Replace("+", "::");

                string special;
                if (tref.Namespace == "System" && specialTypeNames.TryGetValue(name, out special))
                {
                    name = special;
                }

                name = NameMangling.UnDecorateName(name);

                w.WriteReference(name, this.FullName, tref);

                ITypeCollection genericArguments = tref.GenericArguments;
                if (genericArguments.Count > 0)
                {
                    w.Write("<");
                    bool first = true;
                    foreach (IType type1 in genericArguments)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            w.Write(", ");
                        }
                        new TypeRef(type1).WriteNameWithRef(w);
                    }
                    w.Write(">");
                }

                return(name);
            }

            IArrayType type2 = type as IArrayType;

            if (type2 != null)
            {
                w.WriteKeyword("array");
                w.Write("<");
                new TypeRef(type2.ElementType).WriteNameWithRef(w);

                if (type2.Dimensions.Count > 1)
                {
                    w.Write(", ");
                    w.WriteAsLiteral(type2.Dimensions.Count);
                }
                w.Write(">");
            }

            IPointerType type4 = type as IPointerType;

            if (type4 != null)
            {
                new TypeRef(type4.ElementType).WriteNameWithRef(w);
                w.Write("*");
            }

            IReferenceType type3 = type as IReferenceType;

            if (type3 != null)
            {
                new TypeRef(type3.ElementType).WriteNameWithRef(w);
                w.Write("%");
            }

            IOptionalModifier modifier2 = type as IOptionalModifier;

            if (modifier2 != null)
            {
                WriteModify(w, new TypeRef(modifier2.Modifier), new TypeRef(modifier2.ElementType), false);
            }

            IRequiredModifier modifier = type as IRequiredModifier;

            if (modifier != null)
            {
                WriteModify(w, new TypeRef(modifier.Modifier), new TypeRef(modifier.ElementType), true);
            }

            IFunctionPointer fptr = type as IFunctionPointer;

            if (fptr != null)
            {
                w.Write("(");
                new TypeRef(fptr.ReturnType.Type).WriteNameWithRef(w);
                w.Write(" (*)(");
                bool first = true;
                foreach (IParameterDeclaration declaration in fptr.Parameters)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        w.Write(", ");
                    }
                    new TypeRef(declaration.ParameterType).WriteNameWithRef(w);
                }
                w.Write("))");
            }

            IGenericParameter parameter = type as IGenericParameter;

            if (parameter != null)
            {
                w.WriteReference(parameter.Name, "/* ジェネリックパラメータ */ " + parameter.Name, null);
            }

            IGenericArgument argument = type as IGenericArgument;

            if (argument != null)
            {
                new TypeRef(argument.Resolve()).WriteNameWithRef(w);
            }

            if (type is IValueTypeConstraint)
            {
                w.WriteKeyword("value class");
            }
            else if (type is IDefaultConstructorConstraint)
            {
                w.Write("<DefaultConstructorConstraint>");
            }

            return("<不明な型>");
        }