Skip to content

Commit a05117d

Browse files
committed
✨ [Sema, Driver, Lex, Frontend] Implement naive #embed for C23 and C++26.
Superfluous formatting changes
1 parent 0b4b6a6 commit a05117d

File tree

13 files changed

+657
-651
lines changed

13 files changed

+657
-651
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ def : DiagGroup<"strict-aliasing=1">;
721721
def : DiagGroup<"strict-aliasing=2">;
722722
def : DiagGroup<"strict-aliasing">;
723723

724+
724725
// Just silence warnings about -Wstrict-overflow for now.
725726
def : DiagGroup<"strict-overflow=0">;
726727
def : DiagGroup<"strict-overflow=1">;

clang/include/clang/Lex/PPCallbacks.h

Lines changed: 43 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
#include "llvm/ADT/StringRef.h"
2323

2424
namespace clang {
25-
class Token;
26-
class IdentifierInfo;
27-
class MacroDefinition;
28-
class MacroDirective;
29-
class MacroArgs;
25+
class Token;
26+
class IdentifierInfo;
27+
class MacroDefinition;
28+
class MacroDirective;
29+
class MacroArgs;
3030

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

39-
enum FileChangeReason {
40-
EnterFile, ExitFile, SystemHeaderPragma, RenameFile
41-
};
39+
enum FileChangeReason { EnterFile, ExitFile, SystemHeaderPragma, RenameFile };
4240

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

5350
enum class LexedFileChangeReason { EnterFile, ExitFile };
5451

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

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

208205
/// Callback invoked whenever there was an explicit module-import
209206
/// syntax.
@@ -215,49 +212,40 @@ class PPCallbacks {
215212
///
216213
/// \param Imported The imported module; can be null if importing failed.
217214
///
218-
virtual void moduleImport(SourceLocation ImportLoc,
219-
ModuleIdPath Path,
220-
const Module *Imported) {
221-
}
215+
virtual void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
216+
const Module *Imported) {}
222217

223218
/// Callback invoked when the end of the main file is reached.
224219
///
225220
/// No subsequent callbacks will be made.
226-
virtual void EndOfMainFile() {
227-
}
221+
virtual void EndOfMainFile() {}
228222

229223
/// Callback invoked when a \#ident or \#sccs directive is read.
230224
/// \param Loc The location of the directive.
231225
/// \param str The text of the directive.
232226
///
233-
virtual void Ident(SourceLocation Loc, StringRef str) {
234-
}
227+
virtual void Ident(SourceLocation Loc, StringRef str) {}
235228

236229
/// Callback invoked when start reading any pragma directive.
237230
virtual void PragmaDirective(SourceLocation Loc,
238-
PragmaIntroducerKind Introducer) {
239-
}
231+
PragmaIntroducerKind Introducer) {}
240232

241233
/// Callback invoked when a \#pragma comment directive is read.
242234
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
243-
StringRef Str) {
244-
}
235+
StringRef Str) {}
245236

246237
/// Callback invoked when a \#pragma mark comment is read.
247-
virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {
248-
}
238+
virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {}
249239

250240
/// Callback invoked when a \#pragma detect_mismatch directive is
251241
/// read.
252242
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
253-
StringRef Value) {
254-
}
243+
StringRef Value) {}
255244

256245
/// Callback invoked when a \#pragma clang __debug directive is read.
257246
/// \param Loc The location of the debug directive.
258247
/// \param DebugType The identifier following __debug.
259-
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) {
260-
}
248+
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType) {}
261249

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

283270
/// Callback invoked when a \#pragma gcc diagnostic push directive
284271
/// is read.
285-
virtual void PragmaDiagnosticPush(SourceLocation Loc,
286-
StringRef Namespace) {
287-
}
272+
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) {}
288273

289274
/// Callback invoked when a \#pragma gcc diagnostic pop directive
290275
/// is read.
291-
virtual void PragmaDiagnosticPop(SourceLocation Loc,
292-
StringRef Namespace) {
293-
}
276+
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) {}
294277

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

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

322304
/// Callback invoked when a \#pragma warning(push) directive is read.
323-
virtual void PragmaWarningPush(SourceLocation Loc, int Level) {
324-
}
305+
virtual void PragmaWarningPush(SourceLocation Loc, int Level) {}
325306

326307
/// Callback invoked when a \#pragma warning(pop) directive is read.
327-
virtual void PragmaWarningPop(SourceLocation Loc) {
328-
}
308+
virtual void PragmaWarningPop(SourceLocation Loc) {}
329309

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

352332
/// Hook called whenever a macro definition is seen.
353333
virtual void MacroDefined(const Token &MacroNameTok,
354-
const MacroDirective *MD) {
355-
}
334+
const MacroDirective *MD) {}
356335

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

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

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

393-
enum ConditionValueKind {
394-
CVK_NotEvaluated, CVK_False, CVK_True
395-
};
369+
enum ConditionValueKind { CVK_NotEvaluated, CVK_False, CVK_True };
396370

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

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

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

425396
/// Hook called whenever an \#elifdef branch is taken.
426397
/// \param Loc the source location of the directive.
427398
/// \param MacroNameTok Information on the token being tested.
428399
/// \param MD The MacroDefinition if the name was a macro, null otherwise.
429400
virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
430-
const MacroDefinition &MD) {
431-
}
401+
const MacroDefinition &MD) {}
432402
/// Hook called whenever an \#elifdef is skipped.
433403
/// \param Loc the source location of the directive.
434404
/// \param ConditionRange The SourceRange of the expression being tested.
435405
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
436406
// FIXME: better to pass in a list (or tree!) of Tokens.
437407
virtual void Elifdef(SourceLocation Loc, SourceRange ConditionRange,
438-
SourceLocation IfLoc) {
439-
}
408+
SourceLocation IfLoc) {}
440409

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

449417
/// Hook called whenever an \#elifndef branch is taken.
450418
/// \param Loc the source location of the directive.
451419
/// \param MacroNameTok Information on the token being tested.
452420
/// \param MD The MacroDefinition if the name was a macro, null otherwise.
453421
virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
454-
const MacroDefinition &MD) {
455-
}
422+
const MacroDefinition &MD) {}
456423
/// Hook called whenever an \#elifndef is skipped.
457424
/// \param Loc the source location of the directive.
458425
/// \param ConditionRange The SourceRange of the expression being tested.
459426
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
460427
// FIXME: better to pass in a list (or tree!) of Tokens.
461428
virtual void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
462-
SourceLocation IfLoc) {
463-
}
429+
SourceLocation IfLoc) {}
464430

465431
/// Hook called whenever an \#else is seen.
466432
/// \param Loc the source location of the directive.
467433
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
468-
virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {
469-
}
434+
virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {}
470435

471436
/// Hook called whenever an \#endif is seen.
472437
/// \param Loc the source location of the directive.
473438
/// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive.
474-
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {
475-
}
439+
virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {}
476440
};
477441

478442
/// Simple wrapper class for chaining callbacks.
@@ -482,7 +446,7 @@ class PPChainedCallbacks : public PPCallbacks {
482446
public:
483447
PPChainedCallbacks(std::unique_ptr<PPCallbacks> _First,
484448
std::unique_ptr<PPCallbacks> _Second)
485-
: First(std::move(_First)), Second(std::move(_Second)) {}
449+
: First(std::move(_First)), Second(std::move(_Second)) {}
486450

487451
~PPChainedCallbacks() override;
488452

@@ -692,8 +656,7 @@ class PPChainedCallbacks : public PPCallbacks {
692656
Second->MacroDefined(MacroNameTok, MD);
693657
}
694658

695-
void MacroUndefined(const Token &MacroNameTok,
696-
const MacroDefinition &MD,
659+
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
697660
const MacroDirective *Undef) override {
698661
First->MacroUndefined(MacroNameTok, MD, Undef);
699662
Second->MacroUndefined(MacroNameTok, MD, Undef);
@@ -759,7 +722,7 @@ class PPChainedCallbacks : public PPCallbacks {
759722
}
760723
/// Hook called whenever an \#elifndef is skipped.
761724
void Elifndef(SourceLocation Loc, SourceRange ConditionRange,
762-
SourceLocation IfLoc) override {
725+
SourceLocation IfLoc) override {
763726
First->Elifndef(Loc, ConditionRange, IfLoc);
764727
Second->Elifndef(Loc, ConditionRange, IfLoc);
765728
}
@@ -777,6 +740,6 @@ class PPChainedCallbacks : public PPCallbacks {
777740
}
778741
};
779742

780-
} // end namespace clang
743+
} // end namespace clang
781744

782745
#endif

0 commit comments

Comments
 (0)