private TemplateProto GetTemplateProto(CXCursor cursor) { TemplateProto tp = new TemplateProto(); clang.visitChildren(cursor, (CXCursor c, CXCursor p, IntPtr data) => { switch (c.kind) { case CXCursorKind.CXCursor_TemplateTypeParameter: tp.AddTemplateParameter(GetTemplateTypeParameter(c)); break; case CXCursorKind.CXCursor_NonTypeTemplateParameter: tp.AddTemplateParameter(GetTemplateNonTypeParameter(AST_, tp, c)); break; case CXCursorKind.CXCursor_TemplateTemplateParameter: tp.AddTemplateParameter(GetTemplateTemplateParameter(c)); break; default: break; } return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); return(tp); }
private TemplateParameter GetTemplateTemplateParameter(CXCursor cursor) { string paramName = clang.getCursorSpelling(cursor).ToString(); bool isVariadic = ClangTraits.IsVariadicTemplateParameter(cursor); TemplateParameter param = new TemplateParameter(paramName, TemplateParameterKind.Template, isVariadic); TemplateProto proto = GetTemplateProto(cursor); param.SetExtra(proto); return(param); }
private TemplateParameter GetTemplateNonTypeParameter(AST ast, TemplateProto tp, CXCursor cursor) { string paramName = clang.getCursorSpelling(cursor).ToString(); bool isVariadic = ClangTraits.IsVariadicTemplateParameter(cursor); // check if dependent or nontype bool isDependent = false; string dependName = null; string default_value = null; clang.visitChildren(cursor, (CXCursor c, CXCursor p, IntPtr data) => { if (ClangTraits.IsTypeRef(c)) { CXType t = clang.getCursorType(c); if (ClangTraits.IsUnexposedType(t)) { isDependent = true; dependName = clang.getCursorSpelling(c).ToString(); } } else if (ClangTraits.IsNonTypeTemplateParamLiteral(c)) { List <string> tokens = ASTVisitor.GetCursorTokens(c); default_value = string.Concat(tokens); } return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); TemplateParameter param; if (isDependent) { Debug.Assert(dependName != null); param = new TemplateParameter(paramName, TemplateParameterKind.Dependent, isVariadic); TemplateParameter dependeParam = tp.GetTemplateParameter(dependName); Debug.Assert(dependeParam != null); param.SetExtra(dependeParam, default_value); } else { CXType type = clang.getCursorType(cursor); NativeType nativeType = TypeVisitorHelper.GetNativeType(AST_, type); param = new TemplateParameter(paramName, TemplateParameterKind.NoneType, isVariadic); param.SetExtra(nativeType, default_value); } return(param); }
public void SetExtra(TemplateProto proto) { Debug.Assert(Kind == TemplateParameterKind.Template); Extra = proto; }