use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.
the class REPLContext method endEvaluation.
public void endEvaluation() {
final IContext context = this.getContext();
this.currentClass.resolveTypes(this.markers, context);
this.currentClass.resolve(this.markers, context);
this.currentClass.checkTypes(this.markers, context);
this.currentClass.check(this.markers, context);
if (this.markers.getErrors() > 0) {
this.printErrors();
this.cleanup();
return;
}
for (int i = this.getCompilationContext().config.getConstantFolding() - 1; i >= 0; i--) {
this.currentClass.foldConstants();
}
this.currentClass.cleanup(this, this.currentClass);
final Class<?> theClass = this.compileAndLoad();
for (IMember member : this.members) {
this.processMember(member, theClass);
}
this.printErrors();
this.cleanup();
}
use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.
the class LambdaExpr method withType.
@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
if (!this.isType(type)) {
return null;
}
if (type.getTheClass() == Types.OBJECT_CLASS) {
type = this.getType();
}
if (type != this.type) {
// If this is not the type initially created and returned by getType(), remove the LAMBDA_TYPE_INFERRED flag
this.flags &= ~LAMBDA_TYPE_INFERRED;
}
this.type = type;
this.method = type.getFunctionalMethod();
this.inferTypes(markers);
final IContext combinedContext = context.push(this);
if ((this.flags & VALUE_RESOLVED) == 0) {
this.value = this.value.resolve(markers, combinedContext);
this.flags |= VALUE_RESOLVED;
}
if (this.returnType.isUninferred()) {
this.returnType = this.value.getType();
}
this.value = TypeChecker.convertValue(this.value, this.returnType, this.returnType, markers, combinedContext, LAMBDA_MARKER_SUPPLIER);
this.inferReturnType(type, this.value.getType());
if (this.returnType.isUninferred() && this.value.isResolved()) {
markers.add(Markers.semanticError(this.position, "lambda.return_type.infer"));
}
context.pop();
return this;
}
use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.
the class Field method resolve.
@Override
public void resolve(MarkerList markers, IContext context) {
super.resolve(markers, context);
if (this.value != null) {
final IContext context1 = new CombiningContext(this, context);
this.value = this.value.resolve(markers, context1);
boolean inferType = false;
if (this.type == Types.UNKNOWN) {
inferType = true;
this.type = this.value.getType();
}
final TypeChecker.MarkerSupplier markerSupplier = TypeChecker.markerSupplier("field.type.incompatible", "field.type", "value.type", this.name);
this.value = TypeChecker.convertValue(this.value, this.type, this.type, markers, context1, markerSupplier);
if (inferType) {
this.type = this.value.getType();
if (this.type == Types.UNKNOWN && this.value.isResolved()) {
markers.add(Markers.semantic(this.position, "field.type.infer", this.name.unqualified));
this.type = Types.ANY;
}
}
} else if (this.type == Types.UNKNOWN) {
markers.add(Markers.semantic(this.position, "field.type.infer.novalue", this.name.unqualified));
this.type = Types.ANY;
}
if (this.property == null) {
return;
}
this.property.setType(this.type);
final IMethod getter = this.property.getGetter();
final IMethod setter = this.property.getSetter();
final IValue receiver = this.hasModifier(Modifiers.STATIC) ? null : new ThisExpr(this.enclosingClass.getThisType(), VariableThis.DEFAULT);
if (getter != null) {
getter.setType(this.type);
if (getter.getValue() == null) {
// get: this.FIELD_NAME
getter.setValue(new FieldAccess(getter.getPosition(), receiver, this));
}
}
if (setter != null) {
final IParameter setterParameter = setter.getParameters().get(0);
setterParameter.setType(this.type);
if (setter.getValue() == null) {
final SourcePosition setterPosition = setter.getPosition();
if (this.hasModifier(Modifiers.FINAL)) {
markers.add(Markers.semanticError(setterPosition, "field.property.setter.final", this.name));
// avoid abstract method error
setter.setValue(new VoidValue(setterPosition));
} else {
// set: this.FIELD_NAME = newValue
setter.setValue(new FieldAssignment(setterPosition, receiver, this, new FieldAccess(setterPosition, null, setterParameter)));
}
}
}
this.property.resolve(markers, context);
}
use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.
the class ExternalClass method resolveGenerics.
private void resolveGenerics() {
if ((this.resolved & GENERICS) != 0) {
return;
}
this.resolved |= GENERICS;
final int typeParams;
if (this.typeParameters == null || (typeParams = this.typeParameters.size()) <= 0) {
return;
}
final IContext context = this.getCombiningContext();
for (int i = 0; i < typeParams; i++) {
final ITypeParameter typeParameter = this.typeParameters.get(i);
typeParameter.resolveTypes(null, context);
}
}
use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.
the class ExternalClass method resolveSuperTypes.
private void resolveSuperTypes() {
if ((this.resolved & SUPER_TYPES) != 0) {
return;
}
this.resolved |= SUPER_TYPES;
final IContext context = this.getCombiningContext();
if (this.superType != null) {
this.superType = this.superType.resolveType(null, context);
}
if (this.interfaces != null) {
this.interfaces.resolveTypes(null, context);
}
}
Aggregations