Пример #1
0
        private void ProcessField(NativeClass thisClass, CXCursor cursor, CXCursor parent, bool isStatic = false)
        {
            // get field name
            string fieldName = clang.getCursorSpelling(cursor).ToString();

            // get field type
            CXType     type       = clang.getCursorType(cursor);
            NativeType nativeType = TypeVisitorHelper.GetNativeType(AST_, type);

            // get field access specifier
            AccessSpecifier access = ClangTraits.ToAccessSpecifier(clang.getCXXAccessSpecifier(cursor));

            // create field object
            Field f = new Field
            {
                Name     = fieldName,
                Access   = access,
                Type     = nativeType,
                IsStatic = isStatic
            };

            thisClass.AddField(f);
        }
Пример #2
0
 public EnumVisitor(AST ast, NativeClass ownerClass = null)
 {
     AST_        = ast;
     OwnerClass_ = ownerClass;
 }
Пример #3
0
 public void SetClass(NativeClass c)
 {
     SetType(BasicType.Object, c);
 }
Пример #4
0
        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);
        }
Пример #5
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);
        }
Пример #6
0
 public ClassVisitor(AST ast, NativeClass owner = null)
 {
     AST_        = ast;
     OwnerClass_ = owner;
 }