internal override void WriteTo(CCodeWriterBase c) { if (this.Method.IsStaticMethod()) { c.WriteTypeFullName(this.Method.ContainingType); c.TextSpan("::"); c.WriteMethodName(this.Method, addTemplate: true); } else { var receiverOpt = this.ReceiverOpt; if (receiverOpt != null) { receiverOpt = this.PrepareMethodReceiver(receiverOpt, this.Method); // if method name is empty then receiverOpt returns function pointer if (!string.IsNullOrWhiteSpace(this.Method.Name)) { c.WriteAccess(receiverOpt); } else { c.WriteExpressionInParenthesesIfNeeded(receiverOpt); } } c.WriteMethodName(this.Method, addTemplate: true /*, methodSymbolForName: explicitMethod*/); } WriteCallArguments(this._arguments, this.Method != null ? this.Method.Parameters : (IEnumerable <IParameterSymbol>)null, c); }
internal override void WriteTo(CCodeWriterBase c) { c.WriteExpressionInParenthesesIfNeeded(this.Operand); c.TextSpan("["); this.Index.WriteTo(c); c.TextSpan("]"); }
internal override void WriteTo(CCodeWriterBase c) { bool changedLeft; this.Left = AdjustEnumType(this.Left, out changedLeft); bool changedRight; this.Right = AdjustEnumType(this.Right, out changedRight); var castOfResult = (changedRight || changedLeft) && Type.TypeKind == TypeKind.Enum; if (castOfResult) { c.TextSpan("(("); c.WriteType(Type); c.TextSpan(")("); } var reminder = GetOperatorKind(this.OperatorKind) == BinaryOperatorKind.Remainder && (this.Left.Type.IsRealValueType() || this.Right.Type.IsRealValueType()); if (reminder) { c.TextSpan("std::remainder("); c.WriteExpressionInParenthesesIfNeeded(this.Left); c.TextSpan(","); c.WhiteSpace(); c.WriteExpressionInParenthesesIfNeeded(this.Right); c.TextSpan(")"); } else { c.WriteExpressionInParenthesesIfNeeded(this.Left); c.WhiteSpace(); this.WriteOperator(c); c.WhiteSpace(); c.WriteExpressionInParenthesesIfNeeded(this.Right); } if (castOfResult) { c.TextSpan("))"); } }
internal override void WriteTo(CCodeWriterBase c) { if (this.Field.IsStatic) { c.WriteTypeFullName(this.Field.ContainingType); c.TextSpan("::"); c.WriteName(this.Field); } else { if (this.PointerAccess) { var pointerIndirect = this.ReceiverOpt as PointerIndirectionOperator; if (pointerIndirect != null) { c.WriteExpressionInParenthesesIfNeeded(pointerIndirect.Operand); c.TextSpan("->"); c.WriteName(this.Field); return; } } if (this.ReceiverOpt != null) { var primitiveValueAccess = this.Field.ContainingType != null && this.Field.ContainingType.IsPrimitiveValueType() && this.Field.Name == "m_value" && this.ReceiverOpt is Conversion && ((Conversion)this.ReceiverOpt).ConversionKind == ConversionKind.Unboxing; if (primitiveValueAccess) { c.WriteExpressionInParenthesesIfNeeded(this.ReceiverOpt); return; } else { c.WriteAccess(this.ReceiverOpt); } } c.WriteName(this.Field); } }
internal override void WriteTo(CCodeWriterBase c) { c.WriteExpressionInParenthesesIfNeeded(this.Condition); c.WhiteSpace(); c.TextSpan("?"); c.WhiteSpace(); this.Consequence.WriteTo(c); c.WhiteSpace(); c.TextSpan(":"); c.WhiteSpace(); this.Alternative.WriteTo(c); }
internal override void WriteTo(CCodeWriterBase c) { var interfaceCastRequired = this.ConversionKind == ConversionKind.Boxing && Type.TypeKind == TypeKind.Interface; if (interfaceCastRequired) { c.TextSpan(this.TypeSource.AllInterfaces.Contains((INamedTypeSymbol)Type) ? "interface_cast" : "dynamic_interface_cast"); c.TextSpan("<"); c.WriteType(Type); c.TextSpan(">"); c.TextSpan("("); } var effectiveExpression = this.Operand; if (this.ConversionKind == ConversionKind.Boxing && this.Operand.IsStaticWrapperCall()) { effectiveExpression = new Cast { Type = this.TypeSource, Operand = effectiveExpression, CCast = true, UseEnumUnderlyingType = true, }; } var parenthesis = false; if (this.WriteCast(c, out parenthesis)) { if (parenthesis) { c.WriteExpressionInParenthesesIfNeeded(effectiveExpression); } else { c.TextSpan("("); effectiveExpression.WriteTo(c); c.TextSpan(")"); } } if (interfaceCastRequired) { c.TextSpan(")"); } }
internal override void WriteTo(CCodeWriterBase c) { c.WriteExpressionInParenthesesIfNeeded(this.ReceiverOpt); switch (this.AccessType) { case AccessTypes.Dot: c.TextSpan("."); break; case AccessTypes.DoubleColon: c.TextSpan("::"); break; default: c.TextSpan("->"); break; } this.Expression.WriteTo(c); }
internal override void WriteTo(CCodeWriterBase c) { var interfaceCastRequired = this.ConversionKind == ConversionKind.Boxing && Type.TypeKind == TypeKind.Interface; if (interfaceCastRequired) { c.TextSpan(this.TypeSource.AllInterfaces.Contains((INamedTypeSymbol)Type) ? "interface_cast" : "dynamic_interface_cast_or_throw"); c.TextSpan("<"); c.WriteType(Type, containingNamespace: MethodOwner?.ContainingNamespace); c.TextSpan(">"); c.TextSpan("("); } var castRequired = this.ConversionKind == ConversionKind.Boxing && TypeSource.TypeKind == TypeKind.TypeParameter && Type.TypeKind == TypeKind.TypeParameter; if (castRequired) { c.TextSpan("cast<"); c.WriteType(Type, containingNamespace: MethodOwner?.ContainingNamespace); c.TextSpan(">"); c.TextSpan("("); } var effectiveExpression = this.Operand; if ((this.ConversionKind == ConversionKind.Boxing || this.ConversionKind == ConversionKind.ImplicitReference) && this.Operand.IsStaticOrSupportedVolatileWrapperCall()) { effectiveExpression = new Cast { Type = this.TypeSource, Operand = effectiveExpression, CCast = true, UseEnumUnderlyingType = true, MethodOwner = MethodOwner }; } if (this.ConversionKind == ConversionKind.Unboxing && this.Operand.Type.TypeKind == TypeKind.Interface) { effectiveExpression = new Conversion { Type = new NamedTypeImpl { SpecialType = SpecialType.System_Object }, TypeSource = this.TypeSource, Operand = effectiveExpression, ConversionKind = ConversionKind.ImplicitReference, MethodOwner = MethodOwner }; } var parenthesis = false; if (this.WriteCast(c, out parenthesis)) { if (parenthesis) { c.WriteExpressionInParenthesesIfNeeded(effectiveExpression); } else { c.TextSpan("("); if (this.ConversionKind == ConversionKind.Boxing && Cs2CGenerator.DebugOutput) { c.TextSpan("__FILE__, __LINE__, "); } effectiveExpression.WriteTo(c); c.TextSpan(")"); } } if (castRequired) { c.TextSpan(")"); } if (interfaceCastRequired) { c.TextSpan(")"); } }
internal override void WriteTo(CCodeWriterBase c) { var effectiveType = Type; ////if (this.UseEnumUnderlyingType && effectiveType.TypeKind == TypeKind.Enum) ////{ //// effectiveType = ((INamedTypeSymbol)effectiveType).EnumUnderlyingType; ////} if (this.Constrained) { c.TextSpan("constrained<"); c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast); c.TextSpan(">("); this.Operand.WriteTo(c); c.TextSpan(")"); } else if (this.Reference) { c.TextSpan("(("); c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast); c.TextSpan("&)"); c.WriteExpressionInParenthesesIfNeeded(this.Operand); c.TextSpan(")"); } else if (this.CCast) { c.TextSpan("(("); c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast); c.TextSpan(")"); c.WriteExpressionInParenthesesIfNeeded(this.Operand); c.TextSpan(")"); } else if (this.MapPointerCast) { c.TextSpan("map_pointer_cast<"); this.MapPointerCastTypeParameter1.WriteTo(c); c.TextSpan(", "); this.MapPointerCastTypeParameter2.WriteTo(c); c.TextSpan(">("); c.WriteExpressionInParenthesesIfNeeded(this.Operand); c.TextSpan(")"); } else if (this.BoxByRef) { c.TextSpan("__box_ref_t"); c.TextSpan("("); new Cast { CCast = true, Type = new PointerTypeImpl { PointedAtType = Type }, Operand = Operand }.WriteTo(c); c.TextSpan(")"); } else { c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast); c.TextSpan("("); this.Operand.WriteTo(c); c.TextSpan(")"); } }
internal override void WriteTo(CCodeWriterBase c) { var effectiveType = Type; ////if (this.UseEnumUnderlyingType && effectiveType.TypeKind == TypeKind.Enum) ////{ //// effectiveType = ((INamedTypeSymbol)effectiveType).EnumUnderlyingType; ////} if (this.Constrained) { c.TextSpan("constrained"); var refValue = false; switch (this.Operand) { case Local localVar: refValue = localVar.IsRef || localVar.IsOut; break; case Parameter parameter: var refKind = parameter.ParameterSymbol.RefKind; refValue = refKind.HasFlag(Microsoft.CodeAnalysis.RefKind.Ref) || refKind.HasFlag(Microsoft.CodeAnalysis.RefKind.Out); break; case Cast cast: refValue = cast.BoxByRef; break; } if (refValue) { c.TextSpan("_ref"); } c.TextSpan("<"); if (this.ValueTypeToClass) { c.TextSpan("typename std::remove_pointer<typename valuetype_to_class<"); } c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast, containingNamespace: MethodOwner?.ContainingNamespace); if (this.ValueTypeToClass) { c.TextSpan(">::type>::type*"); } c.TextSpan(">("); this.Operand.WriteTo(c); c.TextSpan(")"); } else if (this.Reference) { c.TextSpan("(("); c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast, containingNamespace: MethodOwner?.ContainingNamespace); c.TextSpan("&)"); c.WriteExpressionInParenthesesIfNeeded(this.Operand); c.TextSpan(")"); } else if (this.CCast) { c.TextSpan("(("); c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast, containingNamespace: MethodOwner?.ContainingNamespace); c.TextSpan(")"); c.WriteExpressionInParenthesesIfNeeded(this.Operand); c.TextSpan(")"); } else if (this.MapPointerCast) { c.TextSpan("map_pointer_cast<"); this.MapPointerCastTypeParameter1.WriteTo(c); c.TextSpan(", "); this.MapPointerCastTypeParameter2.WriteTo(c); c.TextSpan(">("); c.WriteExpressionInParenthesesIfNeeded(this.Operand); c.TextSpan(")"); } else if (this.BoxByRef) { c.TextSpan("__box_ref_t"); c.TextSpan("("); new Cast { CCast = true, Type = new PointerTypeImpl { PointedAtType = Type }, Operand = Operand, MethodOwner = MethodOwner }.WriteTo(c); c.TextSpan(")"); } else { c.WriteType(effectiveType, this.ClassCast, valueTypeAsClass: this.ClassCast, containingNamespace: MethodOwner?.ContainingNamespace); c.TextSpan("("); this.Operand.WriteTo(c); c.TextSpan(")"); } }