Search in sources :

Example 1 with Scope

use of lucee.runtime.type.scope.Scope in project Lucee by lucee.

the class Trace method _doEndTag.

public void _doEndTag() throws IOException, PageException {
    PageSource ps = pageContext.getCurrentTemplatePageSource();
    // var
    String varValue = null;
    Object value = null, traceValue = null;
    if (!StringUtil.isEmpty(var)) {
        try {
            if (caller instanceof Scope)
                value = VariableInterpreter.getVariable(pageContext, var, (Scope) caller);
            else
                value = pageContext.getVariable(var);
        } catch (PageException e) {
            varValue = "(undefined)";
            follow = false;
        }
        if (follow) {
            // print.o(1);
            if (StringUtil.isEmpty(text, true))
                text = var;
            // print.o(2);
            traceValue = TraceObjectSupport.toTraceObject(pageContext.getDebugger(), value, type, category, text);
            if (caller instanceof Scope)
                VariableInterpreter.setVariable(pageContext, var, traceValue, (Scope) caller);
            else
                pageContext.setVariable(var, traceValue);
        }
        try {
            varValue = new ScriptConverter().serialize(value);
        } catch (ConverterException e) {
            if (value != null)
                varValue = "(" + Caster.toTypeName(value) + ")";
        }
    }
    DebugTrace trace = ((DebuggerImpl) pageContext.getDebugger()).addTrace(type, category, text, ps, var, varValue);
    DebugTrace[] traces = pageContext.getDebugger().getTraces(pageContext);
    String total = "(1st trace)";
    if (traces.length > 1) {
        long t = 0;
        for (int i = 0; i < traces.length; i++) {
            t += traces[i].getTime();
        }
        total = "(" + t + ")";
    }
    boolean hasCat = !StringUtil.isEmpty(trace.getCategory());
    boolean hasText = !StringUtil.isEmpty(trace.getText());
    boolean hasVar = !StringUtil.isEmpty(var);
    // inline
    if (inline) {
        lucee.runtime.format.TimeFormat tf = new lucee.runtime.format.TimeFormat(pageContext.getConfig().getLocale());
        StringBuffer sb = new StringBuffer();
        sb.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"white\">");
        sb.append("<tr>");
        // sb.append("<td><img src=\"/CFIDE/debug/images/Error_16x16.gif\" alt=\"Error type\">");
        sb.append("<td>");
        sb.append("<font color=\"orange\">");
        sb.append("<b>");
        sb.append(DebugTraceImpl.toType(trace.getType(), "INFO") + " - ");
        sb.append("[CFTRACE " + tf.format(new DateTimeImpl(pageContext.getConfig()), "hh:mm:ss:l") + "]");
        sb.append("[" + trace.getTime() + " ms " + total + "]");
        sb.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
        if (hasCat || hasText)
            sb.append(" -");
        if (hasCat)
            sb.append("  [" + trace.getCategory() + "]");
        if (hasText)
            sb.append(" <i>" + trace.getText() + "&nbsp;</i>");
        sb.append("</b>");
        sb.append("</font>");
        sb.append("</td>");
        sb.append("</tr>");
        sb.append("</table>");
        pageContext.forceWrite(sb.toString());
        if (hasVar)
            Dump.call(pageContext, value, var);
    }
    // log
    Log log = ((ConfigImpl) pageContext.getConfig()).getLog("trace");
    StringBuffer msg = new StringBuffer();
    msg.append("[" + trace.getTime() + " ms " + total + "] ");
    msg.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
    if (hasCat || hasText || hasVar)
        msg.append("- ");
    if (hasCat)
        msg.append("[" + trace.getCategory() + "] ");
    if (hasVar)
        msg.append("[" + var + "=" + varValue + "] ");
    if (hasText)
        msg.append(" " + trace.getText() + " ");
    log.log(trace.getType(), "cftrace", msg.toString());
    // abort
    if (abort)
        throw new Abort(Abort.SCOPE_REQUEST);
}
Also used : PageException(lucee.runtime.exp.PageException) ConverterException(lucee.runtime.converter.ConverterException) Log(lucee.commons.io.log.Log) DebuggerImpl(lucee.runtime.debug.DebuggerImpl) PageSource(lucee.runtime.PageSource) Abort(lucee.runtime.exp.Abort) Scope(lucee.runtime.type.scope.Scope) DebugTrace(lucee.runtime.debug.DebugTrace) ScriptConverter(lucee.runtime.converter.ScriptConverter) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 2 with Scope

use of lucee.runtime.type.scope.Scope in project Lucee by lucee.

the class FDVariableComparator method getVariables.

private static List getVariables(FDStackFrameImpl frame, PageContextImpl pc, List list, String strScope) throws FDLanguageException {
    Scope scope;
    try {
        scope = pc.scope(strScope, null);
        if (scope != null)
            return copyValues(frame, list, scope);
        Object value = pc.undefinedScope().get(strScope, null);
        if (value != null) {
            if (value instanceof Struct)
                return copyValues(frame, new ArrayList(), (Struct) value);
            throw new FDLanguageException("[" + strScope + "] is not of type scope, type is [" + Caster.toTypeName(value) + "]");
        }
        throw new FDLanguageException("[" + strScope + "] does not exist in the current context");
    } catch (PageException e) {
        throw new FDLanguageException(e);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Scope(lucee.runtime.type.scope.Scope) FDLanguageException(com.intergral.fusiondebug.server.FDLanguageException) ArrayList(java.util.ArrayList) Struct(lucee.runtime.type.Struct)

Example 3 with Scope

use of lucee.runtime.type.scope.Scope in project Lucee by lucee.

the class Evaluate method call.

public static Object call(PageContext pc, Object[] objs, boolean preciseMath) throws PageException {
    // define a ohter enviroment for the function
    if (objs.length > 1 && objs[objs.length - 1] instanceof Scope) {
        // Variables Scope
        Variables var = null;
        Local lcl = null, cLcl = null;
        Argument arg = null, cArg = null;
        if (objs[objs.length - 1] instanceof Variables) {
            var = (Variables) objs[objs.length - 1];
        } else if (objs[objs.length - 1] instanceof CallerImpl) {
            CallerImpl ci = ((CallerImpl) objs[objs.length - 1]);
            var = ci.getVariablesScope();
            lcl = ci.getLocalScope();
            arg = ci.getArgumentsScope();
        }
        if (var != null) {
            Variables cVar = pc.variablesScope();
            pc.setVariablesScope(var);
            if (lcl != null && !(lcl instanceof LocalNotSupportedScope)) {
                cLcl = pc.localScope();
                cArg = pc.argumentsScope();
                pc.setFunctionScopes(lcl, arg);
            }
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(cVar);
                if (cLcl != null)
                    pc.setFunctionScopes(cLcl, cArg);
            }
        } else // Undefined Scope
        if (objs[objs.length - 1] instanceof Undefined) {
            PageContextImpl pci = (PageContextImpl) pc;
            Undefined undefined = (Undefined) objs[objs.length - 1];
            boolean check = undefined.getCheckArguments();
            Variables orgVar = pc.variablesScope();
            Argument orgArgs = pc.argumentsScope();
            Local orgLocal = pc.localScope();
            pci.setVariablesScope(undefined.variablesScope());
            if (check)
                pci.setFunctionScopes(undefined.localScope(), undefined.argumentsScope());
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(orgVar);
                if (check)
                    pci.setFunctionScopes(orgLocal, orgArgs);
            }
        }
    }
    return _call(pc, objs, objs.length, preciseMath);
}
Also used : Variables(lucee.runtime.type.scope.Variables) Undefined(lucee.runtime.type.scope.Undefined) CallerImpl(lucee.runtime.type.scope.CallerImpl) Scope(lucee.runtime.type.scope.Scope) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Argument(lucee.runtime.type.scope.Argument) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl)

Example 4 with Scope

use of lucee.runtime.type.scope.Scope in project Lucee by lucee.

the class CFMLExpressionInterpreter method startElement.

/**
 * Extrahiert den Start Element einer Variale,
 * dies ist entweder eine Funktion, eine Scope Definition oder eine undefinierte Variable.
 * <br />
 * EBNF:<br />
 * <code>identifier "(" functionArg ")" | scope | identifier;</code>
 * @param name Einstiegsname
 * @return CFXD Element
 * @throws PageException
 */
private Ref startElement(String name) throws PageException {
    // check function
    if (!limited && cfml.isCurrent('(')) {
        FunctionLibFunction function = fld.getFunction(name);
        Ref[] arguments = functionArg(name, true, function, ')');
        if (function != null)
            return new BIFCall(function, arguments);
        Ref ref = new lucee.runtime.interpreter.ref.var.Scope(Scope.SCOPE_UNDEFINED);
        return new UDFCall(ref, name, arguments);
    }
    // check scope
    return scope(name);
}
Also used : UDFCall(lucee.runtime.interpreter.ref.func.UDFCall) Ref(lucee.runtime.interpreter.ref.Ref) Scope(lucee.runtime.type.scope.Scope) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall)

Example 5 with Scope

use of lucee.runtime.type.scope.Scope in project Lucee by lucee.

the class ValueList method toColumn.

protected static QueryColumn toColumn(PageContext pc, String strQueryColumn) throws PageException {
    // if(strQueryColumn.indexOf('.')<1)
    // throw new ExpressionException("invalid query column definition ["+strQueryColumn+"]");
    VariableReference ref = ((PageContextImpl) pc).getVariableReference(strQueryColumn);
    if (ref.getParent() instanceof Scope)
        throw new ExpressionException("invalid query column definition [" + strQueryColumn + "]");
    Query query = Caster.toQuery(ref.getParent());
    return query.getColumn(ref.getKey());
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference) Scope(lucee.runtime.type.scope.Scope) Query(lucee.runtime.type.Query) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

Scope (lucee.runtime.type.scope.Scope)7 PageContextImpl (lucee.runtime.PageContextImpl)2 PageException (lucee.runtime.exp.PageException)2 FDLanguageException (com.intergral.fusiondebug.server.FDLanguageException)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Log (lucee.commons.io.log.Log)1 PageSource (lucee.runtime.PageSource)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)1 ConverterException (lucee.runtime.converter.ConverterException)1 ScriptConverter (lucee.runtime.converter.ScriptConverter)1 DebugTrace (lucee.runtime.debug.DebugTrace)1 DebuggerImpl (lucee.runtime.debug.DebuggerImpl)1 Abort (lucee.runtime.exp.Abort)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 TemplateException (lucee.runtime.exp.TemplateException)1 GatewayEngineImpl (lucee.runtime.gateway.GatewayEngineImpl)1 Ref (lucee.runtime.interpreter.ref.Ref)1 BIFCall (lucee.runtime.interpreter.ref.func.BIFCall)1