use of php.runtime.loader.dump.io.DumpOutputStream in project jphp by jphp-compiler.
the class ClassDumper method save.
@Override
public void save(ClassEntity entity, OutputStream output) throws IOException {
if (entity.getType() == ClassEntity.Type.CLASS && entity.getData() == null)
throw new DumpException("Class '" + entity.getName() + "' not compiled");
DumpOutputStream printer = new DumpOutputStream(output);
printer.writeBoolean(entity.isStatic());
// type
printer.writeEnum(entity.getType());
printer.writeBoolean(entity.isAbstract());
printer.writeBoolean(entity.isFinal());
// print name
printer.writeName(entity.getName());
printer.writeName(entity.getCompiledInternalName());
printer.writeTrace(debugInformation ? entity.getTrace() : null);
// parent
ClassEntity parent = entity.getParent();
if (entity.getParent() != null) {
printer.writeName(parent.getName());
} else {
// write null
printer.writeName(null);
}
// constants
List<ConstantEntity> constants = new ArrayList<ConstantEntity>();
for (ConstantEntity el : entity.getConstants()) {
if (el.isOwned(entity))
constants.add(el);
}
printer.writeInt(constants.size());
for (ConstantEntity el : constants) {
constantDumper.save(el, output);
}
// properties
List<PropertyEntity> properties = new ArrayList<PropertyEntity>();
for (PropertyEntity el : entity.getStaticProperties()) {
if (el.isOwned(entity))
properties.add(el);
}
for (PropertyEntity el : entity.getProperties()) {
if (el.isOwned(entity))
properties.add(el);
}
printer.writeInt(properties.size());
for (PropertyEntity el : properties) {
propertyDumper.save(el, output);
}
// methods
printer.writeInt(entity.getMethodCounts());
List<MethodEntity> methods = entity.getOwnedMethods();
printer.writeInt(methods.size());
for (MethodEntity el : methods) {
methodDumper.save(el, output);
}
// interfaces
printer.writeInt(entity.getInterfaces().size());
for (ClassEntity el : entity.getInterfaces().values()) {
printer.writeName(el.getName());
}
// traits
printer.writeInt(entity.getTraits().size());
for (ClassEntity el : entity.getTraits().values()) {
printer.writeName(el.getName());
}
if (includeData) {
printer.writeRawData(entity.getData(), Integer.MAX_VALUE);
} else {
printer.writeRawData(null);
}
// addition raw data
printer.writeRawData(null);
}
use of php.runtime.loader.dump.io.DumpOutputStream in project jphp by jphp-compiler.
the class ModuleDumper method save.
@Override
public void save(ModuleEntity entity, OutputStream output) throws IOException {
if (entity.getData() == null)
throw new DumpException("Module '" + entity.getName() + "' not compiled");
DumpOutputStream data = new DumpOutputStream(output);
// version
data.writeInt(DUMP_STAMP);
data.writeInt(DUMP_VERSION);
// legacy code.
data.writeEnum(LangMode.DEFAULT);
// module name
data.writeName(entity.getContext().getModuleName());
data.writeName(entity.getInternalName());
// trace
data.writeTrace(entity.getTrace());
// constants
data.writeInt(entity.getConstants().size());
for (ConstantEntity e : entity.getConstants()) {
constantDumper.save(e, output);
}
// closures
data.writeInt(entity.getClosures().size());
for (ClosureEntity e : entity.getClosures()) {
closureDumper.save(e, output);
}
// generators
data.writeInt(entity.getGenerators().size());
for (GeneratorEntity e : entity.getGenerators()) {
generatorDumper.save(e, output);
}
// functions
data.writeInt(entity.getFunctions().size());
for (FunctionEntity e : entity.getFunctions()) {
functionDumper.save(e, output);
}
// classes
data.writeInt(entity.getClasses().size());
for (ClassEntity e : entity.getClasses()) {
classDumper.save(e, output);
}
if (includeData) {
// byte code
data.writeInt(entity.getData().length);
data.write(entity.getData());
} else {
data.writeInt(0);
}
// 5 mb
data.writeRawData(null, 1024 * 1024 * 5);
}
use of php.runtime.loader.dump.io.DumpOutputStream in project jphp by jphp-compiler.
the class ParameterDumper method save.
@Override
public void save(ParameterEntity entity, OutputStream output) throws IOException {
DumpOutputStream print = new DumpOutputStream(output);
// hint type
print.writeEnum(entity.getType());
// hint class type
print.writeName(entity.getTypeClass());
// & ref
print.writeBoolean(entity.isReference());
// mutable
print.writeBoolean(entity.isMutable());
// used
print.writeBoolean(entity.isUsed());
// variadic
print.writeBoolean(entity.isVariadic());
// nullable
print.writeBoolean(entity.isNullable());
// name
print.writeName(entity.getName());
// trace
print.writeTrace(debugInformation ? entity.getTrace() : null);
// memory
print.writeMemory(entity.getDefaultValue());
print.writeName(entity.getDefaultValueConstName());
// raw
print.writeRawData(null);
}
use of php.runtime.loader.dump.io.DumpOutputStream in project jphp by jphp-compiler.
the class PropertyDumper method save.
@Override
public void save(PropertyEntity entity, OutputStream output) throws IOException {
DumpOutputStream print = new DumpOutputStream(output);
// static
print.writeBoolean(entity.isStatic());
// modifier
print.writeEnum(entity.getModifier());
// name
print.writeName(entity.getName());
// trace
print.writeTrace(debugInformation ? entity.getTrace() : null);
// def
print.writeBoolean(entity.isDefault());
// def value
print.writeMemory(entity.getDefaultValue());
// raw
print.writeRawData(null);
}
use of php.runtime.loader.dump.io.DumpOutputStream in project jphp by jphp-compiler.
the class ClosureDumper method save.
@Override
public void save(ClosureEntity entity, OutputStream output) throws IOException {
if (!entity.isLoaded())
throw new DumpException("Closure not loaded");
DumpOutputStream data = new DumpOutputStream(output);
data.writeName(entity.getInternalName());
data.writeBoolean(entity.isReturnReference());
methodDumper.save(entity.methodMagicInvoke, output);
data.writeInt(entity.parameters == null ? 0 : entity.parameters.length);
if (entity.parameters != null)
for (ParameterEntity param : entity.parameters) {
parameterDumper.save(param, output);
}
data.writeInt(entity.uses == null ? 0 : entity.uses.length);
if (entity.uses != null)
for (ParameterEntity param : entity.uses) {
parameterDumper.save(param, output);
}
if (includeData) {
data.writeRawData(entity.getData(), Integer.MAX_VALUE);
} else {
data.writeRawData(null);
}
}
Aggregations