Skip to content

Commit 44f49b5

Browse files
authored
[NFC] Move RegisterBuiltinMacro function into the Preprocessor class (#100142)
The `RegisterBuiltinMacro` function has been moved to the Preprocessor class for accessibility and has been refactored for readability.
1 parent c2b61fc commit 44f49b5

File tree

2 files changed

+47
-49
lines changed

2 files changed

+47
-49
lines changed

clang/include/clang/Lex/Preprocessor.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,19 @@ class Preprocessor {
26172617
/// \#pragma GCC poison/system_header/dependency and \#pragma once.
26182618
void RegisterBuiltinPragmas();
26192619

2620+
/// RegisterBuiltinMacro - Register the specified identifier in the identifier
2621+
/// table and mark it as a builtin macro to be expanded.
2622+
IdentifierInfo *RegisterBuiltinMacro(const char *Name) {
2623+
// Get the identifier.
2624+
IdentifierInfo *Id = getIdentifierInfo(Name);
2625+
2626+
// Mark it as being a macro that is builtin.
2627+
MacroInfo *MI = AllocateMacroInfo(SourceLocation());
2628+
MI->setIsBuiltinMacro();
2629+
appendDefMacroDirective(Id, MI);
2630+
return Id;
2631+
}
2632+
26202633
/// Register builtin macros such as __LINE__ with the identifier table.
26212634
void RegisterBuiltinMacros();
26222635

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -323,84 +323,69 @@ void Preprocessor::dumpMacroInfo(const IdentifierInfo *II) {
323323
}
324324
}
325325

326-
/// RegisterBuiltinMacro - Register the specified identifier in the identifier
327-
/// table and mark it as a builtin macro to be expanded.
328-
static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char *Name){
329-
// Get the identifier.
330-
IdentifierInfo *Id = PP.getIdentifierInfo(Name);
331-
332-
// Mark it as being a macro that is builtin.
333-
MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());
334-
MI->setIsBuiltinMacro();
335-
PP.appendDefMacroDirective(Id, MI);
336-
return Id;
337-
}
338-
339326
/// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the
340327
/// identifier table.
341328
void Preprocessor::RegisterBuiltinMacros() {
342-
Ident__LINE__ = RegisterBuiltinMacro(*this, "__LINE__");
343-
Ident__FILE__ = RegisterBuiltinMacro(*this, "__FILE__");
344-
Ident__DATE__ = RegisterBuiltinMacro(*this, "__DATE__");
345-
Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
346-
Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
347-
Ident_Pragma = RegisterBuiltinMacro(*this, "_Pragma");
348-
Ident__FLT_EVAL_METHOD__ = RegisterBuiltinMacro(*this, "__FLT_EVAL_METHOD__");
329+
Ident__LINE__ = RegisterBuiltinMacro("__LINE__");
330+
Ident__FILE__ = RegisterBuiltinMacro("__FILE__");
331+
Ident__DATE__ = RegisterBuiltinMacro("__DATE__");
332+
Ident__TIME__ = RegisterBuiltinMacro("__TIME__");
333+
Ident__COUNTER__ = RegisterBuiltinMacro("__COUNTER__");
334+
Ident_Pragma = RegisterBuiltinMacro("_Pragma");
335+
Ident__FLT_EVAL_METHOD__ = RegisterBuiltinMacro("__FLT_EVAL_METHOD__");
349336

350337
// C++ Standing Document Extensions.
351338
if (getLangOpts().CPlusPlus)
352-
Ident__has_cpp_attribute =
353-
RegisterBuiltinMacro(*this, "__has_cpp_attribute");
339+
Ident__has_cpp_attribute = RegisterBuiltinMacro("__has_cpp_attribute");
354340
else
355341
Ident__has_cpp_attribute = nullptr;
356342

357343
// GCC Extensions.
358-
Ident__BASE_FILE__ = RegisterBuiltinMacro(*this, "__BASE_FILE__");
359-
Ident__INCLUDE_LEVEL__ = RegisterBuiltinMacro(*this, "__INCLUDE_LEVEL__");
360-
Ident__TIMESTAMP__ = RegisterBuiltinMacro(*this, "__TIMESTAMP__");
344+
Ident__BASE_FILE__ = RegisterBuiltinMacro("__BASE_FILE__");
345+
Ident__INCLUDE_LEVEL__ = RegisterBuiltinMacro("__INCLUDE_LEVEL__");
346+
Ident__TIMESTAMP__ = RegisterBuiltinMacro("__TIMESTAMP__");
361347

362348
// Microsoft Extensions.
363349
if (getLangOpts().MicrosoftExt) {
364-
Ident__identifier = RegisterBuiltinMacro(*this, "__identifier");
365-
Ident__pragma = RegisterBuiltinMacro(*this, "__pragma");
350+
Ident__identifier = RegisterBuiltinMacro("__identifier");
351+
Ident__pragma = RegisterBuiltinMacro("__pragma");
366352
} else {
367353
Ident__identifier = nullptr;
368354
Ident__pragma = nullptr;
369355
}
370356

371357
// Clang Extensions.
372-
Ident__FILE_NAME__ = RegisterBuiltinMacro(*this, "__FILE_NAME__");
373-
Ident__has_feature = RegisterBuiltinMacro(*this, "__has_feature");
374-
Ident__has_extension = RegisterBuiltinMacro(*this, "__has_extension");
375-
Ident__has_builtin = RegisterBuiltinMacro(*this, "__has_builtin");
358+
Ident__FILE_NAME__ = RegisterBuiltinMacro("__FILE_NAME__");
359+
Ident__has_feature = RegisterBuiltinMacro("__has_feature");
360+
Ident__has_extension = RegisterBuiltinMacro("__has_extension");
361+
Ident__has_builtin = RegisterBuiltinMacro("__has_builtin");
376362
Ident__has_constexpr_builtin =
377-
RegisterBuiltinMacro(*this, "__has_constexpr_builtin");
378-
Ident__has_attribute = RegisterBuiltinMacro(*this, "__has_attribute");
363+
RegisterBuiltinMacro("__has_constexpr_builtin");
364+
Ident__has_attribute = RegisterBuiltinMacro("__has_attribute");
379365
if (!getLangOpts().CPlusPlus)
380-
Ident__has_c_attribute = RegisterBuiltinMacro(*this, "__has_c_attribute");
366+
Ident__has_c_attribute = RegisterBuiltinMacro("__has_c_attribute");
381367
else
382368
Ident__has_c_attribute = nullptr;
383369

384-
Ident__has_declspec = RegisterBuiltinMacro(*this, "__has_declspec_attribute");
385-
Ident__has_embed = RegisterBuiltinMacro(*this, "__has_embed");
386-
Ident__has_include = RegisterBuiltinMacro(*this, "__has_include");
387-
Ident__has_include_next = RegisterBuiltinMacro(*this, "__has_include_next");
388-
Ident__has_warning = RegisterBuiltinMacro(*this, "__has_warning");
389-
Ident__is_identifier = RegisterBuiltinMacro(*this, "__is_identifier");
390-
Ident__is_target_arch = RegisterBuiltinMacro(*this, "__is_target_arch");
391-
Ident__is_target_vendor = RegisterBuiltinMacro(*this, "__is_target_vendor");
392-
Ident__is_target_os = RegisterBuiltinMacro(*this, "__is_target_os");
370+
Ident__has_declspec = RegisterBuiltinMacro("__has_declspec_attribute");
371+
Ident__has_embed = RegisterBuiltinMacro("__has_embed");
372+
Ident__has_include = RegisterBuiltinMacro("__has_include");
373+
Ident__has_include_next = RegisterBuiltinMacro("__has_include_next");
374+
Ident__has_warning = RegisterBuiltinMacro("__has_warning");
375+
Ident__is_identifier = RegisterBuiltinMacro("__is_identifier");
376+
Ident__is_target_arch = RegisterBuiltinMacro("__is_target_arch");
377+
Ident__is_target_vendor = RegisterBuiltinMacro("__is_target_vendor");
378+
Ident__is_target_os = RegisterBuiltinMacro("__is_target_os");
393379
Ident__is_target_environment =
394-
RegisterBuiltinMacro(*this, "__is_target_environment");
395-
Ident__is_target_variant_os =
396-
RegisterBuiltinMacro(*this, "__is_target_variant_os");
380+
RegisterBuiltinMacro("__is_target_environment");
381+
Ident__is_target_variant_os = RegisterBuiltinMacro("__is_target_variant_os");
397382
Ident__is_target_variant_environment =
398-
RegisterBuiltinMacro(*this, "__is_target_variant_environment");
383+
RegisterBuiltinMacro("__is_target_variant_environment");
399384

400385
// Modules.
401-
Ident__building_module = RegisterBuiltinMacro(*this, "__building_module");
386+
Ident__building_module = RegisterBuiltinMacro("__building_module");
402387
if (!getLangOpts().CurrentModule.empty())
403-
Ident__MODULE__ = RegisterBuiltinMacro(*this, "__MODULE__");
388+
Ident__MODULE__ = RegisterBuiltinMacro("__MODULE__");
404389
else
405390
Ident__MODULE__ = nullptr;
406391
}

0 commit comments

Comments
 (0)