public static bool VisitTemplate(CXCursor cursor, NativeClass c, AST ast) { CXType type = clang.getCursorType(cursor); CXCursor templateCursor = clang.getSpecializedCursorTemplate(cursor); if (ClangTraits.IsInvalid(templateCursor)) { return(false); } string templateID = clang.getCursorUSR(templateCursor).ToString(); ClassTemplate template = ast.GetClassTemplate(templateID); CXCursor originalTemplateCursor = clang.getSpecializedCursorTemplate(templateCursor); ClassTemplate originalTemplate; if (ClangTraits.IsInvalid(originalTemplateCursor)) { originalTemplate = template; } else { string originalTemplateID = clang.getCursorUSR(originalTemplateCursor).ToString(); originalTemplate = ast.GetClassTemplate(originalTemplateID); } c.SetTemplate(template, originalTemplate); return(true); }
public static NativeType GetNativeType(AST ast, CXType cxType, TypeVisitContext context = null) { CXType type = cxType; if (ClangTraits.IsElaboratedType(type) || ClangTraits.IsUnexposedType(type)) { type = clang.getCursorType(clang.getTypeDeclaration(type)); } Debug.Assert(!ClangTraits.IsInvalid(type)); string typeName = clang.getTypeSpelling(type).ToString(); Debug.Assert(typeName.Length > 0); NativeType nativeType = ast.GetType(typeName); if (!nativeType.Parsed) { nativeType.Parsed = true; // get cursor spelling as unscoped name CXCursor declaration = clang.getTypeDeclaration(type); nativeType.UnscopedName = clang.getCursorSpelling(declaration).ToString(); // not a type reference nor a type with qualifiers if (ClangTraits.IsTypeEntity(type) || typeName == "std::nullptr_t") { ProcessTypeEntity(ast, nativeType, type, context); } // using or typedef else if (ClangTraits.IsTypedef(type)) { ProcessTypedef(ast, nativeType, type, context); } else if (ClangTraits.IsArray(type)) { ProcessArray(ast, nativeType, type, context); } // reference and pointer else if (ClangTraits.IsReference(type) || ClangTraits.IsPointer(type)) { ProcessReferencePointer(ast, nativeType, type, context); } else if (ClangTraits.IsMemberPointer(type)) { ProcessMemberPointer(ast, nativeType, cxType, context); } else { Debug.Assert(false); } } return(nativeType); }
public static bool VisitTemplateParameter( CXCursor cursor, CXType type, NativeClass @class, AST ast, TypeVisitContext context) { ClassTemplate template = @class.OriginalTemplate; Debug.Assert(template != null); Debug.Assert(template.TP != null); int templateArgNum = clang.Type_getNumTemplateArguments(type); if (templateArgNum < 0) { return(false); } @class.SetTemplateParameterCount(templateArgNum); int contextIndex = 0; for (uint loop = 0; loop < templateArgNum; ++loop) { TemplateParameter param = template.TP.GetTemplateParameter(loop); Debug.Assert(param != null); if (param.Kind == TemplateParameterKind.Type) { CXType argType = clang.Type_getTemplateArgumentAsType(type, loop); Debug.Assert(!ClangTraits.IsInvalid(argType)); NativeType nativeArgType = TypeVisitorHelper.GetNativeType(ast, argType, context); @class.SetTemplateParameter(loop, nativeArgType); } else if (param.Kind == TemplateParameterKind.NoneType || param.Kind == TemplateParameterKind.Dependent) { string literal; if (context != null && !context.Empty) { literal = context.Consume(); } else { literal = (param.Extra as TemplateNonTypeParam).DefaultLiteral; } Debug.Assert(literal != null); @class.SetTemplateParameter(loop, literal); ++contextIndex; } else { Debug.Assert(TemplateParameterKind.Template == param.Kind); // not support now ClassTemplate templateParam = null; @class.SetTemplateParameter(loop, templateParam); } } return(true); }