use of org.objectweb.asm.Type in project semantic-versioning by jeluard.
the class StreamDiffHandler method addMethodNodes.
/**
* Add the method nodes for the method descriptor.
* This writes out an <arguments> node containing the
* argument types for the method, followed by a <return> node
* containing the return type.
*
* @param desc The descriptor for the method to write out.
* @throws IOException when there is an underlying IOException.
*/
protected void addMethodNodes(String desc) throws IOException {
Type[] args = Type.getArgumentTypes(desc);
Type ret = Type.getReturnType(desc);
out.write("<arguments>");
for (int i = 0; i < args.length; i++) addTypeNode(args[i]);
out.write("</arguments>");
out.write("<return>");
addTypeNode(ret);
out.write("</return>");
}
use of org.objectweb.asm.Type in project semantic-versioning by jeluard.
the class DOMDiffHandler method addMethodNodes.
/**
* Add the method nodes for the method descriptor.
* This writes out an <arguments> node containing the
* argument types for the method, followed by a <return> node
* containing the return type.
*
* @param desc The descriptor for the method to write out.
*/
protected void addMethodNodes(String desc) {
Type[] args = Type.getArgumentTypes(desc);
Type ret = Type.getReturnType(desc);
Node currentNode = this.currentNode;
Element tmp = doc.createElementNS(XML_URI, "arguments");
currentNode.appendChild(tmp);
this.currentNode = tmp;
for (int i = 0; i < args.length; i++) addTypeNode(args[i]);
tmp = doc.createElementNS(XML_URI, "return");
currentNode.appendChild(tmp);
this.currentNode = tmp;
addTypeNode(ret);
this.currentNode = currentNode;
}
use of org.objectweb.asm.Type in project jphp by jphp-compiler.
the class ClassStmtCompiler method writeDefaultConstructors.
protected void writeDefaultConstructors() {
if (!isSystem && !isClosure() && entity.getParent() != null && entity.getParent().getNativeClass() != null && !BaseObject.class.isAssignableFrom(entity.getParent().getNativeClass())) {
for (Constructor el : entity.getParent().getNativeClass().getConstructors()) {
Class<?>[] parameterTypes = el.getParameterTypes();
if (parameterTypes.length == 2 && parameterTypes[0] == Environment.class && parameterTypes[1] == ClassEntity.class) {
continue;
}
MethodNode constructor = new MethodNodeImpl();
constructor.name = Constants.INIT_METHOD;
constructor.access = el.getModifiers();
constructor.exceptions = new ArrayList();
MethodStmtCompiler methodCompiler = new MethodStmtCompiler(this, constructor);
ExpressionStmtCompiler expressionCompiler = new ExpressionStmtCompiler(methodCompiler, null);
LabelNode l0 = writeLabel(constructor, statement.getMeta().getStartLine());
methodCompiler.addLocalVariable("~this", l0);
Type[] argumentTypes = new Type[parameterTypes.length];
int i = 0;
for (Class type : parameterTypes) {
argumentTypes[i++] = Type.getType(type);
methodCompiler.addLocalVariable("arg" + i, l0, type);
}
constructor.desc = Type.getMethodDescriptor(Type.getType(void.class), argumentTypes);
methodCompiler.writeHeader();
expressionCompiler.writeVarLoad("~this");
for (i = 0; i < argumentTypes.length; i++) {
expressionCompiler.writeVarLoad("arg" + (i + 1));
}
constructor.instructions.add(new MethodInsnNode(INVOKESPECIAL, node.superName, Constants.INIT_METHOD, constructor.desc, false));
methodCompiler.writeFooter();
constructor.instructions.add(new InsnNode(RETURN));
node.methods.add(constructor);
}
}
}
use of org.objectweb.asm.Type in project jphp by jphp-compiler.
the class ExpressionStmtCompiler method writeUnaryOperator.
Memory writeUnaryOperator(OperatorExprToken operator, boolean returnValue, boolean writeOpcode) {
if (stackEmpty(true))
unexpectedToken(operator);
StackItem o = stackPop();
ValueExprToken L = o.getToken();
Memory mem = tryWritePush(o, false, false, true);
StackItem.Type type = tryGetType(o);
if (mem != null) {
Memory result = CompilerUtils.calcUnary(getCompiler().getEnvironment(), operator.toTraceInfo(getCompiler().getContext()), mem, operator);
if (operator instanceof ValueIfElseToken) {
ValueIfElseToken valueIfElseToken = (ValueIfElseToken) operator;
ExprStmtToken ret = valueIfElseToken.getValue();
if (mem.toBoolean()) {
if (ret == null)
result = mem;
else
result = writeExpression(ret, true, true, false);
} else {
result = writeExpression(valueIfElseToken.getAlternative(), true, true, false);
}
} else if (operator instanceof ArrayGetExprToken && !(operator instanceof ArrayGetRefExprToken)) {
// TODO: check!!!
/*Memory array = mem;
ArrayGetExprToken arrayGet = (ArrayGetExprToken)operator;
for(ExprStmtToken expr : arrayGet.getParameters()){
Memory key = writeExpression(expr, true, true, false);
if (key == null)
break;
result = array = array.valueOfIndex(key).toImmutable();
}*/
}
if (result != null) {
stackPush(result);
setStackPeekAsImmutable();
return result;
}
}
if (!writeOpcode)
return null;
writeLineNumber(operator);
String name = operator.getCode();
Class operatorResult = operator.getResultClass();
LocalVariable variable = null;
if (L instanceof VariableExprToken) {
variable = method.getLocalVariable(((VariableExprToken) L).getName());
if (operator instanceof ArrayPushExprToken || operator instanceof ArrayGetRefExprToken)
variable.setValue(null);
}
if (operator instanceof IncExprToken || operator instanceof DecExprToken) {
if (variable == null || variable.isReference()) {
if (operator.getAssociation() == Association.LEFT && returnValue) {
writePush(o);
if (stackPeek().type.isConstant())
unexpectedToken(operator);
writePushDup();
writePopImmutable();
code.add(new InsnNode(SWAP));
writePushDup();
} else {
writePush(o);
if (stackPeek().type.isConstant())
unexpectedToken(operator);
writePushDup();
}
writeSysDynamicCall(Memory.class, name, operatorResult);
writeSysDynamicCall(Memory.class, "assign", Memory.class, operatorResult);
if (!returnValue || operator.getAssociation() == Association.LEFT) {
writePopAll(1);
}
} else {
writePush(o);
if (stackPeek().type.isConstant())
unexpectedToken(operator);
if (operator.getAssociation() == Association.LEFT && returnValue) {
writeVarLoad(variable);
}
writeSysDynamicCall(Memory.class, name, operatorResult);
// TODO for constant values
variable.setValue(null);
if (operator.getAssociation() == Association.RIGHT)
writeVarStore(variable, returnValue);
else {
writeVarStore(variable, false);
}
}
} else if (operator instanceof AmpersandRefToken) {
writePush(o, false, false);
setStackPeekAsImmutable();
Token token = o.getToken();
if (token instanceof VariableExprToken) {
LocalVariable local = method.getLocalVariable(((VariableExprToken) token).getName());
local.setValue(null);
}
} else if (operator instanceof SilentToken) {
writePushEnv();
writeSysDynamicCall(Environment.class, "__pushSilent", void.class);
writePush(o);
writePushEnv();
writeSysDynamicCall(Environment.class, "__popSilent", void.class);
} else if (operator instanceof ValueIfElseToken) {
writePush(o);
ValueIfElseToken valueIfElseToken = (ValueIfElseToken) operator;
LabelNode end = new LabelNode();
LabelNode elseL = new LabelNode();
if (valueIfElseToken.getValue() == null) {
StackItem.Type dup = stackPeek().type;
writePushDup();
writePopBoolean();
code.add(new JumpInsnNode(Opcodes.IFEQ, elseL));
stackPop();
writePopBoxing();
stackPop();
code.add(new JumpInsnNode(Opcodes.GOTO, end));
code.add(elseL);
// remove duplicate of condition value , IMPORTANT!!!
makePop(dup);
writeExpression(valueIfElseToken.getAlternative(), true, false);
writePopBoxing();
code.add(end);
} else {
writePopBoolean();
code.add(new JumpInsnNode(Opcodes.IFEQ, elseL));
stackPop();
writeExpression(valueIfElseToken.getValue(), true, false);
writePopBoxing();
stackPop();
// goto end
code.add(new JumpInsnNode(Opcodes.GOTO, end));
// else
code.add(elseL);
writeExpression(valueIfElseToken.getAlternative(), true, false);
writePopBoxing();
code.add(end);
}
setStackPeekAsImmutable(false);
} else if (operator instanceof ArrayGetExprToken) {
stackPush(o);
writeArrayGet((ArrayGetExprToken) operator, returnValue);
} else if (operator instanceof CallOperatorToken) {
stackPush(o);
CallOperatorToken call = (CallOperatorToken) operator;
writePushParameters(call.getParameters());
writePushEnv();
writePushTraceInfo(operator);
writeSysStaticCall(InvokeHelper.class, "callAny", Memory.class, Memory.class, Memory[].class, Environment.class, TraceInfo.class);
if (!returnValue)
writePopAll(1);
} else {
writePush(o);
writePopBoxing();
if (operator.isEnvironmentNeeded() && operator.isTraceNeeded()) {
writePushEnv();
writePushTraceInfo(operator);
writeSysDynamicCall(Memory.class, name, operatorResult, Environment.class, TraceInfo.class);
} else if (operator.isEnvironmentNeeded()) {
writePushEnv();
writeSysDynamicCall(Memory.class, name, operatorResult, Environment.class);
} else if (operator.isTraceNeeded()) {
writePushTraceInfo(operator);
writeSysDynamicCall(Memory.class, name, operatorResult, TraceInfo.class);
} else
writeSysDynamicCall(Memory.class, name, operatorResult);
if (!returnValue) {
writePopAll(1);
}
}
return null;
}
use of org.objectweb.asm.Type in project jphp by jphp-compiler.
the class ExpressionStmtCompiler method writeSysCall.
@SuppressWarnings("unchecked")
void writeSysCall(Class clazz, int INVOKE_TYPE, String method, Class returnClazz, Class... paramClasses) {
if (INVOKE_TYPE != INVOKESPECIAL && clazz != null) {
if (compiler.getScope().isDebugMode()) {
if (!methodExists(clazz, method, paramClasses)) {
throw new NoSuchMethodException(clazz, method, paramClasses);
}
}
}
Type[] args = new Type[paramClasses.length];
if (INVOKE_TYPE == INVOKEVIRTUAL || INVOKE_TYPE == INVOKEINTERFACE)
// this
stackPop();
for (int i = 0; i < args.length; i++) {
args[i] = Type.getType(paramClasses[i]);
stackPop();
}
String owner = clazz == null ? this.method.clazz.node.name : Type.getInternalName(clazz);
if (clazz == null && this.method.clazz.entity.isTrait())
throw new CriticalException("[Compiler Error] Cannot use current classname in Trait");
code.add(new MethodInsnNode(INVOKE_TYPE, owner, method, Type.getMethodDescriptor(Type.getType(returnClazz), args), clazz != null && clazz.isInterface()));
if (returnClazz != void.class) {
stackPush(null, StackItem.Type.valueOf(returnClazz));
}
}
Aggregations