/// <summary> /// Writes the declaration/definitions of 'F' to StringBuffer 'SB', taking into account parameters specified in specification 'S'. /// </summary> public override void WriteFunction() { foreach (string floatName in m_fgs.FloatNames) { FloatType FT = m_specification.GetFloatType(floatName); bool computeMultivectorValue = true; G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_gmv.Name, computeMultivectorValue); // comment Comment comment = new Comment(m_fgs.AddUserComment("Returns Hadamard product (coordinate-wise multiplication) of " + FAI[0].TypeName + " and " + FAI[1].TypeName + ".")); // if scalar or specialized: generate specialized function if (m_gmvFunc) { G25.CG.Shared.CANSparts.ADD_SUB_HP_TYPE productType = (IsInverse(m_fgs)) ? G25.CG.Shared.CANSparts.ADD_SUB_HP_TYPE.IHP : G25.CG.Shared.CANSparts.ADD_SUB_HP_TYPE.HP; m_funcName[FT.type] = G25.CG.Shared.GmvCASNparts.WriteAddSubHpFunction(m_specification, m_cgd, FT, FAI, m_fgs, comment, productType); } else { // write simple specialized function: // because of lack of overloading, function names include names of argument types G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(m_specification, FT, m_fgs, FAI); m_funcName[FT.type] = CF.OutputName; // write out the function: G25.CG.Shared.Functions.WriteSpecializedFunction(m_specification, m_cgd, CF, FT, FAI, m_returnValue, comment); } } } // end of WriteFunction
/// <summary> /// Writes any addition or subtraction function for general multivectors, /// based on CASN parts code. /// </summary> /// <param name="S"></param> /// <param name="cgd"></param> /// <param name="FT"></param> /// <param name="FAI"></param> /// <param name="F"></param> /// <param name="comment"></param> /// <param name="funcType">ADD, SUB or HP</param> /// <returns>Full name of generated function.</returns> public static string WriteAddSubHpFunction(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.CG.Shared.FuncArgInfo[] FAI, G25.fgs F, Comment comment, G25.CG.Shared.CANSparts.ADD_SUB_HP_TYPE funcType) { // setup instructions System.Collections.Generic.List <G25.CG.Shared.Instruction> I = new System.Collections.Generic.List <G25.CG.Shared.Instruction>(); int nbTabs = 1; // write this function: string code = G25.CG.Shared.CANSparts.GetAddSubtractHpCode(S, cgd, FT, funcType, FAI, fgs.RETURN_ARG_NAME); // add one instruction (verbatim code) I.Add(new G25.CG.Shared.VerbatimCodeInstruction(nbTabs, code)); // because of lack of overloading, function names include names of argument types G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(S, FT, F, FAI); // setup return type and argument: string returnTypeName = FT.GetMangledName(S, S.m_GMV.Name); G25.CG.Shared.FuncArgInfo returnArgument = null; if (S.OutputC()) { returnArgument = new G25.CG.Shared.FuncArgInfo(S, CF, -1, FT, S.m_GMV.Name, false); // false = compute value } string funcName = CF.OutputName; //if (S.OutputC()) // funcName = FT.GetMangledName(S, funcName); // write function bool inline = false; // never inline GMV functions bool staticFunc = Functions.OutputStaticFunctions(S); G25.CG.Shared.Functions.WriteFunction(S, cgd, F, inline, staticFunc, returnTypeName, funcName, returnArgument, FAI, I, comment); return(funcName); }