Search in sources :

Example 1 with HintType

use of php.runtime.common.HintType in project jphp by jphp-compiler.

the class FunctionGenerator method processArgument.

@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 SelfExprToken) {
        if (analyzer.getClazz() == null) {
            unexpectedToken(next);
        }
        next = analyzer.getClazz().getName();
    }
    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;
}
Also used : CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) HintType(php.runtime.common.HintType) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) ArgumentUnpackExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) AmpersandRefToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) ArgumentUnpackExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken) AmpersandRefToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken)

Example 2 with HintType

use of php.runtime.common.HintType in project jphp by jphp-compiler.

the class ParameterEntity method setType.

public void setType(String type) {
    HintType _type = HintType.of(type);
    this.typeChecker = _type == null ? null : TypeChecker.of(_type);
}
Also used : HintType(php.runtime.common.HintType)

Aggregations

HintType (php.runtime.common.HintType)2 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)1 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)1 Token (org.develnext.jphp.core.tokenizer.token.Token)1 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)1 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)1 AmpersandRefToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken)1 ArgumentUnpackExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken)1 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)1