use of org.gradle.language.nativeplatform.internal.MacroFunction in project gradle by gradle.
the class RegexBackedCSourceParser method parseSource.
protected IncludeDirectives parseSource(Reader sourceReader) throws IOException {
Set<Include> includes = Sets.newLinkedHashSet();
List<Macro> macros = Lists.newArrayList();
List<MacroFunction> macroFunctions = Lists.newArrayList();
BufferedReader reader = new BufferedReader(sourceReader);
PreprocessingReader lineReader = new PreprocessingReader(reader);
Buffer buffer = new Buffer();
while (true) {
buffer.reset();
if (!lineReader.readNextLine(buffer.value)) {
break;
}
buffer.consumeWhitespace();
if (!buffer.consume('#')) {
continue;
}
buffer.consumeWhitespace();
if (buffer.consume("define")) {
parseDefineDirectiveBody(buffer, macros, macroFunctions);
} else if (buffer.consume("include")) {
parseIncludeOrImportDirectiveBody(buffer, false, includes);
} else if (buffer.consume("import")) {
parseIncludeOrImportDirectiveBody(buffer, true, includes);
}
}
return new DefaultIncludeDirectives(ImmutableList.copyOf(includes), ImmutableList.copyOf(macros), ImmutableList.copyOf(macroFunctions));
}
use of org.gradle.language.nativeplatform.internal.MacroFunction 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();
}
}
Aggregations