private TemplateParameter GetTemplateTypeParameter(CXCursor cursor) { string paramName = clang.getCursorSpelling(cursor).ToString(); bool isVariadic = ClangTraits.IsVariadicTemplateParameter(cursor); TemplateParameter param = new TemplateParameter(paramName, TemplateParameterKind.Type, isVariadic); return(param); }
public void SetExtra(TemplateParameter extra, string literal) { Debug.Assert(TemplateParameterKind.Dependent == Kind); Debug.Assert(TemplateParameterKind.Type == extra.Kind); Extra = new TemplateNonTypeParam { NoneType = extra, DefaultLiteral = literal }; }
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 AddTemplateParameter(TemplateParameter param) { ParametersList.Add(param); }
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); }