use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class ClassMetadata method createDefaultConstructor.
private CodeConstructor createDefaultConstructor() {
// init(classParams...)
final SourcePosition position = this.theClass.position();
final AttributeList attributes = this.theClass.getConstructorAttributes();
attributes.addFlag(Modifiers.GENERATED);
final CodeConstructor constructor = new CodeConstructor(this.theClass, attributes);
constructor.setPosition(position);
this.copyClassParameters(constructor);
// : super(superParams...)
final IType superType = this.theClass.getSuperType();
if (superType != null) {
// Generate the constructor body
ArgumentList arguments = this.theClass.getSuperConstructorArguments();
if (arguments == null) {
arguments = ArgumentList.empty();
}
final InitializerCall init = new InitializerCall(this.theClass.getPosition(), true, arguments, superType);
constructor.setInitializer(init);
}
// { this.classParams... = classParams... }
final ParameterList classParams = this.theClass.getParameters();
final StatementList ctorBody = new StatementList();
final ParameterList ctorParams = constructor.getParameters();
// j is the counter for class parameters, as there may be leading synthetic constructor parameters
for (int i = 0, j = 0, count = ctorParams.size(); i < count; i++) {
final IParameter ctorParam = ctorParams.get(i);
if (ctorParam.hasModifier(Modifiers.SYNTHETIC)) {
continue;
}
final IParameter classParam = classParams.get(j++);
if (classParam.hasModifier(Modifiers.OVERRIDE)) {
continue;
}
final IValue receiver = new ThisExpr(this.theClass);
final FieldAccess access = new FieldAccess(ctorParam);
final FieldAssignment assignment = new FieldAssignment(position, receiver, classParam, access);
ctorBody.add(assignment);
}
constructor.setValue(ctorBody);
return constructor;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class Annotation method resolve.
@Override
public void resolve(MarkerList markers, IContext context) {
this.arguments.resolve(markers, context);
final IClass theClass;
if (this.type == null || (theClass = this.type.getTheClass()) == null) {
return;
}
final ParameterList parameterList = theClass.getParameters();
for (int i = 0, count = parameterList.size(); i < count; i++) {
final IParameter parameter = parameterList.get(i);
final IType parameterType = parameter.getType();
final IValue value = this.arguments.get(parameter);
if (value == null) {
if (parameter.getValue() == null) {
markers.add(Markers.semanticError(this.getPosition(), "annotation.parameter.missing", this.type, parameter.getName()));
}
continue;
}
IValue typedValue = value.withType(parameterType, parameterType, markers, context);
if (typedValue == null) {
markers.add(TypeChecker.typeError(value, parameterType, parameterType, "annotation.parameter.type", parameter.getName()));
continue;
}
typedValue = IValue.toAnnotationConstant(typedValue, markers, context);
if (typedValue != value) {
this.arguments.set(i, parameter.getLabel(), typedValue);
}
}
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class Annotation method write.
public void write(AnnotationVisitor writer) {
final IClass iclass = this.type.getTheClass();
final ParameterList parameterList = iclass.getParameters();
for (int i = 0, count = parameterList.size(); i < count; i++) {
final IParameter parameter = parameterList.get(i);
final IValue argument = this.arguments.get(parameter);
if (argument != null) {
argument.writeAnnotationValue(writer, parameter.getName().qualified);
}
}
writer.visitEnd();
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class AbstractMethod method checkMutating.
private void checkMutating(MarkerList markers, IValue receiver) {
final IType receiverType = receiver.getType();
if (receiverType.getMutability() != Mutability.IMMUTABLE) {
return;
}
final Annotation mutatingAnnotation = this.getAnnotation(Types.MUTATING_CLASS);
if (mutatingAnnotation == null) {
return;
}
final IValue value = mutatingAnnotation.getArguments().get(0, Names.value);
final String stringValue = value != null ? value.stringValue() : Mutating.DEFAULT_MESSAGE;
StringBuilder builder = new StringBuilder(stringValue);
int index = builder.indexOf("{method}");
if (index >= 0) {
builder.replace(index, index + 8, this.name.unqualified);
}
index = builder.indexOf("{type}");
if (index >= 0) {
builder.replace(index, index + 6, receiverType.toString());
}
markers.add(new SemanticError(receiver.getPosition(), builder.toString()));
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class ArgumentList method checkVarargsMatch.
protected static //
int checkVarargsMatch(//
int[] matchValues, //
IType[] matchTypes, //
int matchStartIndex, //
IValue[] values, //
int startIndex, //
int endIndex, IParameter param, IImplicitContext implicitContext) {
final IValue argument = values[startIndex];
final IType paramType = param.getCovariantType();
final int matchIndex = matchStartIndex + startIndex;
if (argument.checkVarargs(false)) {
return checkMatch_(matchValues, matchTypes, matchIndex, argument, paramType, implicitContext) ? 0 : MISMATCH;
}
if (startIndex == endIndex) {
return 0;
}
final int count = endIndex - startIndex;
final ArrayExpr arrayExpr = newArrayExpr(values, startIndex, count);
if (!checkMatch_(matchValues, matchTypes, matchIndex, arrayExpr, paramType, implicitContext)) {
return MISMATCH;
}
// We fill the remaining entries that are reserved for the (now wrapped) varargs values with the match value
// of the array expression and the element type
final int value = matchValues[matchIndex];
final IType type = arrayExpr.getElementType();
for (int i = 0; i < count; i++) {
matchValues[matchIndex + i] = value;
matchTypes[matchIndex + i] = type;
}
return count;
}
Aggregations