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(")"); }
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(")"); } }