Exemplo n.º 1
0
        private void DefineFunction(CodeType typeDecl, CppFunction func)
        {
            if (func.Name == "ArraySizeHelper")
            {
                return;
            }

            if (func.LinkageKind != CppLinkageKind.External)
            {
                throw new NotImplementedException();
            }

            TypeDesc retType = GetTypeDesc(func.ReturnType);
            var      fn      = new CodeMethod(func.Name);

            fn.RetVal = new CodeMethodParameter(null)
            {
                Type = ResolveCefType(retType.ToString())
            };
            fn.Attributes = CodeAttributes.Public | CodeAttributes.External | CodeAttributes.Unsafe | CodeAttributes.Static;
            if (func.CallingConvention == CppCallingConvention.C)
            {
                fn.CustomAttributes.AddDllImportfAttribute(CallingConvention.Cdecl);
            }
            else if (func.CallingConvention == CppCallingConvention.X86StdCall)
            {
                fn.CustomAttributes.AddDllImportfAttribute(CallingConvention.StdCall);
            }
            else
            {
                throw new NotImplementedException();
            }

            string filename = func.Span.Start.File;

            filename = Path.GetRelativePath(BaseDirectory, filename).Replace('\\', '/');
            fn.Comments.AddVSDocComment(func.Comment, "summary");
            fn.Comments.AddVSDocComment(string.Format("Defined in {0} as\n{1}", filename, func.ToString()), "remarks");

            CppContainerList <CppParameter> @params = func.Parameters;

            for (int i = 0; i < @params.Count; i++)
            {
                CppParameter arg = @params[i];

                var      param     = new CodeMethodParameter(arg.Name.EscapeName());
                TypeDesc paramType = GetTypeDesc(arg.Type);

                string argType = paramType.ToString();
                while (argType.StartsWith("const "))
                {
                    argType         = argType.Substring(6);
                    param.Direction = CodeMethodParameterDirection.In;
                }

                param.Type = ResolveCefType(argType);
                fn.Parameters.Add(param);
            }

            typeDecl.Members.Add(fn);
        }