TT_CtorInitializerColon,
TT_LineComment,
TT_BlockComment,
+ TT_DirectorySeparator,
TT_ObjCMethodSpecifier
};
}
}
+ void parseIncludeDirective() {
+ while (Index < Tokens.size()) {
+ if (Tokens[Index].Tok.is(tok::slash))
+ Annotations[Index].Type = TokenAnnotation::TT_DirectorySeparator;
+ else if (Tokens[Index].Tok.is(tok::less))
+ Annotations[Index].Type = TokenAnnotation::TT_TemplateOpener;
+ else if (Tokens[Index].Tok.is(tok::greater))
+ Annotations[Index].Type = TokenAnnotation::TT_TemplateCloser;
+ next();
+ }
+ }
+
+ void parsePreprocessorDirective() {
+ next();
+ if (Index >= Tokens.size())
+ return;
+ switch (Tokens[Index].Tok.getIdentifierInfo()->getPPKeywordID()) {
+ case tok::pp_include:
+ parseIncludeDirective();
+ break;
+ default:
+ break;
+ }
+ }
+
void parseLine() {
+ if (Tokens[Index].Tok.is(tok::hash)) {
+ parsePreprocessorDirective();
+ return;
+ }
while (Index < Tokens.size()) {
consumeToken();
}
Annotation.SpaceRequiredBefore = Style.SplitTemplateClosingGreater;
else
Annotation.SpaceRequiredBefore = false;
+ } else if (
+ Annotation.Type == TokenAnnotation::TT_DirectorySeparator ||
+ Annotations[i - 1].Type == TokenAnnotation::TT_DirectorySeparator) {
+ Annotation.SpaceRequiredBefore = false;
} else if (
Annotation.Type == TokenAnnotation::TT_BinaryOperator ||
Annotations[i - 1].Type == TokenAnnotation::TT_BinaryOperator) {
}
bool isBinaryOperator(const FormatToken &Tok) {
- // Comma is a binary operator, but does not behave a such wrt. formatting.
+ // Comma is a binary operator, but does not behave as such wrt. formatting.
return getBinOpPrecedence(Tok.Tok.getKind(), true, true) > prec::Comma;
}
}
if (FormatTok.Tok.is(tok::raw_identifier)) {
- const IdentifierInfo &Info = IdentTable.get(tokenText(FormatTok.Tok));
+ IdentifierInfo &Info = IdentTable.get(tokenText(FormatTok.Tok));
+ FormatTok.Tok.setIdentifierInfo(&Info);
FormatTok.Tok.setKind(Info.getTokenID());
}
TEST_F(FormatTest, HandlesIncludeDirectives) {
EXPECT_EQ("#include <string>\n", format("#include <string>\n"));
+ EXPECT_EQ("#include <a/b/c.h>\n", format("#include <a/b/c.h>\n"));
EXPECT_EQ("#include \"a/b/string\"\n", format("#include \"a/b/string\"\n"));
EXPECT_EQ("#include \"string.h\"\n", format("#include \"string.h\"\n"));
EXPECT_EQ("#include \"string.h\"\n", format("#include \"string.h\"\n"));