Ejemplo n.º 1
0
 @Override
 public IType getExpressionType() {
   switch (getKind()) {
     case lk_this:
       {
         IScope scope = CPPVisitor.getContainingScope(this);
         IType type = CPPVisitor.getImpliedObjectType(scope);
         if (type == null) {
           return new ProblemType(ISemanticProblem.TYPE_UNRESOLVED_NAME);
         }
         return new CPPPointerType(type);
       }
     case lk_true:
     case lk_false:
       return CPPBasicType.BOOLEAN;
     case lk_char_constant:
       return new CPPBasicType(getCharType(), 0, this);
     case lk_float_constant:
       return classifyTypeOfFloatLiteral();
     case lk_integer_constant:
       return classifyTypeOfIntLiteral();
     case lk_string_literal:
       IType type = new CPPBasicType(getCharType(), 0, this);
       type = new CPPQualifierType(type, true, false);
       return new CPPArrayType(type, getStringLiteralSize());
   }
   return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
 }
Ejemplo n.º 2
0
  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;
  }
Ejemplo n.º 3
0
 private IType[] getParameterTypes() {
   ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator();
   if (lambdaDtor != null) {
     return CPPVisitor.createParameterTypes(lambdaDtor);
   }
   return IType.EMPTY_TYPE_ARRAY;
 }
Ejemplo n.º 4
0
 private IType getReturnType() {
   ICPPASTFunctionDeclarator lambdaDtor = fLambdaExpression.getDeclarator();
   if (lambdaDtor != null) {
     IASTTypeId trailingReturnType = lambdaDtor.getTrailingReturnType();
     if (trailingReturnType != null) {
       return CPPVisitor.createType(trailingReturnType);
     }
   }
   IASTCompoundStatement body = fLambdaExpression.getBody();
   if (body != null) {
     IASTStatement[] stmts = body.getStatements();
     if (stmts.length > 0) {
       // Gnu extension allows to deduce return type in complex compound statements
       IASTStatement stmt = stmts[stmts.length - 1];
       if (stmt instanceof IASTReturnStatement) {
         IASTReturnStatement rtstmt = (IASTReturnStatement) stmt;
         IASTExpression expr = rtstmt.getReturnValue();
         if (expr != null) {
           IType type = expr.getExpressionType();
           type = Conversions.lvalue_to_rvalue(type, false);
           if (type != null) {
             return type;
           }
         }
       }
     }
   }
   return CPPSemantics.VOID_TYPE;
 }
 @Override
 public ICPPEvaluation getEvaluation() {
   if (fEvaluation == null) {
     if (fOperand1 == null || fOperand2 == null) {
       fEvaluation = EvalFixed.INCOMPLETE;
     } else {
       IType t1 = CPPVisitor.createType(fOperand1);
       IType t2 = CPPVisitor.createType(fOperand2);
       if (t1 == null || t2 == null) {
         fEvaluation = EvalFixed.INCOMPLETE;
       } else {
         fEvaluation = new EvalBinaryTypeId(fOperator, t1, t2, this);
       }
     }
   }
   return fEvaluation;
 }
Ejemplo n.º 6
0
  @Override
  public int getRoleForName(IASTName n) {
    // 3.1.2
    IASTNode parent = ASTQueries.findOutermostDeclarator(this).getParent();
    if (parent instanceof IASTDeclaration) {
      // a declaration is a definition unless ...
      if (parent instanceof IASTFunctionDefinition) return r_definition;

      if (parent instanceof IASTSimpleDeclaration) {
        final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) parent;

        // unless it declares a function without body
        if (this instanceof IASTFunctionDeclarator) {
          return r_declaration;
        }

        final int storage = sdecl.getDeclSpecifier().getStorageClass();
        // unless it contains the extern specifier or a linkage-specification and neither
        // initializer nor function-body
        if (getInitializer() == null
            && (storage == IASTDeclSpecifier.sc_extern || isSimpleLinkageSpec(sdecl))) {
          return r_declaration;
        }
        // unless it declares a static data member in a class declaration
        if (storage == IASTDeclSpecifier.sc_static
            && CPPVisitor.getContainingScope(parent) instanceof ICPPClassScope) {
          return r_declaration;
        }
        // unless it is a class name declaration: no declarator in this case
        // unless it is a typedef declaration
        if (storage == IASTDeclSpecifier.sc_typedef)
          return r_definition; // should actually be a declaration

        // unless it is a using-declaration or using-directive: no declarator in this case
      }

      // all other cases
      return r_definition;
    }

    if (parent instanceof IASTTypeId) return r_reference;

    if (parent instanceof IASTParameterDeclaration)
      return (n.getLookupKey().length > 0) ? r_definition : r_declaration;

    return r_unclear;
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
 @Override
 public IBinding getOwner() {
   return CPPVisitor.findDeclarationOwner(fLambdaExpression, true);
 }
Ejemplo n.º 9
0
 @Override
 public char[][] getQualifiedNameCharArray() {
   return CPPVisitor.getQualifiedNameCharArray(this);
 }
Ejemplo n.º 10
0
 @Override
 public String[] getQualifiedName() {
   return CPPVisitor.getQualifiedName(this);
 }
Ejemplo n.º 11
0
 @Override
 public IScope getScope() {
   return CPPVisitor.getContainingScope(fLambdaExpression);
 }
 @Override
 public IScope getScope() {
   return CPPVisitor.getContainingScope(getASTName());
 }