Search in sources :

Example 1 with Modifier

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

the class ClassGenerator method processBlock.

protected void processBlock(ClassStmtToken result, NameToken firstTraitName, ListIterator<Token> iterator) {
    if (result.isInterface())
        unexpectedToken(iterator.previous());
    while (true) {
        NameToken className = nextAndExpectedSensitive(iterator, NameToken.class);
        NameToken methodName;
        Token token = nextToken(iterator);
        if (token instanceof StaticAccessExprToken) {
            className = analyzer.getRealName(className);
            Token nextTokenSensitive = nextTokenSensitive(iterator);
            if (nextTokenSensitive instanceof NameToken) {
                methodName = (NameToken) nextTokenSensitive;
            } else {
                unexpectedToken(nextTokenSensitive);
                return;
            }
        } else {
            iterator.previous();
            methodName = className;
            if (className.getClass() != NameToken.class)
                unexpectedToken(className);
            className = firstTraitName;
        }
        Token what = nextToken(iterator);
        if (what instanceof AsStmtToken) {
            Token one = nextTokenSensitive(iterator, PrivateStmtToken.class, ProtectedStmtToken.class, PublicStmtToken.class, FinalStmtToken.class, StaticExprToken.class);
            if (one instanceof NameToken) {
                result.addAlias(className.getName(), methodName.getName(), null, ((NameToken) one).getName());
            } else if (isTokenClass(one, PrivateStmtToken.class, ProtectedStmtToken.class, PublicStmtToken.class)) {
                Modifier modifier = Modifier.PRIVATE;
                if (one instanceof ProtectedStmtToken)
                    modifier = Modifier.PROTECTED;
                else if (one instanceof PublicStmtToken)
                    modifier = Modifier.PUBLIC;
                token = nextTokenSensitive(iterator);
                String name = null;
                if (token instanceof NameToken) {
                    NameToken two = (NameToken) token;
                    if (two.getClass() != NameToken.class)
                        unexpectedToken(two);
                    name = two.getName();
                } else if (token instanceof SemicolonToken) {
                    iterator.previous();
                // nop
                } else
                    unexpectedToken(token);
                result.addAlias(className.getName(), methodName.getName(), modifier, name);
            } else
                unexpectedToken(one);
            nextAndExpected(iterator, SemicolonToken.class);
        } else if (what instanceof InsteadofStmtToken) {
            Set<String> names = new HashSet<String>();
            Set<String> namesLower = new HashSet<String>();
            NameToken cls;
            while (true) {
                cls = nextAndExpected(iterator, NameToken.class);
                cls = analyzer.getRealName(cls);
                if (!namesLower.add(cls.getName().toLowerCase())) {
                    analyzer.getEnvironment().error(iterator.previous().toTraceInfo(analyzer.getContext()), ErrorType.E_ERROR, Messages.ERR_TRAIT_MULTIPLE_RULE, methodName.getName(), cls.getName());
                }
                names.add(cls.getName());
                Token next = nextToken(iterator);
                if (next instanceof CommaToken)
                    continue;
                if (next instanceof SemicolonToken)
                    break;
            }
            if (!result.addReplacement(className.getName(), methodName.getName(), names)) {
                analyzer.getEnvironment().error(iterator.previous().toTraceInfo(analyzer.getContext()), ErrorType.E_ERROR, Messages.ERR_TRAIT_MULTIPLE_RULE, methodName.getName(), cls.getName());
            }
        } else
            unexpectedToken(what);
        if (isClosedBrace(nextTokenAndPrev(iterator), BraceExprToken.Kind.BLOCK)) {
            iterator.next();
            break;
        }
    }
}
Also used : CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) 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) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) Modifier(php.runtime.common.Modifier)

Example 2 with Modifier

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

the class VarDump method printObject.

@Override
protected void printObject(ObjectMemory value, int level, Set<Integer> used) {
    ClassEntity classEntity = value.getReflection();
    if (used.contains(value.getPointer())) {
        printer.write("*RECURSION*\n");
    } else {
        ArrayMemory arr;
        if (classEntity.methodMagicDebugInfo != null) {
            try {
                Memory tmp = env.invokeMethod(value.value, classEntity.methodMagicDebugInfo.getName());
                if (tmp.isArray()) {
                    arr = tmp.toValue(ArrayMemory.class);
                } else {
                    arr = new ArrayMemory();
                }
            } catch (RuntimeException e) {
                throw e;
            } catch (Throwable throwable) {
                throw new RuntimeException(throwable);
            }
        } else
            arr = value.getProperties();
        printer.write("object(");
        printer.write(classEntity.getName());
        printer.write(")#" + value.getPointer());
        printer.write(" (" + arr.size() + ") {\n");
        level += 1;
        used.add(value.getPointer());
        if (classEntity.methodMagicDebugInfo == null) {
            for (PropertyEntity entity : classEntity.getProperties()) {
                if (entity.getGetter() != null && !entity.isHiddenInDebugInfo()) {
                    printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                    printer.write("[\"");
                    printer.write(entity.getName());
                    printer.write('"');
                    printer.write(":getter]=>\n");
                    printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                    try {
                        print(entity.getValue(env, TraceInfo.UNKNOWN, value.value), level, used);
                    } catch (RuntimeException e) {
                        throw e;
                    } catch (Throwable throwable) {
                        throw new RuntimeException(throwable);
                    }
                }
            }
        }
        ForeachIterator iterator = arr.foreachIterator(false, false);
        while (iterator.next()) {
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            Memory key = iterator.getMemoryKey();
            printer.write('[');
            if (key.isString()) {
                String realKey = key.toString();
                int pos;
                Modifier modifier = Modifier.PUBLIC;
                String className = "";
                if ((pos = realKey.lastIndexOf("\0")) > -1) {
                    if (realKey.startsWith("\0*\0")) {
                        modifier = Modifier.PROTECTED;
                    } else {
                        modifier = Modifier.PRIVATE;
                        className = realKey.substring(1, pos);
                    }
                    realKey = realKey.substring(pos + 1);
                }
                printer.write('"');
                printer.write(realKey);
                printer.write('"');
                switch(modifier) {
                    case PRIVATE:
                        printer.write(":\"" + className + "\":private");
                        break;
                    case PROTECTED:
                        printer.write(":protected");
                }
            } else {
                printer.write(key.toString());
            }
            printer.write("]=>\n");
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            print(iterator.getValue(), level, used);
        //printer.write('\n');
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        printer.write("}\n");
        used.remove(value.getPointer());
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ForeachIterator(php.runtime.lang.ForeachIterator) PropertyEntity(php.runtime.reflection.PropertyEntity) Memory(php.runtime.Memory) Modifier(php.runtime.common.Modifier)

Example 3 with Modifier

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

the class ClassGenerator method processProperty.

protected List<ClassVarStmtToken> processProperty(ClassStmtToken clazz, VariableExprToken current, List<Token> modifiers, ListIterator<Token> iterator) {
    Token next = current;
    Token prev = null;
    Set<VariableExprToken> variables = new LinkedHashSet<VariableExprToken>();
    List<ExprStmtToken> initValues = new ArrayList<>();
    ExprStmtToken initValue = null;
    List<ClassVarStmtToken> result = new ArrayList<ClassVarStmtToken>();
    Modifier modifier = Modifier.PUBLIC;
    boolean isStatic = false;
    for (Token token : modifiers) {
        if (token instanceof PrivateStmtToken)
            modifier = Modifier.PRIVATE;
        else if (token instanceof ProtectedStmtToken)
            modifier = Modifier.PROTECTED;
        else if (token instanceof StaticExprToken)
            isStatic = true;
    }
    do {
        if (next instanceof VariableExprToken) {
            if (!variables.add((VariableExprToken) next)) {
                throw new ParseException(Messages.ERR_IDENTIFIER_X_ALREADY_USED.fetch(next.getWord()), next.toTraceInfo(analyzer.getContext()));
            }
            initValues.add(null);
        } else if (next instanceof CommaToken) {
            if (!(prev instanceof VariableExprToken))
                unexpectedToken(next);
        } else if (next instanceof AssignExprToken) {
            if (!(prev instanceof VariableExprToken))
                unexpectedToken(next);
            initValue = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, Separator.COMMA_OR_SEMICOLON, null);
            initValues.set(initValues.size() - 1, initValue);
            if (iterator.hasPrevious() && isBreak(iterator.previous())) {
                iterator.next();
                break;
            }
            if (iterator.hasNext()) {
                iterator.next();
            }
        //break;
        } else if (next instanceof SemicolonToken) {
            if (!(prev instanceof VariableExprToken))
                unexpectedToken(next);
            break;
        }
        prev = next;
        next = nextToken(iterator);
    } while (true);
    int i = 0;
    for (VariableExprToken variable : variables) {
        ClassVarStmtToken classVar = new ClassVarStmtToken(variable.getMeta());
        classVar.setModifier(modifier);
        classVar.setStatic(isStatic);
        classVar.setValue(initValues.get(i));
        classVar.setVariable(variable);
        classVar.setClazz(clazz);
        result.add(classVar);
        i++;
    }
    return result;
}
Also used : CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) 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) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) ParseException(php.runtime.exceptions.ParseException) Modifier(php.runtime.common.Modifier)

Example 4 with Modifier

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

the class ConstantDumper method load.

@Override
public ConstantEntity load(InputStream input) throws IOException {
    DumpInputStream dump = new DumpInputStream(input);
    boolean cs = dump.readBoolean();
    Modifier modifier = dump.readModifier();
    String name = dump.readName();
    TraceInfo trace = dump.readTrace(context);
    Memory value = dump.readMemory();
    ConstantEntity entity = new ConstantEntity(name, value, cs);
    entity.setContext(context);
    entity.setTrace(trace);
    dump.readRawData();
    return entity;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) Memory(php.runtime.Memory) TraceInfo(php.runtime.env.TraceInfo) Modifier(php.runtime.common.Modifier) ConstantEntity(php.runtime.reflection.ConstantEntity)

Example 5 with Modifier

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

the class PrintR method printObject.

@Override
protected void printObject(ObjectMemory value, int level, Set<Integer> used) {
    ClassEntity classEntity = value.getReflection();
    writeObjectHeader(classEntity.getName());
    if (used.contains(value.getPointer())) {
        printer.write(" *RECURSION*");
    } else {
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        writeOpen();
        level += 1;
        used.add(value.getPointer());
        ArrayMemory props;
        if (env != null && classEntity.methodMagicDebugInfo != null) {
            try {
                Memory tmp = env.invokeMethod(value.value, classEntity.methodMagicDebugInfo.getName());
                if (tmp.isArray()) {
                    props = tmp.toValue(ArrayMemory.class);
                } else {
                    props = new ArrayMemory();
                }
            } catch (RuntimeException e) {
                throw e;
            } catch (Throwable throwable) {
                throw new RuntimeException(throwable);
            }
        } else {
            props = value.getProperties();
        }
        if (classEntity.methodMagicDebugInfo != null) {
            for (PropertyEntity entity : classEntity.getProperties()) {
                if (entity.getGetter() != null && !entity.isHiddenInDebugInfo()) {
                    printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                    printer.write("[");
                    printer.write(entity.getName());
                    printer.write(":getter] => ");
                    try {
                        print(entity.getValue(env, TraceInfo.UNKNOWN, value.value));
                    } catch (RuntimeException e) {
                        throw e;
                    } catch (Throwable throwable) {
                        throw new RuntimeException(throwable);
                    }
                    writeSeparator(false);
                }
            }
        }
        if (props != null) {
            ForeachIterator iterator = props.foreachIterator(false, false);
            int i = 0;
            int size = classEntity.properties.size();
            while (iterator.next()) {
                printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                Object key = iterator.getKey();
                printer.write('[');
                String realKey = key.toString();
                int pos;
                Modifier modifier = Modifier.PUBLIC;
                String className = "";
                if ((pos = realKey.lastIndexOf("\0")) > -1) {
                    if (realKey.startsWith("\0*\0")) {
                        modifier = Modifier.PROTECTED;
                    } else {
                        modifier = Modifier.PRIVATE;
                        className = realKey.substring(1, pos);
                    }
                    realKey = realKey.substring(pos + 1);
                }
                printer.write(realKey);
                switch(modifier) {
                    case PRIVATE:
                        printer.write(":" + className + ":private");
                        break;
                    case PROTECTED:
                        printer.write(":protected");
                }
                printer.write("] => ");
                print(iterator.getValue(), level + 1, used);
                writeSeparator(i == size - 1);
                i++;
            }
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        writeClose();
        used.remove(value.getPointer());
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ForeachIterator(php.runtime.lang.ForeachIterator) PropertyEntity(php.runtime.reflection.PropertyEntity) Memory(php.runtime.Memory) Modifier(php.runtime.common.Modifier)

Aggregations

Modifier (php.runtime.common.Modifier)5 Memory (php.runtime.Memory)3 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)2 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)2 Token (org.develnext.jphp.core.tokenizer.token.Token)2 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)2 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)2 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)2 ForeachIterator (php.runtime.lang.ForeachIterator)2 ClassEntity (php.runtime.reflection.ClassEntity)2 PropertyEntity (php.runtime.reflection.PropertyEntity)2 TraceInfo (php.runtime.env.TraceInfo)1 ParseException (php.runtime.exceptions.ParseException)1 DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)1 ConstantEntity (php.runtime.reflection.ConstantEntity)1