public Context getContext() { if (context == null){ context = new Context(null, new File(fileName)); } return context; }
public TraceInfo(Context context, int startLine, int endLine, int startPosition, int endPosition) { this.fileName = !context.isLikeFile() ? null : context.getFileName(); this.context = context; this.startLine = startLine; this.endLine = endLine; this.startPosition = startPosition; this.endPosition = endPosition; }
public String getModuleNameNoThrow(){ try { return getModuleName(); } catch (IOException e){ return file.getAbsolutePath(); } }
public Tokenizer(Context context) throws IOException { this.context = context; this.code = context.getContent(); this.codeLength = code.length(); this.rawMode = context.isLikeFile(); reset(); }
public ModuleEntity importCompiledModule(Context context, boolean debugInformation) throws Throwable { String moduleName = context.getModuleName(); ModuleEntity module = moduleName == null ? null : scope.findUserModule(moduleName); if (module == null) { ModuleDumper moduleDumper = new ModuleDumper(context, this, debugInformation); module = moduleDumper.load(context.getInputStream(getDefaultCharset())); synchronized (scope) { scope.loadModule(module); } } registerModule(module); scope.addUserModule(module); return module; }
@Test public void testParseError() throws IOException { Throwable ex = null; Tokenizer tokenizer = new Tokenizer(new Context( " 'foobar \n ")); try { tokenizer.nextToken(); } catch (Throwable e){ ex = e; } assertTrue(ex instanceof ParseException); TraceInfo traceInfo = ((ParseException) ex).getTraceInfo(); assertNotNull(traceInfo); assertNull(traceInfo.getContext().getFileName()); assertEquals(1, traceInfo.getStartLine()); assertEquals(1, traceInfo.getEndLine()); assertEquals(1, traceInfo.getStartPosition()); assertEquals(1, traceInfo.getEndPosition()); }
String moduleName = sourceDirectory .toPath() .relativize(Paths.get(_context.getModuleName())) .toString() .replace('\\', '/'); Context context = new Context(new ByteArrayInputStream(new byte[0]), moduleName, env.getDefaultCharset());
@Signature({ @Arg("source"), @Arg(value = "compiled", optional = @Optional("false")), @Arg(value = "debugInformation", optional = @Optional("true")) }) public Memory __construct(Environment env, Memory... args) throws Throwable { InputStream is = Stream.getInputStream(env, args[0]); try { if (is != null) { is = new BufferedInputStream(is); } Context context = new Context(is, Stream.getPath(args[0]), env.getDefaultCharset()); if (args[1].toBoolean()) { ModuleDumper moduleDumper = new ModuleDumper(context, env, args[2].toBoolean()); module = moduleDumper.load(context.getInputStream(env.getDefaultCharset())); } else { AbstractCompiler compiler = env.scope.createCompiler(env, context); module = compiler.compile(false); } register(env); } finally { Stream.closeStream(env, is); } return Memory.NULL; }
public String getSourceFile() { return context.getFileName(); }
@Signature public boolean isReadOnly() { return !getContext().isLikeFile(); }
Thread.currentThread().getContextClassLoader().getResource("resources/" + name).getFile() )); Context context = new Context(test.getFile(), file); environment.getScope().addUserModule(module); environment.registerModule(module); environment.getModuleManager().addModule(context.getFileName(), module);
@Signature public void write(Environment env, SourceManager manager, SourceFile file) throws Throwable { Context context = file.getContext(); if (!file.isReadOnly()) { Stream stream = Stream.create(env, context.getFileName(), "w+"); try { env.invokeMethod( this, "writeModule", ObjectMemory.valueOf(manager), ObjectMemory.valueOf(file), ObjectMemory.valueOf(file.getModuleRecord()), ObjectMemory.valueOf(stream) ); } finally { env.invokeMethod(stream, "close"); } } }
public ModuleEntity importModule(Context context) throws Throwable { String moduleName = context.getModuleName(); ModuleEntity module = moduleName == null ? null : scope.findUserModule(moduleName); if (module == null) { AbstractCompiler compiler = scope.createCompiler(this, context); module = compiler.compile(true); synchronized (scope) { scope.loadModule(module); } } registerModule(module); return module; }
public Context fetchContext(Stream stream) throws Throwable { if (stream instanceof FileStream) { return new Context( new BufferedInputStream(Stream.getInputStream(env, stream)), stream.getPath(), env.getDefaultCharset() ); } return new Context( new BufferedInputStream(Stream.getInputStream(env, stream)), stream.getPath(), env.getDefaultCharset() ); }
public void toOutput(Writer writer, int flags){ try { OpcodePrinter opcodePrinter = new OpcodePrinter(module); writer.write("#### Module class: " + module.getContext().getModuleName() + "\n"); opcodePrinter.toWriter(writer, flags); writer.write("#### /Module class \n\n\n");
@Signature public static List<SourceToken> parseAll(Environment env, String text) { Tokenizer tokenizer = new Tokenizer(text, new Context(text)); Token token; List<SourceToken> result = new ArrayList<>(); try { while ((token = tokenizer.nextToken()) != null) { result.add(new SourceToken(env, token)); } } catch (ParseException|StringIndexOutOfBoundsException e){ // TODO remove StringIndexOutOfBoundsException bug in jphp! return null; } return result; } }
data.writeName(entity.getContext().getModuleName()); data.writeName(entity.getInternalName());
protected Context getContext(String file) { InputStream bootstrap = getResource(file); if (bootstrap != null) { return new Context(bootstrap, file, environment.getDefaultCharset()); } else return null; }
@Signature public void __construct(Environment env, Memory path, String moduleName, String charset) throws IOException { stream = Stream.getInputStream(env, path); Context context = new Context(stream, moduleName, Charset.forName(charset)); tokenizer = new Tokenizer(context); }