Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] AST for a C++ project

For my Arduino Eclipse Plugin Named Sloeber I have written code that looks for a method (Serial.Begin([baudRate]) in a specific function (Setup) to return [baudRate].

I start by the indexer like Thomas described but I use plain text parsing code to get the parameter text. This because the AST sometimes caused unwanted delays and parsing was really easy in my case.

Everything is in a class you can find here https://github.com/jantje/arduino-eclipse-plugin/blob/master/io.sloeber.core/src/io/sloeber/common/IndexHelper.java

This is the code that calls it to find the baud rate

    public static int getCodeBaudRate(IProject iProject) {
    String parentFunc = "setup"; //$NON-NLS-1$
    String childFunc = "Serial.begin"; //$NON-NLS-1$
String baudRate = IndexHelper.findParameterInFunction(iProject, parentFunc, childFunc, null);
    if (baudRate == null) {
        return -1;
    }
    return Integer.parseInt(baudRate);

    }

I hope this helps you out.

Jantje


Op 1/12/2016 om 14:12 schreef Corbat Thomas:
Yes exactly. If you don't specify the flags the whole compilation unit should be parsed.

If I got your intention correctly, I think it should be feasible to use the index to find such locations. But this will not give you AST nodes to work with, but only IIndexNames. But if the location of such a name is within the project you can parse the translation unit of the corresponding file and get the AST.

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of sim0s
Sent: Donnerstag, 1. Dezember 2016 12:16
To: cdt-dev@xxxxxxxxxxx
Subject: Re: [cdt-dev] AST for a C++ project

Thanks Thomas.

When you say "what flags", I suppose you mean the following command:
tu.getAST(index, aFlag);// e.g., aFlag = ITranslationUnit.AST_SKIP_INDEXED_HEADERS


Essentially what I am trying to achieve is the following:
Parse a C++ project and find some nodes (e.g., function calls) that belong to a specific namespace.

Initially, I tried to achieve this through the index. However, there is the problem that a compilation unit (using the flag I say above) was only parsing a single C++ file. So not all nodes of interest were captured.
That's why I need to create the AST of the entire C++ project. However, I'd like to avoid creating AST for "conventional" libraries such as std etc.

Thanks again.



--
View this message in context: http://eclipse.1072660.n5.nabble.com/AST-for-a-C-project-tp186484p186488.html
Sent from the Eclipse CDT - Development mailing list archive at Nabble.com.
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev




Back to the top