本文整理汇总了C++中Sema::getLangOpts方法的典型用法代码示例。如果您正苦于以下问题:C++ Sema::getLangOpts方法的具体用法?C++ Sema::getLangOpts怎么用?C++ Sema::getLangOpts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sema
的用法示例。
在下文中一共展示了Sema::getLangOpts方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsKnownEmitted
// Do we know that we will eventually codegen the given function?
static bool IsKnownEmitted(Sema &S, FunctionDecl *FD) {
// Templates are emitted when they're instantiated.
if (FD->isDependentContext())
return false;
// When compiling for device, host functions are never emitted. Similarly,
// when compiling for host, device and global functions are never emitted.
// (Technically, we do emit a host-side stub for global functions, but this
// doesn't count for our purposes here.)
Sema::CUDAFunctionTarget T = S.IdentifyCUDATarget(FD);
if (S.getLangOpts().CUDAIsDevice && T == Sema::CFT_Host)
return false;
if (!S.getLangOpts().CUDAIsDevice &&
(T == Sema::CFT_Device || T == Sema::CFT_Global))
return false;
// Check whether this function is externally visible -- if so, it's
// known-emitted.
//
// We have to check the GVA linkage of the function's *definition* -- if we
// only have a declaration, we don't know whether or not the function will be
// emitted, because (say) the definition could include "inline".
FunctionDecl *Def = FD->getDefinition();
if (Def &&
!isDiscardableGVALinkage(S.getASTContext().GetGVALinkageForFunction(Def)))
return true;
// Otherwise, the function is known-emitted if it's in our set of
// known-emitted functions.
return S.DeviceKnownEmittedFns.count(FD) > 0;
}
示例2: SetStorageClassSpec
bool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
const char *&PrevSpec,
unsigned &DiagID,
const PrintingPolicy &Policy) {
// OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class
// specifiers are not supported.
// It seems sensible to prohibit private_extern too
// The cl_clang_storage_class_specifiers extension enables support for
// these storage-class specifiers.
// OpenCL v1.2 s6.8 changes this to "The auto and register storage-class
// specifiers are not supported."
if (S.getLangOpts().OpenCL &&
!S.getOpenCLOptions().cl_clang_storage_class_specifiers) {
switch (SC) {
case SCS_extern:
case SCS_private_extern:
case SCS_static:
if (S.getLangOpts().OpenCLVersion < 120) {
DiagID = diag::err_opencl_unknown_type_specifier;
PrevSpec = getSpecifierName(SC);
return true;
}
break;
case SCS_auto:
case SCS_register:
DiagID = diag::err_opencl_unknown_type_specifier;
PrevSpec = getSpecifierName(SC);
return true;
default:
break;
}
}
if (StorageClassSpec != SCS_unspecified) {
// Maybe this is an attempt to use C++11 'auto' outside of C++11 mode.
bool isInvalid = true;
if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) {
if (SC == SCS_auto)
return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, Policy);
if (StorageClassSpec == SCS_auto) {
isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc,
PrevSpec, DiagID, Policy);
assert(!isInvalid && "auto SCS -> TST recovery failed");
}
}
// Changing storage class is allowed only if the previous one
// was the 'extern' that is part of a linkage specification and
// the new storage class is 'typedef'.
if (isInvalid &&
!(SCS_extern_in_linkage_spec &&
StorageClassSpec == SCS_extern &&
SC == SCS_typedef))
return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID);
}
StorageClassSpec = SC;
StorageClassSpecLoc = Loc;
assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield");
return false;
}
示例3: CheckAsmLValue
/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently
/// ignore "noop" casts in places where an lvalue is required by an inline asm.
/// We emulate this behavior when -fheinous-gnu-extensions is specified, but
/// provide a strong guidance to not use it.
///
/// This method checks to see if the argument is an acceptable l-value and
/// returns false if it is a case we can handle.
static bool CheckAsmLValue(const Expr *E, Sema &S) {
// Type dependent expressions will be checked during instantiation.
if (E->isTypeDependent())
return false;
if (E->isLValue())
return false; // Cool, this is an lvalue.
// Okay, this is not an lvalue, but perhaps it is the result of a cast that we
// are supposed to allow.
const Expr *E2 = E->IgnoreParenNoopCasts(S.Context);
if (E != E2 && E2->isLValue()) {
if (!S.getLangOpts().HeinousExtensions)
S.Diag(E2->getLocStart(), diag::err_invalid_asm_cast_lvalue)
<< E->getSourceRange();
else
S.Diag(E2->getLocStart(), diag::warn_invalid_asm_cast_lvalue)
<< E->getSourceRange();
// Accept, even if we emitted an error diagnostic.
return false;
}
// None of the above, just randomly invalid non-lvalue.
return true;
}
示例4: HandleDLLImportAttr
static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
// Attribute can be applied only to functions or variables.
FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
if (!FD && !isa<VarDecl>(D)) {
// Apparently Visual C++ thinks it is okay to not emit a warning
// in this case, so only emit a warning when -fms-extensions is not
// specified.
if (!S.getLangOpts().MicrosoftExt)
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << 2 /*variable and function*/;
return;
}
// Currently, the dllimport attribute is ignored for inlined functions.
// Warning is emitted.
if (FD && FD->isInlineSpecified()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
return;
}
unsigned Index = Attr.getAttributeSpellingListIndex();
DLLImportAttr *NewAttr = S.mergeDLLImportAttr(D, Attr.getRange(), Index);
if (NewAttr)
D->addAttr(NewAttr);
}
示例5: EraseUnwantedCUDAMatchesImpl
static void EraseUnwantedCUDAMatchesImpl(Sema &S, const FunctionDecl *Caller,
llvm::SmallVectorImpl<T> &Matches,
FetchDeclFn FetchDecl) {
assert(S.getLangOpts().CUDATargetOverloads &&
"Should not be called w/o enabled target overloads.");
if (Matches.size() <= 1)
return;
// Find the best call preference among the functions in Matches.
Sema::CUDAFunctionPreference P, BestCFP = Sema::CFP_Never;
for (auto const &Match : Matches) {
P = S.IdentifyCUDAPreference(Caller, FetchDecl(Match));
if (P > BestCFP)
BestCFP = P;
}
// Erase all functions with lower priority.
for (unsigned I = 0, N = Matches.size(); I != N;)
if (S.IdentifyCUDAPreference(Caller, FetchDecl(Matches[I])) < BestCFP) {
Matches[I] = Matches[--N];
Matches.resize(N);
} else {
++I;
}
}
示例6: CorrectedStr
// Returns true on failure.
static bool
LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
//SourceRange BaseRange,
const StructType *STy,
SourceLocation OpLoc) {
StructTypeDecl *SDecl = STy->getDecl();
DeclContext *DC = SDecl;
// The record definition is complete, now look up the member.
SemaRef.LookupQualifiedName(R, DC);
if (!R.empty())
return false;
#if 0
// We didn't find anything with the given name, so try to correct
// for typos.
DeclarationName Name = R.getLookupName();
RecordMemberExprValidatorCCC Validator;
TypoCorrection Corrected = SemaRef.CorrectTypo(R.getLookupNameInfo(),
R.getLookupKind(), NULL,
&SS, Validator, DC);
R.clear();
if (NamedDecl *ND = Corrected.getCorrectionDecl()) {
std::string CorrectedStr(
Corrected.getAsString(SemaRef.getLangOpts()));
std::string CorrectedQuotedStr(
Corrected.getQuoted(SemaRef.getLangOpts()));
R.setLookupName(Corrected.getCorrection());
R.addDecl(ND);
SemaRef.Diag(R.getNameLoc(), diag::err_no_member_suggest)
<< Name << DC << CorrectedQuotedStr << SS.getRange()
<< FixItHint::CreateReplacement(Corrected.getCorrectionRange(),
CorrectedStr);
SemaRef.Diag(ND->getLocation(), diag::note_previous_decl)
<< ND->getDeclName();
}
#endif
// FIXME: Is this right? (also in clang)
return false;
}
示例7: IsKnownEmitted
// Do we know that we will eventually codegen the given function?
static bool IsKnownEmitted(Sema &S, FunctionDecl *FD) {
// Templates are emitted when they're instantiated.
if (FD->isDependentContext())
return false;
// When compiling for device, host functions are never emitted. Similarly,
// when compiling for host, device and global functions are never emitted.
// (Technically, we do emit a host-side stub for global functions, but this
// doesn't count for our purposes here.)
Sema::CUDAFunctionTarget T = S.IdentifyCUDATarget(FD);
if (S.getLangOpts().CUDAIsDevice && T == Sema::CFT_Host)
return false;
if (!S.getLangOpts().CUDAIsDevice &&
(T == Sema::CFT_Device || T == Sema::CFT_Global))
return false;
// Externally-visible and similar functions are always emitted.
if (!isDiscardableGVALinkage(S.getASTContext().GetGVALinkageForFunction(FD)))
return true;
// Otherwise, the function is known-emitted if it's in our set of
// known-emitted functions.
return S.CUDAKnownEmittedFns.count(FD) > 0;
}
示例8:
/// Return true if a particular note should be downgraded to a compatibility
/// warning in C++11 mode.
static bool IsCXX98CompatWarning(Sema &S, unsigned InDiagNote) {
return S.getLangOpts().CPlusPlus0x &&
InDiagNote == diag::note_protected_by_variable_non_pod;
}
示例9: getContextsForContextKind
static unsigned long long getContextsForContextKind(
enum CodeCompletionContext::Kind kind,
Sema &S) {
unsigned long long contexts = 0;
switch (kind) {
case CodeCompletionContext::CCC_OtherWithMacros: {
//We can allow macros here, but we don't know what else is permissible
//So we'll say the only thing permissible are macros
contexts = CXCompletionContext_MacroName;
break;
}
case CodeCompletionContext::CCC_TopLevel:
case CodeCompletionContext::CCC_ObjCIvarList:
case CodeCompletionContext::CCC_ClassStructUnion:
case CodeCompletionContext::CCC_Type: {
contexts = CXCompletionContext_AnyType |
CXCompletionContext_ObjCInterface;
if (S.getLangOpts().CPlusPlus) {
contexts |= CXCompletionContext_EnumTag |
CXCompletionContext_UnionTag |
CXCompletionContext_StructTag |
CXCompletionContext_ClassTag |
CXCompletionContext_NestedNameSpecifier;
}
break;
}
case CodeCompletionContext::CCC_Statement: {
contexts = CXCompletionContext_AnyType |
CXCompletionContext_ObjCInterface |
CXCompletionContext_AnyValue;
if (S.getLangOpts().CPlusPlus) {
contexts |= CXCompletionContext_EnumTag |
CXCompletionContext_UnionTag |
CXCompletionContext_StructTag |
CXCompletionContext_ClassTag |
CXCompletionContext_NestedNameSpecifier;
}
break;
}
case CodeCompletionContext::CCC_Expression: {
contexts = CXCompletionContext_AnyValue;
if (S.getLangOpts().CPlusPlus) {
contexts |= CXCompletionContext_AnyType |
CXCompletionContext_ObjCInterface |
CXCompletionContext_EnumTag |
CXCompletionContext_UnionTag |
CXCompletionContext_StructTag |
CXCompletionContext_ClassTag |
CXCompletionContext_NestedNameSpecifier;
}
break;
}
case CodeCompletionContext::CCC_ObjCMessageReceiver: {
contexts = CXCompletionContext_ObjCObjectValue |
CXCompletionContext_ObjCSelectorValue |
CXCompletionContext_ObjCInterface;
if (S.getLangOpts().CPlusPlus) {
contexts |= CXCompletionContext_CXXClassTypeValue |
CXCompletionContext_AnyType |
CXCompletionContext_EnumTag |
CXCompletionContext_UnionTag |
CXCompletionContext_StructTag |
CXCompletionContext_ClassTag |
CXCompletionContext_NestedNameSpecifier;
}
break;
}
case CodeCompletionContext::CCC_DotMemberAccess: {
contexts = CXCompletionContext_DotMemberAccess;
break;
}
case CodeCompletionContext::CCC_ArrowMemberAccess: {
contexts = CXCompletionContext_ArrowMemberAccess;
break;
}
case CodeCompletionContext::CCC_ObjCPropertyAccess: {
contexts = CXCompletionContext_ObjCPropertyAccess;
break;
}
case CodeCompletionContext::CCC_EnumTag: {
contexts = CXCompletionContext_EnumTag |
CXCompletionContext_NestedNameSpecifier;
break;
}
case CodeCompletionContext::CCC_UnionTag: {
contexts = CXCompletionContext_UnionTag |
CXCompletionContext_NestedNameSpecifier;
break;
}
case CodeCompletionContext::CCC_ClassOrStructTag: {
contexts = CXCompletionContext_StructTag |
CXCompletionContext_ClassTag |
CXCompletionContext_NestedNameSpecifier;
break;
}
case CodeCompletionContext::CCC_ObjCProtocolName: {
contexts = CXCompletionContext_ObjCProtocol;
break;
}
case CodeCompletionContext::CCC_Namespace: {
//.........这里部分代码省略.........
示例10: Finish
/// Finish - This does final analysis of the declspec, rejecting things like
/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
/// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
/// DeclSpec is guaranteed self-consistent, even if an error occurred.
void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
// Before possibly changing their values, save specs as written.
SaveWrittenBuiltinSpecs();
// Check the type specifier components first.
// If decltype(auto) is used, no other type specifiers are permitted.
if (TypeSpecType == TST_decltype_auto &&
(TypeSpecWidth != TSW_unspecified ||
TypeSpecComplex != TSC_unspecified ||
TypeSpecSign != TSS_unspecified ||
TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
TypeQualifiers)) {
const unsigned NumLocs = 9;
SourceLocation ExtraLocs[NumLocs] = {
TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc
};
FixItHint Hints[NumLocs];
SourceLocation FirstLoc;
for (unsigned I = 0; I != NumLocs; ++I) {
if (ExtraLocs[I].isValid()) {
if (FirstLoc.isInvalid() ||
S.getSourceManager().isBeforeInTranslationUnit(ExtraLocs[I],
FirstLoc))
FirstLoc = ExtraLocs[I];
Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
}
}
TypeSpecWidth = TSW_unspecified;
TypeSpecComplex = TSC_unspecified;
TypeSpecSign = TSS_unspecified;
TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
TypeQualifiers = 0;
S.Diag(TSTLoc, diag::err_decltype_auto_cannot_be_combined)
<< Hints[0] << Hints[1] << Hints[2] << Hints[3]
<< Hints[4] << Hints[5] << Hints[6] << Hints[7];
}
// Validate and finalize AltiVec vector declspec.
if (TypeAltiVecVector) {
if (TypeAltiVecBool) {
// Sign specifiers are not allowed with vector bool. (PIM 2.1)
if (TypeSpecSign != TSS_unspecified) {
S.Diag(TSSLoc, diag::err_invalid_vector_bool_decl_spec)
<< getSpecifierName((TSS)TypeSpecSign);
}
// Only char/int are valid with vector bool. (PIM 2.1)
if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) &&
(TypeSpecType != TST_int)) || TypeAltiVecPixel) {
S.Diag(TSTLoc, diag::err_invalid_vector_bool_decl_spec)
<< (TypeAltiVecPixel ? "__pixel" :
getSpecifierName((TST)TypeSpecType, Policy));
}
// Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short) &&
(TypeSpecWidth != TSW_longlong))
S.Diag(TSWLoc, diag::err_invalid_vector_bool_decl_spec)
<< getSpecifierName((TSW)TypeSpecWidth);
// vector bool long long requires VSX support or ZVector.
if ((TypeSpecWidth == TSW_longlong) &&
(!S.Context.getTargetInfo().hasFeature("vsx")) &&
(!S.Context.getTargetInfo().hasFeature("power8-vector")) &&
!S.getLangOpts().ZVector)
S.Diag(TSTLoc, diag::err_invalid_vector_long_long_decl_spec);
// Elements of vector bool are interpreted as unsigned. (PIM 2.1)
if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) ||
(TypeSpecWidth != TSW_unspecified))
TypeSpecSign = TSS_unsigned;
} else if (TypeSpecType == TST_double) {
// vector long double and vector long long double are never allowed.
// vector double is OK for Power7 and later, and ZVector.
if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong)
S.Diag(TSWLoc, diag::err_invalid_vector_long_double_decl_spec);
else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
!S.getLangOpts().ZVector)
S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
} else if (TypeSpecType == TST_float) {
// vector float is unsupported for ZVector.
if (S.getLangOpts().ZVector)
S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec);
} else if (TypeSpecWidth == TSW_long) {
// vector long is unsupported for ZVector and deprecated for AltiVec.
if (S.getLangOpts().ZVector)
S.Diag(TSWLoc, diag::err_invalid_vector_long_decl_spec);
else
S.Diag(TSWLoc, diag::warn_vector_long_decl_spec_combination)
<< getSpecifierName((TST)TypeSpecType, Policy);
}
if (TypeAltiVecPixel) {
//TODO: perform validation
//.........这里部分代码省略.........
示例11: ParseAST
void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
// Collect global stats on Decls/Stmts (until we have a module streamer).
if (PrintStats) {
Decl::EnableStatistics();
Stmt::EnableStatistics();
}
// Also turn on collection of stats inside of the Sema object.
bool OldCollectStats = PrintStats;
std::swap(OldCollectStats, S.CollectStats);
ASTConsumer *Consumer = &S.getASTConsumer();
OwningPtr<Parser> ParseOP(new Parser(S.getPreprocessor(), S,
SkipFunctionBodies));
Parser &P = *ParseOP.get();
PrettyStackTraceParserEntry CrashInfo(P);
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<Parser>
CleanupParser(ParseOP.get());
S.getPreprocessor().EnterMainSourceFile();
P.Initialize();
S.Initialize();
// C11 6.9p1 says translation units must have at least one top-level
// declaration. C++ doesn't have this restriction. We also don't want to
// complain if we have a precompiled header, although technically if the PCH
// is empty we should still emit the (pedantic) diagnostic.
Parser::DeclGroupPtrTy ADecl;
ExternalASTSource *External = S.getASTContext().getExternalSource();
if (External)
External->StartTranslationUnit(Consumer);
if (P.ParseTopLevelDecl(ADecl)) {
if (!External && !S.getLangOpts().CPlusPlus)
P.Diag(diag::ext_empty_translation_unit);
} else {
do {
// If we got a null return and something *was* parsed, ignore it. This
// is due to a top-level semicolon, an action override, or a parse error
// skipping something.
if (ADecl && !Consumer->HandleTopLevelDecl(ADecl.get()))
return;
} while (!P.ParseTopLevelDecl(ADecl));
}
// Process any TopLevelDecls generated by #pragma weak.
for (SmallVector<Decl*,2>::iterator
I = S.WeakTopLevelDecls().begin(),
E = S.WeakTopLevelDecls().end(); I != E; ++I)
Consumer->HandleTopLevelDecl(DeclGroupRef(*I));
Consumer->HandleTranslationUnit(S.getASTContext());
std::swap(OldCollectStats, S.CollectStats);
if (PrintStats) {
llvm::errs() << "\nSTATISTICS:\n";
P.getActions().PrintStats();
S.getASTContext().PrintStats();
Decl::PrintStats();
Stmt::PrintStats();
Consumer->PrintStats();
}
}