Search in sources :

Example 1 with IASTAmbiguousDeclarator

use of org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator in project Cpp4CIA by thanhminhmr.

the class AstBuilder method createFromDeclarator.

@Nonnull
private CppNode createFromDeclarator(@Nonnull CppNode parentNode, @Nullable CppNode typeNode, @Nonnull IASTDeclarator declarator, boolean isTypedef) {
    final IASTName declaratorName = declarator.getName();
    final IBinding declaratorBinding = declaratorName.resolveBinding();
    final String signature = ASTStringUtil.getSignatureString(declarator);
    if (declarator instanceof IASTAmbiguousDeclarator) {
        return createUnknownNode(parentNode, declaratorBinding, declaratorName.toString(), isTypedef);
    } else if (declarator instanceof ICPPASTFunctionDeclarator) {
        // region Function
        final ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) declarator;
        final CppNode functionNode = createNode(declaratorBinding, declaratorName, signature, new FunctionNode(), parentNode);
        if (functionNode instanceof FunctionNode) {
            if (!(typeNode instanceof IntegralNode) || !typeNode.getName().isEmpty()) {
                ((FunctionNode) functionNode).setType(typeNode);
            // functionNode.addDependencyTo(typeNode, DependencyType.USE);
            }
            for (final ICPPASTParameterDeclaration functionParameter : functionDeclarator.getParameters()) {
                final CppNode parameterType = createFromDeclSpecifier(functionNode, functionParameter.getDeclSpecifier());
                if (!(parameterType instanceof IntegralNode) || !parameterType.getName().equals("void")) {
                    createFromDeclarator(functionNode, parameterType, functionParameter.getDeclarator(), true);
                    ((FunctionNode) functionNode).addParameter(parameterType);
                // functionNode.addDependencyTo(parameterType, DependencyType.USE);
                }
            }
            final IASTInitializer initializer = declarator.getInitializer();
            if (initializer != null && initializer.getChildren().length > 0) {
                ((FunctionNode) functionNode).setBody(initializer.getRawSignature());
                childrenCreationQueue.add(Pair.mutableOf(functionNode, initializer));
            }
        }
        // endregion
        return functionNode;
    } else if (declarator instanceof ICPPASTDeclarator) {
        if (isTypedef) {
            // region Typedef
            final CppNode typedefNode = createNode(declaratorBinding, declaratorName, signature, new TypedefNode(), parentNode);
            if (typedefNode instanceof TypedefNode) {
                ((TypedefNode) typedefNode).setType(typeNode);
            // typedefNode.addDependencyTo(typeNode, DependencyType.USE);
            }
            // endregion
            return typedefNode;
        } else {
            // region Variable
            final CppNode variableNode = createNode(declaratorBinding, declaratorName, signature, new VariableNode(), parentNode);
            if (variableNode instanceof VariableNode) {
                ((VariableNode) variableNode).setType(typeNode);
                // variableNode.addDependencyTo(typeNode, DependencyType.USE);
                final IASTInitializer initializer = declarator.getInitializer();
                if (initializer != null) {
                    ((VariableNode) variableNode).setBody(initializer.getRawSignature());
                    childrenCreationQueue.add(Pair.mutableOf(variableNode, initializer));
                }
            }
            // endregion
            return variableNode;
        }
    } else {
        // todo: debug?
        throw new IllegalArgumentException("createFromDeclarator(declarator = (" + Utilities.objectIdentifyString(declarator) + "))");
    }
}
Also used : ICPPASTFunctionDeclarator(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator) IBinding(org.eclipse.cdt.core.dom.ast.IBinding) FunctionNode(mrmathami.cia.cpp.ast.FunctionNode) CppNode(mrmathami.cia.cpp.ast.CppNode) ICPPASTDeclarator(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator) VariableNode(mrmathami.cia.cpp.ast.VariableNode) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IASTInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) IASTAmbiguousDeclarator(org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator) IntegralNode(mrmathami.cia.cpp.ast.IntegralNode) ICPPASTParameterDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration) TypedefNode(mrmathami.cia.cpp.ast.TypedefNode) Nonnull(mrmathami.annotations.Nonnull)

Aggregations

Nonnull (mrmathami.annotations.Nonnull)1 CppNode (mrmathami.cia.cpp.ast.CppNode)1 FunctionNode (mrmathami.cia.cpp.ast.FunctionNode)1 IntegralNode (mrmathami.cia.cpp.ast.IntegralNode)1 TypedefNode (mrmathami.cia.cpp.ast.TypedefNode)1 VariableNode (mrmathami.cia.cpp.ast.VariableNode)1 IASTInitializer (org.eclipse.cdt.core.dom.ast.IASTInitializer)1 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)1 IBinding (org.eclipse.cdt.core.dom.ast.IBinding)1 ICPPASTDeclarator (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator)1 ICPPASTFunctionDeclarator (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator)1 ICPPASTParameterDeclaration (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration)1 IASTAmbiguousDeclarator (org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator)1