コード例 #1
0
        private static void CompareFuncs(CppContainerList <CppFunction> functions1, CppContainerList <CppFunction> functions2)
        {
            WriteLine(Environment.NewLine);

            ForegroundColor = ConsoleColor.Yellow;

            //TODO: Add deprecated option.
            var f1 = functions1.Except(functions1.Where(f => f.Span.Start.File.Contains("deprecated")));

            var f2 = functions2.Except(functions2.Where(f => f.Span.Start.File.Contains("deprecated")));

            if (f1.Count() != f2.Count())
            {
                System.Diagnostics.Debug.WriteLine($"function count is different. v1 has {f1.Count()}, v2 has {f2.Count()}");
            }

            foreach (var function in f1.Where(f1 => !f2.Any(f2 => f2.Name == f1.Name)))
            {
                // functions in v1, not in v2
                System.Diagnostics.Debug.WriteLine($"function {function.Name} was removed from libvlc 4");
            }

            ForegroundColor = ConsoleColor.Green;

            foreach (var function in f2.Where(f2 => !f1.Any(f1 => f1.Name == f2.Name)))
            {
                // functions in v2, not in v1
                System.Diagnostics.Debug.WriteLine($"function {function.Name} was added in libvlc 4");
            }
            // functions in v2, not in v1

            // for same functions, check return parameter, parameter count, parameter order, parameter type, parameter name, comment.
        }
コード例 #2
0
ファイル: VS16_8_FIX.cs プロジェクト: wuzlai521/CefNet
 static partial void FixSTL1300RemoveIncludesAfterParse(CppContainerList <CppFunction> functions)
 {
     for (int i = functions.Count - 1; i >= 0; i--)
     {
         if (Path.GetFileName(functions[i].SourceFile) == "intrin0.h")
         {
             functions.RemoveAt(i);
         }
     }
 }
コード例 #3
0
        private static void CompareStructFields(string structName, CppContainerList <CppField> fields1,
                                                CppContainerList <CppField> fields2)
        {
            if (fields1.Count == 0 && fields2.Count == 0)
            {
                return;
            }

            if (fields1.Count != fields2.Count)
            {
                ForegroundColor = ConsoleColor.Red;
                WriteLine($"{structName} {nameof(fields1)} count is {fields1.Count} in libvlc 3");
                WriteLine($"{structName} {nameof(fields1)} count is {fields2.Count} in libvlc 4");
            }

            foreach (var field in fields1.Where(f1 => !fields2.Any(f2 => f2.Name == f1.Name)))
            {
                WriteLine($"field {field.Name} is missing from v2");
                // item missing in v2
            }

            var union1 = fields1.FirstOrDefault(f1 => f1.Name == "u");
            var union2 = fields2.FirstOrDefault(f2 => f2.Name == "u");

            if (union1 != null && union2 != null)
            {
                CompareEventsUnion(union1, union2);
            }

            foreach (var field in fields2.Where(f2 => !fields1.Any(f1 => f1.Name == f2.Name)))
            {
                // item missing in v1
                WriteLine($"field {field.Name} is missing from v1");
            }

            //fields1.Where(s => s.Name)
            // type, name, visibility, comment
            //for (var i = 0; i < fields1.Count; i++)
            //{
            //    var f1 = fields1[i];
            //    var f2 = fields2[i];
            ////    if(f1.Type == )
            //    if (f1.Type.GetDisplayName() != f2.Type.GetDisplayName())
            //        WriteLine($"{nameof(f1.Type)} {f1.Type.GetDisplayName()} is different than {f2.Type.GetDisplayName()}");
            //    if(f1.Name != f2.Name)
            //        WriteLine($"{nameof(f1.Name)} {f1.Name} is different than {f2.Name}");
            //    if(f1.Visibility != f2.Visibility)
            //        WriteLine($"{nameof(f1.Visibility)} {f1.Visibility} is different than {f2.Visibility}");
            //    if(f1.Comment?.ChildrenToString() != f2.Comment?.ChildrenToString())
            //        WriteLine($"{nameof(f1.Comment)} {f1.Comment?.ChildrenToString()} is different than {f2.Comment?.ChildrenToString()}");
            //}
        }
コード例 #4
0
        public TypedefMap(CppContainerList <CppTypedef> types)
        {
            foreach (var t in types)
            {
                Add(t.ElementType.GetDisplayName(), t.Name);
                Add(t.Name, t.ElementType.GetDisplayName());

                if (t.IsPrimitiveType())
                {
                    V.AddTypeConversion(t.Name, t.ElementTypeAsPrimitive().GetVType());
                }
            }
        }
コード例 #5
0
        private void DefineField(CodeType typeDecl, CppField field)
        {
            CodeMethod caller = null;

            TypeDesc fieldType = GetTypeDesc(field.Type);
            var      fld       = new CodeField(ResolveCefType(fieldType.ToString()), field.Name.EscapeName());

            if (fieldType.IsCallable)
            {
                fld.Attributes = CodeAttributes.Public;                // | CodeAttributes.ReadOnly;
                fld.Comments.AddVSDocComment(fieldType.Name, "summary");

                CppFunctionType fnType  = fieldType.FunctionTypeRef;
                TypeDesc        retType = GetTypeDesc(fnType.ReturnType);
                caller = new CodeMethod(field.Name.ToUpperCamel(fnType.Parameters.Count).EscapeName());
                var rvtype = new CodeMethodParameter(null);
                rvtype.Type = ResolveCefType(retType.ToString());
                if (retType.Name == "char16" || retType.Name == "wchar")
                {
                    rvtype.CustomAttributes.Add(new CustomCodeAttribute("return: MarshalAs(UnmanagedType.U2)"));
                    throw new NotImplementedException();                     // TODO: check it
                }
                caller.RetVal     = rvtype;
                caller.Attributes = CodeAttributes.Public | CodeAttributes.Unsafe;
                //caller.CustomAttributes.AddMethodImplForwardRefAttribute();
                caller.CustomAttributes.Add(new CustomCodeAttribute("NativeName")
                {
                    Parameters = { "\"" + field.Name + "\"" }
                });
                caller.Comments.AddVSDocComment(field.Comment, "summary");
                caller.Callee = fld;
                CppContainerList <CppParameter> @params = fnType.Parameters;
                for (int i = 0; i < @params.Count; i++)
                {
                    CppParameter arg = @params[i];
                    if (i == 0 && arg.Name == "self")
                    {
                        string argTypeName = ResolveCefType(arg.Type.GetDisplayName());
                        if (argTypeName == typeDecl.Name + "*")
                        {
                            caller.HasThisArg = true;
                            continue;
                        }
                    }
                    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;
                    }
                    if (param.Direction == CodeMethodParameterDirection.In)
                    {
                        param.CustomAttributes.Add(new CustomCodeAttribute("Immutable"));
                    }
                    if (argType == "char16" || argType == "wchar")
                    {
                        param.CustomAttributes.Add(new CustomCodeAttribute("MarshalAs(UnmanagedType.U2)"));
                        throw new NotImplementedException();                         // TODO: check it
                    }
                    param.Type = ResolveCefType(argType);
                    caller.Parameters.Add(param);
                }

                //fld.TypeName = GetNativeDelegate(caller, typeDecl);
                caller.Body = GetNativeCallMehtodBody(caller, fld, typeDecl);
            }
            else
            {
                fld.Comments.AddVSDocComment(field.Comment, "summary");
                fld.Attributes = CodeAttributes.Public;
                if (fieldType.Name == "char16" || fieldType.Name == "wchar")
                {
                    fld.CustomAttributes.Add(new CustomCodeAttribute("MarshalAs(UnmanagedType.U2)"));
                }
            }
            typeDecl.Members.Add(fld);
            if (caller != null)
            {
                typeDecl.Members.Add(caller);
            }
        }
コード例 #6
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);
        }
コード例 #7
0
 static partial void FixSTL1300RemoveIncludesAfterParse(CppContainerList <CppFunction> functions);
コード例 #8
0
        private static void CompareStructs(CppContainerList <CppClass> structsv3, CppContainerList <CppClass> structsv4)
        {
            WriteLine($"LibVLC 3 has {structsv3.Count} structs");
            WriteLine($"LibVLC 4 has {structsv4.Count} structs");

            List <CppClass>   v3structMissingFromv4 = new List <CppClass>();
            List <CppClass>   v4structMissingFromv3 = new List <CppClass>();
            List <StructDiff> structDiffs           = new List <StructDiff>();

            foreach (var s in structsv3)
            {
                var match = structsv4.FirstOrDefault(ss => ss.Name == s.Name);
                if (match == null)
                {
                    v3structMissingFromv4.Add(s);
                    continue;
                }

                if (match.SizeOf != s.SizeOf)
                {
                    ForegroundColor = ConsoleColor.Red;
                    WriteLine($"{match.Name} size is {s.SizeOf} in libvlc 3 and {match.SizeOf} in libvlc 4");
                }

                CompareStructFields(s.Name, s.Fields, match.Fields);
                //var diff = !match.Comment?.ChildrenToString()?.Equals(s.Comment?.ChildrenToString());
                //if (diff.HasValue && !diff.Value && (match.Comment != null && s.Comment != null)) continue;

                structDiffs.Add(new StructDiff
                {
                    Name      = s.Name,
                    Commentv3 = s.Comment?.ChildrenToString(),
                    Commentv4 = match.Comment?.ChildrenToString()
                });
            }

            foreach (var s in structsv4)
            {
                var match = structsv3.FirstOrDefault(ss => ss.Name == s.Name);
                if (match == null)
                {
                    ForegroundColor = ConsoleColor.Red;
                    v4structMissingFromv3.Add(s);
                    continue;
                }

                if (match.Comment == null && s.Comment == null)
                {
                    continue;
                }
                if (match.Comment == null || s.Comment == null)
                {
                    ForegroundColor = ConsoleColor.Red;
                    WriteLine($"Comment changed for {s.Name}");
                    if (match.Comment == null)
                    {
                        WriteLine($"{match.Name} has no more documentation");
                    }
                    else
                    {
                        WriteLine($"{s.Name} has no more documentation");
                    }
                    continue;
                }
                if (!match.Comment.ChildrenToString().Equals(s.Comment.ChildrenToString()))
                {
                    ForegroundColor = ConsoleColor.Red;
                    WriteLine($"Comment changed for {s.Name}");
                    WriteLine($"LibVLC 4: {s.Comment.ChildrenToString()}");
                    WriteLine($"LibVLC 3: {match.Comment.ChildrenToString()}");
                }
            }
        }