/// <summary> /// Translates an object creation, e.g. "new float4(...)". /// </summary> /// <remarks> /// GLSL 1.1 does not support matrix casts. /// </remarks> public override StringBuilder VisitObjectCreateExpression(ObjectCreateExpression objCreateExpr) { if (!(objCreateExpr.Type.GetType() == typeof(SimpleType))) { return(base.VisitObjectCreateExpression(objCreateExpr)); } var simpleType = (SimpleType)objCreateExpr.Type; var dataType = simpleType.Annotation <TypeReference>().ToType(); if (dataType == typeof(float3x3)) { var methodRef = (MethodReference)objCreateExpr.Annotations.First(); var methodDef = methodRef.Resolve(); var methodParam = methodDef.Parameters.FirstOrDefault(); if (methodParam != null && methodParam.ParameterType.IsType <float4x4>()) { var instr = GetInstructionFromStmt(objCreateExpr.GetParent <Statement>()); DebugLog.Warning("Matrix casting (float4x4 to float3x3) is not supported " + "in GLSL 1.1. Expression has been converted automatically", instr); var argName = objCreateExpr.Arguments.First().AcceptVisitor(this); var row1 = argName + "[0].xyz"; var row2 = argName + "[1].xyz"; var row3 = argName + "[2].xyz"; var type = objCreateExpr.Type.AcceptVisitor(this).ToString(); return(new StringBuilder().Method(type, row1, row2, row3)); } } return(base.VisitObjectCreateExpression(objCreateExpr)); }
string GuessParameterName(ObjectCreateExpression objectCreateExpression, List <string> validNames) { if (validNames.Count == 1) { return(validNames[0]); } var parent = objectCreateExpression.GetParent <IfElseStatement>(); if (parent == null) { return(null); } return(GetParameterName(parent.Condition)); }