Exemple #1
0
        public static NativeType GetNativeType(AST ast, CXType cxType, TypeVisitContext context = null)
        {
            CXType type = cxType;

            if (ClangTraits.IsElaboratedType(type) || ClangTraits.IsUnexposedType(type))
            {
                type = clang.getCursorType(clang.getTypeDeclaration(type));
            }
            Debug.Assert(!ClangTraits.IsInvalid(type));

            string typeName = clang.getTypeSpelling(type).ToString();

            Debug.Assert(typeName.Length > 0);
            NativeType nativeType = ast.GetType(typeName);

            if (!nativeType.Parsed)
            {
                nativeType.Parsed = true;

                // get cursor spelling as unscoped name
                CXCursor declaration = clang.getTypeDeclaration(type);
                nativeType.UnscopedName = clang.getCursorSpelling(declaration).ToString();

                // not a type reference nor a type with qualifiers
                if (ClangTraits.IsTypeEntity(type) || typeName == "std::nullptr_t")
                {
                    ProcessTypeEntity(ast, nativeType, type, context);
                }
                // using or typedef
                else if (ClangTraits.IsTypedef(type))
                {
                    ProcessTypedef(ast, nativeType, type, context);
                }
                else if (ClangTraits.IsArray(type))
                {
                    ProcessArray(ast, nativeType, type, context);
                }
                // reference and pointer
                else if (ClangTraits.IsReference(type) || ClangTraits.IsPointer(type))
                {
                    ProcessReferencePointer(ast, nativeType, type, context);
                }
                else if (ClangTraits.IsMemberPointer(type))
                {
                    ProcessMemberPointer(ast, nativeType, cxType, context);
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            return(nativeType);
        }
Exemple #2
0
        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);
        }