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

            cTypePrinter.PushScope(TypePrintScopeKind.Local);

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

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

            cTypePrinter.PushScope(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}");
        }
Example #2
0
        public void TestPrintQualifiedSpecialization()
        {
            var functionWithSpecializationArg = AstContext.FindFunction("functionWithSpecializationArg").First();
            var cppTypePrinter = new CppTypePrinter(Context);

            cppTypePrinter.PushScope(TypePrintScopeKind.Qualified);
            Assert.That(functionWithSpecializationArg.Parameters[0].Visit(cppTypePrinter).Type,
                        Is.EqualTo("const TestTemplateClass<int>"));
        }
Example #3
0
        public void TestPrintNestedInSpecialization()
        {
            var template       = AstContext.FindDecl <ClassTemplate>("TestTemplateClass").First();
            var cppTypePrinter = new CppTypePrinter(Context);

            cppTypePrinter.PushScope(TypePrintScopeKind.Qualified);
            Assert.That(template.Specializations[4].Classes.First().Visit(cppTypePrinter).Type,
                        Is.EqualTo("TestTemplateClass<Math::Complex>::NestedInTemplate"));
        }
Example #4
0
        public void TestPrintingSpecializationWithConstValue()
        {
            var template       = AstContext.FindDecl <ClassTemplate>("TestSpecializationArguments").First();
            var cppTypePrinter = new CppTypePrinter(Context);

            cppTypePrinter.PushScope(TypePrintScopeKind.Qualified);
            Assert.That(template.Specializations.Last().Visit(cppTypePrinter).Type,
                        Is.EqualTo("TestSpecializationArguments<const TestASTEnumItemByName>"));
        }
Example #5
0
        public SymbolsCodeGenerator(BindingContext context, IEnumerable <TranslationUnit> units)
            : base(context, units)
        {
            cppTypePrinter = new CppTypePrinter(Context)
            {
                ResolveTypedefs = true,
                ResolveTypeMaps = false
            };

            cppTypePrinter.PushContext(TypePrinterContextKind.Native);
            cppTypePrinter.PushScope(TypePrintScopeKind.Qualified);
        }
Example #6
0
        public void TestVolatile()
        {
            var cppTypePrinter = new CppTypePrinter(Context);

            cppTypePrinter.PushScope(TypePrintScopeKind.Qualified);
            var builtin = new BuiltinType(PrimitiveType.Char);
            var pointee = new QualifiedType(builtin, new TypeQualifiers {
                IsConst = true, IsVolatile = true
            });
            var type = pointee.Visit(cppTypePrinter).Type;

            Assert.That(type, Is.EqualTo("const volatile char"));
        }
        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;
            }
        }
Example #8
0
        public void TestPrintingConstPointerWithConstType()
        {
            var cppTypePrinter = new CppTypePrinter(Context)
            {
                ResolveTypeMaps = false
            };

            cppTypePrinter.PushScope(TypePrintScopeKind.Qualified);
            var builtin = new BuiltinType(PrimitiveType.Char);
            var pointee = new QualifiedType(builtin, new TypeQualifiers {
                IsConst = true
            });
            var pointer = new QualifiedType(new PointerType(pointee), new TypeQualifiers {
                IsConst = true
            });
            string type = pointer.Visit(cppTypePrinter);

            Assert.That(type, Is.EqualTo("const char* const"));
        }