#ifndef LLVM_CLANG_LEX_DEPENDENCYDIRECTIVESSCANNER_H
#define LLVM_CLANG_LEX_DEPENDENCYDIRECTIVESSCANNER_H
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/ArrayRef.h"
namespace clang {
namespace tok {
enum TokenKind : unsigned short;
}
class DiagnosticsEngine;
namespace dependency_directives_scan {
struct Token {
unsigned Offset;
unsigned Length;
tok::TokenKind Kind;
unsigned short Flags;
Token(unsigned Offset, unsigned Length, tok::TokenKind Kind,
unsigned short Flags)
: Offset(Offset), Length(Length), Kind(Kind), Flags(Flags) {}
unsigned getEnd() const { return Offset + Length; }
bool is(tok::TokenKind K) const { return Kind == K; }
bool isNot(tok::TokenKind K) const { return Kind != K; }
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
return is(K1) || is(K2);
}
template <typename... Ts> bool isOneOf(tok::TokenKind K1, Ts... Ks) const {
return is(K1) || isOneOf(Ks...);
}
};
enum DirectiveKind : uint8_t {
pp_none,
pp_include,
pp___include_macros,
pp_define,
pp_undef,
pp_import,
pp_pragma_import,
pp_pragma_once,
pp_pragma_push_macro,
pp_pragma_pop_macro,
pp_pragma_include_alias,
pp_include_next,
pp_if,
pp_ifdef,
pp_ifndef,
pp_elif,
pp_elifdef,
pp_elifndef,
pp_else,
pp_endif,
decl_at_import,
cxx_module_decl,
cxx_import_decl,
cxx_export_module_decl,
cxx_export_import_decl,
pp_eof,
};
struct Directive {
ArrayRef<Token> Tokens;
DirectiveKind Kind = pp_none;
Directive() = default;
Directive(DirectiveKind K, ArrayRef<Token> Tokens)
: Tokens(Tokens), Kind(K) {}
};
}
bool scanSourceForDependencyDirectives(
StringRef Input, SmallVectorImpl<dependency_directives_scan::Token> &Tokens,
SmallVectorImpl<dependency_directives_scan::Directive> &Directives,
DiagnosticsEngine *Diags = nullptr,
SourceLocation InputSourceLoc = SourceLocation());
void printDependencyDirectivesAsSource(
StringRef Source,
ArrayRef<dependency_directives_scan::Directive> Directives,
llvm::raw_ostream &OS);
}
#endif