From 0162bb2bdeb1200f0dd02e5766484eaca4d54956 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 20 Jul 2014 14:36:24 +0000 Subject: [PATCH] ide: Context goto now works on local variables and parameters too git-svn-id: svn://ultimatepp.org/upp/trunk@7524 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CppBase/CppBase.h | 1 + uppsrc/CppBase/Parser.cpp | 4 ++++ uppsrc/ide/Assist.cpp | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/uppsrc/CppBase/CppBase.h b/uppsrc/CppBase/CppBase.h index af3c1f7a7..98d422d48 100644 --- a/uppsrc/CppBase/CppBase.h +++ b/uppsrc/CppBase/CppBase.h @@ -436,6 +436,7 @@ public: struct Local : Moveable { String type; bool isptr; + int line; }; VectorMap local; diff --git a/uppsrc/CppBase/Parser.cpp b/uppsrc/CppBase/Parser.cpp index 02e793ccd..537e53738 100644 --- a/uppsrc/CppBase/Parser.cpp +++ b/uppsrc/CppBase/Parser.cpp @@ -785,11 +785,13 @@ Array Parser::Declaration(bool l0, bool more) void Parser::Locals(const String& type) { + Line(); Array d = Declaration(true, true); for(int i = 0; i < d.GetCount(); i++) { Local& l = local.Add(d[i].name); l.type = type; l.isptr = d[i].isptr; + l.line = line + 1; } } @@ -829,6 +831,7 @@ bool Parser::TryDecl() if(t == tk_int || t == tk_bool || t == tk_float || t == tk_double || t == tk_void || t == tk_long || t == tk_signed || t == tk_unsigned || t == tk_short || t == tk_char || t == tk___int8 || t == tk___int16 || t == tk___int32 || t == tk___int64) { + q++; while(lex[q] == '*' || lex[q] == '&') q++; if(!lex.IsId(q)) @@ -1246,6 +1249,7 @@ CppItem& Parser::Fn(const Decl& d, const String& templ, bool body, Local& l = local.Add(p.name); l.type = p.type; l.isptr = p.isptr; + l.line = line + 1; } ScAdd(param, p.natural); if(i) diff --git a/uppsrc/ide/Assist.cpp b/uppsrc/ide/Assist.cpp index 59fc1a7c3..130c7c8a9 100644 --- a/uppsrc/ide/Assist.cpp +++ b/uppsrc/ide/Assist.cpp @@ -1157,6 +1157,7 @@ void Ide::ContextGoto0(int pos) ci++; } editor.Context(parser, ci); + if(xp.GetCount() == 0 && IsNull(tp)) type.Add(parser.current_scope); else { @@ -1167,8 +1168,19 @@ void Ide::ContextGoto0(int pos) String id = editor.GetWord(pos); if(id.GetCount() == 0) return; + + if(xp.GetCount() == 0) { + q = parser.local.Find(id); + if(q >= 0) { + AddHistory(); + editor.SetCursor(editor.GetPos(parser.local[q].line - 1)); + return; + } + } + Vector scope; bool istype = false; + if(xp.GetCount() == 0) { // 'String' String t = Qualify(CodeBase(), parser.current_scope, id); if(CodeBase().Find(t) >= 0) { @@ -1191,6 +1203,7 @@ void Ide::ContextGoto0(int pos) if(GetIdScope(r, type[i], id, done)) scope.Add(r); } + if(scope.GetCount() == 0) { Index done; String r; @@ -1198,9 +1211,6 @@ void Ide::ContextGoto0(int pos) scope.Add(r); } - if(scope.GetCount() == 0) - return; - for(int j = 0; j < scope.GetCount(); j++) { q = CodeBase().Find(scope[j]); if(q >= 0) {