/// <summary> /// Writes code for return m_name. /// </summary> /// <param name="SB">Where the code goes.</param> /// <param name="S">Specification of algebra.</param> /// <param name="cgd">Not used yet.</param> public override void Write(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd) { if (m_type is G25.FloatType) { AppendTabs(SB); // Temp hack to override the float type: G25.FloatType FT = m_floatType; //m_type as G25.FloatType; // Should postops still be applied? ApplyPostOp(S, plugins, cog, BL, valueStr); // Not required so far? SB.AppendLine(CodeUtil.GenerateScalarReturnCode(S, FT, m_mustCast, m_value)); } else if (m_type is G25.SMV) { if (S.OutputC()) { bool ptr = true; bool declareVariable = false; new AssignInstruction(m_nbTabs, m_type, m_floatType, m_mustCast, m_value, G25.fgs.RETURN_ARG_NAME, ptr, declareVariable, m_postOp, m_postOpValue).Write(SB, S, cgd); } else { G25.SMV smv = m_type as G25.SMV; RefGA.BasisBlade[] BL = BasisBlade.GetNonConstBladeList(smv); bool writeZeros = true; string[] valueStr = CodeUtil.GetAssignmentStrings(S, m_floatType, m_mustCast, BL, m_value, writeZeros); // apply post operation (like "/ n2") ApplyPostOp(S, cgd, BL, valueStr); SB.AppendLine(CodeUtil.GenerateReturnCode(S, smv, m_floatType, valueStr, m_nbTabs, writeZeros)); } } }
} // end of GenerateScalarReturnCode() /// <summary> /// Generates the code to assign a multivector value (which may have symbolic coordinates) to a specialized multivector. /// </summary> /// <param name="S">Specification of algebra. Used to known names of basis vector, output language, access strings, etc.</param> /// <param name="FT">Floating point type of destination.</param> /// <param name="mustCast">Set to true if a cast to 'FT' must be performed before assigned to 'dstName'.</param> /// <param name="dstSmv">Type of specialized multivector assigned to.</param> /// <param name="dstName">Name of specialized multivector assigned to.</param> /// <param name="dstPtr">Is the destination of pointer?</param> /// <param name="value">Multivector value to assign to the SMV. Must not contain basis blades inside the symbolic scalars.</param> /// <param name="nbTabs">Number of tabs to put before the code.</param> /// <param name="writeZeros">Some callers want to skip <c>"= 0.0"</c> assignments because they would be redundant. For /// example the caller may know that the destination is already set to zero. If so, set this argument to false and /// code for setting coordinates to 0 will not be generated.</param> /// <returns>String of code for dstName = value;</returns> public static string GenerateSMVassignmentCode(Specification S, FloatType FT, bool mustCast, G25.SMV dstSmv, String dstName, bool dstPtr, RefGA.Multivector value, int nbTabs, bool writeZeros) { RefGA.BasisBlade[] BL = BasisBlade.GetNonConstBladeList(dstSmv); string[] accessStr = GetAccessStr(S, dstSmv, dstName, dstPtr); string[] assignedStr = GetAssignmentStrings(S, FT, mustCast, BL, value, writeZeros); //int nbTabs = 1; return(GenerateAssignmentCode(S, accessStr, assignedStr, nbTabs, writeZeros)); } // end of GenerateSMVassignmentCode
/// <summary> /// Writes code for m_name = m_value. /// </summary> /// <param name="SB">Where the code goes.</param> /// <param name="S">Specification of algebra.</param> /// <param name="cgd">Not used yet.</param> public override void Write(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd) { if (m_type is G25.SMV) { G25.SMV dstSmv = m_type as G25.SMV; if (m_declareVariable) { SB.AppendLine("/* cannot yet assign and declare SMV type at the same time */"); } RefGA.BasisBlade[] BL = BasisBlade.GetNonConstBladeList(dstSmv); string[] accessStr = CodeUtil.GetAccessStr(S, dstSmv, m_name, m_ptr); bool writeZeros = true; string[] valueStr = CodeUtil.GetAssignmentStrings(S, m_floatType, m_mustCast, BL, m_value, writeZeros); // apply post operation (like "/ n2") ApplyPostOp(S, cgd, BL, valueStr); SB.AppendLine(CodeUtil.GenerateAssignmentCode(S, accessStr, valueStr, m_nbTabs, writeZeros)); } else if (m_type is G25.FloatType) { // temp hack to override float type. G25.FloatType FT = this.m_floatType; // m_type as G25.FloatType; AppendTabs(SB); if (m_declareVariable) { // also declare the variable right here? // output "/t type " SB.Append(FT.type + " "); } // output name = ....; RefGA.BasisBlade[] BL = new RefGA.BasisBlade[1] { RefGA.BasisBlade.ONE }; String[] accessStr = new String[1] { m_name }; bool writeZeros = true; String[] valueStr = CodeUtil.GetAssignmentStrings(S, FT, m_mustCast, BL, m_value, writeZeros); // apply post operation (like "/ n2") ApplyPostOp(S, cgd, BL, valueStr); SB.AppendLine(CodeUtil.GenerateAssignmentCode(S, accessStr, valueStr, 0, writeZeros)); } else { SB.AppendLine("/* to do: implement " + GetType().ToString() + " for type " + m_type.GetType().ToString() + " */"); } }