Author Topic: new idea: high light local variables in a function body  (Read 9236 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
new idea: high light local variables in a function body
« on: March 19, 2015, 06:08:47 am »
I see that we have a function:
Code
void CodeCompletion::UpdateEditorSyntax(cbEditor* ed)
which give a set of tokens(keywords) as member variables to scintilla control, so that it can highlight them, by
Code
    ed->GetControl()->SetKeyWords(3, keywords);
    ed->GetControl()->Colourise(0, -1);

So, if we put a mouse in a function body, and let our parser parse the function body, and give scintilla control all the local variable tokens, and finally we can only highlight them inside the function body by
Code
    ed->GetControl()->SetKeyWords(3, local_variables_list);
    ed->GetControl()->Colourise(begin_of_function_body, end_of_function_body);
:)

EDIT: some old similar discussion: CC based semantic highlight
« Last Edit: March 19, 2015, 06:25:06 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: new idea: high light local variables in a function body
« Reply #1 on: March 19, 2015, 09:10:46 am »
No you can't, because this is global keyword set.

This example code will break it easily:
Code
int myGlobal=5;

int myFunc() {
    int myGlobal=7;
   
    ... do something with the myGlobal...
}

This feature needs to be done with a custom lexer or modifications to scintilla.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: new idea: high light local variables in a function body
« Reply #2 on: March 20, 2015, 03:23:41 pm »
No you can't, because this is global keyword set.

This example code will break it easily:
Code
int myGlobal=5;

int myFunc() {
    int myGlobal=7;
   
    ... do something with the myGlobal...
}

This feature needs to be done with a custom lexer or modifications to scintilla.
Indeed, I agree with you, so it is hard to implement this idea.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.