2017-11-04 06:35:27 +08:00
|
|
|
//===- IdentifierTable.cpp - Hash table for identifier lookup -------------===//
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-07-05 01:53:21 +08:00
|
|
|
// This file implements the IdentifierInfo, IdentifierVisitor, and
|
2006-07-03 12:28:52 +08:00
|
|
|
// IdentifierTable interfaces.
|
2006-06-18 13:43:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-11 00:31:55 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2017-11-04 06:35:27 +08:00
|
|
|
#include "clang/Basic/CharInfo.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2014-05-11 00:31:55 +08:00
|
|
|
#include "clang/Basic/OperatorKinds.h"
|
2015-06-20 02:14:38 +08:00
|
|
|
#include "clang/Basic/Specifiers.h"
|
2020-05-08 03:11:03 +08:00
|
|
|
#include "clang/Basic/TargetBuiltins.h"
|
2017-11-04 06:35:27 +08:00
|
|
|
#include "clang/Basic/TokenKinds.h"
|
|
|
|
#include "llvm/ADT/DenseMapInfo.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2014-05-11 00:31:55 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2017-11-04 06:35:27 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/Allocator.h"
|
2012-01-17 14:56:22 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-11-04 06:35:27 +08:00
|
|
|
#include <cassert>
|
2009-03-03 06:20:04 +08:00
|
|
|
#include <cstdio>
|
2017-11-04 06:35:27 +08:00
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
2007-10-24 06:18:37 +08:00
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2020-05-08 03:11:03 +08:00
|
|
|
// A check to make sure the ObjCOrBuiltinID has sufficient room to store the
|
|
|
|
// largest possible target/aux-target combination. If we exceed this, we likely
|
|
|
|
// need to just change the ObjCOrBuiltinIDBits value in IdentifierTable.h.
|
|
|
|
static_assert(2 * LargestBuiltinID < (2 << (ObjCOrBuiltinIDBits - 1)),
|
|
|
|
"Insufficient ObjCOrBuiltinID Bits");
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IdentifierTable Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-04 06:35:27 +08:00
|
|
|
IdentifierIterator::~IdentifierIterator() = default;
|
2010-10-15 06:11:03 +08:00
|
|
|
|
2017-11-04 06:35:27 +08:00
|
|
|
IdentifierInfoLookup::~IdentifierInfoLookup() = default;
|
2009-01-16 02:47:46 +08:00
|
|
|
|
2010-10-15 06:11:03 +08:00
|
|
|
namespace {
|
2017-11-04 06:35:27 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// A simple identifier lookup iterator that represents an
|
2017-11-04 06:35:27 +08:00
|
|
|
/// empty sequence of identifiers.
|
|
|
|
class EmptyLookupIterator : public IdentifierIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StringRef Next() override { return StringRef(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
2010-10-15 06:11:03 +08:00
|
|
|
|
2013-04-18 06:10:55 +08:00
|
|
|
IdentifierIterator *IdentifierInfoLookup::getIdentifiers() {
|
2010-10-15 06:11:03 +08:00
|
|
|
return new EmptyLookupIterator();
|
|
|
|
}
|
|
|
|
|
2018-04-17 05:07:08 +08:00
|
|
|
IdentifierTable::IdentifierTable(IdentifierInfoLookup *ExternalLookup)
|
|
|
|
: HashTable(8192), // Start with space for 8K identifiers.
|
|
|
|
ExternalLookup(ExternalLookup) {}
|
|
|
|
|
2009-01-16 02:47:46 +08:00
|
|
|
IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
|
2018-04-17 05:07:08 +08:00
|
|
|
IdentifierInfoLookup *ExternalLookup)
|
|
|
|
: IdentifierTable(ExternalLookup) {
|
2006-10-27 11:59:10 +08:00
|
|
|
// Populate the identifier table with info about keywords for the current
|
|
|
|
// language.
|
2006-10-18 14:07:05 +08:00
|
|
|
AddKeywords(LangOpts);
|
2006-07-03 12:28:52 +08:00
|
|
|
}
|
2006-06-18 13:43:12 +08:00
|
|
|
|
2006-10-18 14:07:05 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Language Keyword Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
// Constants for TokenKinds.def
|
|
|
|
namespace {
|
2017-11-04 06:35:27 +08:00
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
enum {
|
2018-10-31 04:51:28 +08:00
|
|
|
KEYC99 = 0x1,
|
|
|
|
KEYCXX = 0x2,
|
|
|
|
KEYCXX11 = 0x4,
|
|
|
|
KEYGNU = 0x8,
|
|
|
|
KEYMS = 0x10,
|
|
|
|
BOOLSUPPORT = 0x20,
|
|
|
|
KEYALTIVEC = 0x40,
|
|
|
|
KEYNOCXX = 0x80,
|
|
|
|
KEYBORLAND = 0x100,
|
|
|
|
KEYOPENCLC = 0x200,
|
|
|
|
KEYC11 = 0x400,
|
|
|
|
KEYNOMS18 = 0x800,
|
|
|
|
KEYNOOPENCL = 0x1000,
|
|
|
|
WCHARSUPPORT = 0x2000,
|
|
|
|
HALFSUPPORT = 0x4000,
|
|
|
|
CHAR8SUPPORT = 0x8000,
|
|
|
|
KEYCONCEPTS = 0x10000,
|
|
|
|
KEYOBJC = 0x20000,
|
|
|
|
KEYZVECTOR = 0x40000,
|
|
|
|
KEYCOROUTINES = 0x80000,
|
|
|
|
KEYMODULES = 0x100000,
|
2020-04-22 03:37:19 +08:00
|
|
|
KEYCXX20 = 0x200000,
|
2018-10-31 04:51:28 +08:00
|
|
|
KEYOPENCLCXX = 0x400000,
|
[MSVC] Recognize `static_assert` keyword in C and C++98
Summary:
The main effect is that clang now accepts the following conforming C11
code with MSVC headers:
#include <assert.h>
static_assert(1, "true");
This is a non-conforming extension (the keyword is outside the
implementer's namespace), so it is placed under -fms-compatibility
instead of -fms-extensions like most MSVC-specific keyword extensions.
Normally, in C11, the compiler is supposed to provide the _Static_assert
keyword, and assert.h should define static_assert to _Static_assert.
However, that is not what MSVC does, and MSVC doesn't even provide
_Static_assert.
This also has the less important side effect of enabling static_assert
in C++98 mode with -fms-compatibility. It's exceptionally difficult to
use modern MSVC headers without C++14 even, so this is relatively
unimportant.
Fixes PR26672
Patch by Andrey Bokhanko!
Reviewers: rsmith, thakis
Subscribers: cfe-commits, STL_MSFT
Differential Revision: https://reviews.llvm.org/D17444
llvm-svn: 354162
2019-02-16 03:59:45 +08:00
|
|
|
KEYMSCOMPAT = 0x800000,
|
2020-04-22 03:37:19 +08:00
|
|
|
KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
KEYALL = (0xffffff & ~KEYNOMS18 &
|
2015-03-18 20:55:29 +08:00
|
|
|
~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
|
2009-04-28 11:13:54 +08:00
|
|
|
};
|
2014-10-29 18:59:18 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// How a keyword is treated in the selected standard.
|
2014-10-29 18:59:18 +08:00
|
|
|
enum KeywordStatus {
|
|
|
|
KS_Disabled, // Disabled
|
|
|
|
KS_Extension, // Is an extension
|
|
|
|
KS_Enabled, // Enabled
|
|
|
|
KS_Future // Is a keyword in future standard
|
|
|
|
};
|
2017-11-04 06:35:27 +08:00
|
|
|
|
|
|
|
} // namespace
|
2014-10-29 18:59:18 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Translates flags as specified in TokenKinds.def into keyword status
|
2014-10-29 18:59:18 +08:00
|
|
|
/// in the given language standard.
|
2014-12-11 20:18:08 +08:00
|
|
|
static KeywordStatus getKeywordStatus(const LangOptions &LangOpts,
|
2014-10-29 18:59:18 +08:00
|
|
|
unsigned Flags) {
|
|
|
|
if (Flags == KEYALL) return KS_Enabled;
|
|
|
|
if (LangOpts.CPlusPlus && (Flags & KEYCXX)) return KS_Enabled;
|
|
|
|
if (LangOpts.CPlusPlus11 && (Flags & KEYCXX11)) return KS_Enabled;
|
2020-04-22 03:37:19 +08:00
|
|
|
if (LangOpts.CPlusPlus20 && (Flags & KEYCXX20)) return KS_Enabled;
|
2014-10-29 18:59:18 +08:00
|
|
|
if (LangOpts.C99 && (Flags & KEYC99)) return KS_Enabled;
|
|
|
|
if (LangOpts.GNUKeywords && (Flags & KEYGNU)) return KS_Extension;
|
|
|
|
if (LangOpts.MicrosoftExt && (Flags & KEYMS)) return KS_Extension;
|
[MSVC] Recognize `static_assert` keyword in C and C++98
Summary:
The main effect is that clang now accepts the following conforming C11
code with MSVC headers:
#include <assert.h>
static_assert(1, "true");
This is a non-conforming extension (the keyword is outside the
implementer's namespace), so it is placed under -fms-compatibility
instead of -fms-extensions like most MSVC-specific keyword extensions.
Normally, in C11, the compiler is supposed to provide the _Static_assert
keyword, and assert.h should define static_assert to _Static_assert.
However, that is not what MSVC does, and MSVC doesn't even provide
_Static_assert.
This also has the less important side effect of enabling static_assert
in C++98 mode with -fms-compatibility. It's exceptionally difficult to
use modern MSVC headers without C++14 even, so this is relatively
unimportant.
Fixes PR26672
Patch by Andrey Bokhanko!
Reviewers: rsmith, thakis
Subscribers: cfe-commits, STL_MSFT
Differential Revision: https://reviews.llvm.org/D17444
llvm-svn: 354162
2019-02-16 03:59:45 +08:00
|
|
|
if (LangOpts.MSVCCompat && (Flags & KEYMSCOMPAT)) return KS_Enabled;
|
2014-10-29 18:59:18 +08:00
|
|
|
if (LangOpts.Borland && (Flags & KEYBORLAND)) return KS_Extension;
|
|
|
|
if (LangOpts.Bool && (Flags & BOOLSUPPORT)) return KS_Enabled;
|
|
|
|
if (LangOpts.Half && (Flags & HALFSUPPORT)) return KS_Enabled;
|
|
|
|
if (LangOpts.WChar && (Flags & WCHARSUPPORT)) return KS_Enabled;
|
2018-05-01 13:02:45 +08:00
|
|
|
if (LangOpts.Char8 && (Flags & CHAR8SUPPORT)) return KS_Enabled;
|
2014-10-29 18:59:18 +08:00
|
|
|
if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) return KS_Enabled;
|
2018-10-16 22:57:20 +08:00
|
|
|
if (LangOpts.ZVector && (Flags & KEYZVECTOR)) return KS_Enabled;
|
[OpenCL] Restrict various keywords in OpenCL C++ mode
Restrict the following keywords in the OpenCL C++ language mode,
according to Sections 2.2 & 2.9 of the OpenCL C++ 1.0 Specification.
- dynamic_cast
- typeid
- register (already restricted in OpenCL C, update the diagnostic)
- thread_local
- exceptions (try/catch/throw)
- access qualifiers read_only, write_only, read_write
Support the `__global`, `__local`, `__constant`, `__private`, and
`__generic` keywords in OpenCL C++. Leave the unprefixed address
space qualifiers such as global available, i.e., do not mark them as
reserved keywords in OpenCL C++. libclcxx provides explicit address
space pointer classes such as `global_ptr` and `global<T>` that are
implemented using the `__`-prefixed qualifiers.
Differential Revision: https://reviews.llvm.org/D46022
llvm-svn: 331874
2018-05-09 21:16:17 +08:00
|
|
|
if (LangOpts.OpenCL && !LangOpts.OpenCLCPlusPlus && (Flags & KEYOPENCLC))
|
|
|
|
return KS_Enabled;
|
|
|
|
if (LangOpts.OpenCLCPlusPlus && (Flags & KEYOPENCLCXX)) return KS_Enabled;
|
2014-10-29 18:59:18 +08:00
|
|
|
if (!LangOpts.CPlusPlus && (Flags & KEYNOCXX)) return KS_Enabled;
|
|
|
|
if (LangOpts.C11 && (Flags & KEYC11)) return KS_Enabled;
|
|
|
|
// We treat bridge casts as objective-C keywords so we can warn on them
|
|
|
|
// in non-arc mode.
|
2018-10-31 04:31:30 +08:00
|
|
|
if (LangOpts.ObjC && (Flags & KEYOBJC)) return KS_Enabled;
|
2020-04-22 03:37:19 +08:00
|
|
|
if (LangOpts.CPlusPlus20 && (Flags & KEYCONCEPTS)) return KS_Enabled;
|
2019-02-24 05:06:26 +08:00
|
|
|
if (LangOpts.Coroutines && (Flags & KEYCOROUTINES)) return KS_Enabled;
|
2016-07-23 10:32:21 +08:00
|
|
|
if (LangOpts.ModulesTS && (Flags & KEYMODULES)) return KS_Enabled;
|
2017-08-14 05:32:33 +08:00
|
|
|
if (LangOpts.CPlusPlus && (Flags & KEYALLCXX)) return KS_Future;
|
2020-04-29 14:41:11 +08:00
|
|
|
if (LangOpts.CPlusPlus && !LangOpts.CPlusPlus20 && (Flags & CHAR8SUPPORT))
|
|
|
|
return KS_Future;
|
2014-10-29 18:59:18 +08:00
|
|
|
return KS_Disabled;
|
2009-04-28 11:13:54 +08:00
|
|
|
}
|
|
|
|
|
2006-10-18 14:07:05 +08:00
|
|
|
/// 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.
|
2011-07-23 18:55:15 +08:00
|
|
|
static void AddKeyword(StringRef Keyword,
|
2009-04-28 11:13:54 +08:00
|
|
|
tok::TokenKind TokenCode, unsigned Flags,
|
2006-10-18 14:07:05 +08:00
|
|
|
const LangOptions &LangOpts, IdentifierTable &Table) {
|
2014-12-11 20:18:08 +08:00
|
|
|
KeywordStatus AddResult = getKeywordStatus(LangOpts, Flags);
|
2011-10-12 03:57:52 +08:00
|
|
|
|
2014-01-14 20:51:41 +08:00
|
|
|
// Don't add this keyword under MSVCCompat.
|
2015-03-18 12:15:23 +08:00
|
|
|
if (LangOpts.MSVCCompat && (Flags & KEYNOMS18) &&
|
2015-05-11 11:57:49 +08:00
|
|
|
!LangOpts.isCompatibleWithMSVC(LangOptions::MSVC2015))
|
2015-03-18 20:55:29 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't add this keyword under OpenCL.
|
|
|
|
if (LangOpts.OpenCL && (Flags & KEYNOOPENCL))
|
|
|
|
return;
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
// Don't add this keyword if disabled in this language.
|
2014-10-29 18:59:18 +08:00
|
|
|
if (AddResult == KS_Disabled) return;
|
2009-04-28 11:13:54 +08:00
|
|
|
|
2011-10-12 03:57:52 +08:00
|
|
|
IdentifierInfo &Info =
|
2014-10-29 18:59:18 +08:00
|
|
|
Table.get(Keyword, AddResult == KS_Future ? tok::identifier : TokenCode);
|
|
|
|
Info.setIsExtensionToken(AddResult == KS_Extension);
|
2015-05-14 12:00:59 +08:00
|
|
|
Info.setIsFutureCompatKeyword(AddResult == KS_Future);
|
2006-10-18 14:07:05 +08:00
|
|
|
}
|
|
|
|
|
2006-11-22 01:23:33 +08:00
|
|
|
/// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
|
|
|
|
/// representations.
|
2011-07-23 18:55:15 +08:00
|
|
|
static void AddCXXOperatorKeyword(StringRef Keyword,
|
2006-11-22 01:23:33 +08:00
|
|
|
tok::TokenKind TokenCode,
|
|
|
|
IdentifierTable &Table) {
|
2010-08-12 06:55:12 +08:00
|
|
|
IdentifierInfo &Info = Table.get(Keyword, TokenCode);
|
2007-10-24 06:18:37 +08:00
|
|
|
Info.setIsCPlusPlusOperatorKeyword();
|
2006-11-22 01:23:33 +08:00
|
|
|
}
|
|
|
|
|
2012-06-16 05:27:44 +08:00
|
|
|
/// AddObjCKeyword - Register an Objective-C \@keyword like "class" "selector"
|
|
|
|
/// or "property".
|
2011-07-23 18:55:15 +08:00
|
|
|
static void AddObjCKeyword(StringRef Name,
|
2010-03-12 19:27:37 +08:00
|
|
|
tok::ObjCKeywordKind ObjCID,
|
2006-10-18 14:07:05 +08:00
|
|
|
IdentifierTable &Table) {
|
2010-03-12 19:27:37 +08:00
|
|
|
Table.get(Name).setObjCKeywordID(ObjCID);
|
2006-10-18 14:07:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// AddKeywords - Add all keywords to the symbol table.
|
|
|
|
///
|
|
|
|
void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
|
|
|
|
// Add keywords and tokens for the current language.
|
|
|
|
#define KEYWORD(NAME, FLAGS) \
|
2011-07-23 18:55:15 +08:00
|
|
|
AddKeyword(StringRef(#NAME), tok::kw_ ## NAME, \
|
2009-04-28 11:13:54 +08:00
|
|
|
FLAGS, LangOpts, *this);
|
|
|
|
#define ALIAS(NAME, TOK, FLAGS) \
|
2011-07-23 18:55:15 +08:00
|
|
|
AddKeyword(StringRef(NAME), tok::kw_ ## TOK, \
|
2009-04-28 11:13:54 +08:00
|
|
|
FLAGS, LangOpts, *this);
|
2006-11-22 01:23:33 +08:00
|
|
|
#define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
|
2006-12-04 15:48:37 +08:00
|
|
|
if (LangOpts.CXXOperatorNames) \
|
2011-07-23 18:55:15 +08:00
|
|
|
AddCXXOperatorKeyword(StringRef(#NAME), tok::ALIAS, *this);
|
2018-10-31 04:31:30 +08:00
|
|
|
#define OBJC_AT_KEYWORD(NAME) \
|
|
|
|
if (LangOpts.ObjC) \
|
2011-07-23 18:55:15 +08:00
|
|
|
AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
|
2011-04-10 06:50:59 +08:00
|
|
|
#define TESTING_KEYWORD(NAME, FLAGS)
|
2006-10-18 14:07:05 +08:00
|
|
|
#include "clang/Basic/TokenKinds.def"
|
2011-04-10 06:50:59 +08:00
|
|
|
|
|
|
|
if (LangOpts.ParseUnknownAnytype)
|
|
|
|
AddKeyword("__unknown_anytype", tok::kw___unknown_anytype, KEYALL,
|
|
|
|
LangOpts, *this);
|
2015-05-27 03:44:52 +08:00
|
|
|
|
2015-10-05 01:51:05 +08:00
|
|
|
if (LangOpts.DeclSpecKeyword)
|
2015-05-27 03:44:52 +08:00
|
|
|
AddKeyword("__declspec", tok::kw___declspec, KEYALL, LangOpts, *this);
|
2018-04-17 05:07:08 +08:00
|
|
|
|
2019-04-12 05:18:23 +08:00
|
|
|
// Add the 'import' contextual keyword.
|
2018-04-17 05:07:08 +08:00
|
|
|
get("import").setModulesImport(true);
|
2006-10-18 14:07:05 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Checks if the specified token kind represents a keyword in the
|
2014-12-11 20:18:08 +08:00
|
|
|
/// specified language.
|
|
|
|
/// \returns Status of the keyword in the language.
|
|
|
|
static KeywordStatus getTokenKwStatus(const LangOptions &LangOpts,
|
|
|
|
tok::TokenKind K) {
|
|
|
|
switch (K) {
|
|
|
|
#define KEYWORD(NAME, FLAGS) \
|
|
|
|
case tok::kw_##NAME: return getKeywordStatus(LangOpts, FLAGS);
|
|
|
|
#include "clang/Basic/TokenKinds.def"
|
|
|
|
default: return KS_Disabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Returns true if the identifier represents a keyword in the
|
2014-12-11 20:18:08 +08:00
|
|
|
/// specified language.
|
2017-04-11 23:01:53 +08:00
|
|
|
bool IdentifierInfo::isKeyword(const LangOptions &LangOpts) const {
|
2014-12-11 20:18:08 +08:00
|
|
|
switch (getTokenKwStatus(LangOpts, getTokenID())) {
|
|
|
|
case KS_Enabled:
|
|
|
|
case KS_Extension:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Returns true if the identifier represents a C++ keyword in the
|
2017-04-11 23:01:53 +08:00
|
|
|
/// specified language.
|
|
|
|
bool IdentifierInfo::isCPlusPlusKeyword(const LangOptions &LangOpts) const {
|
|
|
|
if (!LangOpts.CPlusPlus || !isKeyword(LangOpts))
|
|
|
|
return false;
|
|
|
|
// This is a C++ keyword if this identifier is not a keyword when checked
|
|
|
|
// using LangOptions without C++ support.
|
|
|
|
LangOptions LangOptsNoCPP = LangOpts;
|
|
|
|
LangOptsNoCPP.CPlusPlus = false;
|
|
|
|
LangOptsNoCPP.CPlusPlus11 = false;
|
2020-04-22 03:37:19 +08:00
|
|
|
LangOptsNoCPP.CPlusPlus20 = false;
|
2017-04-11 23:01:53 +08:00
|
|
|
return !isKeyword(LangOptsNoCPP);
|
|
|
|
}
|
|
|
|
|
2007-10-07 15:52:34 +08:00
|
|
|
tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
|
|
|
|
// We use a perfect hash function here involving the length of the keyword,
|
|
|
|
// the first and third character. For preprocessor ID's there are no
|
|
|
|
// collisions (if there were, the switch below would complain about duplicate
|
|
|
|
// case values). Note that this depends on 'if' being null terminated.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-07 15:52:34 +08:00
|
|
|
#define HASH(LEN, FIRST, THIRD) \
|
|
|
|
(LEN << 5) + (((FIRST-'a') + (THIRD-'a')) & 31)
|
|
|
|
#define CASE(LEN, FIRST, THIRD, NAME) \
|
|
|
|
case HASH(LEN, FIRST, THIRD): \
|
|
|
|
return memcmp(Name, #NAME, LEN) ? tok::pp_not_keyword : tok::pp_ ## NAME
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-07 15:52:34 +08:00
|
|
|
unsigned Len = getLength();
|
2007-10-11 04:59:57 +08:00
|
|
|
if (Len < 2) return tok::pp_not_keyword;
|
2009-10-18 02:13:02 +08:00
|
|
|
const char *Name = getNameStart();
|
2007-10-07 15:52:34 +08:00
|
|
|
switch (HASH(Len, Name[0], Name[2])) {
|
|
|
|
default: return tok::pp_not_keyword;
|
|
|
|
CASE( 2, 'i', '\0', if);
|
|
|
|
CASE( 4, 'e', 'i', elif);
|
|
|
|
CASE( 4, 'e', 's', else);
|
|
|
|
CASE( 4, 'l', 'n', line);
|
|
|
|
CASE( 4, 's', 'c', sccs);
|
|
|
|
CASE( 5, 'e', 'd', endif);
|
|
|
|
CASE( 5, 'e', 'r', error);
|
|
|
|
CASE( 5, 'i', 'e', ident);
|
|
|
|
CASE( 5, 'i', 'd', ifdef);
|
|
|
|
CASE( 5, 'u', 'd', undef);
|
|
|
|
|
|
|
|
CASE( 6, 'a', 's', assert);
|
|
|
|
CASE( 6, 'd', 'f', define);
|
|
|
|
CASE( 6, 'i', 'n', ifndef);
|
|
|
|
CASE( 6, 'i', 'p', import);
|
|
|
|
CASE( 6, 'p', 'a', pragma);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2007-10-07 15:52:34 +08:00
|
|
|
CASE( 7, 'd', 'f', defined);
|
|
|
|
CASE( 7, 'i', 'c', include);
|
|
|
|
CASE( 7, 'w', 'r', warning);
|
|
|
|
|
|
|
|
CASE( 8, 'u', 'a', unassert);
|
|
|
|
CASE(12, 'i', 'c', include_next);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-04 03:48:16 +08:00
|
|
|
CASE(14, '_', 'p', __public_macro);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2012-01-04 03:48:16 +08:00
|
|
|
CASE(15, '_', 'p', __private_macro);
|
|
|
|
|
2009-04-09 02:24:34 +08:00
|
|
|
CASE(16, '_', 'i', __include_macros);
|
2007-10-07 15:52:34 +08:00
|
|
|
#undef CASE
|
|
|
|
#undef HASH
|
|
|
|
}
|
|
|
|
}
|
2006-10-18 14:07:05 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stats Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
/// PrintStats - Print statistics about how well the identifier table is doing
|
|
|
|
/// at hashing identifiers.
|
|
|
|
void IdentifierTable::PrintStats() const {
|
2006-10-30 07:43:13 +08:00
|
|
|
unsigned NumBuckets = HashTable.getNumBuckets();
|
|
|
|
unsigned NumIdentifiers = HashTable.getNumItems();
|
|
|
|
unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
|
2006-06-18 13:43:12 +08:00
|
|
|
unsigned AverageIdentifierSize = 0;
|
|
|
|
unsigned MaxIdentifierLength = 0;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-10-30 07:43:13 +08:00
|
|
|
// TODO: Figure out maximum times an identifier had to probe for -stats.
|
2009-01-21 07:28:34 +08:00
|
|
|
for (llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator>::const_iterator
|
2007-02-11 16:19:57 +08:00
|
|
|
I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
|
|
|
|
unsigned IdLen = I->getKeyLength();
|
|
|
|
AverageIdentifierSize += IdLen;
|
|
|
|
if (MaxIdentifierLength < IdLen)
|
|
|
|
MaxIdentifierLength = IdLen;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
fprintf(stderr, "\n*** Identifier Table Stats:\n");
|
|
|
|
fprintf(stderr, "# Identifiers: %d\n", NumIdentifiers);
|
|
|
|
fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
|
|
|
|
fprintf(stderr, "Hash density (#identifiers per bucket): %f\n",
|
|
|
|
NumIdentifiers/(double)NumBuckets);
|
|
|
|
fprintf(stderr, "Ave identifier length: %f\n",
|
|
|
|
(AverageIdentifierSize/(double)NumIdentifiers));
|
|
|
|
fprintf(stderr, "Max identifier length: %d\n", MaxIdentifierLength);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-06-18 13:43:12 +08:00
|
|
|
// Compute statistics about the memory allocated for identifiers.
|
2006-10-30 07:43:13 +08:00
|
|
|
HashTable.getAllocator().PrintStats();
|
2006-06-18 13:43:12 +08:00
|
|
|
}
|
Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
llvm-svn: 42395
2007-09-27 22:38:14 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SelectorTable Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-10-06 04:15:24 +08:00
|
|
|
unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
|
|
|
|
return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
|
2008-11-17 22:58:09 +08:00
|
|
|
namespace clang {
|
2017-11-04 06:35:27 +08:00
|
|
|
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
/// One of these variable length records is kept for each
|
2007-10-06 02:42:47 +08:00
|
|
|
/// selector containing more than one keyword. We use a folding set
|
2009-09-09 23:08:12 +08:00
|
|
|
/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
|
2007-10-06 02:42:47 +08:00
|
|
|
/// this class is provided strictly through Selector.
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
class alignas(IdentifierInfoAlignment) MultiKeywordSelector
|
|
|
|
: public detail::DeclarationNameExtra,
|
|
|
|
public llvm::FoldingSetNode {
|
|
|
|
MultiKeywordSelector(unsigned nKeys) : DeclarationNameExtra(nKeys) {}
|
2017-11-04 06:35:27 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
public:
|
2007-10-06 02:42:47 +08:00
|
|
|
// Constructor for keyword selectors.
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV)
|
|
|
|
: DeclarationNameExtra(nKeys) {
|
2007-10-06 02:42:47 +08:00
|
|
|
assert((nKeys > 1) && "not a multi-keyword selector");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
// Fill in the trailing keyword array.
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this + 1);
|
2007-10-06 02:42:47 +08:00
|
|
|
for (unsigned i = 0; i != nKeys; ++i)
|
|
|
|
KeyInfo[i] = IIV[i];
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
// getName - Derive the full selector name and return it.
|
|
|
|
std::string getName() const;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
using DeclarationNameExtra::getNumArgs;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2017-11-04 06:35:27 +08:00
|
|
|
using keyword_iterator = IdentifierInfo *const *;
|
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
keyword_iterator keyword_begin() const {
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
return reinterpret_cast<keyword_iterator>(this + 1);
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
2017-11-04 06:35:27 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
keyword_iterator keyword_end() const {
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
return keyword_begin() + getNumArgs();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
2017-11-04 06:35:27 +08:00
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
|
2008-11-17 22:58:09 +08:00
|
|
|
assert(i < getNumArgs() && "getIdentifierInfoForSlot(): illegal index");
|
2007-10-06 02:42:47 +08:00
|
|
|
return keyword_begin()[i];
|
|
|
|
}
|
2017-11-04 06:35:27 +08:00
|
|
|
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys,
|
|
|
|
unsigned NumArgs) {
|
2007-10-06 02:42:47 +08:00
|
|
|
ID.AddInteger(NumArgs);
|
2007-10-07 09:33:16 +08:00
|
|
|
for (unsigned i = 0; i != NumArgs; ++i)
|
|
|
|
ID.AddPointer(ArgTys[i]);
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
2017-11-04 06:35:27 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) {
|
2008-11-17 22:58:09 +08:00
|
|
|
Profile(ID, keyword_begin(), getNumArgs());
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
};
|
2017-11-04 06:35:27 +08:00
|
|
|
|
|
|
|
} // namespace clang.
|
2007-10-06 02:42:47 +08:00
|
|
|
|
2019-08-15 00:57:11 +08:00
|
|
|
bool Selector::isKeywordSelector(ArrayRef<StringRef> Names) const {
|
|
|
|
assert(!Names.empty() && "must have >= 1 selector slots");
|
|
|
|
if (getNumArgs() != Names.size())
|
|
|
|
return false;
|
|
|
|
for (unsigned I = 0, E = Names.size(); I != E; ++I) {
|
|
|
|
if (getNameForSlot(I) != Names[I])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Selector::isUnarySelector(StringRef Name) const {
|
|
|
|
return isUnarySelector() && getNameForSlot(0) == Name;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
unsigned Selector::getNumArgs() const {
|
|
|
|
unsigned IIF = getIdentifierInfoFlag();
|
2012-05-05 02:24:37 +08:00
|
|
|
if (IIF <= ZeroArg)
|
2007-10-06 02:42:47 +08:00
|
|
|
return 0;
|
|
|
|
if (IIF == OneArg)
|
|
|
|
return 1;
|
2012-05-05 02:24:37 +08:00
|
|
|
// We point to a MultiKeywordSelector.
|
|
|
|
MultiKeywordSelector *SI = getMultiKeywordSelector();
|
2009-09-09 23:08:12 +08:00
|
|
|
return SI->getNumArgs();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
|
2012-05-05 02:24:37 +08:00
|
|
|
if (getIdentifierInfoFlag() < MultiArg) {
|
2007-10-07 09:33:16 +08:00
|
|
|
assert(argIndex == 0 && "illegal keyword index");
|
2009-04-27 06:20:50 +08:00
|
|
|
return getAsIdentifierInfo();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
2017-11-04 06:35:27 +08:00
|
|
|
|
2012-05-05 02:24:37 +08:00
|
|
|
// We point to a MultiKeywordSelector.
|
|
|
|
MultiKeywordSelector *SI = getMultiKeywordSelector();
|
2007-10-06 02:42:47 +08:00
|
|
|
return SI->getIdentifierInfoForSlot(argIndex);
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Selector::getNameForSlot(unsigned int argIndex) const {
|
2011-02-19 06:29:55 +08:00
|
|
|
IdentifierInfo *II = getIdentifierInfoForSlot(argIndex);
|
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table):
1. Store common kinds inline in DeclarationName instead of
DeclarationNameExtra. Currently the kind of C++ constructor, destructor,
conversion function and overloaded operator names is stored in
DeclarationNameExtra. Instead store it inline in DeclarationName.
To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra
and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of
DeclarationName::Ptr. This is already the case on 64 bits archs anyway.
This also allow us to remove DeclarationNameExtra from CXXSpecialName
and CXXOperatorIdName, which shave off a pointer from CXXSpecialName.
2. Synchronize the enumerations DeclarationName::NameKind,
DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag.
This makes DeclarationName::getNameKind much more efficient since we can
replace the switch table by a single comparison and an addition.
3. Put the overloaded operator names inline in DeclarationNameTable to remove
an indirection. This increase the size of DeclarationNameTable a little
bit but this is not important since it is only used in ASTContext, and
never copied nor moved from. This also get rid of the last dynamic
allocation in DeclarationNameTable.
Altogether these optimizations cut the run time of parsing all of Boost by
about 0.8%. While we are at it, do the following NFC modifications:
1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra,
CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra
in a namespace detail since these classes are only meant to be used by
DeclarationName and DeclarationNameTable. Make this more explicit by making
the members of these classes private and friending DeclarationName(Table).
2. Make DeclarationName::getFETokenInfo a non-template since every users are
using it to get a void *. It was supposed to be used with a type to avoid
a subsequent static_cast.
3. Change the internal functions DeclarationName::getAs* to castAs* since when
we use them we already know the correct kind. This has no external impact
since all of these are private.
Reviewed By: erichkeane, rjmccall
Differential Revision: https://reviews.llvm.org/D52267
llvm-svn: 342729
2018-09-21 20:53:22 +08:00
|
|
|
return II ? II->getName() : StringRef();
|
2011-02-19 06:29:55 +08:00
|
|
|
}
|
|
|
|
|
2007-10-07 09:33:16 +08:00
|
|
|
std::string MultiKeywordSelector::getName() const {
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> Str;
|
2009-10-18 02:13:02 +08:00
|
|
|
llvm::raw_svector_ostream OS(Str);
|
2007-10-07 09:33:16 +08:00
|
|
|
for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
|
|
|
|
if (*I)
|
2009-10-19 05:17:35 +08:00
|
|
|
OS << (*I)->getName();
|
2009-10-18 02:13:02 +08:00
|
|
|
OS << ':';
|
2007-10-07 09:33:16 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2020-01-29 03:23:46 +08:00
|
|
|
return std::string(OS.str());
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
2008-11-24 11:33:13 +08:00
|
|
|
std::string Selector::getAsString() const {
|
2009-04-27 06:20:50 +08:00
|
|
|
if (InfoPtr == 0)
|
|
|
|
return "<null selector>";
|
|
|
|
|
2012-05-05 02:24:37 +08:00
|
|
|
if (getIdentifierInfoFlag() < MultiArg) {
|
2009-03-07 07:36:28 +08:00
|
|
|
IdentifierInfo *II = getAsIdentifierInfo();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2016-11-04 14:32:57 +08:00
|
|
|
if (getNumArgs() == 0) {
|
|
|
|
assert(II && "If the number of arguments is 0 then II is guaranteed to "
|
|
|
|
"not be null.");
|
2020-01-29 03:23:46 +08:00
|
|
|
return std::string(II->getName());
|
2016-11-04 14:32:57 +08:00
|
|
|
}
|
2009-10-18 02:13:02 +08:00
|
|
|
|
|
|
|
if (!II)
|
|
|
|
return ":";
|
2009-03-07 07:36:28 +08:00
|
|
|
|
2009-10-19 05:17:35 +08:00
|
|
|
return II->getName().str() + ":";
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-05-05 02:24:37 +08:00
|
|
|
// We have a multiple keyword selector.
|
|
|
|
return getMultiKeywordSelector()->getName();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
2014-01-04 01:59:55 +08:00
|
|
|
void Selector::print(llvm::raw_ostream &OS) const {
|
|
|
|
OS << getAsString();
|
|
|
|
}
|
|
|
|
|
2018-05-31 22:45:32 +08:00
|
|
|
LLVM_DUMP_METHOD void Selector::dump() const { print(llvm::errs()); }
|
|
|
|
|
2011-03-02 09:50:55 +08:00
|
|
|
/// 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.
|
2011-07-23 18:55:15 +08:00
|
|
|
static bool startsWithWord(StringRef name, StringRef word) {
|
2011-03-02 09:50:55 +08:00
|
|
|
if (name.size() < word.size()) return false;
|
2013-02-09 06:30:41 +08:00
|
|
|
return ((name.size() == word.size() || !isLowercase(name[word.size()])) &&
|
|
|
|
name.startswith(word));
|
2011-03-02 09:50:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjCMethodFamily Selector::getMethodFamilyImpl(Selector sel) {
|
|
|
|
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
|
|
|
|
if (!first) return OMF_None;
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef name = first->getName();
|
2011-03-02 09:50:55 +08:00
|
|
|
if (sel.isUnarySelector()) {
|
|
|
|
if (name == "autorelease") return OMF_autorelease;
|
|
|
|
if (name == "dealloc") return OMF_dealloc;
|
2011-08-29 06:35:17 +08:00
|
|
|
if (name == "finalize") return OMF_finalize;
|
2011-03-02 09:50:55 +08:00
|
|
|
if (name == "release") return OMF_release;
|
|
|
|
if (name == "retain") return OMF_retain;
|
|
|
|
if (name == "retainCount") return OMF_retainCount;
|
2011-06-11 09:09:30 +08:00
|
|
|
if (name == "self") return OMF_self;
|
2014-08-23 00:57:26 +08:00
|
|
|
if (name == "initialize") return OMF_initialize;
|
2011-03-02 09:50:55 +08:00
|
|
|
}
|
2017-03-06 23:58:34 +08:00
|
|
|
|
|
|
|
if (name == "performSelector" || name == "performSelectorInBackground" ||
|
|
|
|
name == "performSelectorOnMainThread")
|
|
|
|
return OMF_performSelector;
|
2011-03-02 09:50:55 +08:00
|
|
|
|
|
|
|
// The other method families may begin with a prefix of underscores.
|
|
|
|
while (!name.empty() && name.front() == '_')
|
|
|
|
name = name.substr(1);
|
|
|
|
|
|
|
|
if (name.empty()) return OMF_None;
|
|
|
|
switch (name.front()) {
|
|
|
|
case 'a':
|
|
|
|
if (startsWithWord(name, "alloc")) return OMF_alloc;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (startsWithWord(name, "copy")) return OMF_copy;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
if (startsWithWord(name, "init")) return OMF_init;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (startsWithWord(name, "mutableCopy")) return OMF_mutableCopy;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
if (startsWithWord(name, "new")) return OMF_new;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMF_None;
|
|
|
|
}
|
2007-10-06 02:42:47 +08:00
|
|
|
|
2013-07-24 06:42:28 +08:00
|
|
|
ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
|
2013-07-24 03:31:17 +08:00
|
|
|
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
|
|
|
|
if (!first) return OIT_None;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-07-24 03:31:17 +08:00
|
|
|
StringRef name = first->getName();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-07-24 03:31:17 +08:00
|
|
|
if (name.empty()) return OIT_None;
|
|
|
|
switch (name.front()) {
|
|
|
|
case 'a':
|
2013-08-30 00:22:26 +08:00
|
|
|
if (startsWithWord(name, "array")) return OIT_Array;
|
2013-07-24 03:31:17 +08:00
|
|
|
break;
|
|
|
|
case 'd':
|
2013-10-11 02:23:13 +08:00
|
|
|
if (startsWithWord(name, "default")) return OIT_ReturnsSelf;
|
2013-07-24 03:31:17 +08:00
|
|
|
if (startsWithWord(name, "dictionary")) return OIT_Dictionary;
|
|
|
|
break;
|
2013-08-03 04:54:18 +08:00
|
|
|
case 's':
|
2013-10-11 02:23:13 +08:00
|
|
|
if (startsWithWord(name, "shared")) return OIT_ReturnsSelf;
|
|
|
|
if (startsWithWord(name, "standard")) return OIT_Singleton;
|
2017-06-03 14:40:10 +08:00
|
|
|
break;
|
2013-09-19 04:35:47 +08:00
|
|
|
case 'i':
|
|
|
|
if (startsWithWord(name, "init")) return OIT_Init;
|
Fix clang -Wimplicit-fallthrough warnings across llvm, NFC
This patch should not introduce any behavior changes. It consists of
mostly one of two changes:
1. Replacing fall through comments with the LLVM_FALLTHROUGH macro
2. Inserting 'break' before falling through into a case block consisting
of only 'break'.
We were already using this warning with GCC, but its warning behaves
slightly differently. In this patch, the following differences are
relevant:
1. GCC recognizes comments that say "fall through" as annotations, clang
doesn't
2. GCC doesn't warn on "case N: foo(); default: break;", clang does
3. GCC doesn't warn when the case contains a switch, but falls through
the outer case.
I will enable the warning separately in a follow-up patch so that it can
be cleanly reverted if necessary.
Reviewers: alexfh, rsmith, lattner, rtrieu, EricWF, bollu
Differential Revision: https://reviews.llvm.org/D53950
llvm-svn: 345882
2018-11-02 03:54:45 +08:00
|
|
|
break;
|
2013-07-24 03:31:17 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return OIT_None;
|
|
|
|
}
|
|
|
|
|
2014-09-10 07:10:54 +08:00
|
|
|
ObjCStringFormatFamily Selector::getStringFormatFamilyImpl(Selector sel) {
|
|
|
|
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
|
|
|
|
if (!first) return SFF_None;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-09-10 07:10:54 +08:00
|
|
|
StringRef name = first->getName();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-09-10 07:10:54 +08:00
|
|
|
switch (name.front()) {
|
|
|
|
case 'a':
|
|
|
|
if (name == "appendFormat") return SFF_NSString;
|
|
|
|
break;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-09-10 07:10:54 +08:00
|
|
|
case 'i':
|
|
|
|
if (name == "initWithFormat") return SFF_NSString;
|
|
|
|
break;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-09-10 07:10:54 +08:00
|
|
|
case 'l':
|
|
|
|
if (name == "localizedStringWithFormat") return SFF_NSString;
|
|
|
|
break;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-09-10 07:10:54 +08:00
|
|
|
case 's':
|
|
|
|
if (name == "stringByAppendingFormat" ||
|
|
|
|
name == "stringWithFormat") return SFF_NSString;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return SFF_None;
|
|
|
|
}
|
|
|
|
|
2009-03-04 13:35:38 +08:00
|
|
|
namespace {
|
2017-11-04 06:35:27 +08:00
|
|
|
|
|
|
|
struct SelectorTableImpl {
|
|
|
|
llvm::FoldingSet<MultiKeywordSelector> Table;
|
|
|
|
llvm::BumpPtrAllocator Allocator;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
2009-03-04 13:35:38 +08:00
|
|
|
|
|
|
|
static SelectorTableImpl &getSelectorTableImpl(void *P) {
|
|
|
|
return *static_cast<SelectorTableImpl*>(P);
|
|
|
|
}
|
|
|
|
|
2013-06-11 05:36:55 +08:00
|
|
|
SmallString<64>
|
2013-06-08 06:29:12 +08:00
|
|
|
SelectorTable::constructSetterName(StringRef Name) {
|
2013-06-11 05:36:55 +08:00
|
|
|
SmallString<64> SetterName("set");
|
|
|
|
SetterName += Name;
|
|
|
|
SetterName[3] = toUppercase(SetterName[3]);
|
|
|
|
return SetterName;
|
2013-06-08 06:29:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-11 05:36:55 +08:00
|
|
|
Selector
|
2013-06-08 06:29:12 +08:00
|
|
|
SelectorTable::constructSetterSelector(IdentifierTable &Idents,
|
|
|
|
SelectorTable &SelTable,
|
|
|
|
const IdentifierInfo *Name) {
|
|
|
|
IdentifierInfo *SetterName =
|
|
|
|
&Idents.get(constructSetterName(Name->getName()));
|
2012-02-04 21:45:25 +08:00
|
|
|
return SelTable.getUnarySelector(SetterName);
|
|
|
|
}
|
|
|
|
|
2018-05-23 08:52:20 +08:00
|
|
|
std::string SelectorTable::getPropertyNameFromSetterSelector(Selector Sel) {
|
|
|
|
StringRef Name = Sel.getNameForSlot(0);
|
|
|
|
assert(Name.startswith("set") && "invalid setter name");
|
|
|
|
return (Twine(toLowercase(Name[3])) + Name.drop_front(4)).str();
|
|
|
|
}
|
|
|
|
|
2011-04-19 06:47:04 +08:00
|
|
|
size_t SelectorTable::getTotalMemory() const {
|
|
|
|
SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
|
|
|
|
return SelTabImpl.Allocator.getTotalMemory();
|
|
|
|
}
|
2009-03-04 13:35:38 +08:00
|
|
|
|
2007-10-07 10:00:24 +08:00
|
|
|
Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) {
|
|
|
|
if (nKeys < 2)
|
|
|
|
return Selector(IIV[0], nKeys);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-04 13:35:38 +08:00
|
|
|
SelectorTableImpl &SelTabImpl = getSelectorTableImpl(Impl);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
// Unique selector, to guarantee there is one per name.
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
MultiKeywordSelector::Profile(ID, IIV, nKeys);
|
|
|
|
|
2014-05-08 14:41:40 +08:00
|
|
|
void *InsertPos = nullptr;
|
2009-03-04 13:35:38 +08:00
|
|
|
if (MultiKeywordSelector *SI =
|
|
|
|
SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
|
2007-10-06 02:42:47 +08:00
|
|
|
return Selector(SI);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-10-06 02:42:47 +08:00
|
|
|
// MultiKeywordSelector objects are not allocated with new because they have a
|
|
|
|
// variable size array (for parameter types) at the end of them.
|
2009-03-04 13:35:38 +08:00
|
|
|
unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *);
|
|
|
|
MultiKeywordSelector *SI =
|
2016-10-20 22:27:22 +08:00
|
|
|
(MultiKeywordSelector *)SelTabImpl.Allocator.Allocate(
|
|
|
|
Size, alignof(MultiKeywordSelector));
|
2007-10-06 02:42:47 +08:00
|
|
|
new (SI) MultiKeywordSelector(nKeys, IIV);
|
2009-03-04 13:35:38 +08:00
|
|
|
SelTabImpl.Table.InsertNode(SI, InsertPos);
|
2007-10-06 02:42:47 +08:00
|
|
|
return Selector(SI);
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectorTable::SelectorTable() {
|
2009-03-04 13:35:38 +08:00
|
|
|
Impl = new SelectorTableImpl();
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SelectorTable::~SelectorTable() {
|
2009-03-04 13:35:38 +08:00
|
|
|
delete &getSelectorTableImpl(Impl);
|
2007-10-06 02:42:47 +08:00
|
|
|
}
|
|
|
|
|
2009-11-04 08:56:37 +08:00
|
|
|
const char *clang::getOperatorSpelling(OverloadedOperatorKind Operator) {
|
|
|
|
switch (Operator) {
|
|
|
|
case OO_None:
|
|
|
|
case NUM_OVERLOADED_OPERATORS:
|
2014-05-08 14:41:40 +08:00
|
|
|
return nullptr;
|
2010-03-12 19:27:37 +08:00
|
|
|
|
2009-11-04 08:56:37 +08:00
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
case OO_##Name: return Spelling;
|
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
}
|
2010-03-12 19:27:37 +08:00
|
|
|
|
2012-01-17 14:56:22 +08:00
|
|
|
llvm_unreachable("Invalid OverloadedOperatorKind!");
|
2009-11-04 08:56:37 +08:00
|
|
|
}
|
2015-06-20 02:14:38 +08:00
|
|
|
|
2015-06-25 06:02:08 +08:00
|
|
|
StringRef clang::getNullabilitySpelling(NullabilityKind kind,
|
|
|
|
bool isContextSensitive) {
|
2015-06-20 02:14:38 +08:00
|
|
|
switch (kind) {
|
|
|
|
case NullabilityKind::NonNull:
|
2015-06-25 06:02:08 +08:00
|
|
|
return isContextSensitive ? "nonnull" : "_Nonnull";
|
2015-06-20 02:14:38 +08:00
|
|
|
|
|
|
|
case NullabilityKind::Nullable:
|
2015-06-25 06:02:08 +08:00
|
|
|
return isContextSensitive ? "nullable" : "_Nullable";
|
2015-06-20 02:14:38 +08:00
|
|
|
|
2020-12-07 22:14:25 +08:00
|
|
|
case NullabilityKind::NullableResult:
|
|
|
|
assert(!isContextSensitive &&
|
|
|
|
"_Nullable_result isn't supported as context-sensitive keyword");
|
|
|
|
return "_Nullable_result";
|
|
|
|
|
2015-06-20 02:14:38 +08:00
|
|
|
case NullabilityKind::Unspecified:
|
2015-06-25 06:02:08 +08:00
|
|
|
return isContextSensitive ? "null_unspecified" : "_Null_unspecified";
|
2015-06-20 02:14:38 +08:00
|
|
|
}
|
2015-06-20 08:06:30 +08:00
|
|
|
llvm_unreachable("Unknown nullability kind.");
|
2015-06-20 02:14:38 +08:00
|
|
|
}
|