예제 #1
0
        public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
        {
            if (!VisitType(pointer, quals))
            {
                return(false);
            }

            var pointee = pointer.Pointee.Desugar();

            if (pointee is FunctionType)
            {
                var cppTypePrinter = new CppTypePrinter(Context.Context);
                cppTypePrinter.PushContext(TypePrinterContextKind.Managed);
                var cppTypeName = pointer.Visit(cppTypePrinter, quals);

                return(VisitDelegateType(cppTypeName));
            }

            Enumeration @enum;

            if (pointee.TryGetEnum(out @enum))
            {
                var isRef = Context.Parameter.Usage == ParameterUsage.Out ||
                            Context.Parameter.Usage == ParameterUsage.InOut;

                Context.ArgumentPrefix.Write("&");
                Context.Return.Write($"(::{@enum.QualifiedOriginalName}){0}{Context.Parameter.Name}",
                                     isRef ? string.Empty : "*");
                return(true);
            }

            Class @class;

            if (pointee.TryGetClass(out @class) && @class.IsValueType)
            {
                if (Context.Function == null)
                {
                    Context.Return.Write("&");
                }
                return(pointer.QualifiedPointee.Visit(this));
            }

            var finalPointee = pointer.GetFinalPointee();

            if (finalPointee.IsPrimitiveType())
            {
                var cppTypePrinter = new CppTypePrinter(Context.Context);
                var cppTypeName    = pointer.Visit(cppTypePrinter, quals);

                Context.Return.Write($"({cppTypeName})");
                Context.Return.Write(Context.Parameter.Name);
                return(true);
            }

            return(pointer.QualifiedPointee.Visit(this));
        }
예제 #2
0
        public override bool VisitEnumDecl(Enumeration @enum)
        {
            var typePrinter = new CppTypePrinter(Context.Context);

            typePrinter.PushContext(TypePrinterContextKind.Managed);
            var typeName = typePrinter.VisitDeclaration(@enum);

            Context.Return.Write($"({typeName}){Context.ReturnVarName}");

            return(true);
        }
예제 #3
0
        public SymbolsCodeGenerator(BindingContext context, IEnumerable <TranslationUnit> units)
            : base(context, units)
        {
            cppTypePrinter = new CppTypePrinter(Context)
            {
                ScopeKind       = TypePrintScopeKind.Qualified,
                ResolveTypedefs = true
            };

            cppTypePrinter.PushContext(TypePrinterContextKind.Native);
        }
예제 #4
0
        public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
        {
            var decl = typedef.Declaration;

            TypeMap typeMap;

            if (Context.Context.TypeMaps.FindTypeMap(decl.Type, out typeMap) &&
                typeMap.DoesMarshalling)
            {
                typeMap.CppMarshalToNative(Context);
                return(typeMap.IsValueType);
            }

            FunctionType func;

            if (decl.Type.IsPointerTo(out func))
            {
                var typePrinter = new CppTypePrinter(Context.Context);
                typePrinter.PushContext(TypePrinterContextKind.Native);
                var declName = decl.Visit(typePrinter);
                typePrinter.PopContext();

                // Use the original typedef name if available, otherwise just use the function pointer type
                string cppTypeName;
                if (!decl.IsSynthetized)
                {
                    cppTypeName = "::" + typedef.Declaration.QualifiedOriginalName;
                }
                else
                {
                    cppTypeName = decl.Type.Visit(typePrinter, quals);
                }

                VisitDelegateType(cppTypeName);
                return(true);
            }

            PrimitiveType primitive;

            if (decl.Type.IsPrimitiveType(out primitive))
            {
                Context.Return.Write($"(::{typedef.Declaration.QualifiedOriginalName})");
            }

            return(decl.Type.Visit(this));
        }
예제 #5
0
        private static void DisableSingleTypeMap(Class mapped, BindingContext context)
        {
            var names = new List <string> {
                mapped.OriginalName
            };

            foreach (TypePrintScopeKind kind in Enum.GetValues(typeof(TypePrintScopeKind)))
            {
                var cppTypePrinter = new CppTypePrinter(context);
                cppTypePrinter.PushContext(TypePrinterContextKind.Native);
                cppTypePrinter.PushScope(kind);
                names.Add(mapped.Visit(cppTypePrinter));
            }
            foreach (var name in names.Where(context.TypeMaps.TypeMaps.ContainsKey))
            {
                context.TypeMaps.TypeMaps[name].IsEnabled = false;
            }
        }
예제 #6
0
        public override void GenerateClassEvents(Class @class)
        {
            foreach (var @event in @class.Events)
            {
                if ([email protected])
                {
                    continue;
                }

                var cppTypePrinter = new CppTypePrinter(Context);
                cppTypePrinter.PushContext(TypePrinterContextKind.Native);
                var cppArgs = cppTypePrinter.VisitParameters(@event.Parameters, hasNames: true);

                WriteLine("private:");
                Indent();

                var delegateName = string.Format("_{0}Delegate", @event.Name);
                WriteLine("delegate void {0}({1});", delegateName, cppArgs);
                WriteLine("{0}^ {0}Instance;", delegateName);

                WriteLine("void _{0}Raise({1});", @event.Name, cppArgs);
                WriteLine("{0} _{1};", @event.Type, @event.Name);

                Unindent();
                WriteLine("public:");
                Indent();

                WriteLine("event {0} {1}", @event.Type, @event.Name);
                WriteOpenBraceAndIndent();

                WriteLine("void add({0} evt);", @event.Type);
                WriteLine("void remove({0} evt);", @event.Type);

                var cliTypePrinter = new CLITypePrinter(Context);
                var cliArgs        = cliTypePrinter.VisitParameters(@event.Parameters, hasNames: true);

                WriteLine("void raise({0});", cliArgs);
                UnindentAndWriteCloseBrace();
                Unindent();
            }
        }