Search in sources :

Example 1 with Macro

use of org.gradle.language.nativeplatform.internal.Macro 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 Macro

use of org.gradle.language.nativeplatform.internal.Macro 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)

Aggregations

Macro (org.gradle.language.nativeplatform.internal.Macro)2 BufferedReader (java.io.BufferedReader)1 Include (org.gradle.language.nativeplatform.internal.Include)1 IncludeDirectives (org.gradle.language.nativeplatform.internal.IncludeDirectives)1 MacroFunction (org.gradle.language.nativeplatform.internal.MacroFunction)1 SimpleExpression (org.gradle.language.nativeplatform.internal.incremental.sourceparser.SimpleExpression)1