// Every identifier and every keyword can be a macro instance.
// Pipe the resulting string through a lexer to create proper Tokens
// and to expand recursively all macros which may be in there.
//
PreprocessorAction ppaction = PreprocessorAction.NO_OPERATION;
Macro macro = macros.get(curr.getValue());
if (macro != null) {
List<Token> replTokens = new LinkedList<Token>();
int tokensConsumed = 0;
List<Token> arguments = new ArrayList<Token>();
if (macro.params == null) {
tokensConsumed = 1;
replTokens = expandMacro(macro.name, serialize(evaluateHashhashOperators(macro.body)));
}
else {
int tokensConsumedMatchingArgs = expandFunctionLikeMacro(macro.name,
tokens.subList(1, tokens.size()),
replTokens);
if (tokensConsumedMatchingArgs > 0) {
tokensConsumed = 1 + tokensConsumedMatchingArgs;
}
}
if (tokensConsumed > 0) {
replTokens = reallocate(replTokens, curr);
LOG.trace("[{}:{}]: replacing '" + curr.getValue()
+ (arguments.isEmpty()
? ""
: "(" + serialize(arguments, ", ") + ")") + "' -> '" + serialize(replTokens) + "'",
filename, curr.getLine());
ppaction = new PreprocessorAction(
tokensConsumed,
Lists.newArrayList(Trivia.createSkippedText(tokens.subList(0, tokensConsumed))),
replTokens);
}
}