Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
Check macro usage on every identifier like token: issues and discussions
ollydbg:
--- Code: ---void Function1(void)
{
int some_int;
for (int for_int = 0; for_int < 5; ++for_int)
{
// //some_int
//for //for_int
}
}
void Function2(void)
{
int value1 = 0;
int value2 = 0;
// hover on "value1"
if (!value1) {}
// hover on "value1" and "value2"
if (value1 && value2) {}
// Above tooltips will be shown correctly because the statements
// within if(...), do(...), etc are NOT parsed entirely.
// Revision 10230 "fixes" this problem, but now, parsing these statements
// introduces the following regression.
//if (!value1) {} // adds a new token "! value1"
//if (value1 && value2){} // adds a new token "value1&& value2"
}
--- End code ---
It looks like if (xxx), where xxx is an expression.
and the Code::Blocks / Tickets / #145 Code completion ignores parameters of catch-clauses, the test code I use:
--- Code: ---class E
{
int a;
};
int main()
{
try
{
}
catch(E exp123)
{
exp|
}
return 0;
}
--- End code ---
Where catch(yyy), here yyy is much like function arguments, which is not an expression.
And the void ParserThread::HandleConditionalArguments() is mainly handling the "xxx", not "yyy". :)
ollydbg:
--- Quote ---* CC: [huki] parser - fix for function pointer parsing with assignment.
--- End quote ---
I think remove the ';' check is not quite good, you just want to support some patters like:
--- Code: ---m_Str AAA (*BBB) (...);
m_Str AAA (*BBB) (...) = some_function;
--- End code ---
Why not just check if the peek is either ';' or '='?
I think there are other cases which could not lead to a function pointer, such as C's Type Casting.
--- Code: ---m_Str AAA (*typeA) (*typeB)(*typeC)....
--- End code ---
Or maybe, there are other cases.
Huki:
--- Quote from: ollydbg on November 06, 2015, 03:27:25 pm ---
--- Quote ---* CC: [huki] parser - fix for function pointer parsing with assignment.
--- End quote ---
I think remove the ';' check is not quite good, you just want to support some patters like:
--- Code: ---m_Str AAA (*BBB) (...);
m_Str AAA (*BBB) (...) = some_function;
--- End code ---
Why not just check if the peek is either ';' or '='?
I think there are other cases which could not lead to a function pointer, such as C's Type Casting.
--- Code: ---m_Str AAA (*typeA) (*typeB)(*typeC)....
--- End code ---
Or maybe, there are other cases.
--- End quote ---
I agree, checking for both ';' and '=' should be ok. Modified patch:
--- Code: ---From f01ada3e356006475787c481316f405ab47359f9 Mon Sep 17 00:00:00 2001
From: huki <gk7huki@gmail.com>
Date: Wed, 8 Apr 2015 08:12:47 +0530
Subject: [PATCH 15/17] CC: [huki] parser - fix for function pointer parsing
with assignment.
---
src/plugins/codecompletion/parser/parserthread.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/plugins/codecompletion/parser/parserthread.cpp b/src/plugins/codecompletion/parser/parserthread.cpp
index 813bdd5..d3e6cdd 100644
--- a/src/plugins/codecompletion/parser/parserthread.cpp
+++ b/src/plugins/codecompletion/parser/parserthread.cpp
@@ -2227,7 +2227,7 @@ void ParserThread::HandleFunction(wxString& name, bool isOperator, bool isPointe
int pos = name.find(ParserConsts::ptr);
// pattern: m_Str AAA (*BBB) (...);
- if (peek == ParserConsts::semicolon && pos != wxNOT_FOUND)
+ if (pos != wxNOT_FOUND && (peek == ParserConsts::semicolon || peek == ParserConsts::equals))
{
name.RemoveLast(); // remove ")"
name.Remove(0, pos+1).Trim(false); // remove "(* "
@@ -2235,7 +2235,7 @@ void ParserThread::HandleFunction(wxString& name, bool isOperator, bool isPointe
// pattern: m_Str AAA (*BBB[X][Y]) (...);
pos = name.find(ParserConsts::oparray_chr);
if (pos != wxNOT_FOUND)
- name.Remove(pos);
+ name.Remove(pos).Trim(true);
TRACE(_T("HandleFunction() : Add token name='")+name+_T("', args='")+args+_T("', return type='") + m_Str+ _T("'"));
Token* newToken = DoAddToken(tkFunction, name, lineNr, 0, 0, args);
--
2.1.4
--- End code ---
I added the Trim(true) for safety, in case the name contains a trailing space. But I see you already handled that case in the tokenizer's ReadParentheses (see your commit). So feel free to ignore this part.
Then, the only change is to test for both ";" and "=".
Huki:
--- Quote from: ollydbg on October 29, 2015, 04:01:56 pm ---
--- Code: ---void Function2(void)
{
int value1 = 0;
int value2 = 0;
// hover on "value1"
if (!value1) {}
// hover on "value1" and "value2"
if (value1 && value2) {}
// Above tooltips will be shown correctly because the statements
// within if(...), do(...), etc are NOT parsed entirely.
// Revision 10230 "fixes" this problem, but now, parsing these statements
// introduces the following regression.
//if (!value1) {} // adds a new token "! value1"
//if (value1 && value2){} // adds a new token "value1&& value2"
}
--- End code ---
It looks like if (xxx), where xxx is an expression.
and the Code::Blocks / Tickets / #145 Code completion ignores parameters of catch-clauses, the test code I use:
--- Code: ---class E
{
int a;
};
int main()
{
try
{
}
catch(E exp123)
{
exp|
}
return 0;
}
--- End code ---
Where catch(yyy), here yyy is much like function arguments, which is not an expression.
And the void ParserThread::HandleConditionalArguments() is mainly handling the "xxx", not "yyy". :)
--- End quote ---
Then we can add a parameter "bool parseArguments" to HandleConditionalArguments(), which will be false by default for 'if', 'do', 'while' and can be set to true to handle catch expressions. Is that ok with you?
ollydbg:
--- Quote from: Huki on November 06, 2015, 10:48:40 pm ---...
Then we can add a parameter "bool parseArguments" to HandleConditionalArguments(), which will be false by default for 'if', 'do', 'while' and can be set to true to handle catch expressions. Is that ok with you?
--- End quote ---
I totally agree on this idea. Thanks.
--- Quote from: Huki on November 06, 2015, 10:26:03 pm ---...
I agree, checking for both ';' and '=' should be ok. Modified patch:
...
I added the Trim(true) for safety, in case the name contains a trailing space. But I see you already handled that case in the tokenizer's ReadParentheses (see your commit). So feel free to ignore this part.
Then, the only change is to test for both ";" and "=".
--- End quote ---
Thanks for the modified patch, I'm OK with this change. This is what I'm going to commit:
--- Code: ---From 23346fed9a26273fbde0f9f859cac9da0e31ec2d Mon Sep 17 00:00:00 2001
From: huki <gk7huki@gmail.com>
Date: Wed, 8 Apr 2015 08:12:47 +0530
Subject: * CC: parser - fix for function pointer parsing with assignment.
(Thanks Huki)
Parsing code pattern:
m_Str AAA (*BBB) (...) = some_function;
See discussion here:
http://forums.codeblocks.org/index.php/topic,19769.msg140852.html#msg140852
diff --git a/src/plugins/codecompletion/parser/parserthread.cpp b/src/plugins/codecompletion/parser/parserthread.cpp
index 813bdd5..d86cfee 100644
--- a/src/plugins/codecompletion/parser/parserthread.cpp
+++ b/src/plugins/codecompletion/parser/parserthread.cpp
@@ -2227,15 +2227,17 @@ void ParserThread::HandleFunction(wxString& name, bool isOperator, bool isPointe
int pos = name.find(ParserConsts::ptr);
// pattern: m_Str AAA (*BBB) (...);
- if (peek == ParserConsts::semicolon && pos != wxNOT_FOUND)
+ // pattern: m_Str AAA (*BBB) (...) = some_function;
+ if (pos != wxNOT_FOUND && (peek == ParserConsts::semicolon || peek == ParserConsts::equals))
{
name.RemoveLast(); // remove ")"
name.Remove(0, pos+1).Trim(false); // remove "(* "
// pattern: m_Str AAA (*BBB[X][Y]) (...);
+ // Trim(true) for safety, in case the name contains a trailing space
pos = name.find(ParserConsts::oparray_chr);
if (pos != wxNOT_FOUND)
- name.Remove(pos);
+ name.Remove(pos).Trim(true);
TRACE(_T("HandleFunction() : Add token name='")+name+_T("', args='")+args+_T("', return type='") + m_Str+ _T("'"));
Token* newToken = DoAddToken(tkFunction, name, lineNr, 0, 0, args);
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version