use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class Intrinsics method readAnnotation.
public static IntrinsicData readAnnotation(IMethod method, Annotation annotation) {
final ArgumentList arguments = annotation.getArguments();
final IValue compilerCode = arguments.get(LazyFields.COMPILER_CODE);
if (compilerCode != null && compilerCode.valueTag() == IValue.INT) {
return new CompilerIntrinsic(compilerCode.intValue());
}
final IValue value = arguments.get(LazyFields.VALUE);
if (value == null || value.valueTag() != IValue.ARRAY) {
return null;
}
final ArrayExpr valueArray = (ArrayExpr) value;
final ArgumentList values = valueArray.getValues();
final int size = values.size();
int insnCount = 0;
int[] ints = new int[size];
for (int i = 0; i < size; i++) {
int opcode = values.get(i).intValue();
ints[i] = opcode;
insnCount++;
if (Opcodes.isFieldOrMethodOpcode(opcode)) {
ints[i + 1] = values.get(i + 1).intValue();
ints[i + 2] = values.get(i + 2).intValue();
ints[i + 3] = values.get(i + 3).intValue();
i += 3;
} else if (Opcodes.isJumpOpcode(opcode) || Opcodes.isLoadOpcode(opcode) || Opcodes.isStoreOpcode(opcode) || opcode == Opcodes.LDC || opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) {
ints[i + 1] = values.get(i + 1).intValue();
i += 1;
}
}
if (size > insnCount) {
IValue stringValue = arguments.get(LazyFields.STRINGS);
ArrayExpr strings = (ArrayExpr) stringValue;
return readComplex(method, insnCount, ints, strings);
}
return new SimpleIntrinsicData(method, ints);
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class StatementList method resolve.
@Override
public IValue resolve(MarkerList markers, IContext context) {
if (this.valueCount <= 0) {
return this;
}
context = context.push(this);
// Resolve and check all values
final int lastIndex = this.valueCount - 1;
for (int i = 0; i < this.valueCount; i++) {
final IValue resolvedValue = this.values[i] = this.values[i].resolve(markers, context);
final int valueTag = resolvedValue.valueTag();
if (valueTag == IValue.VARIABLE) {
this.addVariable((VariableStatement) resolvedValue, markers, context);
continue;
}
if (valueTag == IValue.MEMBER_STATEMENT) {
this.addMethod((MemberStatement) resolvedValue, markers);
continue;
}
if (i == lastIndex) {
break;
}
if (!resolvedValue.isStatement()) {
final IValue applyStatementCall = resolveApplyStatement(markers, context, resolvedValue);
if (applyStatementCall != null) {
this.values[i] = applyStatementCall;
continue;
}
}
this.values[i] = IStatement.checkStatement(markers, context, resolvedValue, "statementlist.statement");
}
context.pop();
return this;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class StatementList method toString.
@Override
public void toString(String prefix, StringBuilder buffer) {
if (this.valueCount == 0) {
if (Formatting.getBoolean("statement.empty.newline")) {
buffer.append('{').append('\n').append(prefix).append('}');
} else if (Formatting.getBoolean("statement.empty.space_between")) {
buffer.append("{ }");
} else {
buffer.append("{}");
}
return;
}
buffer.append('{').append('\n');
String indentedPrefix = Formatting.getIndent("statement.indent", prefix);
int prevLine = 0;
Label label;
for (int i = 0; i < this.valueCount; i++) {
IValue value = this.values[i];
SourcePosition pos = value.getPosition();
buffer.append(indentedPrefix);
if (pos != null) {
if (pos.startLine() - prevLine > 1 && i > 0) {
buffer.append('\n').append(indentedPrefix);
}
prevLine = pos.endLine();
}
if (this.labels != null && i < this.labels.length && (label = this.labels[i]) != null) {
buffer.append("label ");
buffer.append(label.name);
if (Formatting.getBoolean("label.separator.space_before")) {
buffer.append(' ');
}
buffer.append(':');
if (Formatting.getBoolean("label.separator.newline_after")) {
buffer.append('\n').append(indentedPrefix);
} else if (Formatting.getBoolean("label.separator.newline_after")) {
buffer.append(' ');
}
}
value.toString(indentedPrefix, buffer);
if (Formatting.getBoolean("statement.semicolon")) {
buffer.append(';');
}
buffer.append('\n');
}
buffer.append(prefix).append('}');
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class UnapplyPattern method withType.
@Override
public Pattern withType(IType type, MarkerList markers) {
// PatternType.unapply(_ : MatchedType)
final IClass matchClass = this.type.getTheClass();
if (matchClass == null) {
return null;
}
final MethodCall methodCall = new MethodCall(this.position, new ClassAccess(this.type), Names.unapply, new ArgumentList(new DummyValue(type)));
final IValue resolvedCall = methodCall.resolveCall(MarkerList.BLACKHOLE, matchClass, false);
return resolvedCall != null && this.withMethod(type, resolvedCall, markers) ? this : null;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class MultiImport method resolveImplicit.
@Override
public IValue resolveImplicit(IType type) {
IValue candidate = null;
for (int i = 0; i < this.importCount; i++) {
final IValue value = this.imports[i].asContext().resolveImplicit(type);
if (value == null) {
continue;
}
if (candidate != null) {
// ambiguous
return null;
}
candidate = value;
}
return candidate;
}
Aggregations