/// <summary> /// Resolves a converter (underscore constructor) dependency. /// Searches for a converter from 'fromType' to 'toType'. /// /// If the function is not found, this is also enlisted in cgd.m_missingDependencies. /// Call cgd.PrintMissingDependencies() should be called to report the missing dependencies /// to the end-user. /// </summary> /// <param name="S">The spec.</param> /// <param name="cgd">Missing dependencies go into cgd.m_missingDependencies.</param> /// <param name="fromType"></param> /// <param name="toType"></param> /// <param name="FT"></param> /// <returns></returns> public static string GetConverterDependency(Specification S, CGdata cgd, string fromType, string toType, G25.FloatType FT) { // look for 'funcName' in all G25.fgs in the spec // string funcName = "_" + FT.GetMangledName(S, toType); string funcName = "_" + toType; foreach (G25.fgs F in S.m_functions) { if (F.IsConverter(S)) // is 'F' a converter (underscore constructor)? { if ((F.Name == funcName) && (F.ArgumentTypeNames[0] == fromType)) { return G25.CG.Shared.Converter.GetConverterName(S, F, FT.GetMangledName(S, fromType), FT.GetMangledName(S, toType)); } } } // converter not found: add it to missing deps: { // add dependency to list of missing deps: string outputName = null; string[] argumentTypes = new string[] { fromType }; string[] argVarNames = null; string returnTypeName = null; string metricName = null; string comment = null; Dictionary<string, string> options = null; G25.fgs F = new G25.fgs(funcName, outputName, returnTypeName, argumentTypes, argVarNames, new string[] { FT.type }, metricName, comment, options); cgd.AddMissingDependency(S, F); } // return fictional name: G25.fgs tmpF = null; return "missingFunction_" + G25.CG.Shared.Converter.GetConverterName(S, tmpF, FT.GetMangledName(S, fromType), FT.GetMangledName(S, toType)); }
/// <summary> /// Returns the name of a generated function (for example <c>gp_mv_mv</c>). /// The function is found by looking through all G25.FGS in the Specification. /// /// If the function is not found, a fictional name is returned, i.e. "missingFunction_" + functionName. /// This name will then show up in the generated code, which will not compile as a result. /// /// If the function is not found, this is also enlisted in cgd.m_missingDependencies. /// Call cgd.PrintMissingDependencies() should be called to report the missing dependencies /// to the end-user. /// </summary> /// <param name="S">The spec.</param> /// <param name="cgd">Missing dependencies go into cgd.m_missingDependencies.</param> /// <param name="functionName">Basic name of the function to be found.</param> /// <param name="argumentTypes">Names of the arguments types (not mangled).</param> /// <param name="returnTypeName">Name of the return type (can be null or "" for default return type).</param> /// <param name="FT">Floating point type.</param> /// <param name="metricName">(optional, can be null for don't care)</param> /// <returns>The mangled name of the function.</returns> public static string GetDependency(Specification S, CGdata cgd, string functionName, string[] argumentTypes, string returnTypeName, G25.FloatType FT, string metricName) { // bool returnTrueName = dependent on cgd.mode try { return(GetFunctionName(S, functionName, argumentTypes, returnTypeName, FT, metricName)); } catch (DependencyException) { // function not found, return a fictional name, and remember dependency G25.fgs F = null; { // get name of dep, and make sure it does not get mangled string outputName = functionName + cgd.GetDontMangleUniqueId(); if (returnTypeName != null) { outputName = outputName + "_returns_" + returnTypeName; } // add dependency to list of missing deps: string[] argVarNames = null; Dictionary <String, String> options = null; string comment = null; G25.fgs tmpF = new G25.fgs(functionName, outputName, returnTypeName, argumentTypes, argVarNames, new String[] { FT.type }, metricName, comment, options); F = cgd.AddMissingDependency(S, tmpF); } return(cgd.m_dependencyPrefix + F.OutputName); } } // end of GetDependency()
} // end of GetDependency() /// <summary> /// Resolves a converter (underscore constructor) dependency. /// Searches for a converter from 'fromType' to 'toType'. /// /// If the function is not found, this is also enlisted in cgd.m_missingDependencies. /// Call cgd.PrintMissingDependencies() should be called to report the missing dependencies /// to the end-user. /// </summary> /// <param name="S">The spec.</param> /// <param name="cgd">Missing dependencies go into cgd.m_missingDependencies.</param> /// <param name="fromType"></param> /// <param name="toType"></param> /// <param name="FT"></param> /// <returns></returns> public static string GetConverterDependency(Specification S, CGdata cgd, string fromType, string toType, G25.FloatType FT) { // look for 'funcName' in all G25.fgs in the spec // string funcName = "_" + FT.GetMangledName(S, toType); string funcName = "_" + toType; foreach (G25.fgs F in S.m_functions) { if (F.IsConverter(S)) // is 'F' a converter (underscore constructor)? { if ((F.Name == funcName) && (F.ArgumentTypeNames[0] == fromType)) { return(G25.CG.Shared.Converter.GetConverterName(S, F, FT.GetMangledName(S, fromType), FT.GetMangledName(S, toType))); } } } // converter not found: add it to missing deps: { // add dependency to list of missing deps: string outputName = null; string[] argumentTypes = new string[] { fromType }; string[] argVarNames = null; string returnTypeName = null; string metricName = null; string comment = null; Dictionary <string, string> options = null; G25.fgs F = new G25.fgs(funcName, outputName, returnTypeName, argumentTypes, argVarNames, new string[] { FT.type }, metricName, comment, options); cgd.AddMissingDependency(S, F); } // return fictional name: G25.fgs tmpF = null; return("missingFunction_" + G25.CG.Shared.Converter.GetConverterName(S, tmpF, FT.GetMangledName(S, fromType), FT.GetMangledName(S, toType))); }
/// <summary> /// Returns the name of a generated function (for example <c>gp_mv_mv</c>). /// The function is found by looking through all G25.FGS in the Specification. /// /// If the function is not found, a fictional name is returned, i.e. "missingFunction_" + functionName. /// This name will then show up in the generated code, which will not compile as a result. /// /// If the function is not found, this is also enlisted in cgd.m_missingDependencies. /// Call cgd.PrintMissingDependencies() should be called to report the missing dependencies /// to the end-user. /// </summary> /// <param name="S">The spec.</param> /// <param name="cgd">Missing dependencies go into cgd.m_missingDependencies.</param> /// <param name="functionName">Basic name of the function to be found.</param> /// <param name="argumentTypes">Names of the arguments types (not mangled).</param> /// <param name="returnTypeName">Name of the return type (can be null or "" for default return type).</param> /// <param name="FT">Floating point type.</param> /// <param name="metricName">(optional, can be null for don't care)</param> /// <returns>The mangled name of the function.</returns> public static string GetDependency(Specification S, CGdata cgd, string functionName, string[] argumentTypes, string returnTypeName, G25.FloatType FT, string metricName) { // bool returnTrueName = dependent on cgd.mode try { return GetFunctionName(S, functionName, argumentTypes, returnTypeName, FT, metricName); } catch (DependencyException) { // function not found, return a fictional name, and remember dependency G25.fgs F = null; { // get name of dep, and make sure it does not get mangled string outputName = functionName + cgd.GetDontMangleUniqueId(); if (returnTypeName != null) outputName = outputName + "_returns_" + returnTypeName; // add dependency to list of missing deps: string[] argVarNames = null; Dictionary<String, String> options = null; string comment = null; G25.fgs tmpF = new G25.fgs(functionName, outputName, returnTypeName, argumentTypes, argVarNames, new String[] { FT.type }, metricName, comment, options); F = cgd.AddMissingDependency(S, tmpF); } return cgd.m_dependencyPrefix + F.OutputName; } }