コード例 #1
0
        public void CodeGen(CodeBuilder builder)
        {
            if (Summary != null)
            {
                builder.AppendSummary(Summary);
            }

            Visibility.CodeGen(builder);

            if (ReturnType != null)
            {
                ReturnType.CodeGen(builder);
            }
            else
            {
                builder.AppendToken("void");
            }

            builder.AppendToken(Name);
            builder.ForceNoWhitespace();

            builder.AppendToken("()");
            builder.BeginBlock();

            Body.CodeGen(builder);

            builder.EndBlock();
        }
コード例 #2
0
        public void CodeGen(CodeBuilder builder)
        {
            if (Summary != null)
            {
                builder.AppendSummary(Summary);
            }

            Visibility.CodeGen(builder);

            if (CompileTimeConstant)
            {
                builder.AppendToken("const");
            }
            else
            {
                builder.AppendToken("static readonly");
            }

            Type.CodeGen(builder);

            builder.AppendToken(Name);

            builder.AppendToken("=");

            Expression.CodeGen(builder);

            builder.EndOfStatement();
        }
コード例 #3
0
    public void EmitRemoteEventArgsAndHandler(CodeBuilder b, CefCallbackFunction cb)
    {
        if (cb.IsBasicEvent)
        {
            return;
        }

        if (!ShouldEmitEventHandler(emittedRemoteHandlers, cb))
        {
            return;
        }

        b.AppendSummaryAndRemarks(cb.Comments, true, true);
        b.AppendLine("public delegate void {0}(object sender, {1} e);", cb.RemoteEventHandlerName, cb.RemoteEventArgsClassName);
        b.AppendLine();

        b.AppendSummaryAndRemarks(cb.Comments, true, true);
        b.BeginClass(cb.RemoteEventArgsClassName + " : CfrEventArgs", GeneratorConfig.ClassModifiers(cb.RemoteEventArgsClassName));
        b.AppendLine();

        b.AppendLine("private {0}RemoteEventCall call;", cb.RemoteCallName);
        b.AppendLine();

        for (var i = 1; i <= cb.Signature.ManagedParameters.Count() - 1; i++)
        {
            cb.Signature.ManagedParameters[i].EmitRemoteEventArgFields(b);
        }
        b.AppendLine();

        if (!cb.Signature.PublicReturnType.IsVoid)
        {
            b.AppendLine("internal {0} m_returnValue;", cb.Signature.PublicReturnType.RemoteSymbol);
            b.AppendLine("private bool returnValueSet;");
            b.AppendLine();
        }

        b.AppendLine("internal {0}({1}RemoteEventCall call) {{ this.call = call; }}", cb.RemoteEventArgsClassName, cb.RemoteCallName);
        b.AppendLine();

        for (var i = 1; i <= cb.Signature.ManagedParameters.Count() - 1; i++)
        {
            var arg = cb.Signature.ManagedParameters[i];
            var cd  = new CommentNode();
            if (arg.ParameterType.IsIn && arg.ParameterType.IsOut)
            {
                cd.Lines = new string[] { string.Format("Get or set the {0} parameter for the <see cref=\"{1}.{2}\"/> render process callback.", arg.PublicPropertyName, CefStruct.RemoteSymbol, cb.PublicFunctionName) };
            }
            else if (arg.ParameterType.IsIn)
            {
                cd.Lines = new string[] { string.Format("Get the {0} parameter for the <see cref=\"{1}.{2}\"/> render process callback.", arg.PublicPropertyName, CefStruct.RemoteSymbol, cb.PublicFunctionName) };
            }
            else
            {
                cd.Lines = new string[] { string.Format("Set the {0} out parameter for the <see cref=\"{1}.{2}\"/> render process callback.", arg.PublicPropertyName, CefStruct.RemoteSymbol, cb.PublicFunctionName) };
            }
            if (arg.ParameterType is CefStructArrayType && arg.ParameterType.IsIn)
            {
                cd.Lines = cd.Lines.Concat(new string[] { "Do not keep a reference to the elements of this array outside of this function." }).ToArray();
            }
            b.AppendSummary(cd);
            b.BeginBlock("public {0} {1}", arg.ParameterType.RemoteSymbol, arg.PublicPropertyName);
            if (arg.ParameterType.IsIn)
            {
                b.BeginBlock("get");
                b.AppendLine("CheckAccess();");
                arg.EmitRemoteEventArgGetterStatements(b);
                b.EndBlock();
            }
            if (arg.ParameterType.IsOut)
            {
                b.BeginBlock("set");
                b.AppendLine("CheckAccess();");
                arg.EmitRemoteEventArgSetterStatements(b);
                b.EndBlock();
            }
            b.EndBlock();
        }
        if (!cb.Signature.PublicReturnType.IsVoid)
        {
            var cd = new CommentNode();
            cd.Lines = new string[] {
                string.Format("Set the return value for the <see cref=\"{0}.{1}\"/> render process callback.", CefStruct.RemoteClassName, cb.PublicFunctionName),
                "Calling SetReturnValue() more then once per callback or from different event handlers will cause an exception to be thrown."
            };
            b.AppendSummary(cd);
            b.BeginBlock("public void SetReturnValue({0} returnValue)", cb.Signature.PublicReturnType.RemoteSymbol);
            b.BeginIf("returnValueSet");
            b.AppendLine("throw new CfxException(\"The return value has already been set\");");
            b.EndBlock();
            b.AppendLine("m_returnValue = returnValue;");
            b.AppendLine("returnValueSet = true;");
            b.EndBlock();
        }

        if (cb.Signature.ManagedParameters.Count() > 1)
        {
            b.AppendLine();
            EmitEventToString(b, cb);
        }
        b.EndBlock();
    }
コード例 #4
0
ファイル: CefEnumType.cs プロジェクト: tianqiq/ChromiumFX
    public void EmitEnum(CodeBuilder b)
    {
        var enumName = CSharp.ApplyStyle(CfxName);

        b.AppendSummaryAndRemarks(comments);

        if (Name.Contains("_flags") || additionalFlags.Contains(enumName))
        {
            b.AppendLine("[Flags()]");
        }

        var prefixBuilder = new StringBuilder();
        var allEqual      = true;

        do
        {
            char c = members[0].Name[prefixBuilder.Length];
            for (var i = 1; i <= members.Length - 1; i++)
            {
                if (c != members[i].Name[prefixBuilder.Length])
                {
                    allEqual = false;
                    break;
                }
            }
            if (allEqual)
            {
                prefixBuilder.Append(c);
            }
        } while(allEqual);

        while (prefixBuilder.Length > 0 && prefixBuilder[prefixBuilder.Length - 1] != '_')
        {
            --prefixBuilder.Length;
        }

        b.BeginBlock("public enum {0}", enumName);
        foreach (var m in members)
        {
            m.PublicName = CSharp.ApplyStyle(m.Name.Substring(prefixBuilder.Length));

            if (char.IsDigit(m.PublicName[0]))
            {
                switch (enumName)
                {
                case "CfxScaleFactor":
                    m.PublicName = "ScaleFactor" + m.PublicName;
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
            }

            b.AppendSummary(m.Comments);
            b.Append(m.PublicName);
            if (m.Value != null)
            {
                b.Append(" = {0}", GetEnumMemberValue(m.Value));
            }
            b.AppendLine(",");
        }
        b.TrimRight();
        b.CutRight(1);
        b.AppendLine();
        b.EndBlock();
    }
コード例 #5
0
    public void EmitRemoteEventArgsAndHandler(CodeBuilder b, CommentData comments)
    {
        if (IsBasicEvent)
        {
            return;
        }

        b.AppendSummaryAndRemarks(comments, true, true);
        b.AppendLine("public delegate void {0}(object sender, {1} e);", RemoteEventHandlerName, RemoteEventArgsClassName);
        b.AppendLine();

        b.AppendSummaryAndRemarks(comments, true, true);
        b.BeginClass(RemoteEventArgsClassName + " : CfrEventArgs", GeneratorConfig.ClassModifiers(RemoteEventArgsClassName));
        b.AppendLine();

        for (var i = 1; i <= Signature.ManagedArguments.Count() - 1; i++)
        {
            if (Signature.ManagedArguments[i].ArgumentType.IsIn)
            {
                b.AppendLine("bool {0}Fetched;", Signature.ManagedArguments[i].PublicPropertyName);
                b.AppendLine("{0} m_{1};", Signature.ManagedArguments[i].ArgumentType.RemoteSymbol, Signature.ManagedArguments[i].PublicPropertyName);
            }
        }
        b.AppendLine();

        if (!Signature.PublicReturnType.IsVoid)
        {
            b.AppendLine("private bool returnValueSet;");
            b.AppendLine();
        }

        b.AppendLine("internal {0}(ulong eventArgsId) : base(eventArgsId) {{}}", RemoteEventArgsClassName);
        b.AppendLine();

        for (var i = 1; i <= Signature.ManagedArguments.Count() - 1; i++)
        {
            var arg = Signature.ManagedArguments[i];
            var cd  = new CommentData();
            if (arg.ArgumentType.IsIn && arg.ArgumentType.IsOut)
            {
                cd.Lines = new string[] { string.Format("Get or set the {0} parameter for the <see cref=\"{1}.{2}\"/> render process callback.", arg.PublicPropertyName, Parent.RemoteSymbol, PublicFunctionName) };
            }
            else if (arg.ArgumentType.IsIn)
            {
                cd.Lines = new string[] { string.Format("Get the {0} parameter for the <see cref=\"{1}.{2}\"/> render process callback.", arg.PublicPropertyName, Parent.RemoteSymbol, PublicFunctionName) };
            }
            else
            {
                cd.Lines = new string[] { string.Format("Set the {0} out parameter for the <see cref=\"{1}.{2}\"/> render process callback.", arg.PublicPropertyName, Parent.RemoteSymbol, PublicFunctionName) };
            }
            b.AppendSummary(cd);
            b.BeginBlock("public {0} {1}", arg.ArgumentType.RemoteSymbol, arg.PublicPropertyName);
            if (arg.ArgumentType.IsIn)
            {
                b.BeginBlock("get");
                b.AppendLine("CheckAccess();");
                b.BeginBlock("if(!{0}Fetched)", arg.PublicPropertyName);
                b.AppendLine("{0}Fetched = true;", arg.PublicPropertyName);
                b.AppendLine("var call = new {0}Get{1}RenderProcessCall();", EventName, arg.PublicPropertyName);
                b.AppendLine("call.eventArgsId = eventArgsId;");
                b.AppendLine("call.RequestExecution(CfxRemoteCallContext.CurrentContext.connection);");
                b.AppendLine("m_{0} = {1};", arg.PublicPropertyName, arg.ArgumentType.RemoteWrapExpression("call.value"));
                b.EndBlock();
                b.AppendLine("return m_{0};", arg.PublicPropertyName);
                b.EndBlock();
            }
            if (arg.ArgumentType.IsOut)
            {
                b.BeginBlock("set");
                b.AppendLine("CheckAccess();");
                if (arg.ArgumentType.IsIn)
                {
                    b.AppendLine("m_{0} = value;", arg.PublicPropertyName);
                    b.AppendLine("{0}Fetched = true;", arg.PublicPropertyName);
                }
                b.AppendLine("var call = new {0}Set{1}RenderProcessCall();", EventName, arg.PublicPropertyName);
                b.AppendLine("call.eventArgsId = eventArgsId;");
                b.AppendLine("call.value = {0};", arg.ArgumentType.RemoteUnwrapExpression("value"));
                b.AppendLine("call.RequestExecution(CfxRemoteCallContext.CurrentContext.connection);");
                b.EndBlock();
            }
            b.EndBlock();
        }
        if (!Signature.PublicReturnType.IsVoid)
        {
            var cd = new CommentData();
            cd.Lines = new string[] {
                string.Format("Set the return value for the <see cref=\"{0}.{1}\"/> render process callback.", Parent.RemoteClassName, PublicFunctionName),
                "Calling SetReturnValue() more then once per callback or from different event handlers will cause an exception to be thrown."
            };
            b.AppendSummary(cd);
            b.BeginBlock("public void SetReturnValue({0} returnValue)", Signature.PublicReturnType.RemoteSymbol);
            b.BeginIf("returnValueSet");
            b.AppendLine("throw new CfxException(\"The return value has already been set\");");
            b.EndBlock();
            b.AppendLine("var call = new {0}SetReturnValueRenderProcessCall();", EventName);
            b.AppendLine("call.eventArgsId = eventArgsId;");
            b.AppendLine("call.value = {0};", Signature.PublicReturnType.RemoteUnwrapExpression("returnValue"));
            b.AppendLine("call.RequestExecution(CfxRemoteCallContext.CurrentContext.connection);");
            b.AppendLine("returnValueSet = true;");
            b.EndBlock();
        }

        if (Signature.ManagedArguments.Count() > 1)
        {
            b.AppendLine();
            EmitEventToString(b);
        }
        b.EndBlock();
    }
コード例 #6
0
    public void EmitPublicEventArgsAndHandler(CodeBuilder b, CommentData comments)
    {
        if (emittedHandlers.ContainsKey(EventName))
        {
            var c0 = emittedHandlers[EventName];
            if (c0 != null)
            {
                if (c0.Lines.Length != comments.Lines.Length)
                {
                    System.Diagnostics.Debugger.Break();
                }
                for (var i = 0; i <= c0.Lines.Length - 1; i++)
                {
                    if (c0.Lines[i] != comments.Lines[i])
                    {
                        // two handlers use same event but with different comments
                        System.Diagnostics.Debugger.Break();
                    }
                }
            }
            return;
        }
        emittedHandlers.Add(EventName, comments);

        if (IsBasicEvent)
        {
            return;
        }

        b.AppendSummaryAndRemarks(comments, false, true);
        b.AppendLine("public delegate void {0}(object sender, {1} e);", EventHandlerName, PublicEventArgsClassName);
        b.AppendLine();

        b.AppendSummaryAndRemarks(comments, false, true);
        b.BeginClass(PublicEventArgsClassName + " : CfxEventArgs", GeneratorConfig.ClassModifiers(PublicEventArgsClassName));
        b.AppendLine();

        for (var i = 1; i <= Signature.ManagedArguments.Count() - 1; i++)
        {
            Signature.ManagedArguments[i].EmitPublicEventArgFields(b);
        }
        b.AppendLine();

        if (!Signature.PublicReturnType.IsVoid)
        {
            b.AppendLine("internal {0} m_returnValue;", Signature.PublicReturnType.PublicSymbol);
            b.AppendLine("private bool returnValueSet;");
            b.AppendLine();
        }

        b.BeginBlock("internal {0}({1})", PublicEventArgsClassName, Signature.PublicEventConstructorArgumentList);
        Signature.EmitPublicEventCtorStatements(b);
        b.EndBlock();
        b.AppendLine();

        for (var i = 1; i <= Signature.ManagedArguments.Count() - 1; i++)
        {
            var arg = Signature.ManagedArguments[i];
            var cd  = new CommentData();
            if (arg.ArgumentType.IsIn && arg.ArgumentType.IsOut)
            {
                cd.Lines = new string[] { string.Format("Get or set the {0} parameter for the <see cref=\"{1}.{2}\"/> callback.", arg.PublicPropertyName, Parent.ClassName, PublicName) };
            }
            else if (arg.ArgumentType.IsIn)
            {
                cd.Lines = new string[] { string.Format("Get the {0} parameter for the <see cref=\"{1}.{2}\"/> callback.", arg.PublicPropertyName, Parent.ClassName, PublicName) };
            }
            else
            {
                cd.Lines = new string[] { string.Format("Set the {0} out parameter for the <see cref=\"{1}.{2}\"/> callback.", arg.PublicPropertyName, Parent.ClassName, PublicName) };
            }
            if (arg.ArgumentType is CefStructArrayType && arg.ArgumentType.IsIn)
            {
                cd.Lines = cd.Lines.Concat(new string[] { "Do not keep a reference to the elements of this array outside of this function." }).ToArray();
            }
            b.AppendSummary(cd);
            b.BeginBlock("public {0} {1}", arg.ArgumentType.PublicSymbol, arg.PublicPropertyName);
            if (arg.ArgumentType.IsIn)
            {
                b.BeginBlock("get");
                b.AppendLine("CheckAccess();");
                arg.EmitPublicEventArgGetterStatements(b);
                b.EndBlock();
            }
            if (arg.ArgumentType.IsOut)
            {
                b.BeginBlock("set");
                b.AppendLine("CheckAccess();");
                arg.EmitPublicEventArgSetterStatements(b);
                b.EndBlock();
            }
            b.EndBlock();
        }

        if (!Signature.PublicReturnType.IsVoid)
        {
            var cd = new CommentData();
            cd.Lines = new string[] {
                string.Format("Set the return value for the <see cref=\"{0}.{1}\"/> callback.", Parent.ClassName, PublicFunctionName),
                "Calling SetReturnValue() more then once per callback or from different event handlers will cause an exception to be thrown."
            };
            b.AppendSummary(cd);
            b.BeginBlock("public void SetReturnValue({0} returnValue)", Signature.PublicReturnType.PublicSymbol);
            b.AppendLine("CheckAccess();");
            b.BeginIf("returnValueSet");
            b.AppendLine("throw new CfxException(\"The return value has already been set\");");
            b.EndBlock();
            b.AppendLine("returnValueSet = true;");
            b.AppendLine("this.m_returnValue = returnValue;");
            b.EndBlock();
        }

        if (Signature.ManagedArguments.Count() > 1)
        {
            b.AppendLine();
            EmitEventToString(b);
        }
        b.EndBlock();
    }