Re: semantic-analyze-possible-completion

fulvio ciriaco <[email protected]> Fri, 30 Jan 2015 09:16:07 +0100
Newsgroups gmane.emacs.cedet
Message-ID <[email protected]>
Hello,
perhaps Eric could give further advice knowing that the
fortran <use modulename> clause maps perfectly to the c++
<using namespace modulename> clause.
The module could be in a similarly named file but also elsewhere
and a file can indeed contain several modules.
So, one could say that a fortran module and a c++ namespace
are actually the same concept.

Fulvio

On 30/01/2015 04:13, Eric Ludlam wrote:
> On 01/28/2015 05:30 PM, Martin Stein wrote:
>> Hi,
>>
>> I got somehow lost trying to figure out how to get completion to work
>> with my fortran parser.
> Anything past completing some top level tag names gets tricky the
> farther you diverge from how C++ represents tags in Semantic.
>
>> A typical example looks like:
>>
>> module mod
>>
>> use some_module
>>
>> contains
>>
>>      subroutine sub(arg)
>>      ...
>>      end subroutine
>>
>> ...
>>
>> end module
>>
>>
>> Accordingly there is one big tag of class 'module, containing in its
>> attributes all the information, in particular there is a 'subroutine tag
>> of name "sub" buried in :members. Now if I type "call s" I expect that
>> sub is found, but it is not.
> You are using terms like 'module and 'subroutine.  Does that mean the
> class of your generated tags are 'module and 'subroutine?  Looking in
> the old f90.by parser, I see it is creating tags without using TYPE-TAG,
> FUNCTION-TAG, etc macros.
>
> If a 'module' acts like a 'type' (ie - a class or struct in C++) then it
> should use that tag class instead of 'module'.  Likewise for subroutine.
>
> You can use semantic-symbol->name-assoc-list to give them more fortranny
> type names for humans to read.
>
>> If I want to have a function name completed in C code, relevant
>> functions are found as top level tags (as there is no encompassing
>> module-like structure), hence (semantic-analyze-find-tags-by-prefix
>> completetext) in line 192 of analyze/complete.el finds the proper tag.
>>
>> I know that semantic-analyze-possible-completions does the work and is
>> overloadable. Should I overload this function? It seems that the code
> Hopefully not.  Overloading right at the possible completions function
> is for languages where the usual analysis is unneeded, and when there is
> some better way to do it.   For example, in grammar mode, it overloads
> so it can figure out if it is completing in lisp code, or in grammar
> code, then forks off to the right completion engine.
>
>> structure outlined above does not fit its inner workings, which is
>> designed for C. On the other hand this function is overloaded only for
>> some corner-cases (clang, part of grammar).
>> Do I miss something and that routine should still work for fortran, e.g.
>> by overloading some buried helper functions? For example, the relevant
>> tags are contained in the context object. But it does not seem to be
>> queried for those tags? (At least not in my small C example I tested).
> Right.  Usually all that is needed is to implement a few key functions,
> like where to find include files, how to extract tag members, and the
> like.  I don't know enough fortran to know where the problem is, though
> I suspect you can mash some fortran concepts into vaguely similar c
> constructs to make it work as I mentioned above.  Java completions
> worked with very little modification due to the similarities.
>
> My first step in debugging this stuff is to get each of the fields in
> the context returned by `semantic-analyze-current-context' to work.
> Once there is a context, the completion engine extracts the found tags
> (in the :prefix) to calculate the completions.  For example, for this C
> code:
>
> struct foo {
>     int bar;
> };
>
> int myfunc() {
>
>     struct foo me;
>
>     me.b -!-
>
> }
>
> the analyzer returns:
>
> Prefix: struct foo me
>           "b"
>
> meaning it found "me" and turned it into a tag, but doesn't know what
> "b" is.
>
> So it looks at the datatype of "me", calls
> `semantic-analyze-scoped-type-parts', which is a fancy variant of
> `semantic-tag-components' which you may need to override.
>
> from that list it looks for things that start with "b".
>
> If the prefix were just "b", then it would look that up just using basic
> tag searching routines across global tables.
>
>> Another question:
>> What do I need to do to include tags from other modules (included via
>> "use some_module" as in the example above)? I could not find
>> documentation (or hints in other language files) for that.
> You probably need to override semantic-find-tags-included (there are
> some examples in c.el) and to make sure your `use' tags show up as
> `include' tags.  You probably also need to override
> `semantic-tag-include-filename' to convert the used symbol name
> "some_module" into a file name "some_module.f90".
>
> There was another question where a statement was doing double-duty as an
> include and as a 'use' statement.  I only have a guess for that at this
> time regarding expanding it into two tags.  There is probably a better
> idea though.
>
> Eric
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> Cedet-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cedet-devel


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/