public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data) { if (!File.Equals(TranslationUnitParser.GetFileName(cursor))) { return(CXChildVisitResult.Continue); } CXCursor referenced = project.ClangManager.GetCursorReferenced(cursor); string Usr = project.ClangManager.GetCursorUsrString(referenced); if (UsrReferenced.Equals(Usr)) { CXSourceRange range = clang.Cursor_getSpellingNameRange(cursor, 0, 0); var reference = new Reference(project, cursor, range); //FIXME: don't block! Document doc = IdeApp.Workbench.OpenDocument(reference.FileName, project, false).Result; if (!references.Contains(reference) //this check is needed because explicit namespace qualifiers, eg: "std" from std::toupper //are also found when finding eg:toupper references, but has the same cursorkind as eg:"toupper" && doc.Editor.GetTextAt(reference.Begin.Offset, reference.Length).Equals(referenced.ToString())) { references.Add(reference); } } return(CXChildVisitResult.Recurse); }
string GetDefaultParameter(CXCursor handle) { string result = null; handle.VisitChildren((cursor, parent, client_data) => { if (cursor.kind == CXCursorKind.CXCursor_CXXBoolLiteralExpr || cursor.kind == CXCursorKind.CXCursor_IntegerLiteral || cursor.kind == CXCursorKind.CXCursor_FloatingLiteral || cursor.kind == CXCursorKind.CXCursor_CompoundLiteralExpr || cursor.kind == CXCursorKind.CXCursor_FirstExpr || cursor.kind == CXCursorKind.CXCursor_BinaryOperator) { CXSourceRange range = clang.getCursorExtent(cursor); CXToken *tokens = null; uint numTokens = 0; clang.tokenize(cursor.TranslationUnit, range, &tokens, &numTokens); for (int i = 0; i < numTokens; ++i) { result += clang.getTokenSpelling(cursor.TranslationUnit, tokens[i]).ToString(); } clang.disposeTokens(cursor.TranslationUnit, tokens, numTokens); return(CXChildVisitResult.CXChildVisit_Break); } return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData()); return(result); }
/// <summary> /// Get Completion Fix It /// </summary> /// <param name="completion_index">Completion Index</param> /// <param name="fixit_index">Fix It Index</param> /// <param name="replacement_range">Replacement Clang Source Range</param> /// <returns>Completion Fix It</returns> public string GetCompletionFixIt(int completion_index, int fixit_index, out ClangSourceRange replacement_range) { var native_range = new CXSourceRange(); var ret = LibClang.clang_getCompletionFixIt(this.Handle, (uint)completion_index, (uint)fixit_index, ref native_range); replacement_range = native_range.ToManaged(); return(ret.ToManaged()); }
/// <summary> /// Initializes a new instance of the <see cref="CBinding.Refactoring.Reference"/> class. /// </summary> /// <param name="proj">Project.</param> /// <param name="cursor">Cursor referenced.</param> /// <param name="sourceRange">Source location and range.</param> public Reference(CProject proj, CXCursor cursor, CXSourceRange sourceRange) { project = proj; Cursor = cursor; SourceRange = sourceRange; Begin = project.ClangManager.GetSourceLocation(clang.getRangeStart(sourceRange)); End = project.ClangManager.GetSourceLocation(clang.getRangeEnd(sourceRange)); Offset = Begin.Offset; FileName = Begin.FileName; Length = End.Offset - Begin.Offset; }
private void SetSourceProvider(Core.Dependency leaf, CXCursor cursor) { CXSourceRange extent = clang.getCursorExtent(cursor); CXSourceLocation startLocation = clang.getRangeStart(extent); uint startLine = 0, startColumn = 0, offset; CXFile file; clang.getSpellingLocation(startLocation, out file, out startLine, out startColumn, out offset); this.parser.Sources.Create(leaf, new Core.SourceProvider(clang.getFileName(file).ToString())); }
private static int NumLines(CXCursor cursor) { CXSourceRange extent = clang.getCursorExtent(cursor); CXSourceLocation startLocation = clang.getRangeStart(extent); CXSourceLocation endLocation = clang.getRangeEnd(extent); uint startLine = 0, startColumn = 0; uint endLine = 0, endColumn = 0, offset; CXFile file; clang.getSpellingLocation(startLocation, out file, out startLine, out startColumn, out offset); clang.getSpellingLocation(endLocation, out file, out endLine, out endColumn, out offset); return(1 + (int)endLine - (int)startLine); }
private static string GetClass(CXCursor cursor) { CXSourceRange extent = clang.getCursorExtent(cursor); CXSourceLocation startLocation = clang.getRangeStart(extent); CXSourceLocation endLocation = clang.getRangeEnd(extent); uint startLine = 0, startColumn = 0, offset; CXFile file; clang.getSpellingLocation(startLocation, out file, out startLine, out startColumn, out offset); var fp = new System.IO.StreamReader(clang.getFileName(file).ToString()); var line = string.Empty; for (var i = 0; i < startLine; ++i) { line = fp.ReadLine(); } fp.Close(); if (line.Contains("template")) { return(string.Empty); } int index; line = line.Substring(0, line.LastIndexOf('(')); line = line.Substring(0, line.LastIndexOf(':') - 1); index = line.LastIndexOf(' '); if (index != -1) { line = line.Substring(index + 1); } index = line.LastIndexOf('\t'); if (index != -1) { line = line.Substring(index + 1); } line = line.Trim(); return(line.Replace("::", ".")); }
private CXChildVisitResult ParameterVisitor(CXCursor cursor, CXCursor parent, IntPtr data) { if (CXCursorKind.CXCursor_ParmDecl == cursor.kind) { // prepare client data GCHandle astHandle = (GCHandle)data; OnVisitFunctionParameter func = astHandle.Target as OnVisitFunctionParameter; CXType type = clang.getCursorType(cursor); FunctionParameter param = new FunctionParameter { Name = clang.getCursorSpelling(cursor).ToString(), Type = TypeVisitorHelper.GetNativeType(AST_, type) }; clang.visitChildren(cursor, (CXCursor c, CXCursor p, IntPtr d) => { if (ClangTraits.IsLiteralCursor(c)) { // get liter-string from token CXSourceRange range = clang.getCursorExtent(c); IntPtr tokens = IntPtr.Zero; uint numToken; string liter = ""; clang.tokenize(ASTVisitor.CurrentTU, range, out tokens, out numToken); IntPtr tmp = tokens; for (uint loop = 0; loop < numToken; ++loop, IntPtr.Add(tmp, 1)) { CXToken token = Marshal.PtrToStructure <CXToken>(tmp); liter += clang.getTokenSpelling(ASTVisitor.CurrentTU, token).ToString(); } clang.disposeTokens(ASTVisitor.CurrentTU, tokens, numToken); // set default literal param.DefaultValue = liter; } return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); func(param); } return(CXChildVisitResult.CXChildVisit_Recurse); }
public static List <string> GetCursorTokens(CXCursor cursor) { // get liter-string from token CXSourceRange range = clang.getCursorExtent(cursor); IntPtr tokens = IntPtr.Zero; uint numToken; List <string> result = new List <string>(); clang.tokenize(CurrentTU, range, out tokens, out numToken); IntPtr tmp = tokens; for (uint loop = 0; loop < numToken; ++loop, tmp = IntPtr.Add(tmp, Marshal.SizeOf <CXToken>())) { CXToken token = Marshal.PtrToStructure <CXToken>(tmp); result.Add(clang.getTokenSpelling(CurrentTU, token).ToString()); } clang.disposeTokens(CurrentTU, tokens, numToken); return(result); }
static CXToken[] Tokenize(CXTranslationUnit tu, CXSourceRange range) { IntPtr pTokens; uint numTokens; clang.tokenize(tu, range, out pTokens, out numTokens); try { var tokens = new CXToken[numTokens]; unsafe { var p = (CXToken *)pTokens.ToPointer(); for (uint i = 0; i < numTokens; i++) { tokens[i] = p[i]; } } return(tokens); } finally { clang.disposeTokens(tu, pTokens, numTokens); } }
public ClangSourceRange(int begin, int end) { this.source = new CXSourceRange(begin, end); }
internal unsafe static extern CXString clang_getDiagnosticFixIt(CXDiagnostic diagnostic, uint fixIt, CXSourceRange* replacementRange);
internal static unsafe extern void clang_tokenize(CXTranslationUnit tu, CXSourceRange Range, CXToken** Tokens, uint* NumTokens);
internal static extern CXSourceLocation clang_getRangeEnd(CXSourceRange range);
/// <summary> /// Convert to Managed Clang Source Range /// </summary> /// <param name="range">Native Clang Source Range</param> /// <returns>Managed Clang Source Range</returns> internal static ClangSourceRange ToManaged(this CXSourceRange range) { return(new ClangSourceRange(range)); }
/// <summary> /// Constructor /// </summary> /// <param name="source">Native Clang Source Range</param> internal ClangSourceRange(CXSourceRange source) { this.Source = source; }
private static SourceRange ExtractRange(CXSourceRange range) { return(new SourceRange(ExtractLocation(range.Start), ExtractLocation(range.End))); }
/// <summary> /// Constructor /// </summary> /// <param name="source">Native Clang Source Range</param> internal ClangSourceRange(CXSourceRange source) { this._start = ClangSourceLocation.Null; this._end = ClangSourceLocation.Null; this.Source = source; }
static CXSourceRange() { NullRange = Library.clang_getNullRange(); }
internal static extern uint clang_equalRanges(CXSourceRange r1, CXSourceRange r2);
/// <summary> /// Initializes a new instance of the <see cref="SourceRange"/> class. /// </summary> /// <param name="sourceRange">The sourceRange<see cref="CXSourceRange"/></param> internal SourceRange(CXSourceRange sourceRange) { this.m_value = sourceRange; }