public List <SearchTask> Execute(IList <SearchTask> searchTask, string storeResultDir) { var allTasks = new List <SearchTask>(searchTask); var groups = searchTask.GroupBy(i => i.SearchDir); foreach (var group in groups) { var tasks = group.ToList(); somethingChanged: BaseConverter.Founded.Clear(); List <SearchTask> allTasksPart; var projName = DirNameRegex.Match(tasks.First().SearchDir).Value; projName = CashParser.ToTitleCase(projName); var classes = RecursiveSearch(tasks, storeResultDir, true, out allTasksPart, projName); GenerateTestFileForApi(classes, tasks, projName); if (TaskHelper.AddTask(allTasks, allTasksPart)) { tasks = allTasksPart; goto somethingChanged; } } return(allTasks); }
protected override PreParsedElement TryParseElement(PreParsedElement preParsedElement, string templateName) { var test = preParsedElement.CppText; if (!FuncRegex.IsMatch(test))// || VoidFuncRegex.IsMatch(test)) { return(null); } var cppTypeMatch = FuncTypeRegex.Match(test); if (!cppTypeMatch.Success) { return(null); } var nameMatch = FuncNameRegex.Match(test); if (!nameMatch.Success) { return(null); } var paramsMatch = ParamsRegex.Match(test); if (!paramsMatch.Success) { return(null); } try { var field = new ParsedFunc(); field.Type = GetKnownTypeOrDefault(cppTypeMatch.Value, templateName); field.Name = CashParser.ToTitleCase(nameMatch.Value); field.CppName = nameMatch.Value; field.Params = TryParseParams(paramsMatch.Value); field.Comment = preParsedElement.Comment; field.MainComment = preParsedElement.MainComment; return(field); } catch (Exception e) { } var error = new ParsedFunc(); error.Comment = "Parsing error: { preParsedElement.CppText}"; return(error); }
private void AddTypeToTask(string type) { if (!Founded.ContainsKey(type)) { Founded.Add(type, CashParser.ToTitleCase(type)); if (!UnknownTypes.Any(i => i.SearchLine.Equals(type) && string.IsNullOrEmpty(i.SearchDir))) { var task = new SearchTask { Converter = KnownConverter.StructConverter, SearchLine = type, }; UnknownTypes.Add(task); } } }
private void ExtendPreParsedClass(ParsedClass parsedClass) { if (parsedClass == null) { return; } if (!string.IsNullOrEmpty(parsedClass.CppName)) { parsedClass.Name = CashParser.ToTitleCase(parsedClass.CppName); } if (!string.IsNullOrEmpty(parsedClass.CppInherit)) { parsedClass.Inherit = new List <ParsedType> { GetKnownTypeOrDefault(parsedClass.CppInherit) } } ; if (parsedClass.CppConstructorParams != null && parsedClass.CppConstructorParams.Any()) { foreach (var itm in parsedClass.CppConstructorParams) { parsedClass.ConstructorParams.Add(TryParseParam(itm)); } } if (parsedClass.ObjectType != ObjectType.Enum) { string templateName = null; if (parsedClass.IsTemplate) { templateName = CashParser.Unpack(parsedClass.Template, 1); } for (var i = 0; i < parsedClass.Fields.Count; i++) { var preParsedElement = parsedClass.Fields[i]; parsedClass.Fields[i] = TryParseElement(preParsedElement, templateName); } } parsedClass.Fields.RemoveAll(i => i == null); }
protected List <ParsedParams> TryParseParams(string parameters) { parameters = ParamNormRegex.Replace(parameters, string.Empty); parameters = parameters.Trim(); if (string.IsNullOrEmpty(parameters)) { return(new List <ParsedParams>()); } var typeMatches = ParamTypeRegex.Matches(parameters); var nameMatches = ParamNameRegex.Matches(parameters); if (typeMatches.Count != nameMatches.Count) { throw new InvalidCastException(); } var rez = new List <ParsedParams>(); for (var i = 0; i < typeMatches.Count; i++) { var defaultValue = string.Empty; var name = nameMatches[i].Value; var eqv = name.IndexOf("=", StringComparison.Ordinal); if (eqv > -1) { defaultValue = name.Substring(eqv + 1).Trim(); name = name.Remove(eqv).Trim(); } var param = new ParsedParams() { CppName = name, Name = CashParser.ToTitleCase(name, false), Default = defaultValue, CppType = typeMatches[i].Value, Type = GetKnownTypeOrDefault(typeMatches[i].Value) }; rez.Add(param); } return(rez); }
private ParsedParams TryParseParam(string parameters) { parameters = ParamNormRegex.Replace(parameters, string.Empty); parameters = parameters.Trim(); if (string.IsNullOrEmpty(parameters)) { return(new ParsedParams()); } var typeMatche = ParamTypeRegex.Match(parameters); var nameMatche = ParamNameRegex.Match(parameters); if (!typeMatche.Success || !nameMatche.Success) { throw new InvalidCastException(); } var defaultValue = string.Empty; var name = nameMatche.Value; var eqv = name.IndexOf("=", StringComparison.Ordinal); if (eqv > -1) { defaultValue = name.Substring(eqv + 1).Trim(); name = name.Remove(eqv).Trim(); } var rez = new ParsedParams() { CppName = name, Name = CashParser.ToTitleCase(name, false), Default = defaultValue, CppType = typeMatche.Value, Type = GetKnownTypeOrDefault(typeMatche.Value) }; return(rez); }
protected ParsedType GetKnownTypeOrDefault(string type, string templateName = null) { type = type.Trim(); if (NamespacePref.IsMatch(type)) { type = NamespacePref.Replace(type, string.Empty); } if (type.StartsWith("optional<")) { type = CashParser.Unpack(type, 1); } if (type.StartsWith("static ")) { type = type.Remove(0, 7); } if (type.StartsWith("const ")) { type = type.Remove(0, 6); } if (type.EndsWith("<>")) { type = type.Remove(type.Length - 2); } if (type.IndexOf('<') > -1) { return(GetKnownCompositType(type)); } if (_knownTypes.ContainsKey(type)) { return new ParsedType { CppName = type, Name = _knownTypes[type] } } ; if (!string.IsNullOrEmpty(templateName) && type.Equals(templateName, StringComparison.OrdinalIgnoreCase)) { return new ParsedType { CppName = type, Name = templateName } } ; if (Founded.ContainsKey(type)) { return(new ParsedType { CppName = type, Name = Founded[type] }); } if (!NotNameChar.IsMatch(type)) { AddTypeToTask(type); return(new ParsedType { CppName = type, Name = CashParser.ToTitleCase(type) }); } return(new ParsedType { CppName = type, Name = "object" }); }
protected override PreParsedElement TryParseElement(PreParsedElement preParsedElement, string templateName) { var test = preParsedElement.CppText; if (string.IsNullOrEmpty(test)) { return(null); } if (test.StartsWith("static ")) { test = test.Remove(0, 7); } if (test.StartsWith("const ")) { test = test.Remove(0, 6); } if (!_fieldRules.IsMatch(test)) { return(null); } var parts = test.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 2) { return(null); } var cppType = parts[0]; if (_notTypeChar.IsMatch(cppType)) { return(null); } var name = parts[1].Trim(' ', ';'); if (NotNameChar.IsMatch(name)) { return(null); } var coment = string.Empty; if (parts.Length > 2) { coment = string.Join(" ", parts.Skip(2)).TrimStart(' ', '/', '<'); } var field = new PreParsedElement { Type = GetKnownTypeOrDefault(cppType, templateName), Name = CashParser.ToTitleCase(name), CppName = name, Comment = coment, MainComment = preParsedElement.MainComment }; return(field); }