コード例 #1
0
ファイル: FunctionGenerator.java プロジェクト: lzpfmh/jphp
  @SuppressWarnings("unchecked")
  protected ArgumentStmtToken processArgument(ListIterator<Token> iterator) {
    boolean isReference = false;
    boolean isVariadic = false;

    VariableExprToken variable = null;
    ExprStmtToken value = null;

    Token next = nextToken(iterator);
    if (next instanceof CommaToken || isClosedBrace(next, BraceExprToken.Kind.SIMPLE)) return null;

    NameToken hintTypeClass = null;
    HintType hintType = null;

    if (next instanceof NameToken) {
      String word = ((NameToken) next).getName().toLowerCase();
      if (scalarTypeHints.contains(word)) hintType = HintType.of(word);
      else {
        hintType = jphp_scalarTypeHints.contains(word) ? null : HintType.of(word);

        if (hintType == null) hintTypeClass = analyzer.getRealName((NameToken) next);
      }

      next = nextToken(iterator);
    }

    if (next instanceof AmpersandRefToken) {
      isReference = true;
      next = nextToken(iterator);
    }

    if (next instanceof ArgumentUnpackExprToken) {
      isVariadic = true;
      next = nextToken(iterator);
    }

    if (next instanceof VariableExprToken) {
      variable = (VariableExprToken) next;
    } else unexpectedToken(next);

    next = nextToken(iterator);
    if (next instanceof AssignExprToken) {
      if (isVariadic) {
        unexpectedToken(next);
      }

      value =
          analyzer
              .generator(SimpleExprGenerator.class)
              .getToken(nextToken(iterator), iterator, true, BraceExprToken.Kind.SIMPLE);
    } else {
      if (next instanceof CommaToken || isClosedBrace(next, BraceExprToken.Kind.SIMPLE)) {
        if (next instanceof BraceExprToken) {
          iterator.previous();
        } else {
          if (isVariadic) {
            unexpectedToken(next);
          }
        }
      } else unexpectedToken(next);
    }

    ArgumentStmtToken argument = new ArgumentStmtToken(variable.getMeta());
    argument.setName(variable);
    argument.setHintType(hintType);
    argument.setHintTypeClass(hintTypeClass);
    argument.setReference(isReference);
    argument.setVariadic(isVariadic);
    argument.setValue(value);

    if (argument.isReference() && argument.getValue() != null)
      analyzer.getFunction().variable(argument.getName()).setUsed(true);

    return argument;
  }