本文整理汇总了C++中ExprResult::take方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprResult::take方法的具体用法?C++ ExprResult::take怎么用?C++ ExprResult::take使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExprResult
的用法示例。
在下文中一共展示了ExprResult::take方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseLexedMethodDeclaration
void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
// If this is a member template, introduce the template parameter scope.
ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
if (LM.TemplateScope)
Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method);
// Start the delayed C++ method declaration
Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
// Introduce the parameters into scope and parse their default
// arguments.
ParseScope PrototypeScope(this,
Scope::FunctionPrototypeScope|Scope::DeclScope);
for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
// Introduce the parameter into scope.
Actions.ActOnDelayedCXXMethodParameter(getCurScope(),
LM.DefaultArgs[I].Param);
if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
// Save the current token position.
SourceLocation origLoc = Tok.getLocation();
// Parse the default argument from its saved token stream.
Toks->push_back(Tok); // So that the current token doesn't get lost
PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false);
// Consume the previously-pushed token.
ConsumeAnyToken();
// Consume the '='.
assert(Tok.is(tok::equal) && "Default argument not starting with '='");
SourceLocation EqualLoc = ConsumeToken();
// The argument isn't actually potentially evaluated unless it is
// used.
EnterExpressionEvaluationContext Eval(Actions,
Sema::PotentiallyEvaluatedIfUsed,
LM.DefaultArgs[I].Param);
ExprResult DefArgResult;
if (getLangOpts().CPlusPlus0x && Tok.is(tok::l_brace)) {
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
DefArgResult = ParseBraceInitializer();
} else
DefArgResult = ParseAssignmentExpression();
if (DefArgResult.isInvalid())
Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param);
else {
if (Tok.is(tok::cxx_defaultarg_end))
ConsumeToken();
else
Diag(Tok.getLocation(), diag::err_default_arg_unparsed);
Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
DefArgResult.take());
}
assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
Tok.getLocation()) &&
"ParseAssignmentExpression went over the default arg tokens!");
// There could be leftover tokens (e.g. because of an error).
// Skip through until we reach the original token position.
while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
ConsumeAnyToken();
delete Toks;
LM.DefaultArgs[I].Toks = 0;
}
}
PrototypeScope.Exit();
// Finish the delayed C++ method declaration.
Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
}
示例2: SynthesizeSVRInit
Expr* ValueExtractionSynthesizer::SynthesizeSVRInit(Expr* E) {
if (!m_gClingVD)
FindAndCacheRuntimeDecls();
// Build a reference to gCling
ExprResult gClingDRE
= m_Sema->BuildDeclRefExpr(m_gClingVD, m_Context->VoidPtrTy,
VK_RValue, SourceLocation());
// We have the wrapper as Sema's CurContext
FunctionDecl* FD = cast<FunctionDecl>(m_Sema->CurContext);
ExprWithCleanups* Cleanups = 0;
// In case of ExprWithCleanups we need to extend its 'scope' to the call.
if (E && isa<ExprWithCleanups>(E)) {
Cleanups = cast<ExprWithCleanups>(E);
E = Cleanups->getSubExpr();
}
// Build a reference to Value* in the wrapper, should be
// the only argument of the wrapper.
SourceLocation locStart = (E) ? E->getLocStart() : FD->getLocStart();
SourceLocation locEnd = (E) ? E->getLocEnd() : FD->getLocEnd();
ExprResult wrapperSVRDRE
= m_Sema->BuildDeclRefExpr(FD->getParamDecl(0), m_Context->VoidPtrTy,
VK_RValue, locStart);
QualType ETy = (E) ? E->getType() : m_Context->VoidTy;
QualType desugaredTy = ETy.getDesugaredType(*m_Context);
// The expr result is transported as reference, pointer, array, float etc
// based on the desugared type. We should still expose the typedef'ed
// (sugared) type to the cling::Value.
if (desugaredTy->isRecordType() && E->getValueKind() == VK_LValue) {
// returning a lvalue (not a temporary): the value should contain
// a reference to the lvalue instead of copying it.
desugaredTy = m_Context->getLValueReferenceType(desugaredTy);
ETy = m_Context->getLValueReferenceType(ETy);
}
Expr* ETyVP
= utils::Synthesize::CStyleCastPtrExpr(m_Sema, m_Context->VoidPtrTy,
(uint64_t)ETy.getAsOpaquePtr());
Expr* ETransaction
= utils::Synthesize::CStyleCastPtrExpr(m_Sema, m_Context->VoidPtrTy,
(uint64_t)getTransaction());
llvm::SmallVector<Expr*, 6> CallArgs;
CallArgs.push_back(gClingDRE.take());
CallArgs.push_back(wrapperSVRDRE.take());
CallArgs.push_back(ETyVP);
CallArgs.push_back(ETransaction);
ExprResult Call;
SourceLocation noLoc;
if (desugaredTy->isVoidType()) {
// In cases where the cling::Value gets reused we need to reset the
// previous settings to void.
// We need to synthesize setValueNoAlloc(...), E, because we still need
// to run E.
// FIXME: Suboptimal: this discards the already created AST nodes.
QualType vpQT = m_Context->VoidPtrTy;
QualType vQT = m_Context->VoidTy;
Expr* vpQTVP
= utils::Synthesize::CStyleCastPtrExpr(m_Sema, vpQT,
(uint64_t)vQT.getAsOpaquePtr());
CallArgs[2] = vpQTVP;
Call = m_Sema->ActOnCallExpr(/*Scope*/0, m_UnresolvedNoAlloc,
locStart, CallArgs, locEnd);
if (E)
Call = m_Sema->CreateBuiltinBinOp(locStart, BO_Comma, Call.take(), E);
}
else if (desugaredTy->isRecordType() || desugaredTy->isConstantArrayType()){
// 2) object types :
// check existance of copy constructor before call
if (!availableCopyConstructor(desugaredTy, m_Sema))
return E;
// call new (setValueWithAlloc(gCling, &SVR, ETy)) (E)
Call = m_Sema->ActOnCallExpr(/*Scope*/0, m_UnresolvedWithAlloc,
locStart, CallArgs, locEnd);
Expr* placement = Call.take();
if (const ConstantArrayType* constArray
= dyn_cast<ConstantArrayType>(desugaredTy.getTypePtr())) {
CallArgs.clear();
CallArgs.push_back(E);
CallArgs.push_back(placement);
uint64_t arrSize
= m_Context->getConstantArrayElementCount(constArray);
Expr* arrSizeExpr
= utils::Synthesize::IntegerLiteralExpr(*m_Context, arrSize);
CallArgs.push_back(arrSizeExpr);
// 2.1) arrays:
// call copyArray(T* src, void* placement, int size)
Call = m_Sema->ActOnCallExpr(/*Scope*/0, m_UnresolvedCopyArray,
locStart, CallArgs, locEnd);
}
//.........这里部分代码省略.........
示例3: ActOnGCCAsmStmt
StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
bool IsVolatile, unsigned NumOutputs,
unsigned NumInputs, IdentifierInfo **Names,
MultiExprArg constraints, MultiExprArg exprs,
Expr *asmString, MultiExprArg clobbers,
SourceLocation RParenLoc) {
unsigned NumClobbers = clobbers.size();
StringLiteral **Constraints =
reinterpret_cast<StringLiteral**>(constraints.data());
Expr **Exprs = exprs.data();
StringLiteral *AsmString = cast<StringLiteral>(asmString);
StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.data());
SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
// The parser verifies that there is a string literal here.
if (!AsmString->isAscii())
return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character)
<< AsmString->getSourceRange());
for (unsigned i = 0; i != NumOutputs; i++) {
StringLiteral *Literal = Constraints[i];
if (!Literal->isAscii())
return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
<< Literal->getSourceRange());
StringRef OutputName;
if (Names[i])
OutputName = Names[i]->getName();
TargetInfo::ConstraintInfo Info(Literal->getString(), OutputName);
if (!Context.getTargetInfo().validateOutputConstraint(Info))
return StmtError(Diag(Literal->getLocStart(),
diag::err_asm_invalid_output_constraint)
<< Info.getConstraintStr());
// Check that the output exprs are valid lvalues.
Expr *OutputExpr = Exprs[i];
if (CheckAsmLValue(OutputExpr, *this))
return StmtError(Diag(OutputExpr->getLocStart(),
diag::err_asm_invalid_lvalue_in_output)
<< OutputExpr->getSourceRange());
if (RequireCompleteType(OutputExpr->getLocStart(), Exprs[i]->getType(),
diag::err_dereference_incomplete_type))
return StmtError();
OutputConstraintInfos.push_back(Info);
}
SmallVector<TargetInfo::ConstraintInfo, 4> InputConstraintInfos;
for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
StringLiteral *Literal = Constraints[i];
if (!Literal->isAscii())
return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
<< Literal->getSourceRange());
StringRef InputName;
if (Names[i])
InputName = Names[i]->getName();
TargetInfo::ConstraintInfo Info(Literal->getString(), InputName);
if (!Context.getTargetInfo().validateInputConstraint(OutputConstraintInfos.data(),
NumOutputs, Info)) {
return StmtError(Diag(Literal->getLocStart(),
diag::err_asm_invalid_input_constraint)
<< Info.getConstraintStr());
}
Expr *InputExpr = Exprs[i];
// Only allow void types for memory constraints.
if (Info.allowsMemory() && !Info.allowsRegister()) {
if (CheckAsmLValue(InputExpr, *this))
return StmtError(Diag(InputExpr->getLocStart(),
diag::err_asm_invalid_lvalue_in_input)
<< Info.getConstraintStr()
<< InputExpr->getSourceRange());
}
if (Info.allowsRegister()) {
if (InputExpr->getType()->isVoidType()) {
return StmtError(Diag(InputExpr->getLocStart(),
diag::err_asm_invalid_type_in_input)
<< InputExpr->getType() << Info.getConstraintStr()
<< InputExpr->getSourceRange());
}
}
ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
if (Result.isInvalid())
return StmtError();
Exprs[i] = Result.take();
InputConstraintInfos.push_back(Info);
const Type *Ty = Exprs[i]->getType().getTypePtr();
if (Ty->isDependentType())
continue;
//.........这里部分代码省略.........
示例4: ParseOpenMPSimpleVarList
/// \brief Parses list of simple variables for '#pragma omp threadprivate'
/// directive.
///
/// simple-variable-list:
/// '(' id-expression {, id-expression} ')'
///
bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
SmallVectorImpl<Expr *> &VarList,
bool AllowScopeSpecifier) {
VarList.clear();
// Parse '('.
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
if (T.expectAndConsume(diag::err_expected_lparen_after,
getOpenMPDirectiveName(Kind)))
return true;
bool IsCorrect = true;
bool NoIdentIsFound = true;
// Read tokens while ')' or annot_pragma_openmp_end is not found.
while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
CXXScopeSpec SS;
SourceLocation TemplateKWLoc;
UnqualifiedId Name;
// Read var name.
Token PrevTok = Tok;
NoIdentIsFound = false;
if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) {
IsCorrect = false;
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
StopBeforeMatch);
} else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(),
TemplateKWLoc, Name)) {
IsCorrect = false;
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
StopBeforeMatch);
} else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
Tok.isNot(tok::annot_pragma_openmp_end)) {
IsCorrect = false;
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
StopBeforeMatch);
Diag(PrevTok.getLocation(), diag::err_expected)
<< tok::identifier
<< SourceRange(PrevTok.getLocation(), PrevTokLocation);
} else {
DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
ExprResult Res = Actions.ActOnOpenMPIdExpression(getCurScope(), SS,
NameInfo);
if (Res.isUsable())
VarList.push_back(Res.take());
}
// Consume ','.
if (Tok.is(tok::comma)) {
ConsumeToken();
}
}
if (NoIdentIsFound) {
Diag(Tok, diag::err_expected) << tok::identifier;
IsCorrect = false;
}
// Parse ')'.
IsCorrect = !T.consumeClose() && IsCorrect;
return !IsCorrect && VarList.empty();
}
示例5: ActOnMSAsmStmt
//.........这里部分代码省略.........
return Owned(NS);
}
std::string AsmString;
SmallVector<unsigned, 8> TokOffsets;
if (buildMSAsmString(*this, AsmLoc, AsmToks, TokOffsets, AsmString))
return StmtError();
// Get the target specific parser.
std::string Error;
const std::string &TT = TheTriple.getTriple();
const llvm::Target *TheTarget(llvm::TargetRegistry::lookupTarget(TT, Error));
OwningPtr<llvm::MCAsmInfo> MAI(TheTarget->createMCAsmInfo(TT));
OwningPtr<llvm::MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
OwningPtr<llvm::MCObjectFileInfo> MOFI(new llvm::MCObjectFileInfo());
OwningPtr<llvm::MCSubtargetInfo>
STI(TheTarget->createMCSubtargetInfo(TT, "", ""));
llvm::SourceMgr SrcMgr;
llvm::MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr);
llvm::MemoryBuffer *Buffer =
llvm::MemoryBuffer::getMemBuffer(AsmString, "<MS inline asm>");
// Tell SrcMgr about this buffer, which is what the parser will pick up.
SrcMgr.AddNewSourceBuffer(Buffer, llvm::SMLoc());
OwningPtr<llvm::MCStreamer> Str(createNullStreamer(Ctx));
OwningPtr<llvm::MCAsmParser>
Parser(createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI));
OwningPtr<llvm::MCTargetAsmParser>
TargetParser(TheTarget->createMCAsmParser(*STI, *Parser));
// Get the instruction descriptor.
const llvm::MCInstrInfo *MII = TheTarget->createMCInstrInfo();
llvm::MCInstPrinter *IP =
TheTarget->createMCInstPrinter(1, *MAI, *MII, *MRI, *STI);
// Change to the Intel dialect.
Parser->setAssemblerDialect(1);
Parser->setTargetParser(*TargetParser.get());
Parser->setParsingInlineAsm(true);
TargetParser->setParsingInlineAsm(true);
MCAsmParserSemaCallbackImpl MCAPSI(*this, AsmLoc, AsmToks, TokOffsets);
TargetParser->setSemaCallback(&MCAPSI);
SrcMgr.setDiagHandler(MCAsmParserSemaCallbackImpl::MSAsmDiagHandlerCallback,
&MCAPSI);
unsigned NumOutputs;
unsigned NumInputs;
std::string AsmStringIR;
SmallVector<std::pair<void *, bool>, 4> OpDecls;
SmallVector<std::string, 4> Constraints;
SmallVector<std::string, 4> Clobbers;
if (Parser->parseMSInlineAsm(AsmLoc.getPtrEncoding(), AsmStringIR,
NumOutputs, NumInputs, OpDecls, Constraints,
Clobbers, MII, IP, MCAPSI))
return StmtError();
// Build the vector of clobber StringRefs.
unsigned NumClobbers = Clobbers.size();
ClobberRefs.resize(NumClobbers);
for (unsigned i = 0; i != NumClobbers; ++i)
ClobberRefs[i] = StringRef(Clobbers[i]);
// Recast the void pointers and build the vector of constraint StringRefs.
unsigned NumExprs = NumOutputs + NumInputs;
Names.resize(NumExprs);
ConstraintRefs.resize(NumExprs);
Exprs.resize(NumExprs);
for (unsigned i = 0, e = NumExprs; i != e; ++i) {
NamedDecl *OpDecl = static_cast<NamedDecl *>(OpDecls[i].first);
if (!OpDecl)
return StmtError();
DeclarationNameInfo NameInfo(OpDecl->getDeclName(), AsmLoc);
ExprResult OpExpr = BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo,
OpDecl);
if (OpExpr.isInvalid())
return StmtError();
// Need address of variable.
if (OpDecls[i].second)
OpExpr = BuildUnaryOp(getCurScope(), AsmLoc, clang::UO_AddrOf,
OpExpr.take());
Names[i] = OpDecl->getIdentifier();
ConstraintRefs[i] = StringRef(Constraints[i]);
Exprs[i] = OpExpr.take();
}
bool IsSimple = NumExprs > 0;
MSAsmStmt *NS =
new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
/*IsVolatile*/ true, AsmToks, NumOutputs, NumInputs,
Names, ConstraintRefs, Exprs, AsmStringIR,
ClobberRefs, EndLoc);
return Owned(NS);
}
示例6: move
/// ParseRHSOfBinaryExpression - Parse a binary expression that starts with
/// LHS and has a precedence of at least MinPrec.
ExprResult
Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
prec::Level NextTokPrec = getBinOpPrecedence(Tok.getKind(),
getLang().OCTAVEKeywords);
while(1) {
// If this token has a lower precedence than we are allowed to parse (e.g.
// because we are called recursively, or because the token is not a binop),
// then we are done!
if (NextTokPrec < MinPrec || Tok.isAtStartOfLine())
return move(LHS);
// Consume the operator, saving the operator token for error reporting.
Token OpToken = Tok;
SourceLocation OpLoc = ConsumeToken();
ExprResult RHS(ParseUnaryExpression());
if (RHS.isInvalid())
LHS = ExprError();
// Remember the precedence of this operator and get the precedence of the
// operator immediately to the right of the RHS.
prec::Level ThisPrec = NextTokPrec;
NextTokPrec = getBinOpPrecedence(Tok.getKind(),
getLang().OCTAVEKeywords);
// if we meet a tenary colon operator
if ((ThisPrec == NextTokPrec) && (NextTokPrec == prec::Colon)) {
assert(Tok.getKind()==tok::Colon);
SourceLocation SecondColonLoc = ConsumeToken();
ExprResult Limit(ParseUnaryExpression());
if (Limit.isInvalid())
LHS = ExprError();
else
LHS = Actions.ActOnTernaryColonOp(getCurScope(), OpLoc, SecondColonLoc,
LHS.take(), RHS.take(), Limit.take());
return move(LHS);
}
// Assignment and conditional expressions are right-associative.
bool isRightAssoc = (ThisPrec == prec::Assignment);
// Get the precedence of the operator to the right of the RHS. If it binds
// more tightly with RHS than we do, evaluate it completely first.
if (ThisPrec < NextTokPrec ||
(ThisPrec == NextTokPrec && isRightAssoc)) {
// If this is left-associative, only parse things on the RHS that bind
// more tightly than the current operator. If it is left-associative, it
// is okay, to bind exactly as tightly. For example, compile A=B=C=D as
// A=(B=(C=D)), where each paren is a level of recursion here.
// The function takes ownership of the RHS.
RHS = ParseRHSOfBinaryExpression(RHS,
static_cast<prec::Level>(ThisPrec + !isRightAssoc));
if (RHS.isInvalid())
LHS = ExprError();
NextTokPrec = getBinOpPrecedence(Tok.getKind(), getLang().OCTAVEKeywords);
}
assert((NextTokPrec <= ThisPrec || Tok.isAtStartOfLine())
&& "Recursion didn't work!");
if (!LHS.isInvalid()) {
LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(),
OpToken.getKind(), LHS.take(), RHS.take());
}
}
assert(Tok.isAtStartOfLine() && "should at start of line");
return move(LHS);
}
示例7: SynthesizeCheck
Stmt* SynthesizeCheck(SourceLocation Loc, Expr* Arg) {
assert(Arg && "Cannot call with Arg=0");
ASTContext& Context = m_Sema.getASTContext();
//copied from DynamicLookup.cpp
// Lookup Sema type
CXXRecordDecl* SemaRD
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(&m_Sema, "Sema",
utils::Lookup::Namespace(&m_Sema, "clang")));
QualType SemaRDTy = Context.getTypeDeclType(SemaRD);
Expr* VoidSemaArg = utils::Synthesize::CStyleCastPtrExpr(&m_Sema,SemaRDTy,
(uint64_t)&m_Sema);
// Lookup Expr type
CXXRecordDecl* ExprRD
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(&m_Sema, "Expr",
utils::Lookup::Namespace(&m_Sema, "clang")));
QualType ExprRDTy = Context.getTypeDeclType(ExprRD);
Expr* VoidExprArg = utils::Synthesize::CStyleCastPtrExpr(&m_Sema,ExprRDTy,
(uint64_t)Arg);
Expr *args[] = {VoidSemaArg, VoidExprArg};
Scope* S = m_Sema.getScopeForContext(m_Sema.CurContext);
DeclarationName Name
= &Context.Idents.get("cling__runtime__internal__throwNullDerefException");
SourceLocation noLoc;
LookupResult R(m_Sema, Name, noLoc, Sema::LookupOrdinaryName,
Sema::ForRedeclaration);
m_Sema.LookupQualifiedName(R, Context.getTranslationUnitDecl());
assert(!R.empty() && "Cannot find valuePrinterInternal::Select(...)");
CXXScopeSpec CSS;
Expr* UnresolvedLookup
= m_Sema.BuildDeclarationNameExpr(CSS, R, /*ADL*/ false).take();
Expr* call = m_Sema.ActOnCallExpr(S, UnresolvedLookup, noLoc,
args, noLoc).take();
// Check whether we can get the argument'value. If the argument is
// null, throw an exception direclty. If the argument is not null
// then ignore this argument and continue to deal with the next
// argument with the nonnull attribute.
bool Result = false;
if (Arg->EvaluateAsBooleanCondition(Result, Context)) {
if(!Result) {
return call;
}
return Arg;
}
// The argument's value cannot be decided, so we add a UnaryOp
// operation to check its value at runtime.
ExprResult ER = m_Sema.ActOnUnaryOp(S, Loc, tok::exclaim, Arg);
Decl* varDecl = 0;
Stmt* varStmt = 0;
Sema::FullExprArg FullCond(m_Sema.MakeFullExpr(ER.take()));
StmtResult IfStmt = m_Sema.ActOnIfStmt(Loc, FullCond, varDecl,
call, Loc, varStmt);
return IfStmt.take();
}
示例8: BuildDynamicExprInfo
Expr* EvaluateTSynthesizer::BuildDynamicExprInfo(Expr* SubTree,
bool ValuePrinterReq) {
// 1. Find the DynamicExprInfo class
CXXRecordDecl* ExprInfo
= cast_or_null<CXXRecordDecl>(m_Interpreter->LookupDecl("cling").
LookupDecl("DynamicExprInfo").
getSingleDecl());
assert(ExprInfo && "DynamicExprInfo declaration not found!");
// 2. Get the expression containing @-s and get the variable addresses
std::string Template;
llvm::SmallVector<DeclRefExpr*, 4> Addresses;
llvm::raw_string_ostream OS(Template);
const PrintingPolicy& Policy = m_Context->getPrintingPolicy();
StmtPrinterHelper helper(Policy, Addresses, m_Sema);
// In case when we print non paren inits like int i = h->Draw();
// not int i(h->Draw()). This simplifies the LifetimeHandler's
// constructor, there we don't need to add parenthesis while
// wrapping the expression.
if (!isa<ParenListExpr>(SubTree))
OS << '(';
SubTree->printPretty(OS, &helper, Policy);
if (!isa<ParenListExpr>(SubTree))
OS << ')';
OS.flush();
// 3. Build the template
Expr* ExprTemplate = ConstructConstCharPtrExpr(Template.c_str());
// 4. Build the array of addresses
QualType VarAddrTy = m_Sema->BuildArrayType(m_Context->VoidPtrTy,
ArrayType::Normal,
/*ArraySize*/0,
Qualifiers(),
m_NoRange,
DeclarationName() );
ASTOwningVector<Expr*> Inits(*m_Sema);
Scope* S = m_Sema->getScopeForContext(m_Sema->CurContext);
for (unsigned int i = 0; i < Addresses.size(); ++i) {
Expr* UnOp
= m_Sema->BuildUnaryOp(S, m_NoSLoc, UO_AddrOf, Addresses[i]).take();
m_Sema->ImpCastExprToType(UnOp,
m_Context->getPointerType(m_Context->VoidPtrTy),
CK_BitCast);
Inits.push_back(UnOp);
}
// We need valid source locations to avoid assert(InitList.isExplicit()...)
InitListExpr* ILE = m_Sema->ActOnInitList(m_NoSLoc,
move_arg(Inits),
m_NoELoc).takeAs<InitListExpr>();
Expr* ExprAddresses = m_Sema->BuildCompoundLiteralExpr(m_NoSLoc,
m_Context->CreateTypeSourceInfo(VarAddrTy),
m_NoELoc,
ILE).take();
assert (ExprAddresses && "Could not build the void* array");
m_Sema->ImpCastExprToType(ExprAddresses,
m_Context->getPointerType(m_Context->VoidPtrTy),
CK_ArrayToPointerDecay);
// Is the result of the expression to be printed or not
Expr* VPReq = 0;
if (ValuePrinterReq)
VPReq = m_Sema->ActOnCXXBoolLiteral(m_NoSLoc, tok::kw_true).take();
else
VPReq = m_Sema->ActOnCXXBoolLiteral(m_NoSLoc, tok::kw_false).take();
ASTOwningVector<Expr*> CtorArgs(*m_Sema);
CtorArgs.push_back(ExprTemplate);
CtorArgs.push_back(ExprAddresses);
CtorArgs.push_back(VPReq);
// 5. Call the constructor
QualType ExprInfoTy = m_Context->getTypeDeclType(ExprInfo);
ExprResult Initializer = m_Sema->ActOnParenListExpr(m_NoSLoc, m_NoELoc,
move_arg(CtorArgs));
Expr* Result = m_Sema->BuildCXXNew(m_NoSLoc,
/*UseGlobal=*/false,
m_NoSLoc,
/*PlacementArgs=*/MultiExprArg(),
m_NoELoc,
m_NoRange,
ExprInfoTy,
m_Context->CreateTypeSourceInfo(ExprInfoTy),
/*ArraySize=*/0,
//BuildCXXNew depends on the SLoc to be
//valid!
// TODO: Propose a patch in clang
m_NoRange,
Initializer.take(),
/*TypeMayContainAuto*/false
).take();
return Result;
}
示例9: CreateBuiltinBinOp
//.........这里部分代码省略.........
case BO_Mul:
case BO_RDiv:
case BO_LDiv:
case BO_MatrixMul:
case BO_MatrixRDiv:
case BO_MatrixLDiv:
ResultTy = CheckMultiplyDivideOperands(lhs, rhs, OpLoc, false,
Opc == BO_RDiv || Opc == BO_LDiv);
break;
case BO_Add:
ResultTy = CheckAdditionOperands(lhs, rhs, OpLoc);
break;
case BO_Sub:
ResultTy = CheckSubtractionOperands(lhs, rhs, OpLoc);
break;
case BO_Shl:
case BO_Shr:
ResultTy = CheckShiftOperands(lhs, rhs, OpLoc, Opc);
break;
case BO_LE:
case BO_LT:
case BO_GE:
case BO_GT:
ResultTy = CheckCompareOperands(lhs, rhs, OpLoc, Opc, true);
break;
case BO_EQ:
case BO_NE:
ResultTy = CheckCompareOperands(lhs, rhs, OpLoc, Opc, false);
break;
case BO_And:
case BO_Or:
ResultTy = CheckBitwiseOperands(lhs, rhs, OpLoc);
break;
case BO_LAnd:
case BO_LOr:
ResultTy = CheckLogicalOperands(lhs, rhs, OpLoc, Opc);
break;
case BO_MatPowerAssign:
case BO_PowerAssign:
ResultTy = CheckPowerOperands(lhs, rhs, OpLoc,
Opc == BO_PowerAssign);
break;
case BO_MatMulAssign:
case BO_MatRDivAssign:
case BO_MatLDivAssign:
case BO_MulAssign:
case BO_RDivAssign:
case BO_LDivAssign:
CompResultTy = CheckMultiplyDivideOperands(lhs, rhs, OpLoc, true,
Opc == BO_MulAssign || Opc == BO_RDivAssign || Opc == BO_LDivAssign );
CompLHSTy = CompResultTy;
if (!CompResultTy.isNull() && !lhs.isInvalid() && !rhs.isInvalid())
ResultTy = CheckAssignmentOperands(lhs.get(), rhs, OpLoc, CompResultTy);
break;
case BO_AddAssign:
CompResultTy = CheckAdditionOperands(lhs, rhs, OpLoc, &CompLHSTy);
if (!CompResultTy.isNull() && !lhs.isInvalid() && !rhs.isInvalid())
ResultTy = CheckAssignmentOperands(lhs.get(), rhs, OpLoc, CompResultTy);
break;
case BO_SubAssign:
CompResultTy = CheckSubtractionOperands(lhs, rhs, OpLoc, &CompLHSTy);
if (!CompResultTy.isNull() && !lhs.isInvalid() && !rhs.isInvalid())
ResultTy = CheckAssignmentOperands(lhs.get(), rhs, OpLoc, CompResultTy);
break;
case BO_ShlAssign:
case BO_ShrAssign:
CompResultTy = CheckShiftOperands(lhs, rhs, OpLoc, Opc, true);
CompLHSTy = CompResultTy;
if (!CompResultTy.isNull() && !lhs.isInvalid() && !rhs.isInvalid())
ResultTy = CheckAssignmentOperands(lhs.get(), rhs, OpLoc, CompResultTy);
break;
case BO_AndAssign:
case BO_OrAssign:
CompResultTy = CheckBitwiseOperands(lhs, rhs, OpLoc, true);
CompLHSTy = CompResultTy;
if (!CompResultTy.isNull() && !lhs.isInvalid() && !rhs.isInvalid())
ResultTy = CheckAssignmentOperands(lhs.get(), rhs, OpLoc, CompResultTy);
break;
case BO_Colon:
ResultTy = CheckColonOperands(lhs, rhs, OpLoc);
break;
case BO_Comma:
ResultTy = CheckCommaOperands(*this, lhs, rhs, OpLoc);
if (getLangOptions().OOP && !rhs.isInvalid()) {
VK = rhs.get()->getValueKind();
}
break;
}
if (ResultTy.isNull() || lhs.isInvalid() || rhs.isInvalid())
return ExprError();
if (CompResultTy.isNull())
return Owned(new (Context) BinaryOperator(lhs.take(), rhs.take(), Opc,
ResultTy, VK, OpLoc));
if (getLangOptions().OOP) {
VK = VK_LValue;
}
return Owned(new (Context) CompoundAssignOperator(lhs.take(), rhs.take(), Opc,
ResultTy, /*VK, */CompLHSTy,
CompResultTy, OpLoc));
}
示例10: baseNameInfo
ExprResult
Sema::BuildAnonymousStructUnionMemberReference(SourceLocation loc,
IndirectFieldDecl *indirectField,
Expr *baseObjectExpr,
SourceLocation opLoc) {
// First, build the expression that refers to the base object.
bool baseObjectIsPointer = false;
Qualifiers baseQuals;
// Case 1: the base of the indirect field is not a field.
VarDecl *baseVariable = indirectField->getVarDecl();
CXXScopeSpec EmptySS;
if (baseVariable) {
assert(baseVariable->getType()->isRecordType());
// In principle we could have a member access expression that
// accesses an anonymous struct/union that's a static member of
// the base object's class. However, under the current standard,
// static data members cannot be anonymous structs or unions.
// Supporting this is as easy as building a MemberExpr here.
assert(!baseObjectExpr && "anonymous struct/union is static data member?");
DeclarationNameInfo baseNameInfo(DeclarationName(), loc);
ExprResult result
= BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
if (result.isInvalid()) return ExprError();
baseObjectExpr = result.take();
baseObjectIsPointer = false;
baseQuals = baseObjectExpr->getType().getQualifiers();
// Case 2: the base of the indirect field is a field and the user
// wrote a member expression.
} else if (baseObjectExpr) {
// The caller provided the base object expression. Determine
// whether its a pointer and whether it adds any qualifiers to the
// anonymous struct/union fields we're looking into.
QualType objectType = baseObjectExpr->getType();
if (const PointerType *ptr = objectType->getAs<PointerType>()) {
baseObjectIsPointer = true;
objectType = ptr->getPointeeType();
} else {
baseObjectIsPointer = false;
}
baseQuals = objectType.getQualifiers();
}
// Build the implicit member references to the field of the
// anonymous struct/union.
Expr *result = baseObjectExpr;
IndirectFieldDecl::chain_iterator
FI = indirectField->chain_begin(), FEnd = indirectField->chain_end();
// Build the first member access in the chain with full information.
if (!baseVariable) {
FieldDecl *field = cast<FieldDecl>(*FI);
// FIXME: use the real found-decl info!
DeclAccessPair foundDecl = DeclAccessPair::make(field, field->getAccess());
// Make a nameInfo that properly uses the anonymous name.
DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
result = BuildFieldReferenceExpr(*this, result, baseObjectIsPointer,
EmptySS, field, foundDecl,
memberNameInfo).take();
baseObjectIsPointer = false;
// FIXME: check qualified member access
}
// In all cases, we should now skip the first declaration in the chain.
++FI;
while (FI != FEnd) {
FieldDecl *field = cast<FieldDecl>(*FI++);
// FIXME: these are somewhat meaningless
DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
DeclAccessPair foundDecl = DeclAccessPair::make(field, field->getAccess());
result = BuildFieldReferenceExpr(*this, result, /*isarrow*/ false,
EmptySS, field,
foundDecl, memberNameInfo).take();
}
return Owned(result);
}
示例11: ActOnMSAsmStmt
//.........这里部分代码省略.........
Parser->Lex();
// Parse the opcode.
StringRef IDVal;
Parser->ParseIdentifier(IDVal);
// Canonicalize the opcode to lower case.
SmallString<128> Opcode;
for (unsigned j = 0, e = IDVal.size(); j != e; ++j)
Opcode.push_back(tolower(IDVal[j]));
// Parse the operands.
llvm::SMLoc IDLoc;
SmallVector<llvm::MCParsedAsmOperand*, 8> Operands;
bool HadError = TargetParser->ParseInstruction(Opcode.str(), IDLoc,
Operands);
// If we had an error parsing the operands, fail gracefully.
if (HadError) { DEF_SIMPLE_MSASM; return Owned(NS); }
// Match the MCInstr.
unsigned ErrorInfo;
SmallVector<llvm::MCInst, 2> Instrs;
HadError = TargetParser->MatchInstruction(IDLoc, Operands, Instrs,
ErrorInfo,
/*matchingInlineAsm*/ true);
// If we had an error parsing the operands, fail gracefully.
if (HadError) { DEF_SIMPLE_MSASM; return Owned(NS); }
// Get the instruction descriptor.
llvm::MCInst Inst = Instrs[0];
const llvm::MCInstrInfo *MII = TheTarget->createMCInstrInfo();
const llvm::MCInstrDesc &Desc = MII->get(Inst.getOpcode());
llvm::MCInstPrinter *IP =
TheTarget->createMCInstPrinter(1, *MAI, *MII, *MRI, *STI);
// Build the list of clobbers, outputs and inputs.
unsigned NumDefs = Desc.getNumDefs();
for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) {
const llvm::MCOperand &Op = Inst.getOperand(i);
// Immediate.
if (Op.isImm() || Op.isFPImm())
continue;
bool isDef = NumDefs && (i < NumDefs);
// Register/Clobber.
if (Op.isReg() && isDef) {
std::string Reg;
llvm::raw_string_ostream OS(Reg);
IP->printRegName(OS, Op.getReg());
StringRef Clobber(OS.str());
if (!Context.getTargetInfo().isValidClobber(Clobber))
return StmtError(Diag(AsmLoc, diag::err_asm_unknown_register_name) <<
Clobber);
ClobberRegs.insert(Reg);
continue;
}
// Expr/Input or Output.
if (Op.isExpr()) {
const llvm::MCExpr *Expr = Op.getExpr();
const llvm::MCSymbolRefExpr *SymRef;
if ((SymRef = dyn_cast<llvm::MCSymbolRefExpr>(Expr))) {
StringRef Name = SymRef->getSymbol().getName();
IdentifierInfo *II = getIdentifierInfo(Name, AsmToks,
AsmTokRanges[StrIdx].first,
AsmTokRanges[StrIdx].second);
if (II) {
CXXScopeSpec SS;
UnqualifiedId Id;
SourceLocation Loc;
Id.setIdentifier(II, AsmLoc);
ExprResult Result = ActOnIdExpression(getCurScope(), SS, Loc, Id,
false, false);
if (!Result.isInvalid()) {
if (isDef) {
Outputs.push_back(II);
OutputExprs.push_back(Result.take());
} else {
Inputs.push_back(II);
InputExprs.push_back(Result.take());
}
}
}
}
}
}
}
for (std::set<std::string>::iterator I = ClobberRegs.begin(),
E = ClobberRegs.end(); I != E; ++I)
Clobbers.push_back(*I);
MSAsmStmt *NS =
new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
/*IsVolatile*/ true, AsmToks, Inputs, Outputs,
InputExprs, OutputExprs, AsmString, Clobbers,
EndLoc);
return Owned(NS);
}