//===--- Format.cpp - Format C++ code -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file implements functions declared in Format.h. This will be
/// split into separate files as we go.
///
/// This is EXPERIMENTAL code under heavy development. It is not in a state yet,
/// where it can be used to format real code.
///
//===----------------------------------------------------------------------===//
#include "clang/Format/Format.h"
#include "UnwrappedLineParser.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/OperatorPrecedence.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Lex/Lexer.h"
#include <string>
namespace clang {
namespace format {
enum TokenType {
TT_BinaryOperator,
TT_BlockComment,
TT_CastRParen,
TT_ConditionalExpr,
TT_CtorInitializerColon,
TT_DirectorySeparator,
TT_LineComment,
TT_ObjCBlockLParen,
TT_ObjCDecl,
TT_ObjCMethodSpecifier,
TT_ObjCProperty,
TT_OverloadedOperator,
TT_PointerOrReference,
TT_PureVirtualSpecifier,
TT_TemplateCloser,
TT_TemplateOpener,
TT_TrailingUnaryOperator,
TT_UnaryOperator,
TT_Unknown
};
enum LineType {
LT_Invalid,
LT_Other,
LT_PreprocessorDirective,
LT_VirtualFunctionDecl,
LT_ObjCDecl, // An @interface, @implementation, or @protocol line.
LT_ObjCMethodDecl,
LT_ObjCProperty // An @property line.
};
class AnnotatedToken {
public:
AnnotatedToken(const FormatToken &FormatTok)
: FormatTok(FormatTok), Type(TT_Unknown), SpaceRequiredBefore(false),
CanBreakBefore(false), MustBreakBefore(false),
ClosesTemplateDeclaration(false), Parent(NULL) {}
bool is(tok::TokenKind Kind) const {
return FormatTok.Tok.is(Kind);
}
bool isNot(tok::TokenKind Kind) const {
return FormatTok.Tok.isNot(Kind);
}
bool isObjCAtKeyword(tok::ObjCKeywordKind Kind) const {
return FormatTok.