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);
}
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;
}
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);
}
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();
}
}
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);
}
}
}
Aggregations