Exemple #1
0
        public override void VisitDeclContextFunctions(DeclarationContext context)
        {
            var functions = context.Functions.Where(f => !ASTUtils.CheckIgnoreFunction(f)).ToList();
            var unique    = functions.GroupBy(m => m.Name);

            foreach (var group in unique)
            {
                GenerateFunctionGroup(group.ToList());
            }
        }
Exemple #2
0
        public override bool VisitFunctionDecl(Function decl)
        {
            if (!VisitDeclaration(decl))
            {
                return(false);
            }

            if (ASTUtils.CheckIgnoreFunction(decl))
            {
                return(false);
            }

            CheckDuplicate(decl);
            return(false);
        }
Exemple #3
0
        public override bool VisitFunctionDecl(Function decl)
        {
            if (!VisitDeclaration(decl))
            {
                return(false);
            }

            if (ASTUtils.CheckIgnoreFunction(decl, Options))
            {
                return(false);
            }

            if (!decl.TranslationUnit.FileName.StartsWith("Chakra"))
            {
                return(false);
            }

            //Skip TTD functions for now.
            if (decl.Name.StartsWith("JsTTD"))
            {
                return(false);
            }

            var exportElement = new XElement("Export");

            exportElement.SetAttributeValue("name", decl.Name);
            exportElement.SetAttributeValue("target", "Common");
            exportElement.SetAttributeValue("source", decl.TranslationUnit.FileName);

            //Manual attribute defs
            if (decl.Name == "JsCreateStringUtf16")
            {
                exportElement.SetAttributeValue("dllImportEx", ", CharSet = CharSet.Unicode");
            }
            else if (decl.Name == "JsCopyString")
            {
                exportElement.SetAttributeValue("dllImportEx", ", CharSet = CharSet.Ansi");
            }

            //Normalize Comments.
            var commentBuilder = new StringBuilder();

            foreach (Match match in m_rx.Matches(decl.Comment.Text))
            {
                var text = match.Groups["text"].Value;
                text = text.Replace("< 0", "&lt; 0");
                commentBuilder.Append("///" + text + "\r\n");
            }

            var descriptionElement = new XElement("Description");

            descriptionElement.Add(new XText("\r\n      "));
            descriptionElement.Add(new XCData("\r\n" + commentBuilder.ToString()));
            descriptionElement.Add(new XText("\r\n    "));
            exportElement.Add(descriptionElement);

            //Output and map parameters
            var parametersElement = new XElement("Parameters");

            foreach (var param in decl.Parameters)
            {
                var parameterElement = new XElement("Parameter");

                var typeDef = param.Type as TypedefType;
                var pointer = param.Type as PointerType;

                string mappedType;
                if (typeDef != null)
                {
                    mappedType = MapParameterType(decl, param, typeDef.Declaration.QualifiedName);
                }
                else if (pointer != null)
                {
                    if (pointer.Pointee is TypedefType pointerTypeDef)
                    {
                        mappedType = MapParameterType(decl, param, pointerTypeDef.Declaration.ToString());
                    }
                    else
                    {
                        //Fallback to the original qualified type.
                        mappedType = MapParameterType(decl, param, param.QualifiedType.ToString());
                    }
                }
                else
                {
                    mappedType = MapParameterType(decl, param, param.QualifiedType.ToString());
                }

                parameterElement.SetAttributeValue("type", mappedType);

                if (param.Name == "ref" || param.Name == "object")
                {
                    parameterElement.SetAttributeValue("name", "@" + param.Name);
                }
                else
                {
                    parameterElement.SetAttributeValue("name", param.Name);
                }

                if (param.IsOut || param.IsInOut)
                {
                    parameterElement.SetAttributeValue("direction", "Out");
                }

                parametersElement.Add(parameterElement);
            }

            if (parametersElement.HasElements)
            {
                exportElement.Add(parametersElement);
            }

            //Add breaks between Exports from different sources.
            if (m_root.Elements().Where(e => e.Attribute("source").Value == exportElement.Attribute("source").Value).Count() == 0)
            {
                m_root.Add(new XComment("\r\n  ***************************************\r\n  **\r\n  ** " + exportElement.Attribute("source").Value + "\r\n  **\r\n  ***************************************\r\n  "));
            }

            m_root.Add(exportElement);
            return(false);
        }