use of php.runtime.env.TraceInfo in project jphp by jphp-compiler.
the class SimpleExprGenerator method processString.
protected Token processString(StringExprToken string) {
if (string.getSegments().isEmpty()) {
if (string.getQuote() == StringExprToken.Quote.SHELL) {
return new ShellExecExprToken(string.getMeta(), Arrays.<Token>asList(string));
}
return string;
}
List<Token> tokens = new ArrayList<Token>();
int i = 0;
String value = string.getValue();
TokenMeta meta = string.getMeta();
for (StringExprToken.Segment segment : string.getSegments()) {
String prev = value.substring(i, segment.from);
if (!prev.isEmpty()) {
StringExprToken item = new StringExprToken(new TokenMeta(prev, meta.getStartLine() + i, meta.getEndLine(), meta.getStartLine(), meta.getEndLine()), StringExprToken.Quote.SINGLE);
tokens.add(item);
}
String dynamic = value.substring(segment.from, segment.to);
if (!segment.isVariable)
dynamic = dynamic.substring(1, dynamic.length() - 1);
Tokenizer tokenizer = new Tokenizer(dynamic + ";", analyzer.getContext());
try {
SyntaxAnalyzer syntaxAnalyzer = new SyntaxAnalyzer(analyzer.getEnvironment(), tokenizer, analyzer.getFunction());
List<Token> tree = syntaxAnalyzer.getTree();
analyzer.getScope().addVariables(syntaxAnalyzer.getScope().getVariables());
assert tree.size() > 0;
Token item = tree.get(0);
if (!(item instanceof ExprStmtToken))
unexpectedToken(item);
ExprStmtToken expr = (ExprStmtToken) item;
if (expr.isSingle()) {
tokens.add(expr.getSingle());
} else
tokens.add(expr);
} catch (ParseException e) {
TraceInfo oldTrace = e.getTraceInfo();
e.setTraceInfo(new TraceInfo(analyzer.getContext(), meta.getStartLine() + oldTrace.getStartLine(), meta.getEndLine() + oldTrace.getEndLine(), meta.getStartLine() + oldTrace.getStartLine(), meta.getEndLine() + oldTrace.getEndLine()));
throw e;
}
i = segment.to;
}
String prev = value.substring(i);
if (!prev.isEmpty()) {
StringExprToken item = new StringExprToken(new TokenMeta(prev, meta.getStartLine() + i, meta.getEndLine(), meta.getStartLine(), meta.getEndLine()), StringExprToken.Quote.SINGLE);
tokens.add(item);
}
if (string.getQuote() == StringExprToken.Quote.SHELL) {
return new ShellExecExprToken(meta, tokens);
}
StringBuilderExprToken result = new StringBuilderExprToken(meta, tokens);
result.setBinary(string.isBinary());
return result;
}
use of php.runtime.env.TraceInfo in project jphp by jphp-compiler.
the class ParameterEntity method validateTypeHinting.
public static void validateTypeHinting(Environment env, int index, Memory[] args, HintType type, boolean nullable) {
Memory value = args[index - 1];
if (!checkTypeHinting(env, value, type, nullable)) {
String given;
if (value == null) {
given = "none";
} else if (value.isObject()) {
given = "instance of " + value.toValue(ObjectMemory.class).getReflection().getName();
} else {
given = value.getRealType().toString();
}
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement e = stack[2];
StackTraceElement where = stack[3];
TraceInfo trace;
if (where.getLineNumber() <= 0)
trace = env.trace();
else
trace = new TraceInfo(where);
JVMStackTracer.Item item = new JVMStackTracer.Item(env.scope.getClassLoader(), e);
env.error(trace, ErrorType.E_RECOVERABLE_ERROR, "Argument %s passed to %s() must be of the type %s, %s given", index, item.getSignature(), type.toString(), given);
}
}
use of php.runtime.env.TraceInfo in project jphp by jphp-compiler.
the class FileObject method findFiles.
@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory findFiles(final Environment env, Memory... args) {
File[] result;
if (args[0].isNull()) {
result = file.listFiles();
} else {
final Invoker invoker = Invoker.valueOf(env, null, args[0]);
if (invoker == null) {
exception(env, "Invalid filter value, must be callable");
return Memory.NULL;
}
final TraceInfo trace = env.trace();
invoker.setTrace(trace);
result = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
FileObject o = new FileObject(env, __class__, dir);
Memory[] args = new Memory[] { new ObjectMemory(o), new StringMemory(name) };
return invoker.callNoThrow(args).toBoolean();
}
});
}
ArrayMemory arr = new ArrayMemory();
if (result != null) {
for (File e : result) {
arr.add(new ObjectMemory(new FileObject(env, __class__, e)));
}
}
return arr.toConstant();
}
use of php.runtime.env.TraceInfo in project jphp by jphp-compiler.
the class ErrorHandler method onError.
public boolean onError(Environment env, SystemMessage message) {
if (ErrorType.check(errorHandlerFlags, message.getType())) {
TraceInfo trace = message.getTrace().trace;
int argCount = invoker.getArgumentCount();
if (argCount < 4)
argCount = 4;
else if (argCount > 5)
argCount = 5;
Memory[] args = new Memory[argCount];
args[0] = LongMemory.valueOf(message.getType().value);
args[1] = new StringMemory(message.getMessage());
args[2] = new StringMemory(trace.getFileName());
args[3] = LongMemory.valueOf(trace.getStartLine() + 1);
if (argCount > 4)
args[4] = new ArrayMemory(false, message.getTrace().args);
try {
invoker.setTrace(null);
return (invoker.call(args).toValue() != Memory.FALSE);
} catch (ErrorException e) {
throw e;
} catch (BaseException e) {
throw e;
} catch (DieException e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
return false;
}
use of php.runtime.env.TraceInfo in project jphp by jphp-compiler.
the class ErrorException method setTraceInfo.
@Override
public void setTraceInfo(Environment env, TraceInfo trace) {
super.setTraceInfo(env, trace);
Memory line = clazz.refOfProperty(props, "line");
Memory file = clazz.refOfProperty(props, "file");
if (!line.isNull() || !file.isNull()) {
this.trace = new TraceInfo(file.isNull() ? trace.getFileName() : file.toString(), line.isNull() ? trace.getStartLine() : line.toInteger() - 1, trace.getStartPosition());
}
}
Aggregations