Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Standalone indexer works for C not C++

thak for helping

answers in order:

- I believe I have a very recent revision of RDT (about end of may 2010), but I might have taken the code from an older piece of it ...

- will try the logging idea (only not today because I am about to leave)

- I do have problems with file names: included file names actually. I hacked URIRelativeLocationConverter and when I look in the index (index.getAllFiles()) it does give some strange names (absolute filenames with the relative directory prepend at the start, like:  /home/me/test/usr/include/some-header-file.h, where /usr/include/some-header-file.h, is the actual file path).

But as you said, it does work for C so why not C++, actually, for some calls in standard header files, it finds the binding and the definition location, only not for my files :-(

As you can see, I barely know what I am doing here, so any pointer is welcome

- I get the ASTName in a visitor. I am interested in method calls (from where and to where)
So I take all IASTExpression that are FunctionCalls and find my way to the ASTName of the called method (function):

    public int visit(IASTExpression expr) {
        IASTNode called = null;
        if (expr instanceof IASTFunctionCallExpression) {
            IASTNode child = ((IASTFunctionCallExpression) expr).getFunctionNameExpression();
            if (child instanceof IASTIdExpression) {
                called = ((IASTIdExpression) child).getName();
            }
            else if (child instanceof IASTFieldReference) {
                called = ((IASTFieldReference) child).getFieldName();
            };

            if ( (called != null) && (called instanceof IASTName) ) {
                IASTName name = (IASTName)called;
                try {
                    IIndexName decls[] = index.findDeclarations(name.resolveBinding());  // TODO find why binding is empty :-(
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }
        }
        return PROCESS_CONTINUE;
    }

Again, a very similar visitor for C works.


nicolas

On Fri, Jul 16, 2010 at 2:50 PM, Chris Recoskie <recoskie@xxxxxxxxxx> wrote:

Well what you have for a language mapper should work "good enough" for an experiment, but it looks like you got that from an older version of RDT. RDT doesn't hardcode the file extension->language mappings any more.

Probably what you should do is enable progress reporting (there is a StdoutProgresMonitor class in RDT you can use to output the progress info to the console) and turn on all the logging on the indexer. That might lead to more information about what's actually going wrong.

Here is a thought too that comes to mind, as this problem has bitten me before. If you are producing your AST name by parsing a working copy buffer, and the filename in your AST file location does not exactly match the filename as the indexer saw it, index queries using that name will fail. Although, I would tend to think that if that was the problem, you would have that same problem for C. How did you obtain your AST name?



===========================
Chris Recoskie
Team Lead, IBM CDT and RDT
IBM Toronto

Inactive hide details for Nicolas Anquetil ---07/16/2010 08:25:18 AM---I got these from PTP-RDT:     private static final Map<SNicolas Anquetil ---07/16/2010 08:25:18 AM---I got these from PTP-RDT: private static final Map<String,IPDOMLinkageFactory> linkageFactoryMap


From:

Nicolas Anquetil <anquetil.nicolas@xxxxxxxxx>

To:

"CDT General developers list." <cdt-dev@xxxxxxxxxxx>

Date:

07/16/2010 08:25 AM

Subject:

Re: [cdt-dev] Standalone indexer works for C not C++

Sent by:

cdt-dev-bounces@xxxxxxxxxxx




I got these from PTP-RDT:

    private static final Map<String,IPDOMLinkageFactory> linkageFactoryMap = new HashMap<String,IPDOMLinkageFactory>() {{
        put(ILinkage.C_LINKAGE_NAME, new PDOMCLinkageFactory());
        put(ILinkage.CPP_LINKAGE_NAME, new PDOMCPPLinkageFactory());
    }};

    private static final ILanguageMapper languageMapper = new ILanguageMapper(){
        public ILanguage getLanguage(String file) {
            if(file.endsWith(".c"))
                return GCCLanguage.getDefault();
            else if ( file.endsWith(".cpp") || file.endsWith(".C") || file.endsWith(".c++") )
                return GPPLanguage.getDefault();
            return null;
        }
    };


Well, I am not peculiar on the way to use the standalone indexer.
I arrived at this solution by copy-and-paste and trial-and-error.
I don't pretend I am understanding everything it does.

If you can share a better (in the sense that does work) way to do it, I would gladly (and humbly) accept it.

thank

nicolas

On Fri, Jul 16, 2010 at 2:18 PM, Chris Recoskie <recoskie@xxxxxxxxxx> wrote:
    What language is returned by the language mapper?

    We don't use the standalone indexer in quite the same way you are using it, so there may be a subtle difference somewhere in some of the code you don't show.

    ===========================
    Chris Recoskie
    Team Lead, IBM CDT and RDT
    IBM Toronto

    Inactive hide details for Nicolas Anquetil ---07/16/2010 05:58:47 AM---Hi guys, You might recall that I asked how to parse and Nicolas Anquetil ---07/16/2010 05:58:47 AM---Hi guys, You might recall that I asked how to parse and index C projects with


From:

Nicolas Anquetil <anquetil.nicolas@xxxxxxxxx>

To:

cdt-dev@xxxxxxxxxxx

Date:

07/16/2010 05:58 AM

Subject:

[cdt-dev] Standalone indexer works for C not C++

Sent by:

cdt-dev-bounces@xxxxxxxxxxx




    Hi guys,

    You might recall that I asked how to parse and index C projects with
    CDT standalone.

    Well I succeeded thanks to your help.

    However, I also want the same thing for C++ and strangely enough,
    things appear to behave differently :-(

    Would you have a suggestion?

    Following is an excerpt of the code:
    ---
    List<String> tus = // all C (resp. C++) files in the project
    directory. this includes .h
    IIndexLocationConverter locationConverter = new
    URILocationConverter(projectDir.toURI());  // note
    URILocationConverter is based on URIRelativeLocationConverter
    macroDefinitions = Collections.emptyMap();
    scannerInfo = new ScannerInfo(macroDefinitions, includePaths);
    indexer = new StandaloneFastIndexer(new File("xyz"),
    locationConverter, linkageFactoryMap, scannerInfo,
    /*FileEncodingRegistry*/null, mapper, LOG);
    indexer.rebuild(tus, new NullProgressMonitor());
    foreach C /* resp. C++ */ file
     FileContent fc = FileContent.createForExternalFileLocation(srcfile);
     IASTTranslationUnit unit =
    mapper.getLanguage(srcfile).getASTTranslationUnit(fc, scannerInfo,
    ExternalFilesProvider.getInstance(), indexer.getIndex(), 0, LOG);
    ---

    The problem is that with C++ name.resolveBinding() is null in the following:
    ---
    IASTName name = // some ASTName from the unit
    indexer.getIndex().findDeclarations(name.resolveBinding())
    ---


    With C projects it does work :-(

    I understand it is a lot of uncomplete code. If you need the whole
    thing I can send it.

    I believe the main question is: Why is it working for C and not C++?
    What is the difference?
    any suggestion where I should look?

    thanks

    nicolas

    --
    Nicolas Anquetil        Univ. Lille1 / INRIA-equipe RMod

    _______________________________________________
    cdt-dev mailing list

    cdt-dev@xxxxxxxxxxx
    https://dev.eclipse.org/mailman/listinfo/cdt-dev



    _______________________________________________
    cdt-dev mailing list

    cdt-dev@xxxxxxxxxxx
    https://dev.eclipse.org/mailman/listinfo/cdt-dev



--
Nicolas Anquetil        Univ. Lille1 / INRIA-equipe RMod
_______________________________________________

cdt-dev mailing list
cdt-dev@xxxxxxxxxxx

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




--
Nicolas Anquetil        Univ. Lille1 / INRIA-equipe RMod

GIF image

GIF image


Back to the top