Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

code completion enhancement request

(1/2) > >>

killerbot:
recently the code completion was enhanced by recognizing declaration in if / for/while constructs, this is great.

I would like to take it one step small further : range based for :

* say you have a container ==> vector/list/... "container"


--- Code: ---
for (auto foo : container)

for (const auto foo : container)

for (auto& foo : container)

for (const auto& foo : container)


--- End code ---

foo is of the value type (disregarding const and references here) of the container.

Example :
std::vector<MyType> container;   ===> foo is of type MyType

So the syntax seems simple in the "for( ... : ...)", the challenge probably is, do we know the 'container' its value type ? And can we deduce this second level of determination ?


What do our CC experts think ?

oBFusCATed:

--- Quote from: killerbot on December 28, 2012, 07:33:25 pm ---So the syntax seems simple in the "for( ... : ...)", the challenge probably is, do we know the 'container' its value type ? And can we deduce this second level of determination ?

--- End quote ---
Read the standard, I'm sure it explains how the type is deduced. ::)

ptDev:

--- Quote from: killerbot on December 28, 2012, 07:33:25 pm ---recently the code completion was enhanced by recognizing declaration in if / for/while constructs, this is great.

I would like to take it one step small further : range based for :

* say you have a container ==> vector/list/... "container"


--- Code: ---
for (auto foo : container)

for (const auto foo : container)

for (auto& foo : container)

for (const auto& foo : container)


--- End code ---

foo is of the value type (disregarding const and references here) of the container.

Example :
std::vector<MyType> container;   ===> foo is of type MyType

So the syntax seems simple in the "for( ... : ...)", the challenge probably is, do we know the 'container' its value type ? And can we deduce this second level of determination ?


What do our CC experts think ?


--- End quote ---

In your examples, the only issue for CC is that "auto" uses template type deduction.
I don't think CC can handle that yet.

Try explicitly declaring the type in those range based loops, and CC won't have a problem.

killerbot:
I know that, that's why I call it a challenge.
The auto keyword is there to make life easier, and don't repeat types anymore.

So the question is, is our CC able to do such a thing with let's +- minimal effort. That's the extra level is was talking about, (by limiting the complexity), looking at what is at the right hand side of the ":" and then get the type of it. And once CC knows what's the thing on the right hand side (vector<MyType>) can it then easily determine that "MyType" ? )

So still some static analysis, by avoiding turning our CC into a compiler.

FOr that I am gonna start another thread, but our CC is going to have to use compiler backends, I think there was already an experiemtn with clang ?

But in this topic I just want to see if this particular use case might be easier to achieve ...

ptDev:

--- Quote from: killerbot on December 29, 2012, 08:51:31 am ---I know that, that's why I call it a challenge.
The auto keyword is there to make life easier, and don't repeat types anymore.

So the question is, is our CC able to do such a thing with let's +- minimal effort. That's the extra level is was talking about, (by limiting the complexity), looking at what is at the right hand side of the ":" and then get the type of it. And once CC knows what's the thing on the right hand side (vector<MyType>) can it then easily determine that "MyType" ? )

--- End quote ---

I thought of that before. If CC was to able to parametrize some classes by known types, then this use case would be simplified, yes. This change alone, however, does require quite a bit of refactoring as it is.


--- Quote ---So still some static analysis, by avoiding turning our CC into a compiler.

FOr that I am gonna start another thread, but our CC is going to have to use compiler backends, I think there was already an experiemtn with clang ?

But in this topic I just want to see if this particular use case might be easier to achieve ...

--- End quote ---

I remember reading in the forum about someone experimenting with a Clang-based CC, but never heard of any results since...

Navigation

[0] Message Index

[#] Next page

Go to full version