Ejemplo n.º 1
0
        // 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);
        }
Ejemplo n.º 2
0
        private CXChildVisitResult Visitor(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            // prepare client data
            GCHandle    classHandle = (GCHandle)data;
            NativeClass thisClass   = classHandle.Target as NativeClass;

            CXCursorKind kind = clang.getCursorKind(cursor);

            switch (kind)
            {
            case CXCursorKind.CXCursor_FieldDecl:
                ProcessField(thisClass, cursor, parent);
                break;

            case CXCursorKind.CXCursor_VarDecl:
                ProcessField(thisClass, cursor, parent, true);
                break;

            case CXCursorKind.CXCursor_CXXMethod:
                ProcessMethod(thisClass, cursor, parent);
                break;

            case CXCursorKind.CXCursor_CXXBaseSpecifier:
                ProcessBaseClass(thisClass, cursor, parent);
                break;

            case CXCursorKind.CXCursor_CXXFinalAttr:
                thisClass.IsFinal = true;
                break;

            case CXCursorKind.CXCursor_StructDecl:
            case CXCursorKind.CXCursor_ClassDecl:
                // recursive visit child
                ClassVisitor subClassVisitor = new ClassVisitor(AST_, thisClass);
                subClassVisitor.DoVisit(cursor, parent);
                break;

            case CXCursorKind.CXCursor_TypedefDecl:
            case CXCursorKind.CXCursor_TypeAliasDecl:
                ProcessTypeExport(thisClass, cursor, parent);
                break;

            //case CXCursorKind.CXCursor_ClassTemplate:
            //case CXCursorKind.CXCursor_ClassTemplatePartialSpecialization:
            //    break;
            //case CXCursorKind.CXCursor_FunctionTemplate:
            //    break;
            case CXCursorKind.CXCursor_Constructor:
                ProcessConstructor(thisClass, cursor, parent);
                break;

            case CXCursorKind.CXCursor_EnumDecl:
                EnumVisitor subEnumVisitor = new EnumVisitor(AST_, thisClass);
                subEnumVisitor.DoVisit(cursor, parent);
                break;

            default:
                break;
            }

            return(CXChildVisitResult.CXChildVisit_Continue);
        }