diff --git a/build/LLVM.lua b/build/LLVM.lua index 61d77249..f10e8167 100644 --- a/build/LLVM.lua +++ b/build/LLVM.lua @@ -79,6 +79,7 @@ function SetupLLVMLibs() "clangParse", "clangSema", "clangSerialization", + "clangIndex", } StaticLinksOpt { "LLVMProfileData" } diff --git a/src/AST/Class.cs b/src/AST/Class.cs index 8d25dff2..b42042e8 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -220,9 +220,27 @@ namespace CppSharp.AST return base.GetOverloads(function); } + public Method FindMethod(string name) + { + return Methods + .Concat(Templates.OfType() + .Select(t => t.TemplatedFunction) + .OfType()) + .FirstOrDefault(m => m.Name == name); + } + + public Method FindMethodByUSR(string usr) + { + return Methods + .Concat(Templates.OfType() + .Select(t => t.TemplatedFunction) + .OfType()) + .FirstOrDefault(m => m.USR == usr); + } + public override T Visit(IDeclVisitor visitor) { return visitor.VisitClassDecl(this); } } -} \ No newline at end of file +} diff --git a/src/AST/Declaration.cs b/src/AST/Declaration.cs index e34b28fe..d283cae5 100644 --- a/src/AST/Declaration.cs +++ b/src/AST/Declaration.cs @@ -285,6 +285,14 @@ namespace CppSharp.AST // Pointer to the original declaration from Clang. public IntPtr OriginalPtr; + // The Unified Symbol Resolution (USR) for the declaration. + // A Unified Symbol Resolution (USR) is a string that identifies a + // particular entity (function, class, variable, etc.) within a program. + // USRs can be compared across translation units to determine, e.g., + // when references in one translation refer to an entity defined in + // another translation unit. + public string USR; + public List Attributes { get; private set; } protected Declaration() diff --git a/src/AST/Function.cs b/src/AST/Function.cs index 7215e1c7..eea1d2f5 100644 --- a/src/AST/Function.cs +++ b/src/AST/Function.cs @@ -119,6 +119,11 @@ namespace CppSharp.AST OriginalFunction = function.OriginalFunction; Mangled = function.Mangled; Index = function.Index; + if (function.SpecializationInfo != null) + { + SpecializationInfo = new FunctionTemplateSpecialization(function.SpecializationInfo); + SpecializationInfo.SpecializedFunction = function; + } } public QualifiedType ReturnType { get; set; } @@ -136,6 +141,8 @@ namespace CppSharp.AST public CallingConvention CallingConvention { get; set; } + public FunctionTemplateSpecialization SpecializationInfo { get; set; } + public bool IsThisCall { get { return CallingConvention == CallingConvention.ThisCall; } diff --git a/src/AST/Namespace.cs b/src/AST/Namespace.cs index 87c4fc0e..74465295 100644 --- a/src/AST/Namespace.cs +++ b/src/AST/Namespace.cs @@ -216,6 +216,22 @@ namespace CppSharp.AST return @namespace.FindFunction(funcName, createDecl); } + public Function FindFunction(string name) + { + return Functions + .Concat(Templates.OfType() + .Select(t => t.TemplatedFunction)) + .FirstOrDefault(f => f.Name == name); + } + + public Function FindFunctionByUSR(string usr) + { + return Functions + .Concat(Templates.OfType() + .Select(t => t.TemplatedFunction)) + .FirstOrDefault(f => f.USR == usr); + } + Class CreateClass(string name, bool isComplete) { var @class = new Class @@ -294,23 +310,28 @@ namespace CppSharp.AST return newClass; } - public FunctionTemplate FindFunctionTemplate(string name, - List @params) + public FunctionTemplate FindFunctionTemplate(string name) + { + return Templates.OfType() + .FirstOrDefault(t => t.Name == name); + } + + public FunctionTemplate FindFunctionTemplateByUSR(string usr) { - return Templates.FirstOrDefault(template => template.Name == name - && template.Parameters.SequenceEqual(@params)) as FunctionTemplate; + return Templates.OfType() + .FirstOrDefault(t => t.USR == usr); } - public FunctionTemplate FindFunctionTemplate(IntPtr ptr) + public ClassTemplate FindClassTemplate(string name) { - return Templates.FirstOrDefault(template => - template.OriginalPtr == ptr) as FunctionTemplate; + return Templates.OfType() + .FirstOrDefault(t => t.Name == name); } - public ClassTemplate FindClassTemplate(IntPtr ptr) + public ClassTemplate FindClassTemplateByUSR(string usr) { - return Templates.FirstOrDefault(template => - template.OriginalPtr == ptr) as ClassTemplate; + return Templates.OfType() + .FirstOrDefault(t => t.USR == usr); } public TypedefDecl FindTypedef(string name, bool createDecl = false) @@ -417,4 +438,4 @@ namespace CppSharp.AST return visitor.VisitNamespace(this); } } -} \ No newline at end of file +} diff --git a/src/AST/Template.cs b/src/AST/Template.cs index 6cc406c8..f133e78e 100644 --- a/src/AST/Template.cs +++ b/src/AST/Template.cs @@ -13,6 +13,10 @@ namespace CppSharp.AST // Generic type constraint public string Constraint; + + // Whether the template parameter represents a type parameter, + // like "T" in template. + public bool IsTypeParameter; } /// @@ -24,8 +28,18 @@ namespace CppSharp.AST // Name of the declaration. public override string Name { - get { return TemplatedDecl.Name; } - set { base.Name = value; } + get + { + if (TemplatedDecl != null) + return TemplatedDecl.Name; + return base.Name; + } + set + { + base.Name = value; + if (TemplatedDecl != null) + TemplatedDecl.Name = value; + } } protected Template() @@ -111,27 +125,14 @@ namespace CppSharp.AST } } - public ClassTemplateSpecialization FindSpecialization( - TemplateSpecializationType type) - { - return Specializations.FirstOrDefault( - spec => spec.Arguments.SequenceEqual(type.Arguments)); - } - - public ClassTemplateSpecialization FindSpecialization(IntPtr ptr) - { - return Specializations.FirstOrDefault(spec => spec.OriginalPtr == ptr); - } - - public ClassTemplatePartialSpecialization FindPartialSpecialization( - TemplateSpecializationType type) + public ClassTemplateSpecialization FindSpecializationByUSR(string usr) { - return FindSpecialization(type) as ClassTemplatePartialSpecialization; + return Specializations.FirstOrDefault(spec => spec.USR == usr); } - public ClassTemplatePartialSpecialization FindPartialSpecialization(IntPtr ptr) + public ClassTemplatePartialSpecialization FindPartialSpecializationByUSR(string usr) { - return FindSpecialization(ptr) as ClassTemplatePartialSpecialization; + return FindSpecializationByUSR(usr) as ClassTemplatePartialSpecialization; } } @@ -193,13 +194,17 @@ namespace CppSharp.AST /// public class FunctionTemplate : Template { + public List Specializations; + public FunctionTemplate() { + Specializations = new List(); } public FunctionTemplate(Declaration decl) : base(decl) { + Specializations = new List(); } public Function TemplatedFunction @@ -212,4 +217,33 @@ namespace CppSharp.AST return visitor.VisitFunctionTemplateDecl(this); } } + + /// + /// Represents a function template specialization, which refers to a function + /// template with a given set of template arguments. + /// + public class FunctionTemplateSpecialization + { + public FunctionTemplate Template; + + public List Arguments; + + public Function SpecializedFunction; + + public TemplateSpecializationKind SpecializationKind; + + public FunctionTemplateSpecialization() + { + Arguments = new List(); + } + + public FunctionTemplateSpecialization(FunctionTemplateSpecialization fts) + { + Template = fts.Template; + Arguments = new List(); + Arguments.AddRange(fts.Arguments); + SpecializedFunction = fts.SpecializedFunction; + SpecializationKind = fts.SpecializationKind; + } + } } diff --git a/src/AST/Type.cs b/src/AST/Type.cs index bb85852a..2e95a3fe 100644 --- a/src/AST/Type.cs +++ b/src/AST/Type.cs @@ -508,6 +508,9 @@ namespace CppSharp.AST public class TemplateParameterType : Type { public TemplateParameter Parameter; + public uint Depth; + public uint Index; + public bool IsParameterPack; public override T Visit(ITypeVisitor visitor, TypeQualifiers quals = new TypeQualifiers()) @@ -520,7 +523,10 @@ namespace CppSharp.AST var type = obj as TemplateParameterType; if (type == null) return false; - return Parameter.Equals(type.Parameter); + return Parameter.Equals(type.Parameter) + && Depth.Equals(type.Depth) + && Index.Equals(type.Index) + && IsParameterPack.Equals(type.IsParameterPack); } public override int GetHashCode() diff --git a/src/AST/TypeExtensions.cs b/src/AST/TypeExtensions.cs index a29df940..6406bd22 100644 --- a/src/AST/TypeExtensions.cs +++ b/src/AST/TypeExtensions.cs @@ -158,16 +158,22 @@ public static Type Desugar(this Type t) { - var type = t as TypedefType; - - if (type != null) + var typeDef = t as TypedefType; + if (typeDef != null) { - var decl = type.Declaration.Type; - + var decl = typeDef.Declaration.Type; if (decl != null) return decl.Desugar(); } + var substType = t as TemplateParameterSubstitutionType; + if (substType != null) + { + var replacement = substType.Replacement.Type; + if (replacement != null) + return replacement.Desugar(); + } + return t; } diff --git a/src/Core/Parser/ASTConverter.cs b/src/Core/Parser/ASTConverter.cs index 68a74c06..f6fc493d 100644 --- a/src/Core/Parser/ASTConverter.cs +++ b/src/Core/Parser/ASTConverter.cs @@ -496,6 +496,9 @@ namespace CppSharp { var _type = new AST.TemplateParameterType(); _type.Parameter = DeclConverter.VisitTemplateParameter(type.Parameter); + _type.Depth = type.Depth; + _type.Index = type.Index; + _type.IsParameterPack = type.IsParameterPack; VisitType(type, _type); return _type; } @@ -1255,6 +1258,7 @@ namespace CppSharp { var _param = new AST.TemplateParameter(); _param.Name = param.Name; + _param.IsTypeParameter = param.IsTypeParameter; return _param; } @@ -1356,11 +1360,30 @@ namespace CppSharp public override AST.Declaration VisitFunctionTemplate(FunctionTemplate decl) { - var _decl = new AST.FunctionTemplate(); + var _decl = new AST.FunctionTemplate(Visit(decl.TemplatedDecl)); VisitTemplate(decl, _decl); + for (uint i = 0; i < decl.SpecializationsCount; ++i) + { + var _spec = VisitFunctionTemplateSpecialization(decl.getSpecializations(i)); + _decl.Specializations.Add(_spec); + } return _decl; } + private AST.FunctionTemplateSpecialization VisitFunctionTemplateSpecialization(FunctionTemplateSpecialization spec) + { + var _spec = new AST.FunctionTemplateSpecialization(); + _spec.Template = (AST.FunctionTemplate)Visit(spec.Template); + _spec.SpecializedFunction = (AST.Function)Visit(spec.SpecializedFunction); + _spec.SpecializationKind = VisitSpecializationKind(spec.SpecializationKind); + for (uint i = 0; i < spec.ArgumentsCount; ++i) + { + var _arg = VisitTemplateArgument(spec.getArguments(i)); + _spec.Arguments.Add(_arg); + } + return _spec; + } + void VisitPreprocessedEntity(PreprocessedEntity entity, AST.PreprocessedEntity _entity) { VisitDeclaration(entity, _entity); @@ -1416,4 +1439,4 @@ namespace CppSharp #endregion } -#endif \ No newline at end of file +#endif diff --git a/src/CppParser/AST.cpp b/src/CppParser/AST.cpp index fe6e156c..8b0f718f 100644 --- a/src/CppParser/AST.cpp +++ b/src/CppParser/AST.cpp @@ -69,8 +69,16 @@ TemplateSpecializationType::TemplateSpecializationType( DEF_VECTOR(TemplateSpecializationType, TemplateArgument, Arguments) // TemplateParameter -TemplateParameter::TemplateParameter() {} -TemplateParameter::TemplateParameter(const TemplateParameter& rhs) : Name(rhs.Name) {} +TemplateParameter::TemplateParameter() + : IsTypeParameter(false) +{ +} + +TemplateParameter::TemplateParameter(const TemplateParameter& rhs) + : Name(rhs.Name) + , IsTypeParameter(rhs.IsTypeParameter) +{ +} DEF_STRING(TemplateParameter, Name) @@ -341,60 +349,44 @@ Enumeration* DeclarationContext::FindEnumWithItem(const std::string& Name) return nullptr; } -Function* DeclarationContext::FindFunction(const std::string& Name, bool Create) +Function* DeclarationContext::FindFunction(const std::string& USR) { auto foundFunction = std::find_if(Functions.begin(), Functions.end(), - [&](Function* func) { return func->Name == Name; }); + [&](Function* func) { return func->USR == USR; }); if (foundFunction != Functions.end()) return *foundFunction; - if (!Create) - return nullptr; - - auto function = new Function(); - function->Name = Name; - function->_Namespace = this; - Functions.push_back(function); - - return function; -} - -ClassTemplate* -DeclarationContext::FindClassTemplate(void* OriginalPtr) -{ auto foundTemplate = std::find_if(Templates.begin(), Templates.end(), - [&](Template* t) { return t->OriginalPtr == OriginalPtr; }); + [&](Template* t) { return t->TemplatedDecl->USR == USR; }); if (foundTemplate != Templates.end()) - return static_cast(*foundTemplate); + return static_cast((*foundTemplate)->TemplatedDecl); return nullptr; } -FunctionTemplate* -DeclarationContext::FindFunctionTemplate(void* OriginalPtr) +ClassTemplate* +DeclarationContext::FindClassTemplate(const std::string& USR) { - auto foundFunction = std::find_if(Templates.begin(), Templates.end(), - [&](Template* func) { return func->OriginalPtr == OriginalPtr; }); + auto foundTemplate = std::find_if(Templates.begin(), Templates.end(), + [&](Template* t) { return t->USR == USR; }); - if (foundFunction != Templates.end()) - return static_cast(*foundFunction); + if (foundTemplate != Templates.end()) + return static_cast(*foundTemplate); return nullptr; } FunctionTemplate* -DeclarationContext::FindFunctionTemplate(const std::string& Name, - const std::vector& Params) +DeclarationContext::FindFunctionTemplate(const std::string& USR) { - FunctionTemplate* func = 0; - auto foundFunction = std::find_if(Templates.begin(), Templates.end(), - [&](Template* func) { return func->Name == Name && func->Parameters == Params; } + auto foundTemplate = std::find_if(Templates.begin(), Templates.end(), + [&](Template* t) { return t->USR == USR; } ); - if (foundFunction != Templates.end()) - return static_cast(*foundFunction); + if (foundTemplate != Templates.end()) + return static_cast(*foundTemplate); return nullptr; } @@ -423,15 +415,32 @@ TypedefDecl::TypedefDecl() : Declaration(DeclarationKind::Typedef) {} Parameter::Parameter() : Declaration(DeclarationKind::Parameter), IsIndirect(false), HasDefaultValue(false) {} -Function::Function() : Declaration(DeclarationKind::Function), - IsReturnIndirect(false) {} +Function::Function() + : Declaration(DeclarationKind::Function) + , IsReturnIndirect(false) + , SpecializationInfo(0) +{ +} DEF_STRING(Function, Mangled) DEF_STRING(Function, Signature) DEF_VECTOR(Function, Parameter*, Parameters) -Method::Method() : IsDefaultConstructor(false), IsCopyConstructor(false), - IsMoveConstructor(false) { Kind = DeclarationKind::Method; } +Method::Method() + : Function() + , AccessDecl(0) + , IsVirtual(false) + , IsStatic(false) + , IsConst(false) + , IsImplicit(false) + , IsExplicit(false) + , IsOverride(false) + , IsDefaultConstructor(false) + , IsCopyConstructor(false) + , IsMoveConstructor(false) +{ + Kind = DeclarationKind::Method; +} // Enumeration @@ -496,16 +505,44 @@ ClassTemplate::ClassTemplate() : Template(DeclarationKind::ClassTemplate) {} DEF_VECTOR(ClassTemplate, ClassTemplateSpecialization*, Specializations) -ClassTemplateSpecialization::ClassTemplateSpecialization() : TemplatedDecl(0) - { Kind = DeclarationKind::ClassTemplateSpecialization; } +ClassTemplateSpecialization::ClassTemplateSpecialization() + : Class() + , TemplatedDecl(0) +{ + Kind = DeclarationKind::ClassTemplateSpecialization; +} DEF_VECTOR(ClassTemplateSpecialization, TemplateArgument, Arguments) ClassTemplatePartialSpecialization::ClassTemplatePartialSpecialization() - { Kind = DeclarationKind::ClassTemplatePartialSpecialization; } + : ClassTemplateSpecialization() +{ + Kind = DeclarationKind::ClassTemplatePartialSpecialization; +} FunctionTemplate::FunctionTemplate() : Template(DeclarationKind::FunctionTemplate) {} +DEF_VECTOR(FunctionTemplate, FunctionTemplateSpecialization*, Specializations) + +FunctionTemplateSpecialization* FunctionTemplate::FindSpecialization(const std::string& usr) +{ + auto foundSpec = std::find_if(Specializations.begin(), Specializations.end(), + [&](FunctionTemplateSpecialization* cts) { return cts->SpecializedFunction->USR == usr; }); + + if (foundSpec != Specializations.end()) + return static_cast(*foundSpec); + + return nullptr; +} + +FunctionTemplateSpecialization::FunctionTemplateSpecialization() + : Template(0) + , SpecializedFunction(0) +{ +} + +DEF_VECTOR(FunctionTemplateSpecialization, TemplateArgument, Arguments) + Namespace::Namespace() : DeclarationContext(DeclarationKind::Namespace) , IsInline(false) @@ -536,10 +573,10 @@ DEF_VECTOR_STRING(NativeLibrary, Symbols) // ASTContext DEF_VECTOR(ASTContext, TranslationUnit*, TranslationUnits) -ClassTemplateSpecialization* ClassTemplate::FindSpecialization(void* ptr) +ClassTemplateSpecialization* ClassTemplate::FindSpecialization(const std::string& usr) { auto foundSpec = std::find_if(Specializations.begin(), Specializations.end(), - [&](ClassTemplateSpecialization* cts) { return cts->OriginalPtr == ptr; }); + [&](ClassTemplateSpecialization* cts) { return cts->USR == usr; }); if (foundSpec != Specializations.end()) return static_cast(*foundSpec); @@ -547,26 +584,14 @@ ClassTemplateSpecialization* ClassTemplate::FindSpecialization(void* ptr) return nullptr; } -ClassTemplateSpecialization* -ClassTemplate::FindSpecialization(TemplateSpecializationType type) +ClassTemplatePartialSpecialization* ClassTemplate::FindPartialSpecialization(const std::string& usr) { - return 0; -} - -ClassTemplatePartialSpecialization* ClassTemplate::FindPartialSpecialization(void* ptr) -{ - auto foundSpec = FindSpecialization(ptr); + auto foundSpec = FindSpecialization(usr); if (foundSpec != nullptr) return static_cast(foundSpec); return nullptr; } -ClassTemplatePartialSpecialization* -ClassTemplate::FindPartialSpecialization(TemplateSpecializationType type) -{ - return 0; -} - ASTContext::ASTContext() {} TranslationUnit* ASTContext::FindOrCreateModule(std::string File) diff --git a/src/CppParser/AST.h b/src/CppParser/AST.h index 0b306955..82748257 100644 --- a/src/CppParser/AST.h +++ b/src/CppParser/AST.h @@ -191,12 +191,16 @@ struct CS_API TemplateParameter } STRING(Name) + bool IsTypeParameter; }; struct CS_API TemplateParameterType : public Type { DECLARE_TYPE_KIND(TemplateParameter) TemplateParameter Parameter; + unsigned int Depth; + unsigned int Index; + bool IsParameterPack; }; struct CS_API TemplateParameterSubstitutionType : public Type @@ -372,6 +376,7 @@ struct CS_API Declaration unsigned DefinitionOrder; VECTOR(PreprocessedEntity*, PreprocessedEntities) void* OriginalPtr; + std::string USR; }; struct Class; @@ -399,16 +404,14 @@ struct CS_API DeclarationContext : public Declaration CS_IGNORE Class* FindClass(const std::string& Name, bool IsComplete, bool Create = false); - CS_IGNORE ClassTemplate* FindClassTemplate(void* OriginalPtr); - CS_IGNORE FunctionTemplate* FindFunctionTemplate(void* OriginalPtr); - CS_IGNORE FunctionTemplate* FindFunctionTemplate(const std::string& Name, - const std::vector& Params); + CS_IGNORE ClassTemplate* FindClassTemplate(const std::string& USR); + CS_IGNORE FunctionTemplate* FindFunctionTemplate(const std::string& USR); CS_IGNORE Enumeration* FindEnum(void* OriginalPtr); CS_IGNORE Enumeration* FindEnum(const std::string& Name, bool Create = false); CS_IGNORE Enumeration* FindEnumWithItem(const std::string& Name); - CS_IGNORE Function* FindFunction(const std::string& Name, bool Create = false); + CS_IGNORE Function* FindFunction(const std::string& USR); CS_IGNORE TypedefDecl* FindTypedef(const std::string& Name, bool Create = false); @@ -498,6 +501,8 @@ enum struct CXXOperatorKind Conditional }; +struct FunctionTemplateSpecialization; + struct CS_API Function : public Declaration { Function(); @@ -514,6 +519,7 @@ struct CS_API Function : public Declaration STRING(Signature) CppSharp::CppParser::AST::CallingConvention CallingConvention; VECTOR(Parameter*, Parameters) + FunctionTemplateSpecialization* SpecializationInfo; }; struct AccessSpecifierDecl; @@ -638,10 +644,8 @@ struct CS_API ClassTemplate : public Template { ClassTemplate(); VECTOR(ClassTemplateSpecialization*, Specializations) - ClassTemplateSpecialization* FindSpecialization(void* ptr); - ClassTemplateSpecialization* FindSpecialization(TemplateSpecializationType type); - ClassTemplatePartialSpecialization* FindPartialSpecialization(void* ptr); - ClassTemplatePartialSpecialization* FindPartialSpecialization(TemplateSpecializationType type); + ClassTemplateSpecialization* FindSpecialization(const std::string& usr); + ClassTemplatePartialSpecialization* FindPartialSpecialization(const std::string& usr); }; enum struct TemplateSpecializationKind @@ -669,6 +673,17 @@ struct CS_API ClassTemplatePartialSpecialization : public ClassTemplateSpecializ struct CS_API FunctionTemplate : public Template { FunctionTemplate(); + VECTOR(FunctionTemplateSpecialization*, Specializations) + FunctionTemplateSpecialization* FindSpecialization(const std::string& usr); +}; + +struct CS_API FunctionTemplateSpecialization +{ + FunctionTemplateSpecialization(); + FunctionTemplate* Template; + VECTOR(TemplateArgument, Arguments) + Function* SpecializedFunction; + TemplateSpecializationKind SpecializationKind; }; struct CS_API Namespace : public DeclarationContext diff --git a/src/CppParser/Bindings/CLI/AST.cpp b/src/CppParser/Bindings/CLI/AST.cpp index 12c5cbf3..fee744a4 100644 --- a/src/CppParser/Bindings/CLI/AST.cpp +++ b/src/CppParser/Bindings/CLI/AST.cpp @@ -627,6 +627,16 @@ void CppSharp::Parser::AST::TemplateParameter::Name::set(System::String^ s) ((::CppSharp::CppParser::AST::TemplateParameter*)NativePtr)->setName(arg0); } +bool CppSharp::Parser::AST::TemplateParameter::IsTypeParameter::get() +{ + return ((::CppSharp::CppParser::AST::TemplateParameter*)NativePtr)->IsTypeParameter; +} + +void CppSharp::Parser::AST::TemplateParameter::IsTypeParameter::set(bool value) +{ + ((::CppSharp::CppParser::AST::TemplateParameter*)NativePtr)->IsTypeParameter = value; +} + CppSharp::Parser::AST::TemplateParameterType::TemplateParameterType(::CppSharp::CppParser::AST::TemplateParameterType* native) : CppSharp::Parser::AST::Type((::CppSharp::CppParser::AST::Type*)native) { @@ -654,6 +664,36 @@ void CppSharp::Parser::AST::TemplateParameterType::Parameter::set(CppSharp::Pars ((::CppSharp::CppParser::AST::TemplateParameterType*)NativePtr)->Parameter = *(::CppSharp::CppParser::AST::TemplateParameter*)value->NativePtr; } +unsigned int CppSharp::Parser::AST::TemplateParameterType::Depth::get() +{ + return ((::CppSharp::CppParser::AST::TemplateParameterType*)NativePtr)->Depth; +} + +void CppSharp::Parser::AST::TemplateParameterType::Depth::set(unsigned int value) +{ + ((::CppSharp::CppParser::AST::TemplateParameterType*)NativePtr)->Depth = value; +} + +unsigned int CppSharp::Parser::AST::TemplateParameterType::Index::get() +{ + return ((::CppSharp::CppParser::AST::TemplateParameterType*)NativePtr)->Index; +} + +void CppSharp::Parser::AST::TemplateParameterType::Index::set(unsigned int value) +{ + ((::CppSharp::CppParser::AST::TemplateParameterType*)NativePtr)->Index = value; +} + +bool CppSharp::Parser::AST::TemplateParameterType::IsParameterPack::get() +{ + return ((::CppSharp::CppParser::AST::TemplateParameterType*)NativePtr)->IsParameterPack; +} + +void CppSharp::Parser::AST::TemplateParameterType::IsParameterPack::set(bool value) +{ + ((::CppSharp::CppParser::AST::TemplateParameterType*)NativePtr)->IsParameterPack = value; +} + CppSharp::Parser::AST::TemplateParameterSubstitutionType::TemplateParameterSubstitutionType(::CppSharp::CppParser::AST::TemplateParameterSubstitutionType* native) : CppSharp::Parser::AST::Type((::CppSharp::CppParser::AST::Type*)native) { @@ -1614,6 +1654,16 @@ void CppSharp::Parser::AST::Function::CallingConvention::set(CppSharp::Parser::A ((::CppSharp::CppParser::AST::Function*)NativePtr)->CallingConvention = (::CppSharp::CppParser::AST::CallingConvention)value; } +CppSharp::Parser::AST::FunctionTemplateSpecialization^ CppSharp::Parser::AST::Function::SpecializationInfo::get() +{ + return (((::CppSharp::CppParser::AST::Function*)NativePtr)->SpecializationInfo == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::FunctionTemplateSpecialization((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)((::CppSharp::CppParser::AST::Function*)NativePtr)->SpecializationInfo); +} + +void CppSharp::Parser::AST::Function::SpecializationInfo::set(CppSharp::Parser::AST::FunctionTemplateSpecialization^ value) +{ + ((::CppSharp::CppParser::AST::Function*)NativePtr)->SpecializationInfo = (::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)value->NativePtr; +} + CppSharp::Parser::AST::Method::Method(::CppSharp::CppParser::AST::Method* native) : CppSharp::Parser::AST::Function((::CppSharp::CppParser::AST::Function*)native) { @@ -2295,38 +2345,6 @@ void CppSharp::Parser::AST::ClassTemplate::addSpecializations(CppSharp::Parser:: ((::CppSharp::CppParser::AST::ClassTemplate*)NativePtr)->addSpecializations(arg0); } -CppSharp::Parser::AST::ClassTemplateSpecialization^ CppSharp::Parser::AST::ClassTemplate::FindSpecialization(void* ptr) -{ - auto arg0 = (void*)ptr; - auto __ret = ((::CppSharp::CppParser::AST::ClassTemplate*)NativePtr)->FindSpecialization(arg0); - if (__ret == nullptr) return nullptr; - return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ClassTemplateSpecialization((::CppSharp::CppParser::AST::ClassTemplateSpecialization*)__ret); -} - -CppSharp::Parser::AST::ClassTemplateSpecialization^ CppSharp::Parser::AST::ClassTemplate::FindSpecialization(CppSharp::Parser::AST::TemplateSpecializationType^ type) -{ - auto arg0 = *(::CppSharp::CppParser::AST::TemplateSpecializationType*)type->NativePtr; - auto __ret = ((::CppSharp::CppParser::AST::ClassTemplate*)NativePtr)->FindSpecialization(arg0); - if (__ret == nullptr) return nullptr; - return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ClassTemplateSpecialization((::CppSharp::CppParser::AST::ClassTemplateSpecialization*)__ret); -} - -CppSharp::Parser::AST::ClassTemplatePartialSpecialization^ CppSharp::Parser::AST::ClassTemplate::FindPartialSpecialization(void* ptr) -{ - auto arg0 = (void*)ptr; - auto __ret = ((::CppSharp::CppParser::AST::ClassTemplate*)NativePtr)->FindPartialSpecialization(arg0); - if (__ret == nullptr) return nullptr; - return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ClassTemplatePartialSpecialization((::CppSharp::CppParser::AST::ClassTemplatePartialSpecialization*)__ret); -} - -CppSharp::Parser::AST::ClassTemplatePartialSpecialization^ CppSharp::Parser::AST::ClassTemplate::FindPartialSpecialization(CppSharp::Parser::AST::TemplateSpecializationType^ type) -{ - auto arg0 = *(::CppSharp::CppParser::AST::TemplateSpecializationType*)type->NativePtr; - auto __ret = ((::CppSharp::CppParser::AST::ClassTemplate*)NativePtr)->FindPartialSpecialization(arg0); - if (__ret == nullptr) return nullptr; - return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::ClassTemplatePartialSpecialization((::CppSharp::CppParser::AST::ClassTemplatePartialSpecialization*)__ret); -} - unsigned int CppSharp::Parser::AST::ClassTemplate::SpecializationsCount::get() { auto __ret = ((::CppSharp::CppParser::AST::ClassTemplate*)NativePtr)->getSpecializationsCount(); @@ -2423,6 +2441,100 @@ CppSharp::Parser::AST::FunctionTemplate::FunctionTemplate() NativePtr = new ::CppSharp::CppParser::AST::FunctionTemplate(); } +CppSharp::Parser::AST::FunctionTemplateSpecialization^ CppSharp::Parser::AST::FunctionTemplate::getSpecializations(unsigned int i) +{ + auto __ret = ((::CppSharp::CppParser::AST::FunctionTemplate*)NativePtr)->getSpecializations(i); + if (__ret == nullptr) return nullptr; + return (__ret == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::FunctionTemplateSpecialization((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)__ret); +} + +void CppSharp::Parser::AST::FunctionTemplate::addSpecializations(CppSharp::Parser::AST::FunctionTemplateSpecialization^ s) +{ + auto arg0 = (::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)s->NativePtr; + ((::CppSharp::CppParser::AST::FunctionTemplate*)NativePtr)->addSpecializations(arg0); +} + +unsigned int CppSharp::Parser::AST::FunctionTemplate::SpecializationsCount::get() +{ + auto __ret = ((::CppSharp::CppParser::AST::FunctionTemplate*)NativePtr)->getSpecializationsCount(); + return __ret; +} + +CppSharp::Parser::AST::FunctionTemplateSpecialization::FunctionTemplateSpecialization(::CppSharp::CppParser::AST::FunctionTemplateSpecialization* native) +{ + NativePtr = native; +} + +CppSharp::Parser::AST::FunctionTemplateSpecialization::FunctionTemplateSpecialization(System::IntPtr native) +{ + auto __native = (::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)native.ToPointer(); + NativePtr = __native; +} + +CppSharp::Parser::AST::FunctionTemplateSpecialization::FunctionTemplateSpecialization() +{ + NativePtr = new ::CppSharp::CppParser::AST::FunctionTemplateSpecialization(); +} + +CppSharp::Parser::AST::TemplateArgument^ CppSharp::Parser::AST::FunctionTemplateSpecialization::getArguments(unsigned int i) +{ + auto __ret = ((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->getArguments(i); + auto ____ret = new ::CppSharp::CppParser::AST::TemplateArgument(__ret); + return (____ret == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::TemplateArgument((::CppSharp::CppParser::AST::TemplateArgument*)____ret); +} + +void CppSharp::Parser::AST::FunctionTemplateSpecialization::addArguments(CppSharp::Parser::AST::TemplateArgument^ s) +{ + auto &arg0 = *(::CppSharp::CppParser::AST::TemplateArgument*)s->NativePtr; + ((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->addArguments(arg0); +} + +System::IntPtr CppSharp::Parser::AST::FunctionTemplateSpecialization::__Instance::get() +{ + return System::IntPtr(NativePtr); +} + +void CppSharp::Parser::AST::FunctionTemplateSpecialization::__Instance::set(System::IntPtr object) +{ + NativePtr = (::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)object.ToPointer(); +} + +unsigned int CppSharp::Parser::AST::FunctionTemplateSpecialization::ArgumentsCount::get() +{ + auto __ret = ((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->getArgumentsCount(); + return __ret; +} + +CppSharp::Parser::AST::FunctionTemplate^ CppSharp::Parser::AST::FunctionTemplateSpecialization::Template::get() +{ + return (((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->Template == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::FunctionTemplate((::CppSharp::CppParser::AST::FunctionTemplate*)((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->Template); +} + +void CppSharp::Parser::AST::FunctionTemplateSpecialization::Template::set(CppSharp::Parser::AST::FunctionTemplate^ value) +{ + ((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->Template = (::CppSharp::CppParser::AST::FunctionTemplate*)value->NativePtr; +} + +CppSharp::Parser::AST::Function^ CppSharp::Parser::AST::FunctionTemplateSpecialization::SpecializedFunction::get() +{ + return (((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->SpecializedFunction == nullptr) ? nullptr : gcnew CppSharp::Parser::AST::Function((::CppSharp::CppParser::AST::Function*)((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->SpecializedFunction); +} + +void CppSharp::Parser::AST::FunctionTemplateSpecialization::SpecializedFunction::set(CppSharp::Parser::AST::Function^ value) +{ + ((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->SpecializedFunction = (::CppSharp::CppParser::AST::Function*)value->NativePtr; +} + +CppSharp::Parser::AST::TemplateSpecializationKind CppSharp::Parser::AST::FunctionTemplateSpecialization::SpecializationKind::get() +{ + return (CppSharp::Parser::AST::TemplateSpecializationKind)((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->SpecializationKind; +} + +void CppSharp::Parser::AST::FunctionTemplateSpecialization::SpecializationKind::set(CppSharp::Parser::AST::TemplateSpecializationKind value) +{ + ((::CppSharp::CppParser::AST::FunctionTemplateSpecialization*)NativePtr)->SpecializationKind = (::CppSharp::CppParser::AST::TemplateSpecializationKind)value; +} + CppSharp::Parser::AST::Namespace::Namespace(::CppSharp::CppParser::AST::Namespace* native) : CppSharp::Parser::AST::DeclarationContext((::CppSharp::CppParser::AST::DeclarationContext*)native) { diff --git a/src/CppParser/Bindings/CLI/AST.h b/src/CppParser/Bindings/CLI/AST.h index dcd337d2..f95be264 100644 --- a/src/CppParser/Bindings/CLI/AST.h +++ b/src/CppParser/Bindings/CLI/AST.h @@ -43,6 +43,7 @@ namespace CppSharp ref class FullComment; ref class Function; ref class FunctionTemplate; + ref class FunctionTemplateSpecialization; ref class FunctionType; ref class InjectedClassNameType; ref class MacroDefinition; @@ -202,6 +203,15 @@ namespace CppSharp Unknown = 5 }; + public enum struct TemplateSpecializationKind + { + Undeclared = 0, + ImplicitInstantiation = 1, + ExplicitSpecialization = 2, + ExplicitInstantiationDeclaration = 3, + ExplicitInstantiationDefinition = 4 + }; + public enum struct CppAbi { Itanium = 0, @@ -221,15 +231,6 @@ namespace CppSharp UnusedFunctionPointer = 7 }; - public enum struct TemplateSpecializationKind - { - Undeclared = 0, - ImplicitInstantiation = 1, - ExplicitSpecialization = 2, - ExplicitInstantiationDeclaration = 3, - ExplicitInstantiationDefinition = 4 - }; - public enum struct PrimitiveType { Null = 0, @@ -658,6 +659,12 @@ namespace CppSharp void set(System::String^); } + property bool IsTypeParameter + { + bool get(); + void set(bool); + } + static bool operator==(CppSharp::Parser::AST::TemplateParameter^ __op, CppSharp::Parser::AST::TemplateParameter^ param); }; @@ -674,6 +681,24 @@ namespace CppSharp CppSharp::Parser::AST::TemplateParameter^ get(); void set(CppSharp::Parser::AST::TemplateParameter^); } + + property unsigned int Depth + { + unsigned int get(); + void set(unsigned int); + } + + property unsigned int Index + { + unsigned int get(); + void set(unsigned int); + } + + property bool IsParameterPack + { + bool get(); + void set(bool); + } }; public ref class TemplateParameterSubstitutionType : CppSharp::Parser::AST::Type @@ -1201,6 +1226,12 @@ namespace CppSharp void set(CppSharp::Parser::AST::CallingConvention); } + property CppSharp::Parser::AST::FunctionTemplateSpecialization^ SpecializationInfo + { + CppSharp::Parser::AST::FunctionTemplateSpecialization^ get(); + void set(CppSharp::Parser::AST::FunctionTemplateSpecialization^); + } + CppSharp::Parser::AST::Parameter^ getParameters(unsigned int i); void addParameters(CppSharp::Parser::AST::Parameter^ s); @@ -1590,14 +1621,6 @@ namespace CppSharp CppSharp::Parser::AST::ClassTemplateSpecialization^ getSpecializations(unsigned int i); void addSpecializations(CppSharp::Parser::AST::ClassTemplateSpecialization^ s); - - CppSharp::Parser::AST::ClassTemplateSpecialization^ FindSpecialization(void* ptr); - - CppSharp::Parser::AST::ClassTemplateSpecialization^ FindSpecialization(CppSharp::Parser::AST::TemplateSpecializationType^ type); - - CppSharp::Parser::AST::ClassTemplatePartialSpecialization^ FindPartialSpecialization(void* ptr); - - CppSharp::Parser::AST::ClassTemplatePartialSpecialization^ FindPartialSpecialization(CppSharp::Parser::AST::TemplateSpecializationType^ type); }; public ref class ClassTemplateSpecialization : CppSharp::Parser::AST::Class @@ -1646,6 +1669,58 @@ namespace CppSharp FunctionTemplate(::CppSharp::CppParser::AST::FunctionTemplate* native); FunctionTemplate(System::IntPtr native); FunctionTemplate(); + + property unsigned int SpecializationsCount + { + unsigned int get(); + } + + CppSharp::Parser::AST::FunctionTemplateSpecialization^ getSpecializations(unsigned int i); + + void addSpecializations(CppSharp::Parser::AST::FunctionTemplateSpecialization^ s); + }; + + public ref class FunctionTemplateSpecialization : ICppInstance + { + public: + + property ::CppSharp::CppParser::AST::FunctionTemplateSpecialization* NativePtr; + property System::IntPtr __Instance + { + virtual System::IntPtr get(); + virtual void set(System::IntPtr instance); + } + + FunctionTemplateSpecialization(::CppSharp::CppParser::AST::FunctionTemplateSpecialization* native); + FunctionTemplateSpecialization(System::IntPtr native); + FunctionTemplateSpecialization(); + + property unsigned int ArgumentsCount + { + unsigned int get(); + } + + property CppSharp::Parser::AST::FunctionTemplate^ Template + { + CppSharp::Parser::AST::FunctionTemplate^ get(); + void set(CppSharp::Parser::AST::FunctionTemplate^); + } + + property CppSharp::Parser::AST::Function^ SpecializedFunction + { + CppSharp::Parser::AST::Function^ get(); + void set(CppSharp::Parser::AST::Function^); + } + + property CppSharp::Parser::AST::TemplateSpecializationKind SpecializationKind + { + CppSharp::Parser::AST::TemplateSpecializationKind get(); + void set(CppSharp::Parser::AST::TemplateSpecializationKind); + } + + CppSharp::Parser::AST::TemplateArgument^ getArguments(unsigned int i); + + void addArguments(CppSharp::Parser::AST::TemplateArgument^ s); }; public ref class Namespace : CppSharp::Parser::AST::DeclarationContext diff --git a/src/CppParser/Bindings/CSharp/AST.cs b/src/CppParser/Bindings/CSharp/AST.cs index 93da0fe2..75655d9a 100644 --- a/src/CppParser/Bindings/CSharp/AST.cs +++ b/src/CppParser/Bindings/CSharp/AST.cs @@ -131,6 +131,15 @@ namespace CppSharp Unknown = 5 } + public enum TemplateSpecializationKind + { + Undeclared = 0, + ImplicitInstantiation = 1, + ExplicitSpecialization = 2, + ExplicitInstantiationDeclaration = 3, + ExplicitInstantiationDefinition = 4 + } + public enum CppAbi { Itanium = 0, @@ -150,15 +159,6 @@ namespace CppSharp UnusedFunctionPointer = 7 } - public enum TemplateSpecializationKind - { - Undeclared = 0, - ImplicitInstantiation = 1, - ExplicitSpecialization = 2, - ExplicitInstantiationDeclaration = 3, - ExplicitInstantiationDefinition = 4 - } - public enum PrimitiveType { Null = 0, @@ -1498,9 +1498,12 @@ namespace CppSharp public unsafe partial class TemplateParameter : IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 24)] + [StructLayout(LayoutKind.Explicit, Size = 28)] public struct Internal { + [FieldOffset(24)] + public bool IsTypeParameter; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="??0TemplateParameter@AST@CppParser@CppSharp@@QAE@XZ")] @@ -1552,7 +1555,7 @@ namespace CppSharp public TemplateParameter() { - __Instance = Marshal.AllocHGlobal(24); + __Instance = Marshal.AllocHGlobal(28); Internal.ctor_0(__Instance); } @@ -1597,11 +1600,26 @@ namespace CppSharp Marshal.FreeHGlobal(arg0); } } + + public bool IsTypeParameter + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return __ptr->IsTypeParameter; + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->IsTypeParameter = value; + } + } } public unsafe partial class TemplateParameterType : CppSharp.Parser.AST.Type, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 32)] + [StructLayout(LayoutKind.Explicit, Size = 48)] public new struct Internal { [FieldOffset(0)] @@ -1613,6 +1631,15 @@ namespace CppSharp [FieldOffset(8)] public CppSharp.Parser.AST.TemplateParameter.Internal Parameter; + [FieldOffset(36)] + public uint Depth; + + [FieldOffset(40)] + public uint Index; + + [FieldOffset(44)] + public bool IsParameterPack; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="??0TemplateParameterType@AST@CppParser@CppSharp@@QAE@XZ")] @@ -1647,7 +1674,7 @@ namespace CppSharp public TemplateParameterType() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(32); + __Instance = Marshal.AllocHGlobal(48); Internal.ctor_0(__Instance); } @@ -1661,7 +1688,7 @@ namespace CppSharp get { var __ptr = (Internal*)__Instance.ToPointer(); - var __instance = Marshal.AllocHGlobal(24); + var __instance = Marshal.AllocHGlobal(28); CppSharp.Parser.AST.TemplateParameter.Internal.cctor_1(__instance, new global::System.IntPtr(&__ptr->Parameter)); return (__instance == IntPtr.Zero) ? null : new CppSharp.Parser.AST.TemplateParameter(__instance); } @@ -1672,6 +1699,51 @@ namespace CppSharp __ptr->Parameter = ReferenceEquals(value, null) ? new CppSharp.Parser.AST.TemplateParameter.Internal() : *(CppSharp.Parser.AST.TemplateParameter.Internal*) (value.__Instance); } } + + public uint Depth + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return __ptr->Depth; + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->Depth = value; + } + } + + public uint Index + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return __ptr->Index; + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->Index = value; + } + } + + public bool IsParameterPack + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return __ptr->IsParameterPack; + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->IsParameterPack = value; + } + } } public unsafe partial class TemplateParameterSubstitutionType : CppSharp.Parser.AST.Type, IDisposable @@ -2563,7 +2635,7 @@ namespace CppSharp public unsafe partial class Declaration : IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 92)] + [StructLayout(LayoutKind.Explicit, Size = 116)] public struct Internal { [FieldOffset(0)] @@ -2663,7 +2735,7 @@ namespace CppSharp public Declaration(CppSharp.Parser.AST.DeclarationKind kind) { - __Instance = Marshal.AllocHGlobal(92); + __Instance = Marshal.AllocHGlobal(116); var arg0 = kind; Internal.ctor_0(__Instance, arg0); } @@ -2874,7 +2946,7 @@ namespace CppSharp public unsafe partial class DeclarationContext : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 188)] + [StructLayout(LayoutKind.Explicit, Size = 212)] public new struct Internal { [FieldOffset(0)] @@ -2904,7 +2976,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(184)] + [FieldOffset(208)] public bool IsAnonymous; [SuppressUnmanagedCodeSecurity] @@ -2912,15 +2984,10 @@ namespace CppSharp EntryPoint="??0DeclarationContext@AST@CppParser@CppSharp@@QAE@W4DeclarationKind@123@@Z")] internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance, CppSharp.Parser.AST.DeclarationKind kind); - [SuppressUnmanagedCodeSecurity] - [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, - EntryPoint="??0DeclarationContext@AST@CppParser@CppSharp@@QAE@XZ")] - internal static extern global::System.IntPtr ctor_1(global::System.IntPtr instance); - [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="??0DeclarationContext@AST@CppParser@CppSharp@@QAE@ABU0123@@Z")] - internal static extern global::System.IntPtr cctor_3(global::System.IntPtr instance, global::System.IntPtr _0); + internal static extern global::System.IntPtr cctor_2(global::System.IntPtr instance, global::System.IntPtr _0); [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, @@ -3051,18 +3118,11 @@ namespace CppSharp public DeclarationContext(CppSharp.Parser.AST.DeclarationKind kind) : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(188); + __Instance = Marshal.AllocHGlobal(212); var arg0 = kind; Internal.ctor_0(__Instance, arg0); } - public DeclarationContext() - : this(IntPtr.Zero) - { - __Instance = Marshal.AllocHGlobal(188); - Internal.ctor_1(__Instance); - } - protected override void Dispose(bool disposing) { base.Dispose(disposing); @@ -3240,7 +3300,7 @@ namespace CppSharp public unsafe partial class TypedefDecl : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 100)] + [StructLayout(LayoutKind.Explicit, Size = 124)] public new struct Internal { [FieldOffset(0)] @@ -3270,7 +3330,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; [SuppressUnmanagedCodeSecurity] @@ -3307,7 +3367,7 @@ namespace CppSharp public TypedefDecl() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(100); + __Instance = Marshal.AllocHGlobal(124); Internal.ctor_0(__Instance); } @@ -3336,7 +3396,7 @@ namespace CppSharp public unsafe partial class Parameter : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 108)] + [StructLayout(LayoutKind.Explicit, Size = 132)] public new struct Internal { [FieldOffset(0)] @@ -3366,16 +3426,16 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; - [FieldOffset(100)] + [FieldOffset(124)] public bool IsIndirect; - [FieldOffset(101)] + [FieldOffset(125)] public bool HasDefaultValue; - [FieldOffset(104)] + [FieldOffset(128)] public uint Index; [SuppressUnmanagedCodeSecurity] @@ -3412,7 +3472,7 @@ namespace CppSharp public Parameter() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(108); + __Instance = Marshal.AllocHGlobal(132); Internal.ctor_0(__Instance); } @@ -3486,7 +3546,7 @@ namespace CppSharp public unsafe partial class Function : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 176)] + [StructLayout(LayoutKind.Explicit, Size = 204)] public new struct Internal { [FieldOffset(0)] @@ -3516,30 +3576,33 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.QualifiedType.Internal ReturnType; - [FieldOffset(100)] + [FieldOffset(124)] public bool IsReturnIndirect; - [FieldOffset(101)] + [FieldOffset(125)] public bool IsVariadic; - [FieldOffset(102)] + [FieldOffset(126)] public bool IsInline; - [FieldOffset(103)] + [FieldOffset(127)] public bool IsPure; - [FieldOffset(104)] + [FieldOffset(128)] public bool IsDeleted; - [FieldOffset(108)] + [FieldOffset(132)] public CppSharp.Parser.AST.CXXOperatorKind OperatorKind; - [FieldOffset(160)] + [FieldOffset(184)] public CppSharp.Parser.AST.CallingConvention CallingConvention; + [FieldOffset(200)] + public global::System.IntPtr SpecializationInfo; + [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="??0Function@AST@CppParser@CppSharp@@QAE@XZ")] @@ -3609,7 +3672,7 @@ namespace CppSharp public Function() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(176); + __Instance = Marshal.AllocHGlobal(204); Internal.ctor_0(__Instance); } @@ -3795,11 +3858,26 @@ namespace CppSharp __ptr->CallingConvention = value; } } + + public CppSharp.Parser.AST.FunctionTemplateSpecialization SpecializationInfo + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return (__ptr->SpecializationInfo == IntPtr.Zero) ? null : new CppSharp.Parser.AST.FunctionTemplateSpecialization(__ptr->SpecializationInfo); + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->SpecializationInfo = value == (CppSharp.Parser.AST.FunctionTemplateSpecialization) null ? global::System.IntPtr.Zero : value.__Instance; + } + } } public unsafe partial class Method : CppSharp.Parser.AST.Function, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 204)] + [StructLayout(LayoutKind.Explicit, Size = 232)] public new struct Internal { [FieldOffset(0)] @@ -3829,64 +3907,67 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.QualifiedType.Internal ReturnType; - [FieldOffset(100)] + [FieldOffset(124)] public bool IsReturnIndirect; - [FieldOffset(101)] + [FieldOffset(125)] public bool IsVariadic; - [FieldOffset(102)] + [FieldOffset(126)] public bool IsInline; - [FieldOffset(103)] + [FieldOffset(127)] public bool IsPure; - [FieldOffset(104)] + [FieldOffset(128)] public bool IsDeleted; - [FieldOffset(108)] + [FieldOffset(132)] public CppSharp.Parser.AST.CXXOperatorKind OperatorKind; - [FieldOffset(160)] + [FieldOffset(184)] public CppSharp.Parser.AST.CallingConvention CallingConvention; - [FieldOffset(176)] + [FieldOffset(200)] + public global::System.IntPtr SpecializationInfo; + + [FieldOffset(204)] public global::System.IntPtr AccessDecl; - [FieldOffset(180)] + [FieldOffset(208)] public bool IsVirtual; - [FieldOffset(181)] + [FieldOffset(209)] public bool IsStatic; - [FieldOffset(182)] + [FieldOffset(210)] public bool IsConst; - [FieldOffset(183)] + [FieldOffset(211)] public bool IsImplicit; - [FieldOffset(184)] + [FieldOffset(212)] public bool IsExplicit; - [FieldOffset(185)] + [FieldOffset(213)] public bool IsOverride; - [FieldOffset(188)] + [FieldOffset(216)] public CppSharp.Parser.AST.CXXMethodKind MethodKind; - [FieldOffset(192)] + [FieldOffset(220)] public bool IsDefaultConstructor; - [FieldOffset(193)] + [FieldOffset(221)] public bool IsCopyConstructor; - [FieldOffset(194)] + [FieldOffset(222)] public bool IsMoveConstructor; - [FieldOffset(196)] + [FieldOffset(224)] public CppSharp.Parser.AST.QualifiedType.Internal ConversionType; [SuppressUnmanagedCodeSecurity] @@ -3923,7 +4004,7 @@ namespace CppSharp public Method() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(204); + __Instance = Marshal.AllocHGlobal(232); Internal.ctor_0(__Instance); } @@ -4117,7 +4198,7 @@ namespace CppSharp public unsafe partial class Enumeration : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 116)] + [StructLayout(LayoutKind.Explicit, Size = 140)] public new struct Internal { [FieldOffset(0)] @@ -4147,13 +4228,13 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.Enumeration.EnumModifiers Modifiers; - [FieldOffset(96)] + [FieldOffset(120)] public global::System.IntPtr Type; - [FieldOffset(100)] + [FieldOffset(124)] public global::System.IntPtr BuiltinType; [SuppressUnmanagedCodeSecurity] @@ -4197,7 +4278,7 @@ namespace CppSharp public unsafe partial class Item : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 128)] + [StructLayout(LayoutKind.Explicit, Size = 152)] public new struct Internal { [FieldOffset(0)] @@ -4227,7 +4308,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(120)] + [FieldOffset(144)] public ulong Value; [SuppressUnmanagedCodeSecurity] @@ -4274,7 +4355,7 @@ namespace CppSharp public Item() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(128); + __Instance = Marshal.AllocHGlobal(152); Internal.ctor_0(__Instance); } @@ -4334,7 +4415,7 @@ namespace CppSharp public Enumeration() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(116); + __Instance = Marshal.AllocHGlobal(140); Internal.ctor_0(__Instance); } @@ -4347,7 +4428,7 @@ namespace CppSharp { var __ret = new CppSharp.Parser.AST.Enumeration.Item.Internal(); Internal.getItems_0(__Instance, new IntPtr(&__ret), i); - var __instance = Marshal.AllocHGlobal(128); + var __instance = Marshal.AllocHGlobal(152); CppSharp.Parser.AST.Enumeration.Item.Internal.cctor_1(__instance, new global::System.IntPtr(&__ret)); return (__instance == IntPtr.Zero) ? null : new CppSharp.Parser.AST.Enumeration.Item(__instance); } @@ -4415,7 +4496,7 @@ namespace CppSharp public unsafe partial class Variable : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 124)] + [StructLayout(LayoutKind.Explicit, Size = 148)] public new struct Internal { [FieldOffset(0)] @@ -4445,7 +4526,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(116)] + [FieldOffset(140)] public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; [SuppressUnmanagedCodeSecurity] @@ -4492,7 +4573,7 @@ namespace CppSharp public Variable() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(124); + __Instance = Marshal.AllocHGlobal(148); Internal.ctor_0(__Instance); } @@ -4643,7 +4724,7 @@ namespace CppSharp public unsafe partial class Field : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 108)] + [StructLayout(LayoutKind.Explicit, Size = 132)] public new struct Internal { [FieldOffset(0)] @@ -4673,13 +4754,13 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.QualifiedType.Internal QualifiedType; - [FieldOffset(100)] + [FieldOffset(124)] public uint Offset; - [FieldOffset(104)] + [FieldOffset(128)] public global::System.IntPtr Class; [SuppressUnmanagedCodeSecurity] @@ -4716,7 +4797,7 @@ namespace CppSharp public Field() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(108); + __Instance = Marshal.AllocHGlobal(132); Internal.ctor_0(__Instance); } @@ -4775,7 +4856,7 @@ namespace CppSharp public unsafe partial class AccessSpecifierDecl : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 92)] + [StructLayout(LayoutKind.Explicit, Size = 116)] public new struct Internal { [FieldOffset(0)] @@ -4839,7 +4920,7 @@ namespace CppSharp public AccessSpecifierDecl() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(92); + __Instance = Marshal.AllocHGlobal(116); Internal.ctor_0(__Instance); } @@ -4851,7 +4932,7 @@ namespace CppSharp public unsafe partial class Class : CppSharp.Parser.AST.DeclarationContext, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 252)] + [StructLayout(LayoutKind.Explicit, Size = 276)] public new struct Internal { [FieldOffset(0)] @@ -4881,37 +4962,37 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(184)] + [FieldOffset(208)] public bool IsAnonymous; - [FieldOffset(236)] + [FieldOffset(260)] public bool IsPOD; - [FieldOffset(237)] + [FieldOffset(261)] public bool IsAbstract; - [FieldOffset(238)] + [FieldOffset(262)] public bool IsUnion; - [FieldOffset(239)] + [FieldOffset(263)] public bool IsDynamic; - [FieldOffset(240)] + [FieldOffset(264)] public bool IsPolymorphic; - [FieldOffset(241)] + [FieldOffset(265)] public bool HasNonTrivialDefaultConstructor; - [FieldOffset(242)] + [FieldOffset(266)] public bool HasNonTrivialCopyConstructor; - [FieldOffset(243)] + [FieldOffset(267)] public bool HasNonTrivialDestructor; - [FieldOffset(244)] + [FieldOffset(268)] public bool IsExternCContext; - [FieldOffset(248)] + [FieldOffset(272)] public global::System.IntPtr Layout; [SuppressUnmanagedCodeSecurity] @@ -5008,7 +5089,7 @@ namespace CppSharp public Class() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(252); + __Instance = Marshal.AllocHGlobal(276); Internal.ctor_0(__Instance); } @@ -5258,7 +5339,7 @@ namespace CppSharp public unsafe partial class Template : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 108)] + [StructLayout(LayoutKind.Explicit, Size = 132)] public new struct Internal { [FieldOffset(0)] @@ -5288,7 +5369,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public global::System.IntPtr TemplatedDecl; [SuppressUnmanagedCodeSecurity] @@ -5345,7 +5426,7 @@ namespace CppSharp public Template(CppSharp.Parser.AST.DeclarationKind kind) : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(108); + __Instance = Marshal.AllocHGlobal(132); var arg0 = kind; Internal.ctor_0(__Instance, arg0); } @@ -5353,7 +5434,7 @@ namespace CppSharp public Template() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(108); + __Instance = Marshal.AllocHGlobal(132); Internal.ctor_1(__Instance); } @@ -5366,7 +5447,7 @@ namespace CppSharp { var __ret = new CppSharp.Parser.AST.TemplateParameter.Internal(); Internal.getParameters_0(__Instance, new IntPtr(&__ret), i); - var __instance = Marshal.AllocHGlobal(24); + var __instance = Marshal.AllocHGlobal(28); CppSharp.Parser.AST.TemplateParameter.Internal.cctor_1(__instance, new global::System.IntPtr(&__ret)); return (__instance == IntPtr.Zero) ? null : new CppSharp.Parser.AST.TemplateParameter(__instance); } @@ -5404,7 +5485,7 @@ namespace CppSharp public unsafe partial class ClassTemplate : CppSharp.Parser.AST.Template, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 120)] + [StructLayout(LayoutKind.Explicit, Size = 144)] public new struct Internal { [FieldOffset(0)] @@ -5434,7 +5515,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public global::System.IntPtr TemplatedDecl; [SuppressUnmanagedCodeSecurity] @@ -5462,26 +5543,6 @@ namespace CppSharp EntryPoint="?addSpecializations@ClassTemplate@AST@CppParser@CppSharp@@QAEXAAPAUClassTemplateSpecialization@234@@Z")] internal static extern void addSpecializations_0(global::System.IntPtr instance, global::System.IntPtr s); - [SuppressUnmanagedCodeSecurity] - [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, - EntryPoint="?FindSpecialization@ClassTemplate@AST@CppParser@CppSharp@@QAEPAUClassTemplateSpecialization@234@PAX@Z")] - internal static extern global::System.IntPtr FindSpecialization_0(global::System.IntPtr instance, void* ptr); - - [SuppressUnmanagedCodeSecurity] - [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, - EntryPoint="?FindSpecialization@ClassTemplate@AST@CppParser@CppSharp@@QAEPAUClassTemplateSpecialization@234@UTemplateSpecializationType@234@@Z")] - internal static extern global::System.IntPtr FindSpecialization_1(global::System.IntPtr instance, CppSharp.Parser.AST.TemplateSpecializationType.Internal type); - - [SuppressUnmanagedCodeSecurity] - [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, - EntryPoint="?FindPartialSpecialization@ClassTemplate@AST@CppParser@CppSharp@@QAEPAUClassTemplatePartialSpecialization@234@PAX@Z")] - internal static extern global::System.IntPtr FindPartialSpecialization_0(global::System.IntPtr instance, void* ptr); - - [SuppressUnmanagedCodeSecurity] - [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, - EntryPoint="?FindPartialSpecialization@ClassTemplate@AST@CppParser@CppSharp@@QAEPAUClassTemplatePartialSpecialization@234@UTemplateSpecializationType@234@@Z")] - internal static extern global::System.IntPtr FindPartialSpecialization_1(global::System.IntPtr instance, CppSharp.Parser.AST.TemplateSpecializationType.Internal type); - [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="?getSpecializationsCount@ClassTemplate@AST@CppParser@CppSharp@@QAEIXZ")] @@ -5506,7 +5567,7 @@ namespace CppSharp public ClassTemplate() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(120); + __Instance = Marshal.AllocHGlobal(144); Internal.ctor_0(__Instance); } @@ -5528,38 +5589,6 @@ namespace CppSharp Internal.addSpecializations_0(__Instance, arg0); } - public CppSharp.Parser.AST.ClassTemplateSpecialization FindSpecialization(void* ptr) - { - var arg0 = ptr; - var __ret = Internal.FindSpecialization_0(__Instance, arg0); - if (__ret == global::System.IntPtr.Zero) return null; - return (__ret == IntPtr.Zero) ? null : new CppSharp.Parser.AST.ClassTemplateSpecialization(__ret); - } - - public CppSharp.Parser.AST.ClassTemplateSpecialization FindSpecialization(CppSharp.Parser.AST.TemplateSpecializationType type) - { - var arg0 = ReferenceEquals(type, null) ? new CppSharp.Parser.AST.TemplateSpecializationType.Internal() : *(CppSharp.Parser.AST.TemplateSpecializationType.Internal*) (type.__Instance); - var __ret = Internal.FindSpecialization_1(__Instance, arg0); - if (__ret == global::System.IntPtr.Zero) return null; - return (__ret == IntPtr.Zero) ? null : new CppSharp.Parser.AST.ClassTemplateSpecialization(__ret); - } - - public CppSharp.Parser.AST.ClassTemplatePartialSpecialization FindPartialSpecialization(void* ptr) - { - var arg0 = ptr; - var __ret = Internal.FindPartialSpecialization_0(__Instance, arg0); - if (__ret == global::System.IntPtr.Zero) return null; - return (__ret == IntPtr.Zero) ? null : new CppSharp.Parser.AST.ClassTemplatePartialSpecialization(__ret); - } - - public CppSharp.Parser.AST.ClassTemplatePartialSpecialization FindPartialSpecialization(CppSharp.Parser.AST.TemplateSpecializationType type) - { - var arg0 = ReferenceEquals(type, null) ? new CppSharp.Parser.AST.TemplateSpecializationType.Internal() : *(CppSharp.Parser.AST.TemplateSpecializationType.Internal*) (type.__Instance); - var __ret = Internal.FindPartialSpecialization_1(__Instance, arg0); - if (__ret == global::System.IntPtr.Zero) return null; - return (__ret == IntPtr.Zero) ? null : new CppSharp.Parser.AST.ClassTemplatePartialSpecialization(__ret); - } - public uint SpecializationsCount { get @@ -5572,7 +5601,7 @@ namespace CppSharp public unsafe partial class ClassTemplateSpecialization : CppSharp.Parser.AST.Class, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 272)] + [StructLayout(LayoutKind.Explicit, Size = 296)] public new struct Internal { [FieldOffset(0)] @@ -5602,43 +5631,43 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(184)] + [FieldOffset(208)] public bool IsAnonymous; - [FieldOffset(236)] + [FieldOffset(260)] public bool IsPOD; - [FieldOffset(237)] + [FieldOffset(261)] public bool IsAbstract; - [FieldOffset(238)] + [FieldOffset(262)] public bool IsUnion; - [FieldOffset(239)] + [FieldOffset(263)] public bool IsDynamic; - [FieldOffset(240)] + [FieldOffset(264)] public bool IsPolymorphic; - [FieldOffset(241)] + [FieldOffset(265)] public bool HasNonTrivialDefaultConstructor; - [FieldOffset(242)] + [FieldOffset(266)] public bool HasNonTrivialCopyConstructor; - [FieldOffset(243)] + [FieldOffset(267)] public bool HasNonTrivialDestructor; - [FieldOffset(244)] + [FieldOffset(268)] public bool IsExternCContext; - [FieldOffset(248)] + [FieldOffset(272)] public global::System.IntPtr Layout; - [FieldOffset(252)] + [FieldOffset(276)] public global::System.IntPtr TemplatedDecl; - [FieldOffset(268)] + [FieldOffset(292)] public CppSharp.Parser.AST.TemplateSpecializationKind SpecializationKind; [SuppressUnmanagedCodeSecurity] @@ -5690,7 +5719,7 @@ namespace CppSharp public ClassTemplateSpecialization() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(272); + __Instance = Marshal.AllocHGlobal(296); Internal.ctor_0(__Instance); } @@ -5756,7 +5785,7 @@ namespace CppSharp public unsafe partial class ClassTemplatePartialSpecialization : CppSharp.Parser.AST.ClassTemplateSpecialization, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 272)] + [StructLayout(LayoutKind.Explicit, Size = 296)] public new struct Internal { [FieldOffset(0)] @@ -5786,43 +5815,43 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(184)] + [FieldOffset(208)] public bool IsAnonymous; - [FieldOffset(236)] + [FieldOffset(260)] public bool IsPOD; - [FieldOffset(237)] + [FieldOffset(261)] public bool IsAbstract; - [FieldOffset(238)] + [FieldOffset(262)] public bool IsUnion; - [FieldOffset(239)] + [FieldOffset(263)] public bool IsDynamic; - [FieldOffset(240)] + [FieldOffset(264)] public bool IsPolymorphic; - [FieldOffset(241)] + [FieldOffset(265)] public bool HasNonTrivialDefaultConstructor; - [FieldOffset(242)] + [FieldOffset(266)] public bool HasNonTrivialCopyConstructor; - [FieldOffset(243)] + [FieldOffset(267)] public bool HasNonTrivialDestructor; - [FieldOffset(244)] + [FieldOffset(268)] public bool IsExternCContext; - [FieldOffset(248)] + [FieldOffset(272)] public global::System.IntPtr Layout; - [FieldOffset(252)] + [FieldOffset(276)] public global::System.IntPtr TemplatedDecl; - [FieldOffset(268)] + [FieldOffset(292)] public CppSharp.Parser.AST.TemplateSpecializationKind SpecializationKind; [SuppressUnmanagedCodeSecurity] @@ -5859,7 +5888,7 @@ namespace CppSharp public ClassTemplatePartialSpecialization() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(272); + __Instance = Marshal.AllocHGlobal(296); Internal.ctor_0(__Instance); } @@ -5871,7 +5900,7 @@ namespace CppSharp public unsafe partial class FunctionTemplate : CppSharp.Parser.AST.Template, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 108)] + [StructLayout(LayoutKind.Explicit, Size = 144)] public new struct Internal { [FieldOffset(0)] @@ -5901,7 +5930,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public global::System.IntPtr TemplatedDecl; [SuppressUnmanagedCodeSecurity] @@ -5912,12 +5941,27 @@ namespace CppSharp [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="??0FunctionTemplate@AST@CppParser@CppSharp@@QAE@ABU0123@@Z")] - internal static extern global::System.IntPtr cctor_1(global::System.IntPtr instance, global::System.IntPtr _0); + internal static extern global::System.IntPtr cctor_2(global::System.IntPtr instance, global::System.IntPtr _0); [SuppressUnmanagedCodeSecurity] [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, EntryPoint="??1FunctionTemplate@AST@CppParser@CppSharp@@QAE@XZ")] internal static extern void dtor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?getSpecializations@FunctionTemplate@AST@CppParser@CppSharp@@QAEPAUFunctionTemplateSpecialization@234@I@Z")] + internal static extern global::System.IntPtr getSpecializations_0(global::System.IntPtr instance, uint i); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?addSpecializations@FunctionTemplate@AST@CppParser@CppSharp@@QAEXAAPAUFunctionTemplateSpecialization@234@@Z")] + internal static extern void addSpecializations_0(global::System.IntPtr instance, global::System.IntPtr s); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?getSpecializationsCount@FunctionTemplate@AST@CppParser@CppSharp@@QAEIXZ")] + internal static extern uint getSpecializationsCount_0(global::System.IntPtr instance); } internal FunctionTemplate(FunctionTemplate.Internal* native) @@ -5938,7 +5982,7 @@ namespace CppSharp public FunctionTemplate() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(108); + __Instance = Marshal.AllocHGlobal(144); Internal.ctor_0(__Instance); } @@ -5946,11 +5990,183 @@ namespace CppSharp { base.Dispose(disposing); } + + public CppSharp.Parser.AST.FunctionTemplateSpecialization getSpecializations(uint i) + { + var __ret = Internal.getSpecializations_0(__Instance, i); + if (__ret == global::System.IntPtr.Zero) return null; + return (__ret == IntPtr.Zero) ? null : new CppSharp.Parser.AST.FunctionTemplateSpecialization(__ret); + } + + public void addSpecializations(CppSharp.Parser.AST.FunctionTemplateSpecialization s) + { + var arg0 = s == (CppSharp.Parser.AST.FunctionTemplateSpecialization) null ? global::System.IntPtr.Zero : s.__Instance; + Internal.addSpecializations_0(__Instance, arg0); + } + + public uint SpecializationsCount + { + get + { + var __ret = Internal.getSpecializationsCount_0(__Instance); + return __ret; + } + } + } + + public unsafe partial class FunctionTemplateSpecialization : IDisposable + { + [StructLayout(LayoutKind.Explicit, Size = 24)] + public struct Internal + { + [FieldOffset(0)] + public global::System.IntPtr Template; + + [FieldOffset(16)] + public global::System.IntPtr SpecializedFunction; + + [FieldOffset(20)] + public CppSharp.Parser.AST.TemplateSpecializationKind SpecializationKind; + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="??0FunctionTemplateSpecialization@AST@CppParser@CppSharp@@QAE@XZ")] + internal static extern global::System.IntPtr ctor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="??0FunctionTemplateSpecialization@AST@CppParser@CppSharp@@QAE@ABU0123@@Z")] + internal static extern global::System.IntPtr cctor_2(global::System.IntPtr instance, global::System.IntPtr _0); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="??1FunctionTemplateSpecialization@AST@CppParser@CppSharp@@QAE@XZ")] + internal static extern void dtor_0(global::System.IntPtr instance); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?getArguments@FunctionTemplateSpecialization@AST@CppParser@CppSharp@@QAE?AUTemplateArgument@234@I@Z")] + internal static extern void getArguments_0(global::System.IntPtr instance, global::System.IntPtr @return, uint i); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?addArguments@FunctionTemplateSpecialization@AST@CppParser@CppSharp@@QAEXAAUTemplateArgument@234@@Z")] + internal static extern void addArguments_0(global::System.IntPtr instance, global::System.IntPtr s); + + [SuppressUnmanagedCodeSecurity] + [DllImport("CppSharp.CppParser.dll", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.ThisCall, + EntryPoint="?getArgumentsCount@FunctionTemplateSpecialization@AST@CppParser@CppSharp@@QAEIXZ")] + internal static extern uint getArgumentsCount_0(global::System.IntPtr instance); + } + + public global::System.IntPtr __Instance { get; protected set; } + + internal FunctionTemplateSpecialization(FunctionTemplateSpecialization.Internal* native) + : this(new global::System.IntPtr(native)) + { + } + + internal FunctionTemplateSpecialization(FunctionTemplateSpecialization.Internal native) + : this(&native) + { + } + + public FunctionTemplateSpecialization(global::System.IntPtr native, bool isInternalImpl = false) + { + __Instance = native; + } + + public FunctionTemplateSpecialization() + { + __Instance = Marshal.AllocHGlobal(24); + Internal.ctor_0(__Instance); + } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + Internal.dtor_0(__Instance); + Marshal.FreeHGlobal(__Instance); + } + + public CppSharp.Parser.AST.TemplateArgument getArguments(uint i) + { + var __ret = new CppSharp.Parser.AST.TemplateArgument.Internal(); + Internal.getArguments_0(__Instance, new IntPtr(&__ret), i); + var __instance = Marshal.AllocHGlobal(20); + CppSharp.Runtime.Helpers.memcpy(__instance, new IntPtr(&__ret), new UIntPtr(20)); + return (__instance == IntPtr.Zero) ? null : new CppSharp.Parser.AST.TemplateArgument(__instance); + } + + public void addArguments(CppSharp.Parser.AST.TemplateArgument s) + { + var arg0 = s == (CppSharp.Parser.AST.TemplateArgument) null ? global::System.IntPtr.Zero : s.__Instance; + Internal.addArguments_0(__Instance, arg0); + } + + public uint ArgumentsCount + { + get + { + var __ret = Internal.getArgumentsCount_0(__Instance); + return __ret; + } + } + + public CppSharp.Parser.AST.FunctionTemplate Template + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return (__ptr->Template == IntPtr.Zero) ? null : new CppSharp.Parser.AST.FunctionTemplate(__ptr->Template); + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->Template = value == (CppSharp.Parser.AST.FunctionTemplate) null ? global::System.IntPtr.Zero : value.__Instance; + } + } + + public CppSharp.Parser.AST.Function SpecializedFunction + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return (__ptr->SpecializedFunction == IntPtr.Zero) ? null : new CppSharp.Parser.AST.Function(__ptr->SpecializedFunction); + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->SpecializedFunction = value == (CppSharp.Parser.AST.Function) null ? global::System.IntPtr.Zero : value.__Instance; + } + } + + public CppSharp.Parser.AST.TemplateSpecializationKind SpecializationKind + { + get + { + var __ptr = (Internal*)__Instance.ToPointer(); + return __ptr->SpecializationKind; + } + + set + { + var __ptr = (Internal*)__Instance.ToPointer(); + __ptr->SpecializationKind = value; + } + } } public unsafe partial class Namespace : CppSharp.Parser.AST.DeclarationContext, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 192)] + [StructLayout(LayoutKind.Explicit, Size = 216)] public new struct Internal { [FieldOffset(0)] @@ -5980,10 +6196,10 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(184)] + [FieldOffset(208)] public bool IsAnonymous; - [FieldOffset(188)] + [FieldOffset(212)] public bool IsInline; [SuppressUnmanagedCodeSecurity] @@ -6020,7 +6236,7 @@ namespace CppSharp public Namespace() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(192); + __Instance = Marshal.AllocHGlobal(216); Internal.ctor_0(__Instance); } @@ -6047,7 +6263,7 @@ namespace CppSharp public unsafe partial class PreprocessedEntity : CppSharp.Parser.AST.Declaration, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 96)] + [StructLayout(LayoutKind.Explicit, Size = 120)] public new struct Internal { [FieldOffset(0)] @@ -6077,7 +6293,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.MacroLocation Location; [SuppressUnmanagedCodeSecurity] @@ -6114,7 +6330,7 @@ namespace CppSharp public PreprocessedEntity() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(96); + __Instance = Marshal.AllocHGlobal(120); Internal.ctor_0(__Instance); } @@ -6141,7 +6357,7 @@ namespace CppSharp public unsafe partial class MacroDefinition : CppSharp.Parser.AST.PreprocessedEntity, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 120)] + [StructLayout(LayoutKind.Explicit, Size = 144)] public new struct Internal { [FieldOffset(0)] @@ -6171,7 +6387,7 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.MacroLocation Location; [SuppressUnmanagedCodeSecurity] @@ -6218,7 +6434,7 @@ namespace CppSharp public MacroDefinition() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(120); + __Instance = Marshal.AllocHGlobal(144); Internal.ctor_0(__Instance); } @@ -6247,7 +6463,7 @@ namespace CppSharp public unsafe partial class MacroExpansion : CppSharp.Parser.AST.PreprocessedEntity, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 124)] + [StructLayout(LayoutKind.Explicit, Size = 148)] public new struct Internal { [FieldOffset(0)] @@ -6277,10 +6493,10 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(92)] + [FieldOffset(116)] public CppSharp.Parser.AST.MacroLocation Location; - [FieldOffset(120)] + [FieldOffset(144)] public global::System.IntPtr Definition; [SuppressUnmanagedCodeSecurity] @@ -6327,7 +6543,7 @@ namespace CppSharp public MacroExpansion() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(124); + __Instance = Marshal.AllocHGlobal(148); Internal.ctor_0(__Instance); } @@ -6371,7 +6587,7 @@ namespace CppSharp public unsafe partial class TranslationUnit : CppSharp.Parser.AST.Namespace, IDisposable { - [StructLayout(LayoutKind.Explicit, Size = 232)] + [StructLayout(LayoutKind.Explicit, Size = 256)] public new struct Internal { [FieldOffset(0)] @@ -6401,13 +6617,13 @@ namespace CppSharp [FieldOffset(88)] public void* OriginalPtr; - [FieldOffset(184)] + [FieldOffset(208)] public bool IsAnonymous; - [FieldOffset(188)] + [FieldOffset(212)] public bool IsInline; - [FieldOffset(216)] + [FieldOffset(240)] public bool IsSystemHeader; [SuppressUnmanagedCodeSecurity] @@ -6469,7 +6685,7 @@ namespace CppSharp public TranslationUnit() : this(IntPtr.Zero) { - __Instance = Marshal.AllocHGlobal(232); + __Instance = Marshal.AllocHGlobal(256); Internal.ctor_0(__Instance); } diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 239b55a9..2a8255ce 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -296,6 +297,15 @@ static std::string GetTagDeclName(const clang::TagDecl* D) return GetDeclName(D); } +static std::string GetDeclUSR(const clang::Decl* D) +{ + using namespace clang; + SmallString<128> usr; + if (!index::generateUSRForDecl(D, usr)) + return usr.str(); + return ""; +} + static clang::Decl* GetPreviousDeclInContext(const clang::Decl* D) { assert(!D->getLexicalDeclContext()->decls_empty()); @@ -727,26 +737,32 @@ WalkTemplateSpecializationKind(clang::TemplateSpecializationKind Kind) ClassTemplateSpecialization* Parser::WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* CTS) { + using namespace clang; + auto CT = WalkClassTemplate(CTS->getSpecializedTemplate()); - auto Spec = CT->FindSpecialization(CTS); - if (Spec != nullptr) - return Spec; + auto USR = GetDeclUSR(CTS); + auto TS = CT->FindSpecialization(USR); + if (TS != nullptr) + return TS; - auto TS = new ClassTemplateSpecialization(); + TS = new ClassTemplateSpecialization(); HandleDeclaration(CTS, TS); - TS->Name = CTS->getName(); - auto NS = GetNamespace(CTS); assert(NS && "Expected a valid namespace"); TS->_Namespace = NS; - + TS->Name = CTS->getName(); TS->TemplatedDecl = CT; TS->SpecializationKind = WalkTemplateSpecializationKind(CTS->getSpecializationKind()); + auto &TAL = CTS->getTemplateArgs(); + if (auto TSI = CTS->getTypeAsWritten()) + { + auto TL = TSI->getTypeLoc(); + auto TSL = TL.getAs(); + TS->Arguments = WalkTemplateArgumentList(&TAL, &TSL); + } CT->Specializations.push_back(TS); - // TODO: Parse the template argument list - if (CTS->isCompleteDefinition()) WalkRecordCXX(CTS, TS); @@ -758,12 +774,15 @@ Parser::WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* ClassTemplatePartialSpecialization* Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecializationDecl* CTS) { + using namespace clang; + auto CT = WalkClassTemplate(CTS->getSpecializedTemplate()); - auto Spec = CT->FindPartialSpecialization((void*) CTS); - if (Spec != nullptr) - return Spec; + auto USR = GetDeclUSR(CTS); + auto TS = CT->FindPartialSpecialization(USR); + if (TS != nullptr) + return TS; - auto TS = new ClassTemplatePartialSpecialization(); + TS = new ClassTemplatePartialSpecialization(); HandleDeclaration(CTS, TS); TS->Name = CTS->getName(); @@ -774,10 +793,15 @@ Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecia TS->TemplatedDecl = CT; TS->SpecializationKind = WalkTemplateSpecializationKind(CTS->getSpecializationKind()); + auto &TAL = CTS->getTemplateArgs(); + if (auto TSI = CTS->getTypeAsWritten()) + { + auto TL = TSI->getTypeLoc(); + auto TSL = TL.getAs(); + TS->Arguments = WalkTemplateArgumentList(&TAL, &TSL); + } CT->Specializations.push_back(TS); - // TODO: Parse the template argument list - if (CTS->isCompleteDefinition()) WalkRecordCXX(CTS, TS); @@ -786,57 +810,173 @@ Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecia //-----------------------------------// +CppSharp::CppParser::TemplateParameter +WalkTemplateParameter(const clang::NamedDecl* D) +{ + using namespace clang; + + auto TP = CppSharp::CppParser::TemplateParameter(); + if (D == nullptr) + return TP; + + TP.Name = GetDeclName(D); + switch (D->getKind()) + { + case Decl::TemplateTypeParm: + { + auto TTPD = cast(D); + TP.IsTypeParameter = true; + break; + } + default: + break; + } + return TP; +} + +//-----------------------------------// + +static std::vector +WalkTemplateParameterList(const clang::TemplateParameterList* TPL) +{ + auto params = std::vector(); + + for (auto it = TPL->begin(); it != TPL->end(); ++it) + { + auto ND = *it; + auto TP = WalkTemplateParameter(ND); + params.push_back(TP); + } + + return params; +} + +//-----------------------------------// + ClassTemplate* Parser::WalkClassTemplate(clang::ClassTemplateDecl* TD) { auto NS = GetNamespace(TD); assert(NS && "Expected a valid namespace"); - auto CT = NS->FindClassTemplate((void*) TD); + auto USR = GetDeclUSR(TD); + auto CT = NS->FindClassTemplate(USR); if (CT != nullptr) return CT; CT = new ClassTemplate(); HandleDeclaration(TD, CT); + CT->Name = GetDeclName(TD); CT->_Namespace = NS; NS->Templates.push_back(CT); CT->TemplatedDecl = WalkRecordCXX(TD->getTemplatedDecl()); + CT->Parameters = WalkTemplateParameterList(TD->getTemplateParameters()); - auto TPL = TD->getTemplateParameters(); - for(auto it = TPL->begin(); it != TPL->end(); ++it) - { - auto ND = *it; + return CT; +} + +//-----------------------------------// + +std::vector +Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, + clang::TemplateSpecializationTypeLoc* TSTL) +{ + using namespace clang; - auto TP = TemplateParameter(); - TP.Name = ND->getNameAsString(); + auto params = std::vector(); - CT->Parameters.push_back(TP); + for (size_t i = 0, e = TAL->size(); i < e; i++) + { + auto TA = TAL->get(i); + TemplateArgumentLoc *ArgLoc = 0; + if (TSTL && i < TSTL->getNumArgs()) + { + auto TAL = TSTL->getArgLoc(i); + ArgLoc = &TAL; + } + auto Arg = WalkTemplateArgument(TA, ArgLoc); + params.push_back(Arg); } - return CT; + return params; } //-----------------------------------// -static std::vector -WalkTemplateParameterList(const clang::TemplateParameterList* TPL) +std::vector +Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, + const clang::ASTTemplateArgumentListInfo* TALI) { - auto params = std::vector(); - - for(auto it = TPL->begin(); it != TPL->end(); ++it) - { - auto ND = *it; + using namespace clang; - auto TP = CppSharp::CppParser::TemplateParameter(); - TP.Name = ND->getNameAsString(); + auto params = std::vector(); + for (size_t i = 0, e = TAL->size(); i < e; i++) + { + auto TA = TAL->get(i); + auto ArgLoc = TALI->operator[](i); + auto TP = WalkTemplateArgument(TA, &ArgLoc); params.push_back(TP); } return params; } +//-----------------------------------// + +CppSharp::CppParser::TemplateArgument +Parser::WalkTemplateArgument(const clang::TemplateArgument& TA, clang::TemplateArgumentLoc* ArgLoc) +{ + auto Arg = CppSharp::CppParser::TemplateArgument(); + + switch (TA.getKind()) + { + case clang::TemplateArgument::Type: + { + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Type; + if (ArgLoc) + { + auto ArgTL = ArgLoc->getTypeSourceInfo()->getTypeLoc(); + Arg.Type = GetQualifiedType(TA.getAsType(), WalkType(TA.getAsType(), &ArgTL)); + } + else + { + Arg.Type = GetQualifiedType(TA.getAsType(), WalkType(TA.getAsType())); + } + break; + } + case clang::TemplateArgument::Declaration: + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Declaration; + Arg.Declaration = WalkDeclaration(TA.getAsDecl(), 0); + break; + case clang::TemplateArgument::NullPtr: + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::NullPtr; + break; + case clang::TemplateArgument::Integral: + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Integral; + //Arg.Type = WalkType(TA.getIntegralType(), 0); + Arg.Integral = TA.getAsIntegral().getLimitedValue(); + break; + case clang::TemplateArgument::Template: + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Template; + break; + case clang::TemplateArgument::TemplateExpansion: + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::TemplateExpansion; + break; + case clang::TemplateArgument::Expression: + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Expression; + break; + case clang::TemplateArgument::Pack: + Arg.Kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Pack; + break; + } + + return Arg; +} + +//-----------------------------------// + FunctionTemplate* Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD) { using namespace clang; @@ -844,32 +984,27 @@ FunctionTemplate* Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD) auto NS = GetNamespace(TD); assert(NS && "Expected a valid namespace"); - auto FT = NS->FindFunctionTemplate((void*)TD); + auto USR = GetDeclUSR(TD); + auto FT = NS->FindFunctionTemplate(USR); if (FT != nullptr) return FT; - auto Params = WalkTemplateParameterList(TD->getTemplateParameters()); - CppSharp::CppParser::AST::Function* Function = nullptr; auto TemplatedDecl = TD->getTemplatedDecl(); if (auto MD = dyn_cast(TemplatedDecl)) - Function = WalkMethodCXX(MD); + Function = WalkMethodCXX(MD, /*AddToClass=*/false); else Function = WalkFunction(TemplatedDecl, /*IsDependent=*/true, /*AddToNamespace=*/false); - auto Name = TD->getNameAsString(); - FT = NS->FindFunctionTemplate(Name, Params); - if (FT != nullptr && FT->TemplatedDecl == Function) - return FT; - FT = new FunctionTemplate(); HandleDeclaration(TD, FT); + FT->Name = GetDeclName(TD); FT->_Namespace = NS; FT->TemplatedDecl = Function; - FT->Parameters = Params; + FT->Parameters = WalkTemplateParameterList(TD->getTemplateParameters()); NS->Templates.push_back(FT); @@ -878,6 +1013,23 @@ FunctionTemplate* Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD) //-----------------------------------// +CppSharp::CppParser::FunctionTemplateSpecialization* +Parser::WalkFunctionTemplateSpec(clang::FunctionTemplateSpecializationInfo* FTSI, CppSharp::CppParser::Function* Function) +{ + using namespace clang; + + auto FTS = new CppSharp::CppParser::FunctionTemplateSpecialization(); + FTS->SpecializationKind = WalkTemplateSpecializationKind(FTSI->getTemplateSpecializationKind()); + FTS->SpecializedFunction = Function; + if (auto TALI = FTSI->TemplateArgumentsAsWritten) + FTS->Arguments = WalkTemplateArgumentList(FTSI->TemplateArguments, TALI); + FTS->Template = WalkFunctionTemplate(FTSI->getTemplate()); + FTS->Template->Specializations.push_back(FTS); + + return FTS; +} +//-----------------------------------// + static CXXMethodKind GetMethodKindFromDecl(clang::DeclarationName Name) { using namespace clang; @@ -921,13 +1073,13 @@ static CXXOperatorKind GetOperatorKindFromDecl(clang::DeclarationName Name) return CXXOperatorKind::None; } -Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) +Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD, bool AddToClass) { using namespace clang; // We could be in a redeclaration, so process the primary context. if (MD->getPrimaryContext() != MD) - return WalkMethodCXX(cast(MD->getPrimaryContext())); + return WalkMethodCXX(cast(MD->getPrimaryContext()), AddToClass); auto RD = MD->getParent(); auto Decl = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false); @@ -935,20 +1087,25 @@ Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) auto Class = static_cast(Decl); // Check for an already existing method that came from the same declaration. + auto USR = GetDeclUSR(MD); for (unsigned I = 0, E = Class->Methods.size(); I != E; ++I) { Method* Method = Class->Methods[I]; - if (Method->OriginalPtr == MD) - return Method; + if (Method->USR == USR) + return Method; + } + for (unsigned I = 0, E = Class->Templates.size(); I != E; ++I) + { + Template* Template = Class->Templates[I]; + if (Template->TemplatedDecl->USR == USR) + return static_cast(Template->TemplatedDecl); } - DeclarationName Name = MD->getDeclName(); - - Method* Method = new CppSharp::CppParser::Method(); + auto Method = new CppSharp::CppParser::Method(); HandleDeclaration(MD, Method); Method->Access = ConvertToAccess(MD->getAccess()); - Method->MethodKind = GetMethodKindFromDecl(Name); + Method->MethodKind = GetMethodKindFromDecl(MD->getDeclName()); Method->IsStatic = MD->isStatic(); Method->IsVirtual = MD->isVirtual(); Method->IsConst = MD->isConst(); @@ -974,7 +1131,8 @@ Method* Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) Method->ConversionType = GetQualifiedType(CD->getConversionType(), ConvTy); } - Class->Methods.push_back(Method); + if (AddToClass) + Class->Methods.push_back(Method); return Method; } @@ -1539,71 +1697,35 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, if (TS->isSugared()) TST->Desugared = WalkType(TS->desugar()); - auto TypeLocClass = TL->getTypeLocClass(); - - if (TypeLocClass == TypeLoc::Qualified) - { - auto UTL = TL->getUnqualifiedLoc(); - TL = &UTL; - } - else if (TypeLocClass == TypeLoc::Elaborated) - { - auto ETL = TL->getAs(); - auto ITL = ETL.getNextTypeLoc(); - TL = &ITL; - } - - assert(TL->getTypeLocClass() == TypeLoc::TemplateSpecialization); - auto TSTL = TL->getAs(); - - for (unsigned I = 0, E = TS->getNumArgs(); I != E; ++I) + if (TL && !TL->isNull()) { - const clang::TemplateArgument& TA = TS->getArg(I); - auto Arg = TemplateArgument(); - - TemplateArgumentLoc ArgLoc; - ArgLoc = TSTL.getArgLoc(I); - - switch(TA.getKind()) - { - case clang::TemplateArgument::Type: + auto TypeLocClass = TL->getTypeLocClass(); + if (TypeLocClass == TypeLoc::Qualified) { - Arg.Kind = TemplateArgument::ArgumentKind::Type; - TypeLoc ArgTL; - ArgTL = ArgLoc.getTypeSourceInfo()->getTypeLoc(); - Arg.Type = GetQualifiedType(TA.getAsType(), - WalkType(TA.getAsType(), &ArgTL)); - break; + auto UTL = TL->getUnqualifiedLoc(); + TL = &UTL; } - case clang::TemplateArgument::Declaration: - Arg.Kind = TemplateArgument::ArgumentKind::Declaration; - Arg.Declaration = WalkDeclaration(TA.getAsDecl(), 0); - break; - case clang::TemplateArgument::NullPtr: - Arg.Kind = TemplateArgument::ArgumentKind::NullPtr; - break; - case clang::TemplateArgument::Integral: - Arg.Kind = TemplateArgument::ArgumentKind::Integral; - //Arg.Type = WalkType(TA.getIntegralType(), 0); - Arg.Integral = TA.getAsIntegral().getLimitedValue(); - break; - case clang::TemplateArgument::Template: - Arg.Kind = TemplateArgument::ArgumentKind::Template; - break; - case clang::TemplateArgument::TemplateExpansion: - Arg.Kind = TemplateArgument::ArgumentKind::TemplateExpansion; - break; - case clang::TemplateArgument::Expression: - Arg.Kind = TemplateArgument::ArgumentKind::Expression; - break; - case clang::TemplateArgument::Pack: - Arg.Kind = TemplateArgument::ArgumentKind::Pack; - break; + else if (TypeLocClass == TypeLoc::Elaborated) + { + auto ETL = TL->getAs(); + auto ITL = ETL.getNextTypeLoc(); + TL = &ITL; } - TST->Arguments.push_back(Arg); + assert(TL->getTypeLocClass() == TypeLoc::TemplateSpecialization); } + TemplateSpecializationTypeLoc *TSTL = 0; + if (TL && !TL->isNull()) + { + auto TSpecTL = TL->getAs(); + TSTL = &TSpecTL; + } + + TemplateArgumentList TArgs(TemplateArgumentList::OnStack, TS->getArgs(), + TS->getNumArgs()); + TST->Arguments = WalkTemplateArgumentList(&TArgs, TSTL); + Ty = TST; break; } @@ -1611,10 +1733,33 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, { auto TP = Type->getAs(); - auto TPT = new TemplateParameterType(); + auto TPT = new CppSharp::CppParser::TemplateParameterType(); if (auto Ident = TP->getIdentifier()) TPT->Parameter.Name = Ident->getName(); + if (TL && !TL->isNull()) + { + auto TypeLocClass = TL->getTypeLocClass(); + if (TypeLocClass == TypeLoc::Qualified) + { + auto UTL = TL->getUnqualifiedLoc(); + TL = &UTL; + } + else if (TypeLocClass == TypeLoc::Elaborated) + { + auto ETL = TL->getAs(); + auto ITL = ETL.getNextTypeLoc(); + TL = &ITL; + } + + assert(TL->getTypeLocClass() == TypeLoc::TemplateTypeParm); + auto TTTL = TL->getAs(); + + TPT->Parameter = WalkTemplateParameter(TTTL.getDecl()); + } + TPT->Depth = TP->getDepth(); + TPT->Index = TP->getIndex(); + TPT->IsParameterPack = TP->isParameterPack(); Ty = TPT; break; @@ -1965,6 +2110,9 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F, F->Parameters[Index++]->IsIndirect = I->info.isIndirect(); } } + + if (auto FTSI = FD->getTemplateSpecializationInfo()) + F->SpecializationInfo = WalkFunctionTemplateSpec(FTSI, F); } Function* Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDependent, @@ -1977,9 +2125,8 @@ Function* Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDependent, auto NS = GetNamespace(FD); assert(NS && "Expected a valid namespace"); - auto Name = FD->getNameAsString(); - Function* F = NS->FindFunction(Name, /*Create=*/ false); - + auto USR = GetDeclUSR(FD); + auto F = NS->FindFunction(USR); if (F != nullptr) return F; @@ -2233,6 +2380,7 @@ void Parser::HandleDeclaration(clang::Decl* D, Declaration* Decl) return; Decl->OriginalPtr = (void*) D; + Decl->USR = GetDeclUSR(D); if (Decl->PreprocessedEntities.empty() && !D->isImplicit()) { diff --git a/src/CppParser/Parser.h b/src/CppParser/Parser.h index b47690a5..0f1155c4 100644 --- a/src/CppParser/Parser.h +++ b/src/CppParser/Parser.h @@ -75,14 +75,18 @@ protected: WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* CTS); ClassTemplatePartialSpecialization* WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecializationDecl* CTS); - Method* WalkMethodCXX(clang::CXXMethodDecl* MD); + Method* WalkMethodCXX(clang::CXXMethodDecl* MD, bool AddToClass = true); Field* WalkFieldCXX(clang::FieldDecl* FD, Class* Class); ClassTemplate* WalkClassTemplate(clang::ClassTemplateDecl* TD); FunctionTemplate* WalkFunctionTemplate(clang::FunctionTemplateDecl* TD); + FunctionTemplateSpecialization* WalkFunctionTemplateSpec(clang::FunctionTemplateSpecializationInfo* FTS, Function* Function); Variable* WalkVariable(clang::VarDecl* VD); RawComment* WalkRawComment(const clang::RawComment* RC); Type* WalkType(clang::QualType QualType, clang::TypeLoc* TL = 0, bool DesugarType = false); + TemplateArgument WalkTemplateArgument(const clang::TemplateArgument& TA, clang::TemplateArgumentLoc* ArgLoc); + std::vector WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, clang::TemplateSpecializationTypeLoc* TSTL); + std::vector WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, const clang::ASTTemplateArgumentListInfo* TSTL); void WalkVTable(clang::CXXRecordDecl* RD, Class* C); VTableLayout WalkVTableLayout(const clang::VTableLayout& VTLayout); VTableComponent WalkVTableComponent(const clang::VTableComponent& Component); diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs index 3292e1df..b037befc 100644 --- a/src/Generator.Tests/AST/TestAST.cs +++ b/src/Generator.Tests/AST/TestAST.cs @@ -19,7 +19,7 @@ namespace CppSharp.Generator.Tests.AST [SetUp] public void Setup() { - ParseLibrary("AST.h"); + ParseLibrary("AST.h", "ASTExtensions.h"); passBuilder = new PassBuilder(Driver); } @@ -168,5 +168,62 @@ namespace CppSharp.Generator.Tests.AST Assert.NotNull(@enum); Assert.IsTrue(@enum.ItemsByName.ContainsKey("TestItemByName")); } + + [Test] + public void TestASTFunctionTemplates() + { + var @class = AstContext.FindClass("TestTemplateFunctions").FirstOrDefault(); + Assert.IsNotNull(@class, "Couldn't find TestTemplateFunctions class."); + Assert.AreEqual(6, @class.Templates.Count); + var twoParamMethodTemplate = @class.Templates.OfType() + .FirstOrDefault(t => t.Name == "MethodTemplateWithTwoTypeParameter"); + Assert.IsNotNull(twoParamMethodTemplate); + Assert.AreEqual(2, twoParamMethodTemplate.Parameters.Count); + Assert.AreEqual("T", twoParamMethodTemplate.Parameters[0].Name); + Assert.AreEqual("S", twoParamMethodTemplate.Parameters[1].Name); + Assert.IsTrue(twoParamMethodTemplate.Parameters[0].IsTypeParameter); + Assert.IsTrue(twoParamMethodTemplate.Parameters[1].IsTypeParameter); + var twoParamMethod = twoParamMethodTemplate.TemplatedFunction as Method; + Assert.IsNotNull(twoParamMethod); + Assert.IsInstanceOf(twoParamMethod.Parameters[0].Type); + Assert.IsInstanceOf(twoParamMethod.Parameters[1].Type); + Assert.AreEqual(twoParamMethodTemplate.Parameters[0], + ((TemplateParameterType)twoParamMethod.Parameters[0].Type).Parameter); + Assert.AreEqual(twoParamMethodTemplate.Parameters[1], + ((TemplateParameterType)twoParamMethod.Parameters[1].Type).Parameter); + Assert.AreEqual(0, ((TemplateParameterType)twoParamMethod.Parameters[0].Type).Index); + Assert.AreEqual(1, ((TemplateParameterType)twoParamMethod.Parameters[1].Type).Index); + } + + [Test] + public void TestASTClassTemplates() + { + var template = AstContext.TranslationUnits + .SelectMany(u => u.Templates.OfType()) + .FirstOrDefault(t => t.Name == "TestTemplateClass"); + Assert.IsNotNull(template, "Couldn't find TestTemplateClass class."); + Assert.AreEqual(1, template.Parameters.Count); + var templateTypeParameter = template.Parameters[0]; + Assert.AreEqual("T", templateTypeParameter.Name); + var ctor = template.TemplatedClass.Constructors + .FirstOrDefault(c => c.Parameters.Count == 1 && c.Parameters[0].Name == "v"); + Assert.IsNotNull(ctor); + var paramType = ctor.Parameters[0].Type as TemplateParameterType; + Assert.IsNotNull(paramType); + Assert.AreEqual(templateTypeParameter, paramType.Parameter); + Assert.AreEqual(3, template.Specializations.Count); + Assert.AreEqual(TemplateSpecializationKind.ExplicitInstantiationDefinition, template.Specializations[0].SpecializationKind); + Assert.AreEqual(TemplateSpecializationKind.ExplicitInstantiationDefinition, template.Specializations[1].SpecializationKind); + Assert.AreEqual(TemplateSpecializationKind.Undeclared, template.Specializations[2].SpecializationKind); + var typeDef = AstContext.FindTypedef("TestTemplateClassInt").FirstOrDefault(); + Assert.IsNotNull(typeDef, "Couldn't find TestTemplateClassInt typedef."); + var integerInst = typeDef.Type as TemplateSpecializationType; + Assert.AreEqual(1, integerInst.Arguments.Count); + var intArgument = integerInst.Arguments[0]; + Assert.AreEqual(new BuiltinType(PrimitiveType.Int32), intArgument.Type.Type); + Class classTemplate; + Assert.IsTrue(typeDef.Type.TryGetClass(out classTemplate)); + Assert.AreEqual(classTemplate, template.TemplatedClass); + } } } diff --git a/src/Generator.Tests/ASTTestFixture.cs b/src/Generator.Tests/ASTTestFixture.cs index e1f84ebf..69a3c3d9 100644 --- a/src/Generator.Tests/ASTTestFixture.cs +++ b/src/Generator.Tests/ASTTestFixture.cs @@ -10,7 +10,7 @@ namespace CppSharp.Generator.Tests protected DriverOptions Options; protected ASTContext AstContext; - protected void ParseLibrary(string file) + protected void ParseLibrary(params string[] files) { Options = new DriverOptions(); @@ -22,7 +22,7 @@ namespace CppSharp.Generator.Tests Options.addIncludeDirs(testsPath); #endif - Options.Headers.Add(file); + Options.Headers.AddRange(files); Driver = new Driver(Options, new TextDiagnosticPrinter()); if (!Driver.ParseCode()) diff --git a/src/Generator/Generator.cs b/src/Generator/Generator.cs index 1606cc2a..436c8909 100644 --- a/src/Generator/Generator.cs +++ b/src/Generator/Generator.cs @@ -71,7 +71,7 @@ namespace CppSharp.Generators if (!unit.IsGenerated || !unit.HasDeclarations) continue; - if (unit.IsSystemHeader) + if (unit.IsSystemHeader || !unit.IsValid) continue; var templates = Generate(unit); diff --git a/src/Generator/Passes/CleanUnitPass.cs b/src/Generator/Passes/CleanUnitPass.cs index 9e933183..2d3628ba 100644 --- a/src/Generator/Passes/CleanUnitPass.cs +++ b/src/Generator/Passes/CleanUnitPass.cs @@ -18,9 +18,12 @@ namespace CppSharp.Passes // Try to get an include path that works from the original include // directories paths. - - unit.IncludePath = GetIncludePath(unit.FilePath); - return true; + if (unit.IsValid) + { + unit.IncludePath = GetIncludePath(unit.FilePath); + return true; + } + return false; } string GetIncludePath(string filePath) diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 9d4bb5d2..4d27d849 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -292,6 +293,15 @@ static std::string GetTagDeclName(const clang::TagDecl* D) return GetDeclName(D); } +static std::string GetDeclUSR(const clang::Decl* D) +{ + using namespace clang; + SmallString<128> usr; + if (!index::generateUSRForDecl(D, usr)) + return usr.str(); + return ""; +} + static clang::Decl* GetPreviousDeclInContext(const clang::Decl* D) { assert(!D->getLexicalDeclContext()->decls_empty()); @@ -725,26 +735,33 @@ WalkTemplateSpecializationKind(clang::TemplateSpecializationKind Kind) CppSharp::AST::ClassTemplateSpecialization^ Parser::WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* CTS) { + using namespace clang; + using namespace clix; + auto CT = WalkClassTemplate(CTS->getSpecializedTemplate()); - auto Spec = CT->FindSpecialization(System::IntPtr(CTS)); - if (Spec != nullptr) - return Spec; + auto USR = marshalString(GetDeclUSR(CTS)); + auto TS = CT->FindSpecializationByUSR(USR); + if (TS != nullptr) + return TS; - auto TS = gcnew CppSharp::AST::ClassTemplateSpecialization(); + TS = gcnew CppSharp::AST::ClassTemplateSpecialization(); HandleDeclaration(CTS, TS); - TS->Name = clix::marshalString(CTS->getName()); - auto NS = GetNamespace(CTS); assert(NS && "Expected a valid namespace"); TS->Namespace = NS; - + TS->Name = clix::marshalString(GetDeclName(CTS)); TS->TemplatedDecl = CT; TS->SpecializationKind = WalkTemplateSpecializationKind(CTS->getSpecializationKind()); + auto &TAL = CTS->getTemplateArgs(); + if (auto TSI = CTS->getTypeAsWritten()) + { + auto TL = TSI->getTypeLoc(); + auto TSL = TL.getAs(); + TS->Arguments = WalkTemplateArgumentList(&TAL, &TSL); + } CT->Specializations->Add(TS); - // TODO: Parse the template argument list - if (CTS->isCompleteDefinition()) WalkRecordCXX(CTS, TS); @@ -756,15 +773,19 @@ Parser::WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* CppSharp::AST::ClassTemplatePartialSpecialization^ Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecializationDecl* CTS) { + using namespace clang; + using namespace clix; + auto CT = WalkClassTemplate(CTS->getSpecializedTemplate()); - auto Spec = CT->FindPartialSpecialization(System::IntPtr(CTS)); - if (Spec != nullptr) - return Spec; + auto USR = marshalString(GetDeclUSR(CTS)); + auto TS = CT->FindPartialSpecializationByUSR(USR); + if (TS != nullptr) + return TS; - auto TS = gcnew CppSharp::AST::ClassTemplatePartialSpecialization(); + TS = gcnew CppSharp::AST::ClassTemplatePartialSpecialization(); HandleDeclaration(CTS, TS); - TS->Name = clix::marshalString(CTS->getName()); + TS->Name = clix::marshalString(GetDeclName(CTS)); auto NS = GetNamespace(CTS); assert(NS && "Expected a valid namespace"); @@ -772,10 +793,15 @@ Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecia TS->TemplatedDecl = CT; TS->SpecializationKind = WalkTemplateSpecializationKind(CTS->getSpecializationKind()); + auto &TAL = CTS->getTemplateArgs(); + if (auto TSI = CTS->getTypeAsWritten()) + { + auto TL = TSI->getTypeLoc(); + auto TSL = TL.getAs(); + TS->Arguments = WalkTemplateArgumentList(&TAL, &TSL); + } CT->Specializations->Add(TS); - // TODO: Parse the template argument list - if (CTS->isCompleteDefinition()) WalkRecordCXX(CTS, TS); @@ -784,6 +810,52 @@ Parser::WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecia //-----------------------------------// +CppSharp::AST::TemplateParameter +WalkTemplateParameter(const clang::NamedDecl* D) +{ + using namespace clang; + using namespace clix; + + auto TP = CppSharp::AST::TemplateParameter(); + if (D == nullptr) + return TP; + + TP.Name = marshalString(GetDeclName(D)); + switch (D->getKind()) + { + case Decl::TemplateTypeParm: + { + auto TTPD = cast(D); + TP.IsTypeParameter = true; + break; + } + default: + break; + } + return TP; +} + +//-----------------------------------// + +static List^ +WalkTemplateParameterList(const clang::TemplateParameterList* TPL) +{ + using namespace clang; + + auto params = gcnew List(); + + for (auto it = TPL->begin(); it != TPL->end(); ++it) + { + auto ND = *it; + auto TP = WalkTemplateParameter(ND); + params->Add(TP); + } + + return params; +} + +//-----------------------------------// + CppSharp::AST::ClassTemplate^ Parser::WalkClassTemplate(clang::ClassTemplateDecl* TD) { using namespace clang; @@ -792,52 +864,128 @@ CppSharp::AST::ClassTemplate^ Parser::WalkClassTemplate(clang::ClassTemplateDecl auto NS = GetNamespace(TD); assert(NS && "Expected a valid namespace"); - auto CT = NS->FindClassTemplate(System::IntPtr(TD)); + auto USR = marshalString(GetDeclUSR(TD)); + auto CT = NS->FindClassTemplateByUSR(USR); if (CT != nullptr) return CT; CT = gcnew CppSharp::AST::ClassTemplate(); HandleDeclaration(TD, CT); + CT->Name = marshalString(GetDeclName(TD)); CT->Namespace = NS; NS->Templates->Add(CT); CT->TemplatedDecl = WalkRecordCXX(TD->getTemplatedDecl()); + CT->Parameters = WalkTemplateParameterList(TD->getTemplateParameters()); - auto TPL = TD->getTemplateParameters(); - for(auto it = TPL->begin(); it != TPL->end(); ++it) - { - auto ND = *it; + return CT; +} + +//-----------------------------------// + +List^ +Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, + clang::TemplateSpecializationTypeLoc* TSTL) +{ + using namespace clang; - auto TP = CppSharp::AST::TemplateParameter(); - TP.Name = clix::marshalString(ND->getNameAsString()); + auto params = gcnew List(); - CT->Parameters->Add(TP); + for (size_t i = 0, e = TAL->size(); i < e; i++) + { + auto TA = TAL->get(i); + TemplateArgumentLoc *ArgLoc = 0; + if (TSTL && i < TSTL->getNumArgs()) + { + auto TAL = TSTL->getArgLoc(i); + ArgLoc = &TAL; + } + auto Arg = WalkTemplateArgument(TA, ArgLoc); + params->Add(Arg); } - return CT; + return params; } //-----------------------------------// -static List^ -WalkTemplateParameterList(const clang::TemplateParameterList* TPL) +List^ +Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, + const clang::ASTTemplateArgumentListInfo* TALI) { - auto params = gcnew List(); - - for(auto it = TPL->begin(); it != TPL->end(); ++it) - { - auto ND = *it; + using namespace clang; - auto TP = CppSharp::AST::TemplateParameter(); - TP.Name = clix::marshalString(ND->getNameAsString()); + auto params = gcnew List(); + for (size_t i = 0, e = TAL->size(); i < e; i++) + { + auto TA = TAL->get(i); + auto ArgLoc = TALI->operator[](i); + auto TP = WalkTemplateArgument(TA, &ArgLoc); params->Add(TP); } return params; } +//-----------------------------------// + +CppSharp::AST::TemplateArgument +Parser::WalkTemplateArgument(const clang::TemplateArgument& TA, clang::TemplateArgumentLoc* ArgLoc) +{ + using namespace clang; + using namespace clix; + + auto Arg = CppSharp::AST::TemplateArgument(); + + switch (TA.getKind()) + { + case TemplateArgument::Type: + { + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Type; + if (ArgLoc) + { + auto ArgTL = ArgLoc->getTypeSourceInfo()->getTypeLoc(); + Arg.Type = GetQualifiedType(TA.getAsType(), WalkType(TA.getAsType(), &ArgTL)); + } + else + { + Arg.Type = GetQualifiedType(TA.getAsType(), WalkType(TA.getAsType())); + } + break; + } + case TemplateArgument::Declaration: + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Declaration; + Arg.Declaration = WalkDeclaration(TA.getAsDecl(), 0); + break; + case TemplateArgument::NullPtr: + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::NullPtr; + break; + case TemplateArgument::Integral: + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Integral; + //Arg.Type = WalkType(TA.getIntegralType(), 0); + Arg.Integral = TA.getAsIntegral().getLimitedValue(); + break; + case TemplateArgument::Template: + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Template; + break; + case TemplateArgument::TemplateExpansion: + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::TemplateExpansion; + break; + case TemplateArgument::Expression: + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Expression; + break; + case TemplateArgument::Pack: + Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Pack; + break; + } + + return Arg; +} + +//-----------------------------------// + CppSharp::AST::FunctionTemplate^ Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD) { @@ -847,32 +995,27 @@ Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD) auto NS = GetNamespace(TD); assert(NS && "Expected a valid namespace"); - auto FT = NS->FindFunctionTemplate(System::IntPtr(TD)); + auto USR = marshalString(GetDeclUSR(TD)); + auto FT = NS->FindFunctionTemplateByUSR(USR); if (FT != nullptr) return FT; - auto Params = WalkTemplateParameterList(TD->getTemplateParameters()); - CppSharp::AST::Function^ Function = nullptr; auto TemplatedDecl = TD->getTemplatedDecl(); if (auto MD = dyn_cast(TemplatedDecl)) - Function = WalkMethodCXX(MD); + Function = WalkMethodCXX(MD, /*AddToClass=*/false); else Function = WalkFunction(TemplatedDecl, /*IsDependent=*/true, - /*AddToNamespace=*/false); - - auto Name = clix::marshalString(TD->getNameAsString()); - FT = NS->FindFunctionTemplate(Name, Params); - if (FT != nullptr && FT->TemplatedDecl == Function) - return FT; + /*AddToNamespace=*/false); FT = gcnew CppSharp::AST::FunctionTemplate(Function); HandleDeclaration(TD, FT); + FT->Name = marshalString(GetDeclName(TD)); FT->Namespace = NS; FT->TemplatedDecl = Function; - FT->Parameters = Params; + FT->Parameters = WalkTemplateParameterList(TD->getTemplateParameters()); NS->Templates->Add(FT); @@ -881,6 +1024,24 @@ Parser::WalkFunctionTemplate(clang::FunctionTemplateDecl* TD) //-----------------------------------// +CppSharp::AST::FunctionTemplateSpecialization^ +Parser::WalkFunctionTemplateSpec(clang::FunctionTemplateSpecializationInfo* FTSI, CppSharp::AST::Function^ Function) +{ + using namespace clang; + + auto FTS = gcnew CppSharp::AST::FunctionTemplateSpecialization(); + FTS->SpecializationKind = WalkTemplateSpecializationKind(FTSI->getTemplateSpecializationKind()); + FTS->SpecializedFunction = Function; + if (auto TALI = FTSI->TemplateArgumentsAsWritten) + FTS->Arguments = WalkTemplateArgumentList(FTSI->TemplateArguments, TALI); + FTS->Template = WalkFunctionTemplate(FTSI->getTemplate()); + FTS->Template->Specializations->Add(FTS); + + return FTS; +} + +//-----------------------------------// + static CppSharp::AST::CXXMethodKind GetMethodKindFromDecl(clang::DeclarationName Name) { using namespace clang; @@ -924,13 +1085,14 @@ static CppSharp::AST::CXXOperatorKind GetOperatorKindFromDecl(clang::Declaration return CppSharp::AST::CXXOperatorKind::None; } -CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) +CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD, bool AddToClass) { using namespace clang; + using namespace clix; // We could be in a redeclaration, so process the primary context. if (MD->getPrimaryContext() != MD) - return WalkMethodCXX(cast(MD->getPrimaryContext())); + return WalkMethodCXX(cast(MD->getPrimaryContext()), AddToClass); auto RD = MD->getParent(); auto Decl = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false); @@ -938,15 +1100,12 @@ CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) auto Class = safe_cast(Decl); // Check for an already existing method that came from the same declaration. - for each (CppSharp::AST::Method^ Method in Class->Methods) - { - if (Method->OriginalPtr.ToPointer() == MD) - return Method; - } - - DeclarationName Name = MD->getDeclName(); + auto USR = marshalString(GetDeclUSR(MD)); + auto Method = Class->FindMethodByUSR(USR); + if (Method != nullptr) + return Method; - CppSharp::AST::Method^ Method = gcnew CppSharp::AST::Method(); + Method = gcnew CppSharp::AST::Method(); HandleDeclaration(MD, Method); Method->Access = ConvertToAccess(MD->getAccess()); @@ -957,7 +1116,7 @@ CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) WalkFunction(MD, Method); - Method->Kind = GetMethodKindFromDecl(Name); + Method->Kind = GetMethodKindFromDecl(MD->getDeclName()); if (const CXXConstructorDecl* CD = dyn_cast(MD)) { @@ -977,7 +1136,8 @@ CppSharp::AST::Method^ Parser::WalkMethodCXX(clang::CXXMethodDecl* MD) Method->ConversionType = GetQualifiedType(CD->getConversionType(), ConvTy); } - Class->Methods->Add(Method); + if (AddToClass) + Class->Methods->Add(Method); return Method; } @@ -1555,71 +1715,35 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* if (TS->isSugared()) TST->Desugared = WalkType(TS->desugar()); - auto TypeLocClass = TL->getTypeLocClass(); - - if (TypeLocClass == TypeLoc::Qualified) - { - auto UTL = TL->getUnqualifiedLoc(); - TL = &UTL; - } - else if (TypeLocClass == TypeLoc::Elaborated) - { - auto ETL = TL->getAs(); - auto ITL = ETL.getNextTypeLoc(); - TL = &ITL; - } - - assert(TL->getTypeLocClass() == TypeLoc::TemplateSpecialization); - auto TSTL = TL->getAs(); - - for (unsigned I = 0, E = TS->getNumArgs(); I != E; ++I) + if (TL && !TL->isNull()) { - const TemplateArgument& TA = TS->getArg(I); - auto Arg = CppSharp::AST::TemplateArgument(); - - TemplateArgumentLoc ArgLoc; - ArgLoc = TSTL.getArgLoc(I); - - switch(TA.getKind()) - { - case TemplateArgument::Type: + auto TypeLocClass = TL->getTypeLocClass(); + if (TypeLocClass == TypeLoc::Qualified) { - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Type; - TypeLoc ArgTL; - ArgTL = ArgLoc.getTypeSourceInfo()->getTypeLoc(); - Arg.Type = GetQualifiedType(TA.getAsType(), - WalkType(TA.getAsType(), &ArgTL)); - break; + auto UTL = TL->getUnqualifiedLoc(); + TL = &UTL; } - case TemplateArgument::Declaration: - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Declaration; - Arg.Declaration = WalkDeclaration(TA.getAsDecl(), 0); - break; - case TemplateArgument::NullPtr: - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::NullPtr; - break; - case TemplateArgument::Integral: - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Integral; - //Arg.Type = WalkType(TA.getIntegralType(), 0); - Arg.Integral = TA.getAsIntegral().getLimitedValue(); - break; - case TemplateArgument::Template: - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Template; - break; - case TemplateArgument::TemplateExpansion: - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::TemplateExpansion; - break; - case TemplateArgument::Expression: - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Expression; - break; - case TemplateArgument::Pack: - Arg.Kind = CppSharp::AST::TemplateArgument::ArgumentKind::Pack; - break; + else if (TypeLocClass == TypeLoc::Elaborated) + { + auto ETL = TL->getAs(); + auto ITL = ETL.getNextTypeLoc(); + TL = &ITL; } - TST->Arguments->Add(Arg); + assert(TL->getTypeLocClass() == TypeLoc::TemplateSpecialization); + } + + TemplateSpecializationTypeLoc *TSTL = 0; + if (TL && !TL->isNull()) + { + auto TSpecTL = TL->getAs(); + TSTL = &TSpecTL; } + TemplateArgumentList TArgs(TemplateArgumentList::OnStack, TS->getArgs(), + TS->getNumArgs()); + TST->Arguments = WalkTemplateArgumentList(&TArgs, TSTL); + Ty = TST; break; } @@ -1631,6 +1755,29 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* if (auto Ident = TP->getIdentifier()) TPT->Parameter.Name = marshalString(Ident->getName()); + if (TL && !TL->isNull()) + { + auto TypeLocClass = TL->getTypeLocClass(); + if (TypeLocClass == TypeLoc::Qualified) + { + auto UTL = TL->getUnqualifiedLoc(); + TL = &UTL; + } + else if (TypeLocClass == TypeLoc::Elaborated) + { + auto ETL = TL->getAs(); + auto ITL = ETL.getNextTypeLoc(); + TL = &ITL; + } + + assert(TL->getTypeLocClass() == TypeLoc::TemplateTypeParm); + auto TTTL = TL->getAs(); + + TPT->Parameter = WalkTemplateParameter(TTTL.getDecl()); + } + TPT->Depth = TP->getDepth(); + TPT->Index = TP->getIndex(); + TPT->IsParameterPack = TP->isParameterPack(); Ty = TPT; break; @@ -1983,6 +2130,9 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F, F->Parameters[Index++]->IsIndirect = I->info.isIndirect(); } } + + if (auto FTSI = FD->getTemplateSpecializationInfo()) + F->SpecializationInfo = WalkFunctionTemplateSpec(FTSI, F); } CppSharp::AST::Function^ Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDependent, @@ -1996,9 +2146,8 @@ CppSharp::AST::Function^ Parser::WalkFunction(clang::FunctionDecl* FD, bool IsDe auto NS = GetNamespace(FD); assert(NS && "Expected a valid namespace"); - auto Name = marshalString(FD->getNameAsString()); - CppSharp::AST::Function^ F = NS->FindFunction(Name, /*Create=*/ false); - + auto USR = marshalString(GetDeclUSR(FD)); + auto F = NS->FindFunctionByUSR(USR); if (F != nullptr) return F; @@ -2254,6 +2403,7 @@ void Parser::HandleDeclaration(clang::Decl* D, CppSharp::AST::Declaration^ Decl) return; Decl->OriginalPtr = System::IntPtr(D); + Decl->USR = clix::marshalString(GetDeclUSR(D)); if (Decl->PreprocessedEntities->Count == 0 && !D->isImplicit()) { diff --git a/src/Parser/Parser.h b/src/Parser/Parser.h index 6cf7d9cf..0e46fe53 100644 --- a/src/Parser/Parser.h +++ b/src/Parser/Parser.h @@ -73,15 +73,19 @@ protected: WalkClassTemplateSpecialization(clang::ClassTemplateSpecializationDecl* CTS); CppSharp::AST::ClassTemplatePartialSpecialization^ WalkClassTemplatePartialSpecialization(clang::ClassTemplatePartialSpecializationDecl* CTS); - CppSharp::AST::Method^ WalkMethodCXX(clang::CXXMethodDecl* MD); + CppSharp::AST::Method^ WalkMethodCXX(clang::CXXMethodDecl* MD, bool AddToClass = true); CppSharp::AST::Field^ WalkFieldCXX(clang::FieldDecl* FD, CppSharp::AST::Class^ Class); CppSharp::AST::ClassTemplate^ Parser::WalkClassTemplate(clang::ClassTemplateDecl* TD); CppSharp::AST::FunctionTemplate^ Parser::WalkFunctionTemplate( clang::FunctionTemplateDecl* TD); + CppSharp::AST::FunctionTemplateSpecialization^ WalkFunctionTemplateSpec(clang::FunctionTemplateSpecializationInfo* FTS, CppSharp::AST::Function^ Function); CppSharp::AST::Variable^ WalkVariable(clang::VarDecl* VD); CppSharp::AST::RawComment^ WalkRawComment(const clang::RawComment* RC); CppSharp::AST::Type^ WalkType(clang::QualType QualType, clang::TypeLoc* TL = 0, bool DesugarType = false); + CppSharp::AST::TemplateArgument WalkTemplateArgument(const clang::TemplateArgument& TA, clang::TemplateArgumentLoc* ArgLoc); + List^ WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, clang::TemplateSpecializationTypeLoc* TSTL); + List^ WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, const clang::ASTTemplateArgumentListInfo* TSTL); CppSharp::AST::QualifiedType^ WalkQualifiedType(clang::TypeSourceInfo* TSI); void WalkVTable(clang::CXXRecordDecl* RD, CppSharp::AST::Class^ C); CppSharp::AST::VTableLayout^ WalkVTableLayout(const clang::VTableLayout& VTLayout); diff --git a/tests/Native/AST.h b/tests/Native/AST.h index 0a7091de..5d7edd27 100644 --- a/tests/Native/AST.h +++ b/tests/Native/AST.h @@ -22,4 +22,38 @@ namespace Math } // Tests Enum.ItemByName -enum TestASTEnumItemByName { TestItemByName }; \ No newline at end of file +enum TestASTEnumItemByName { TestItemByName }; + +// Tests class templates +template +class TestTemplateClass +{ +public: + TestTemplateClass(T v); + T Identity(T x); + T value; +}; + +// Tests function templates +class TestTemplateFunctions +{ +public: + template T Identity(T x) { return x; } + template void Ignore() { }; + template void MethodTemplateWithTwoTypeParameter(T t, S s) { }; + template void Ignore(TestTemplateClass v) { }; + template T Valid(TestTemplateClass v, T x) { return x; }; + template T& Valid(TestTemplateClass v, T x) const { return x; } +}; + +// Explicit instantiation +template class TestTemplateClass; +// Implicit instantiation +typedef TestTemplateClass TestTemplateClassInt; + +// Now use the typedef +class TestTemplateClass2 +{ +public: + TestTemplateClassInt* CreateIntTemplate(); +}; diff --git a/tests/Native/ASTExtensions.h b/tests/Native/ASTExtensions.h new file mode 100644 index 00000000..3182addd --- /dev/null +++ b/tests/Native/ASTExtensions.h @@ -0,0 +1,9 @@ +#include "AST.h" +#include + +// Tests class templates accross translation units +// Explicit instantiation +template class TestTemplateClass; +// Implicit instantiations +typedef TestTemplateClass TestTemplateClassComplex; +typedef TestTemplateClass> TestTemplateClassMoreComplex; \ No newline at end of file