//===--- Comment.h - Comment AST nodes --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines comment AST nodes.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_COMMENT_H
#define LLVM_CLANG_AST_COMMENT_H
#include "clang/Basic/SourceLocation.h"
#include "clang/AST/Type.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
namespace clang {
class Decl;
class ParmVarDecl;
class TemplateParameterList;
namespace comments {
/// Any part of the comment.
/// Abstract class.
class Comment {
protected:
/// Preferred location to show caret.
SourceLocation Loc;
/// Source range of this AST node.
SourceRange Range;
class CommentBitfields {
friend class Comment;
/// Type of this AST node.
unsigned Kind : 8;
};
enum { NumCommentBits = 8 };
class InlineContentCommentBitfields {
friend class InlineContentComment;
unsigned : NumCommentBits;
/// True if there is a newline after this inline content node.
/// (There is no separate AST node for a newline.)
unsigned HasTrailingNewline : 1;
};
enum { NumInlineContentCommentBits = NumCommentBits + 1 };
class TextCommentBitfields {
friend class TextComment;
unsigned : NumInlineContentCommentBits;
/// True if \c IsWhitespace field contains a valid value.
mutable unsigned IsWhitespaceValid : 1;
/// True if this comment AST node contains only whitespace.
mutable unsigned IsWhitespace : 1;
};
enum { NumTextCommentBits = NumInlineContentCommentBits + 2 };
class InlineCommandCommentBitfields {
friend class InlineCommandComment;
unsigned : NumInlineContentCommentBits;
unsigned RenderKind : 2;
};
enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 1 };
class HTMLStartTagCommentBitfields {
friend class HTMLStartTagComment;
unsigned : NumInlineContentCommentBits;
/// True if this tag is self-closing (e. g., <br />). This is based on tag
/// spelling in comment (plain <br> would not set this flag).
unsigned IsSelfClosing : 1;
};
enum { NumHTMLStartTagCommentBits = NumInlineContentCommentBits + 1 };
class ParagraphCommentBitfields {
friend class ParagraphComment;
unsigned : NumCommentBits;
/// True if \c IsWhitespace field contains a valid value.
mutable unsigned IsWhitespaceValid : 1;
/// True if this comment AST node contains only whitespace.
mutable unsigned IsWhitespace : 1;
};
enum { NumParagraphCommentBits = NumCommentBits + 2 };
class ParamCommandCommentBitfields {
friend class ParamCommandComment;
unsigned : NumCommentBits;
/// Parameter passing direction, see ParamCommandComment::PassDirection.
unsigned Direction : 2;
/// True if direction was specified explicitly in the comment.
unsigned IsDirectionExplicit : 1;
};
enum { NumParamCommandCommentBits = 11 };
union {
CommentBitfields CommentBits;
InlineContentCommentBitfields InlineContentCommentBits;
TextCommentBitfields TextCommentBits;
InlineCommandCommentBitfields InlineCommandCommentBits;
HTMLStartTagCommentBitfields HTMLStartTagCommentBits;
ParagraphCommentBitfields ParagraphCommentBits;
ParamCommandCommentBitfields ParamCommandCommentBits;
};
void setSourceRange(SourceRange SR) {
Range = SR;
}
void setLocation(SourceLocation L) {
Loc = L;
}
public:
enum CommentKind {
NoCommentKind = 0,
#define COMMENT(CLASS, PARENT) CLASS##Kind,
#define COMMENT_RANGE(BASE, FIRST, LAST) \
First##BASE##Constant=FIRST##Kind, Last##BASE##Constant=LAST##Kind,
#define LAST_COMMENT_RANGE(BASE, FIRST, LAST) \
First##BASE##Constant=FIRST##Kind, Last##BASE##Constant=LAST##Kind
#define ABSTRACT_COMMENT(COMMENT)
#include "clang/AST/CommentNodes.inc"
};
Comment(CommentKind K,
SourceLocation LocBegin,
SourceLocation LocEnd) :
Loc(LocBegin), Range(SourceRange(LocBegin, LocEnd)) {
CommentBits.Kind = K;
}
CommentKind getCommentKind() const {
return static_cast<CommentKind>(CommentBits.Kind);
}
const char *getCommentKindName() const;
LLVM_ATTRIBUTE_USED void dump() const;
LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
void dump(llvm::raw_ostream &OS, SourceManager *SM) const;
static bool classof(const Comment *) { return