From e40bd48ee00c7c15034c10f52f9d0732df2b395f Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Sat, 6 Aug 2022 19:39:35 +0200 Subject: [PATCH] Fixing issues... --- uppsrc/ide/Assist.cpp | 11 ++++---- uppsrc/ide/Assist.h | 2 +- uppsrc/ide/IncludeTrick.cpp | 4 ++- uppsrc/ide/clang/Indexer.cpp | 26 ++++++++----------- uppsrc/ide/clang/Signature.cpp | 27 ++++++++++++-------- uppsrc/ide/clang/Visitor.cpp | 3 --- uppsrc/ide/clang/todo.txt | 35 +++++++++++++++++++------- uppsrc/ide/idefile.cpp | 4 +-- uppsrc/ide/main.cpp | 9 ------- upptst/ide_CleanupId/etalon.log | 28 ++++++++++++++++++--- upptst/ide_CleanupId/ide_CleanupId.cpp | 22 ++++++++++++++-- 11 files changed, 110 insertions(+), 61 deletions(-) diff --git a/uppsrc/ide/Assist.cpp b/uppsrc/ide/Assist.cpp index 87378c500..8449899e2 100644 --- a/uppsrc/ide/Assist.cpp +++ b/uppsrc/ide/Assist.cpp @@ -436,14 +436,14 @@ bool AssistEditor::IncludeAssist() return true; } -CurrentFileContext AssistEditor::CurrentContext() +CurrentFileContext AssistEditor::CurrentContext(int pos) { CurrentFileContext cfx; cfx.filename = cfx.real_filename = NormalizePath(theide->editfile); cfx.includes = theide->GetCurrentIncludePath(); cfx.defines = theide->GetCurrentDefines(); if(!IsView() && GetLength() < 200000) { - cfx.content = Get(); + cfx.content = Get(0, min(GetLength(), pos)); if(!IsSourceFile(cfx.filename)) { if(master_source.GetCount()) { MakeIncludeTrick(cfx); @@ -459,7 +459,7 @@ CurrentFileContext AssistEditor::CurrentContext() DDUMP(cfx.filename); DDUMP(cfx.real_filename); if(cfx.content.GetCount()) - SaveFile(ConfigFile("pseudo_header_src.cpp"), cfx.content); + SaveFile(ConfigFile("CurrentContext.cpp"), cfx.content); #endif return cfx; } @@ -514,9 +514,10 @@ void AssistEditor::Assist(bool macros) return; int pos = GetCursor(); - int line = GetLinePos(pos); // TODO: limit, solve subincludes + ReadIdBackPos(pos, false); // libclang does now work well if file is not truncated for autocomplete + CurrentFileContext cfx = CurrentContext(pos); + int line = GetLinePos(pos); int line_delta; - CurrentFileContext cfx = CurrentContext(); if(cfx.content.GetCount()) StartAutoComplete(cfx, line + line_delta + 1, pos + 1, macros, [=](const Vector& items) { for(const AutoCompleteItem& m : items) { diff --git a/uppsrc/ide/Assist.h b/uppsrc/ide/Assist.h index bc76c6633..02e703da3 100644 --- a/uppsrc/ide/Assist.h +++ b/uppsrc/ide/Assist.h @@ -153,7 +153,7 @@ struct AssistEditor : CodeEditor, Navigator { PPInfo hdepend2; String master_source; - CurrentFileContext CurrentContext(); + CurrentFileContext CurrentContext(int pos = INT_MAX); void SyncCurrentFile(const CurrentFileContext& ctx); void SyncCurrentFile(); void SyncHeaders(); diff --git a/uppsrc/ide/IncludeTrick.cpp b/uppsrc/ide/IncludeTrick.cpp index aeceae492..9e0be243a 100644 --- a/uppsrc/ide/IncludeTrick.cpp +++ b/uppsrc/ide/IncludeTrick.cpp @@ -19,13 +19,15 @@ void AssistEditor::SyncHeaders() master_source = FindMasterSource(hdepend2, GetIdeWorkspace(), editfile); LLOG("Master source " << editfile << " -> " << master_source); } - + +#ifdef _DEBUG // TODO: Remove hdepend2.WhenBlitzBlock = [=](const String& inc, const String& path) { PutConsole(String() << inc << " blocks BLITZ of " << path); }; if(hdepend2.BlitzApproved(editfile)) PutConsole(editfile + " BLITZ approved"); +#endif } bool AssistEditor::DoIncludeTrick(Index& visited, int level, StringBuffer& out, String path, const String& target_path, int& line_delta) diff --git a/uppsrc/ide/clang/Indexer.cpp b/uppsrc/ide/clang/Indexer.cpp index 7d42a4c0d..42b14f63f 100644 --- a/uppsrc/ide/clang/Indexer.cpp +++ b/uppsrc/ide/clang/Indexer.cpp @@ -1,7 +1,7 @@ #include "clang.h" #define LTIMING(x) //TIMING(x) -#define LTIMESTOP(x) DTIMESTOP(x) +#define LTIMESTOP(x) //DTIMESTOP(x) #define LLOG(x) //DLOG(x) #define LDUMP(x) //DDUMP(x) #define LDUMPM(x) //DDUMPM(x) @@ -179,7 +179,7 @@ void Indexer::IndexerThread() VectorMap do_file_cache; v.WhenFile = [&](const String& path) { - DTIMING("WhenFile"); + LTIMING("WhenFile"); if(IsNull(path)) return false; if(current_file != path) { @@ -193,7 +193,7 @@ void Indexer::IndexerThread() current_file = path; int q = do_file_cache.Find(path); if(q < 0) { - DTIMING("WhenFile 2"); + LTIMING("WhenFile 2"); Mutex::Lock __(mutex); do_file = job.file_times.Find(NormalizePath(path)) >= 0; do_file_cache.Add(path, do_file); @@ -222,7 +222,7 @@ void Indexer::IndexerThread() f.includes = job.includes; (CppFileInfo&)f = pick(m.value); f.time = job.file_times.Get(path, Time::Low()); - DLOG("Storing " << path); + LLOG("Storing " << path); // TODO: Compress ? SaveChangedFile(CachedAnnotationPath(path, f.defines, f.includes, job.master_files.Get(path, Null)), StoreAsString(f), true); GuiLock __; @@ -234,7 +234,7 @@ void Indexer::IndexerThread() { Mutex::Lock __(mutex); if(--running_indexers == 0 && jobs.GetCount()) { - DLOG("Done everything " << (msecs() - tm0) / 1000.0 << " s"); + LLOG("Done everything " << (msecs() - tm0) / 1000.0 << " s"); jobs.Clear(); scheduler.Broadcast(); last = true; @@ -242,7 +242,7 @@ void Indexer::IndexerThread() } #ifdef _DEBUG if(last) - DumpIndex(); // TODO remove + DumpIndex(); // TODO remove? #endif if(Thread::IsShutdownThreads()) break; @@ -281,7 +281,7 @@ void Indexer::SchedulerThread() while(!Thread::IsShutdownThreads()) { scheduler.Wait(); - DTIMESTOP("Scheduler"); + LTIMESTOP("Scheduler"); Mutex::Lock __(mutex); String includes, defines; @@ -303,7 +303,7 @@ void Indexer::SchedulerThread() ppi.Dirty(); { - DTIMING("Load workspace"); + LTIMING("Load workspace"); Workspace wspc; wspc.Scan(main); @@ -325,7 +325,7 @@ void Indexer::SchedulerThread() } { // TODO different master header currentfile / index issue - DTIMING("Dependencies"); + LTIMING("Dependencies"); for(const Vector>& pk : sources) for(const Tuple& m : pk) { if(IsCSourceFile(m.a)) { @@ -346,9 +346,6 @@ void Indexer::SchedulerThread() Index dirty_files; // files that need to be recompiled (including headers) - DDUMPM(files); - DDUMP(dirty_files); - { LTIMESTOP("Loading from cache, checking filetimes"); for(const auto& m : ~files) { @@ -390,7 +387,6 @@ void Indexer::SchedulerThread() { LTIMESTOP("Create indexer jobs"); - LDUMP(includes); jobs.Clear(); jobi = 0; for(const auto& pkg : ~sources) { @@ -401,7 +397,7 @@ void Indexer::SchedulerThread() job.file_times.Add(path, files.Get(path, Time::Low())); for(int q = master.Find(path); q >= 0; q = master.FindNext(q)) { String hpath = header[q]; - if(dirty_files.Find(hpath) >= 0) { + if(dirty_files.Find(hpath) >= 0) { // TODO: Ignore external includes if times are ok job.file_times.Add(hpath, files.Get(hpath, Time::Low())); job.master_files.Add(header[q], path); } @@ -438,7 +434,7 @@ void Indexer::SchedulerThread() } } if(jobs.GetCount()) { - DLOG("======= Unleash indexers"); + LLOG("======= Unleash indexers"); event.Broadcast(); } } diff --git a/uppsrc/ide/clang/Signature.cpp b/uppsrc/ide/clang/Signature.cpp index 9a01bb659..15424ef5b 100644 --- a/uppsrc/ide/clang/Signature.cpp +++ b/uppsrc/ide/clang/Signature.cpp @@ -76,38 +76,45 @@ String CleanupId(const char *s) }; while(*s && *s != '{') { if(iscid(*s)) { + auto IsOperator = [](const char *s) { + return memcmp(s, "operator", 8) == 0; + }; + const char *b = s; String id; while(iscid(*s) || *s == ':') { - s++; - if(*s == '<' && !operator_def) { - id.Cat(b, s); - SkipT(); + id.Cat(*s++); + if(*s == '<') { + if(id.GetCount() == 8 && IsOperator(id)) + break; + if(id.GetCount() > 8) { + const char *s = ~id + id.GetCount() - 8; + if(IsOperator(s) && !iscid(s[-1])) + break; + } + SkipT(); // Skip template arguments like in Foo::Method() -> Foo::Method b = s; + } } - id.Cat(b, s); if(id == s_attribute) { while(mm.GetCount() && mm[mm.GetCount() - 1] == ' ') mm.SetLength(mm.GetCount() - 1); break; } - if((*s == ',' || *s == ')') && was_param_type) { + if((*s == ',' || *s == ')' || *s == '[') && was_param_type) { was_param_type = false; continue; } if(IsIgnored(id)) continue; - auto IsOperator = [](const char *s) { - return memcmp(s, "operator", 8) == 0; - }; if(was_id) mm.Cat(' '); if(!operator_def) // because of conversion operators e.g. Foo::operator bool() name_pos = mm.GetCount(); if(id.GetCount() == 8 && IsOperator(id)) operator_def = true; - if(id.GetCount() > 8) { // conversion operator? + if(id.GetCount() > 8) { const char *s = ~id + id.GetCount() - 8; operator_def = IsOperator(s) && !iscid(s[-1]); } diff --git a/uppsrc/ide/clang/Visitor.cpp b/uppsrc/ide/clang/Visitor.cpp index 4b0513992..a21c2037a 100644 --- a/uppsrc/ide/clang/Visitor.cpp +++ b/uppsrc/ide/clang/Visitor.cpp @@ -245,9 +245,7 @@ bool ClangVisitor::ProcessNode(CXCursor cursor) CXCursor ref = clang_getCursorReferenced(cursor); String id = ci.Id(); - DHITCOUNT("Resolved ID"); if(id.GetCount()) { - DTIMING("Has ID"); LoadLocation(); AnnotationItem& r = info.GetAdd(loc.path).items.Add(); r.kind = ci.Kind(); @@ -284,7 +282,6 @@ bool ClangVisitor::ProcessNode(CXCursor cursor) } if(!clang_Cursor_isNull(ref)) { - DTIMING("Ref"); LoadLocation(); SourceLocation ref_loc = GetLocation(clang_getCursorLocation(ref)); int q = tfn.Find(ref_loc); diff --git a/uppsrc/ide/clang/todo.txt b/uppsrc/ide/clang/todo.txt index 5ab17c357..2deab4d00 100644 --- a/uppsrc/ide/clang/todo.txt +++ b/uppsrc/ide/clang/todo.txt @@ -20,7 +20,7 @@ ISUES: - Do TODOs -- header header +- header without .cpp speed - aux files / autocomplete @@ -76,8 +76,6 @@ ISUES: - reduce cache -- id = main(int,const char*argv[]) - argv[] should not be there - - first macro in the file (AssistTest) is ignored - when scope is selected in navigator, search should be ingored @@ -86,11 +84,12 @@ ISUES: - AutoComplete remove duplicate lines -- Indexer.cpp refs - [3, 417] Upp::Stream::operator // operator<< ? +- Indexer.cpp refs (issue with macro) [3, 417] Upp::operator [3, 417] Upp::VppLog() [3, 417] Upp::EOL + +- Indexer.cpp refs [3, 418] CoEvent::Broadcast() // somehow choose Indexer::event here [9, 418] CoEvent::Broadcast() [3, 418] Indexer::event @@ -120,16 +119,25 @@ ISUES: - Time GatherDependencies(const String& path, VectorMap& result, Index& define_includes, Alt+I next line "No relevant..." -- No autocomplete in void MainConfigDlg::FlagDlg() - -- void MainConfigDlg::FlagDlg() no Upp function on Ctrl+Space - - TriggerIndexer should probably also restart CurrentFile and maybe autocomplete - TriggerIndexer on theide exit - different master header currentfile / index issue +- DLOG(CleanupId(s)); - jump on CleanupId does go to DLOG (it has a good reason to, but anyway...) + +- In CONSOLE_APP_MAIN jumps do not wrok + +- Alt-K - maybe should show declaration/definition too? + +- Indexer.cpp [7, 423] (Indexer::Job&,const Upp::String&)const + +- Indexer.cpp [32, 368] FileAnnotation&&)(false) + +- Alt-K in void AssistEditor::Assist(bool macros) does not show all (_Bool problem?) + +- In Navigator, Assist should be before AssistEditor, when search is "Assist" GREAT CODEBASE PURGE: @@ -204,6 +212,15 @@ LATER: DONE: +- No autocomplete in void MainConfigDlg::FlagDlg() + +- void MainConfigDlg::FlagDlg() no Upp function on Ctrl+Space + +- id = main(int,const char*argv[]) - argv[] should not be there + +- Indexer.cpp refs + [3, 417] Upp::Stream::operator // operator<< ? + - FlagDlg - Size SplashCtrl::MakeLogo(Ctrl& parent, Array& ctrl) diff --git a/uppsrc/ide/idefile.cpp b/uppsrc/ide/idefile.cpp index c8c7b9f2c..375ea5492 100644 --- a/uppsrc/ide/idefile.cpp +++ b/uppsrc/ide/idefile.cpp @@ -386,10 +386,8 @@ void Ide::SaveFile0(bool always) FindFile ff(editfile); fd.filetime = edittime = ff.GetLastWriteTime(); - if(editor.IsDirty()) { - DLOG("========= Saved " << editfile); + if(editor.IsDirty()) TriggerIndexer(); - } editor.ClearDirty(); diff --git a/uppsrc/ide/main.cpp b/uppsrc/ide/main.cpp index 1ff3c0087..6430d4d6f 100644 --- a/uppsrc/ide/main.cpp +++ b/uppsrc/ide/main.cpp @@ -118,15 +118,6 @@ GUI_APP_MAIN void AppMain___() #endif { -#if 0 _DBG_ - PPInfo ppi; - VectorMap files; - ppi.SetIncludes("C:\\u\\llvm_ide\\uppsrc\\Core"); - ppi.GatherDependencies("C:\\u\\llvm_ide\\uppsrc\\Core\\Cpu.cpp", files); - DDUMPM(files); - return; -#endif - // Ctrl::ShowRepaint(50); #ifdef flagPEAKMEM diff --git a/upptst/ide_CleanupId/etalon.log b/upptst/ide_CleanupId/etalon.log index 113bf17a6..28c7db3aa 100644 --- a/upptst/ide_CleanupId/etalon.log +++ b/upptst/ide_CleanupId/etalon.log @@ -1,4 +1,26 @@ -* C:\upp\out\llvm_tests\CLANGx64.Debug.Debug_Full\ide_CleanupId.exe 29.07.2022 01:06:12, user: cxl +* C:\upp\out\llvm_tests\CLANGx64.Debug.Debug_Full\ide_CleanupId.exe 06.08.2022 14:31:04, user: cxl -CleanupId("Upp::Index::Find(const Upp::String &k) const") = Upp::Index::Find(const Upp::String&)const -CleanupId("clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy, enum CXPrintingPolicyProperty Property, unsigned int Value) __attribute__((dllimport))") = clang_PrintingPolicy_setProperty(CXPrintingPolicy,CXPrintingPolicyProperty,unsigned int) +====== +Foo1::operator<<(int) +Foo1::operator<<(int) +====== +Foo1::operator<(int) +Foo1::operator<(int) +====== +Upp::Index::Find(const Upp::String &k) const +Upp::Index::Find(const Upp::String&)const +====== +clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy, enum CXPrintingPolicyProperty Property, unsigned int Value) __attribute__((dllimport)) +clang_PrintingPolicy_setProperty(CXPrintingPolicy,CXPrintingPolicyProperty,unsigned int) +====== +Foo1::Method() +Foo1::Method() +====== +Foo3::Foo3() noexcept +Foo3::Foo3() +====== +Foo1::operator*(int) +Foo1::operator*(int) +====== +main(int argc, const char *argv[]) +main(int,const char*[]) diff --git a/upptst/ide_CleanupId/ide_CleanupId.cpp b/upptst/ide_CleanupId/ide_CleanupId.cpp index f5ac88e60..ca163db31 100644 --- a/upptst/ide_CleanupId/ide_CleanupId.cpp +++ b/upptst/ide_CleanupId/ide_CleanupId.cpp @@ -6,8 +6,26 @@ CONSOLE_APP_MAIN { StdLogSetup(LOG_COUT|LOG_FILE); - DDUMP(CleanupId("Upp::Index::Find(const Upp::String &k) const")); - DDUMP(CleanupId("clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy, enum CXPrintingPolicyProperty Property, unsigned int Value) __attribute__((dllimport))")); +#if 0 + String s = CleanupId("main(int argc, const char *argv[])"); + DDUMP(s); + return; +#endif + + for(String s : { + "Foo1::operator<<(int)", + "Foo1::operator<(int)", + "Upp::Index::Find(const Upp::String &k) const", + "clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy, enum CXPrintingPolicyProperty Property, unsigned int Value) __attribute__((dllimport))", + "Foo1::Method()", + "Foo3::Foo3() noexcept", + "Foo1::operator*(int)", + "main(int argc, const char *argv[])", + }) { + DLOG("======"); + DLOG(s); + DLOG(CleanupId(s)); + } CheckLogEtalon(); }