@Override
  public boolean isSameType(IType type) {
    if (type instanceof ITypedef) {
      return type.isSameType(this);
    }

    if (type instanceof PDOMNode) {
      PDOMNode node = (PDOMNode) type;
      if (node.getPDOM() == getPDOM()) {
        return node.getRecord() == getRecord();
      }
    }

    if (type instanceof IEnumeration) {
      IEnumeration etype = (IEnumeration) type;
      char[] nchars = etype.getNameCharArray();
      if (nchars.length == 0) {
        nchars = ASTTypeUtil.createNameForAnonymous(etype);
      }
      if (nchars == null || !CharArrayUtils.equals(nchars, getNameCharArray())) return false;

      return SemanticUtil.haveSameOwner(this, etype);
    }
    return false;
  }
  private Collection<IBinding> cppRemoveSecondaryBindings(
      Set<IBinding> primaryBindings, IASTName sourceName) {
    List<IBinding> result = new ArrayList<IBinding>();
    String[] sourceQualifiedName = null;
    int funcArgCount = -1;
    if (sourceName != null) {
      final IBinding binding = sourceName.resolveBinding();
      if (binding != null) {
        sourceQualifiedName = CPPVisitor.getQualifiedName(binding);
        if (binding instanceof ICPPUnknownBinding) {
          LookupData data = CPPSemantics.createLookupData(sourceName);
          if (data.isFunctionCall()) {
            funcArgCount = data.getFunctionArgumentCount();
          }
        }
      }
    }

    for (Iterator<IBinding> iterator = primaryBindings.iterator(); iterator.hasNext(); ) {
      IBinding binding = iterator.next();
      if (sourceQualifiedName != null) {
        String[] qualifiedName = CPPVisitor.getQualifiedName(binding);
        if (!Arrays.equals(qualifiedName, sourceQualifiedName)) {
          iterator.remove();
          continue;
        }
      }
      if (funcArgCount != -1) {
        // For c++ we can check the number of parameters.
        if (binding instanceof ICPPFunction) {
          ICPPFunction f = (ICPPFunction) binding;
          if (f.getRequiredArgumentCount() > funcArgCount) {
            iterator.remove();
            result.add(binding);
            continue;
          }
          if (!f.takesVarArgs() && !f.hasParameterPack()) {
            final IType[] parameterTypes = f.getType().getParameterTypes();
            int maxArgs = parameterTypes.length;
            if (maxArgs == 1 && SemanticUtil.isVoidType(parameterTypes[0])) {
              maxArgs = 0;
            }
            if (maxArgs < funcArgCount) {
              iterator.remove();
              result.add(binding);
              continue;
            }
          }
        }
      }
    }

    return result;
  }
Esempio n. 3
0
  private IType computeType(IASTNode point) {
    if (isTypeDependent()) return new TypeOfDependentExpression(this);

    ICPPFunction overload = getOverload(point);
    if (overload != null) return ExpressionTypes.typeFromFunctionCall(overload);

    switch (fOperator) {
      case op_sizeof:
      case op_sizeofParameterPack:
        return CPPVisitor.get_SIZE_T(point);
      case op_typeid:
        return CPPVisitor.get_type_info(point);
      case op_throw:
        return CPPSemantics.VOID_TYPE;
      case op_amper:
        if (fAddressOfQualifiedNameBinding instanceof ICPPMember) {
          ICPPMember member = (ICPPMember) fAddressOfQualifiedNameBinding;
          if (!member.isStatic()) {
            try {
              return new CPPPointerToMemberType(
                  member.getType(), member.getClassOwner(), false, false, false);
            } catch (DOMException e) {
              return e.getProblem();
            }
          }
        }
        return new CPPPointerType(fArgument.getTypeOrFunctionSet(point));
      case op_star:
        IType type = fArgument.getTypeOrFunctionSet(point);
        type = prvalueTypeWithResolvedTypedefs(type);
        if (type instanceof IPointerType) {
          return glvalueType(((IPointerType) type).getType());
        }
        if (type instanceof ISemanticProblem) {
          return type;
        }
        return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
      case op_noexcept:
      case op_not:
        return CPPBasicType.BOOLEAN;
      case op_postFixDecr:
      case op_postFixIncr:
        return prvalueType(fArgument.getTypeOrFunctionSet(point));
      case op_minus:
      case op_plus:
      case op_tilde:
        final IType t1 = prvalueType(fArgument.getTypeOrFunctionSet(point));
        final IType t2 = SemanticUtil.getNestedType(t1, TDEF);
        final IType t3 = CPPArithmeticConversion.promoteCppType(t2);
        return (t3 == null || t3 == t2) ? t1 : t3;
    }
    return fArgument.getTypeOrFunctionSet(point);
  }
 /** Constructs a string in the format: (paramName1,paramName2,...) */
 private static String getFunctionParameterString(IFunctionType functionType) throws DOMException {
   IType[] types = functionType.getParameterTypes();
   if (types.length == 1 && SemanticUtil.isVoidType(types[0])) {
     types = new IType[0];
   }
   StringBuilder result = new StringBuilder();
   result.append('(');
   for (int i = 0; i < types.length; i++) {
     if (i > 0) {
       result.append(',');
     }
     ASTTypeUtil.appendType(types[i], true, result);
   }
   if (functionType instanceof ICPPFunctionType
       && ((ICPPFunctionType) functionType).takesVarArgs()) {
     if (types.length != 0) {
       result.append(',');
     }
     result.append("..."); // $NON-NLS-1$
   }
   result.append(')');
   return result.toString();
 }
Esempio n. 5
0
  private ICPPFunction computeOverload(IASTNode point) {
    OverloadableOperator op = OverloadableOperator.fromUnaryExpression(fOperator);
    if (op == null) return null;

    if (fArgument.isTypeDependent()) return null;

    if (fAddressOfQualifiedNameBinding instanceof ICPPMember) {
      ICPPMember member = (ICPPMember) fAddressOfQualifiedNameBinding;
      if (!member.isStatic()) return null;
    }

    IType type = fArgument.getTypeOrFunctionSet(point);
    type = SemanticUtil.getNestedType(type, TDEF | REF | CVTYPE);
    if (!CPPSemantics.isUserDefined(type)) return null;

    ICPPEvaluation[] args;
    if (fOperator == op_postFixDecr || fOperator == op_postFixIncr) {
      args = new ICPPEvaluation[] {fArgument, ZERO_EVAL};
    } else {
      args = new ICPPEvaluation[] {fArgument};
    }
    return CPPSemantics.findOverloadedOperator(point, args, type, op, LookupMode.LIMITED_GLOBALS);
  }
Esempio n. 6
0
  private ICPPMethod[] createMethods() {
    boolean needConversionOperator =
        fLambdaExpression.getCaptureDefault() == CaptureDefault.UNSPECIFIED
            && fLambdaExpression.getCaptures().length == 0;

    final ICPPClassScope scope = getCompositeScope();
    ICPPMethod[] result = new ICPPMethod[needConversionOperator ? 6 : 5];

    // Deleted default constructor: A()
    CPPImplicitConstructor ctor =
        new CPPImplicitConstructor(
            scope, CharArrayUtils.EMPTY, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY);
    ctor.setDeleted(true);
    result[0] = ctor;

    // Copy constructor: A(const A &)
    IType pType = new CPPReferenceType(SemanticUtil.constQualify(this), false);
    ICPPParameter[] ps = new ICPPParameter[] {new CPPParameter(pType, 0)};
    ctor = new CPPImplicitConstructor(scope, CharArrayUtils.EMPTY, ps);
    result[1] = ctor;

    // Deleted copy assignment operator: A& operator = (const A &)
    IType refType = new CPPReferenceType(this, false);
    ICPPFunctionType ft = CPPVisitor.createImplicitFunctionType(refType, ps, false, false);
    ICPPMethod m = new CPPImplicitMethod(scope, OverloadableOperator.ASSIGN.toCharArray(), ft, ps);
    result[2] = m;

    // Destructor: ~A()
    ft =
        CPPVisitor.createImplicitFunctionType(
            NO_RETURN_TYPE, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY, false, false);
    m = new CPPImplicitMethod(scope, new char[] {'~'}, ft, ICPPParameter.EMPTY_CPPPARAMETER_ARRAY);
    result[3] = m;

    // Function call operator
    final IType returnType = getReturnType();
    final IType[] parameterTypes = getParameterTypes();
    ft = new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false);

    ICPPParameter[] params = new ICPPParameter[parameterTypes.length];
    for (int i = 0; i < params.length; i++) {
      params[i] = new CPPParameter(parameterTypes[i], i);
    }
    m =
        new CPPImplicitMethod(scope, OverloadableOperator.PAREN.toCharArray(), ft, params) {
          @Override
          public boolean isImplicit() {
            return false;
          }
        };
    result[4] = m;

    // Conversion operator
    if (needConversionOperator) {
      final CPPFunctionType conversionTarget = new CPPFunctionType(returnType, parameterTypes);
      ft = new CPPFunctionType(conversionTarget, IType.EMPTY_TYPE_ARRAY, true, false, false);
      m =
          new CPPImplicitMethod(
              scope, CPPASTConversionName.createName(conversionTarget, null), ft, params);
      result[5] = m;
    }
    return result;
  }
Esempio n. 7
0
 @Override
 public long getMaxValue() {
   return SemanticUtil.computeMaxValue(this);
 }
 @Override
 public boolean acceptBinding(IBinding binding) throws CoreException {
   return binding instanceof ICPPMethod
       && SemanticUtil.isConversionOperator(((ICPPMethod) binding))
       && super.acceptBinding(binding);
 }