diff --git a/uppsrc/CppBase/CppBase.h b/uppsrc/CppBase/CppBase.h index aae77c296..6cfbedacd 100644 --- a/uppsrc/CppBase/CppBase.h +++ b/uppsrc/CppBase/CppBase.h @@ -107,6 +107,9 @@ struct FlatPP { const FlatPP& GetFlatPPFile(const char *path); // with #includes resolved +String NormalizeSourcePath(const String& path, const String& currdir); +String NormalizeSourcePath(const String& path); + void ClearSources(); const Index& GetAllSources(); void GatherSources(const String& master_path, const String& path_); diff --git a/uppsrc/CppBase/cpp.cpp b/uppsrc/CppBase/cpp.cpp index 7857fb2a4..2a5b6b56a 100644 --- a/uppsrc/CppBase/cpp.cpp +++ b/uppsrc/CppBase/cpp.cpp @@ -173,6 +173,7 @@ void Cpp::DoFlatInclude(const String& header_path) void Cpp::Do(const String& sourcefile, Stream& in, const String& currentfile, bool get_macros) { + LLOG("Cpp::Do " << sourcefile << ", current: " << currentfile); if(visited.Find(currentfile) >= 0 || visited.GetCount() > 20000) return; visited.Add(currentfile); diff --git a/uppsrc/CppBase/ppfile.cpp b/uppsrc/CppBase/ppfile.cpp index 670555bbb..36affbe1e 100644 --- a/uppsrc/CppBase/ppfile.cpp +++ b/uppsrc/CppBase/ppfile.cpp @@ -341,11 +341,11 @@ String GetIncludePath0(const char *s, const char *filedir) while(*s != '\r' && *s != '\n') { if(*s == type) { if(type == '\"') { - String fn = NormalizePath(name, filedir); + String fn = NormalizeSourcePath(name, filedir); if(FileExists(fn)) return fn; } - return GetFileOnPath(name, GetIncludePath(), false); + return NormalizeSourcePath(GetFileOnPath(name, GetIncludePath(), false)); } name.Cat(*s++); } diff --git a/uppsrc/CppBase/srcfiles.cpp b/uppsrc/CppBase/srcfiles.cpp index 9f285e352..65bb3a757 100644 --- a/uppsrc/CppBase/srcfiles.cpp +++ b/uppsrc/CppBase/srcfiles.cpp @@ -7,6 +7,21 @@ NAMESPACE_UPP static VectorMap sSrcFile; static Index sIncludes; +String NormalizeSourcePath(const String& path, const String& currdir) +{ + LTIMING("NormalizeSourcePath"); +#ifdef PLATFORM_WIN32 + return ToLower(NormalizePath(path, currdir)); +#else + return NormalizePath(path, currdir); +#endif +} + +String NormalizeSourcePath(const String& path) +{ + return NormalizeSourcePath(path, GetCurrentDirectory()); +} + void ClearSources() { sSrcFile.Clear(); @@ -26,7 +41,7 @@ const VectorMap& GetAllSourceMasters() void GatherSources(const String& master_path, const String& path_, Vector& parents) { RHITCOUNT("GatherSources"); - String path = NormalizePath(path_); + String path = NormalizeSourcePath(path_); if(sSrcFile.Find(path) >= 0) return; int ii = sSrcFile.GetCount(); @@ -47,7 +62,7 @@ void GatherSources(const String& master_path, const String& path) { LTIMING("GatherSources"); Vector parents; - GatherSources(master_path, path, parents); + GatherSources(NormalizeSourcePath(master_path), path, parents); } String GetMasterFile(const String& file) diff --git a/uppsrc/ide/Assist.cpp b/uppsrc/ide/Assist.cpp index 41d458a35..8d24b9378 100644 --- a/uppsrc/ide/Assist.cpp +++ b/uppsrc/ide/Assist.cpp @@ -10,6 +10,8 @@ #define LLOG(x) #endif +#define LTIMING(x) + class IndexSeparatorFrameCls : public CtrlFrame { virtual void FrameLayout(Rect& r) { r.right -= 1; } virtual void FramePaint(Draw& w, const Rect& r) { @@ -286,41 +288,37 @@ Vector AssistEditor::ReadBack(int q) return r; } -int memcmp_i(const char *s, const char *t, int n) -{ - while(n--) { - int q = ToUpper(*s++) - ToUpper(*t++); - if(q) - return q; - } - return 0; -} - void AssistEditor::SyncAssist() { - String name; - name = ReadIdBack(GetCursor(), include_assist); + LTIMING("SyncAssist"); + String name = ReadIdBack(GetCursor(), include_assist); + String uname = ToUpper(name); assist.Clear(); int typei = type.GetCursor() - 1; - for(int p = 0; p < 2; p++) { + Buffer found(assist_item.GetCount(), false); + for(int pass = 0; pass < 2; pass++) { VectorMap over; + LTIMING("FindPass"); for(int i = 0; i < assist_item.GetCount(); i++) { const CppItemInfo& m = assist_item[i]; - if((typei < 0 || m.typei == typei) && - (p ? memcmp_i(name, m.name, name.GetCount()) == 0 - && memcmp(name, m.name, name.GetCount()) - : memcmp(name, m.name, name.GetCount()) == 0)) { - int q = include_assist ? -1 : over.Find(m.name); - if(q < 0 || over[q] == m.typei && m.scope.GetCount()) { - assist.Add(RawToValue(m)); - if(q < 0) - over.Add(m.name, m.typei); - } + if(!found[i] && + (typei < 0 || m.typei == typei) && + (pass ? m.uname.StartsWith(uname) : m.name.StartsWith(name))) { + int q = include_assist ? -1 : over.Find(m.name); + if(q < 0 || over[q] == m.typei && m.scope.GetCount()) { + LTIMING("Assist Add"); + found[i] = true; + assist.Add(RawToValue(m)); + if(q < 0) + over.Add(m.name, m.typei); + } } } } - if(!include_assist) + if(!include_assist) { + LTIMING("Sort assist"); assist.Sort(0, CppItemInfoOrder); + } } bool AssistEditor::IncludeAssist() @@ -408,6 +406,7 @@ bool AssistEditor::IncludeAssist() void AssistEditor::Assist() { + LTIMING("Assist"); if(!assist_active) return; CloseAssist(); @@ -432,6 +431,7 @@ void AssistEditor::Assist() thisback = true; thisbackn = false; GatherItems(parser.current_scope, false, in_types, false); + RemoveDuplicates(); PopUpAssist(); return; } @@ -439,6 +439,7 @@ void AssistEditor::Assist() thisback = true; thisbackn = true; GatherItems(parser.current_scope, false, in_types, false); + RemoveDuplicates(); PopUpAssist(); return; } @@ -461,13 +462,15 @@ void AssistEditor::Assist() } else { GatherItems(parser.current_scope, false, in_types, true); - Index in_types2; Vector usings = Split(parser.context.namespace_using, ';'); for(int i = 0; i < usings.GetCount(); i++) - GatherItems(usings[i], false, in_types2, true); - GatherItems("", false, in_types2, true); + if(parser.current_scope != usings[i]) // Do not scan namespace already scanned + GatherItems(usings[i], false, in_types, true); + if(parser.current_scope.GetCount()) // Do not scan global namespace twice + GatherItems("", false, in_types, true); } } + RemoveDuplicates(); PopUpAssist(); } diff --git a/uppsrc/ide/Assist.h b/uppsrc/ide/Assist.h index 6b067fd39..d65144554 100644 --- a/uppsrc/ide/Assist.h +++ b/uppsrc/ide/Assist.h @@ -201,10 +201,9 @@ struct AssistEditor : CodeEditor, Navigator { void Virtuals(); void Thisbacks(); void AssistItemAdd(const String& scope, const CppItem& m, int typei); - void GatherItems0(const String& type, bool only_public, Index& in_types, - bool types); void GatherItems(const String& type, bool only_public, Index& in_types, bool types); + void RemoveDuplicates(); void SelParam(); int Ch(int q); diff --git a/uppsrc/ide/Browser/Base.cpp b/uppsrc/ide/Browser/Base.cpp index b78587cff..0f0aa580f 100644 --- a/uppsrc/ide/Browser/Base.cpp +++ b/uppsrc/ide/Browser/Base.cpp @@ -197,7 +197,7 @@ void BaseInfoSync(Progress& pi) int GetSourceFileIndex(const String& path) { - return source_file.FindPut(path); + return source_file.FindPut(NormalizeSourcePath(path)); } String GetSourceFilePath(int file) @@ -232,7 +232,8 @@ bool CheckFile(SourceFileInfo& f, const String& path) return true; Cpp pp; FileIn in(path); - pp.Preprocess(path, in, GetMasterFile(path), true); + String npath = NormalizeSourcePath(path); + pp.Preprocess(npath, in, GetMasterFile(npath), true); String included_id_macros = pp.GetIncludedMacroValues(f.ids.GetKeys()); if(f.included_id_macros != included_id_macros) { f.depends_time = Null; diff --git a/uppsrc/ide/ContextGoto.cpp b/uppsrc/ide/ContextGoto.cpp index 01b507d60..41e59578b 100644 --- a/uppsrc/ide/ContextGoto.cpp +++ b/uppsrc/ide/ContextGoto.cpp @@ -297,14 +297,17 @@ void Ide::ContextGoto0(int pos) q = CodeBase().Find(scope[j]); if(q >= 0) { const Array& n = CodeBase()[q]; - for(int pass = 0; pass < 2; pass++) - for(int i = 0; i < n.GetCount(); i++) { - if((pass || !istype[j] || n[i].IsType()) && n[i].name == id) { - JumpToDefinition(n, i, scope[j]); - FindId(id); - return; + for(int anyfile = 0; anyfile < 2; anyfile++) + for(int pass = 0; pass < 2; pass++) + for(int i = 0; i < n.GetCount(); i++) { + if(n[i].name == id + && (pass || !istype[j] || n[i].IsType()) + && (anyfile || findarg(n[i].filetype, FILE_CPP, FILE_C) >= 0)) { + JumpToDefinition(n, i, scope[j]); + FindId(id); + return; + } } - } } } } diff --git a/uppsrc/ide/Cpp.cpp b/uppsrc/ide/Cpp.cpp index 8b7ad5067..e84ec4815 100644 --- a/uppsrc/ide/Cpp.cpp +++ b/uppsrc/ide/Cpp.cpp @@ -10,6 +10,8 @@ #define LLOG(x) #endif +#define LTIMING(x) + static Array sEmpty; const Array& GetTypeItems(const String& type) @@ -117,12 +119,15 @@ void AssistScanError(int line, const String& text) void AssistEditor::Context(Parser& parser, int pos) { + LTIMING("Context"); + theide->ScanFile(false); String s = Get(0, pos); StringStream ss(s); Cpp cpp; - cpp.Preprocess(theide->editfile, ss, GetMasterFile(theide->editfile)); + String path = NormalizeSourcePath(theide->editfile); + cpp.Preprocess(path, ss, GetMasterFile(path)); parser.dobody = true; StringStream pin(cpp.output); @@ -273,13 +278,15 @@ int CharFilterT(int c) void AssistEditor::AssistItemAdd(const String& scope, const CppItem& m, int typei) { + if(*m.name == '.' || m.name.GetCount() == 0) + return; CppItemInfo& f = assist_item.Add(m.name); f.typei = typei; f.scope = scope; (CppItem&)f = m; } -void AssistEditor::GatherItems0(const String& type, bool only_public, Index& in_types, bool types) +void AssistEditor::GatherItems(const String& type, bool only_public, Index& in_types, bool types) { LLOG("GatherItems " << type); if(in_types.Find(type) >= 0) { @@ -292,6 +299,7 @@ void AssistEditor::GatherItems0(const String& type, bool only_public, Index= 0) { if(types) { + LLOG("GatherItems types"); if(ntp.GetCount()) ntp << "::"; int typei = assist_type.FindAdd(""); @@ -338,7 +346,7 @@ void AssistEditor::GatherItems0(const String& type, bool only_public, Index& in_types, bool types) +void AssistEditor::RemoveDuplicates() { - int i0 = assist_item.GetCount(); - GatherItems0(type, only_public, in_types, types); - StableSort(assist_item.Begin() + i0, assist_item.End(), OrderAssistItems); + LTIMING("RemoveDuplicates"); + StableSort(assist_item, OrderAssistItems); Vector remove; - int i = i0; - while(i < assist_item.GetCount()) { + int i = 0; + while(i < assist_item.GetCount()) { // Remove identical items int ii = i; i++; - while(i < assist_item.GetCount() && assist_item[i].qitem == assist_item[ii].qitem) + while(i < assist_item.GetCount() + && assist_item[ii].typei == assist_item[i].typei + && assist_item[ii].qitem == assist_item[i].qitem) remove.Add(i++); - i++; } assist_item.Remove(remove); } diff --git a/uppsrc/ide/ide.upp b/uppsrc/ide/ide.upp index b662eeda4..af5aa8653 100644 --- a/uppsrc/ide/ide.upp +++ b/uppsrc/ide/ide.upp @@ -42,8 +42,8 @@ file EditorTabBar.cpp, Bottom.cpp, t.cpp, - Cpp.cpp, Assist.h, + Cpp.cpp, Assist.cpp, DCopy.cpp, ContextGoto.cpp,