use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class Deprecation method getReasons.
private static Reason[] getReasons(ArgumentList arguments) {
final IValue value = arguments.get(DEP_REASONS_PARAM);
if (value == null) {
return null;
}
assert value.valueTag() == IValue.ARRAY;
final ArrayExpr array = (ArrayExpr) value;
final ArgumentList values = array.getValues();
final int size = values.size();
if (size <= 0) {
return null;
}
final Reason[] reasons = new Reason[size];
for (int i = 0; i < size; i++) {
final IValue element = values.get(i);
assert element.valueTag() == IValue.ENUM_ACCESS;
final EnumValue enumValue = (EnumValue) element;
reasons[i] = Reason.valueOf(enumValue.getInternalName());
}
return reasons;
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class Deprecation method getReplacements.
private static String[] getReplacements(ArgumentList arguments) {
IValue value = arguments.get(DEP_REPLACE_PARAM);
if (value == null) {
return null;
}
assert value.valueTag() == IValue.ARRAY;
final ArrayExpr array = (ArrayExpr) value;
final ArgumentList values = array.getValues();
final int size = values.size();
if (size == 0) {
return null;
}
String[] replacements = new String[size];
for (int i = 0; i < size; i++) {
IValue element = values.get(i);
assert element.valueTag() == IValue.STRING;
replacements[i] = element.stringValue();
}
return replacements;
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class Deprecation method checkDeprecation.
private static void checkDeprecation(IMember member, SourcePosition position, MarkerList markers) {
Annotation annotation = member.getAnnotation(DEPRECATED_CLASS);
if (annotation == null) {
annotation = new ExternalAnnotation(DEPRECATED);
}
final ArgumentList arguments = annotation.getArguments();
final MarkerLevel markerLevel = AnnotationUtil.getEnumValue(arguments, DEP_LEVEL_PARAM, MarkerLevel.class);
if (markerLevel == null || markerLevel == MarkerLevel.IGNORE) {
return;
}
String value = AnnotationUtil.getStringValue(arguments, DEP_VALUE_PARAM);
final String description = AnnotationUtil.getStringValue(arguments, DEP_DESC_PARAM);
final String since = AnnotationUtil.getStringValue(arguments, DEP_SINCE_PARAM);
final String forRemoval = AnnotationUtil.getStringValue(arguments, DEP_UNTIL_PARAM);
value = replaceMember(member, value);
if (since != null) {
value = value.replace("{since}", since);
}
if (forRemoval != null) {
value = value.replace("{forRemoval}", forRemoval);
}
final Marker marker = Markers.withText(position, markerLevel, value);
assert marker != null;
// Description
if (description != null && !description.isEmpty()) {
marker.addInfo(Markers.getSemantic("deprecated.description", description));
}
// Since
if (since != null && !since.isEmpty()) {
marker.addInfo(Markers.getSemantic("deprecated.since", since));
}
if (forRemoval != null && !forRemoval.isEmpty()) {
marker.addInfo(Markers.getSemantic("deprecated.forRemoval", forRemoval));
}
// Until
// Reasons
final Reason[] reasons = getReasons(arguments);
if (reasons != null) {
final int reasonCount = reasons.length;
// more than one reason
if (reasonCount == 1) {
marker.addInfo(Markers.getSemantic("deprecated.reason", reasonName(reasons[0])));
} else if (reasonCount > 0) {
final StringBuilder builder = new StringBuilder(reasonName(reasons[0]));
for (int i = 1; i < reasonCount; i++) {
builder.append(", ").append(reasonName(reasons[i]));
}
marker.addInfo(Markers.getSemantic("deprecated.reasons", builder.toString()));
}
}
// Replacements
final String[] replacements = getReplacements(arguments);
if (replacements != null) {
for (String replacement : replacements) {
marker.addInfo("\t\t" + replacement);
}
marker.addInfo(Markers.getSemantic("deprecated.replacements"));
}
markers.add(marker);
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class ExpressionParser method parseApply.
/**
* Parses an APPLY call, without parenthesis. It might be possible that {@code pm.reparse()} has to be called after
* this method, depending on the token that is passed. E.g.:
* <p>
* <p>
* <pre>
* this 3
* print "abc"
* button { ... }
* </pre>
*
* @param pm
* the current parsing context manager
* @param token
* the first token of the expression that is a parameter to the APPLY method
* @param call
* the method or apply call
*/
private void parseApply(IParserManager pm, IToken token, ICall call) {
if (token.type() != BaseSymbols.OPEN_CURLY_BRACKET) {
final ArgumentList arguments = new ArgumentList(1);
call.setArguments(arguments);
pm.pushParser(new ExpressionParser(arguments).withFlags(this.flags | IGNORE_APPLY | IGNORE_OPERATOR));
return;
}
if (this.hasFlag(IGNORE_CLOSURE)) {
this.end(pm, false);
return;
}
final ArgumentList arguments = new ArgumentList(1);
call.setArguments(arguments);
pm.pushParser(new StatementListParser(arguments, true));
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class ArrayLiteralParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
int type = token.type();
switch(this.mode) {
case OPEN_BRACKET:
pm.pushParser(this.newExpressionParser(this.keys));
this.mode = SEPARATOR | COLON;
this.startPosition = token;
if (type != BaseSymbols.OPEN_SQUARE_BRACKET) {
pm.reparse();
pm.report(token, "array.open_bracket");
}
return;
case SEPARATOR | COLON:
if (type == BaseSymbols.COLON) {
this.mode = SEPARATOR;
this.values = new ArgumentList(this.keys.size());
pm.pushParser(this.newExpressionParser(this.values));
return;
}
// Fallthrough
case SEPARATOR:
if (type == BaseSymbols.CLOSE_SQUARE_BRACKET) {
pm.popParser();
this.end(token);
return;
}
this.mode = this.values != null ? COLON : SEPARATOR;
pm.pushParser(this.newExpressionParser(this.keys));
if (type != BaseSymbols.COMMA && type != BaseSymbols.SEMICOLON) {
pm.report(token, "array.separator");
}
return;
case COLON:
if (type == BaseSymbols.CLOSE_SQUARE_BRACKET) {
pm.popParser();
this.end(token);
return;
}
this.mode = SEPARATOR;
pm.pushParser(this.newExpressionParser(this.values));
if (type != BaseSymbols.COLON) {
pm.reparse();
pm.report(token, "array.map.colon");
}
return;
case END:
}
}
Aggregations