summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.h
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-04 07:21:18 +0000
committerDaniel Jasper <djasper@google.com>2013-02-04 07:21:18 +0000
commit3a9370cbca9145696eafdc7c8b9849371eecfe01 (patch)
treed0a24274cfa47fabe551227bbb9265c84a054316 /clang/lib/Format/TokenAnnotator.h
parent1f5a71492de40dcb9d150815c84506842b3d17b8 (diff)
downloadbcm5719-llvm-3a9370cbca9145696eafdc7c8b9849371eecfe01.tar.gz
bcm5719-llvm-3a9370cbca9145696eafdc7c8b9849371eecfe01.zip
Restructuring of token annotation for formatting.
This combines several changes: * Calculation token type (e.g. for * and &) in the AnnotatingParser. * Calculate the scope binding strength in the AnnotatingParser. * Let <> and [] scopes bind stronger than () and {} scopes. * Add minimal debugging output. llvm-svn: 174307
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.h')
-rw-r--r--clang/lib/Format/TokenAnnotator.h46
1 files changed, 7 insertions, 39 deletions
diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h
index 5ffa2c4f297..0386b88f913 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -69,7 +69,7 @@ public:
: FormatTok(FormatTok), Type(TT_Unknown), SpaceRequiredBefore(false),
CanBreakBefore(false), MustBreakBefore(false),
ClosesTemplateDeclaration(false), MatchingParen(NULL),
- ParameterCount(1), Parent(NULL) {
+ ParameterCount(1), BindingStrength(0), SplitPenalty(0), Parent(NULL) {
}
bool is(tok::TokenKind Kind) const { return FormatTok.Tok.is(Kind); }
@@ -101,6 +101,11 @@ public:
/// \brief The total length of the line up to and including this token.
unsigned TotalLength;
+ // FIXME: Come up with a 'cleaner' concept.
+ /// \brief The binding strength of a token. This is a combined value of
+ /// operator precedence, parenthesis nesting, etc.
+ unsigned BindingStrength;
+
/// \brief Penalty for inserting a line break before this token.
unsigned SplitPenalty;
@@ -166,48 +171,12 @@ public:
}
void annotate();
- void calculateExtraInformation(AnnotatedToken &Current);
+ void calculateFormattingInformation(AnnotatedToken &Current);
private:
/// \brief Calculate the penalty for splitting before \c Tok.
unsigned splitPenalty(const AnnotatedToken &Tok);
- void determineTokenTypes(AnnotatedToken &Current, bool IsExpression,
- bool LookForFunctionName);
-
- /// \brief Starting from \p Current, this searches backwards for an
- /// identifier which could be the start of a function name and marks it.
- void findFunctionName(AnnotatedToken *Current);
-
- /// \brief Returns the previous token ignoring comments.
- const AnnotatedToken *getPreviousToken(const AnnotatedToken &Tok) {
- const AnnotatedToken *PrevToken = Tok.Parent;
- while (PrevToken != NULL && PrevToken->is(tok::comment))
- PrevToken = PrevToken->Parent;
- return PrevToken;
- }
-
- /// \brief Returns the next token ignoring comments.
- const AnnotatedToken *getNextToken(const AnnotatedToken &Tok) {
- if (Tok.Children.empty())
- return NULL;
- const AnnotatedToken *NextToken = &Tok.Children[0];
- while (NextToken->is(tok::comment)) {
- if (NextToken->Children.empty())
- return NULL;
- NextToken = &NextToken->Children[0];
- }
- return NextToken;
- }
-
- /// \brief Return the type of the given token assuming it is * or &.
- TokenType determineStarAmpUsage(const AnnotatedToken &Tok, bool IsExpression);
-
- TokenType determinePlusMinusCaretUsage(const AnnotatedToken &Tok);
-
- /// \brief Determine whether ++/-- are pre- or post-increments/-decrements.
- TokenType determineIncrementUsage(const AnnotatedToken &Tok);
-
bool spaceRequiredBetween(const AnnotatedToken &Left,
const AnnotatedToken &Right);
@@ -221,7 +190,6 @@ private:
AnnotatedLine &Line;
};
-
} // end namespace format
} // end namespace clang
OpenPOWER on IntegriCloud