diff --git a/uppsrc/ide/Usage.cpp b/uppsrc/ide/Usage.cpp index 40348faa0..ac5a34403 100644 --- a/uppsrc/ide/Usage.cpp +++ b/uppsrc/ide/Usage.cpp @@ -150,6 +150,7 @@ void Ide::Usage(const String& id, const String& name, Point ref_pos) } else { bool isvirtual = false; + bool isstatic = false; bool istype = false; String cls; Progress pi("Indexing files"); @@ -160,15 +161,19 @@ void Ide::Usage(const String& id, const String& name, Point ref_pos) } for(const auto& f : ~CodeIndex()) for(const AnnotationItem& m : f.value.items) { - if(m.id == id && m.isvirtual) { - isvirtual = true; - cls = m.nest; - break; - } - if(m.id == id && IsStruct(m.kind)) { - istype = true; - cls = m.nest; - break; + if(m.id == id) { + if(m.isvirtual) { + isvirtual = true; + cls = m.nest; + break; + } + if(IsStruct(m.kind)) { + istype = true; + cls = m.nest; + break; + } + if(m.id == id && m.isstatic && f.key == editfile) + isstatic = true; } } @@ -196,32 +201,35 @@ void Ide::Usage(const String& id, const String& name, Point ref_pos) GatherVirtuals(bases, cls, signature, ids, visited); } - UsageId(name, id, ids, istype, unique); + UsageId(name, id, ids, istype, isstatic, unique); } UsageFinish(); } -void Ide::UsageId(const String& name, const String& id, const Index& ids, bool istype, Index& unique) +void Ide::UsageId(const String& name, const String& id, const Index& ids, bool istype, bool isstatic, Index& unique) { int q = id.ReverseFind("::"); String constructor = id + "::" + (q >= 0 ? id.Mid(q + 2) : id) + "("; String destructor = id + "::~("; SortByKey(CodeIndex()); for(int src = 0; src < 2; src++) - for(const auto& f : ~CodeIndex()) - if((findarg(GetFileExt(f.key), ".h", "") < 0) == src) { // headers first - auto Add = [&](Point mpos) { - AddReferenceLine(f.key, mpos, name, unique); - }; - for(const AnnotationItem& m : f.value.items) { - if(ids.Find(m.id) >= 0 || istype && (m.id.StartsWith(constructor) || m.id.StartsWith(destructor))) - Add(m.pos); + for(const auto& f : ~CodeIndex()) { + if(!isstatic || f.key == editfile) + if((findarg(GetFileExt(f.key), ".h", "") < 0) == src) { // headers first + auto Add = [&](Point mpos) { + AddReferenceLine(f.key, mpos, name, unique); + }; + for(const AnnotationItem& m : f.value.items) { + if(ids.Find(m.id) >= 0 || istype && (m.id.StartsWith(constructor) || m.id.StartsWith(destructor))) + Add(m.pos); + } + for(const ReferenceItem& m : f.value.refs) + if(ids.Find(m.id) >= 0) { + Add(m.pos); + } } - for(const ReferenceItem& m : f.value.refs) - if(ids.Find(m.id) >= 0) - Add(m.pos); - } + } } void Ide::UsageFinish() @@ -279,7 +287,7 @@ void Ide::FindDesignerItemReferences(const String& id, const String& name) ids.Add(m.id); SetFFound(ffoundi_next); FFound().Clear(); - UsageId(name, m.id, ids, IsStruct(m.kind), unique); + UsageId(name, m.id, ids, IsStruct(m.kind), m.isstatic, unique); UsageFinish(); return; } diff --git a/uppsrc/ide/clang/Indexer.cpp b/uppsrc/ide/clang/Indexer.cpp index 88dbc152a..5330ad948 100644 --- a/uppsrc/ide/clang/Indexer.cpp +++ b/uppsrc/ide/clang/Indexer.cpp @@ -89,6 +89,7 @@ void AnnotationItem::Serialize(Stream& s) % pos % definition % isvirtual + % isstatic % name % type % id @@ -105,7 +106,8 @@ void ReferenceItem::Serialize(Stream& s) { s % id % pos - % ref_pos; + % ref_pos + ; } void FileAnnotation::Serialize(Stream& s) @@ -115,7 +117,8 @@ void FileAnnotation::Serialize(Stream& s) % master_file % time % items - % refs; + % refs + ; } String CachedAnnotationPath(const String& source_file, const String& defines, const String& includes, const String& master_file) diff --git a/uppsrc/ide/clang/Visitor.cpp b/uppsrc/ide/clang/Visitor.cpp index b69ec73e5..8ce5269c6 100644 --- a/uppsrc/ide/clang/Visitor.cpp +++ b/uppsrc/ide/clang/Visitor.cpp @@ -299,6 +299,8 @@ bool ClangVisitor::ProcessNode(CXCursor cursor) r.nspace = ci.Nspace(); r.bases = ci.Bases(); r.isvirtual = kind == CXCursor_CXXMethod && clang_CXXMethod_isVirtual(cursor); + r.isstatic = clang_Cursor_getStorageClass(cursor) == CX_SC_Static; + if(findarg(r.kind, CXCursor_Constructor, CXCursor_Destructor) >= 0) { int q = r.id.Find('('); if(q >= 0) { diff --git a/uppsrc/ide/clang/clang.dli b/uppsrc/ide/clang/clang.dli index 5917746a7..7c4c6a880 100644 --- a/uppsrc/ide/clang/clang.dli +++ b/uppsrc/ide/clang/clang.dli @@ -25,6 +25,7 @@ FN(CXSourceLocation, clang_getCursorLocation, (CXCursor)) FN(CXCursor, clang_getCursorReferenced, (CXCursor)) FN(unsigned, clang_isCursorDefinition, (CXCursor)) FN(unsigned, clang_CXXMethod_isVirtual, (CXCursor C)) +FN(unsigned, clang_CXXMethod_isStatic, (CXCursor C)) FN(int, clang_Cursor_isNull, (CXCursor cursor)) FN(CXCursor, clang_getTranslationUnitCursor, (CXTranslationUnit)) FN(void, clang_PrintingPolicy_setProperty, (CXPrintingPolicy Policy, @@ -73,3 +74,5 @@ FN(enum CXDiagnosticSeverity, clang_getDiagnosticSeverity, (CXDiagnostic)) FN(CXType, clang_getTypedefDeclUnderlyingType, (CXCursor C)) FN(CXCursor, clang_getTypeDeclaration, (CXType T)) + +FN(enum CX_StorageClass, clang_Cursor_getStorageClass, (CXCursor)) diff --git a/uppsrc/ide/clang/clang.h b/uppsrc/ide/clang/clang.h index d996001a7..235868b80 100644 --- a/uppsrc/ide/clang/clang.h +++ b/uppsrc/ide/clang/clang.h @@ -146,6 +146,7 @@ struct AnnotationItem : Moveable { int kind = Null; bool definition = false; bool isvirtual = false; + bool isstatic = false; void Serialize(Stream& s); }; diff --git a/uppsrc/ide/clang/clang.upp b/uppsrc/ide/clang/clang.upp index 84e958c70..ffa13892a 100644 --- a/uppsrc/ide/clang/clang.upp +++ b/uppsrc/ide/clang/clang.upp @@ -11,10 +11,10 @@ file clang.h, libclang.h, clang.dli, + libclang.cpp, util.cpp, macros.cpp, Signature.cpp, - libclang.cpp, clang.cpp, Visitor.cpp, CurrentFile.cpp, diff --git a/uppsrc/ide/clang/libclang.cpp b/uppsrc/ide/clang/libclang.cpp index 9f27c6401..720327482 100644 --- a/uppsrc/ide/clang/libclang.cpp +++ b/uppsrc/ide/clang/libclang.cpp @@ -125,6 +125,11 @@ unsigned int clang_CXXMethod_isVirtual(CXCursor cursor) return LibClang().clang_CXXMethod_isVirtual(cursor); } +unsigned int clang_CXXMethod_isStatic(CXCursor cursor) +{ + return LibClang().clang_CXXMethod_isStatic(cursor); +} + int clang_Cursor_isNull(CXCursor cursor) { return LibClang().clang_Cursor_isNull(cursor); @@ -271,4 +276,9 @@ enum CXDiagnosticSeverity clang_getDiagnosticSeverity(CXDiagnostic d) return LibClang().clang_getDiagnosticSeverity(d); } +enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor c) +{ + return LibClang().clang_Cursor_getStorageClass(c); +} + #endif diff --git a/uppsrc/ide/clang/libclang.h b/uppsrc/ide/clang/libclang.h index 7189652e5..72951dc68 100644 --- a/uppsrc/ide/clang/libclang.h +++ b/uppsrc/ide/clang/libclang.h @@ -1972,6 +1972,7 @@ CXSourceLocation clang_getCursorLocation(CXCursor); CXCursor clang_getCursorReferenced(CXCursor); unsigned clang_isCursorDefinition(CXCursor); unsigned clang_CXXMethod_isVirtual(CXCursor C); +unsigned clang_CXXMethod_isStatic(CXCursor C); int clang_Cursor_isNull(CXCursor cursor); CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor); @@ -2026,3 +2027,22 @@ enum CXDiagnosticSeverity { }; enum CXDiagnosticSeverity clang_getDiagnosticSeverity(CXDiagnostic); + +enum CX_StorageClass { + CX_SC_Invalid, + CX_SC_None, + CX_SC_Extern, + CX_SC_Static, + CX_SC_PrivateExtern, + CX_SC_OpenCLWorkGroupLocal, + CX_SC_Auto, + CX_SC_Register +}; + +/** + * Returns the storage class for a function or variable declaration. + * + * If the passed in Cursor is not a function or variable declaration, + * CX_SC_Invalid is returned else the storage class. + */ +enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor); diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index 35727c8d3..1fdfe7c35 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -965,7 +965,7 @@ public: String GetFileLine(const String& path, int linei); void AddReferenceLine(const String& path, Point pos, const String& name, Index& unique); void UsageFinish(); - void UsageId(const String& name, const String& id, const Index& ids, bool istype, Index& unique); + void UsageId(const String& name, const String& id, const Index& ids, bool istype, bool isstatic, Index& unique); void Usage(); void IdUsage(); void Usage(const String& id, const String& name, Point ref_pos);