コード例 #1
0
        private string GetNativeCallMehtodBody(CodeMethod caller, CodeField field, CodeType typeDecl)
        {
            var sb = new StringBuilder();

            sb.Append("fixed (").Append(typeDecl.Name).Append("* self = &this)\n{\n\t");
            if (caller.RetVal.Type != "void")
            {
                sb.Append("return ");
            }

            var argTypes = new List <string>();

            if (caller.HasThisArg)
            {
                argTypes.Add(typeDecl.Name + "*");
            }
            argTypes.AddRange(caller.Parameters.Select(arg => CSharpCodeGen.GetClrTypeName(arg.Type)));
            argTypes.Add(CSharpCodeGen.GetClrTypeName(caller.RetVal.Type));

            sb.Append("((delegate* unmanaged[Stdcall]<").Append(string.Join(", ", argTypes)).Append(">)");
            sb.Append(field.Name).Append(")(");
            var args = new List <string>();

            if (caller.HasThisArg)
            {
                args.Add("self");
            }
            args.AddRange(caller.Parameters.Select(arg => arg.Name));
            sb.Append(string.Join(", ", args));
            sb.Append(");");
            sb.Append("\n}");

            return(sb.ToString());
        }
コード例 #2
0
ファイル: CefApiBuilderBase.cs プロジェクト: wuzlai521/CefNet
        public void Format(CppClass @class, TextWriter langStream, TextWriter msilStream)
        {
            var codefile = CreateCodeFile(this.Namespace, @class);

            var sb = new StringBuilder();

            using (var w = new StringWriter(sb))
            {
                var codeGen = new CSharpCodeGen();
                codeGen.Directives.Add("#pragma warning disable 0169, 1591, 1573");
                codeGen.GenerateCode(codefile, w);
                w.Flush();
            }
            langStream.WriteLine(sb.ToString());

            //sb.Clear();

            //using (var w = new StringWriter(sb))
            //{
            //	var codeGen = CreateMsilCodeGen();
            //	codeGen.ResolveTypeName += CodeGen_ResolveTypeName;
            //	codeGen.GenerateCode(codefile, w);
            //	codeGen.ResolveTypeName -= CodeGen_ResolveTypeName;

            //	w.Flush();
            //}
            //msilStream.WriteLine(sb.ToString());
        }
コード例 #3
0
ファイル: CefApiBuilderBase.cs プロジェクト: wuzlai521/CefNet
        public void Format(CppTypeDeclaration typeDecl, TextWriter stream)
        {
            var codefile = CreateCodeFile(this.Namespace, typeDecl);

            var sb = new StringBuilder();

            using (var w = new StringWriter(sb))
            {
                var codeGen = new CSharpCodeGen();
                codeGen.Directives.Add("#pragma warning disable 0169, 1591, 1573");
                codeGen.GenerateCode(codefile, w);
                w.Flush();
            }
            stream.WriteLine(sb.ToString());
        }
コード例 #4
0
        private string GetNativeDelegate(CodeMethod caller, CodeType typeDecl)
        {
            var sb = new StringBuilder();

            sb.Append("delegate* unmanaged[Stdcall]<");
            var args = new List <string>();

            if (caller.HasThisArg)
            {
                args.Add(typeDecl.Name + "*");
            }
            args.AddRange(caller.Parameters.Select(arg => CSharpCodeGen.GetClrTypeName(arg.Type)));
            args.Add(CSharpCodeGen.GetClrTypeName(caller.RetVal.Type));
            sb.Append(string.Join(", ", args));
            sb.Append(">");
            return(sb.ToString());
        }