Search in sources :

Example 1 with ICPPASTFunctionDefinition

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

the class ASTComparison method typeSensitiveNodeEquals.

private static <T extends IASTNode> boolean typeSensitiveNodeEquals(T expected, T actual, EnumSet<ComparisonArg> args) {
    if (!expected.getClass().equals(actual.getClass())) {
        return false;
    }
    if (expected instanceof IASTDeclaration) {
        /* Terminal checks */
        if (expected instanceof ICPPASTFunctionDefinition) {
            ICPPASTFunctionDefinition et = as(expected);
            ICPPASTFunctionDefinition at = as(actual);
            return et.isDefaulted() == at.isDefaulted() && et.isDeleted() == at.isDeleted();
        } else if (expected instanceof ICPPASTTemplateDeclaration) {
            ICPPASTTemplateDeclaration et = as(expected);
            ICPPASTTemplateDeclaration at = as(actual);
            return et.isExported() == at.isExported();
        } else if (expected instanceof ICPPASTNamespaceDefinition) {
            ICPPASTNamespaceDefinition et = as(expected);
            ICPPASTNamespaceDefinition at = as(actual);
            return et.isInline() == at.isInline();
        } else if (expected instanceof ICPPASTVisibilityLabel) {
            ICPPASTVisibilityLabel et = as(expected);
            ICPPASTVisibilityLabel at = as(actual);
            return et.getVisibility() == at.getVisibility();
        } else if (expected instanceof ICPPASTLinkageSpecification) {
            ICPPASTLinkageSpecification et = as(expected);
            ICPPASTLinkageSpecification at = as(actual);
            return et.getLiteral().equals(at.getLiteral());
        } else if (expected instanceof ICPPASTUsingDeclaration) {
            ICPPASTUsingDeclaration et = as(expected);
            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 */
        ICPPASTTemplateParameter e = as(expected);
        ICPPASTTemplateParameter a = as(actual);
        if (e.isParameterPack() != a.isParameterPack())
            return false;
        if (expected instanceof ICPPASTSimpleTypeTemplateParameter) {
            ICPPASTSimpleTypeTemplateParameter et = as(expected);
            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) {
            ICPPASTFunctionDeclarator e = as(expected);
            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 */
        ICPPASTDeclSpecifier e = as(expected);
        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) {
            ICPPASTNamedTypeSpecifier et = as(expected);
            ICPPASTNamedTypeSpecifier at = as(actual);
            return et.isTypename() == at.isTypename();
        } else if (expected instanceof ICPPASTCompositeTypeSpecifier) {
            ICPPASTCompositeTypeSpecifier et = as(expected);
            ICPPASTCompositeTypeSpecifier at = as(actual);
            return et.isFinal() == at.isFinal() && et.isVirtual() == at.isVirtual() && et.getKey() == at.getKey();
        } else if (expected instanceof ICPPASTElaboratedTypeSpecifier) {
            ICPPASTElaboratedTypeSpecifier et = as(expected);
            ICPPASTElaboratedTypeSpecifier at = as(actual);
            return et.getKind() == at.getKind();
        } else if (expected instanceof ICPPASTEnumerationSpecifier) {
            ICPPASTEnumerationSpecifier et = as(expected);
            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) {
            ICPPASTUnaryExpression et = as(expected);
            ICPPASTUnaryExpression at = as(actual);
            return et.getOperator() == at.getOperator();
        } else if (expected instanceof ICPPASTBinaryExpression) {
            ICPPASTBinaryExpression et = as(expected);
            ICPPASTBinaryExpression at = as(actual);
            return et.getOperator() == at.getOperator();
        } else if (expected instanceof ICPPASTLiteralExpression) {
            ICPPASTLiteralExpression et = as(expected);
            ICPPASTLiteralExpression at = as(actual);
            return et.getKind() == at.getKind() && equalsRaw(et, at, args);
        } else if (expected instanceof ICPPASTCastExpression) {
            ICPPASTCastExpression et = as(expected);
            ICPPASTCastExpression at = as(actual);
            return et.getOperator() == at.getOperator();
        } else if (expected instanceof ICPPASTNewExpression) {
            ICPPASTNewExpression et = as(expected);
            ICPPASTNewExpression at = as(actual);
            return et.isArrayAllocation() == at.isArrayAllocation() && et.isGlobal() == at.isGlobal() && et.isNewTypeId() == at.isNewTypeId();
        } else if (expected instanceof ICPPASTDeleteExpression) {
            ICPPASTDeleteExpression et = as(expected);
            ICPPASTDeleteExpression at = as(actual);
            return et.isVectored() == at.isVectored() && et.isGlobal() == at.isGlobal();
        } else if (expected instanceof ICPPASTFieldReference) {
            ICPPASTFieldReference et = as(expected);
            ICPPASTFieldReference at = as(actual);
            return et.isPointerDereference() == at.isPointerDereference() && et.isTemplate() == at.isTemplate();
        } else if (expected instanceof ICPPASTLambdaExpression) {
            ICPPASTLambdaExpression et = as(expected);
            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 */
        ICPPASTReferenceOperator et = as(expected);
        ICPPASTReferenceOperator at = as(actual);
        return et.isRValueReference() == at.isRValueReference();
    } else if (expected instanceof IASTPointer) {
        /* Pointers */
        IASTPointer et = as(expected);
        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 */
        ICPPASTPackExpandable e = as(expected);
        ICPPASTPackExpandable a = as(actual);
        if (e.isPackExpansion() != a.isPackExpansion())
            return false;
        if (expected instanceof ICPPASTInitializerList) {
            ICPPASTInitializerList et = as(expected);
            ICPPASTInitializerList at = as(actual);
            return et.getSize() == at.getSize();
        } else if (expected instanceof ICPPASTBaseSpecifier) {
            ICPPASTBaseSpecifier et = as(expected);
            ICPPASTBaseSpecifier at = as(actual);
            return et.isVirtual() == at.isVirtual() && et.getVisibility() == at.getVisibility();
        } else if (expected instanceof ICPPASTCapture) {
            ICPPASTCapture et = as(expected);
            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 */
        ICPPASTName e = as(expected);
        ICPPASTName a = as(actual);
        if (e.isQualified() != a.isQualified())
            return false;
        if (expected instanceof ICPPASTTemplateId) {
            ICPPASTTemplateId et = as(expected);
            ICPPASTTemplateId at = as(actual);
            return et.isDeclaration() == at.isDeclaration();
        } else if (expected instanceof ICPPASTQualifiedName) {
            ICPPASTQualifiedName et = as(expected);
            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)

Aggregations

IASTArrayModifier (org.eclipse.cdt.core.dom.ast.IASTArrayModifier)1 IASTConditionalExpression (org.eclipse.cdt.core.dom.ast.IASTConditionalExpression)1 IASTDeclaration (org.eclipse.cdt.core.dom.ast.IASTDeclaration)1 IASTExpression (org.eclipse.cdt.core.dom.ast.IASTExpression)1 IASTIdExpression (org.eclipse.cdt.core.dom.ast.IASTIdExpression)1 IASTInitializer (org.eclipse.cdt.core.dom.ast.IASTInitializer)1 IASTPointer (org.eclipse.cdt.core.dom.ast.IASTPointer)1 IASTSimpleDeclaration (org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration)1 IASTStatement (org.eclipse.cdt.core.dom.ast.IASTStatement)1 IASTTranslationUnit (org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)1 ICPPASTAliasDeclaration (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration)1 ICPPASTArraySubscriptExpression (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression)1 ICPPASTBinaryExpression (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression)1 ICPPASTCapture (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture)1 ICPPASTCastExpression (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression)1 ICPPASTCompositeTypeSpecifier (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier)1 ICPPASTBaseSpecifier (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier)1 ICPPASTDeclSpecifier (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier)1 ICPPASTDeclarator (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator)1 ICPPASTDeleteExpression (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression)1