Browse Source

Move `CppTypePrinter` to generators and inherit from `TypePrinter`.

pull/1174/head
Joao Matos 7 years ago committed by João Matos
parent
commit
6dfd16ba9b
  1. 7
      src/AST/ITypePrinter.cs
  2. 6
      src/AST/Type.cs
  3. 11
      src/Generator.Tests/AST/TestAST.cs
  4. 128
      src/Generator/Generators/C/CppTypePrinter.cs
  5. 1
      src/Generator/Generators/CLI/CLIHeaders.cs
  6. 1
      src/Generator/Generators/CLI/CLIMarshal.cs
  7. 1
      src/Generator/Generators/CLI/CLISources.cs
  8. 2
      src/Generator/Generators/CLI/CLITypePrinter.cs
  9. 1
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  10. 1
      src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs
  11. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  12. 7
      src/Generator/Generators/TypePrinter.cs
  13. 1
      src/Generator/Passes/CheckIgnoredDecls.cs
  14. 5
      src/Generator/Passes/SymbolsCodeGenerator.cs
  15. 1
      src/Generator/Types/TypeMapDatabase.cs

7
src/AST/ITypePrinter.cs

@ -12,6 +12,13 @@ namespace CppSharp.AST
Managed Managed
} }
public enum TypePrintScopeKind
{
Local,
Qualified,
GlobalQualified
}
public enum MarshalKind public enum MarshalKind
{ {
Unknown, Unknown,

6
src/AST/Type.cs

@ -28,12 +28,6 @@ namespace CppSharp.AST
public abstract T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals public abstract T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals
= new TypeQualifiers()); = new TypeQualifiers());
public string ToNativeString()
{
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
return Visit(cppTypePrinter);
}
public override string ToString() public override string ToString()
{ {
return TypePrinterDelegate(this); return TypePrinterDelegate(this);

11
src/Generator.Tests/AST/TestAST.cs

@ -2,6 +2,7 @@ using System;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators.C;
using CppSharp.Generators.CSharp; using CppSharp.Generators.CSharp;
using CppSharp.Passes; using CppSharp.Passes;
using NUnit.Framework; using NUnit.Framework;
@ -463,7 +464,7 @@ namespace CppSharp.Generator.Tests.AST
var builtin = new BuiltinType(PrimitiveType.Char); var builtin = new BuiltinType(PrimitiveType.Char);
var pointee = new QualifiedType(builtin, new TypeQualifiers { IsConst = true }); var pointee = new QualifiedType(builtin, new TypeQualifiers { IsConst = true });
var pointer = new QualifiedType(new PointerType(pointee), new TypeQualifiers { IsConst = true }); var pointer = new QualifiedType(new PointerType(pointee), new TypeQualifiers { IsConst = true });
var type = pointer.Visit(cppTypePrinter); var type = pointer.Visit(cppTypePrinter).Type;
Assert.That(type, Is.EqualTo("const char* const")); Assert.That(type, Is.EqualTo("const char* const"));
} }
@ -472,7 +473,7 @@ namespace CppSharp.Generator.Tests.AST
{ {
var template = AstContext.FindDecl<ClassTemplate>("TestSpecializationArguments").First(); var template = AstContext.FindDecl<ClassTemplate>("TestSpecializationArguments").First();
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified }; var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
Assert.That(template.Specializations.Last().Visit(cppTypePrinter), Assert.That(template.Specializations.Last().Visit(cppTypePrinter).Type,
Is.EqualTo("TestSpecializationArguments<const TestASTEnumItemByName>")); Is.EqualTo("TestSpecializationArguments<const TestASTEnumItemByName>"));
} }
@ -517,7 +518,7 @@ namespace CppSharp.Generator.Tests.AST
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified }; var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
var builtin = new BuiltinType(PrimitiveType.Char); var builtin = new BuiltinType(PrimitiveType.Char);
var pointee = new QualifiedType(builtin, new TypeQualifiers { IsConst = true, IsVolatile = true }); var pointee = new QualifiedType(builtin, new TypeQualifiers { IsConst = true, IsVolatile = true });
var type = pointee.Visit(cppTypePrinter); var type = pointee.Visit(cppTypePrinter).Type;
Assert.That(type, Is.EqualTo("const volatile char")); Assert.That(type, Is.EqualTo("const volatile char"));
} }
@ -533,7 +534,7 @@ namespace CppSharp.Generator.Tests.AST
{ {
var template = AstContext.FindDecl<ClassTemplate>("TestTemplateClass").First(); var template = AstContext.FindDecl<ClassTemplate>("TestTemplateClass").First();
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified }; var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
Assert.That(template.Specializations[3].Classes.First().Visit(cppTypePrinter), Assert.That(template.Specializations[3].Classes.First().Visit(cppTypePrinter).Type,
Is.EqualTo("TestTemplateClass<Math::Complex>::NestedInTemplate")); Is.EqualTo("TestTemplateClass<Math::Complex>::NestedInTemplate"));
} }
@ -542,7 +543,7 @@ namespace CppSharp.Generator.Tests.AST
{ {
var functionWithSpecializationArg = AstContext.FindFunction("functionWithSpecializationArg").First(); var functionWithSpecializationArg = AstContext.FindFunction("functionWithSpecializationArg").First();
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified }; var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
Assert.That(functionWithSpecializationArg.Parameters[0].Visit(cppTypePrinter), Assert.That(functionWithSpecializationArg.Parameters[0].Visit(cppTypePrinter).Type,
Is.EqualTo("const TestTemplateClass<int>")); Is.EqualTo("const TestTemplateClass<int>"));
} }

128
src/AST/CppTypePrinter.cs → src/Generator/Generators/C/CppTypePrinter.cs

@ -1,9 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
namespace CppSharp.AST namespace CppSharp.Generators.C
{ {
public enum CppTypePrintFlavorKind public enum CppTypePrintFlavorKind
{ {
@ -12,14 +13,7 @@ namespace CppSharp.AST
ObjC ObjC
} }
public enum TypePrintScopeKind public class CppTypePrinter : TypePrinter
{
Local,
Qualified,
GlobalQualified
}
public class CppTypePrinter : ITypePrinter<string>, IDeclVisitor<string>
{ {
public CppTypePrintFlavorKind PrintFlavorKind { get; set; } public CppTypePrintFlavorKind PrintFlavorKind { get; set; }
public TypePrintScopeKind PrintScopeKind { get; set; } public TypePrintScopeKind PrintScopeKind { get; set; }
@ -38,13 +32,13 @@ namespace CppSharp.AST
public bool ResolveTypedefs { get; set; } public bool ResolveTypedefs { get; set; }
public virtual string VisitTagType(TagType tag, TypeQualifiers quals) public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
{ {
var qual = GetStringQuals(quals); var qual = GetStringQuals(quals);
return $"{qual}{tag.Declaration.Visit(this)}"; return $"{qual}{tag.Declaration.Visit(this)}";
} }
public virtual string VisitArrayType(ArrayType array, TypeQualifiers quals) public override TypePrinterResult VisitArrayType(ArrayType array, TypeQualifiers quals)
{ {
var typeName = array.Type.Visit(this); var typeName = array.Type.Visit(this);
@ -74,7 +68,7 @@ namespace CppSharp.AST
return string.Empty; return string.Empty;
} }
public virtual string VisitPointerType(PointerType pointer, TypeQualifiers quals) public override TypePrinterResult VisitPointerType(PointerType pointer, TypeQualifiers quals)
{ {
var pointee = pointer.Pointee; var pointee = pointer.Pointee;
@ -104,18 +98,18 @@ namespace CppSharp.AST
return $"{pointeeType}{mod}{(string.IsNullOrEmpty(qual) ? string.Empty : " ")}{qual}"; return $"{pointeeType}{mod}{(string.IsNullOrEmpty(qual) ? string.Empty : " ")}{qual}";
} }
public virtual string VisitMemberPointerType(MemberPointerType member, TypeQualifiers quals) public override TypePrinterResult VisitMemberPointerType(MemberPointerType member, TypeQualifiers quals)
{ {
return string.Empty; return string.Empty;
} }
public virtual string VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals) public override TypePrinterResult VisitBuiltinType(BuiltinType builtin, TypeQualifiers quals)
{ {
var qual = GetStringQuals(quals); var qual = GetStringQuals(quals);
return $"{qual}{VisitPrimitiveType(builtin.Type)}"; return $"{qual}{VisitPrimitiveType(builtin.Type)}";
} }
public virtual string VisitPrimitiveType(PrimitiveType primitive) public TypePrinterResult VisitPrimitiveType(PrimitiveType primitive)
{ {
switch (primitive) switch (primitive)
{ {
@ -177,13 +171,13 @@ namespace CppSharp.AST
throw new NotSupportedException(); throw new NotSupportedException();
} }
public virtual string VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals) public override TypePrinterResult VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals)
{ {
var qual = GetStringQuals(quals); var qual = GetStringQuals(quals);
return $"{qual}{VisitPrimitiveType(primitive)}"; return $"{qual}{VisitPrimitiveType(primitive)}";
} }
public virtual string VisitTypedefType(TypedefType typedef, TypeQualifiers quals) public override TypePrinterResult VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
{ {
FunctionType func; FunctionType func;
if (ResolveTypedefs && !typedef.Declaration.Type.IsPointerTo(out func)) if (ResolveTypedefs && !typedef.Declaration.Type.IsPointerTo(out func))
@ -192,17 +186,17 @@ namespace CppSharp.AST
return $"{qual}{typedef.Declaration.Visit(this)}"; return $"{qual}{typedef.Declaration.Visit(this)}";
} }
public virtual string VisitAttributedType(AttributedType attributed, TypeQualifiers quals) public override TypePrinterResult VisitAttributedType(AttributedType attributed, TypeQualifiers quals)
{ {
return attributed.Modified.Visit(this); return attributed.Modified.Visit(this);
} }
public virtual string VisitDecayedType(DecayedType decayed, TypeQualifiers quals) public override TypePrinterResult VisitDecayedType(DecayedType decayed, TypeQualifiers quals)
{ {
return decayed.Decayed.Visit(this); return decayed.Decayed.Visit(this);
} }
public virtual string VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals) public override TypePrinterResult VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals)
{ {
var specialization = template.GetClassTemplateSpecialization(); var specialization = template.GetClassTemplateSpecialization();
if (specialization == null) if (specialization == null)
@ -212,7 +206,7 @@ namespace CppSharp.AST
return $"{qual}{VisitClassTemplateSpecializationDecl(specialization)}"; return $"{qual}{VisitClassTemplateSpecializationDecl(specialization)}";
} }
public virtual string VisitDependentTemplateSpecializationType( public override TypePrinterResult VisitDependentTemplateSpecializationType(
DependentTemplateSpecializationType template, TypeQualifiers quals) DependentTemplateSpecializationType template, TypeQualifiers quals)
{ {
if (template.Desugared.Type != null) if (template.Desugared.Type != null)
@ -220,7 +214,7 @@ namespace CppSharp.AST
return string.Empty; return string.Empty;
} }
public virtual string VisitTemplateParameterType(TemplateParameterType param, TypeQualifiers quals) public override TypePrinterResult VisitTemplateParameterType(TemplateParameterType param, TypeQualifiers quals)
{ {
if (param.Parameter == null || param.Parameter.Name == null) if (param.Parameter == null || param.Parameter.Name == null)
return string.Empty; return string.Empty;
@ -228,41 +222,41 @@ namespace CppSharp.AST
return param.Parameter.Name; return param.Parameter.Name;
} }
public virtual string VisitTemplateParameterSubstitutionType( public override TypePrinterResult VisitTemplateParameterSubstitutionType(
TemplateParameterSubstitutionType param, TypeQualifiers quals) TemplateParameterSubstitutionType param, TypeQualifiers quals)
{ {
return param.Replacement.Type.Visit(this, quals); return param.Replacement.Type.Visit(this, quals);
} }
public virtual string VisitInjectedClassNameType(InjectedClassNameType injected, TypeQualifiers quals) public override TypePrinterResult VisitInjectedClassNameType(InjectedClassNameType injected, TypeQualifiers quals)
{ {
return injected.Class.Visit(this); return injected.Class.Visit(this);
} }
public virtual string VisitDependentNameType(DependentNameType dependent, TypeQualifiers quals) public override TypePrinterResult VisitDependentNameType(DependentNameType dependent, TypeQualifiers quals)
{ {
return dependent.Qualifier.Type != null ? dependent.Qualifier.Visit(this) : string.Empty; return dependent.Qualifier.Type != null ? dependent.Qualifier.Visit(this).Type : string.Empty;
} }
public virtual string VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals) public override TypePrinterResult VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals)
{ {
return string.Empty; return string.Empty;
} }
public virtual string VisitUnaryTransformType(UnaryTransformType unaryTransformType, TypeQualifiers quals) public override TypePrinterResult VisitUnaryTransformType(UnaryTransformType unaryTransformType, TypeQualifiers quals)
{ {
if (unaryTransformType.Desugared.Type != null) if (unaryTransformType.Desugared.Type != null)
return unaryTransformType.Desugared.Visit(this); return unaryTransformType.Desugared.Visit(this);
return unaryTransformType.BaseType.Visit(this); return unaryTransformType.BaseType.Visit(this);
} }
public virtual string VisitVectorType(VectorType vectorType, TypeQualifiers quals) public override TypePrinterResult VisitVectorType(VectorType vectorType, TypeQualifiers quals)
{ {
// an incomplete implementation but we'd hardly need anything better // an incomplete implementation but we'd hardly need anything better
return "__attribute__()"; return "__attribute__()";
} }
public virtual string VisitCILType(CILType type, TypeQualifiers quals) public override TypePrinterResult VisitCILType(CILType type, TypeQualifiers quals)
{ {
if (type.Type == typeof(string)) if (type.Type == typeof(string))
return quals.IsConst ? "const char*" : "char*"; return quals.IsConst ? "const char*" : "char*";
@ -298,17 +292,17 @@ namespace CppSharp.AST
return "void*"; return "void*";
} }
public virtual string VisitUnsupportedType(UnsupportedType type, TypeQualifiers quals) public override TypePrinterResult VisitUnsupportedType(UnsupportedType type, TypeQualifiers quals)
{ {
return string.Empty; return string.Empty;
} }
public virtual string VisitDeclaration(Declaration decl, TypeQualifiers quals) public override TypePrinterResult VisitDeclaration(Declaration decl, TypeQualifiers quals)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual string VisitFunctionType(FunctionType function, TypeQualifiers quals) public override TypePrinterResult VisitFunctionType(FunctionType function, TypeQualifiers quals)
{ {
var arguments = function.Parameters; var arguments = function.Parameters;
var returnType = function.ReturnType; var returnType = function.ReturnType;
@ -320,7 +314,7 @@ namespace CppSharp.AST
return string.Format("{0} ({1})", returnType.Visit(this), args); return string.Format("{0} ({1})", returnType.Visit(this), args);
} }
public virtual string VisitParameters(IEnumerable<Parameter> @params, public override TypePrinterResult VisitParameters(IEnumerable<Parameter> @params,
bool hasNames = true) bool hasNames = true)
{ {
var args = new List<string>(); var args = new List<string>();
@ -334,9 +328,9 @@ namespace CppSharp.AST
return string.Join(", ", args); return string.Join(", ", args);
} }
public virtual string VisitParameter(Parameter arg, bool hasName = true) public override TypePrinterResult VisitParameter(Parameter arg, bool hasName = true)
{ {
var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers); var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers).Type;
var name = arg.Name; var name = arg.Name;
var printName = hasName && !string.IsNullOrEmpty(name); var printName = hasName && !string.IsNullOrEmpty(name);
@ -347,12 +341,12 @@ namespace CppSharp.AST
return printName ? string.Format("{0} {1}", type, name) : type; return printName ? string.Format("{0} {1}", type, name) : type;
} }
public virtual string VisitDelegate(FunctionType function) public override TypePrinterResult VisitDelegate(FunctionType function)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual string GetDeclName(Declaration declaration, TypePrintScopeKind scope) public TypePrinterResult GetDeclName(Declaration declaration, TypePrintScopeKind scope)
{ {
switch (scope) switch (scope)
{ {
@ -374,22 +368,22 @@ namespace CppSharp.AST
throw new NotSupportedException(); throw new NotSupportedException();
} }
public virtual string VisitDeclaration(Declaration decl) public override TypePrinterResult VisitDeclaration(Declaration decl)
{ {
return GetDeclName(decl, PrintScopeKind); return GetDeclName(decl, PrintScopeKind);
} }
public string VisitTranslationUnit(TranslationUnit unit) public override TypePrinterResult VisitTranslationUnit(TranslationUnit unit)
{ {
return VisitDeclaration(unit); return VisitDeclaration(unit);
} }
public virtual string VisitClassDecl(Class @class) public override TypePrinterResult VisitClassDecl(Class @class)
{ {
return VisitDeclaration(@class); return VisitDeclaration(@class);
} }
public virtual string VisitClassTemplateSpecializationDecl(ClassTemplateSpecialization specialization) public override TypePrinterResult VisitClassTemplateSpecializationDecl(ClassTemplateSpecialization specialization)
{ {
return string.Format("{0}<{1}>", specialization.TemplatedDecl.Visit(this), return string.Format("{0}<{1}>", specialization.TemplatedDecl.Visit(this),
string.Join(", ", string.Join(", ",
@ -398,17 +392,17 @@ namespace CppSharp.AST
!(a.Type.Type is DependentNameType)).Select(a => a.Type.Visit(this)))); !(a.Type.Type is DependentNameType)).Select(a => a.Type.Visit(this))));
} }
public virtual string VisitFieldDecl(Field field) public override TypePrinterResult VisitFieldDecl(Field field)
{ {
return VisitDeclaration(field); return VisitDeclaration(field);
} }
public virtual string VisitFunctionDecl(Function function) public override TypePrinterResult VisitFunctionDecl(Function function)
{ {
return VisitDeclaration(function); return VisitDeclaration(function);
} }
public virtual string VisitMethodDecl(Method method) public override TypePrinterResult VisitMethodDecl(Method method)
{ {
// HACK: this should never happen but there's an inexplicable crash with the 32-bit Windows CI - I have no time to fix it right now // HACK: this should never happen but there's an inexplicable crash with the 32-bit Windows CI - I have no time to fix it right now
var functionType = method.FunctionType.Type.Desugar() as FunctionType; var functionType = method.FunctionType.Type.Desugar() as FunctionType;
@ -431,12 +425,12 @@ namespace CppSharp.AST
return $"{returnType}{@class}::{name}({@params}){@const}{exceptionType}"; return $"{returnType}{@class}::{name}({@params}){@const}{exceptionType}";
} }
public virtual string VisitParameterDecl(Parameter parameter) public override TypePrinterResult VisitParameterDecl(Parameter parameter)
{ {
return VisitParameter(parameter, hasName: false); return VisitParameter(parameter, hasName: false);
} }
public virtual string VisitTypedefDecl(TypedefDecl typedef) public override TypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
{ {
if (ResolveTypedefs) if (ResolveTypedefs)
return typedef.Type.Visit(this); return typedef.Type.Visit(this);
@ -450,72 +444,72 @@ namespace CppSharp.AST
typedef.OriginalName : $"{originalNamespace}::{typedef.OriginalName}"; typedef.OriginalName : $"{originalNamespace}::{typedef.OriginalName}";
} }
public virtual string VisitTypeAliasDecl(TypeAlias typeAlias) public override TypePrinterResult VisitTypeAliasDecl(TypeAlias typeAlias)
{ {
return VisitDeclaration(typeAlias); return VisitDeclaration(typeAlias);
} }
public virtual string VisitEnumDecl(Enumeration @enum) public override TypePrinterResult VisitEnumDecl(Enumeration @enum)
{ {
return VisitDeclaration(@enum); return VisitDeclaration(@enum);
} }
public virtual string VisitEnumItemDecl(Enumeration.Item item) public override TypePrinterResult VisitEnumItemDecl(Enumeration.Item item)
{ {
return VisitDeclaration(item); return VisitDeclaration(item);
} }
public virtual string VisitVariableDecl(Variable variable) public override TypePrinterResult VisitVariableDecl(Variable variable)
{ {
return VisitDeclaration(variable); return VisitDeclaration(variable);
} }
public virtual string VisitClassTemplateDecl(ClassTemplate template) public override TypePrinterResult VisitClassTemplateDecl(ClassTemplate template)
{ {
return VisitDeclaration(template); return VisitDeclaration(template);
} }
public virtual string VisitFunctionTemplateDecl(FunctionTemplate template) public override TypePrinterResult VisitFunctionTemplateDecl(FunctionTemplate template)
{ {
return VisitDeclaration(template); return VisitDeclaration(template);
} }
public virtual string VisitMacroDefinition(MacroDefinition macro) public override TypePrinterResult VisitMacroDefinition(MacroDefinition macro)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual string VisitNamespace(Namespace @namespace) public override TypePrinterResult VisitNamespace(Namespace @namespace)
{ {
return VisitDeclaration(@namespace); return VisitDeclaration(@namespace);
} }
public virtual string VisitEvent(Event @event) public override TypePrinterResult VisitEvent(Event @event)
{ {
return string.Empty; return string.Empty;
} }
public virtual string VisitProperty(Property property) public override TypePrinterResult VisitProperty(Property property)
{ {
return VisitDeclaration(property); return VisitDeclaration(property);
} }
public virtual string VisitFriend(Friend friend) public override TypePrinterResult VisitFriend(Friend friend)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual string ToString(Type type) public override string ToString(CppSharp.AST.Type type)
{ {
return type.Visit(this); return type.Visit(this);
} }
public virtual string VisitTemplateTemplateParameterDecl(TemplateTemplateParameter templateTemplateParameter) public override TypePrinterResult VisitTemplateTemplateParameterDecl(TemplateTemplateParameter templateTemplateParameter)
{ {
return templateTemplateParameter.Name; return templateTemplateParameter.Name;
} }
public virtual string VisitTemplateParameterDecl(TypeTemplateParameter templateParameter) public override TypePrinterResult VisitTemplateParameterDecl(TypeTemplateParameter templateParameter)
{ {
if (templateParameter.DefaultArgument.Type == null) if (templateParameter.DefaultArgument.Type == null)
return templateParameter.Name; return templateParameter.Name;
@ -523,7 +517,7 @@ namespace CppSharp.AST
return $"{templateParameter.Name} = {templateParameter.DefaultArgument.Visit(this)}"; return $"{templateParameter.Name} = {templateParameter.DefaultArgument.Visit(this)}";
} }
public virtual string VisitNonTypeTemplateParameterDecl(NonTypeTemplateParameter nonTypeTemplateParameter) public override TypePrinterResult VisitNonTypeTemplateParameterDecl(NonTypeTemplateParameter nonTypeTemplateParameter)
{ {
if (nonTypeTemplateParameter.DefaultArgument == null) if (nonTypeTemplateParameter.DefaultArgument == null)
return nonTypeTemplateParameter.Name; return nonTypeTemplateParameter.Name;
@ -531,27 +525,27 @@ namespace CppSharp.AST
return $"{nonTypeTemplateParameter.Name} = {nonTypeTemplateParameter.DefaultArgument.String}"; return $"{nonTypeTemplateParameter.Name} = {nonTypeTemplateParameter.DefaultArgument.String}";
} }
public string VisitTypedefNameDecl(TypedefNameDecl typedef) public override TypePrinterResult VisitTypedefNameDecl(TypedefNameDecl typedef)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual string VisitTypeAliasTemplateDecl(TypeAliasTemplate typeAliasTemplate) public override TypePrinterResult VisitTypeAliasTemplateDecl(TypeAliasTemplate typeAliasTemplate)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual string VisitFunctionTemplateSpecializationDecl(FunctionTemplateSpecialization specialization) public override TypePrinterResult VisitFunctionTemplateSpecializationDecl(FunctionTemplateSpecialization specialization)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual string VisitVarTemplateDecl(VarTemplate template) public override TypePrinterResult VisitVarTemplateDecl(VarTemplate template)
{ {
return VisitDeclaration(template); return VisitDeclaration(template);
} }
public virtual string VisitVarTemplateSpecializationDecl(VarTemplateSpecialization template) public override TypePrinterResult VisitVarTemplateSpecializationDecl(VarTemplateSpecialization template)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

1
src/Generator/Generators/CLI/CLIHeaders.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators.C;
using CppSharp.Generators.CSharp; using CppSharp.Generators.CSharp;
namespace CppSharp.Generators.CLI namespace CppSharp.Generators.CLI

1
src/Generator/Generators/CLI/CLIMarshal.cs

@ -3,6 +3,7 @@ using System.Linq;
using System.Text; using System.Text;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators.C;
using CppSharp.Types; using CppSharp.Types;
using Delegate = CppSharp.AST.Delegate; using Delegate = CppSharp.AST.Delegate;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

1
src/Generator/Generators/CLI/CLISources.cs

@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators.C;
using CppSharp.Generators.CSharp; using CppSharp.Generators.CSharp;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

2
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -271,7 +271,7 @@ namespace CppSharp.Generators.CLI
DependentNameType dependent, TypeQualifiers quals) DependentNameType dependent, TypeQualifiers quals)
{ {
return dependent.Qualifier.Type != null ? return dependent.Qualifier.Type != null ?
dependent.Qualifier.Visit(this) : string.Empty; dependent.Qualifier.Visit(this).Type : string.Empty;
} }
public override TypePrinterResult VisitPackExpansionType( public override TypePrinterResult VisitPackExpansionType(

1
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -3,6 +3,7 @@ using System.Linq;
using System.Text; using System.Text;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators.C;
using CppSharp.Types; using CppSharp.Types;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;

1
src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators.C;
namespace CppSharp.Generators.CSharp namespace CppSharp.Generators.CSharp
{ {

2
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -587,7 +587,7 @@ namespace CppSharp.Generators.CSharp
return a.Integral.ToString(CultureInfo.InvariantCulture); return a.Integral.ToString(CultureInfo.InvariantCulture);
var type = a.Type.Type.Desugar(); var type = a.Type.Type.Desugar();
return type.IsPointerToPrimitiveType() ? IntPtrType : return type.IsPointerToPrimitiveType() ? IntPtrType :
type.IsPrimitiveType(PrimitiveType.Void) ? "object" : type.Visit(this); type.IsPrimitiveType(PrimitiveType.Void) ? "object" : type.Visit(this).Type;
} }
public override TypePrinterResult VisitParameterDecl(Parameter parameter) public override TypePrinterResult VisitParameterDecl(Parameter parameter)

7
src/Generator/Generators/TypePrinter.cs

@ -14,6 +14,11 @@ namespace CppSharp.Generators
return new TypePrinterResult { Type = type }; return new TypePrinterResult { Type = type };
} }
public static implicit operator string(TypePrinterResult result)
{
return result.Type;
}
public override string ToString() => Type; public override string ToString() => Type;
} }
@ -325,7 +330,7 @@ namespace CppSharp.Generators
return VisitDeclaration(typedef); return VisitDeclaration(typedef);
} }
public TypePrinterResult VisitTypedefNameDecl(TypedefNameDecl typedef) public virtual TypePrinterResult VisitTypedefNameDecl(TypedefNameDecl typedef)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

1
src/Generator/Passes/CheckIgnoredDecls.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Types; using CppSharp.Types;
using CppSharp.Generators.C;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {

5
src/Generator/Passes/SymbolsCodeGenerator.cs

@ -5,6 +5,7 @@ using System.Text;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Generators.C;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {
@ -245,9 +246,9 @@ namespace CppSharp.Passes
switch (a.Kind) switch (a.Kind)
{ {
case TemplateArgument.ArgumentKind.Type: case TemplateArgument.ArgumentKind.Type:
return a.Type.Visit(cppTypePrinter); return a.Type.Visit(cppTypePrinter).Type;
case TemplateArgument.ArgumentKind.Declaration: case TemplateArgument.ArgumentKind.Declaration:
return a.Declaration.Visit(cppTypePrinter); return a.Declaration.Visit(cppTypePrinter).Type;
case TemplateArgument.ArgumentKind.Integral: case TemplateArgument.ArgumentKind.Integral:
return a.Integral.ToString(CultureInfo.InvariantCulture); return a.Integral.ToString(CultureInfo.InvariantCulture);
} }

1
src/Generator/Types/TypeMapDatabase.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Generators.C;
using Type = CppSharp.AST.Type; using Type = CppSharp.AST.Type;
namespace CppSharp.Types namespace CppSharp.Types

Loading…
Cancel
Save