Search in sources :

Example 1 with IASTSimpleDeclaration

use of org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ILTISDummyRenameRefactoring method collectModifications.

@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
    IASTTranslationUnit ast = refactoringContext.getAST(tu, pm);
    IASTSimpleDeclaration funcDeclaration = (IASTSimpleDeclaration) ast.getDeclarations()[0];
    IASTFunctionDeclarator declarator = (IASTFunctionDeclarator) funcDeclaration.getDeclarators()[0];
    IASTFunctionDeclarator newDeclarator = declarator.copy();
    IASTName newName = CPPNodeFactory.getDefault().newName("b".toCharArray());
    newDeclarator.setName(newName);
    ASTRewrite rewrite = collector.rewriterForTranslationUnit(ast);
    rewrite.replace(declarator, newDeclarator, new TextEditGroup(""));
}
Also used : IASTFunctionDeclarator(org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator) IASTSimpleDeclaration(org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) ASTRewrite(org.eclipse.cdt.core.dom.rewrite.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 2 with IASTSimpleDeclaration

use of org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class DummyRenameRefactoring method collectModifications.

@Override
protected void collectModifications(IProgressMonitor pm, ModificationCollector collector) throws CoreException, OperationCanceledException {
    IASTTranslationUnit ast = refactoringContext.getAST(tu, pm);
    IASTSimpleDeclaration funcDeclaration = (IASTSimpleDeclaration) ast.getDeclarations()[0];
    IASTFunctionDeclarator declarator = (IASTFunctionDeclarator) funcDeclaration.getDeclarators()[0];
    IASTFunctionDeclarator newDeclarator = declarator.copy();
    IASTName newName = CPPNodeFactory.getDefault().newName("b".toCharArray());
    newDeclarator.setName(newName);
    ASTRewrite rewrite = collector.rewriterForTranslationUnit(ast);
    rewrite.replace(declarator, newDeclarator, new TextEditGroup(""));
}
Also used : IASTFunctionDeclarator(org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator) IASTSimpleDeclaration(org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) ASTRewrite(org.eclipse.cdt.core.dom.rewrite.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 3 with IASTSimpleDeclaration

use of org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ASTComparison method typeSensitiveNodeEquals.

private static <T extends IASTNode> boolean typeSensitiveNodeEquals(final T expected, final T actual, final EnumSet<ComparisonArg> args) {
    if (!expected.getClass().equals(actual.getClass())) {
        return false;
    }
    if (expected instanceof IASTDeclaration) {
        /* Terminal checks */
        if (expected instanceof ICPPASTFunctionDefinition) {
            final ICPPASTFunctionDefinition et = as(expected);
            final ICPPASTFunctionDefinition at = as(actual);
            return et.isDefaulted() == at.isDefaulted() && et.isDeleted() == at.isDeleted();
        } else if (expected instanceof ICPPASTTemplateDeclaration) {
            final ICPPASTTemplateDeclaration et = as(expected);
            final ICPPASTTemplateDeclaration at = as(actual);
            return et.isExported() == at.isExported();
        } else if (expected instanceof ICPPASTNamespaceDefinition) {
            final ICPPASTNamespaceDefinition et = as(expected);
            final ICPPASTNamespaceDefinition at = as(actual);
            return et.isInline() == at.isInline();
        } else if (expected instanceof ICPPASTVisibilityLabel) {
            final ICPPASTVisibilityLabel et = as(expected);
            final ICPPASTVisibilityLabel at = as(actual);
            return et.getVisibility() == at.getVisibility();
        } else if (expected instanceof ICPPASTLinkageSpecification) {
            final ICPPASTLinkageSpecification et = as(expected);
            final ICPPASTLinkageSpecification at = as(actual);
            return et.getLiteral().equals(at.getLiteral());
        } else if (expected instanceof ICPPASTUsingDeclaration) {
            final ICPPASTUsingDeclaration et = as(expected);
            final ICPPASTUsingDeclaration at = as(actual);
            return et.isTypename() == at.isTypename();
        } else if (expected instanceof IASTSimpleDeclaration || expected instanceof ICPPASTAliasDeclaration || expected instanceof ICPPASTUsingDirective) {
            /* All tokens are stored in the child-nodes */
            return defaultHandler(expected, actual, args);
        }
    /* Continue comparing raw-signature */
    } else if (expected instanceof ICPPASTTemplateParameter) {
        /* Template Parameter */
        final ICPPASTTemplateParameter e = as(expected);
        final ICPPASTTemplateParameter a = as(actual);
        if (e.isParameterPack() != a.isParameterPack()) {
            return false;
        }
        if (expected instanceof ICPPASTSimpleTypeTemplateParameter) {
            final ICPPASTSimpleTypeTemplateParameter et = as(expected);
            final ICPPASTSimpleTypeTemplateParameter at = as(actual);
            return et.getParameterType() == at.getParameterType();
        } else if (expected instanceof ICPPASTParameterDeclaration || expected instanceof ICPPASTTemplatedTypeTemplateParameter) {
            /* All tokens are stored in the child-nodes */
            return defaultHandler(expected, actual, args);
        }
    } else if (expected instanceof ICPPASTDeclarator) {
        /* Terminal checks */
        if (expected instanceof ICPPASTFunctionDeclarator) {
            final ICPPASTFunctionDeclarator e = as(expected);
            final ICPPASTFunctionDeclarator a = as(actual);
            return e.isConst() == a.isConst() && e.isFinal() == a.isFinal() && e.isPureVirtual() == a.isPureVirtual() && e.isVolatile() == a.isVolatile();
        } else {
            /* All tokens are stored in the child-nodes */
            return defaultHandler(expected, actual, args);
        }
    /* Continue comparing raw-signature */
    } else if (expected instanceof ICPPASTDeclSpecifier) {
        /* DeclSpecifier */
        final ICPPASTDeclSpecifier e = as(expected);
        final ICPPASTDeclSpecifier a = as(actual);
        if (e.isConst() != a.isConst() || e.isVirtual() != a.isVirtual() || e.isVolatile() != a.isVolatile() || e.isConstexpr() != a.isConstexpr() || e.isExplicit() != a.isExplicit() || e.isFriend() != a.isFriend() || e.isRestrict() != a.isRestrict() || e.isThreadLocal() != a.isThreadLocal() || e.getStorageClass() != a.getStorageClass()) {
            return false;
        }
        /* Terminal checks */
        if (expected instanceof ICPPASTNamedTypeSpecifier) {
            final ICPPASTNamedTypeSpecifier et = as(expected);
            final ICPPASTNamedTypeSpecifier at = as(actual);
            return et.isTypename() == at.isTypename();
        } else if (expected instanceof ICPPASTCompositeTypeSpecifier) {
            final ICPPASTCompositeTypeSpecifier et = as(expected);
            final ICPPASTCompositeTypeSpecifier at = as(actual);
            return et.isFinal() == at.isFinal() && et.isVirtual() == at.isVirtual() && et.getKey() == at.getKey();
        } else if (expected instanceof ICPPASTElaboratedTypeSpecifier) {
            final ICPPASTElaboratedTypeSpecifier et = as(expected);
            final ICPPASTElaboratedTypeSpecifier at = as(actual);
            return et.getKind() == at.getKind();
        } else if (expected instanceof ICPPASTEnumerationSpecifier) {
            final ICPPASTEnumerationSpecifier et = as(expected);
            final ICPPASTEnumerationSpecifier at = as(actual);
            return et.isOpaque() == at.isOpaque() && et.isScoped() == at.isScoped();
        } else {
            return defaultHandler(expected, actual, args);
        }
    /* Continue comparing raw-signature */
    } else if (expected instanceof IASTExpression) {
        if (expected instanceof ICPPASTUnaryExpression) {
            final ICPPASTUnaryExpression et = as(expected);
            final ICPPASTUnaryExpression at = as(actual);
            return et.getOperator() == at.getOperator();
        } else if (expected instanceof ICPPASTBinaryExpression) {
            final ICPPASTBinaryExpression et = as(expected);
            final ICPPASTBinaryExpression at = as(actual);
            return et.getOperator() == at.getOperator();
        } else if (expected instanceof ICPPASTLiteralExpression) {
            final ICPPASTLiteralExpression et = as(expected);
            final ICPPASTLiteralExpression at = as(actual);
            return et.getKind() == at.getKind() && equalsRaw(et, at, args);
        } else if (expected instanceof ICPPASTCastExpression) {
            final ICPPASTCastExpression et = as(expected);
            final ICPPASTCastExpression at = as(actual);
            return et.getOperator() == at.getOperator();
        } else if (expected instanceof ICPPASTNewExpression) {
            final ICPPASTNewExpression et = as(expected);
            final ICPPASTNewExpression at = as(actual);
            return et.isArrayAllocation() == at.isArrayAllocation() && et.isGlobal() == at.isGlobal() && et.isNewTypeId() == at.isNewTypeId();
        } else if (expected instanceof ICPPASTDeleteExpression) {
            final ICPPASTDeleteExpression et = as(expected);
            final ICPPASTDeleteExpression at = as(actual);
            return et.isVectored() == at.isVectored() && et.isGlobal() == at.isGlobal();
        } else if (expected instanceof ICPPASTFieldReference) {
            final ICPPASTFieldReference et = as(expected);
            final ICPPASTFieldReference at = as(actual);
            return et.isPointerDereference() == at.isPointerDereference() && et.isTemplate() == at.isTemplate();
        } else if (expected instanceof ICPPASTLambdaExpression) {
            final ICPPASTLambdaExpression et = as(expected);
            final ICPPASTLambdaExpression at = as(actual);
            return et.getCaptureDefault() == at.getCaptureDefault();
        } else if (expected instanceof ICPPASTFunctionCallExpression || expected instanceof ICPPASTSimpleTypeConstructorExpression || expected instanceof ICPPASTLambdaExpression || expected instanceof ICPPASTPackExpansionExpression || expected instanceof IASTIdExpression || expected instanceof ICPPASTArraySubscriptExpression || expected instanceof ICPPASTExpressionList || expected instanceof IASTConditionalExpression) {
            /* All tokens are stored in the child-nodes */
            return defaultHandler(expected, actual, args);
        }
    /* Continue comparing raw-signature */
    } else if (expected instanceof ICPPASTReferenceOperator) {
        /* ReferenceOperator */
        final ICPPASTReferenceOperator et = as(expected);
        final ICPPASTReferenceOperator at = as(actual);
        return et.isRValueReference() == at.isRValueReference();
    } else if (expected instanceof IASTPointer) {
        /* Pointers */
        final IASTPointer et = as(expected);
        final IASTPointer at = as(actual);
        return et.isConst() == at.isConst() && et.isRestrict() == at.isRestrict() && et.isVolatile() == at.isVolatile();
    } else if (expected instanceof IASTStatement) {
        return defaultHandler(expected, actual, args);
    } else if (expected instanceof ICPPASTPackExpandable) {
        /* ICPPASTPackExpandable */
        final ICPPASTPackExpandable e = as(expected);
        final ICPPASTPackExpandable a = as(actual);
        if (e.isPackExpansion() != a.isPackExpansion()) {
            return false;
        }
        if (expected instanceof ICPPASTInitializerList) {
            final ICPPASTInitializerList et = as(expected);
            final ICPPASTInitializerList at = as(actual);
            return et.getSize() == at.getSize();
        } else if (expected instanceof ICPPASTBaseSpecifier) {
            final ICPPASTBaseSpecifier et = as(expected);
            final ICPPASTBaseSpecifier at = as(actual);
            return et.isVirtual() == at.isVirtual() && et.getVisibility() == at.getVisibility();
        } else if (expected instanceof ICPPASTCapture) {
            final ICPPASTCapture et = as(expected);
            final ICPPASTCapture at = as(actual);
            return et.capturesThisPointer() == at.capturesThisPointer() && et.isByReference() == at.isByReference();
        } else if (expected instanceof ICPPASTTypeId) {
            return true;
        } else {
            return defaultHandler(expected, actual, args);
        }
    } else if (expected instanceof ICPPASTName) {
        /* Names */
        final ICPPASTName e = as(expected);
        final ICPPASTName a = as(actual);
        if (e.isQualified() != a.isQualified()) {
            return false;
        }
        if (expected instanceof ICPPASTTemplateId) {
            final ICPPASTTemplateId et = as(expected);
            final ICPPASTTemplateId at = as(actual);
            return et.isDeclaration() == at.isDeclaration();
        } else if (expected instanceof ICPPASTQualifiedName) {
            final ICPPASTQualifiedName et = as(expected);
            final ICPPASTQualifiedName at = as(actual);
            return et.isFullyQualified() == at.isFullyQualified();
        } else if (expected instanceof ICPPASTTemplateId) {
            /* Relevant information is contained in the children */
            return defaultHandler(expected, actual, args);
        }
    } else {
        /* OTHER */
        if (expected instanceof IASTTranslationUnit || expected instanceof IASTArrayModifier || expected instanceof IASTInitializer) {
            /* Relevant information is contained in the children */
            return defaultHandler(expected, actual, args);
        }
    /* Continue comparing raw-signature */
    }
    /* Default case */
    return equalsNormalizedRaw(expected, actual);
}
Also used : IASTExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) ICPPASTLinkageSpecification(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification) ICPPASTInitializerList(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerList) ICPPASTDeclSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier) ICPPASTTemplateDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration) IASTStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) ICPPASTExpressionList(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpressionList) ICPPASTParameterDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration) IASTConditionalExpression(org.eclipse.cdt.core.dom.ast.IASTConditionalExpression) ICPPASTDeleteExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression) ICPPASTArraySubscriptExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression) ICPPASTFunctionDeclarator(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator) IASTArrayModifier(org.eclipse.cdt.core.dom.ast.IASTArrayModifier) ICPPASTLiteralExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression) ICPPASTUsingDirective(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective) IASTIdExpression(org.eclipse.cdt.core.dom.ast.IASTIdExpression) ICPPASTTemplateId(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId) ICPPASTNamedTypeSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier) ICPPASTNamespaceDefinition(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition) ICPPASTTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter) ICPPASTFieldReference(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference) ICPPASTVisibilityLabel(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel) IASTInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) ICPPASTElaboratedTypeSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier) ICPPASTUnaryExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression) ICPPASTName(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName) ICPPASTQualifiedName(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName) IASTPointer(org.eclipse.cdt.core.dom.ast.IASTPointer) ICPPASTNewExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression) ICPPASTDeclarator(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator) ICPPASTCompositeTypeSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier) ICPPASTFunctionCallExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression) ICPPASTFunctionDefinition(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition) ICPPASTSimpleTypeTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter) ICPPASTLambdaExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression) ICPPASTSimpleTypeConstructorExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression) ICPPASTReferenceOperator(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator) ICPPASTBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier) ICPPASTEnumerationSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier) IASTSimpleDeclaration(org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration) IASTDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) ICPPASTAliasDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration) ICPPASTPackExpandable(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpandable) ICPPASTUsingDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration) ICPPASTPackExpansionExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression) ICPPASTTypeId(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId) ICPPASTCastExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression) ICPPASTTemplatedTypeTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter) ICPPASTCapture(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture) ICPPASTBinaryExpression(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression)

Example 4 with IASTSimpleDeclaration

use of org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration in project Cpp4CIA by thanhminhmr.

the class AstBuilder method createChildrenFromDeclaration.

@Nonnull
private List<CppNode> createChildrenFromDeclaration(@Nonnull CppNode parentNode, @Nonnull IASTDeclaration declaration) {
    if (declaration instanceof ICPPASTVisibilityLabel || declaration instanceof IASTASMDeclaration || declaration instanceof IASTProblemDeclaration || declaration instanceof ICPPASTStaticAssertDeclaration || declaration instanceof ICPPASTExplicitTemplateInstantiation || declaration instanceof ICPPASTInitCapture) {
        // skipped
        return List.of();
    } else if (declaration instanceof ICPPASTUsingDeclaration) {
        // region Using Declaration / Directive
        final IASTName declarationName = ((ICPPASTUsingDeclaration) declaration).getName();
        final IBinding declarationBinding = declarationName.resolveBinding();
        final CppNode declarationNode = createNode(declarationBinding, declarationName, null, new TypedefNode(), parentNode);
        if (declarationNode instanceof TypedefNode && declarationBinding instanceof ICPPUsingDeclaration) {
            for (final IBinding delegateBinding : ((ICPPUsingDeclaration) declarationBinding).getDelegates()) {
                createUnknownNode(declarationNode, delegateBinding, declarationName.toString(), true);
            }
        }
        // endregion
        return List.of(declarationNode);
    } else if (declaration instanceof ICPPASTUsingDirective) {
        // region Using Declaration / Directive
        final IASTName usingName = ((ICPPASTUsingDirective) declaration).getQualifiedName();
        final CppNode usingNode = createUnknownNode(parentNode, usingName.resolveBinding(), usingName.toString(), true);
        // endregion
        return List.of(usingNode);
    } else if (declaration instanceof ICPPASTLinkageSpecification) {
        final ICPPASTLinkageSpecification linkageSpecification = (ICPPASTLinkageSpecification) declaration;
        // region extern "C"
        final List<CppNode> childrenNode = new ArrayList<>();
        for (final IASTDeclaration linkageDeclaration : linkageSpecification.getDeclarations(false)) {
            childrenNode.addAll(createChildrenFromDeclaration(parentNode, linkageDeclaration));
        }
        // endregion
        return childrenNode;
    } else if (declaration instanceof ICPPASTNamespaceDefinition) {
        final ICPPASTNamespaceDefinition namespaceDefinition = (ICPPASTNamespaceDefinition) declaration;
        // region Namespace
        final IASTName namespaceName = namespaceDefinition.getName();
        final CppNode namespaceNode = createNode(namespaceName.resolveBinding(), namespaceName, null, new NamespaceNode(), parentNode);
        for (final IASTDeclaration namespaceDeclaration : namespaceDefinition.getDeclarations(false)) {
            createChildrenFromDeclaration(namespaceNode, namespaceDeclaration);
        }
        // endregion
        return List.of(namespaceNode);
    } else if (declaration instanceof IASTSimpleDeclaration) {
        final IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
        // region Simple Declaration
        final IASTDeclSpecifier simpleSpecifier = simpleDeclaration.getDeclSpecifier();
        final CppNode simpleNodeType = createFromDeclSpecifier(parentNode, simpleSpecifier);
        final List<CppNode> simpleNodeList = new ArrayList<>();
        final boolean isTypedef = simpleSpecifier.getStorageClass() == IASTDeclSpecifier.sc_typedef;
        for (final IASTDeclarator simpleDeclarator : simpleDeclaration.getDeclarators()) {
            simpleNodeList.add(createFromDeclarator(parentNode, simpleNodeType, simpleDeclarator, isTypedef));
        }
        // endregion
        return !simpleNodeList.isEmpty() ? simpleNodeList : List.of(simpleNodeType);
    } else if (declaration instanceof ICPPASTFunctionDefinition) {
        final ICPPASTFunctionDefinition functionDefinition = (ICPPASTFunctionDefinition) declaration;
        // region Function
        final CppNode functionReturnType = createFromDeclSpecifier(parentNode, functionDefinition.getDeclSpecifier());
        final CppNode functionNode = createFromDeclarator(parentNode, functionReturnType, functionDefinition.getDeclarator(), false);
        final StringBuilder functionBodyBuilder = new StringBuilder(functionNode instanceof FunctionNode ? Objects.requireNonNullElse(((FunctionNode) functionNode).getBody(), "") : "");
        // function with constructor
        for (final ICPPASTConstructorChainInitializer memberChainInitializer : functionDefinition.getMemberInitializers()) {
            final IASTName memberName = memberChainInitializer.getMemberInitializerId();
            createUnknownNode(functionNode, memberName.resolveBinding(), memberName.toString(), true);
            functionBodyBuilder.append(memberName).append('(');
            final IASTInitializer memberInitializer = memberChainInitializer.getInitializer();
            if (memberInitializer != null) {
                childrenCreationQueue.add(Pair.mutableOf(functionNode, memberInitializer));
                functionBodyBuilder.append(memberInitializer.getRawSignature());
            }
            functionBodyBuilder.append(");");
        }
        // function with body
        final IASTStatement functionBody = functionDefinition.getBody();
        if (functionBody != null && functionBody.getChildren().length > 0) {
            childrenCreationQueue.add(Pair.mutableOf(functionNode, functionBody));
            functionBodyBuilder.append(functionBody.getRawSignature());
        }
        if (functionBodyBuilder.length() > 0 && functionNode instanceof FunctionNode) {
            ((FunctionNode) functionNode).setBody(functionBodyBuilder.toString());
        }
        // endregion
        return List.of(functionNode);
    } else if (declaration instanceof ICPPASTTemplateDeclaration) {
        final ICPPASTTemplateDeclaration templateDeclaration = (ICPPASTTemplateDeclaration) declaration;
        // region Template
        final List<CppNode> innerNodeList = createChildrenFromDeclaration(parentNode, templateDeclaration.getDeclaration());
        if (!innerNodeList.isEmpty()) {
            final CppNode innerNode = innerNodeList.get(0);
            for (final ICPPASTTemplateParameter templateParameter : templateDeclaration.getTemplateParameters()) {
                createFromTemplateParameter(innerNode, templateParameter);
            }
        }
        // endregion
        return innerNodeList;
    } else if (declaration instanceof ICPPASTNamespaceAlias) {
        final ICPPASTNamespaceAlias namespaceAlias = (ICPPASTNamespaceAlias) declaration;
        // region Namespace Alias
        final IASTName aliasName = namespaceAlias.getAlias();
        final CppNode aliasNode = createNode(aliasName.resolveBinding(), aliasName, null, new TypedefNode(), parentNode);
        final IASTName mappingName = namespaceAlias.getMappingName();
        createUnknownNode(aliasNode, mappingName.resolveBinding(), mappingName.toString(), true);
        // endregion
        return List.of(aliasNode);
    } else if (declaration instanceof ICPPASTAliasDeclaration) {
        final ICPPASTAliasDeclaration aliasDefinition = (ICPPASTAliasDeclaration) declaration;
        // region Alias
        final IASTName aliasName = aliasDefinition.getAlias();
        final ICPPASTTypeId aliasTypeId = aliasDefinition.getMappingTypeId();
        final IASTDeclSpecifier aliasDeclSpecifier = aliasTypeId.getDeclSpecifier();
        final IASTDeclarator aliasDeclarator = aliasTypeId.getAbstractDeclarator();
        final CppNode aliasNode = createNode(aliasName.resolveBinding(), aliasName, ASTStringUtil.getSignatureString(aliasDeclSpecifier, aliasDeclarator), new TypedefNode(), parentNode);
        final CppNode aliasType = createFromDeclSpecifier(aliasNode, aliasDeclSpecifier);
        createFromDeclarator(aliasNode, aliasType, aliasDeclarator, false);
        // endregion
        return List.of(aliasNode);
    } else {
        // todo: debug?
        throw new IllegalArgumentException("createChildrenFromDeclaration(parentNode = (" + Utilities.objectIdentifyString(parentNode) + "), declaration = (" + Utilities.objectIdentifyString(declaration) + "))");
    }
}
Also used : ICPPASTExplicitTemplateInstantiation(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation) ICPPASTConstructorChainInitializer(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer) IBinding(org.eclipse.cdt.core.dom.ast.IBinding) CppNode(mrmathami.cia.cpp.ast.CppNode) ICPPASTLinkageSpecification(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification) IASTProblemDeclaration(org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration) IASTDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) ICPPASTFunctionDefinition(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition) ICPPASTTemplateDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration) IASTStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TypedefNode(mrmathami.cia.cpp.ast.TypedefNode) IASTDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) ICPPASTStaticAssertDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTStaticAssertDeclaration) ICPPASTNamespaceAlias(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias) IASTSimpleDeclaration(org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration) IASTDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) IASTASMDeclaration(org.eclipse.cdt.core.dom.ast.IASTASMDeclaration) ICPPASTAliasDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration) FunctionNode(mrmathami.cia.cpp.ast.FunctionNode) ICPPASTUsingDirective(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective) NamespaceNode(mrmathami.cia.cpp.ast.NamespaceNode) ICPPASTUsingDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration) ICPPASTNamespaceDefinition(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition) ICPPASTTemplateParameter(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter) IASTName(org.eclipse.cdt.core.dom.ast.IASTName) ICPPASTTypeId(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId) ICPPASTVisibilityLabel(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel) IASTInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) ICPPUsingDeclaration(org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration) ICPPASTInitCapture(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitCapture) Nonnull(mrmathami.annotations.Nonnull)

Aggregations

IASTSimpleDeclaration (org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration)4 IASTName (org.eclipse.cdt.core.dom.ast.IASTName)3 IASTTranslationUnit (org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)3 IASTDeclaration (org.eclipse.cdt.core.dom.ast.IASTDeclaration)2 IASTFunctionDeclarator (org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator)2 IASTInitializer (org.eclipse.cdt.core.dom.ast.IASTInitializer)2 IASTStatement (org.eclipse.cdt.core.dom.ast.IASTStatement)2 ICPPASTAliasDeclaration (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration)2 ICPPASTFunctionDefinition (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition)2 ICPPASTLinkageSpecification (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification)2 ICPPASTNamespaceDefinition (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)2 ICPPASTTemplateDeclaration (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration)2 ICPPASTTemplateParameter (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter)2 ICPPASTTypeId (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId)2 ICPPASTUsingDeclaration (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration)2 ICPPASTUsingDirective (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective)2 ICPPASTVisibilityLabel (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1