From 9ff668bdd26bab07860976e6fa90db2e700c930a Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 20 Sep 2015 16:43:43 +0000 Subject: [PATCH] ide: Fixed assist++ issues git-svn-id: svn://ultimatepp.org/upp/trunk@8952 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Algo.h | 2 +- uppsrc/CppBase/CppItem.cpp | 1 + uppsrc/CppBase/Qualify.cpp | 38 ++++++++++++++++++++++++++++++++++++ uppsrc/CppBase/ScopeInfo.cpp | 20 +++++++++---------- uppsrc/CppBase/macro.cpp | 2 +- uppsrc/CppBase/ppconfig.cpp | 3 ++- uppsrc/CppBase/ppfile.cpp | 10 ++++++---- uppsrc/ide/ContextGoto.cpp | 1 - uppsrc/ide/Navigator.cpp | 15 ++++++++++---- uppsrc/ide/idewin.cpp | 2 +- 10 files changed, 71 insertions(+), 23 deletions(-) diff --git a/uppsrc/Core/Algo.h b/uppsrc/Core/Algo.h index ad342c221..6567d6efd 100644 --- a/uppsrc/Core/Algo.h +++ b/uppsrc/Core/Algo.h @@ -798,7 +798,7 @@ void Sort(I l, I h, const Less& less) ++iih; if(pass > 5 || min(ii - l, h - iih) > (max(ii - l, h - iih) >> pass)) { // partition sizes ok or we have done max attempts if(ii - l < h - iih - 1) { // recurse on smaller partition, tail on larger - Sort(l, ii, less); + Sort(l, ii, less); l = iih + 1; } else { diff --git a/uppsrc/CppBase/CppItem.cpp b/uppsrc/CppBase/CppItem.cpp index f3dd28e36..509d9d51b 100644 --- a/uppsrc/CppBase/CppItem.cpp +++ b/uppsrc/CppBase/CppItem.cpp @@ -74,6 +74,7 @@ void CppItem::Dump(Stream& s) const PUT(qptype); PUT(tname); PUT(ctname); + PUT(using_namespaces); #undef PUT } diff --git a/uppsrc/CppBase/Qualify.cpp b/uppsrc/CppBase/Qualify.cpp index 1ace92118..900b87a0d 100644 --- a/uppsrc/CppBase/Qualify.cpp +++ b/uppsrc/CppBase/Qualify.cpp @@ -201,6 +201,43 @@ void QualifyTypes(CppBase& base, const String& scope, CppItem& m) m.qptype = QualifyIds(nf, m.ptype, m.using_namespaces, true); } +void QualifyPass0(CppBase& base) +{ // Move scopes - solve: namespace X { struct C { void Foo(); }; using namespace X; void C::Foo() {} + Vector remove_scope; + for(int ni = 0; ni < base.GetCount(); ni++) { + Array& n = base[ni]; + ScopeInfo nf(base); + String scope = base.GetKey(ni); + String usings; + int toscopei = -1; + Vector remove_item; + for(int i = 0; i < n.GetCount(); i++) { + CppItem& m = n[i]; + if(m.qualify && m.impl) { + if(usings != m.using_namespaces) { + usings = m.using_namespaces; + toscopei = -1; + Vector h = Split(m.using_namespaces, ';'); + for(int i = 0; i < h.GetCount(); i++) { + String ns = h[i] + "::" + scope; + toscopei = base.Find(ns); + if(toscopei >= 0) + break; + } + } + if(toscopei >= 0 && toscopei != ni) { + base[toscopei].Add(m); + remove_item.Add(i); + } + } + } + n.Remove(remove_item); + if(scope.GetCount() && n.GetCount() == 0) + remove_scope.Add(ni); + } + base.Remove(remove_scope); +} + void QualifyPass1(CppBase& base) { // Qualify types LTIMING("QualifyPass1"); @@ -267,6 +304,7 @@ void Qualify(CppBase& base) } } base.namespaces.Clear(); + QualifyPass0(base); QualifyPass1(base); QualifyPass2(base); } diff --git a/uppsrc/CppBase/ScopeInfo.cpp b/uppsrc/CppBase/ScopeInfo.cpp index 1ba156371..f7c9c7687 100644 --- a/uppsrc/CppBase/ScopeInfo.cpp +++ b/uppsrc/CppBase/ScopeInfo.cpp @@ -109,17 +109,17 @@ const Vector& ScopeInfo::GetScopes(const String& usings_) usings = usings_; nvalid = true; scopes.Clear(); - if(scopei < 0) - return scopes; - String nn = base.GetKey(scopei); - while(nn.GetCount()) { - if(nn[0] == ':' && nn.GetCount() == 2) { - scopes.Add(nn); - return scopes; + if(scopei >= 0) { + String nn = base.GetKey(scopei); + while(nn.GetCount()) { + if(nn[0] == ':' && nn.GetCount() == 2) { + scopes.Add(nn); + return scopes; + } + scopes.Add(nn + "::"); + int q = nn.ReverseFind(':'); + nn.Trim(max(0, q - 1)); } - scopes.Add(nn + "::"); - int q = nn.ReverseFind(':'); - nn.Trim(max(0, q - 1)); } scopes.Add(""); Vector h = Split(usings, ';'); diff --git a/uppsrc/CppBase/macro.cpp b/uppsrc/CppBase/macro.cpp index 6becef9f9..1aa4564bb 100644 --- a/uppsrc/CppBase/macro.cpp +++ b/uppsrc/CppBase/macro.cpp @@ -14,7 +14,7 @@ String CppMacro::Define(const char *s) try { if(!p.IsId()) return Null; - p.NoSkipSpaces().NoSkipComments(); // '#define TEST(x)' is difference form '#define TEST (x)' - later is parameterless + p.NoSkipSpaces().NoSkipComments(); // '#define TEST(x)' is different form '#define TEST (x)' - later is parameterless id = p.ReadId(); param.Clear(); if(p.Char('(')) { diff --git a/uppsrc/CppBase/ppconfig.cpp b/uppsrc/CppBase/ppconfig.cpp index 2d04ebdb7..91911f8b8 100644 --- a/uppsrc/CppBase/ppconfig.cpp +++ b/uppsrc/CppBase/ppconfig.cpp @@ -30,7 +30,8 @@ String GetStdDefs() h = Split(ignore, ';'); for(int i = 0; i < h.GetCount(); i++) defs << "#define " << h[i] << "\n"; - defs << "#define NULL NULL"; + defs << "#define NULL NULL\n"; + defs << "#define DrawText DrawText\n"; // DrawTextA/DrawTextW fiasco... return defs; } diff --git a/uppsrc/CppBase/ppfile.cpp b/uppsrc/CppBase/ppfile.cpp index 9ddc96cfa..01ffd98b8 100644 --- a/uppsrc/CppBase/ppfile.cpp +++ b/uppsrc/CppBase/ppfile.cpp @@ -104,9 +104,10 @@ PPMacro *FindPPMacro(const String& id, Index& segment_id, int& segmenti) Index undef; PPMacro *r; + int best; for(int pass = 0; pass < 2; pass++) { r = NULL; - int best = segmenti; + best = segmenti; int line = -1; int q = sAllMacros.Find(id); while(q >= 0) { @@ -116,7 +117,7 @@ PPMacro *FindPPMacro(const String& id, Index& segment_id, int& segmenti) undef.FindAdd(m.segment_id); // cancel out undefined macro... } else - if(pass == 0 || undef.Find(m.undef_segment_id) < 0) { + if(pass == 0 || m.segment_id == 0 || undef.Find(m.undef_segment_id) < 0) { int si = m.segment_id == 0 ? INT_MAX : segment_id.Find(m.segment_id); // defs macros always override if(si > best || si >= 0 && si == best && m.line > line) { best = si; @@ -129,6 +130,7 @@ PPMacro *FindPPMacro(const String& id, Index& segment_id, int& segmenti) if(undef.GetCount() == 0) break; } + segmenti = best; return r; } @@ -194,7 +196,7 @@ void PPFile::Parse(Stream& in) md5.Put("#", 1); md5.Put(id); md5.Put(0); - md5.Put(m.macro.md5, 16); + md5.Put(m.macro.md5, 16); } } else @@ -206,7 +208,7 @@ void PPFile::Parse(Stream& in) md5.Put(1); int segmenti = -1; PPMacro *um = FindPPMacro(id, local_segments, segmenti); - if(um) { // heuristic: only local undefs are allowed + if(um && segmenti) { // heuristic: only local undefs are allowed PPItem& m = item.Add(); m.type = PP_DEFINES; m.segment_id = ++sPPserial; diff --git a/uppsrc/ide/ContextGoto.cpp b/uppsrc/ide/ContextGoto.cpp index dfe5724c7..8dbf072cb 100644 --- a/uppsrc/ide/ContextGoto.cpp +++ b/uppsrc/ide/ContextGoto.cpp @@ -214,7 +214,6 @@ void Ide::ContextGoto0(int pos) Vector scope; Vector istype; // prefer type (e.g. struct Foo) over constructor (Foo::Foo()) - for(int i = 0; i < type.GetCount(); i++) { // 'x.attr' Index done; String r; diff --git a/uppsrc/ide/Navigator.cpp b/uppsrc/ide/Navigator.cpp index 2fd1f8960..bf857d760 100644 --- a/uppsrc/ide/Navigator.cpp +++ b/uppsrc/ide/Navigator.cpp @@ -194,7 +194,7 @@ void Navigator::GoToNavLine() bool Navigator::NavLine::operator<(const NavLine& b) const { - String p1 = GetSourceFilePath(file); // + String p1 = GetSourceFilePath(file); String p2 = GetSourceFilePath(b.file); return CombineCompare/*(!impl, !b.impl)*/ (GetFileExt(p2), GetFileExt(p1)) // .h > .c @@ -538,6 +538,7 @@ void Navigator::Search() String usearch_name = ToUpper(search_name); ArrayMap imap; bool local = sorting && IsNull(s); + VectorMap nest_pass; for(int pass = -1; pass < 2; pass++) { for(int i = 0; i < b.GetCount(); i++) { String nest = b.GetKey(i); @@ -558,7 +559,13 @@ void Navigator::Search() : m.name.StartsWith(search_name)) || both && foundnest) { String key = nest + '\1' + m.qitem; - int q = imap.Find(key); + int q = nest_pass.Find(nest); + int p = pass; + if(q < 0) // We do not want classes to be split based on pass + nest_pass.Add(nest, pass); + else + p = nest_pass[q]; + q = imap.Find(key); if(q < 0) { NavItem& ni = imap.Add(key); ni.Set(m); @@ -566,7 +573,7 @@ void Navigator::Search() ni.decl_line = ni.line; ni.decl_file = ni.file; ni.decl = !ni.impl; - ni.pass = pass; + ni.pass = p; NavLine& l = ni.linefo.Add(); l.impl = m.impl; l.file = m.file; @@ -574,13 +581,13 @@ void Navigator::Search() } else { NavItem& mm = imap[q]; - String n = mm.natural; if(!m.impl && (!mm.decl || CombineCompare(mm.decl_file, m.file)(mm.decl_line, m.line) < 0)) { mm.decl = true; mm.decl_line = m.line; mm.decl_file = m.file; + mm.natural = m.natural; } NavLine& l = mm.linefo.Add(); l.impl = m.impl; diff --git a/uppsrc/ide/idewin.cpp b/uppsrc/ide/idewin.cpp index fb4cbc6a9..f6fddb0f5 100644 --- a/uppsrc/ide/idewin.cpp +++ b/uppsrc/ide/idewin.cpp @@ -1090,7 +1090,7 @@ void AppMain___() if(!FileExists(ppdefs)) #endif SaveFile(ppdefs, GetStdDefs()); - + SetPPDefs(LoadFile(ppdefs)); ide.LoadLastMain();