clang 22.0.0git
IdentifierTable.cpp File Reference
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/DiagnosticLex.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetBuiltins.h"
#include "clang/Basic/TokenKinds.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdio>
#include <cstring>
#include <string>
#include "clang/Basic/TokenKinds.def"
#include "clang/Basic/OperatorKinds.def"

Go to the source code of this file.

Macros

#define KEYWORD(NAME, FLAGS)
#define ALIAS(NAME, TOK, FLAGS)
#define CXX_KEYWORD_OPERATOR(NAME, ALIAS)
#define OBJC_AT_KEYWORD(NAME)
#define NOTABLE_IDENTIFIER(NAME)
#define TESTING_KEYWORD(NAME, FLAGS)
#define KEYWORD(NAME, FLAGS)
#define HASH(LEN, FIRST, THIRD)
#define CASE(LEN, FIRST, THIRD, NAME)
#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly)
#define KEYWORD(NAME, FLAGS)

Functions

static KeywordStatus getKeywordStatusHelper (const LangOptions &LangOpts, TokenKey Flag)
static KeywordStatus getKeywordStatus (const LangOptions &LangOpts, unsigned Flags)
 Translates flags as specified in TokenKinds.def into keyword status in the given language standard.
static bool IsKeywordInCpp (unsigned Flags)
static void MarkIdentifierAsKeywordInCpp (IdentifierTable &Table, StringRef Name)
static void AddKeyword (StringRef Keyword, tok::TokenKind TokenCode, unsigned Flags, const LangOptions &LangOpts, IdentifierTable &Table)
 AddKeyword - This method is used to associate a token ID with specific identifiers because they are language keywords.
static void AddCXXOperatorKeyword (StringRef Keyword, tok::TokenKind TokenCode, IdentifierTable &Table)
 AddCXXOperatorKeyword - Register a C++ operator keyword alternative representations.
static void AddObjCKeyword (StringRef Name, tok::ObjCKeywordKind ObjCID, IdentifierTable &Table)
 AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or "property".
static void AddNotableIdentifier (StringRef Name, tok::NotableIdentifierKind BTID, IdentifierTable &Table)
static KeywordStatus getTokenKwStatus (const LangOptions &LangOpts, tok::TokenKind K)
 Checks if the specified token kind represents a keyword in the specified language.
static bool startsWithWord (StringRef name, StringRef word)
 Interpreting the given string using the normal CamelCase conventions, determine whether the given string starts with the given "word", which is assumed to end in a lowercase letter.
static SelectorTableImpl & getSelectorTableImpl (void *P)

Macro Definition Documentation

◆ ALIAS

#define ALIAS ( NAME,
TOK,
FLAGS )
Value:
AddKeyword(StringRef(NAME), tok::kw_ ## TOK, \
FLAGS, LangOpts, *this);
static void AddKeyword(StringRef Keyword, tok::TokenKind TokenCode, unsigned Flags, const LangOptions &LangOpts, IdentifierTable &Table)
AddKeyword - This method is used to associate a token ID with specific identifiers because they are l...
#define TOK(X)
Definition TokenKinds.h:26

Referenced by sanitizeFilenameAsIdentifier().

◆ CASE

#define CASE ( LEN,
FIRST,
THIRD,
NAME )
Value:
case HASH(LEN, FIRST, THIRD): \
return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
#define HASH(LEN, FIRST, THIRD)
return(__x > > __y)|(__x<<(32 - __y))

Referenced by clang::IdentifierInfo::getPPKeywordID(), and getStableLevel().

◆ CXX_KEYWORD_OPERATOR

#define CXX_KEYWORD_OPERATOR ( NAME,
ALIAS )
Value:
if (LangOpts.CXXOperatorNames) \
AddCXXOperatorKeyword(StringRef(#NAME), tok::ALIAS, *this); \
else \
MarkIdentifierAsKeywordInCpp(*this, StringRef(#NAME));

◆ HASH

#define HASH ( LEN,
FIRST,
THIRD )
Value:
(LEN << 6) + (((FIRST - 'a') - (THIRD - 'a')) & 63)

Referenced by clang::IdentifierInfo::getPPKeywordID().

◆ KEYWORD [1/3]

#define KEYWORD ( NAME,
FLAGS )
Value:
AddKeyword(StringRef(#NAME), tok::kw_ ## NAME, \
FLAGS, LangOpts, *this);

Referenced by sanitizeFilenameAsIdentifier().

◆ KEYWORD [2/3]

#define KEYWORD ( NAME,
FLAGS )
Value:
case tok::kw_##NAME: return getKeywordStatus(LangOpts, FLAGS);
static KeywordStatus getKeywordStatus(const LangOptions &LangOpts, unsigned Flags)
Translates flags as specified in TokenKinds.def into keyword status in the given language standard.

◆ KEYWORD [3/3]

#define KEYWORD ( NAME,
FLAGS )
Value:
.Case(#NAME, FLAGS)

◆ NOTABLE_IDENTIFIER

#define NOTABLE_IDENTIFIER ( NAME)
Value:
AddNotableIdentifier(StringRef(#NAME), tok::NAME, *this);
static void AddNotableIdentifier(StringRef Name, tok::NotableIdentifierKind BTID, IdentifierTable &Table)

◆ OBJC_AT_KEYWORD

#define OBJC_AT_KEYWORD ( NAME)
Value:
if (LangOpts.ObjC) \
AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);

◆ OVERLOADED_OPERATOR

#define OVERLOADED_OPERATOR ( Name,
Spelling,
Token,
Unary,
Binary,
MemberOnly )
Value:
case OO_##Name: return Spelling;

◆ TESTING_KEYWORD

#define TESTING_KEYWORD ( NAME,
FLAGS )

Function Documentation

◆ AddCXXOperatorKeyword()

void AddCXXOperatorKeyword ( StringRef Keyword,
tok::TokenKind TokenCode,
IdentifierTable & Table )
static

AddCXXOperatorKeyword - Register a C++ operator keyword alternative representations.

Definition at line 293 of file IdentifierTable.cpp.

References clang::IdentifierTable::get(), clang::Keyword, and clang::IdentifierInfo::setIsCPlusPlusOperatorKeyword().

◆ AddKeyword()

void AddKeyword ( StringRef Keyword,
tok::TokenKind TokenCode,
unsigned Flags,
const LangOptions & LangOpts,
IdentifierTable & Table )
static

AddKeyword - This method is used to associate a token ID with specific identifiers because they are language keywords.

This causes the lexer to automatically map matching identifiers to specialized token codes.

Definition at line 267 of file IdentifierTable.cpp.

References clang::IdentifierTable::get(), getKeywordStatus(), IsKeywordInCpp(), clang::Keyword, MarkIdentifierAsKeywordInCpp(), clang::IdentifierInfo::setIsExtensionToken(), and clang::IdentifierInfo::setIsFutureCompatKeyword().

Referenced by clang::IdentifierTable::AddKeywords().

◆ AddNotableIdentifier()

void AddNotableIdentifier ( StringRef Name,
tok::NotableIdentifierKind BTID,
IdentifierTable & Table )
static

◆ AddObjCKeyword()

void AddObjCKeyword ( StringRef Name,
tok::ObjCKeywordKind ObjCID,
IdentifierTable & Table )
static

AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or "property".

Definition at line 302 of file IdentifierTable.cpp.

References clang::IdentifierTable::get(), and clang::IdentifierInfo::setObjCKeywordID().

◆ getKeywordStatus()

KeywordStatus getKeywordStatus ( const LangOptions & LangOpts,
unsigned Flags )
static

Translates flags as specified in TokenKinds.def into keyword status in the given language standard.

Definition at line 225 of file IdentifierTable.cpp.

References getKeywordStatusHelper(), clang::LangOptions::isCompatibleWithMSVC(), and clang::LangOptionsBase::MSVC2015.

Referenced by AddKeyword().

◆ getKeywordStatusHelper()

KeywordStatus getKeywordStatusHelper ( const LangOptions & LangOpts,
TokenKey Flag )
static

Definition at line 137 of file IdentifierTable.cpp.

References clang::LangOptions::isSYCL().

Referenced by getKeywordStatus().

◆ getSelectorTableImpl()

SelectorTableImpl & getSelectorTableImpl ( void * P)
static

◆ getTokenKwStatus()

KeywordStatus getTokenKwStatus ( const LangOptions & LangOpts,
tok::TokenKind K )
static

Checks if the specified token kind represents a keyword in the specified language.

Returns
Status of the keyword in the language.

Definition at line 359 of file IdentifierTable.cpp.

Referenced by clang::IdentifierInfo::isKeyword().

◆ IsKeywordInCpp()

bool IsKeywordInCpp ( unsigned Flags)
static

Definition at line 252 of file IdentifierTable.cpp.

Referenced by AddKeyword().

◆ MarkIdentifierAsKeywordInCpp()

void MarkIdentifierAsKeywordInCpp ( IdentifierTable & Table,
StringRef Name )
static

◆ startsWithWord()

bool startsWithWord ( StringRef name,
StringRef word )
static

Interpreting the given string using the normal CamelCase conventions, determine whether the given string starts with the given "word", which is assumed to end in a lowercase letter.

Definition at line 636 of file IdentifierTable.cpp.

References clang::isLowercase().

Referenced by clang::Selector::getInstTypeMethodFamily().