コード例 #1
0
        public void ProcessCode()
        {
            TranslationUnitPasses.RunPasses(pass =>
            {
                Diagnostics.Debug("Pass '{0}'", pass);

                Diagnostics.PushIndent(4);
                pass.VisitLibrary(ASTContext);
                Diagnostics.PopIndent();
            });
            Generator.Process();
        }
コード例 #2
0
        public override bool VisitClassDecl(Class @class)
        {
            // FIXME: Add a better way to hook the event
            if (!isHooked)
            {
                Generator.OnUnitGenerated += OnUnitGenerated;
                isHooked = true;
            }

            if (!VisitDeclaration(@class))
            {
                return(false);
            }

            // We can't handle value types yet
            // The generated code assumes that a NativePtr is available
            if (@class.IsValueType)
            {
                return(false);
            }

            foreach (var method in @class.Methods)
            {
                if (!IsInsertionOperator(method))
                {
                    continue;
                }

                // Create the ToString method
                var stringType = GetType("std::string");
                if (stringType == null)
                {
                    stringType = new CILType(typeof(string));
                }
                var toStringMethod = new Method()
                {
                    Name       = "ToString",
                    Namespace  = @class,
                    ReturnType = new QualifiedType(stringType),
                    SynthKind  = FunctionSynthKind.ComplementOperator,
                    IsOverride = true,
                    IsProxy    = true
                };

                @class.Methods.Add(toStringMethod);

                Diagnostics.Debug("Function converted to ToString: {0}::{1}",
                                  @class.Name, method.Name);

                break;
            }

            var methodEqualsParam = new Parameter
            {
                Name          = "object",
                QualifiedType = new QualifiedType(new CILType(typeof(Object))),
            };

            var methodEquals = new Method
            {
                Name       = "Equals",
                Namespace  = @class,
                ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Bool)),
                Parameters = new List <Parameter> {
                    methodEqualsParam
                },
                SynthKind  = FunctionSynthKind.ComplementOperator,
                IsOverride = true,
                IsProxy    = true
            };

            @class.Methods.Add(methodEquals);

            var methodHashCode = new Method
            {
                Name       = "GetHashCode",
                Namespace  = @class,
                ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Int)),
                SynthKind  = FunctionSynthKind.ComplementOperator,
                IsOverride = true,
                IsProxy    = true
            };

            @class.Methods.Add(methodHashCode);
            return(true);
        }