llvm/clang/lib/Lex/DependencyDirectivesScanner.cpp

//===- DependencyDirectivesScanner.cpp ------------------------------------===//
//
// 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.
///
//===----------------------------------------------------------------------===//

#include "clang/Lex/DependencyDirectivesScanner.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Lex/LexDiagnostic.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Pragma.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSwitch.h"
#include <optional>

usingnamespaceclang;
usingnamespaceclang::dependency_directives_scan;
usingnamespacellvm;

namespace {

struct DirectiveWithTokens {};

/// Does an efficient "scan" of the sources to detect the presence of
/// preprocessor (or module import) directives and collects the raw lexed tokens
/// for those directives so that the \p Lexer can "replay" them when the file is
/// included.
///
/// Note that the behavior of the raw lexer is affected by the language mode,
/// while at this point we want to do a scan and collect tokens once,
/// irrespective of the language mode that the file will get included in. To
/// compensate for that the \p Lexer, while "replaying", will adjust a token
/// where appropriate, when it could affect the preprocessor's state.
/// For example in a directive like
///
/// \code
///   #if __has_cpp_attribute(clang::fallthrough)
/// \endcode
///
/// The preprocessor needs to see '::' as 'tok::coloncolon' instead of 2
/// 'tok::colon'. The \p Lexer will adjust if it sees consecutive 'tok::colon'
/// while in C++ mode.
struct Scanner {};

} // end anonymous namespace

bool Scanner::reportError(const char *CurPtr, unsigned Err) {}

static void skipOverSpaces(const char *&First, const char *const End) {}

[[nodiscard]] static bool isRawStringLiteral(const char *First,
                                             const char *Current) {}

static void skipRawString(const char *&First, const char *const End) {}

// Returns the length of EOL, either 0 (no end-of-line), 1 (\n) or 2 (\r\n)
static unsigned isEOL(const char *First, const char *const End) {}

static void skipString(const char *&First, const char *const End) {}

// Returns the length of the skipped newline
static unsigned skipNewline(const char *&First, const char *End) {}

static bool wasLineContinuation(const char *First, unsigned EOLLen) {}

static void skipToNewlineRaw(const char *&First, const char *const End) {}

static void skipLineComment(const char *&First, const char *const End) {}

static void skipBlockComment(const char *&First, const char *const End) {}

/// \returns True if the current single quotation mark character is a C++14
/// digit separator.
static bool isQuoteCppDigitSeparator(const char *const Start,
                                     const char *const Cur,
                                     const char *const End) {}

void Scanner::skipLine(const char *&First, const char *const End) {}

void Scanner::skipDirective(StringRef Name, const char *&First,
                            const char *const End) {}

static void skipWhitespace(const char *&First, const char *const End) {}

bool Scanner::lexModuleDirectiveBody(DirectiveKind Kind, const char *&First,
                                     const char *const End) {}

dependency_directives_scan::Token &Scanner::lexToken(const char *&First,
                                                     const char *const End) {}

dependency_directives_scan::Token &
Scanner::lexIncludeFilename(const char *&First, const char *const End) {}

void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) {}

StringRef
Scanner::cleanStringIfNeeded(const dependency_directives_scan::Token &Tok) {}

std::optional<StringRef>
Scanner::tryLexIdentifierOrSkipLine(const char *&First, const char *const End) {}

StringRef Scanner::lexIdentifier(const char *&First, const char *const End) {}

bool Scanner::isNextIdentifierOrSkipLine(StringRef Id, const char *&First,
                                         const char *const End) {}

bool Scanner::isNextTokenOrSkipLine(tok::TokenKind K, const char *&First,
                                    const char *const End) {}

std::optional<StringRef>
Scanner::tryLexStringLiteralOrSkipLine(const char *&First,
                                       const char *const End) {}

bool Scanner::lexAt(const char *&First, const char *const End) {}

bool Scanner::lexModule(const char *&First, const char *const End) {}

bool Scanner::lex_Pragma(const char *&First, const char *const End) {}

bool Scanner::lexPragma(const char *&First, const char *const End) {}

bool Scanner::lexEndif(const char *&First, const char *const End) {}

bool Scanner::lexDefault(DirectiveKind Kind, const char *&First,
                         const char *const End) {}

static bool isStartOfRelevantLine(char First) {}

bool Scanner::lexPPLine(const char *&First, const char *const End) {}

static void skipUTF8ByteOrderMark(const char *&First, const char *const End) {}

bool Scanner::scanImpl(const char *First, const char *const End) {}

bool Scanner::scan(SmallVectorImpl<Directive> &Directives) {}

bool clang::scanSourceForDependencyDirectives(
    StringRef Input, SmallVectorImpl<dependency_directives_scan::Token> &Tokens,
    SmallVectorImpl<Directive> &Directives, DiagnosticsEngine *Diags,
    SourceLocation InputSourceLoc) {}

void clang::printDependencyDirectivesAsSource(
    StringRef Source,
    ArrayRef<dependency_directives_scan::Directive> Directives,
    llvm::raw_ostream &OS) {}