本文整理汇总了C++中ASTContext::getIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTContext::getIdentifier方法的具体用法?C++ ASTContext::getIdentifier怎么用?C++ ASTContext::getIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTContext
的用法示例。
在下文中一共展示了ASTContext::getIdentifier方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: formDeclName
DeclName swift::formDeclName(ASTContext &ctx,
StringRef baseName,
ArrayRef<StringRef> argumentLabels,
bool isFunctionName) {
// We cannot import when the base name is not an identifier.
if (baseName.empty() || !Lexer::isIdentifier(baseName))
return DeclName();
// Get the identifier for the base name.
Identifier baseNameId = ctx.getIdentifier(baseName);
// For non-functions, just use the base name.
if (!isFunctionName) return baseNameId;
// For functions, we need to form a complete name.
// Convert the argument names.
SmallVector<Identifier, 4> argumentLabelIds;
for (auto argName : argumentLabels) {
if (argumentLabels.empty() || !Lexer::isIdentifier(argName)) {
argumentLabelIds.push_back(Identifier());
continue;
}
argumentLabelIds.push_back(ctx.getIdentifier(argName));
}
// Build the result.
return DeclName(ctx, baseNameId, argumentLabelIds);
}
示例2: Implementation
Implementation(SourceManager &SM, unsigned BufferID,
const LangOptions &Opts, StringRef ModuleName)
: LangOpts(Opts),
Diags(SM),
Ctx(LangOpts, SearchPathOpts, SM, Diags),
SF(new (Ctx) SourceFile(
*Module::create(Ctx.getIdentifier(ModuleName), Ctx),
SourceFileKind::Main, BufferID,
SourceFile::ImplicitModuleImportKind::None)) {
}
示例3: isSanitizerInstrumentation
// Returns true when the instruction represents added instrumentation for
/// run-time sanitizers.
static bool isSanitizerInstrumentation(SILInstruction *Instruction,
ASTContext &Ctx) {
auto *BI = dyn_cast<BuiltinInst>(Instruction);
if (!BI)
return false;
Identifier Name = BI->getName();
if (Name == Ctx.getIdentifier("tsanInoutAccess"))
return true;
return false;
}
示例4: declareOptionalType
static void declareOptionalType(ASTContext &ctx, SourceFile *fileForLookups,
Identifier name) {
auto wrapped = new (ctx) GenericTypeParamDecl(fileForLookups,
ctx.getIdentifier("Wrapped"),
SourceLoc(), /*depth*/0,
/*index*/0);
auto params = GenericParamList::create(ctx, SourceLoc(), wrapped,
SourceLoc());
auto decl = new (ctx) EnumDecl(SourceLoc(), name, SourceLoc(),
/*inherited*/{}, params, fileForLookups);
wrapped->setDeclContext(decl);
fileForLookups->Decls.push_back(decl);
}
示例5: getIdentifierForObjCSelector
static Identifier getIdentifierForObjCSelector(ObjCSelector selector, ASTContext &Ctxt) {
SmallVector<char, 64> buffer;
auto str = selector.getString(buffer);
return Ctxt.getIdentifier(str);
}
示例6: assert
ImportDepth::ImportDepth(ASTContext &context, CompilerInvocation &invocation) {
llvm::DenseSet<ModuleDecl *> seen;
std::deque<std::pair<ModuleDecl *, uint8_t>> worklist;
StringRef mainModule = invocation.getModuleName();
auto *main = context.getLoadedModule(context.getIdentifier(mainModule));
assert(main && "missing main module");
worklist.emplace_back(main, uint8_t(0));
// Imports from -import-name such as Playground auxiliary sources are treated
// specially by applying import depth 0.
llvm::StringSet<> auxImports;
for (StringRef moduleName :
invocation.getFrontendOptions().ImplicitImportModuleNames)
auxImports.insert(moduleName);
// Private imports from this module.
// FIXME: only the private imports from the current source file.
ModuleDecl::ImportFilter importFilter;
importFilter |= ModuleDecl::ImportFilterKind::Private;
importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
SmallVector<ModuleDecl::ImportedModule, 16> mainImports;
main->getImportedModules(mainImports, importFilter);
for (auto &import : mainImports) {
uint8_t depth = 1;
if (auxImports.count(import.second->getName().str()))
depth = 0;
worklist.emplace_back(import.second, depth);
}
// Fill depths with BFS over module imports.
while (!worklist.empty()) {
ModuleDecl *module;
uint8_t depth;
std::tie(module, depth) = worklist.front();
worklist.pop_front();
if (!seen.insert(module).second)
continue;
// Insert new module:depth mapping.
const clang::Module *CM = module->findUnderlyingClangModule();
if (CM) {
depths[CM->getFullModuleName()] = depth;
} else {
depths[module->getName().str()] = depth;
}
// Add imports to the worklist.
SmallVector<ModuleDecl::ImportedModule, 16> imports;
module->getImportedModules(imports);
for (auto &import : imports) {
uint8_t next = std::max(depth, uint8_t(depth + 1)); // unsigned wrap
// Implicitly imported sub-modules get the same depth as their parent.
if (const clang::Module *CMI = import.second->findUnderlyingClangModule())
if (CM && CMI->isSubModuleOf(CM))
next = depth;
worklist.emplace_back(import.second, next);
}
}
}