// AST traverse private CXChildVisitResult Visitor(CXCursor cursor, CXCursor parent, IntPtr data) { // skip system headers CXSourceLocation location = clang.getCursorLocation(cursor); if (clang.Location_isFromMainFile(location) == 0) { return(CXChildVisitResult.CXChildVisit_Continue); } // prepare client data GCHandle astHandle = (GCHandle)data; AST ast = astHandle.Target as AST; // get visitor IASTVisitor visitor = null; switch (cursor.kind) { // dealing with class case CXCursorKind.CXCursor_StructDecl: case CXCursorKind.CXCursor_ClassDecl: visitor = new ClassVisitor(ast); break; // dealing with enum type case CXCursorKind.CXCursor_EnumDecl: visitor = new EnumVisitor(ast); break; // dealing with function case CXCursorKind.CXCursor_FunctionDecl: visitor = new FunctionVisitor(ast); break; case CXCursorKind.CXCursor_Namespace: // ignore anonymous namespace if (clang.Cursor_isAnonymous(cursor) != 0) { return(CXChildVisitResult.CXChildVisit_Continue); } ProcessNamespace(cursor, data); return(CXChildVisitResult.CXChildVisit_Continue); case CXCursorKind.CXCursor_TypeAliasDecl: case CXCursorKind.CXCursor_TypedefDecl: //TypeVisitorHelper.GetNativeType(ast, clang.getCursorType(cursor)); visitor = new TypeVisitor(ast); break; case CXCursorKind.CXCursor_ClassTemplate: visitor = new ClassTemplateVisitor(ast, this, false); break; case CXCursorKind.CXCursor_ClassTemplatePartialSpecialization: visitor = new ClassTemplateVisitor(ast, this, true); break; case CXCursorKind.CXCursor_FunctionTemplate: break; default: // TODO ... any other break; } if (visitor != null) { if (!visitor.DoVisit(cursor, parent)) { return(CXChildVisitResult.CXChildVisit_Break); } } // deep iteratoring in sub visitor return(CXChildVisitResult.CXChildVisit_Continue); }
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); }
public ClassVisitor(AST ast, NativeClass owner = null) { AST_ = ast; OwnerClass_ = owner; }
public TypeVisitor(AST ast) { AST_ = ast; }
public ClassTemplateVisitor(AST ast, ASTVisitor visitor, bool isPartial) { AST_ = ast; visitor_ = visitor; isPartial_ = isPartial; }