本文整理汇总了C#中Specification.OutputCpp方法的典型用法代码示例。如果您正苦于以下问题:C# Specification.OutputCpp方法的具体用法?C# Specification.OutputCpp怎么用?C# Specification.OutputCpp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Specification
的用法示例。
在下文中一共展示了Specification.OutputCpp方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetComment
private static string GetComment(Specification S, bool declOnly, G25.fgs FGS, G25.Operator op, G25.FloatType FT, bool assign)
{
StringBuilder SB = new StringBuilder();
if ((S.OutputCpp()) && op.IsUnaryInPlace())
{
if (op.IsPrefix)
{
SB.Append("returns (" + FGS.ArgumentVariableNames[0] + " = " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0] + "))");
}
else
{
SB.Append("returns input value of " + FGS.ArgumentVariableNames[0] + ", but sets " + FGS.ArgumentVariableNames[0] + " to " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0] + ")");
}
}
else if (assign)
{
SB.Append("returns (" + FGS.ArgumentVariableNames[0] + " = " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0]);
SB.Append(", " + FGS.ArgumentVariableNames[1]);
SB.Append("))");
}
else {
SB.Append("returns " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0]);
if (op.IsBinary())
SB.Append(", " + FGS.ArgumentVariableNames[1]);
SB.Append(")");
}
return SB.ToString();
}
示例2: WriteOMtoOMcopy
public static void WriteOMtoOMcopy(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, OM srcOm, OM dstOm)
{
StringBuilder declSB = cgd.m_declSB;
StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB;
string srcTypeName = FT.GetMangledName(S, srcOm.Name);
string dstTypeName = FT.GetMangledName(S, dstOm.Name);
bool writeDecl = S.OutputC();
string funcName = GetFunctionName(S, (S.OutputC() ? "" : dstTypeName), "set", srcTypeName + "_to_" + dstTypeName);
// do we inline this func?
string inlineStr = G25.CG.Shared.Util.GetInlineString(S, S.m_inlineSet, " ");
string dstArgStr = (S.OutputC()) ? (dstTypeName + " *dst, ") : "";
string refStr = (S.OutputC()) ? "*" : ((S.OutputCpp()) ? "&" : "");
string CONST = (S.OutputCppOrC()) ? "const " : "";
string funcDecl = inlineStr + "void " + funcName + "(" + dstArgStr + CONST + srcTypeName + " " + refStr + "src)";
// write comment, function declaration
Comment comment = new Comment("Copies a " + srcTypeName + " to a " + dstTypeName + "\n" +
"Warning 1: coordinates which cannot be represented are silenty lost.\n" +
"Warning 2: coordinates which are not present in 'src' are set to zero in 'dst'.\n");
if (writeDecl)
{
comment.Write(declSB, S, 0);
declSB.Append(funcDecl);
declSB.AppendLine(";");
}
if (S.OutputCSharpOrJava())
comment.Write(defSB, S, 0);
defSB.Append(funcDecl);
{
defSB.AppendLine(" {");
Dictionary<Tuple<int, int, int>, Tuple<int, int, double>> D = dstOm.getMapping(srcOm);
StringBuilder copySB = new StringBuilder();
List<string> setToZero = new List<string>();
string matrixStr = (S.OutputC()) ? "m" : "m_m";
string dstMatrixStr = (S.OutputC()) ? "dst->" + matrixStr : matrixStr;
string ptrStr = (S.OutputC()) ? "->" : ".";
// For all grades of som, for all columns, for all rows, check D, get entry, set; otherwise set to null
// Do not use foreach() on D because we want to fill in coordinates in their proper order.
for (int gradeIdx = 1; gradeIdx < dstOm.Domain.Length; gradeIdx++)
{
for (int somRangeIdx = 0; somRangeIdx < dstOm.Range[gradeIdx].Length; somRangeIdx++)
{
for (int somDomainIdx = 0; somDomainIdx < dstOm.Domain[gradeIdx].Length; somDomainIdx++)
{
Tuple<int, int, int> key = new Tuple<int, int, int>(gradeIdx, somDomainIdx, somRangeIdx);
int somMatrixIdx = dstOm.getCoordinateIndex(gradeIdx, somDomainIdx, somRangeIdx);
string dstString = dstMatrixStr + gradeIdx + "[" + somMatrixIdx + "] = ";
if (D.ContainsKey(key))
{
Tuple<int, int, double> value = D[key];
int gomMatrixIdx = srcOm.getCoordinateIndex(gradeIdx, value.Value1, value.Value2);
double multiplier = value.Value3;
string multiplierString = (multiplier == 1.0) ? "" : (FT.DoubleToString(S, multiplier) + " * ");
copySB.AppendLine("\t" + dstString + multiplierString + " src" + ptrStr + matrixStr + gradeIdx + "[" + gomMatrixIdx + "];");
}
else
{
setToZero.Add(dstString);
}
}
}
}
// append copy statements
defSB.Append(copySB);
// append statements to set coordinates to zero
if (setToZero.Count > 0)
{
int cnt = 0;
defSB.Append("\t");
foreach (string str in setToZero)
{
defSB.Append(str);
cnt++;
if (cnt > 8)
{
cnt = 0;
defSB.AppendLine("");
defSB.Append("\t\t");
}
}
defSB.AppendLine(FT.DoubleToString(S, 0.0) + ";");
}
defSB.AppendLine("}");
}
}
示例3: GetFuncDecl
private static string GetFuncDecl(Specification S, bool declOnly, G25.fgs FGS, G25.Operator op, G25.FloatType FT, bool assign, bool constVal, bool returnByReference)
{
StringBuilder SB = new StringBuilder();
string inlineStr = G25.CG.Shared.Util.GetInlineString(S, (!declOnly) && S.m_inlineOperators, " ");
string returnTypeName = (FGS.m_returnTypeName.Length > 0) ? FGS.m_returnTypeName : FT.type;
if (!S.IsFloatType(returnTypeName)) returnTypeName = FT.GetMangledName(S, returnTypeName);
string arg1typeName = FT.GetMangledName(S, FGS.ArgumentTypeNames[0]);
string arg2typeName = (FGS.NbArguments > 1) ? FT.GetMangledName(S, FGS.ArgumentTypeNames[1]) : "";
SB.Append(inlineStr);
SB.Append(returnTypeName);
SB.Append(" ");
if (returnByReference) SB.Append("&");
SB.Append("operator");
SB.Append(op.Symbol);
if (assign) SB.Append("=");
SB.Append("(");
if (constVal) SB.Append("const ");
SB.Append(arg1typeName);
SB.Append(" &");
SB.Append(FGS.ArgumentVariableNames[0]);
if (op.IsBinary())
{
SB.Append(", const ");
SB.Append(arg2typeName);
SB.Append(" &");
SB.Append(FGS.ArgumentVariableNames[1]);
}
else if ((S.OutputCpp()) && op.IsPostfixUnary())
{ // add a dummy int argument so C++ knows this is a unary postfix op
SB.Append(", int");
}
SB.Append(")");
return SB.ToString();
}
示例4: WriteGomParts
/// <summary>
/// Generates functions which compute parts of the application of a general outermorphism to a general multivector.
///
/// This function should be called early on in the code generation process, at least
/// before any of the <c>???()</c> functions is called.
/// </summary>
/// <param name="S">Specification (used for output language, GMV).</param>
/// <param name="cgd">Where the result goes.</param>
public static void WriteGomParts(Specification S, CGdata cgd)
{
if (S.m_GOM == null) return; // nothing to do if GOM not defiend
int nbBaseTabs = (S.OutputCSharpOrJava()) ? 1 : 0;
int nbCodeTabs = nbBaseTabs + 1;
G25.GMV gmv = S.m_GMV;
G25.GOM gom = S.m_GOM;
string nameGOM = "O";
string nameSrcGMV = "A";
string nameDstGMV = "C";
// get symbolic multivector value
RefGA.Multivector[] M1 = null;
{
bool ptr = (S.OutputC());
int allGroups = -1;
M1 = G25.CG.Shared.Symbolic.GMVtoSymbolicMultivector(S, gmv, nameSrcGMV, ptr, allGroups);
}
foreach (G25.FloatType FT in S.m_floatTypes)
{
// map from code fragment to name of function
Dictionary<string, string> generatedCode = new Dictionary<string, string>();
// loop over all groups of the GMV, multiply with GOM, and assign the result
for (int srcGroup = 0; srcGroup < gmv.NbGroups; srcGroup++)
{
RefGA.Multivector inputValue = M1[srcGroup];
if (inputValue.IsScalar()) continue;
// Replace each basis blade in 'inputValue' with its value under the outermorphism.
RefGA.Multivector returnValue = RefGA.Multivector.ZERO; // returnValue = gom * gmv[srcGroup]
for (int i = 0; i < inputValue.BasisBlades.Length; i++)
{
// get input blade and domain for that grade
RefGA.BasisBlade inputBlade = inputValue.BasisBlades[i];
RefGA.BasisBlade[] domainBlades = gom.DomainForGrade(inputBlade.Grade());
for (int c = 0; c < domainBlades.Length; c++)
{
// if a match is found in the domain, add range vector to m_returnValue
if (domainBlades[c].bitmap == inputBlade.bitmap)
{
bool ptr = (S.OutputC());
RefGA.Multivector omColumnValue = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, gom.DomainSmvForGrade(inputBlade.Grade())[c], nameGOM, ptr);
RefGA.Multivector inputBladeScalarMultiplier = new RefGA.Multivector(new RefGA.BasisBlade(inputBlade, 0));
RefGA.Multivector domainBladeScalarMultiplier = new RefGA.Multivector(new RefGA.BasisBlade(domainBlades[c], 0));
returnValue = RefGA.Multivector.Add(returnValue,
RefGA.Multivector.gp(
RefGA.Multivector.gp(omColumnValue, inputBladeScalarMultiplier),
domainBladeScalarMultiplier));
break; // no need to search the other domainBlades too
}
}
} // end of 'compute return value'
// assign returnValue to various groups of the gmv
for (int dstGroup = 0; dstGroup < gmv.NbGroups; dstGroup++)
{
bool mustCast = false;
bool writeZeros = false; // no need to generate "+= 0.0;"
int dstBaseIdx = 0;
string code = G25.CG.Shared.CodeUtil.GenerateGMVassignmentCode(S, FT, mustCast, gmv, nameDstGMV, dstGroup, dstBaseIdx, returnValue, nbCodeTabs, writeZeros);
string funcName = GetGomPartFunctionName(S, FT, srcGroup, dstGroup);
cgd.m_gmvGomPartFuncNames[new Tuple<string, string>(FT.type, funcName)] = (code.Length > 0);
if (code.Length == 0) continue;
if (!S.m_GMV.IsGroupedByGrade(S.m_dimension))
code = code.Replace("=", "+=");
// check if code was already generated, and, if so, reuse it
if (generatedCode.ContainsKey(code))
{
// ready generated: call that function
code = "\t" + generatedCode[code] + "(" + nameGOM + ", " + nameSrcGMV + ", " + nameDstGMV + ");\n";
}
else
{
// not generated yet: remember code -> function
generatedCode[code] = funcName;
}
// write comment
string comment = "Computes the partial application of a general outermorphism to a general multivector";
string OM_PTR = "";
if (S.OutputC()) OM_PTR = "*";
else if (S.OutputCpp()) OM_PTR = "&";
//.........这里部分代码省略.........
示例5: WriteOperatorBody
private static void WriteOperatorBody(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, G25.fgs FGS, G25.Operator op, string funcName)
{
bool returnTypeEqualsFirstArgument = FGS.ReturnTypeName == FGS.ArgumentTypeNames[0];
if ((S.OutputCpp()) && op.IsUnaryInPlace() && returnTypeEqualsFirstArgument) // special unary case for C++
{
if (op.IsPrefix)
{
SB.AppendLine("\t" + FGS.ArgumentVariableNames[0] + " = " + funcName + "(" + FGS.ArgumentVariableNames[0] + ");");
SB.AppendLine("\treturn " + FGS.ArgumentVariableNames[0] + ";");
}
else
{
SB.AppendLine("\t" + FGS.ReturnTypeName + " retVal(" + FGS.ArgumentVariableNames[0] + ");");
SB.AppendLine("\t" + FGS.ArgumentVariableNames[0] + " = " + funcName + "(" + FGS.ArgumentVariableNames[0] + ");");
SB.AppendLine("\treturn retVal;");
}
}
else // regular operator function
{
SB.Append("\treturn " + funcName + "(" + FGS.ArgumentVariableNames[0]);
if (op.IsBinary()) SB.Append(", " + FGS.ArgumentVariableNames[1]);
SB.AppendLine(");");
}
}
示例6: GetAccessStr
/// <summary>
/// Returns an array of 'access strings' which are source code expressions that can be
/// used to access the coordinates of <c>smv</c>. The entries in the array correspond to
/// the non-const basis blades in <c>smv</c>.
///
/// An example of access strings is <c>"A.e1"</c>, <c>"A.e2"</c>, <c>"A.e3"</c>, for a 3-D vector type.
/// This could also be <c>"A.c[0]"</c>, <c>"A.c[1]"</c>, <c>"A.c[2]"</c> if coordinates are stored in an array.
///
/// If 'ptr' is true, <c>"->"</c> will be used to access instance variables, otherwise <c>"."</c> is used.
/// (this may need to be tweaked as more languages are available for output).
/// </summary>
/// <param name="S">Used for basis blade names, language, COORD_STORAGE, etc.</param>
/// <param name="smv">The specialized multivector for which access strings are generated.</param>
/// <param name="smvName">The variable name to be used in the access strings. For example, specify <c>"A"</c> to get <c>"A.c[0]"</c> and so on.</param>
/// <param name="ptr">Is the variable a pointer or a reference/value?</param>
/// <returns>Array of strings that can be used to access the non-constant coordinates of the 'smv'.</returns>
public static string[] GetAccessStr(Specification S, G25.SMV smv, string smvName, bool ptr)
{
string[] AL = new string[smv.NbNonConstBasisBlade];
string accessStr = (ptr) ? "->" : ".";
string memberPrefix = "";
// C++: override "this->" to ""
if (S.OutputCpp())
{
memberPrefix = "m_";
if ((smvName == SmvUtil.THIS) && (ptr == true))
{
smvName = "";
accessStr = "";
}
}
// C#, Java: override "this." to ""
else if (S.OutputCSharpOrJava())
{
memberPrefix = "m_";
if ((smvName == SmvUtil.THIS) && (ptr == false))
{
smvName = "";
accessStr = "";
}
}
string prefix = smvName + accessStr + memberPrefix;
for (int i = 0; i < smv.NbNonConstBasisBlade; i++)
AL[i] = prefix + smv.GetCoordLangID(i, S);
return AL;
}
示例7: GetIncrementCode
/// <summary>
/// Returns the code for <c>gmv + scalar</c>
///
/// The code is NOT composed of calls to functions generated by <c>WriteCANSparts()</c>.
///
/// The returned code is only the body. The function declaration is not included.
/// </summary>
/// <param name="S">Specification of algebra (used for output language).</param>
/// <param name="cgd">Currently not used.</param>
/// <param name="FT">Floating point type.</param>
/// <param name="FAI">Info about function arguments</param>
/// <param name="resultName">Name of variable where the result goes (in the generated code).</param>
/// <param name="increment">Whether write increment or decrement function.</param>
/// <returns>code for the requested function.</returns>
public static string GetIncrementCode(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
G25.CG.Shared.FuncArgInfo[] FAI, string resultName, bool increment)
{
G25.GMV gmv = S.m_GMV;
StringBuilder SB = new StringBuilder();
if (S.OutputC())
{
SB.AppendLine(FT.type + " val" + " = " +
FAI[0].MangledTypeName + "_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "(" + FAI[0].Name + ")" +
((increment) ? " + " : " - ") + FT.DoubleToString(S, 1.0) + ";");
SB.AppendLine(FAI[0].MangledTypeName + "_copy(" + resultName + ", " + FAI[0].Name + ");");
SB.AppendLine(FAI[0].MangledTypeName + "_set_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "(" + resultName + ", val);");
}
else
{
string convertMvIfCode = (S.OutputCSharpOrJava()) ? (".to_" + FAI[0].MangledTypeName + "()") : "";
if (S.OutputCpp())
SB.AppendLine(FAI[0].MangledTypeName + " " + resultName + "(" + FAI[0].Name + ");");
else SB.AppendLine(FAI[0].MangledTypeName + " " + resultName + " = new " + FAI[0].MangledTypeName + "(" + FAI[0].Name + convertMvIfCode + ");");
SB.AppendLine(FT.type + " val" + " = " + resultName + ".get_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "()" +
((increment) ? " + " : " - ") + FT.DoubleToString(S, 1.0) + ";");
SB.AppendLine(resultName + ".set_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "(val);");
SB.AppendLine("return " + resultName + ";");
}
return SB.ToString();
}
示例8: GenerateReturnCode
public static string GenerateReturnCode(Specification S, G25.SMV smv, G25.FloatType FT, String[] valueStr, int nbTabs, bool writeZeros)
{
StringBuilder SB = new StringBuilder();
string smvName = FT.GetMangledName(S, smv.Name);
string STATIC_MEMBER_ACCESS = (S.OutputCpp()) ? "::" : ".";
SB.Append('\t', nbTabs);
SB.Append("return ");
if (S.OutputCSharpOrJava())
SB.Append("new ");
SB.Append(smvName);
SB.Append("(");
if (valueStr.Length > 0)
{
SB.AppendLine(smvName + STATIC_MEMBER_ACCESS + SmvUtil.GetCoordinateOrderConstant(S, smv) + ",");
}
for (int i = 0; i < valueStr.Length; i++) {
SB.Append('\t', nbTabs+2);
SB.Append(valueStr[i]);
if (i < (valueStr.Length - 1)) SB.Append(",");
SB.AppendLine(" // " + smv.NonConstBasisBlade(i).ToLangString(S.m_basisVectorNames) );
}
SB.Append('\t', nbTabs+1);
SB.Append(");");
return SB.ToString();
}
示例9: GetInlineString
/// <summary>
/// Returns the appropriate inline string for the output language.
///
/// Returns "" when inline is false, and the inline string + postFixStr otherwise.
/// </summary>
/// <param name="S"></param>
/// <param name="inline"></param>
/// <param name="postFixStr">Concatenated to inline string. May be null.</param>
/// <returns>Inline string, or ""</returns>
public static string GetInlineString(Specification S, bool inline, String postFixStr)
{
if (inline)
{
if (S.OutputC())
return "";
else if (S.OutputCpp())
return "inline" + postFixStr;
else return "inline_str_to_do" + postFixStr;
}
else return "";
}
示例10: WriteDeclaration
/// <summary>
/// Writes a function declaration to 'SB'.
/// The closing comma is NOT included so the function can also be used as the start of a definition.
/// </summary>
/// <param name="SB">Where declaration goes.</param>
/// <param name="S">Used for all kinds of stuff.</param>
/// <param name="cgd">Results go into cgd.m_defSB, and so on</param>
/// <param name="inline">Should the function we inline?</param>
/// <param name="staticFunc">Static function?</param>
/// <param name="returnType">String which speficies the return type.</param>
/// <param name="functionName">The name of the function which is to be generated.</param>
/// <param name="returnArgument">FuncArgInfo which describes the optional return argument.</param>
/// <param name="arguments">Array of FuncArgInfo which describes the arguments of the function.</param>
public static void WriteDeclaration(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd,
bool inline, bool staticFunc, string returnType, string functionName,
FuncArgInfo returnArgument, FuncArgInfo[] arguments)
{
if (S.OutputJava())
SB.Append("public final ");
else if (S.OutputCSharp())
SB.Append("public ");
if (staticFunc) SB.Append("static ");
SB.Append(G25.CG.Shared.Util.GetInlineString(S, inline, " "));
if (returnArgument != null) returnType = returnArgument.MangledTypeName + "*"; // maybe for C write returnType = returnArgument + "*"?
SB.Append(returnType);
SB.Append(" ");
SB.Append(functionName);
SB.Append("(");
{ // write arguments
bool appendComma = false;
int nbArgs = (arguments == null) ? 0 : arguments.Length;
for (int i = -1; i < nbArgs; i++) // start at -1 for return argument
{
FuncArgInfo A = null;
if (i == -1)
{
A = returnArgument;
if (A == null) continue;
}
else A = arguments[i];
if (appendComma) SB.Append(", ");
if (S.OutputJava())
SB.Append("final ");
if (A.Constant && S.OutputCppOrC())
SB.Append("const ");
SB.Append(A.MangledTypeName);
if (S.OutputCSharpOrJava() && A.IsGMV() && A.MvInterface)
SB.Append(Main.IF_SUFFIX);
if (A.Array && S.OutputCSharpOrJava())
SB.Append("[]");
SB.Append(" ");
if (A.Pointer) SB.Append("*");
else if (S.OutputCpp() && (A.IsMVorOM())) // append '&'?
SB.Append("&");
SB.Append(A.Name);
if (A.Array && S.OutputCppOrC())
SB.Append("[]");
appendComma = true;
}
}
SB.Append(")");
}
示例11: WriteAssignmentFunction
/// <summary>
/// Writes a function to 'SB' which assigns a certain 'value' to a certain 'dstName'.
/// </summary>
/// <param name="S">Used for all kinds of stuff.</param>
/// <param name="cgd">Results go into cgd.m_defSB, and so on</param>
/// <param name="inline">Should the function we inline?</param>
/// <param name="staticFunc">Static function?</param>
/// <param name="returnType">String which speficies the return type.</param>
/// <param name="returnVarName">The name of the variable which should be returned. Should be one of the argument names.</param>
/// <param name="functionName">The name of the function which is to be generated.</param>
/// <param name="arguments">Array of FuncArg which describes the arguments of the function.</param>
/// <param name="dstFT">Floating point type of destination variable.</param>
/// <param name="mustCastDst">set to true if coordinates of 'value' must be cast to 'dstFT'.</param>
/// <param name="dstSmv">G25.SMV type of destination.</param>
/// <param name="dstName">Name of destination.</param>
/// <param name="dstPtr">Is the destination a pointer?</param>
/// <param name="value">Value to be written to the destination.</param>
/// <param name="returnArgument">For use with the 'C' language, an extra argument can be used to return results.</param>
public static void WriteAssignmentFunction(
Specification S, G25.CG.Shared.CGdata cgd,
bool inline, bool staticFunc, string returnType, string returnVarName, string functionName,
FuncArgInfo returnArgument, FuncArgInfo[] arguments,
FloatType dstFT, bool mustCastDst, G25.SMV dstSmv, string dstName, bool dstPtr, RefGA.Multivector value)
{
// where the definition goes:
StringBuilder defSB = (inline) ? cgd.m_inlineDefSB : cgd.m_defSB;
// write declaration yes/no?
bool writeDecl = (!(dstName.Equals(G25.CG.Shared.SmvUtil.THIS) && S.OutputCpp())) && // no declarations for C++ member functions
(!S.OutputCSharpOrJava()); // no declarations in C# and Java
if (writeDecl)
{
WriteDeclaration(cgd.m_declSB, S, cgd, inline, staticFunc, returnType, functionName, returnArgument, arguments);
cgd.m_declSB.AppendLine(";");
}
WriteDeclaration(defSB, S, cgd, inline, staticFunc, returnType, functionName, returnArgument, arguments);
defSB.AppendLine("");
defSB.AppendLine("{");
int nbTabs = 1;
bool declareVariable = false;
AssignInstruction AI = new AssignInstruction(nbTabs, dstSmv, dstFT, mustCastDst, value, dstName, dstPtr, declareVariable);
AI.Write(defSB, S, cgd);
if (returnVarName != null)
{
defSB.AppendLine("\treturn " + returnVarName + ";");
} else if (returnArgument != null) {
defSB.AppendLine("\treturn " + returnArgument.Name + ";");
}
defSB.AppendLine("}");
}
示例12: GetReportInstruction
// add someextra instructions for report usage?
// add extra verbatim code here if rep usage?
// what arguments are required??
public static Instruction GetReportInstruction(Specification S, G25.fgs F, FuncArgInfo[] FAI)
{
if ((S.OutputC()) ||
(!S.m_reportUsage) ||
(FAI.Length == 0)) return new NOPinstruction();
// check if all arguments are GMVs
for (int i = 0; i < FAI.Length; i++)
{
if (!FAI[i].IsGMV()) return new NOPinstruction();
}
// get XML spec
string XMLstr = GetXMLstring(S, F, FAI);
StringBuilder SB = new StringBuilder();
if (S.OutputCSharpOrJava())
{
for (int i = 0; i < FAI.Length; i++)
{
SB.AppendLine("SmvType type_" + FAI[i].Name + " = " + FAI[i].Name + ".to_" + FAI[i].MangledTypeName +"().m_t;");
}
}
{
string MV_CONSTANT = GetSpecializedConstantName(S, S.m_GMV.Name);
string INVALID_CONSTANT = GetSpecializedConstantName(S, INVALID);
// output the test for all specialized MVs
SB.Append("if (");
for (int i = 0; i < FAI.Length; i++)
{
if (i > 0)
{
SB.AppendLine(" && ");
SB.Append("\t");
}
if (S.OutputCpp())
{
SB.Append("(" + FAI[i].Name + ".m_t > " + MV_CONSTANT + ") && (" + FAI[i].Name + ".m_t < " + INVALID_CONSTANT + ")");
}
else if (S.OutputCSharp())
{
SB.Append("(type_" + FAI[i].Name + " > SmvType." + MV_CONSTANT + ") && (type_" + FAI[i].Name + " < SmvType." + INVALID_CONSTANT + ")");
}
else if (S.OutputJava())
{
SB.Append("(type_" + FAI[i].Name + ".compareTo(SmvType." + MV_CONSTANT + ") > 0) && (type_" + FAI[i].Name + ".compareTo(SmvType." + INVALID_CONSTANT + ") < 0)");
}
}
SB.AppendLine(") {");
if (S.OutputCpp())
{
SB.Append("\t\tstd::string reportUsageString = std::string(\"\") + ");
}
else if (S.OutputCSharp())
{
SB.Append("\t\tstring reportUsageString = ");
}
else if (S.OutputJava())
{
SB.Append("\t\tString reportUsageString = ");
}
// output XMLstr, replace placeholders with code
int XMLstrIdx = 0;
int argIdx = 0;
while (XMLstrIdx < XMLstr.Length)
{
string placeHolder = GetPlaceHolderString(argIdx);
int nextIdx = XMLstr.IndexOf(placeHolder, XMLstrIdx);
if (nextIdx < 0) nextIdx = XMLstr.Length;
SB.Append(Util.StringToCode(XMLstr.Substring(XMLstrIdx, nextIdx - XMLstrIdx)));
if (argIdx < FAI.Length)
{
if (S.OutputCpp())
{
SB.Append("+ g_" + S.m_namespace + "Typenames[" + FAI[argIdx].Name + ".m_t] + ");
}
else if (S.OutputCSharp())
{
SB.Append("+ typenames[(int)type_" + FAI[argIdx].Name + "] + ");
}
else if (S.OutputJava())
{
SB.Append("+ typenames[type_" + FAI[argIdx].Name + ".getId()] + ");
}
}
argIdx++;
XMLstrIdx = nextIdx + placeHolder.Length;
}
SB.AppendLine(";");
if (S.OutputCpp())
{
//.........这里部分代码省略.........