本文整理汇总了C++中ASTContext::getLangOptions方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTContext::getLangOptions方法的具体用法?C++ ASTContext::getLangOptions怎么用?C++ ASTContext::getLangOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTContext
的用法示例。
在下文中一共展示了ASTContext::getLangOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findSemiAfterLocation
/// \brief \arg Loc is the end of a statement range. This returns the location
/// of the semicolon following the statement.
/// If no semicolon is found or the location is inside a macro, the returned
/// source location will be invalid.
SourceLocation trans::findSemiAfterLocation(SourceLocation loc,
ASTContext &Ctx) {
SourceManager &SM = Ctx.getSourceManager();
if (loc.isMacroID()) {
if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOptions()))
return SourceLocation();
loc = SM.getExpansionRange(loc).second;
}
loc = Lexer::getLocForEndOfToken(loc, /*Offset=*/0, SM, Ctx.getLangOptions());
// Break down the source location.
std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(loc);
// Try to load the file buffer.
bool invalidTemp = false;
StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
if (invalidTemp)
return SourceLocation();
const char *tokenBegin = file.data() + locInfo.second;
// Lex from the start of the given location.
Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
Ctx.getLangOptions(),
file.begin(), tokenBegin, file.end());
Token tok;
lexer.LexFromRawLexer(tok);
if (tok.isNot(tok::semi))
return SourceLocation();
return tok.getLocation();
}
示例2: ClassifyImpl
Cl Expr::ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const {
assert(!TR->isReferenceType() && "Expressions can't have reference type.");
Cl::Kinds kind = ClassifyInternal(Ctx, this);
// C99 6.3.2.1: An lvalue is an expression with an object type or an
// incomplete type other than void.
if (!Ctx.getLangOptions().CPlusPlus) {
// Thus, no functions.
if (TR->isFunctionType() || TR == Ctx.OverloadTy)
kind = Cl::CL_Function;
// No void either, but qualified void is OK because it is "other than void".
else if (TR->isVoidType() && !Ctx.getCanonicalType(TR).hasQualifiers())
kind = Cl::CL_Void;
}
// Enable this assertion for testing.
switch (kind) {
case Cl::CL_LValue: assert(getValueKind() == VK_LValue); break;
case Cl::CL_XValue: assert(getValueKind() == VK_XValue); break;
case Cl::CL_Function:
case Cl::CL_Void:
case Cl::CL_DuplicateVectorComponents:
case Cl::CL_MemberFunction:
case Cl::CL_SubObjCPropertySetting:
case Cl::CL_ClassTemporary:
case Cl::CL_PRValue: assert(getValueKind() == VK_RValue); break;
}
Cl::ModifiableType modifiable = Cl::CM_Untested;
if (Loc)
modifiable = IsModifiable(Ctx, this, kind, *Loc);
return Classification(kind, modifiable);
}
示例3: canApplyWeak
bool trans::canApplyWeak(ASTContext &Ctx, QualType type,
bool AllowOnUnknownClass) {
if (!Ctx.getLangOptions().ObjCRuntimeHasWeak)
return false;
QualType T = type;
if (T.isNull())
return false;
while (const PointerType *ptr = T->getAs<PointerType>())
T = ptr->getPointeeType();
if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
if (!AllowOnUnknownClass && (!Class || Class->getName() == "NSObject"))
return false; // id/NSObject is not safe for weak.
if (!AllowOnUnknownClass && Class->isForwardDecl())
return false; // forward classes are not verifiable, therefore not safe.
if (Class->isArcWeakrefUnavailable())
return false;
if (isClassInWeakBlacklist(Class))
return false;
}
return true;
}
示例4: getBuiltinID
/// \brief Returns a value indicating whether this function
/// corresponds to a builtin function.
///
/// The function corresponds to a built-in function if it is
/// declared at translation scope or within an extern "C" block and
/// its name matches with the name of a builtin. The returned value
/// will be 0 for functions that do not correspond to a builtin, a
/// value of type \c Builtin::ID if in the target-independent range
/// \c [1,Builtin::First), or a target-specific builtin value.
unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const {
if (!getIdentifier() || !getIdentifier()->getBuiltinID())
return 0;
unsigned BuiltinID = getIdentifier()->getBuiltinID();
if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
return BuiltinID;
// This function has the name of a known C library
// function. Determine whether it actually refers to the C library
// function or whether it just has the same name.
// If this is a static function, it's not a builtin.
if (getStorageClass() == Static)
return 0;
// If this function is at translation-unit scope and we're not in
// C++, it refers to the C library function.
if (!Context.getLangOptions().CPlusPlus &&
getDeclContext()->isTranslationUnit())
return BuiltinID;
// If the function is in an extern "C" linkage specification and is
// not marked "overloadable", it's the real function.
if (isa<LinkageSpecDecl>(getDeclContext()) &&
cast<LinkageSpecDecl>(getDeclContext())->getLanguage()
== LinkageSpecDecl::lang_c &&
!getAttr<OverloadableAttr>())
return BuiltinID;
// Not a builtin
return 0;
}
示例5: ClassifyInternal
static Cl::Kinds ClassifyBinaryOp(ASTContext &Ctx, const BinaryOperator *E) {
assert(Ctx.getLangOptions().CPlusPlus &&
"This is only relevant for C++.");
// C++ [expr.ass]p1: All [...] return an lvalue referring to the left operand.
// Except we override this for writes to ObjC properties.
if (E->isAssignmentOp())
return (E->getLHS()->getObjectKind() == OK_ObjCProperty
? Cl::CL_PRValue : Cl::CL_LValue);
// C++ [expr.comma]p1: the result is of the same value category as its right
// operand, [...].
if (E->getOpcode() == BO_Comma)
return ClassifyInternal(Ctx, E->getRHS());
// C++ [expr.mptr.oper]p6: The result of a .* expression whose second operand
// is a pointer to a data member is of the same value category as its first
// operand.
if (E->getOpcode() == BO_PtrMemD)
return E->getType()->isFunctionType() ? Cl::CL_MemberFunction :
ClassifyInternal(Ctx, E->getLHS());
// C++ [expr.mptr.oper]p6: The result of an ->* expression is an lvalue if its
// second operand is a pointer to data member and a prvalue otherwise.
if (E->getOpcode() == BO_PtrMemI)
return E->getType()->isFunctionType() ?
Cl::CL_MemberFunction : Cl::CL_LValue;
// All other binary operations are prvalues.
return Cl::CL_PRValue;
}
示例6: isRequiredDecl
/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
/// consumers of the AST.
///
/// Such decls will always be deserialized from the PCH file, so we would like
/// this to be as restrictive as possible. Currently the predicate is driven by
/// code generation requirements, if other clients have a different notion of
/// what is "required" then we may have to consider an alternate scheme where
/// clients can iterate over the top-level decls and get information on them,
/// without necessary deserializing them. We could explicitly require such
/// clients to use a separate API call to "realize" the decl. This should be
/// relatively painless since they would presumably only do it for top-level
/// decls.
//
// FIXME: This predicate is essentially IRgen's predicate to determine whether a
// declaration can be deferred. Merge them somehow.
static bool isRequiredDecl(const Decl *D, ASTContext &Context) {
// File scoped assembly must be seen.
if (isa<FileScopeAsmDecl>(D))
return true;
// Otherwise if this isn't a function or a file scoped variable it doesn't
// need to be seen.
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
if (!VD->isFileVarDecl())
return false;
} else if (!isa<FunctionDecl>(D))
return false;
// Aliases and used decls must be seen.
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
return true;
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
// Forward declarations don't need to be seen.
if (!FD->isThisDeclarationADefinition())
return false;
// Constructors and destructors must be seen.
if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>())
return true;
// Otherwise, this is required unless it is static.
//
// FIXME: Inlines.
return FD->getStorageClass() != FunctionDecl::Static;
} else {
const VarDecl *VD = cast<VarDecl>(D);
// In C++, this doesn't need to be seen if it is marked "extern".
if (Context.getLangOptions().CPlusPlus && !VD->getInit() &&
(VD->getStorageClass() == VarDecl::Extern ||
VD->isExternC()))
return false;
// In C, this doesn't need to be seen unless it is a definition.
if (!Context.getLangOptions().CPlusPlus && !VD->getInit())
return false;
// Otherwise, this is required unless it is static.
return VD->getStorageClass() != VarDecl::Static;
}
}
示例7: isTentativeDefinition
bool VarDecl::isTentativeDefinition(ASTContext &Context) const {
if (!isFileVarDecl() || Context.getLangOptions().CPlusPlus)
return false;
const VarDecl *Def = 0;
return (!getDefinition(Def) &&
(getStorageClass() == None || getStorageClass() == Static));
}
示例8: ClassifyInternal
static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E) {
if (E->getType() == Ctx.UnknownAnyTy)
return (isa<FunctionDecl>(E->getMemberDecl())
? Cl::CL_PRValue : Cl::CL_LValue);
// Handle C first, it's easier.
if (!Ctx.getLangOptions().CPlusPlus) {
// C99 6.5.2.3p3
// For dot access, the expression is an lvalue if the first part is. For
// arrow access, it always is an lvalue.
if (E->isArrow())
return Cl::CL_LValue;
// ObjC property accesses are not lvalues, but get special treatment.
Expr *Base = E->getBase()->IgnoreParens();
if (isa<ObjCPropertyRefExpr>(Base))
return Cl::CL_SubObjCPropertySetting;
return ClassifyInternal(Ctx, Base);
}
NamedDecl *Member = E->getMemberDecl();
// C++ [expr.ref]p3: E1->E2 is converted to the equivalent form (*(E1)).E2.
// C++ [expr.ref]p4: If E2 is declared to have type "reference to T", then
// E1.E2 is an lvalue.
if (ValueDecl *Value = dyn_cast<ValueDecl>(Member))
if (Value->getType()->isReferenceType())
return Cl::CL_LValue;
// Otherwise, one of the following rules applies.
// -- If E2 is a static member [...] then E1.E2 is an lvalue.
if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord())
return Cl::CL_LValue;
// -- If E2 is a non-static data member [...]. If E1 is an lvalue, then
// E1.E2 is an lvalue; if E1 is an xvalue, then E1.E2 is an xvalue;
// otherwise, it is a prvalue.
if (isa<FieldDecl>(Member)) {
// *E1 is an lvalue
if (E->isArrow())
return Cl::CL_LValue;
Expr *Base = E->getBase()->IgnoreParenImpCasts();
if (isa<ObjCPropertyRefExpr>(Base))
return Cl::CL_SubObjCPropertySetting;
return ClassifyInternal(Ctx, E->getBase());
}
// -- If E2 is a [...] member function, [...]
// -- If it refers to a static member function [...], then E1.E2 is an
// lvalue; [...]
// -- Otherwise [...] E1.E2 is a prvalue.
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member))
return Method->isStatic() ? Cl::CL_LValue : Cl::CL_MemberFunction;
// -- If E2 is a member enumerator [...], the expression E1.E2 is a prvalue.
// So is everything else we haven't handled yet.
return Cl::CL_PRValue;
}
示例9: ClassifyUnnamed
/// ClassifyUnnamed - Return the classification of an expression yielding an
/// unnamed value of the given type. This applies in particular to function
/// calls and casts.
static Cl::Kinds ClassifyUnnamed(ASTContext &Ctx, QualType T) {
// In C, function calls are always rvalues.
if (!Ctx.getLangOptions().CPlusPlus) return Cl::CL_PRValue;
// C++ [expr.call]p10: A function call is an lvalue if the result type is an
// lvalue reference type or an rvalue reference to function type, an xvalue
// if the result type is an rvalue refernence to object type, and a prvalue
// otherwise.
if (T->isLValueReferenceType())
return Cl::CL_LValue;
const RValueReferenceType *RV = T->getAs<RValueReferenceType>();
if (!RV) // Could still be a class temporary, though.
return T->isRecordType() ? Cl::CL_ClassTemporary : Cl::CL_PRValue;
return RV->getPointeeType()->isFunctionType() ? Cl::CL_LValue : Cl::CL_XValue;
}
示例10: isExternC
bool FunctionDecl::isExternC(ASTContext &Context) const {
// In C, any non-static, non-overloadable function has external
// linkage.
if (!Context.getLangOptions().CPlusPlus)
return getStorageClass() != Static && !getAttr<OverloadableAttr>();
for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit();
DC = DC->getParent()) {
if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
return getStorageClass() != Static &&
!getAttr<OverloadableAttr>();
break;
}
}
return false;
}
示例11: printSourceRange
static void printSourceRange(CharSourceRange range, ASTContext &Ctx,
raw_ostream &OS) {
SourceManager &SM = Ctx.getSourceManager();
const LangOptions &langOpts = Ctx.getLangOptions();
PresumedLoc PL = SM.getPresumedLoc(range.getBegin());
OS << llvm::sys::path::filename(PL.getFilename());
OS << " [" << PL.getLine() << ":"
<< PL.getColumn();
OS << " - ";
SourceLocation end = range.getEnd();
PL = SM.getPresumedLoc(end);
unsigned endCol = PL.getColumn() - 1;
if (!range.isTokenRange())
endCol += Lexer::MeasureTokenLength(end, SM, langOpts);
OS << PL.getLine() << ":" << endCol << "]";
}
示例12: ClassifyConditional
static Cl::Kinds ClassifyConditional(ASTContext &Ctx, const Expr *True,
const Expr *False) {
assert(Ctx.getLangOptions().CPlusPlus &&
"This is only relevant for C++.");
// C++ [expr.cond]p2
// If either the second or the third operand has type (cv) void, [...]
// the result [...] is a prvalue.
if (True->getType()->isVoidType() || False->getType()->isVoidType())
return Cl::CL_PRValue;
// Note that at this point, we have already performed all conversions
// according to [expr.cond]p3.
// C++ [expr.cond]p4: If the second and third operands are glvalues of the
// same value category [...], the result is of that [...] value category.
// C++ [expr.cond]p5: Otherwise, the result is a prvalue.
Cl::Kinds LCl = ClassifyInternal(Ctx, True),
RCl = ClassifyInternal(Ctx, False);
return LCl == RCl ? LCl : Cl::CL_PRValue;
}
示例13: ClassifyImpl
Cl Expr::ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const {
assert(!TR->isReferenceType() && "Expressions can't have reference type.");
Cl::Kinds kind = ClassifyInternal(Ctx, this);
// C99 6.3.2.1: An lvalue is an expression with an object type or an
// incomplete type other than void.
if (!Ctx.getLangOptions().CPlusPlus) {
// Thus, no functions.
if (TR->isFunctionType() || TR == Ctx.OverloadTy)
kind = Cl::CL_Function;
// No void either, but qualified void is OK because it is "other than void".
else if (TR->isVoidType() && !Ctx.getCanonicalType(TR).hasQualifiers())
kind = Cl::CL_Void;
}
Cl::ModifiableType modifiable = Cl::CM_Untested;
if (Loc)
modifiable = IsModifiable(Ctx, this, kind, *Loc);
return Classification(kind, modifiable);
}
示例14: ClassifyDecl
/// ClassifyDecl - Return the classification of an expression referencing the
/// given declaration.
static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D) {
// C++ [expr.prim.general]p6: The result is an lvalue if the entity is a
// function, variable, or data member and a prvalue otherwise.
// In C, functions are not lvalues.
// In addition, NonTypeTemplateParmDecl derives from VarDecl but isn't an
// lvalue unless it's a reference type (C++ [temp.param]p6), so we need to
// special-case this.
if (isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance())
return Cl::CL_MemberFunction;
bool islvalue;
if (const NonTypeTemplateParmDecl *NTTParm =
dyn_cast<NonTypeTemplateParmDecl>(D))
islvalue = NTTParm->getType()->isReferenceType();
else
islvalue = isa<VarDecl>(D) || isa<FieldDecl>(D) ||
(Ctx.getLangOptions().CPlusPlus &&
(isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)));
return islvalue ? Cl::CL_LValue : Cl::CL_PRValue;
}
示例15: IsModifiable
static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E,
Cl::Kinds Kind, SourceLocation &Loc) {
// As a general rule, we only care about lvalues. But there are some rvalues
// for which we want to generate special results.
if (Kind == Cl::CL_PRValue) {
// For the sake of better diagnostics, we want to specifically recognize
// use of the GCC cast-as-lvalue extension.
if (const ExplicitCastExpr *CE =
dyn_cast<ExplicitCastExpr>(E->IgnoreParens())) {
if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) {
Loc = CE->getExprLoc();
return Cl::CM_LValueCast;
}
}
}
if (Kind != Cl::CL_LValue)
return Cl::CM_RValue;
// This is the lvalue case.
// Functions are lvalues in C++, but not modifiable. (C++ [basic.lval]p6)
if (Ctx.getLangOptions().CPlusPlus && E->getType()->isFunctionType())
return Cl::CM_Function;
// You cannot assign to a variable outside a block from within the block if
// it is not marked __block, e.g.
// void takeclosure(void (^C)(void));
// void func() { int x = 1; takeclosure(^{ x = 7; }); }
if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(E)) {
if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
return Cl::CM_NotBlockQualified;
}
// Assignment to a property in ObjC is an implicit setter access. But a
// setter might not exist.
if (const ObjCPropertyRefExpr *Expr = dyn_cast<ObjCPropertyRefExpr>(E)) {
if (Expr->isImplicitProperty() && Expr->getImplicitPropertySetter() == 0)
return Cl::CM_NoSetterProperty;
}
CanQualType CT = Ctx.getCanonicalType(E->getType());
// Const stuff is obviously not modifiable.
if (CT.isConstQualified())
return Cl::CM_ConstQualified;
// Arrays are not modifiable, only their elements are.
if (CT->isArrayType())
return Cl::CM_ArrayType;
// Incomplete types are not modifiable.
if (CT->isIncompleteType())
return Cl::CM_IncompleteType;
// Records with any const fields (recursively) are not modifiable.
if (const RecordType *R = CT->getAs<RecordType>()) {
assert((E->getObjectKind() == OK_ObjCProperty ||
!Ctx.getLangOptions().CPlusPlus) &&
"C++ struct assignment should be resolved by the "
"copy assignment operator.");
if (R->hasConstFields())
return Cl::CM_ConstQualified;
}
return Cl::CM_Modifiable;
}