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}"); }
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>")); }
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")); }
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>")); }
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); }
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; } }
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")); }