Search in sources :

Example 1 with CPPASTFunctionDefinition

use of org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition in project arduino-eclipse-plugin by Sloeber.

the class PdePreprocessor method extendMethodDeclarationsForFile.

private static String extendMethodDeclarationsForFile(String body, IIndex index, ITranslationUnit tu) throws CoreException {
    // add declarations made in ino files.
    String localBody = body;
    IASTTranslationUnit asttu = tu.getAST(index, ITranslationUnit.AST_SKIP_FUNCTION_BODIES | ITranslationUnit.AST_SKIP_ALL_HEADERS);
    IASTNode[] astNodes = asttu.getChildren();
    for (IASTNode astNode : astNodes) {
        if (astNode instanceof CPPASTFunctionDefinition) {
            String addString = astNode.getRawSignature();
            addString = addString.replaceAll("\r\n", NEWLINE);
            addString = addString.replaceAll("\r", NEWLINE);
            addString = addString.replaceAll("//[^\n]+\n", " ");
            addString = addString.replaceAll("\n", " ");
            addString = addString.replaceAll("\\{.*\\}", "");
            if (addString.contains("=") || addString.contains("::")) {
            // ignore when there are assignments in the
            // declaration
            // or when it is a class function
            } else {
                localBody += addString + ';' + NEWLINE;
            }
        }
    }
    return localBody;
}
Also used : CPPASTFunctionDefinition(org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode)

Aggregations

IASTNode (org.eclipse.cdt.core.dom.ast.IASTNode)1 IASTTranslationUnit (org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)1 CPPASTFunctionDefinition (org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition)1