Search in sources :

Example 1 with DSLExpressionReducer

use of com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionReducer in project graal by oracle.

the class CacheExpression method getMergedLibraryIdentifier.

public String getMergedLibraryIdentifier() {
    DSLExpression identifierExpression = getDefaultExpression().reduce(new DSLExpressionReducer() {

        public DSLExpression visitVariable(Variable binary) {
            if (binary.getReceiver() == null) {
                Variable var = new Variable(binary.getReceiver(), "receiver");
                var.setResolvedTargetType(binary.getResolvedTargetType());
                var.setResolvedVariable(new CodeVariableElement(binary.getResolvedType(), "receiver"));
                return var;
            } else {
                return binary;
            }
        }

        public DSLExpression visitNegate(Negate negate) {
            return negate;
        }

        public DSLExpression visitCall(Call binary) {
            return binary;
        }

        public DSLExpression visitBinary(Binary binary) {
            return binary;
        }
    });
    String expressionText = identifierExpression.asString();
    StringBuilder b = new StringBuilder(expressionText);
    boolean nextUpperCase = false;
    int i = 0;
    while (i < b.length()) {
        char charAt = b.charAt(i);
        if (!Character.isJavaIdentifierPart(charAt)) {
            b.deleteCharAt(i);
            nextUpperCase = true;
        } else if (nextUpperCase) {
            nextUpperCase = false;
            if (i != 0) {
                b.setCharAt(i, Character.toUpperCase(b.charAt(i)));
            }
            i++;
        } else {
            i++;
        }
    }
    String libraryName = ElementUtils.getSimpleName(getParameter().getType());
    return b.toString() + libraryName + "_";
}
Also used : Call(com.oracle.truffle.dsl.processor.expression.DSLExpression.Call) Variable(com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) DSLExpressionReducer(com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionReducer) Negate(com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate) Binary(com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary) DSLExpression(com.oracle.truffle.dsl.processor.expression.DSLExpression)

Aggregations

DSLExpression (com.oracle.truffle.dsl.processor.expression.DSLExpression)1 Binary (com.oracle.truffle.dsl.processor.expression.DSLExpression.Binary)1 Call (com.oracle.truffle.dsl.processor.expression.DSLExpression.Call)1 DSLExpressionReducer (com.oracle.truffle.dsl.processor.expression.DSLExpression.DSLExpressionReducer)1 Negate (com.oracle.truffle.dsl.processor.expression.DSLExpression.Negate)1 Variable (com.oracle.truffle.dsl.processor.expression.DSLExpression.Variable)1 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1