static void AddPartReturnDetail(CodeMethodBodyCodePart part, string line) { int indexOfType = line.IndexOf("type:"); if (indexOfType > -1) { part.ReturnType = line.Substring(indexOfType + 5 /*"type:"*/).Trim(); } }
public bool TryGetTranslateParameter(string parName, out CodeMethodBodyCodePart found) { if (translateParts != null) { return(translateParts.TryGetValue(parName, out found)); } found = null; return(false); }
static void AddPartParameterDetail(CodeMethodBodyCodePart part, string line) { int indexOfParam = line.IndexOf("param:"); if (indexOfParam > -1) { int indexOfType = line.IndexOf("type:", indexOfParam); string paramName = line.Substring(indexOfParam + 6 /*"param:"*/, indexOfType - (indexOfParam + 6)).Trim(); paramName = paramName.Substring(0, paramName.Length - 1); //------------------------------------------------------------- string typeName = line.Substring(indexOfType + 5 /*"type:"*/).Trim(); part.ParamName = paramName; part.ParamType = typeName; } }
public MultiPartCodeMethodBody(List <CodeMethodBodyCodePart> codeParts) { this.codeParts = codeParts; //analyze detail int j = codeParts.Count; for (int i = 0; i < j; ++i) { CodeMethodBodyCodePart p = codeParts[i]; switch (p.PartKind) { case MethodBodyCodePartKind.TranslateParam: { if (translateParts == null) { translateParts = new Dictionary <string, CodeMethodBodyCodePart>(); } // translateParts.Add(p.ParamName, p); //analyze new name switch (p.ParamType) { default: throw new NotSupportedException(); case "refptr_same_byref": //refptr_same_byref { string v_name, v_type; GetCppVarTypeAndName(p.PartLines[1], out v_type, out v_name); //cef-specific //get exact var name p.ReplacedParExpression = "&" + v_name; } break; case "simple_byref": case "simple_byref_const": p.ReplacedParExpression = "&" + p.ParamName + "Val"; break; case "string_byref": p.ReplacedParExpression = "&" + p.ParamName + "Str"; break; case "simple_vec_byref_const": case "string_vec_byref_const": case "refptr_vec_diff_byref_const": //cef-specific p.IsList = true; p.ReplacedParExpression = "&" + p.ParamName + "List"; break; case "bool_byref": case "bool_byaddr": p.ReplacedParExpression = "&" + p.ParamName + "Bool"; break; case "struct_byref": case "struct_byref_const": p.ReplacedParExpression = "&" + p.ParamName + "Obj"; break; case "rawptr_diff": { string v_name, v_type; GetCppVarTypeAndName(p.PartLines[1], out v_type, out v_name); if (v_name == "registrarPtr") { //cef-specific //TODO: check the type instead of var name p.ReplacedParExpression = v_name + ".get()"; } else { p.ReplacedParExpression = "&" + p.ParamName + "Ptr"; } } break; case "refptr_diff_byref": p.ReplacedParExpression = "&" + p.ParamName + "Ptr"; break; } } break; case MethodBodyCodePartKind.RestoreParam: { if (restoreParts == null) { restoreParts = new List <CodeMethodBodyCodePart>(); } restoreParts.Add(p); } break; } } }
MultiPartCodeMethodBody ParseCppMethodBody(CodeMethodDeclaration metDecl) { List <CodeMethodBodyCodePart> codeParts = new List <CodeMethodBodyCodePart>(); int endAt = metDecl.EndAtLine; CodeMethodBodyCodePart currentPart = null; for (int lineNo = metDecl.StartAtLine + 1; lineNo <= endAt; ++lineNo) { string line = simpleLineList[lineNo].Trim(); //parse special mx parameter if (line.StartsWith("// Translate param:")) { //begin new currentPart = new CodeMethodBodyCodePart() { PartKind = MethodBodyCodePartKind.TranslateParam, beginAtLine = lineNo }; AddPartParameterDetail(currentPart, line); currentPart.PartLines.Add(line); codeParts.Add(currentPart); } else if (line.StartsWith("// Restore param:")) { //begin new currentPart = new CodeMethodBodyCodePart() { PartKind = MethodBodyCodePartKind.RestoreParam, beginAtLine = lineNo }; AddPartParameterDetail(currentPart, line); currentPart.PartLines.Add(line); codeParts.Add(currentPart); } else if (line.StartsWith("// Verify param:")) { //begin new currentPart = new CodeMethodBodyCodePart() { PartKind = MethodBodyCodePartKind.VerifyParam, beginAtLine = lineNo }; AddPartParameterDetail(currentPart, line); currentPart.PartLines.Add(line); codeParts.Add(currentPart); } else if (line.StartsWith("// Return type:")) { //begin new currentPart = new CodeMethodBodyCodePart() { PartKind = MethodBodyCodePartKind.Return, beginAtLine = lineNo }; AddPartReturnDetail(currentPart, line); currentPart.PartLines.Add(line); codeParts.Add(currentPart); } else if (line.StartsWith("// Execute")) { //begin new currentPart = new CodeMethodBodyCodePart() { PartKind = MethodBodyCodePartKind.Execute, beginAtLine = lineNo }; currentPart.PartLines.Add(line); codeParts.Add(currentPart); } else if (line.StartsWith("//")) { //other block currentPart = new CodeMethodBodyCodePart() { PartKind = MethodBodyCodePartKind.Other, beginAtLine = lineNo }; currentPart.PartLines.Add(line); codeParts.Add(currentPart); } else { //other if (currentPart == null) { currentPart = new CodeMethodBodyCodePart() { PartKind = MethodBodyCodePartKind.Other, beginAtLine = lineNo }; codeParts.Add(currentPart); } currentPart.PartLines.Add(line); } } return(new MultiPartCodeMethodBody(codeParts)); }