//===- clang/Lex/DependencyDirectivesScanner.h ---------------------*- C++ -*-// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// \file /// This is the interface for scanning header and source files to get the /// minimum necessary preprocessor directives for evaluating includes. It /// reduces the source down to #define, #include, #import, @import, and any /// conditional preprocessor logic that contains one of those. /// //===----------------------------------------------------------------------===// #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 { /// Token lexed as part of dependency directive scanning. struct Token { … }; /// Represents the kind of preprocessor directive or a module declaration that /// is tracked by the scanner in its token output. enum DirectiveKind : uint8_t { … }; /// Represents a directive that's lexed as part of the dependency directives /// scanning. It's used to track various preprocessor directives that could /// potentially have an effect on the dependencies. struct Directive { … }; } // end namespace dependency_directives_scan /// Scan the input for the preprocessor directives that might have /// an effect on the dependencies for a compilation unit. /// /// This function ignores all non-preprocessor code and anything that /// can't affect what gets included. /// /// \returns false on success, true on error. If the diagnostic engine is not /// null, an appropriate error is reported using the given input location /// with the offset that corresponds to the \p Input buffer offset. bool scanSourceForDependencyDirectives( StringRef Input, SmallVectorImpl<dependency_directives_scan::Token> &Tokens, SmallVectorImpl<dependency_directives_scan::Directive> &Directives, DiagnosticsEngine *Diags = nullptr, SourceLocation InputSourceLoc = SourceLocation()); /// Print the previously scanned dependency directives as minimized source text. /// /// \param Source The original source text that the dependency directives were /// scanned from. /// \param Directives The previously scanned dependency /// directives. /// \param OS the stream to print the dependency directives on. /// /// This is used primarily for testing purposes, during dependency scanning the /// \p Lexer uses the tokens directly, not their printed version. void printDependencyDirectivesAsSource( StringRef Source, ArrayRef<dependency_directives_scan::Directive> Directives, llvm::raw_ostream &OS); } // end namespace clang #endif // LLVM_CLANG_LEX_DEPENDENCYDIRECTIVESSCANNER_H