use of org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression 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);
}
}
}
use of org.gradle.language.nativeplatform.internal.incremental.sourceparser.ComplexExpression 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;
}
Aggregations