本文整理汇总了C++中Identifier::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ Identifier::empty方法的具体用法?C++ Identifier::empty怎么用?C++ Identifier::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Identifier
的用法示例。
在下文中一共展示了Identifier::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare
int Identifier::compare(Identifier other) const {
// Handle empty identifiers.
if (empty() || other.empty()) {
if (empty() != other.empty()) {
return other.empty() ? -1 : 1;
}
return 0;
}
return str().compare(other.str());
}
示例2: addParameters
static void addParameters(ArrayRef<Identifier> &ArgNames,
const ParameterList *paramList,
TextEntity &Ent,
SourceManager &SM,
unsigned BufferID) {
for (auto ¶m : *paramList) {
StringRef Arg;
if (!ArgNames.empty()) {
Identifier Id = ArgNames.front();
Arg = Id.empty() ? "_" : Id.str();
ArgNames = ArgNames.slice(1);
}
if (auto typeRepr = param->getTypeLoc().getTypeRepr()) {
SourceRange TypeRange = param->getTypeLoc().getSourceRange();
if (auto InOutTyR = dyn_cast_or_null<InOutTypeRepr>(typeRepr))
TypeRange = InOutTyR->getBase()->getSourceRange();
if (TypeRange.isInvalid())
continue;
unsigned StartOffs = SM.getLocOffsetInBuffer(TypeRange.Start, BufferID);
unsigned EndOffs =
SM.getLocOffsetInBuffer(Lexer::getLocForEndOfToken(SM, TypeRange.End),
BufferID);
TextRange TR{ StartOffs, EndOffs-StartOffs };
TextEntity Param(param, Arg, TR, StartOffs);
Ent.SubEntities.push_back(std::move(Param));
}
}
}
示例3: passCallArgNames
bool SemaAnnotator::passCallArgNames(Expr *Fn, TupleExpr *TupleE) {
ValueDecl *D = extractDecl(Fn);
if (!D)
return true; // continue.
ArrayRef<Identifier> ArgNames = TupleE->getElementNames();
ArrayRef<SourceLoc> ArgLocs = TupleE->getElementNameLocs();
for (auto i : indices(ArgNames)) {
Identifier Name = ArgNames[i];
if (Name.empty())
continue;
SourceLoc Loc = ArgLocs[i];
if (Loc.isInvalid())
continue;
CharSourceRange Range{ Loc, Name.getLength() };
bool Continue = SEWalker.visitCallArgName(Name, Range, D);
if (!Continue) {
Cancelled = true;
return false;
}
}
return true;
}
示例4: validateID
bool Identifier::validateID(const std::string & strPurportedID)
{
if (strPurportedID.empty())
return false;
Identifier theID;
const String strID(strPurportedID);
App::Me().Crypto().Util().SetIDFromEncoded(strID, theID);
return !theID.empty();
}
示例5: StoreOutgoing
bool Blockchain::StoreOutgoing(
const Identifier& senderNymID,
const Identifier& accountID,
const Identifier& recipientContactID,
const proto::BlockchainTransaction& transaction) const
{
LOCK_ACCOUNT()
const std::string sNymID = senderNymID.str();
const std::string sAccountID = accountID.str();
auto account = load_account(accountLock, sNymID, sAccountID);
if (false == bool(account)) {
otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist."
<< std::endl;
return false;
}
const auto& txid = transaction.txid();
account->add_outgoing(txid);
auto saved = api_.Storage().Store(sNymID, account->type(), *account);
if (false == saved) {
otErr << OT_METHOD << __FUNCTION__ << ": Failed to save account."
<< std::endl;
return false;
}
saved = api_.Storage().Store(transaction);
if (false == saved) {
otErr << OT_METHOD << __FUNCTION__ << ": Failed to save transaction."
<< std::endl;
return false;
}
if (recipientContactID.empty()) { return true; }
return activity_.AddBlockchainTransaction(
senderNymID,
recipientContactID,
StorageBox::OUTGOINGBLOCKCHAIN,
transaction);
}
示例6: addParameters
static void addParameters(ArrayRef<Identifier> &ArgNames,
const Pattern *Pat,
TextEntity &Ent,
SourceManager &SM,
unsigned BufferID) {
if (auto ParenPat = dyn_cast<ParenPattern>(Pat)) {
addParameters(ArgNames, ParenPat->getSubPattern(), Ent, SM, BufferID);
return;
}
if (auto Tuple = dyn_cast<TuplePattern>(Pat)) {
for (const auto &Elt : Tuple->getElements())
addParameters(ArgNames, Elt.getPattern(), Ent, SM, BufferID);
return;
}
StringRef Arg;
if (!ArgNames.empty()) {
Identifier Id = ArgNames.front();
Arg = Id.empty() ? "_" : Id.str();
ArgNames = ArgNames.slice(1);
}
if (auto Typed = dyn_cast<TypedPattern>(Pat)) {
VarDecl *VD = nullptr;
if (auto Named = dyn_cast<NamedPattern>(Typed->getSubPattern())) {
VD = Named->getDecl();
}
SourceRange TypeRange = Typed->getTypeLoc().getSourceRange();
if (auto InOutTyR =
dyn_cast_or_null<InOutTypeRepr>(Typed->getTypeLoc().getTypeRepr())) {
TypeRange = InOutTyR->getBase()->getSourceRange();
}
if (TypeRange.isInvalid())
return;
unsigned StartOffs = SM.getLocOffsetInBuffer(TypeRange.Start, BufferID);
unsigned EndOffs =
SM.getLocOffsetInBuffer(Lexer::getLocForEndOfToken(SM, TypeRange.End),
BufferID);
TextRange TR{ StartOffs, EndOffs-StartOffs };
TextEntity Param(VD, Arg, TR, StartOffs);
Ent.SubEntities.push_back(std::move(Param));
}
}
示例7: getSubPathDescription
/// Returns a string representation of the SubPath
/// suitable for use in diagnostic text. Only supports the Projections
/// that stored-property relaxation supports: struct stored properties
/// and tuple elements.
std::string AccessSummaryAnalysis::getSubPathDescription(
SILType baseType, const IndexTrieNode *subPath, SILModule &M) {
// Walk the trie to the root to collect the sequence (in reverse order).
llvm::SmallVector<unsigned, 4> reversedIndices;
const IndexTrieNode *I = subPath;
while (!I->isRoot()) {
reversedIndices.push_back(I->getIndex());
I = I->getParent();
}
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
SILType containingType = baseType;
for (unsigned index : reversed(reversedIndices)) {
os << ".";
if (StructDecl *D = containingType.getStructOrBoundGenericStruct()) {
auto iter = D->getStoredProperties().begin();
std::advance(iter, index);
VarDecl *var = *iter;
os << var->getBaseName();
containingType = containingType.getFieldType(var, M);
continue;
}
if (auto tupleTy = containingType.getAs<TupleType>()) {
Identifier elementName = tupleTy->getElement(index).getName();
if (elementName.empty())
os << index;
else
os << elementName;
containingType = containingType.getTupleElementType(index);
continue;
}
llvm_unreachable("Unexpected type in projection SubPath!");
}
return os.str();
}
示例8: filterForDiscriminator
static void filterForDiscriminator(SmallVectorImpl<Result> &results,
DebuggerClient *debugClient) {
Identifier discriminator = debugClient->getPreferredPrivateDiscriminator();
if (discriminator.empty())
return;
auto doesNotMatch = [discriminator](Result next) -> bool {
return !matchesDiscriminator(discriminator, next);
};
auto lastMatchIter = std::find_if_not(results.rbegin(), results.rend(),
doesNotMatch);
if (lastMatchIter == results.rend())
return;
Result lastMatch = *lastMatchIter;
auto newEnd = std::remove_if(results.begin(), lastMatchIter.base()-1,
doesNotMatch);
results.erase(newEnd, results.end());
results.push_back(lastMatch);
}
示例9: getDiscriminatorForPrivateValue
Identifier ModuleFile::getDiscriminatorForPrivateValue(const ValueDecl *D) {
Identifier discriminator = PrivateDiscriminatorsByValue.lookup(D);
assert(!discriminator.empty() && "no discriminator found for decl");
return discriminator;
}
示例10: checkForForbiddenPrefix
void TypeChecker::checkForForbiddenPrefix(Identifier Ident) {
if (!hasEnabledForbiddenTypecheckPrefix())
return;
checkForForbiddenPrefix(Ident.empty() ? StringRef() : Ident.str());
}
示例11: assert
Identifier
SerializedASTFile::getDiscriminatorForPrivateValue(const ValueDecl *D) const {
Identifier discriminator = File.getDiscriminatorForPrivateValue(D);
assert(!discriminator.empty() && "no discriminator found for value");
return discriminator;
}
示例12: performCompile
/// Performs the compile requested by the user.
/// \returns true on error
static bool performCompile(CompilerInstance &Instance,
CompilerInvocation &Invocation,
ArrayRef<const char *> Args,
int &ReturnValue) {
FrontendOptions opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
bool inputIsLLVMIr = Invocation.getInputKind() == InputFileKind::IFK_LLVM_IR;
if (inputIsLLVMIr) {
auto &LLVMContext = llvm::getGlobalContext();
// Load in bitcode file.
assert(Invocation.getInputFilenames().size() == 1 &&
"We expect a single input for bitcode input!");
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(Invocation.getInputFilenames()[0]);
if (!FileBufOrErr) {
Instance.getASTContext().Diags.diagnose(SourceLoc(),
diag::error_open_input_file,
Invocation.getInputFilenames()[0],
FileBufOrErr.getError().message());
return true;
}
llvm::MemoryBuffer *MainFile = FileBufOrErr.get().get();
llvm::SMDiagnostic Err;
std::unique_ptr<llvm::Module> Module = llvm::parseIR(
MainFile->getMemBufferRef(),
Err, LLVMContext);
if (!Module) {
// TODO: Translate from the diagnostic info to the SourceManager location
// if available.
Instance.getASTContext().Diags.diagnose(SourceLoc(),
diag::error_parse_input_file,
Invocation.getInputFilenames()[0],
Err.getMessage());
return true;
}
// TODO: remove once the frontend understands what action it should perform
IRGenOpts.OutputKind = getOutputKind(Action);
return performLLVM(IRGenOpts, Instance.getASTContext(), Module.get());
}
ReferencedNameTracker nameTracker;
bool shouldTrackReferences = !opts.ReferenceDependenciesFilePath.empty();
if (shouldTrackReferences)
Instance.setReferencedNameTracker(&nameTracker);
if (Action == FrontendOptions::DumpParse ||
Action == FrontendOptions::DumpInterfaceHash)
Instance.performParseOnly();
else
Instance.performSema();
FrontendOptions::DebugCrashMode CrashMode = opts.CrashMode;
if (CrashMode == FrontendOptions::DebugCrashMode::AssertAfterParse)
debugFailWithAssertion();
else if (CrashMode == FrontendOptions::DebugCrashMode::CrashAfterParse)
debugFailWithCrash();
ASTContext &Context = Instance.getASTContext();
if (Action == FrontendOptions::REPL) {
runREPL(Instance, ProcessCmdLine(Args.begin(), Args.end()),
Invocation.getParseStdlib());
return false;
}
SourceFile *PrimarySourceFile = Instance.getPrimarySourceFile();
// We've been told to dump the AST (either after parsing or type-checking,
// which is already differentiated in CompilerInstance::performSema()),
// so dump or print the main source file and return.
if (Action == FrontendOptions::DumpParse ||
Action == FrontendOptions::DumpAST ||
Action == FrontendOptions::PrintAST ||
Action == FrontendOptions::DumpTypeRefinementContexts ||
Action == FrontendOptions::DumpInterfaceHash) {
SourceFile *SF = PrimarySourceFile;
if (!SF) {
SourceFileKind Kind = Invocation.getSourceFileKind();
SF = &Instance.getMainModule()->getMainSourceFile(Kind);
}
if (Action == FrontendOptions::PrintAST)
SF->print(llvm::outs(), PrintOptions::printEverything());
else if (Action == FrontendOptions::DumpTypeRefinementContexts)
SF->getTypeRefinementContext()->dump(llvm::errs(), Context.SourceMgr);
else if (Action == FrontendOptions::DumpInterfaceHash)
SF->dumpInterfaceHash(llvm::errs());
else
SF->dump();
return false;
}
//.........这里部分代码省略.........
示例13: ParsingTypeTuple
/// parseTypeTupleBody
/// type-tuple:
/// '(' type-tuple-body? ')'
/// type-tuple-body:
/// type-tuple-element (',' type-tuple-element)* '...'?
/// type-tuple-element:
/// identifier ':' type
/// type
ParserResult<TupleTypeRepr> Parser::parseTypeTupleBody() {
Parser::StructureMarkerRAII ParsingTypeTuple(*this, Tok);
SourceLoc RPLoc, LPLoc = consumeToken(tok::l_paren);
SourceLoc EllipsisLoc;
unsigned EllipsisIdx;
SmallVector<TypeRepr *, 8> ElementsR;
// We keep track of the labels separately, and apply them at the end.
SmallVector<std::tuple<Identifier, SourceLoc, Identifier, SourceLoc>, 4>
Labels;
ParserStatus Status = parseList(tok::r_paren, LPLoc, RPLoc,
tok::comma, /*OptionalSep=*/false,
/*AllowSepAfterLast=*/false,
diag::expected_rparen_tuple_type_list,
[&] () -> ParserStatus {
// If this is a deprecated use of the inout marker in an argument list,
// consume the inout.
SourceLoc InOutLoc;
bool hasAnyInOut = false;
bool hasValidInOut = false;
if (consumeIf(tok::kw_inout, InOutLoc)) {
hasAnyInOut = true;
hasValidInOut = false;
}
// If the tuple element starts with a potential argument label followed by a
// ':' or another potential argument label, then the identifier is an
// element tag, and it is followed by a type annotation.
if (Tok.canBeArgumentLabel() &&
(peekToken().is(tok::colon) || peekToken().canBeArgumentLabel())) {
// Consume the name
Identifier name;
if (!Tok.is(tok::kw__))
name = Context.getIdentifier(Tok.getText());
SourceLoc nameLoc = consumeToken();
// If there is a second name, consume it as well.
Identifier secondName;
SourceLoc secondNameLoc;
if (Tok.canBeArgumentLabel()) {
if (!Tok.is(tok::kw__))
secondName = Context.getIdentifier(Tok.getText());
secondNameLoc = consumeToken();
}
// Consume the ':'.
if (!consumeIf(tok::colon))
diagnose(Tok, diag::expected_parameter_colon);
SourceLoc postColonLoc = Tok.getLoc();
// Consume 'inout' if present.
if (!hasAnyInOut && consumeIf(tok::kw_inout, InOutLoc)) {
hasValidInOut = true;
}
SourceLoc extraneousInOutLoc;
while (consumeIf(tok::kw_inout, extraneousInOutLoc)) {
diagnose(Tok, diag::parameter_inout_var_let_repeated)
.fixItRemove(extraneousInOutLoc);
}
// Parse the type annotation.
ParserResult<TypeRepr> type = parseType(diag::expected_type);
if (type.hasCodeCompletion())
return makeParserCodeCompletionStatus();
if (type.isNull())
return makeParserError();
if (!hasValidInOut && hasAnyInOut) {
diagnose(Tok.getLoc(), diag::inout_as_attr_disallowed)
.fixItRemove(InOutLoc)
.fixItInsert(postColonLoc, "inout ");
}
// If an 'inout' marker was specified, build the type. Note that we bury
// the inout locator within the named locator. This is weird but required
// by sema apparently.
if (InOutLoc.isValid())
type = makeParserResult(new (Context) InOutTypeRepr(type.get(),
InOutLoc));
// Record the label. We will look at these at the end.
if (Labels.empty()) {
Labels.assign(ElementsR.size(),
std::make_tuple(Identifier(), SourceLoc(),
Identifier(), SourceLoc()));
}
Labels.push_back(std::make_tuple(name, nameLoc,
secondName, secondNameLoc));
ElementsR.push_back(type.get());
//.........这里部分代码省略.........
示例14: findDeclContext
DeclContext *
ASTBuilder::findDeclContext(NodePointer node) {
switch (node->getKind()) {
case Demangle::Node::Kind::DeclContext:
case Demangle::Node::Kind::Type:
case Demangle::Node::Kind::BoundGenericClass:
case Demangle::Node::Kind::BoundGenericEnum:
case Demangle::Node::Kind::BoundGenericProtocol:
case Demangle::Node::Kind::BoundGenericStructure:
case Demangle::Node::Kind::BoundGenericTypeAlias:
return findDeclContext(node->getFirstChild());
case Demangle::Node::Kind::Module:
return findModule(node);
case Demangle::Node::Kind::Class:
case Demangle::Node::Kind::Enum:
case Demangle::Node::Kind::Protocol:
case Demangle::Node::Kind::Structure:
case Demangle::Node::Kind::TypeAlias: {
const auto &declNameNode = node->getChild(1);
// Handle local declarations.
if (declNameNode->getKind() == Demangle::Node::Kind::LocalDeclName) {
// Find the AST node for the defining module.
auto moduleNode = findModuleNode(node);
if (!moduleNode) return nullptr;
auto module = findModule(moduleNode);
if (!module) return nullptr;
// Look up the local type by its mangling.
auto mangledName = Demangle::mangleNode(node);
auto decl = module->lookupLocalType(mangledName);
if (!decl) return nullptr;
return dyn_cast<DeclContext>(decl);
}
StringRef name;
StringRef relatedEntityKind;
Identifier privateDiscriminator;
if (declNameNode->getKind() == Demangle::Node::Kind::Identifier) {
name = declNameNode->getText();
} else if (declNameNode->getKind() ==
Demangle::Node::Kind::PrivateDeclName) {
name = declNameNode->getChild(1)->getText();
privateDiscriminator =
Ctx.getIdentifier(declNameNode->getChild(0)->getText());
} else if (declNameNode->getKind() ==
Demangle::Node::Kind::RelatedEntityDeclName) {
name = declNameNode->getChild(0)->getText();
relatedEntityKind = declNameNode->getText();
// Ignore any other decl-name productions for now.
} else {
return nullptr;
}
// Do some special logic for foreign type declarations.
if (privateDiscriminator.empty()) {
if (auto foreignModuleKind = getForeignModuleKind(node->getChild(0))) {
return findForeignTypeDecl(name, relatedEntityKind,
foreignModuleKind.getValue(),
node->getKind());
}
}
DeclContext *dc = findDeclContext(node->getChild(0));
if (!dc) {
return nullptr;
}
return findTypeDecl(dc, Ctx.getIdentifier(name),
privateDiscriminator, node->getKind());
}
case Demangle::Node::Kind::Global:
return findDeclContext(node->getChild(0));
case Demangle::Node::Kind::Extension: {
auto *moduleDecl = dyn_cast_or_null<ModuleDecl>(
findDeclContext(node->getChild(0)));
if (!moduleDecl)
return nullptr;
auto *nominalDecl = dyn_cast_or_null<NominalTypeDecl>(
findDeclContext(node->getChild(1)));
if (!nominalDecl)
return nullptr;
CanGenericSignature genericSig;
if (node->getNumChildren() > 2)
genericSig = demangleGenericSignature(nominalDecl, node->getChild(2));
for (auto *ext : nominalDecl->getExtensions()) {
if (ext->getParentModule() != moduleDecl)
continue;
//.........这里部分代码省略.........
示例15: performCompile
/// Performs the compile requested by the user.
/// \param Instance Will be reset after performIRGeneration when the verifier
/// mode is NoVerify and there were no errors.
/// \returns true on error
static bool performCompile(std::unique_ptr<CompilerInstance> &Instance,
CompilerInvocation &Invocation,
ArrayRef<const char *> Args,
int &ReturnValue,
FrontendObserver *observer) {
FrontendOptions opts = Invocation.getFrontendOptions();
FrontendOptions::ActionType Action = opts.RequestedAction;
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
bool inputIsLLVMIr = Invocation.getInputKind() == InputFileKind::IFK_LLVM_IR;
if (inputIsLLVMIr) {
auto &LLVMContext = getGlobalLLVMContext();
// Load in bitcode file.
assert(Invocation.getInputFilenames().size() == 1 &&
"We expect a single input for bitcode input!");
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(Invocation.getInputFilenames()[0]);
if (!FileBufOrErr) {
Instance->getASTContext().Diags.diagnose(SourceLoc(),
diag::error_open_input_file,
Invocation.getInputFilenames()[0],
FileBufOrErr.getError().message());
return true;
}
llvm::MemoryBuffer *MainFile = FileBufOrErr.get().get();
llvm::SMDiagnostic Err;
std::unique_ptr<llvm::Module> Module = llvm::parseIR(
MainFile->getMemBufferRef(),
Err, LLVMContext);
if (!Module) {
// TODO: Translate from the diagnostic info to the SourceManager location
// if available.
Instance->getASTContext().Diags.diagnose(SourceLoc(),
diag::error_parse_input_file,
Invocation.getInputFilenames()[0],
Err.getMessage());
return true;
}
// TODO: remove once the frontend understands what action it should perform
IRGenOpts.OutputKind = getOutputKind(Action);
return performLLVM(IRGenOpts, Instance->getASTContext(), Module.get());
}
ReferencedNameTracker nameTracker;
bool shouldTrackReferences = !opts.ReferenceDependenciesFilePath.empty();
if (shouldTrackReferences)
Instance->setReferencedNameTracker(&nameTracker);
if (Action == FrontendOptions::Parse ||
Action == FrontendOptions::DumpParse ||
Action == FrontendOptions::DumpInterfaceHash)
Instance->performParseOnly();
else
Instance->performSema();
if (Action == FrontendOptions::Parse)
return Instance->getASTContext().hadError();
if (observer) {
observer->performedSemanticAnalysis(*Instance);
}
FrontendOptions::DebugCrashMode CrashMode = opts.CrashMode;
if (CrashMode == FrontendOptions::DebugCrashMode::AssertAfterParse)
debugFailWithAssertion();
else if (CrashMode == FrontendOptions::DebugCrashMode::CrashAfterParse)
debugFailWithCrash();
ASTContext &Context = Instance->getASTContext();
if (Action == FrontendOptions::REPL) {
runREPL(*Instance, ProcessCmdLine(Args.begin(), Args.end()),
Invocation.getParseStdlib());
return Context.hadError();
}
SourceFile *PrimarySourceFile = Instance->getPrimarySourceFile();
// We've been told to dump the AST (either after parsing or type-checking,
// which is already differentiated in CompilerInstance::performSema()),
// so dump or print the main source file and return.
if (Action == FrontendOptions::DumpParse ||
Action == FrontendOptions::DumpAST ||
Action == FrontendOptions::PrintAST ||
Action == FrontendOptions::DumpScopeMaps ||
Action == FrontendOptions::DumpTypeRefinementContexts ||
Action == FrontendOptions::DumpInterfaceHash) {
SourceFile *SF = PrimarySourceFile;
if (!SF) {
SourceFileKind Kind = Invocation.getSourceFileKind();
SF = &Instance->getMainModule()->getMainSourceFile(Kind);
//.........这里部分代码省略.........