Re: semantic-analyze-possible-completion

Martin Stein <[email protected]> Tue, 03 Feb 2015 21:52:40 +0100
Newsgroups gmane.emacs.cedet
Message-ID <[email protected]>
Hi Fulvio,

> it seems to me from a superficial glance at code in c.el that the magic is
> contained inside the following piece of code:
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> ;; This searches a type in a namespace, following through all using
> ;; statements.
> (defun semantic-c-check-type-namespace-using (type namespace)
>    "Check if TYPE is accessible in NAMESPACE through a using statement.
> Returns the original type from the namespace where it is defined,
> or nil if it cannot be found."
>    (let (usings result usingname usingtype unqualifiedname members
> shortname tmp)
>      ;; Get all using statements from NAMESPACE.
>      (when (and (setq usings (semantic-tag-get-attribute namespace
> :members))
>                 (setq usings (semantic-find-tags-by-class 'using usings)))
>        ;; Get unqualified typename.
>        (when (listp (setq unqualifiedname (semantic-analyze-split-name
>                                            (semantic-tag-name type))))
>          (setq unqualifiedname (car (last unqualifiedname))))
> ...
>  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>  From which it appears to me that each namespace can have some members
> of class 'using,
> each representing a namespace clause, this is parsed to get the
> namespace name and the
> symbols found there. It also makes the search recursively, which exactly
> maps to the fortran
> semantic for use clauses.
Thanks for pointing this out. This piece of code seems to be about 
dereferencing, i.e. recognise bar as foo::bar for a namespace foo for 
which there is a using namespace declaration. But there is no such thing 
in fortran. Members of modules included by use modname are always 
unqualified and do not need to be dereferenced. Once support of F2003 
"associate"-construct should be added, something like this might become 
necessary.

However, there is some similar piece of (recursive) code buried in 
semantic-completable-tags-from-type, which is called from 
semantic-f90-analyze-scoped-type-parts, which is called from 
overloadable semantic-analyze-scoped-tags (which is a core of the 
semantic-calculate-scope routine). I have already copied these three 
functions and somewhat adjusted to Fortran needs. They are just too 
specific for C like languages. In particular I still need to think about 
recursing into use statements in conjunction with public/private 
statements (do not check use statements of a used modules if it does not 
re-export tags from the use statement. As far as I can see there is no 
equivalent in namespaces. Any thoughts on that?
Example (fortran comments are started with "!"):

module modA
use modB
use modC
...
private ! make everything private unless declared otherwise
public modA_mysub
...
end modA

!-------

module modB
use modE
private
public modB_mysub
...
end modB

!-------

module modC
use modD
public  ! make everything public, including members of modD
...
end modC

!-------

module modD
public modD_mysub
...
end module

modB_mysub, modD_mysub is in the scope of modA, anything from modE is 
not in the scope. Standard case would be modE (hence do not recursively 
descent). On the other hand, modules like modC can be useful as 
collection modules. So this is very relevant to me.

Anyway, scope calculation slowly shapes up.

Martin


------------------------------------------------------------------------------
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/