llvm/clang/lib/Format/UnwrappedLineParser.cpp

//===--- UnwrappedLineParser.cpp - Format C++ code ------------------------===//
//
// 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 file contains the implementation of the UnwrappedLineParser,
/// which turns a stream of tokens into UnwrappedLines.
///
//===----------------------------------------------------------------------===//

#include "UnwrappedLineParser.h"
#include "FormatToken.h"
#include "FormatTokenLexer.h"
#include "FormatTokenSource.h"
#include "Macros.h"
#include "TokenAnnotator.h"
#include "clang/Basic/TokenKinds.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Support/raw_ostream.h"

#include <algorithm>
#include <utility>

#define DEBUG_TYPE

namespace clang {
namespace format {

namespace {

void printLine(llvm::raw_ostream &OS, const UnwrappedLine &Line,
               StringRef Prefix = "", bool PrintText = false) {}

LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line) {}

class ScopedDeclarationState {};

} // end anonymous namespace

std::ostream &operator<<(std::ostream &Stream, const UnwrappedLine &Line) {}

class ScopedLineState {};

class CompoundStatementIndenter {};

UnwrappedLineParser::UnwrappedLineParser(
    SourceManager &SourceMgr, const FormatStyle &Style,
    const AdditionalKeywords &Keywords, unsigned FirstStartColumn,
    ArrayRef<FormatToken *> Tokens, UnwrappedLineConsumer &Callback,
    llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
    IdentifierTable &IdentTable)
    :{}

void UnwrappedLineParser::reset() {}

void UnwrappedLineParser::parse() {}

void UnwrappedLineParser::parseFile() {}

void UnwrappedLineParser::parseCSharpGenericTypeConstraint() {}

void UnwrappedLineParser::parseCSharpAttribute() {}

bool UnwrappedLineParser::precededByCommentOrPPDirective() const {}

/// \brief Parses a level, that is ???.
/// \param OpeningBrace Opening brace (\p nullptr if absent) of that level.
/// \param IfKind The \p if statement kind in the level.
/// \param IfLeftBrace The left brace of the \p if block in the level.
/// \returns true if a simple block of if/else/for/while, or false otherwise.
/// (A simple block has a single statement.)
bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
                                     IfStmtKind *IfKind,
                                     FormatToken **IfLeftBrace) {}

void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {}

// Sets the token type of the directly previous right brace.
void UnwrappedLineParser::setPreviousRBraceType(TokenType Type) {}

template <class T>
static inline void hash_combine(std::size_t &seed, const T &v) {}

size_t UnwrappedLineParser::computePPHash() const {}

// Checks whether \p ParsedLine might fit on a single line. If \p OpeningBrace
// is not null, subtracts its length (plus the preceding space) when computing
// the length of \p ParsedLine. We must clone the tokens of \p ParsedLine before
// running the token annotator on it so that we can restore them afterward.
bool UnwrappedLineParser::mightFitOnOneLine(
    UnwrappedLine &ParsedLine, const FormatToken *OpeningBrace) const {}

FormatToken *UnwrappedLineParser::parseBlock(bool MustBeDeclaration,
                                             unsigned AddLevels, bool MunchSemi,
                                             bool KeepBraces,
                                             IfStmtKind *IfKind,
                                             bool UnindentWhitesmithsBraces) {}

static bool isGoogScope(const UnwrappedLine &Line) {}

static bool isIIFE(const UnwrappedLine &Line,
                   const AdditionalKeywords &Keywords) {}

static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
                                   const FormatToken &InitialToken) {}

void UnwrappedLineParser::parseChildBlock() {}

void UnwrappedLineParser::parsePPDirective() {}

void UnwrappedLineParser::conditionalCompilationCondition(bool Unreachable) {}

void UnwrappedLineParser::conditionalCompilationStart(bool Unreachable) {}

void UnwrappedLineParser::conditionalCompilationAlternative() {}

void UnwrappedLineParser::conditionalCompilationEnd() {}

void UnwrappedLineParser::parsePPIf(bool IfDef) {}

void UnwrappedLineParser::parsePPElse() {}

void UnwrappedLineParser::parsePPEndIf() {}

void UnwrappedLineParser::parsePPDefine() {}

void UnwrappedLineParser::parsePPPragma() {}

void UnwrappedLineParser::parsePPUnknown() {}

// Here we exclude certain tokens that are not usually the first token in an
// unwrapped line. This is used in attempt to distinguish macro calls without
// trailing semicolons from other constructs split to several lines.
static bool tokenCanStartNewLine(const FormatToken &Tok) {}

static bool mustBeJSIdent(const AdditionalKeywords &Keywords,
                          const FormatToken *FormatTok) {}

static bool mustBeJSIdentOrValue(const AdditionalKeywords &Keywords,
                                 const FormatToken *FormatTok) {}

// isJSDeclOrStmt returns true if |FormatTok| starts a declaration or statement
// when encountered after a value (see mustBeJSIdentOrValue).
static bool isJSDeclOrStmt(const AdditionalKeywords &Keywords,
                           const FormatToken *FormatTok) {}

// Checks whether a token is a type in K&R C (aka C78).
static bool isC78Type(const FormatToken &Tok) {}

// This function checks whether a token starts the first parameter declaration
// in a K&R C (aka C78) function definition, e.g.:
//   int f(a, b)
//   short a, b;
//   {
//      return a + b;
//   }
static bool isC78ParameterDecl(const FormatToken *Tok, const FormatToken *Next,
                               const FormatToken *FuncName) {}

bool UnwrappedLineParser::parseModuleImport() {}

// readTokenWithJavaScriptASI reads the next token and terminates the current
// line if JavaScript Automatic Semicolon Insertion must
// happen between the current token and the next token.
//
// This method is conservative - it cannot cover all edge cases of JavaScript,
// but only aims to correctly handle certain well known cases. It *must not*
// return true in speculative cases.
void UnwrappedLineParser::readTokenWithJavaScriptASI() {}

void UnwrappedLineParser::parseStructuralElement(
    const FormatToken *OpeningBrace, IfStmtKind *IfKind,
    FormatToken **IfLeftBrace, bool *HasDoWhile, bool *HasLabel) {}

bool UnwrappedLineParser::tryToParsePropertyAccessor() {}

bool UnwrappedLineParser::tryToParseLambda() {}

bool UnwrappedLineParser::tryToParseLambdaIntroducer() {}

void UnwrappedLineParser::tryToParseJSFunction() {}

bool UnwrappedLineParser::tryToParseBracedList() {}

bool UnwrappedLineParser::tryToParseChildBlock() {}

bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) {}

/// \brief Parses a pair of parentheses (and everything between them).
/// \param AmpAmpTokenType If different than TT_Unknown sets this type for all
/// double ampersands. This applies for all nested scopes as well.
///
/// Returns whether there is a `=` token between the parentheses.
bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {}

void UnwrappedLineParser::parseSquare(bool LambdaIntroducer) {}

void UnwrappedLineParser::keepAncestorBraces() {}

static FormatToken *getLastNonComment(const UnwrappedLine &Line) {}

void UnwrappedLineParser::parseUnbracedBody(bool CheckEOF) {}

static void markOptionalBraces(FormatToken *LeftBrace) {}

void UnwrappedLineParser::handleAttributes() {}

bool UnwrappedLineParser::handleCppAttributes() {}

/// Returns whether \c Tok begins a block.
bool UnwrappedLineParser::isBlockBegin(const FormatToken &Tok) const {}

FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
                                                  bool KeepBraces,
                                                  bool IsVerilogAssert) {}

void UnwrappedLineParser::parseTryCatch() {}

void UnwrappedLineParser::parseNamespace() {}

void UnwrappedLineParser::parseNew() {}

void UnwrappedLineParser::parseLoopBody(bool KeepBraces, bool WrapRightBrace) {}

void UnwrappedLineParser::parseForOrWhileLoop(bool HasParens) {}

void UnwrappedLineParser::parseDoWhile() {}

void UnwrappedLineParser::parseLabel(bool LeftAlignLabel) {}

void UnwrappedLineParser::parseCaseLabel() {}

void UnwrappedLineParser::parseSwitch(bool IsExpr) {}

// Operators that can follow a C variable.
static bool isCOperatorFollowingVar(tok::TokenKind Kind) {}

void UnwrappedLineParser::parseAccessSpecifier() {}

/// \brief Parses a requires, decides if it is a clause or an expression.
/// \pre The current token has to be the requires keyword.
/// \returns true if it parsed a clause.
bool UnwrappedLineParser::parseRequires() {}

/// \brief Parses a requires clause.
/// \param RequiresToken The requires keyword token, which starts this clause.
/// \pre We need to be on the next token after the requires keyword.
/// \sa parseRequiresExpression
///
/// Returns if it either has finished parsing the clause, or it detects, that
/// the clause is incorrect.
void UnwrappedLineParser::parseRequiresClause(FormatToken *RequiresToken) {}

/// \brief Parses a requires expression.
/// \param RequiresToken The requires keyword token, which starts this clause.
/// \pre We need to be on the next token after the requires keyword.
/// \sa parseRequiresClause
///
/// Returns if it either has finished parsing the expression, or it detects,
/// that the expression is incorrect.
void UnwrappedLineParser::parseRequiresExpression(FormatToken *RequiresToken) {}

/// \brief Parses a constraint expression.
///
/// This is the body of a requires clause. It returns, when the parsing is
/// complete, or the expression is incorrect.
void UnwrappedLineParser::parseConstraintExpression() {}

bool UnwrappedLineParser::parseEnum() {}

bool UnwrappedLineParser::parseStructLike() {}

namespace {
// A class used to set and restore the Token position when peeking
// ahead in the token source.
class ScopedTokenPosition {};
} // namespace

// Look to see if we have [[ by looking ahead, if
// its not then rewind to the original position.
bool UnwrappedLineParser::tryToParseSimpleAttribute() {}

void UnwrappedLineParser::parseJavaEnumBody() {}

void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {}

void UnwrappedLineParser::parseObjCMethod() {}

void UnwrappedLineParser::parseObjCProtocolList() {}

void UnwrappedLineParser::parseObjCUntilAtEnd() {}

void UnwrappedLineParser::parseObjCInterfaceOrImplementation() {}

void UnwrappedLineParser::parseObjCLightweightGenerics() {}

// Returns true for the declaration/definition form of @protocol,
// false for the expression form.
bool UnwrappedLineParser::parseObjCProtocol() {}

void UnwrappedLineParser::parseJavaScriptEs6ImportExport() {}

void UnwrappedLineParser::parseStatementMacro() {}

void UnwrappedLineParser::parseVerilogHierarchyIdentifier() {}

void UnwrappedLineParser::parseVerilogSensitivityList() {}

unsigned UnwrappedLineParser::parseVerilogHierarchyHeader() {}

void UnwrappedLineParser::parseVerilogTable() {}

void UnwrappedLineParser::parseVerilogCaseLabel() {}

bool UnwrappedLineParser::containsExpansion(const UnwrappedLine &Line) const {}

void UnwrappedLineParser::addUnwrappedLine(LineLevel AdjustLevel) {}

bool UnwrappedLineParser::eof() const {}

bool UnwrappedLineParser::isOnNewLine(const FormatToken &FormatTok) {}

// Checks if \p FormatTok is a line comment that continues the line comment
// section on \p Line.
static bool
continuesLineCommentSection(const FormatToken &FormatTok,
                            const UnwrappedLine &Line,
                            const llvm::Regex &CommentPragmasRegex) {}

void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) {}

void UnwrappedLineParser::nextToken(int LevelDifference) {}

void UnwrappedLineParser::distributeComments(
    const SmallVectorImpl<FormatToken *> &Comments,
    const FormatToken *NextTok) {}

void UnwrappedLineParser::readToken(int LevelDifference) {}

namespace {
template <typename Iterator>
void pushTokens(Iterator Begin, Iterator End,
                llvm::SmallVectorImpl<FormatToken *> &Into) {}
} // namespace

std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
UnwrappedLineParser::parseMacroCall() {}

void UnwrappedLineParser::pushToken(FormatToken *Tok) {}

} // end namespace format
} // end namespace clang