예제 #1
0
        public Dictionary <AST.Type, string> GenerateLocalTranslations(AST.Object type)
        {
            var localTranslations = CppRender.GetLocalTranslations(type);

            UseLocalTranslations = false;
            foreach (var kvp in localTranslations)
            {
                Line("using {0} = {1};", kvp.Value, TypeRef(kvp.Key, false));
            }
            UseLocalTranslations = true;

            return(localTranslations);
        }
예제 #2
0
        public void GenerateWrapperImplementation(AST.Object type)
        {
            var localTranslations = CppRender.GetLocalTranslations(type);

            LocalTranslationsBlock(localTranslations, () =>
            {
                foreach (var ctor in type.Constructors.Where(c => c.Access == AST.Access.Public))
                {
                    WrapperConstructorImplementation(ctor, type);
                }

                Spacer();

                foreach (var member in type.Members.OrderBy(m => m.ConstructType))
                {
                    switch (member)
                    {
                    case AST.Constructor ctor:
                        break;

                    case AST.Property prop:
                        MethodImplementation(prop.CreateGetter().AsConst(), type);

                        if (!prop.IsReadOnly)
                        {
                            MethodImplementation(prop.CreateSetter().AsConst(), type);
                        }
                        break;

                    case AST.Event ev:
                        MethodImplementation(ev.CreateAdder().AsConst(), type);
                        MethodImplementation(ev.CreateRemover().AsConst(), type);
                        break;

                    case AST.Method method:
                        MethodImplementation(method.AsConst(), type);
                        break;

                    default:
                        throw new Exception("Oops, unhandled member type: " + member.ConstructType.ToString());
                    }
                }
            });
        }
예제 #3
0
        public void GenerateStruct(AST.Struct type, bool abi)
        {
            var  strata = Strata;
            Guid id     = (strata == ApiStrata.ABI ? type.Id : type.PrivateId);

            Namespace(type.Namespace, abi, () =>
            {
                var localTranslations = CppRender.GetLocalTranslations(type);

                if (strata == ApiStrata.ABI)
                {
                    localTranslations = null;
                }

                var fields = type.Fields;

                Spacer();

                WriteXmlDocumentation(type.XmlDoc);
                Line("struct comid(\"{0}\") {1}", id, type.Name);
                Block(() =>
                {
                    if (strata == ApiStrata.Normal && CppRender.RequiresABITranslation(type.ToVariable()))
                    {
                        Line("typedef {0} ABIType;", TypeRef(type, true));
                        Spacer();
                    }

                    if (localTranslations != null)
                    {
                        UseLocalTranslations = false;
                        foreach (var kvp in localTranslations)
                        {
                            Line("using {0} = {1};", kvp.Value, TypeRef(kvp.Key, false));
                        }
                        UseLocalTranslations = true;
                        Spacer();
                    }

                    LocalTranslationsBlock(localTranslations, () =>
                    {
                        foreach (var field in fields)
                        {
                            WriteXmlDocumentation(field.XmlDoc);
                            Line("{0} {1};", VariableType(field, AST.VariableContext.Member), field.Name);
                        }

                        Spacer();

                        // Default constructor
                        Line("{0}() {{ }}", type.Name);

                        // Full constructor
                        var constructorArgs = fields.Select(f => f.Morph("_" + f.Name, AST.VariableContext.In));
                        if (strata == ApiStrata.ABI)
                        {
                            constructorArgs = constructorArgs.GetABIParametersCpp();
                        }

                        Line("{0}({1}) : ", type.Name, DeclParameters(constructorArgs));
                        Indent++;
                        List(() =>
                        {
                            foreach (var field in fields)
                            {
                                if (strata == ApiStrata.ABI && field.IsArray)
                                {
                                    ListItem("{0}(_{0}, _{0}_count)", field.Name);
                                }
                                else if (strata == ApiStrata.ABI && field.Type.IsDelegate)
                                {
                                    ListItem("{0}(_{0}, _{0}_context)", field.Name);
                                }
                                else
                                {
                                    ListItem("{0}(_{0})", field.Name);
                                }
                            }
                        });
                        Indent--;
                        Line();
                        Line("{ }");
                    });
                }, ";");
            });

            var prefix = (abi ? "::ABI" : "");

            if (type.Namespace.IsGlobal)
            {
                Line(@"IS_VALUETYPE({0}::{1}, ""{2}"");", prefix, type.Name, id);
            }
            else
            {
                Line(@"IS_VALUETYPE({0}::{1}::{2}, ""{3}"");", prefix, type.Namespace.FullName("::"), type.Name, id);
            }
        }