• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ClangSharp.CXCursor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ClangSharp.CXCursor的典型用法代码示例。如果您正苦于以下问题:C# CXCursor类的具体用法?C# CXCursor怎么用?C# CXCursor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CXCursor类属于ClangSharp命名空间,在下文中一共展示了CXCursor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetTextFromCompoundStmt

        public static string GetTextFromCompoundStmt(CXCursor cursor)
        {
            var stmts = cursor.GetChildren ();

            CXSourceLocation start = clang.getCursorLocation (stmts.First ());
            CXSourceLocation end = clang.getRangeEnd (clang.getCursorExtent (stmts.Last ()));

            CXFile file;
            uint line1, line2;
            uint column1, column2;
            uint offset1, offset2;

            clang.getFileLocation (start, out file, out line1, out column1, out offset1);
            clang.getFileLocation (end, out file, out line2, out column2, out offset2);

            string filePath = clang.getFileName (file).ToString ();

            // We have to read bytes first and then convert them to utf8 string
            // because .net string is utf16 char array, but clang handles utf8 src text only.
            // clang's offset means byte offset (not utf16 char offset)

            uint count = offset2 - offset1 + 1;
            byte[] text = new byte[count];
            using(FileStream fs = File.OpenRead(filePath)) {
                fs.Seek (offset1, SeekOrigin.Begin);
                fs.Read (text, 0, (int)count);
            }

            return Encoding.UTF8.GetString (text);
        }
开发者ID:newky2k,项目名称:sample-translator,代码行数:30,代码来源:MethodHelper.cs


示例2: TranslationUnitPorter

        public TranslationUnitPorter(CXCursor translationUnit, string ns, IBindingLocator bindingLocator)
        {
            if (translationUnit.kind != CXCursorKind.CXCursor_TranslationUnit)
                throw new ArgumentException ();

            if (string.IsNullOrWhiteSpace (ns))
                throw new ArgumentException ();

            if (bindingLocator == null)
                throw new ArgumentNullException ();

            this.translationUnit = translationUnit;
            this.bindingLocator = bindingLocator;

            cu = SyntaxFactory.CompilationUnit ();

            IEnumerable<UsingDirectiveSyntax> usings = CreateUsings ();
            foreach (var u in usings)
                cu = cu.AddUsings (u);

            var nsDecl = CreateNamespace (ns);
            foreach (var c in PortClasses ())
                nsDecl = nsDecl.AddMembers (c);

            cu = cu.AddMembers (nsDecl);
        }
开发者ID:newky2k,项目名称:sample-translator,代码行数:26,代码来源:TranslationUnitPorter.cs


示例3: PortParameter

        public ParameterSyntax PortParameter(CXCursor paramDecl)
        {
            string paramName = paramDecl.ToString ();
            CXType type = clang.getCursorType (paramDecl);

            // We can't pass void as function parameter
            if (type.kind == CXTypeKind.CXType_Void)
                throw new ArgumentException ();

            var paramId = SF.Identifier (paramName);
            ParameterSyntax paramSyntax = SF.Parameter (paramId);

            if (type.kind == CXTypeKind.CXType_ObjCObjectPointer) {
                type = type.GetPointee ();
                TypeSyntax typeSyntax = PortType (type);
                return paramSyntax.WithType (typeSyntax);
            }

            if (type.kind == CXTypeKind.CXType_Pointer) {
                type = type.GetPointee ();

                if(type.kind == CXTypeKind.CXType_Void) // original type was void*
                    return paramSyntax.WithType(CommonTypes.IntPtrTypeSyntax);

                TypeSyntax typeSyntax = PortType (type);
                return paramSyntax.WithType (typeSyntax).WithModifiers (SF.TokenList (SF.Token (SyntaxKind.OutKeyword)));
            }

            TypeSyntax ts = PortType (type);
            return paramSyntax.WithType (ts);
        }
开发者ID:newky2k,项目名称:sample-translator,代码行数:31,代码来源:ObjCTypePorter.cs


示例4: WriteFunction

        public void WriteFunction(CXCursor cursor, string prefixStrip)
        {
            var functionType = clang.getCursorType(cursor);
            var functionName = clang.getCursorSpelling(cursor).ToString();
            var resultType = clang.getCursorResultType(cursor);

            m_tw.WriteLine(@"[DllImport({0}, EntryPoint = ""{1}"", CallingConvention = {2})]",
                m_libraryVarName,
                functionName,
                functionType.CallingConventionSpelling());
            m_tw.Write(@"public static extern ");

            FunctionHelper.WriteReturnType(resultType, m_tw);

            if (functionName.StartsWith(prefixStrip))
            {
                functionName = functionName.Substring(prefixStrip.Length);
            }

            m_tw.Write(@" " + functionName + @"(");

            var numArgTypes = clang.getNumArgTypes(functionType);

            for (uint i = 0; i < numArgTypes; ++i)
            {
                FunctionHelper.WriteArgument(functionType, clang.Cursor_getArgument(cursor, i), m_tw, i);
            }

            m_tw.WriteLine(@");");
            m_tw.WriteLine();
        }
开发者ID:denlittlstar,项目名称:FFmpeg.AutoGen,代码行数:31,代码来源:FunctionVisitor.cs


示例5: Visit

        public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            if (cursor.IsInSystemHeader())
            {
                return CXChildVisitResult.CXChildVisit_Continue;
            }

            var cursorKind = cursor.kind;
            if (cursorKind == CXCursorKind.CXCursor_MacroDefinition)
            {
                var macroName = clang.getCursorSpelling(cursor).ToString();

                if (m_visitedMacros.Contains(macroName))
                {
                    return CXChildVisitResult.CXChildVisit_Continue;
                }

                m_visitedMacros.Add(macroName);

                var expression = getMacroExpression(cursor);
                if (string.IsNullOrWhiteSpace(expression))
                {
                    return CXChildVisitResult.CXChildVisit_Continue;
                }

                m_tw.WriteLine(@"public const int {0} = {1};", macroName, expression);
            }

            return CXChildVisitResult.CXChildVisit_Continue;
        }
开发者ID:Ruslan-B,项目名称:FFmpeg.AutoGen,代码行数:30,代码来源:MacroVisitor.cs


示例6: WriteFunction

        private void WriteFunction(CXCursor cursor, string prefixStrip)
        {
            var functionType = clang.getCursorType(cursor);
            var functionName = clang.getCursorSpelling(cursor).ToString();
            var resultType = clang.getCursorResultType(cursor);

            _tw.WriteLine([email protected]"[DllImport({_libraryVarName}, " +
                          [email protected]"EntryPoint = ""{functionName}"", " +
                          [email protected]"CallingConvention = {functionType.CallingConventionSpelling()}, CharSet = CharSet.Ansi)]");

            if (resultType.IsPtrToConstChar())
                _tw.WriteLine(@"[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ConstCharPtrMarshaler))]");

            _tw.Write(@"public static extern ");

            FunctionHelper.WriteReturnType(resultType, _tw);

            if (functionName.StartsWith(prefixStrip))
                functionName = functionName.Substring(prefixStrip.Length);

            _tw.Write(@" " + functionName + @"(");

            var numArgTypes = clang.getNumArgTypes(functionType);

            for (uint i = 0; i < numArgTypes; ++i)
                FunctionHelper.WriteArgument(functionType, clang.Cursor_getArgument(cursor, i), _tw, i);

            _tw.WriteLine(@");");
            _tw.WriteLine();
        }
开发者ID:Ruslan-B,项目名称:FFmpeg.AutoGen,代码行数:30,代码来源:FunctionVisitor.cs


示例7: Visit

        public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            if (cursor.IsInSystemHeader())
            {
                return CXChildVisitResult.CXChildVisit_Continue;
            }

            CXCursorKind curKind = clang.getCursorKind(cursor);

            // look only at function decls
            if (curKind == CXCursorKind.CXCursor_FunctionDecl)
            {
                var functionName = clang.getCursorSpelling(cursor).ToString();

                if (this.visitedFunctions.Contains(functionName))
                {
                    return CXChildVisitResult.CXChildVisit_Continue;
                }

                this.visitedFunctions.Add(functionName);

                Extensions.WriteFunctionInfoHelper(cursor, this.tw, this.prefixStrip);

                return CXChildVisitResult.CXChildVisit_Continue;
            }

            return CXChildVisitResult.CXChildVisit_Recurse;
        }
开发者ID:krauthaufen,项目名称:ClangSharp,代码行数:28,代码来源:FunctionVisitor.cs


示例8: Visit

        public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            if (cursor.IsInSystemHeader())
            {
                return CXChildVisitResult.CXChildVisit_Continue;
            }

            CXCursorKind curKind = clang.getCursorKind(cursor);
            if (curKind == CXCursorKind.CXCursor_StructDecl)
            {
                this.fieldPosition = 0;
                var structName = clang.getCursorSpelling(cursor).ToString();

                // struct names can be empty, and so we visit its sibling to find the name
                if (string.IsNullOrEmpty(structName))
                {
                    var forwardDeclaringVisitor = new ForwardDeclarationVisitor(cursor);
                    clang.visitChildren(clang.getCursorSemanticParent(cursor), forwardDeclaringVisitor.Visit, new CXClientData(IntPtr.Zero));
                    structName = clang.getCursorSpelling(forwardDeclaringVisitor.ForwardDeclarationCursor).ToString();

                    if (string.IsNullOrEmpty(structName))
                    {
                        structName = "_";
                    }
                }

                if (!this.visitedStructs.Contains(structName))
                {
                    this.IndentedWriteLine("public partial struct " + structName);
                    this.IndentedWriteLine("{");

                    this.indentLevel++;
                    clang.visitChildren(cursor, this.Visit, new CXClientData(IntPtr.Zero));
                    this.indentLevel--;

                    this.IndentedWriteLine("}");
                    this.tw.WriteLine();

                    this.visitedStructs.Add(structName);
                }

                return CXChildVisitResult.CXChildVisit_Continue;
            }

            if (curKind == CXCursorKind.CXCursor_FieldDecl)
            {
                var fieldName = clang.getCursorSpelling(cursor).ToString();
                if (string.IsNullOrEmpty(fieldName))
                {
                    fieldName = "field" + this.fieldPosition; // what if they have fields called field*? :)
                }

                this.fieldPosition++;
                this.IndentedWriteLine(cursor.ToMarshalString(fieldName));
                return CXChildVisitResult.CXChildVisit_Continue;
            }

            return CXChildVisitResult.CXChildVisit_Recurse;
        }
开发者ID:krauthaufen,项目名称:ClangSharp,代码行数:59,代码来源:StructVisitor.cs


示例9: ObjCCategoryImplDeclContext

        public ObjCCategoryImplDeclContext(CXCursor categoryImplDecl)
        {
            if (categoryImplDecl.kind != CXCursorKind.CXCursor_ObjCCategoryImplDecl)
                throw new ArgumentException ();

            ObjCCategoryImpl = categoryImplDecl;
            ExtendedClassRef = GetExtendedClass (ObjCCategoryImpl);
        }
开发者ID:newky2k,项目名称:sample-translator,代码行数:8,代码来源:ObjCCategoryImplDeclContext.cs


示例10: ObjCImplementationDeclContext

        public ObjCImplementationDeclContext(CXCursor cursor)
        {
            if (cursor.kind != CXCursorKind.CXCursor_ObjCImplementationDecl)
                throw new ArgumentException ();

            ImplCursor = cursor;
            DeclCursor = clang.getCanonicalCursor (cursor);
            SuperClassRef = GetSuperClass (DeclCursor);
        }
开发者ID:newky2k,项目名称:sample-translator,代码行数:9,代码来源:ObjCImplementationDeclContext.cs


示例11: ArgumentHelper

        public static void ArgumentHelper(CXType functionType, CXCursor paramCursor, TextWriter tw, uint index)
        {
            var numArgTypes = clang.getNumArgTypes(functionType);
            var type = clang.getArgType(functionType, index);
            var cursorType = clang.getCursorType(paramCursor);

            var spelling = clang.getCursorSpelling(paramCursor).ToString();
            if (string.IsNullOrEmpty(spelling))
            {
                spelling = "param" + index;
            }

            switch (type.kind)
            {
                case CXTypeKind.CXType_Pointer:
                    var pointee = clang.getPointeeType(type);
                    switch (pointee.kind)
                    {
                        case CXTypeKind.CXType_Pointer:
                            tw.Write(pointee.IsPtrToConstChar() && clang.isConstQualifiedType(pointee) != 0 ? "string[]" : "out IntPtr");
                            break;
                        case CXTypeKind.CXType_FunctionProto:
                            tw.Write(clang.getTypeSpelling(cursorType).ToString());
                            break;
                        case CXTypeKind.CXType_Void:
                            tw.Write("IntPtr");
                            break;
                        case CXTypeKind.CXType_Char_S:
                            tw.Write(type.IsPtrToConstChar() ? "[MarshalAs(UnmanagedType.LPStr)] string" : "IntPtr"); // if it's not a const, it's best to go with IntPtr
                            break;
                        case CXTypeKind.CXType_WChar:
                            tw.Write(type.IsPtrToConstChar() ? "[MarshalAs(UnmanagedType.LPWStr)] string" : "IntPtr");
                            break;
                        default:
                            CommonTypeHandling(pointee, tw, "out ");
                            break;
                    }
                    break;
                default:
                    CommonTypeHandling(type, tw);
                    break;
            }

            tw.Write(" @");
            tw.Write(spelling);

            if (index != numArgTypes - 1)
            {
                tw.Write(", ");
            }
        }
开发者ID:rflechner,项目名称:LLVMSharp,代码行数:51,代码来源:Extensions.cs


示例12: Visit

        public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            if (cursor.IsInSystemHeader())
            {
                return CXChildVisitResult.CXChildVisit_Continue;
            }

            var cursorKind = clang.getCursorKind(cursor);

            // look only at function decls
            if (cursorKind == CXCursorKind.CXCursor_FunctionDecl)
            {
                var functionName = clang.getCursorSpelling(cursor).ToString();
                
                if (m_visitedFunctions.Contains(functionName))
                {
                    return CXChildVisitResult.CXChildVisit_Continue;
                }

                string libraryName;
                if (m_exportMap.TryGetValue(functionName, out libraryName))
                {
                    if (!string.Equals(libraryName, m_libraryName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        string message = string.Format(@"Warning: Function {0} belongs to {1}. Skipping generation for {2}.",
                            functionName, libraryName, m_libraryName);
                        Console.WriteLine(message);
                        return CXChildVisitResult.CXChildVisit_Continue;
                    }
                }
                else
                {
                    m_visitedFunctions.Add(functionName);

                    string message = string.Format(@"Info: Unknow function export {0}. Skipping generation for {1}.",
                           functionName, m_libraryName);
                    Console.WriteLine(message);
                    return CXChildVisitResult.CXChildVisit_Continue;
                }

                m_visitedFunctions.Add(functionName);

                WriteFunction(cursor, m_prefixStrip);

                return CXChildVisitResult.CXChildVisit_Continue;
            }

            return CXChildVisitResult.CXChildVisit_Recurse;
        }
开发者ID:denlittlstar,项目名称:FFmpeg.AutoGen,代码行数:49,代码来源:FunctionVisitor.cs


示例13: Dump

        static void Dump(CXCursor cursor, StringBuilder sb, int level, int mask)
        {
            for (int i = 1; i <= level; i++) {
                if (IsSet (mask, level - i)) {
                    if (i == level)
                        sb.Append ("|-");
                    else
                        sb.Append ("| ");
                } else {
                    if (i == level)
                        sb.Append ("`-");
                    else
                        sb.Append ("  ");
                }
            }
            sb.AppendFormat ("{0} {1}\n", cursor.kind, cursor.ToString ());

            CXCursor[] children = cursor.GetChildren ().ToArray();
            for (int i = 0; i < children.Length; i++)
                Dump (children[i], sb, level + 1, (mask << 1) | (i == children.Length - 1 ? 0 : 1));
        }
开发者ID:newky2k,项目名称:sample-translator,代码行数:21,代码来源:CXCursorExtensions.cs


示例14: Visit

        public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            if (cursor.IsInSystemHeader())
            {
                return CXChildVisitResult.CXChildVisit_Continue;
            }

            if (clang.equalCursors(cursor, m_beginningCursor) != 0)
            {
                m_beginningCursorReached = true;
                return CXChildVisitResult.CXChildVisit_Continue;
            }

            if (m_beginningCursorReached)
            {
                ForwardDeclarationCursor = cursor;
                return CXChildVisitResult.CXChildVisit_Break;
            }

            return CXChildVisitResult.CXChildVisit_Recurse;
        }
开发者ID:denlittlstar,项目名称:FFmpeg.AutoGen,代码行数:21,代码来源:ForwardDeclarationVisitor.cs


示例15: getMacroExpression

        private string getMacroExpression(CXCursor cursor)
        {
            var tu = clang.Cursor_getTranslationUnit(cursor);
            var range = clang.getCursorExtent(cursor);

            IntPtr pTokens;
            uint numTokens;
            clang.tokenize(tu, range, out pTokens, out numTokens);

            var sbValue = new StringBuilder();
            for (var n = 1; n < numTokens; n++)
            {
                var offset = n*Marshal.SizeOf<CXToken>();
                var token = Marshal.PtrToStructure<CXToken>(pTokens + offset);

                var tokenKind = clang.getTokenKind(token);
                if (tokenKind != CXTokenKind.CXToken_Comment)
                {
                    var spelling = clang.getTokenSpelling(tu, token).ToString();
                    if (spelling == @"#" ||
                        spelling == @"}" ||
                        spelling == @"L" ||
                        spelling == @"enum" ||
                        spelling == @"int" ||
                        spelling == @"int8_t" ||
                        spelling == @"int64_t" ||
                        spelling == @"struct" ||
                        spelling == @"typedef")
                    {
                        continue;
                    }
                    sbValue.Append(spelling);
                }
            }

            disposeTokens(tu, pTokens, numTokens);

            return sbValue.ToString();
        }
开发者ID:Ruslan-B,项目名称:FFmpeg.AutoGen,代码行数:39,代码来源:MacroVisitor.cs


示例16: getCursorCompletionString

 public static extern CXCompletionString getCursorCompletionString(CXCursor @cursor);
开发者ID:krauthaufen,项目名称:ClangSharp,代码行数:1,代码来源:Generated.cs


示例17: getDefinitionSpellingAndExtent

 public static extern void getDefinitionSpellingAndExtent(CXCursor @param0, out IntPtr @startBuf, out IntPtr @endBuf, out uint @startLine, out uint @startColumn, out uint @endLine, out uint @endColumn);
开发者ID:krauthaufen,项目名称:ClangSharp,代码行数:1,代码来源:Generated.cs


示例18: annotateTokens

 public static extern void annotateTokens(CXTranslationUnit @TU, out CXToken @Tokens, uint @NumTokens, out CXCursor @Cursors);
开发者ID:krauthaufen,项目名称:ClangSharp,代码行数:1,代码来源:Generated.cs


示例19: getCursorReferenceNameRange

 public static extern CXSourceRange getCursorReferenceNameRange(CXCursor @C, uint @NameFlags, uint @PieceIndex);
开发者ID:krauthaufen,项目名称:ClangSharp,代码行数:1,代码来源:Generated.cs


示例20: getSpecializedCursorTemplate

 public static extern CXCursor getSpecializedCursorTemplate(CXCursor @C);
开发者ID:krauthaufen,项目名称:ClangSharp,代码行数:1,代码来源:Generated.cs



注:本文中的ClangSharp.CXCursor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Classes.Player类代码示例发布时间:2022-05-24
下一篇:
C# ViewModels.MvxViewModelRequest类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap