Skip to content

Commit

Permalink
apply suggestions from git-clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Oct 14, 2023
1 parent 748c3b5 commit b6d053e
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 78 deletions.
9 changes: 4 additions & 5 deletions clang/include/clang/AST/Expr.h
Expand Up @@ -4819,13 +4819,12 @@ class PPEmbedExpr final : public Expr {
Expanded,
};

PPEmbedExpr(const ASTContext &Ctx, QualType ResultTy, StringLiteral* Filename, StringLiteral* BinaryData,
SourceLocation BLoc, SourceLocation RParenLoc,
DeclContext *Context);
PPEmbedExpr(const ASTContext &Ctx, QualType ResultTy, StringLiteral *Filename,
StringLiteral *BinaryData, SourceLocation BLoc,
SourceLocation RParenLoc, DeclContext *Context);

/// Build an empty call expression.
explicit PPEmbedExpr(EmptyShell Empty)
: Expr(SourceLocExprClass, Empty) {}
explicit PPEmbedExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {}

/// If the PPEmbedExpr has been resolved return the subexpression
/// representing the resolved value. Otherwise return null.
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/FileManager.h
Expand Up @@ -282,8 +282,9 @@ class FileManager : public RefCountedBase<FileManager> {
getBufferForFile(StringRef Filename, bool isVolatile = false,
bool RequiresNullTerminator = true,
std::optional<int64_t> MaybeLimit = std::nullopt) {
return getBufferForFileImpl(Filename, /*FileSize=*/(MaybeLimit ? *MaybeLimit : -1), isVolatile,
RequiresNullTerminator);
return getBufferForFileImpl(Filename,
/*FileSize=*/(MaybeLimit ? *MaybeLimit : -1),
isVolatile, RequiresNullTerminator);
}

private:
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Frontend/PreprocessorOutputOptions.h
Expand Up @@ -22,7 +22,8 @@ class PreprocessorOutputOptions {
unsigned ShowMacroComments : 1; ///< Show comments, even in macros.
unsigned ShowMacros : 1; ///< Print macro definitions.
unsigned ShowIncludeDirectives : 1; ///< Print includes, imports etc. within preprocessed output.
unsigned ShowEmbedDirectives : 1; ///< Print embeds, etc. within preprocessed output.
unsigned ShowEmbedDirectives : 1; ///< Print embeds, etc. within preprocessed
///< output.
unsigned RewriteIncludes : 1; ///< Preprocess include directives only.
unsigned RewriteImports : 1; ///< Include contents of transitively-imported modules.
unsigned MinimizeWhitespace : 1; ///< Ignore whitespace from input.
Expand Down
12 changes: 6 additions & 6 deletions clang/include/clang/Lex/PPEmbedParameters.h
Expand Up @@ -13,8 +13,8 @@
#ifndef LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H
#define LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H

#include "clang/Lex/Token.h"
#include "clang/Lex/PPDirectiveParameter.h"
#include "clang/Lex/Token.h"
#include "llvm/ADT/SmallVector.h"

namespace clang {
Expand All @@ -25,7 +25,8 @@ class PPEmbedParameterOffset : public PPDirectiveParameter {
public:
size_t Offset;

PPEmbedParameterOffset(size_t Offset, SourceLocation Start, SourceLocation End)
PPEmbedParameterOffset(size_t Offset, SourceLocation Start,
SourceLocation End)
: Offset(Offset), PPDirectiveParameter(Start, End) {}
};

Expand All @@ -35,8 +36,7 @@ class PPEmbedParameterLimit : public PPDirectiveParameter {
public:
size_t Limit;

PPEmbedParameterLimit(size_t Limit, SourceLocation Start,
SourceLocation End)
PPEmbedParameterLimit(size_t Limit, SourceLocation Start, SourceLocation End)
: Limit(Limit), PPDirectiveParameter(Start, End) {}
};

Expand All @@ -47,7 +47,7 @@ class PPEmbedParameterPrefix : public PPDirectiveParameter {
SmallVector<Token, 2> Tokens;

PPEmbedParameterPrefix(SmallVector<Token, 2> Tokens, SourceLocation Start,
SourceLocation End)
SourceLocation End)
: Tokens(std::move(Tokens)), PPDirectiveParameter(Start, End) {}
};

Expand All @@ -58,7 +58,7 @@ class PPEmbedParameterSuffix : public PPDirectiveParameter {
SmallVector<Token, 2> Tokens;

PPEmbedParameterSuffix(SmallVector<Token, 2> Tokens, SourceLocation Start,
SourceLocation End)
SourceLocation End)
: Tokens(std::move(Tokens)), PPDirectiveParameter(Start, End) {}
};

Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Lex/Preprocessor.h
Expand Up @@ -1816,7 +1816,8 @@ class Preprocessor {
/// Parses a simple integer literal to get its numeric value. Floating
/// point literals and user defined literals are rejected. Used primarily to
/// handle pragmas that accept integer arguments.
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, bool WithLex = true);
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value,
bool WithLex = true);

/// Disables macro expansion everywhere except for preprocessor directives.
void SetMacroExpansionOnlyInDirectives() {
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Sema/Sema.h
Expand Up @@ -6130,7 +6130,8 @@ class Sema final {
StringRef GetLocationName(PPEmbedExprContext Context) const;

bool DiagnosePPEmbedExpr(Expr *&E, SourceLocation ContextLocation,
PPEmbedExprContext Context, bool SingleAllowed = true);
PPEmbedExprContext Context,
bool SingleAllowed = true);

// Build a potentially resolved SourceLocExpr.
ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
Expand Down
15 changes: 7 additions & 8 deletions clang/lib/AST/Expr.cpp
Expand Up @@ -2330,19 +2330,18 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
}

PPEmbedExpr::PPEmbedExpr(const ASTContext &Ctx, QualType ResultTy,
StringLiteral *Filename,
StringLiteral *BinaryData,
SourceLocation BLoc,
SourceLocation RParenLoc,
DeclContext *ParentContext)
StringLiteral *Filename, StringLiteral *BinaryData,
SourceLocation BLoc, SourceLocation RParenLoc,
DeclContext *ParentContext)
: Expr(PPEmbedExprClass, ResultTy, VK_PRValue, OK_Ordinary),
BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext), Filename(Filename), BinaryData(BinaryData) {
BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext),
Filename(Filename), BinaryData(BinaryData) {
setDependence(ExprDependence::None);
}

size_t PPEmbedExpr::getDataElementCount(ASTContext &Context) const {
return getDataStringLiteral()->getByteLength() /
(Context.getTypeSize(getType()) / Context.getTypeSize(Context.CharTy));
return getDataStringLiteral()->getByteLength() /
(Context.getTypeSize(getType()) / Context.getTypeSize(Context.CharTy));
}

InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/ExprClassification.cpp
Expand Up @@ -205,7 +205,8 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) {
return Cl::CL_PRValue;

case Expr::PPEmbedExprClass:
// Nominally, this just goes through as a PRValue until we actually expand it and check it.
// Nominally, this just goes through as a PRValue until we actually expand
// it and check it.
return Cl::CL_PRValue;

// Make HLSL this reference-like
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/AST/StmtProfile.cpp
Expand Up @@ -2284,9 +2284,7 @@ void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
VisitExpr(E);
}

void StmtProfiler::VisitPPEmbedExpr(const PPEmbedExpr *E) {
VisitExpr(E);
}
void StmtProfiler::VisitPPEmbedExpr(const PPEmbedExpr *E) { VisitExpr(E); }

void StmtProfiler::VisitRecoveryExpr(const RecoveryExpr *E) { VisitExpr(E); }

Expand Down
1 change: 0 additions & 1 deletion clang/lib/Basic/FileManager.cpp
Expand Up @@ -549,7 +549,6 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
if (MaybeLimit)
FileSize = *MaybeLimit;


// If there's a high enough chance that the file have changed since we
// got its size, force a stat before opening it.
if (isVolatile || Entry->isNamedPipe())
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Basic/IdentifierTable.cpp
Expand Up @@ -422,8 +422,8 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
// collisions (if there were, the switch below would complain about duplicate
// case values). Note that this depends on 'if' being null terminated.

#define HASH(LEN, FIRST, THIRD) \
(LEN << 6) + (((FIRST-'a') - (THIRD-'a')) & 63)
#define HASH(LEN, FIRST, THIRD) \
(LEN << 6) + (((FIRST - 'a') - (THIRD - 'a')) & 63)
#define CASE(LEN, FIRST, THIRD, NAME) \
case HASH(LEN, FIRST, THIRD): \
return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
Expand All @@ -438,7 +438,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
CASE( 4, 'e', 's', else);
CASE( 4, 'l', 'n', line);
CASE( 4, 's', 'c', sccs);
CASE( 5, 'e', 'b', embed);
CASE(5, 'e', 'b', embed);
CASE( 5, 'e', 'd', endif);
CASE( 5, 'e', 'r', error);
CASE( 5, 'i', 'e', ident);
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Expand Up @@ -1324,7 +1324,8 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,

Args.AddAllArgs(CmdArgs,
{options::OPT_D, options::OPT_U, options::OPT_I_Group,
options::OPT_F, options::OPT_index_header_map, options::OPT_EmbedPath_Group});
options::OPT_F, options::OPT_index_header_map,
options::OPT_EmbedPath_Group});

// Add -Wp, and -Xpreprocessor if using the preprocessor.

Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -1399,8 +1399,7 @@ class AnnotatingParser {
if (Tok->isOneOf(Keywords.kw___has_include,
Keywords.kw___has_include_next)) {
parseHasInclude();
}
else if (Tok->is(Keywords.kw___has_embed)) {
} else if (Tok->is(Keywords.kw___has_embed)) {
parseHasEmbed();
}
if (Style.isCSharp() && Tok->is(Keywords.kw_where) && Tok->Next &&
Expand Down
15 changes: 7 additions & 8 deletions clang/lib/Frontend/DependencyFile.cpp
Expand Up @@ -65,11 +65,11 @@ struct DepCollectorPPCallbacks : public PPCallbacks {
/*IsMissing=*/false);
}

void EmbedDirective(SourceLocation HashLoc,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange, CharSourceRange ParametersRange,
OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath) override {
void EmbedDirective(SourceLocation HashLoc, StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
CharSourceRange ParametersRange,
OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath) override {
if (!File)
DepCollector.maybeAddDependency(FileName,
/*FromModule*/ false,
Expand Down Expand Up @@ -97,14 +97,13 @@ struct DepCollectorPPCallbacks : public PPCallbacks {
}

void HasEmbed(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled,
OptionalFileEntryRef File) override {
OptionalFileEntryRef File) override {
if (!File)
return;
StringRef Filename =
llvm::sys::path::remove_leading_dotslash(File->getName());
DepCollector.maybeAddDependency(Filename,
/*FromModule=*/false,
false,
/*FromModule=*/false, false,
/*IsModuleFile=*/false,
&PP.getFileManager(),
/*IsMissing=*/false);
Expand Down
14 changes: 8 additions & 6 deletions clang/lib/Frontend/PrintPreprocessedOutput.cpp
Expand Up @@ -107,9 +107,10 @@ class PrintPPOutputPPCallbacks : public PPCallbacks {

public:
PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream *os, bool lineMarkers,
bool defines, bool DumpIncludeDirectives, bool DumpEmbedDirectives,
bool UseLineDirectives, bool MinimizeWhitespace,
bool DirectivesOnly, bool KeepSystemIncludes)
bool defines, bool DumpIncludeDirectives,
bool DumpEmbedDirectives, bool UseLineDirectives,
bool MinimizeWhitespace, bool DirectivesOnly,
bool KeepSystemIncludes)
: PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
DisableLineMarkers(lineMarkers), DumpDefines(defines),
DumpIncludeDirectives(DumpIncludeDirectives),
Expand Down Expand Up @@ -414,7 +415,7 @@ void PrintPPOutputPPCallbacks::EmbedDirective(
if (DumpEmbedDirectives) {
MoveToLine(HashLoc, /*RequireStartOfLine=*/true);
*OS << "#embed " << (IsAngled ? '<' : '"') << FileName
<< (IsAngled ? '>' : '"') << " /* clang -E -dE */";
<< (IsAngled ? '>' : '"') << " /* clang -E -dE */";
setEmittedDirectiveOnThisLine();
}
}
Expand Down Expand Up @@ -1002,8 +1003,9 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,

PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(
PP, OS, !Opts.ShowLineMarkers, Opts.ShowMacros,
Opts.ShowIncludeDirectives, Opts.ShowEmbedDirectives, Opts.UseLineDirectives,
Opts.MinimizeWhitespace, Opts.DirectivesOnly, Opts.KeepSystemIncludes);
Opts.ShowIncludeDirectives, Opts.ShowEmbedDirectives,
Opts.UseLineDirectives, Opts.MinimizeWhitespace, Opts.DirectivesOnly,
Opts.KeepSystemIncludes);

// Expand macros in pragmas with -fms-extensions. The assumption is that
// the majority of pragmas in such a file will be Microsoft pragmas.
Expand Down
16 changes: 8 additions & 8 deletions clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
Expand Up @@ -463,27 +463,27 @@ void InclusionRewriter::Process(FileID FileId,
// Add line marker to indicate we're returning from an included
// file.
LineInfoExtra = " 2";
}
// fix up lineinfo (since commented out directive changed line
// numbers) for inclusions that were skipped due to header guards
WriteLineInfo(FileName, Line, FileType, LineInfoExtra);
break;
}
// fix up lineinfo (since commented out directive changed line
// numbers) for inclusions that were skipped due to header guards
WriteLineInfo(FileName, Line, FileType, LineInfoExtra);
break;
}
case tok::pp_pragma: {
StringRef Identifier = NextIdentifierName(RawLex, RawToken);
if (Identifier == "clang" || Identifier == "GCC") {
if (NextIdentifierName(RawLex, RawToken) == "system_header") {
// keep the directive in, commented out
CommentOutDirective(RawLex, HashToken, FromFile, LocalEOL,
NextToWrite, Line);
NextToWrite, Line);
// update our own type
FileType = SM.getFileCharacteristic(RawToken.getLocation());
WriteLineInfo(FileName, Line, FileType);
}
} else if (Identifier == "once") {
// keep the directive in, commented out
CommentOutDirective(RawLex, HashToken, FromFile, LocalEOL,
NextToWrite, Line);
NextToWrite, Line);
WriteLineInfo(FileName, Line, FileType);
}
break;
Expand Down Expand Up @@ -535,7 +535,7 @@ void InclusionRewriter::Process(FileID FileId,
OutputContentUpTo(FromFile, NextToWrite,
SM.getFileOffset(RawToken.getLocation()) +
RawToken.getLength(),
LocalEOL, Line, /*EnsureNewline=*/ true);
LocalEOL, Line, /*EnsureNewline=*/true);
WriteLineInfo(FileName, Line, FileType);
RawLex.SetKeepWhitespaceMode(false);
break;
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Lex/PPMacroExpansion.cpp
Expand Up @@ -1321,7 +1321,8 @@ int Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) {
SourceLocation FilenameLoc = Tok.getLocation();
Token FilenameTok = Tok;

Preprocessor::LexEmbedParametersResult Params = this->LexEmbedParameters(Tok, true, false);
Preprocessor::LexEmbedParametersResult Params =
this->LexEmbedParameters(Tok, true, false);
if (!Params.Successful) {
if (Tok.isNot(tok::eod))
this->DiscardUntilEndOfDirective();
Expand All @@ -1339,7 +1340,6 @@ int Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) {
return VALUE__STDC_EMBED_NOT_FOUND__;
}


SmallString<128> FilenameBuffer;
SmallString<256> RelativePath;
StringRef Filename = this->getSpelling(FilenameTok, FilenameBuffer);
Expand All @@ -1351,11 +1351,10 @@ int Preprocessor::EvaluateHasEmbed(Token &Tok, IdentifierInfo *II) {
assert(!Filename.empty());
const FileEntry *LookupFromFile =
this->getCurrentFileLexer() ? this->getCurrentFileLexer()->getFileEntry()
: nullptr;
: nullptr;
OptionalFileEntryRef MaybeFileEntry =
this->LookupEmbedFile(FilenameLoc, Filename, isAngled, false,
LookupFromFile, nullptr,
&RelativePath);
LookupFromFile, nullptr, &RelativePath);
if (Callbacks) {
Callbacks->HasEmbed(LParenLoc, Filename, isAngled, MaybeFileEntry);
}
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Lex/Preprocessor.cpp
Expand Up @@ -1411,7 +1411,8 @@ bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String,
return true;
}

bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, bool WithLex) {
bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value,
bool WithLex) {
assert(Tok.is(tok::numeric_constant));
SmallString<8> IntegerBuffer;
bool NumberInvalid = false;
Expand All @@ -1427,7 +1428,7 @@ bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value, bool W
if (Literal.GetIntegerValue(APVal))
return false;
if (WithLex)
Lex(Tok);
Lex(Tok);
Value = APVal.getLimitedValue();
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Parse/ParseExpr.cpp
Expand Up @@ -1059,9 +1059,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
isVectorLiteral, NotPrimaryExpression);

case tok::identifier:
ParseIdentifier: { // primary-expression: identifier
// unqualified-id: identifier
// constant: enumeration-constant
ParseIdentifier: { // primary-expression: identifier
// unqualified-id: identifier
// constant: enumeration-constant
// Turn a potentially qualified name into a annot_typename or
// annot_cxxscope if it would be valid. This handles things like x::y, etc.
if (getLangOpts().CPlusPlus) {
Expand Down Expand Up @@ -2915,7 +2915,7 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() {
}
const auto OnDecodeError = [&](const llvm::ErrorInfoBase &) {
Diag(Base64Str->getExprLoc(),
diag::err_builtin_pp_embed_invalid_argument)
diag::err_builtin_pp_embed_invalid_argument)
<< "expected a valid base64 encoded string";
};
llvm::Error Err = llvm::decodeBase64(Base64Str->getBytes(), BinaryData);
Expand Down

0 comments on commit b6d053e

Please sign in to comment.