Skip to content

Commit

Permalink
✨ [Sema, Driver, Lex, Frontend] Implement naive #embed for C23 and C+…
Browse files Browse the repository at this point in the history
…+26.

Superfluous formatting changes
  • Loading branch information
h-vetinari committed Oct 14, 2023
1 parent 0b4b6a6 commit a05117d
Show file tree
Hide file tree
Showing 13 changed files with 657 additions and 651 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Expand Up @@ -721,6 +721,7 @@ def : DiagGroup<"strict-aliasing=1">;
def : DiagGroup<"strict-aliasing=2">;
def : DiagGroup<"strict-aliasing">;


// Just silence warnings about -Wstrict-overflow for now.
def : DiagGroup<"strict-overflow=0">;
def : DiagGroup<"strict-overflow=1">;
Expand Down
123 changes: 43 additions & 80 deletions clang/include/clang/Lex/PPCallbacks.h
Expand Up @@ -22,11 +22,11 @@
#include "llvm/ADT/StringRef.h"

namespace clang {
class Token;
class IdentifierInfo;
class MacroDefinition;
class MacroDirective;
class MacroArgs;
class Token;
class IdentifierInfo;
class MacroDefinition;
class MacroDirective;
class MacroArgs;

/// This interface provides a way to observe the actions of the
/// preprocessor as it does its thing.
Expand All @@ -36,9 +36,7 @@ class PPCallbacks {
public:
virtual ~PPCallbacks();

enum FileChangeReason {
EnterFile, ExitFile, SystemHeaderPragma, RenameFile
};
enum FileChangeReason { EnterFile, ExitFile, SystemHeaderPragma, RenameFile };

/// Callback invoked whenever a source file is entered or exited.
///
Expand All @@ -47,8 +45,7 @@ class PPCallbacks {
/// the file before the new one entered for \p Reason EnterFile.
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID = FileID()) {
}
FileID PrevFID = FileID()) {}

enum class LexedFileChangeReason { EnterFile, ExitFile };

Expand Down Expand Up @@ -192,7 +189,7 @@ class PPCallbacks {
/// \param ForPragma If entering from pragma directive.
///
virtual void EnteredSubmodule(Module *M, SourceLocation ImportLoc,
bool ForPragma) { }
bool ForPragma) {}

/// Callback invoked whenever a submodule was left.
///
Expand All @@ -203,7 +200,7 @@ class PPCallbacks {
/// \param ForPragma If entering from pragma directive.
///
virtual void LeftSubmodule(Module *M, SourceLocation ImportLoc,
bool ForPragma) { }
bool ForPragma) {}

/// Callback invoked whenever there was an explicit module-import
/// syntax.
Expand All @@ -215,49 +212,40 @@ class PPCallbacks {
///
/// \param Imported The imported module; can be null if importing failed.
///
virtual void moduleImport(SourceLocation ImportLoc,
ModuleIdPath Path,
const Module *Imported) {
}
virtual void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
const Module *Imported) {}

/// Callback invoked when the end of the main file is reached.
///
/// No subsequent callbacks will be made.
virtual void EndOfMainFile() {
}
virtual void EndOfMainFile() {}

/// Callback invoked when a \#ident or \#sccs directive is read.
/// \param Loc The location of the directive.
/// \param str The text of the directive.
///
virtual void Ident(SourceLocation Loc, StringRef str) {
}
virtual void Ident(SourceLocation Loc, StringRef str) {}

/// Callback invoked when start reading any pragma directive.
virtual void PragmaDirective(SourceLocation Loc,
PragmaIntroducerKind Introducer) {
}
PragmaIntroducerKind Introducer) {}

/// Callback invoked when a \#pragma comment directive is read.
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
StringRef Str) {
}
StringRef Str) {}

/// Callback invoked when a \#pragma mark comment is read.
virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {
}
virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {}

/// Callback invoked when a \#pragma detect_mismatch directive is
/// read.
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
StringRef Value) {
}
StringRef Value) {}

/// Callback invoked when a \#pragma clang __debug directive is read.
/// \param Loc The location of the debug directive.
/// \param DebugType The identifier following __debug.
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) {
}
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) {}

/// Determines the kind of \#pragma invoking a call to PragmaMessage.
enum PragmaMessageKind {
Expand All @@ -277,20 +265,15 @@ class PPCallbacks {
/// \param Kind The type of the message directive.
/// \param Str The text of the message directive.
virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace,
PragmaMessageKind Kind, StringRef Str) {
}
PragmaMessageKind Kind, StringRef Str) {}

/// Callback invoked when a \#pragma gcc diagnostic push directive
/// is read.
virtual void PragmaDiagnosticPush(SourceLocation Loc,
StringRef Namespace) {
}
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) {}

/// Callback invoked when a \#pragma gcc diagnostic pop directive
/// is read.
virtual void PragmaDiagnosticPop(SourceLocation Loc,
StringRef Namespace) {
}
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) {}

/// Callback invoked when a \#pragma gcc diagnostic directive is read.
virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
Expand All @@ -300,8 +283,7 @@ class PPCallbacks {
/// enabled with a pragma.
virtual void PragmaOpenCLExtension(SourceLocation NameLoc,
const IdentifierInfo *Name,
SourceLocation StateLoc, unsigned State) {
}
SourceLocation StateLoc, unsigned State) {}

/// Callback invoked when a \#pragma warning directive is read.
enum PragmaWarningSpecifier {
Expand All @@ -320,12 +302,10 @@ class PPCallbacks {
ArrayRef<int> Ids) {}

/// Callback invoked when a \#pragma warning(push) directive is read.
virtual void PragmaWarningPush(SourceLocation Loc, int Level) {
}
virtual void PragmaWarningPush(SourceLocation Loc, int Level) {}

/// Callback invoked when a \#pragma warning(pop) directive is read.
virtual void PragmaWarningPop(SourceLocation Loc) {
}
virtual void PragmaWarningPop(SourceLocation Loc) {}

/// Callback invoked when a \#pragma execution_character_set(push) directive
/// is read.
Expand All @@ -351,8 +331,7 @@ class PPCallbacks {

/// Hook called whenever a macro definition is seen.
virtual void MacroDefined(const Token &MacroNameTok,
const MacroDirective *MD) {
}
const MacroDirective *MD) {}

/// Hook called whenever a macro \#undef is seen.
/// \param MacroNameTok The active Token
Expand All @@ -362,14 +341,12 @@ class PPCallbacks {
/// MD is released immediately following this callback.
virtual void MacroUndefined(const Token &MacroNameTok,
const MacroDefinition &MD,
const MacroDirective *Undef) {
}
const MacroDirective *Undef) {}

/// Hook called whenever the 'defined' operator is seen.
/// \param MD The MacroDirective if the name was a macro, null otherwise.
virtual void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
SourceRange Range) {
}
SourceRange Range) {}

/// Hook called when a '__has_embed' directive is read.
virtual void HasEmbed(SourceLocation Loc, StringRef FileName, bool IsAngled,
Expand All @@ -387,12 +364,9 @@ class PPCallbacks {
/// \param EndifLoc The end location of the 'endif' token, which may precede
/// the range skipped by the directive (e.g excluding comments after an
/// 'endif').
virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) {
}
virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) {}

enum ConditionValueKind {
CVK_NotEvaluated, CVK_False, CVK_True
};
enum ConditionValueKind { CVK_NotEvaluated, CVK_False, CVK_True };

/// Hook called whenever an \#if is seen.
/// \param Loc the source location of the directive.
Expand All @@ -401,8 +375,7 @@ class PPCallbacks {
///
// FIXME: better to pass in a list (or tree!) of Tokens.
virtual void If(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue) {
}
ConditionValueKind ConditionValue) {}

/// Hook called whenever an \#elif is seen.
/// \param Loc the source location of the directive.
Expand All @@ -411,68 +384,59 @@ class PPCallbacks {
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
// FIXME: better to pass in a list (or tree!) of Tokens.
virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue, SourceLocation IfLoc) {
}
ConditionValueKind ConditionValue, SourceLocation IfLoc) {}

/// Hook called whenever an \#ifdef is seen.
/// \param Loc the source location of the directive.
/// \param MacroNameTok Information on the token being tested.
/// \param MD The MacroDefinition if the name was a macro, null otherwise.
virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) {
}
const MacroDefinition &MD) {}

/// Hook called whenever an \#elifdef branch is taken.
/// \param Loc the source location of the directive.
/// \param MacroNameTok Information on the token being tested.
/// \param MD The MacroDefinition if the name was a macro, null otherwise.
virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) {
}
const MacroDefinition &MD) {}
/// Hook called whenever an \#elifdef is skipped.
/// \param Loc the source location of the directive.
/// \param ConditionRange The SourceRange of the expression being tested.
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
// FIXME: better to pass in a list (or tree!) of Tokens.
virtual void Elifdef(SourceLocation Loc, SourceRange ConditionRange,
SourceLocation IfLoc) {
}
SourceLocation IfLoc) {}

/// Hook called whenever an \#ifndef is seen.
/// \param Loc the source location of the directive.
/// \param MacroNameTok Information on the token being tested.
/// \param MD The MacroDefiniton if the name was a macro, null otherwise.
virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) {
}
const MacroDefinition &MD) {}

/// Hook called whenever an \#elifndef branch is taken.
/// \param Loc the source location of the directive.
/// \param MacroNameTok Information on the token being tested.
/// \param MD The MacroDefinition if the name was a macro, null otherwise.
virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) {
}
const MacroDefinition &MD) {}
/// Hook called whenever an \#elifndef is skipped.
/// \param Loc the source location of the directive.
/// \param ConditionRange The SourceRange of the expression being tested.
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
// FIXME: better to pass in a list (or tree!) of Tokens.
virtual void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
SourceLocation IfLoc) {
}
SourceLocation IfLoc) {}

/// Hook called whenever an \#else is seen.
/// \param Loc the source location of the directive.
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {
}
virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {}

/// Hook called whenever an \#endif is seen.
/// \param Loc the source location of the directive.
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {
}
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {}
};

/// Simple wrapper class for chaining callbacks.
Expand All @@ -482,7 +446,7 @@ class PPChainedCallbacks : public PPCallbacks {
public:
PPChainedCallbacks(std::unique_ptr<PPCallbacks> _First,
std::unique_ptr<PPCallbacks> _Second)
: First(std::move(_First)), Second(std::move(_Second)) {}
: First(std::move(_First)), Second(std::move(_Second)) {}

~PPChainedCallbacks() override;

Expand Down Expand Up @@ -692,8 +656,7 @@ class PPChainedCallbacks : public PPCallbacks {
Second->MacroDefined(MacroNameTok, MD);
}

void MacroUndefined(const Token &MacroNameTok,
const MacroDefinition &MD,
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
const MacroDirective *Undef) override {
First->MacroUndefined(MacroNameTok, MD, Undef);
Second->MacroUndefined(MacroNameTok, MD, Undef);
Expand Down Expand Up @@ -759,7 +722,7 @@ class PPChainedCallbacks : public PPCallbacks {
}
/// Hook called whenever an \#elifndef is skipped.
void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
SourceLocation IfLoc) override {
SourceLocation IfLoc) override {
First->Elifndef(Loc, ConditionRange, IfLoc);
Second->Elifndef(Loc, ConditionRange, IfLoc);
}
Expand All @@ -777,6 +740,6 @@ class PPChainedCallbacks : public PPCallbacks {
}
};

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

#endif

0 comments on commit a05117d

Please sign in to comment.