On 03/09/2010 07:01 AM, Sergei D. wrote:
> 07.03.2010 18:46, Eric M. Ludlam:
>> Hi Sergei,
>>
>> I see why this would be useful. Unfortunately, this isn't something
>> currently supported, and the current parsing setup doesn't actually open
>> includes. Instead, files are organized into trees of dependencies based
>> on the includes at the top level, maximizing performance by parsing such
>> things only once.
>>
>> To resolve this, we'd either have to re-write the parse to include
>> includes, or add logic into the local context parser to also handle
>> includes of this style.
>>
>> If you wanted to try fixing this, semantic-ctxt.el has
>> semantic-get-local-variables, which is likely what you want. An
>> override function can be written for C/C++ to do what you want.
>>
>> I can provide more assistance if needed.
>>
>> Eric
>>
>
> Hm... I'm a beginner and I use emacs about one month and don't know
> lisp. Therefore I may need to be very detailed instructions in order to
> do so... But I want this feature, so can try if you assistance me.
Hi Sergei,
I'll take up that challenge too.
For starters, the issue is in the local variable parser for inside
functions. You can get the output of the function I mention above by
putting the cursor in a function with one of your #includes in it,
perhaps something like this:
int myfcn (int a) {
int b;
#include "foo.c"
char c;
}
just to make sure there's good stuff to find. Then type:
M-: (semantic-get-local-variables) RET
and it will presumably give you a list of tags, where "b" is the first
tag, and there might be a "c".
A favorite keybinding of mine is:
(global-set-key "\M-:" 'data-debug-eval-expression)
which provides much nicer output than the default.
Anyway, clearly it is missing the include.
If you then look at semantic/bovine/c.by, you will find the parser.
Near the top you will see the line that says:
%scopestart codeblock
That means that "codeblock" is for parsing inside code blocks.
If you look for the codeblock rule, which is this:
codeblock
: define
| codeblock-var-or-fun
| type ;; type is less likely to be used here.
| using
;
you see that it handles define, variables, functions, types, and using
statements. It needs the includes in order to even start your project.
There is a macro rule that shows how to parse include statements. All
you probably need to add are the non-system include types.
Once you change the parser, use "C-c C-c" to regenerate the Lisp parser.
Re-evaluate in Emacs the lisp code (with C-M-x in
semantic-c-by--token-table), then run M-x c++-mode RET (or c-mode) in
your test code buffer, and start cycling till it does what you want.
Once that works, it is time to overload semantic-get-local-variables in
semantic-c.el. There are a bunch of examples that show how to start that.
Let me know how it goes.
Eric
|