env.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 3,016 行 · 第 1/5 页
JAVA
3,016 行
*/ public final Value []setFunctionArgsNoCopy(Value []args) { Value []oldArgs = _functionArgs; for (int i = 0; args != null && i < args.length; i++) args[i] = args[i].toValue(); _functionArgs = args; return oldArgs; } /** * Pushes a new environment. */ public final void restoreFunctionArgs(Value []args) { _functionArgs = args; } /** * Returns the function args. */ public final Value []getFunctionArgs() { return _functionArgs; } /** * Removes a specialValue */ public Object removeSpecialValue(String name) { return _specialMap.remove(name); } /** * Returns a constant. */ public Value getConstant(String name) { Value value = getConstantImpl(name); if (value != null) return value; /* XXX: notice(L.l("Converting undefined constant '{0}' to string.", name)); */ value = createString(name); return value; } /** * Returns true if the constant is defined. */ public boolean isDefined(String name) { return getConstantImpl(name) != null; } /** * Returns a constant. */ private Value getConstantImpl(String name) { Value value = _constMap.get(name); if (value != null) return value; value = _quercus.getConstant(name); if (value != null) return value; if (_lowerConstMap != null) { value = _lowerConstMap.get(name.toLowerCase()); if (value != null) return value; } return null; } /** * Removes a constant. */ public Value removeConstant(String name) { return _constMap.remove(name); } /** * Sets a constant. */ public Value addConstant(String name, Value value, boolean isCaseInsensitive) { Value oldValue = _constMap.get(name); if (oldValue != null) return oldValue; _constMap.put(name, value); if (_lowerConstMap != null && isCaseInsensitive) _lowerConstMap.put(name.toLowerCase(), value); return value; } /** * Returns an array of the defined functions. */ public ArrayValue getDefinedConstants() { ArrayValue result = new ArrayValueImpl(); for (Map.Entry<String, Value> entry : _quercus.getConstMap().entrySet()) { result.put(createString(entry.getKey()), entry.getValue()); } for (Map.Entry<String, Value> entry : _constMap.entrySet()) { result.put(createString(entry.getKey()), entry.getValue()); } return result; } /** * Returns true if an extension is loaded. */ public boolean isExtensionLoaded(String name) { return getQuercus().isExtensionLoaded(name); } /** * Returns true if an extension is loaded. */ public HashSet<String> getLoadedExtensions() { return getQuercus().getLoadedExtensions(); } /** * Returns true if an extension is loaded. */ public Value getExtensionFuncs(String name) { return getQuercus().getExtensionFuncs(name); } /** * Returns the default stream resource. */ public StreamContextResource getDefaultStreamContext() { if (_defaultStreamContext == null) _defaultStreamContext = new StreamContextResource(); return _defaultStreamContext; } public ArrayValue getDefinedFunctions() { ArrayValueImpl funs = new ArrayValueImpl(); ArrayValueImpl system = new ArrayValueImpl(); ArrayValueImpl user = new ArrayValueImpl(); AbstractFunction []systemFuns = _quercus.getFunctionMap(); AbstractFunction []envFuns = _fun; for (int i = 0; i < envFuns.length; i++) { if (i < systemFuns.length && systemFuns[i] != null && ! (systemFuns[i] instanceof UndefinedFunction)) { system.append(createString(systemFuns[i].getName())); } else if (envFuns[i] != null && ! (envFuns[i] instanceof UndefinedFunction)) { user.append(createString(envFuns[i].getName())); } } funs.append(createString("internal"), system); funs.append(createString("user"), user); return funs; } /** * Returns the function with a given name. * * Compiled mode normally uses the _fun array directly, so this call * is rare. */ public AbstractFunction findFunction(String name) { int id = _quercus.findFunctionId(name); if (id >= 0) { if (id < _fun.length && ! (_fun[id] instanceof UndefinedFunction)) return _fun[id]; else return null; } AbstractFunction fun = _quercus.findFunctionImpl(name); if (fun != null) return fun; if (isStrict()) return null; name = name.toLowerCase(); id = _quercus.findFunctionId(name); if (id >= 0) { if (id < _fun.length && ! (_fun[id] instanceof UndefinedFunction)) return _fun[id]; else return null; } fun = _quercus.findLowerFunctionImpl(name); if (fun != null) return fun; if (_anonymousFunMap != null) return _anonymousFunMap.get(name); return null; } public AbstractFunction getFunction(String name) { AbstractFunction fun = findFunction(name); if (fun != null) return fun; else throw createErrorException(L.l("'{0}' is an unknown function.", name)); } public void updateFunction(int id, AbstractFunction fun) { if (_fun.length <= id) { AbstractFunction []oldFun = _fun; _fun = new AbstractFunction[id + 256]; System.arraycopy(oldFun, 0, _fun, 0, oldFun.length); } if (_fun[id] == null) _fun[id] = fun; } /* public int getFunctionId(String name) { int id = _quercus.getFunctionId(name); if (_fun.length <= id) { AbstractFunction []oldFun = _fun; _fun = new AbstractFunction[id + 256]; System.arraycopy(oldFun, 0, _fun, 0, oldFun.length); } AbstractFunction []defFuns = _quercus.getFunctionMap(); if (_fun[id] == null) _fun[id] = defFuns[id]; return id; } public int getFunctionIdCount() { return _quercus.getFunctionIdCount(); } */ /** * Finds the java reflection method for the function with the given name. * * @param name the method name * @return the found method or null if no method found. */ public AbstractFunction getFunction(Value name) { name = name.toValue(); if (name instanceof CallbackFunction) return ((CallbackFunction) name).getFunction(); return getFunction(name.toString()); } /* public DefinitionState getDefinitionState() { return _defState; } */ public Value addFunction(String name, AbstractFunction fun) { AbstractFunction staticFun = _quercus.findLowerFunctionImpl(name.toLowerCase()); if (staticFun != null) throw new QuercusException(L.l("can't redefine function {0}", name)); int id = _quercus.getFunctionId(name); // XXX: anonymous/generated functions(?), e.g. like foo2431 if (_fun.length <= id) { AbstractFunction []funMap = new AbstractFunction[id + 256]; System.arraycopy(_fun, 0, funMap, 0, _fun.length); _fun = funMap; } if (_fun[id] != null && ! (_fun[id] instanceof UndefinedFunction)) throw new QuercusException(L.l("can't redefine function {0}", name)); _fun[id] = fun; return BooleanValue.TRUE; } public AbstractFunction createAnonymousFunction(String args, String code) throws IOException { log.log(Level.FINE, code); if (_anonymousFunMap == null) _anonymousFunMap = new HashMap<String, AbstractFunction>(); // PHP naming style for anonymous functions String name = "\u0000lamba" + (_anonymousFunMap.size() + 1); AbstractFunction fun = getQuercus().parseFunction(name, args, code); _anonymousFunMap.put(name, fun); return fun; } /** * Adds a function from a compiled include * * @param name the function name, must be an intern() string * @param lowerName the function name, must be an intern() string */ public Value addFunctionFromPage(String name, String lowerName, AbstractFunction fun) { // XXX: skip the old function check since the include for compiled // pages is already verified. Might have a switch here? /* AbstractFunction oldFun = _lowerFunMap.get(lowerName); if (oldFun == null) oldFun = _quercus.findLowerFunctionImpl(lowerName); if (oldFun != null) { throw new QuercusException(L.l("can't redefine function {0}", name)); } _funMap.put(name, fun); if (! isStrict()) _lowerFunMap.put(lowerName, fun); */ return BooleanValue.TRUE; } /** * Finds the java reflection method for the function with the given name. * * @param className the class name * @param methodName the method name * @return the found method or null if no method found. */ public AbstractFunction findMethod(String className, String methodName) { QuercusClass cl = findClass(className); if (cl == null) { error(L.l("'{0}' is an unknown class.", className)); return null; } AbstractFunction fun = cl.findFunction(methodName); if (fun == null) { error(L.l("'{0}::{1}' is an unknown method.", className, methodName)); return null; } return fun; } /** * Compiles and calluates the given code * * @param code the code to calluate * @return the result */ public Value evalCode(String code) throws IOException { if (log.isLoggable(Level.FINER)) log.finer(code); Quercus quercus = getQuercus(); QuercusProgram program = quercus.parseEvalExpr(code); Value value = program.execute(this); return value; } /** * Evaluates the named function. * * @param name the function name * @return the function value */ public Value call(String name) { AbstractFunction fun = findFunction(name); if (fun == null) return error(L.l("'{0}' is an unknown function.", name)); return fun.call(this); } /** * Evaluates the named function. * * @param name the function name * @param a0 the first argument * @return the function value */ public Value call(String name, Value a0) { AbstractFunction fun = findFunction(name); if (fun == null) return error(L.l("'{0}' is an unknown function.", name)); return fun.call(this, a0); } /** * Evaluates the named function. * * @param name the function name * @param a0 the first argument * @param a1 the second argument * @return the function value */ public Value call(String name, Value a0, Value a1) { return getFunction(name).call(this, a0, a1); } /** * Evaluates the named function. * * @param name the function name * @param a0 the first argument * @param a1 the second argument * @param a2 the third argument * @return the function value */ public Value call(String name, Value a0, Value a1, Value a2) { return getFunction(name).call(this, a0, a1, a2); } /** * Evaluates the named function. * * @param name the function name * @param a0 the first argument * @param a1 the second argument * @param a2 the third argument * @param a3 the fourth argument * @return the function value */ public Value call(String name, Value a0, Value a1, Value a2, Value a3) { return getFunction(name).call(this, a0, a1, a2, a3); } /** * Evaluates the named function. * * @param name the function name * @param a0 the first argument * @param a1 the second argument * @param a2 the third argument * @param a3 the fourth argument * @param a4 the fifth argument * @return the function value */ public Value call(String name, Value a0, Value a1, Value a2, Value a3, Value a4) { return getFunction(name).call(this, a0, a1, a2, a3, a4); } /** * Evaluates the named function. * * @param name the function name * @param args the arguments * @return the function value */ public Value call(String name, Value []args) { return getFunction(name).call(this, args); } /** * Evaluates the named function. * * @param name the function name * @return the function value */ public Value callRef(String name) { AbstractFunction fun = findFunction(name); if (fun == null) return error(L.l("'{0}' is an unknown function.", name)); return fun.callRef(this); } /** * EvalRefuates the named function. * * @param name the function name * @param a0 the first argument * @return the function value */ public Value callRef(String name, Value a0) { AbstractFunction fun = findFunction(name); if (fun == null) return error(L.l("'{0}' is an unknown function.", name)); return fun.callRef(this, a0); } /** * EvalRefuates the named function. * * @param name the function name * @param a0 the first argument * @param a1 the second argument * @return the function value */ public Value callRef(String name, Value a0, Value a1) { AbstractFunction fun = findFunction(name); if (fun == null) return error(L.l("'{0}' is an unknown function.", name)); return fun.callRef(this, a0, a1); } /** * EvalRefuates the named function. * * @param name the function name * @param a0 the first argument * @param a1 the second argument * @param a2 the third argument * @r
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?