コード例 #1
0
  /**
   * Set the type of the given node to be the least upper bound type of the types of the node's
   * children.
   *
   * @param node The specified node.
   * @exception IllegalActionException If an inference error occurs.
   */
  public void visitProductNode(ASTPtProductNode node) throws IllegalActionException {
    Type[] childTypes = _inferAllChildren(node);

    List lexicalTokenList = node.getLexicalTokenList();
    int numChildren = node.jjtGetNumChildren();

    Type resultType = childTypes[0];
    for (int i = 1; i < numChildren; i++) {
      Token operator = (Token) lexicalTokenList.get(i - 1);
      Type nextType = childTypes[i];
      if (operator.kind == PtParserConstants.MULTIPLY) {
        resultType = resultType.multiply(nextType);
      } else if (operator.kind == PtParserConstants.DIVIDE) {
        resultType = resultType.divide(nextType);
      } else if (operator.kind == PtParserConstants.MODULO) {
        resultType = resultType.modulo(nextType);
      } else {
        _assert(false, node, "Invalid operation");
      }
    }
    _setType(node, resultType);
  }