private File findIncludedFile(AstNode ast, Token token, String currFileName) {
String includedFileName = null;
File includedFile = null;
boolean quoted = false;
AstNode node = ast.getFirstDescendant(CppGrammar.includeBodyQuoted);
if(node != null){
includedFileName = stripQuotes(node.getFirstChild().getTokenValue());
quoted = true;
} else if((node = ast.getFirstDescendant(CppGrammar.includeBodyBracketed)) != null) {
node = node.getFirstDescendant(LT).getNextSibling();
StringBuilder sb = new StringBuilder();
while (true) {
String value = node.getTokenValue();
if (value.equals(">")) {
break;
}
sb.append(value);
node = node.getNextSibling();
}
includedFileName = sb.toString();
} else if((node = ast.getFirstDescendant(CppGrammar.includeBodyFreeform)) != null) {
// expand and recurse
String includeBody = serialize(stripEOF(node.getTokens()), "");
String expandedIncludeBody = serialize(stripEOF(CxxLexer.create(this).lex(includeBody)), "");
boolean parseError = false;
AstNode includeBodyAst = null;
try{
includeBodyAst = pplineParser.parse("#include " + expandedIncludeBody);
}
catch(com.sonar.sslr.api.RecognitionException re){
parseError = true;
}
if(parseError || includeBodyAst.getFirstDescendant(CppGrammar.includeBodyFreeform) != null){
LOG.warn("[{}:{}]: cannot parse included filename: {}'",
new Object[] {currFileName, token.getLine(), expandedIncludeBody});
return null;
}