Search in sources :

Example 1 with SimpleExpression

use of org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression in project gradle by gradle.

the class DefaultSourceIncludesResolver method resolveMacro.

private void resolveMacro(MacroLookup visibleMacros, Expression expression, ExpressionVisitor visitor, TokenLookup tokenLookup) {
    boolean found = false;
    for (IncludeDirectives includeDirectives : visibleMacros) {
        Iterable<Macro> macros = includeDirectives.getMacros(expression.getValue());
        for (Macro macro : macros) {
            found = true;
            resolveExpression(visibleMacros, macro, visitor, tokenLookup);
        }
    }
    if (!found) {
        visitor.visitIdentifier(new SimpleExpression(expression.getValue(), IncludeType.IDENTIFIER));
    }
}
Also used : IncludeDirectives(org.gradle.language.nativeplatform.internal.IncludeDirectives) Macro(org.gradle.language.nativeplatform.internal.Macro) SimpleExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression)

Example 2 with SimpleExpression

use of org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression in project gradle by gradle.

the class DefaultSourceIncludesResolver method resolveTokenConcatenationToTokens.

private Collection<Expression> resolveTokenConcatenationToTokens(MacroLookup visibleMacros, Expression expression, ExpressionVisitor visitor, TokenLookup tokenLookup) {
    Expression left = expression.getArguments().get(0);
    Expression right = expression.getArguments().get(1);
    Collection<Expression> leftValues = resolveExpressionToTokens(visibleMacros, left, visitor, tokenLookup);
    Collection<Expression> rightValues = resolveExpressionToTokens(visibleMacros, right, visitor, tokenLookup);
    if (leftValues.isEmpty() || rightValues.isEmpty()) {
        return Collections.emptyList();
    }
    List<Expression> expressions = new ArrayList<Expression>(leftValues.size() * rightValues.size());
    for (Expression leftValue : leftValues) {
        if (leftValue.getType() != IncludeType.IDENTIFIER) {
            if (rightValues.size() == 1) {
                Expression rightValue = rightValues.iterator().next();
                if (rightValue.getType() == IncludeType.EXPRESSIONS && rightValue.getArguments().isEmpty()) {
                    // Empty RHS
                    expressions.add(leftValue);
                    continue;
                }
            }
            // Not supported for now
            visitor.visitUnresolved();
            continue;
        }
        String leftString = leftValue.getValue();
        for (Expression rightValue : rightValues) {
            // Handle just empty string, single identifier or '(' params? ')', should handle more by parsing the tokens into an expression
            if (rightValue.getType() == IncludeType.IDENTIFIER) {
                expressions.add(new SimpleExpression(leftString + rightValue.getValue(), IncludeType.IDENTIFIER));
                continue;
            }
            if (rightValue.getType() == IncludeType.ARGS_LIST) {
                expressions.add(new ComplexExpression(IncludeType.MACRO_FUNCTION, leftString, rightValue.getArguments()));
                continue;
            }
            if (rightValue.getType() == IncludeType.EXPRESSIONS && rightValue.getArguments().isEmpty()) {
                expressions.add(new SimpleExpression(leftString, IncludeType.IDENTIFIER));
                continue;
            }
            visitor.visitUnresolved();
        }
    }
    return expressions;
}
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) ArrayList(java.util.ArrayList) SimpleExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression) ComplexExpression(org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression)

Aggregations

SimpleExpression (org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression)2 ArrayList (java.util.ArrayList)1 Expression (org.gradle.language.nativeplatform.internal.Expression)1 IncludeDirectives (org.gradle.language.nativeplatform.internal.IncludeDirectives)1 Macro (org.gradle.language.nativeplatform.internal.Macro)1 ComplexExpression (org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression)1