Beispiel #1
0
        public static string GetCIdentifier(BindingContext context, Declaration decl,
                                            TypePrintScopeKind scope = TypePrintScopeKind.Qualified)
        {
            var cTypePrinter = new CppTypePrinter(context)
            {
                PrintFlavorKind = CppTypePrintFlavorKind.C,
                ScopeKind       = TypePrintScopeKind.Local
            };

            var functionName = cTypePrinter.VisitDeclaration(decl).ToString();

            if (scope == TypePrintScopeKind.Local)
            {
                return(functionName);
            }

            cTypePrinter.ScopeKind = scope;
            var qualifiedParentName = cTypePrinter.VisitDeclaration(decl.Namespace).ToString();

            // HACK: CppTypePrinter code calls into decl.QualifiedName, which does not take into
            // account language flavor, that code needs to be reworked. For now, hack around it.
            qualifiedParentName = qualifiedParentName.Replace("::", "_");

            return($"{qualifiedParentName}_{functionName}");
        }
Beispiel #2
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.Type = typedef;
                typeMap.CppMarshalToManaged(Context);
                return(typeMap.IsValueType);
            }

            FunctionType function;

            if (decl.Type.IsPointerTo(out function))
            {
                var typePrinter = new CppTypePrinter(Context.Context);
                var typeName    = typePrinter.VisitDeclaration(decl);
                var typeName2   = decl.Type.Visit(typePrinter);
                Context.Return.Write(typeName);
                //return typeName;
                //throw new System.NotImplementedException();
            }

            return(decl.Type.Visit(this));
        }
Beispiel #3
0
        public override bool VisitEnumDecl(Enumeration @enum)
        {
            var typePrinter = new CppTypePrinter(Context.Context);
            var typeName    = typePrinter.VisitDeclaration(@enum);

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

            return(true);
        }