Search in sources :

Example 1 with Expression

use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.

the class ArgsMappingMacroFunction method evaluate.

@Override
public Expression evaluate(List<Expression> arguments) {
    List<Expression> mapped = new ArrayList<Expression>(this.arguments.size());
    int currentMapPos = 0;
    for (Expression argument : this.arguments) {
        currentMapPos = mapInto(argument, arguments, currentMapPos, mapped);
    }
    return new ComplexExpression(type, value, mapped);
}
Also used : Expression(org.gradle.language.nativeplatform.internal.Expression) ArrayList(java.util.ArrayList)

Example 2 with Expression

use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.

the class RegexBackedCSourceParser method parseDirectiveBodyExpression.

/**
 * Parses an expression that forms the body of a directive. Consumes all of the input.
 */
private static Expression parseDirectiveBodyExpression(Buffer buffer) {
    int startPos = buffer.pos;
    Expression expression = parseExpression(buffer);
    buffer.consumeWhitespace();
    if (expression == null || buffer.hasAny()) {
        // Unrecognized expression or extra stuff after the expression, possibly another expression
        return new SimpleExpression(buffer.substring(startPos).trim(), IncludeType.OTHER);
    }
    return expression;
}
Also used : Expression(org.gradle.language.nativeplatform.internal.Expression)

Example 3 with Expression

use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.

the class RegexBackedCSourceParser method readArgument.

private static Expression readArgument(Buffer buffer) {
    Expression expression = parseExpression(buffer);
    if (expression == null) {
        return null;
    }
    buffer.consumeWhitespace();
    if (buffer.hasAny(",)")) {
        return expression;
    }
    List<Expression> expressions = new ArrayList<Expression>();
    expressions.add(expression);
    do {
        expression = parseExpression(buffer);
        if (expression == null) {
            return null;
        }
        expressions.add(expression);
        buffer.consumeWhitespace();
    } while (!buffer.hasAny(",)"));
    return new ComplexExpression(IncludeType.EXPRESSIONS, null, expressions);
}
Also used : Expression(org.gradle.language.nativeplatform.internal.Expression) ArrayList(java.util.ArrayList)

Example 4 with Expression

use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.

the class DefaultSourceIncludesResolver method resolveMacroFunction.

private void resolveMacroFunction(MacroLookup visibleMacros, Expression expression, ExpressionVisitor visitor, TokenLookup tokenLookup) {
    boolean found = false;
    for (IncludeDirectives includeDirectives : visibleMacros) {
        Iterable<MacroFunction> macroFunctions = includeDirectives.getMacroFunctions(expression.getValue());
        for (MacroFunction macro : macroFunctions) {
            List<Expression> arguments = expression.getArguments();
            if (arguments.isEmpty() && macro.getParameterCount() == 1) {
                // Provide an implicit empty argument
                arguments = Collections.singletonList(SimpleExpression.EMPTY_EXPRESSIONS);
            }
            if (macro.getParameterCount() == arguments.size()) {
                found = true;
                Expression result = macro.evaluate(arguments);
                resolveExpression(visibleMacros, result, visitor, tokenLookup);
            }
        }
    }
    if (!found) {
        visitor.visitUnresolved();
    }
}
Also used : IncludeDirectives(org.gradle.language.nativeplatform.internal.IncludeDirectives) MacroFunction(org.gradle.language.nativeplatform.internal.MacroFunction) Expression(org.gradle.language.nativeplatform.internal.Expression) ComplexExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression) SimpleExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression)

Example 5 with Expression

use of org.gradle.language.nativeplatform.internal.Expression in project gradle by gradle.

the class DefaultSourceIncludesResolver method resolveExpressionSequenceForArgs.

private void resolveExpressionSequenceForArgs(MacroLookup visibleMacros, List<Expression> expressions, Expression args, ExpressionVisitor visitor, TokenLookup tokenLookup) {
    if (args.getType() != IncludeType.ARGS_LIST) {
        visitor.visitUnresolved();
        return;
    }
    Expression macroFunctionExpression = expressions.get(expressions.size() - 1);
    List<Expression> headExpressions = expressions.subList(0, expressions.size() - 1);
    Collection<Expression> identifiers = resolveExpressionToTokens(visibleMacros, macroFunctionExpression, visitor, tokenLookup);
    for (Expression value : identifiers) {
        if (value.getType() != IncludeType.IDENTIFIER) {
            visitor.visitUnresolved();
            continue;
        }
        ComplexExpression macroExpression = new ComplexExpression(IncludeType.MACRO_FUNCTION, value.getValue(), args.getArguments());
        if (headExpressions.isEmpty()) {
            resolveExpression(visibleMacros, macroExpression, visitor, tokenLookup);
            return;
        }
        Collection<Expression> resolved = resolveExpressionToTokens(visibleMacros, macroExpression, visitor, tokenLookup);
        for (Expression newArgs : resolved) {
            resolveExpressionSequenceForArgs(visibleMacros, headExpressions, newArgs, visitor, tokenLookup);
        }
    }
}
Also used : Expression(org.gradle.language.nativeplatform.internal.Expression) ComplexExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression) SimpleExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression) ComplexExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression)

Aggregations

Expression (org.gradle.language.nativeplatform.internal.Expression)13 ArrayList (java.util.ArrayList)5 ComplexExpression (org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression)4 SimpleExpression (org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression)4 Nullable (javax.annotation.Nullable)1 IncludeDirectives (org.gradle.language.nativeplatform.internal.IncludeDirectives)1 MacroFunction (org.gradle.language.nativeplatform.internal.MacroFunction)1