Parser, templates and bindings [message #193012] |
Mon, 11 June 2007 10:14  |
Eclipse User |
|
|
|
Originally posted by: dpkg.list.gmail.com
Hi!
I've already sent this question to the cdt-core mailing list, but maybe
this is a more suitable place. Sorry if that's not the case.
I'm using the CDT internal parser (plugin version: 3.1.2) to analyze
some code. I tried to obtain the binding for some method call but all
I get is a ProblemBinding.
The header file for the code I want to parser is like this:
##########################
template <class T>
class SCArrayFix {
public:
T& at(int);
friend class SCAknSettingItemArray;
private:
T elarray[];
};
template <class T>
class SCArrayPtr : public SCArrayFix<T*> {
};
template <class T>
class SCArrayPtrFlat : public SCArrayPtr<T>{
};
class SCAknSettingItemArray : public SCArrayPtrFlat<SCAknSettingItem> {
public:
SCAknSettingItemArray(int);
void toString();
};
#############
In the source code I make this call:
SCAknSettingItemArray* sarray = new SCAknSettingItemArray;
sarray->At(0)->SetEmptyItemText(SomeText);
And when I try to obtain the bind for SetEmptyItemText I get nothing but
a ProblemBinding.
Is it a too complex template structure? Am I doing something wrong?
Hope someone could help me.
Thanks in advance...
|
|
|
|
|
Re: Parser, templates and bindings [message #193148 is a reply to message #193088] |
Tue, 12 June 2007 11:15   |
Eclipse User |
|
|
|
It is not too complex for the parser, but it might be too much for the index.
For performance reasons, I believe that in the latest CDT, that they consult the
index instead of parsing include files.
As a test, you can force the CDT to not do this shortcut by copy/pasting the
contents of Test.h into the .cpp file instead of including it. When I did this
everything seemed to resolve properly, but when using the include, the At()
method didn't resolve (which would cause problems for the SetEmptyItemTextL).
If correctness is more important than performance for you, there should be a way
to get the "complete" DOM AST instead of the one that uses the index.
Dpkg wrote:
>
> Thanks for your answer!
>
> Andrew Niefer wrote:
>> This template structure is not too complex.
>
> Too complex for the parser, I mean :-)
>
>> Once I fixed the problems with the code:
>> 1) define a class SCAknSettingItem, that contains a SetEmptyItemText
>> method.
>> 2) change the reference to be ->at(0) instead of At(0);
>
> I'm sorry, that was my fault. I was trying to simplify the code to make
> things clearer but made some mistakes copying it.
>
> If you don't mind, I'll attach the actual code: Test.cpp and Test.h
>
> The visit method I'm using is something like this.
>
>
>
> ################
>
> public int visit(IASTExpression expression) {
>
> if(expression instanceof CPPASTFunctionCallExpression) {
> CPPASTFunctionCallExpression func_call =
> (CPPASTFunctionCallExpression) expression;
>
> if(func_call.getFunctionNameExpression() instanceof
> CPPASTFieldReference){
> CPPASTFieldReference fref = (CPPASTFieldReference)
> func_call.getFunctionNameExpression();
>
>
> String function_name = fref.getFieldName().toString();
> if(function_name.equals("SetEmptyItemTextL")) {
> logger.debug("Code: " + expression.getRawSignature());
> IBinding bind = fref.getFieldName().resolveBinding();
> logger.debug("->Bind for SetEmptyItemTextL: " + bind);
> }
> }
> }
>
> return super.visit(expression);
> }
>
> #################
>
>
> This is the result:
>
> Code: slist->SettingItemArray()->At(4)->SetEmptyItemTextL(1)
> ->Bind for SetEmptyItemTextL:
> org.eclipse.cdt.internal.core.dom.parser.ProblemBinding@9291cf
>
> Code: cosa->SetEmptyItemTextL(45)
> ->Bind for SetEmptyItemTextL:
> org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod@584294
>
> It's kinda weird, because it resolves the bind perfectly for the second
> line (cosa->SetEmptyItemTextL(45)) but not for the first one.
>
>
>>
>> Then bindings are resolved properly for me. Content assist works and
>> so does open definition. Using the DOM AST view (from the
>> org.eclipse.cdt.ui.tests plugin) shows everything resolving fine.
>>
>> -Andrew
>>
>> Dpkg wrote:
>>> Hi!
>>>
>>> I've already sent this question to the cdt-core mailing list, but
>>> maybe this is a more suitable place. Sorry if that's not the case.
>>>
>>> I'm using the CDT internal parser (plugin version: 3.1.2) to analyze
>>> some code. I tried to obtain the binding for some method call but all
>>> I get is a ProblemBinding.
>>>
>>> The header file for the code I want to parser is like this:
>>>
>>>
>>> ##########################
>>> template <class T>
>>> class SCArrayFix {
>>> public:
>>> T& at(int);
>>> friend class SCAknSettingItemArray;
>>> private:
>>> T elarray[];
>>> };
>>>
>>> template <class T>
>>> class SCArrayPtr : public SCArrayFix<T*> {
>>>
>>> };
>>>
>>> template <class T>
>>> class SCArrayPtrFlat : public SCArrayPtr<T>{
>>>
>>> };
>>>
>>>
>>> class SCAknSettingItemArray : public SCArrayPtrFlat<SCAknSettingItem> {
>>> public:
>>> SCAknSettingItemArray(int);
>>> void toString();
>>>
>>> };
>>> #############
>>>
>>> In the source code I make this call:
>>>
>>> SCAknSettingItemArray* sarray = new SCAknSettingItemArray;
>>> sarray->At(0)->SetEmptyItemText(SomeText);
>>>
>>> And when I try to obtain the bind for SetEmptyItemText I get nothing
>>> but a ProblemBinding.
>>>
>>> Is it a too complex template structure? Am I doing something wrong?
>>>
>>> Hope someone could help me.
>>>
>>> Thanks in advance...
>>>
>
>
> ------------------------------------------------------------ ------------
>
> #include <iostream>
> #include "Test.h"
>
> using namespace std;
>
> CAknSettingItem::CAknSettingItem() {
> this->id = 0;
> this->compuls = 0;
> }
>
> CAknSettingItem::CAknSettingItem(int id) {
> this->id = id;
> this->compuls = 0;
> }
> void CAknSettingItem::toString(){
> cout << "CAknSettingItem " << this->id << " con compuls=" << this->compuls << "\n";
> }
>
> void CAknSettingItem::SetEmptyItemTextL(int comp){
>
> this->compuls=comp;
> }
>
> template <class T> T& CArrayFix<T>::At(int id) {
> cout << this->elarray[id] << endl;
> return this->elarray[id];
> }
>
>
> CAknSettingItemArray::CAknSettingItemArray(int nelem){
> elarray [nelem];
> for(int j = 0; j < nelem;j++){
> elarray[j] = new CAknSettingItem(j);
> }
> }
>
> SettingList::SettingList(){
> this->myarray = new CAknSettingItemArray(5);
> }
>
> CAknSettingItemArray* SettingList::SettingItemArray(){
> return myarray;
> }
>
>
> int main(){
> SettingList* slist = new SettingList;
>
>
> // This fails.
> slist->SettingItemArray()->At(4)->SetEmptyItemTextL(1);
>
> CAknSettingItem* cosa = slist->SettingItemArray()->At(1);
> // This is ok.
> cosa->SetEmptyItemTextL(45);
> }
>
>
>
> ------------------------------------------------------------ ------------
>
>
> class CAknSettingItem {
> public:
> CAknSettingItem();
> CAknSettingItem(int);
> void toString();
> void SetEmptyItemTextL(int);
> private:
> int id;
> int compuls;
> };
>
> template <class T>
> class CArrayFix {
> public:
> T& At(int);
> void SetEmptyTextL(int);
> friend class CAknSettingItemArray;
> private:
> T elarray[];
> };
>
> template <class T>
> class CArrayPtr : public CArrayFix<T*>{
> };
>
>
> template <class T>
> class CArrayPtrFlat : public CArrayPtr<T> {
>
> };
>
>
> class CAknSettingItemArray : public CArrayPtrFlat<CAknSettingItem> {
> public:
> CAknSettingItemArray(int);
> void toString();
>
> };
>
> class SettingList {
> public:
> SettingList();
> void toString();
> CAknSettingItemArray* SettingItemArray();
> private:
> CAknSettingItemArray* myarray;
>
> };
|
|
|
Re: Parser, templates and bindings [message #193157 is a reply to message #193148] |
Tue, 12 June 2007 12:37  |
Eclipse User |
|
|
|
Originally posted by: dpkg.list.gmail.com
Andrew Niefer wrote:
> As a test, you can force the CDT to not do this shortcut by copy/pasting
> the contents of Test.h into the .cpp file instead of including it. When
> I did this everything seemed to resolve properly, but when using the
> include, the At() method didn't resolve (which would cause problems for
> the SetEmptyItemTextL).
I've tried that (copy/paste the header into the cpp file and remove the
include) but it didn't work out. Same ProblemBinding when using the
"long" method invocation. And same proper binding with the short one.
|
|
|
Powered by
FUDForum. Page generated in 0.05635 seconds