コード例 #1
0
ファイル: WikiArticle.cs プロジェクト: cramt/gm_dotnet
        public IDescribeInterface FetchLibraryInfo(string categoryName)
        {
            Console.WriteLine($"Fetching library: {categoryName}");
            var info = new IDescribeInterface {
                Name = categoryName
            };

            info.Description = FetchCategoryDescription(categoryName);

            var request = new RestRequest("api.php");

            request.AddParameter("action", "query");
            request.AddParameter("format", "xml");
            request.AddParameter("list", "categorymembers");
            request.AddParameter("cmlimit", 500);
            request.AddParameter("cmtitle", "Category:" + categoryName);

            var response = API.Execute(request);

            var xml = new XmlDocument();

            xml.LoadXml(response.Content);

            var members = xml.SelectNodes("//api/query/categorymembers/cm");
            var dict    = new Dictionary <int, string>();

            foreach (XmlNode member in members)
            {
                var pageid = int.Parse(member.Attributes["pageid"].Value);
                var name   = member.Attributes["title"].Value.Replace(categoryName + "/", "");
                dict.Add(pageid, name);
            }
            info.Methods = FetchFunctionInfo(dict).Cast <IDescribeMethod>().ToList();
            return(info);
        }
コード例 #2
0
ファイル: InterfaceBuilder.cs プロジェクト: cramt/gm_dotnet
        private CodeTypeDeclaration GenerateInterface(IDescribeInterface declaration)
        {
            var newType = new CodeTypeDeclaration(CleanInterfaceName(declaration.Name))
            {
                IsInterface    = true,
                TypeAttributes = TypeAttributes.Interface | TypeAttributes.Public
            };

            newType.CustomAttributes.AddRange(declaration.Attributes.ToArray());


            foreach (var parent in declaration.Parents)
            {
                newType.BaseTypes.Add(new CodeTypeReference(parent));
            }

            if (!string.IsNullOrWhiteSpace(declaration.Description))
            {
                newType.Comments.Add(new CodeCommentStatement("<summary>", true));
                var desc = BuildDescription(declaration.Description);
                if (desc != null)
                {
                    newType.Comments.AddRange(desc.ToArray());
                }
                else
                {
                    newType.Comments.Add(new CodeCommentStatement(declaration.Description, true));
                }
                newType.Comments.Add(new CodeCommentStatement("</summary>", true));
            }


            foreach (var methodDeclaration in declaration.Methods)
            {
                var newMethod = new CodeMemberMethod
                {
                    Name = methodDeclaration.Name
                };

                if (!string.IsNullOrWhiteSpace(methodDeclaration.Description))
                {
                    newMethod.Comments.Add(new CodeCommentStatement("<summary>", true));
                    newMethod.Comments.Add(new CodeCommentStatement(methodDeclaration.Description, true));
                    newMethod.Comments.Add(new CodeCommentStatement("</summary>", true));
                }

                if (methodDeclaration.Returns.Count == 1)
                {
                    newMethod.ReturnType = new CodeTypeReference(methodDeclaration.Returns[0].Type);
                    if (!string.IsNullOrWhiteSpace(methodDeclaration.Returns[0].Description))
                    {
                        newMethod.Comments.Add(new CodeCommentStatement($"<returns>Type: {methodDeclaration.Returns[0].Type} - {methodDeclaration.Returns[0].Description}</returns>", true));
                    }
                }
                else
                {
                    //f*****g fix it m8
                }

                foreach (var arg in methodDeclaration.Arguments)
                {
                    var param = new CodeParameterDeclarationExpression(arg.Type, arg.Name);
                    if (!string.IsNullOrWhiteSpace(arg.Default))
                    {
                        param.CustomAttributes.Add(new CodeAttributeDeclaration(nameof(OptionalAttribute)));
                        param.CustomAttributes.Add(new CodeAttributeDeclaration(nameof(DefaultValueAttribute), new CodeAttributeArgument(new CodeSnippetExpression(arg.Default))));
                    }
                    param.CustomAttributes.AddRange(arg.Attributes.ToArray());
                    newMethod.Parameters.Add(param);


                    var comment = "";

                    if (!string.IsNullOrWhiteSpace(arg.Description))
                    {
                        comment += arg.Description;
                    }

                    if (!string.IsNullOrWhiteSpace(arg.Default))
                    {
                        if (comment.Length != 0)
                        {
                            comment += " - ";
                        }
                        comment += "Default: " + arg.Default;
                    }
                    newMethod.Comments.Add(new CodeCommentStatement($"<param name='{arg.Name}'>{comment}</param>", true));
                }

                //TODO: Attributes
                newType.Members.Add(newMethod);
            }
            return(newType);
        }
コード例 #3
0
        protected override void VisitChild(VisitorCursor cursor, List <VisitorCursor> parents)
        {
            if (cursor.Kind == CXCursorKind.CXCursor_ClassDecl)
            {
                if (!config.NativeInterfaces.Any(i => i.Name == cursor.Spelling) || cursor.IsForwardDeclaration)
                {
                    return;
                }

                var classInfo = new IDescribeInterface
                {
                    Name = cursor.Spelling
                };


                cursor.VisitChildren((methodCursor) =>
                {
                    if (methodCursor.Kind == CXCursorKind.CXCursor_CXXMethod ||
                        methodCursor.Kind == CXCursorKind.CXCursor_Destructor ||
                        methodCursor.Kind == CXCursorKind.CXCursor_Constructor)
                    {
                        var methodName = methodCursor.Spelling;
                        if (methodCursor.Kind == CXCursorKind.CXCursor_Constructor)
                        {
                            methodName = "ctor" + methodName;
                        }
                        if (methodCursor.Kind == CXCursorKind.CXCursor_Destructor)
                        {
                            methodName = "dtor" + (methodName.Replace("~", ""));
                        }
                        if (methodCursor.IsVirtual)
                        {
                            var methodInfo = new IDescribeMethod
                            {
                                Name    = methodName,
                                Returns = { new IDescribeReturn {
                                                Type = methodCursor.ReturnTypeCSharp
                                            } }
                            };

                            for (uint index = 0; index < methodCursor.NumArgs; ++index)
                            {
                                var paramSpelling = methodCursor.GetArgSpelling(index);

                                if (string.IsNullOrEmpty(paramSpelling))
                                {
                                    paramSpelling = "param" + index;
                                }

                                var info = new IDescribeArgument
                                {
                                    Type = methodCursor.GetArgType(index),
                                    Name = paramSpelling
                                };


                                var tokens      = methodCursor.GetArgCursor(index).GetTokens();
                                var foundEquals = false;
                                for (int i = 0; i < tokens.Length - 1; i++)
                                {
                                    var token = tokens[i];
                                    if (token.Kind == CXTokenKind.CXToken_Punctuation && token.Spelling == "=")
                                    {
                                        foundEquals = true;
                                        continue;
                                    }
                                    if (foundEquals && token.Kind == CXTokenKind.CXToken_Identifier)
                                    {
                                        info.Default = ""; break;
                                    }                                                                                             //probably an enum dont support this(yet(maybe))
                                    if (foundEquals)
                                    {
                                        info.Default += token.Spelling;
                                    }
                                }


                                methodInfo.Arguments.Add(info);
                            }
                            classInfo.Methods.Add(methodInfo);
                        }
                    }

                    if (methodCursor.Kind == CXCursorKind.CXCursor_CXXBaseSpecifier)
                    {
                        var definitionSpelling = methodCursor.CursorDefinition.Spelling;
                        classInfo.Parents.Add(definitionSpelling);
                    }
                });

                this.info.Interfaces.Add(classInfo);
            }
        }