Package com.google.dart.engine.ast

Examples of com.google.dart.engine.ast.Expression


    return null;
  }

  @Override
  public Void visitIfStatement(IfStatement node) {
    Expression condition = node.getCondition();
    safelyVisit(condition);
    Map<Element, Type> thenOverrides = null;
    Statement thenStatement = node.getThenStatement();
    if (thenStatement != null) {
      overrideManager.enterScope();
View Full Code Here


    return null;
  }

  @Override
  public Void visitWhileStatement(WhileStatement node) {
    Expression condition = node.getCondition();
    safelyVisit(condition);
    Statement body = node.getBody();
    if (body != null) {
      overrideManager.enterScope();
      try {
View Full Code Here

  protected void visitForEachStatementInScope(ForEachStatement node) {
    //
    // We visit the iterator before the loop variable because the loop variable cannot be in scope
    // while visiting the iterator.
    //
    Expression iterator = node.getIterator();
    safelyVisit(iterator);
    DeclaredIdentifier loopVariable = node.getLoopVariable();
    SimpleIdentifier identifier = node.getIdentifier();
    safelyVisit(loopVariable);
    safelyVisit(identifier);
View Full Code Here

   */
  private void promoteTypes(Expression condition) {
    if (condition instanceof BinaryExpression) {
      BinaryExpression binary = (BinaryExpression) condition;
      if (binary.getOperator().getType() == TokenType.AMPERSAND_AMPERSAND) {
        Expression left = binary.getLeftOperand();
        Expression right = binary.getRightOperand();
        promoteTypes(left);
        promoteTypes(right);
        clearTypePromotionsIfPotentiallyMutatedIn(right);
      }
    } else if (condition instanceof IsExpression) {
View Full Code Here

  public Void visitAssignmentExpression(AssignmentExpression node) {
    Token operator = node.getOperator();
    TokenType operatorType = operator.getType();
    if (operatorType != TokenType.EQ) {
      operatorType = operatorFromCompoundAssignment(operatorType);
      Expression leftHandSide = node.getLeftHandSide();
      if (leftHandSide != null) {
        String methodName = operatorType.getLexeme();

        Type staticType = getStaticType(leftHandSide);
        MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, methodName);
View Full Code Here

  @Override
  public Void visitBinaryExpression(BinaryExpression node) {
    Token operator = node.getOperator();
    if (operator.isUserDefinableOperator()) {
      Expression leftOperand = node.getLeftOperand();
      if (leftOperand != null) {
        String methodName = operator.getLexeme();

        Type staticType = getStaticType(leftOperand);
        MethodElement staticMethod = lookUpMethod(leftOperand, staticType, methodName);
View Full Code Here

  }

  @Override
  public Void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
    // TODO(brianwilkerson) Can we ever resolve the function being invoked?
    Expression expression = node.getFunction();
    if (expression instanceof FunctionExpression) {
      FunctionExpression functionExpression = (FunctionExpression) expression;
      ExecutableElement functionElement = functionExpression.getElement();
      ArgumentList argumentList = node.getArgumentList();
      ParameterElement[] parameters = resolveArgumentsToFunction(
View Full Code Here

    return null;
  }

  @Override
  public Void visitIndexExpression(IndexExpression node) {
    Expression target = node.getRealTarget();
    Type staticType = getStaticType(target);
    Type propagatedType = getPropagatedType(target);
    String getterMethodName = TokenType.INDEX.getLexeme();
    String setterMethodName = TokenType.INDEX_EQ.getLexeme();
    boolean isInGetterContext = node.inGetterContext();
View Full Code Here

    //
    // We have a method invocation of one of two forms: 'e.m(a1, ..., an)' or 'm(a1, ..., an)'. The
    // first step is to figure out which executable is being invoked, using both the static and the
    // propagated type information.
    //
    Expression target = node.getRealTarget();
    if (target instanceof SuperExpression && !isSuperInValidContext((SuperExpression) target)) {
      return null;
    }
    Element staticElement;
    Element propagatedElement;
    Type staticType = null;
    Type propagatedType = null;
    if (target == null) {
      staticElement = resolveInvokedElement(methodName);
      propagatedElement = null;
    } else if (methodName.getName().equals(FunctionElement.LOAD_LIBRARY_NAME)
        && isDeferredPrefix(target)) {
      LibraryElement importedLibrary = getImportedLibrary(target);
      methodName.setStaticElement(importedLibrary.getLoadLibraryFunction());
      return null;
    } else {
      staticType = getStaticType(target);
      propagatedType = getPropagatedType(target);
      //
      // If this method invocation is of the form 'C.m' where 'C' is a class, then we don't call
      // resolveInvokedElement(..) which walks up the class hierarchy, instead we just look for the
      // member in the type only.
      //
      ClassElementImpl typeReference = getTypeReference(target);
      if (typeReference != null) {
        staticElement = propagatedElement = resolveElement(typeReference, methodName);
      } else {
        staticElement = resolveInvokedElementWithTarget(target, staticType, methodName);
        propagatedElement = resolveInvokedElementWithTarget(target, propagatedType, methodName);
      }
    }
    staticElement = convertSetterToGetter(staticElement);
    propagatedElement = convertSetterToGetter(propagatedElement);
    //
    // Record the results.
    //
    methodName.setStaticElement(staticElement);
    methodName.setPropagatedElement(propagatedElement);
    ArgumentList argumentList = node.getArgumentList();
    if (staticElement != null) {
      ParameterElement[] parameters = computeCorrespondingParameters(argumentList, staticElement);
      if (parameters != null) {
        argumentList.setCorrespondingStaticParameters(parameters);
      }
    }
    if (propagatedElement != null) {
      ParameterElement[] parameters = computeCorrespondingParameters(
          argumentList,
          propagatedElement);
      if (parameters != null) {
        argumentList.setCorrespondingPropagatedParameters(parameters);
      }
    }
    //
    // Then check for error conditions.
    //
    ErrorCode errorCode = checkForInvocationError(target, true, staticElement);
    boolean generatedWithTypePropagation = false;
    if (enableHints && errorCode == null && staticElement == null) {
      // The method lookup may have failed because there were multiple
      // incompatible choices. In this case we don't want to generate a hint.
      if (propagatedElement == null && propagatedType instanceof UnionType) {
        // TODO(collinsn): an improvement here is to make the propagated type of the method call
        // the union of the propagated types of all possible calls.
        if (lookupMethods(target, (UnionType) propagatedType, methodName.getName()).size() > 1) {
          return null;
        }
      }

      errorCode = checkForInvocationError(target, false, propagatedElement);
      if (errorCode == StaticTypeWarningCode.UNDEFINED_METHOD) {
        ClassElement classElementContext = null;
        if (target == null) {
          classElementContext = resolver.getEnclosingClass();
        } else {
          Type type = target.getBestType();
          if (type != null) {
            if (type.getElement() instanceof ClassElement) {
              classElementContext = (ClassElement) type.getElement();
            }
          }
View Full Code Here

    return null;
  }

  @Override
  public Void visitPostfixExpression(PostfixExpression node) {
    Expression operand = node.getOperand();
    String methodName = getPostfixOperator(node);

    Type staticType = getStaticType(operand);
    MethodElement staticMethod = lookUpMethod(operand, staticType, methodName);
    node.setStaticElement(staticMethod);
View Full Code Here

TOP

Related Classes of com.google.dart.engine.ast.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.