/** Returns the implied object type, or <code>null</code>. */ public IType getImpliedObjectType() { if (astName == null) return null; IASTName name = astName; IASTNode nameParent = name.getParent(); while (nameParent instanceof IASTName) { name = (IASTName) nameParent; nameParent = name.getParent(); } final ASTNodeProperty prop = name.getPropertyInParent(); if (prop == CPPSemantics.STRING_LOOKUP_PROPERTY) { return null; } if (prop == IASTFieldReference.FIELD_NAME) { ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) nameParent; return fieldRef.getFieldOwnerType(); } if (prop == IASTIdExpression.ID_NAME) { IScope scope = CPPVisitor.getContainingScope(name); if (scope instanceof ICPPClassScope) { return ((ICPPClassScope) scope).getClassType(); } return CPPVisitor.getImpliedObjectType(scope); } return null; }
@Override public int getAdditionalNameFlags(int standardFlags, IASTName name) { if ((standardFlags & PDOMName.IS_REFERENCE) == PDOMName.IS_REFERENCE) { IASTNode parent = name.getParent(); if (parent instanceof ICPPASTQualifiedName) { // When taking the address of a method it will be called without suppressing // the virtual mechanism parent = parent.getParent(); if (parent instanceof IASTIdExpression) { parent = parent.getParent(); if (parent instanceof IASTUnaryExpression) { if (((IASTUnaryExpression) parent).getOperator() == IASTUnaryExpression.op_amper) return PDOMName.COULD_BE_POLYMORPHIC_METHOD_CALL; } } } else if (parent instanceof ICPPASTFieldReference) { // The name is not qualified ICPPASTFieldReference fr = (ICPPASTFieldReference) parent; parent = parent.getParent(); if (parent instanceof IASTFunctionCallExpression) { // v->member() if (fr.isPointerDereference()) { return PDOMName.COULD_BE_POLYMORPHIC_METHOD_CALL; } // v.member() IASTExpression fieldOwner = fr.getFieldOwner(); if (fieldOwner.getValueCategory().isGLValue()) { while (fieldOwner instanceof IASTUnaryExpression && ((IASTUnaryExpression) fieldOwner).getOperator() == IASTUnaryExpression.op_bracketedPrimary) fieldOwner = ((IASTUnaryExpression) fieldOwner).getOperand(); if (fieldOwner instanceof IASTIdExpression) { IBinding b = ((IASTIdExpression) fieldOwner).getName().resolveBinding(); if (b instanceof IVariable) { IType t = ((IVariable) b).getType(); if (!(t instanceof ICPPReferenceType)) { return 0; } } } return PDOMName.COULD_BE_POLYMORPHIC_METHOD_CALL; } } } else if (parent instanceof IASTIdExpression) { // Calling a member from within a member if (parent.getParent() instanceof IASTFunctionCallExpression) { return PDOMName.COULD_BE_POLYMORPHIC_METHOD_CALL; } } } return 0; }