Search in sources :

Example 1 with MacroFunction

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));
}
Also used : MacroFunction(org.gradle.language.nativeplatform.internal.MacroFunction) Macro(org.gradle.language.nativeplatform.internal.Macro) BufferedReader(java.io.BufferedReader) Include(org.gradle.language.nativeplatform.internal.Include)

Example 2 with MacroFunction

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

Aggregations

MacroFunction (org.gradle.language.nativeplatform.internal.MacroFunction)2 BufferedReader (java.io.BufferedReader)1 Expression (org.gradle.language.nativeplatform.internal.Expression)1 Include (org.gradle.language.nativeplatform.internal.Include)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 SimpleExpression (org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression)1