本文整理汇总了C++中clang::CompilerInstance::getDiagnostics方法的典型用法代码示例。如果您正苦于以下问题:C++ CompilerInstance::getDiagnostics方法的具体用法?C++ CompilerInstance::getDiagnostics怎么用?C++ CompilerInstance::getDiagnostics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clang::CompilerInstance
的用法示例。
在下文中一共展示了CompilerInstance::getDiagnostics方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TextDiagnosticPrinter
void c2ffi::init_ci(config &c, clang::CompilerInstance &ci) {
using clang::DiagnosticOptions;
using clang::TextDiagnosticPrinter;
using clang::TargetOptions;
using clang::TargetInfo;
ci.getInvocation().setLangDefaults(ci.getLangOpts(), c.kind,
clang::LangStandard::lang_unspecified);
DiagnosticOptions *dopt = new DiagnosticOptions;
TextDiagnosticPrinter *tpd =
new TextDiagnosticPrinter(llvm::errs(), dopt, false);
ci.createDiagnostics(tpd);
llvm::IntrusiveRefCntPtr<TargetOptions> *pto =
new llvm::IntrusiveRefCntPtr<TargetOptions>(new TargetOptions());
if(c.arch == "")
(*pto)->Triple = llvm::sys::getDefaultTargetTriple();
else
(*pto)->Triple = c.arch;
TargetInfo *pti = TargetInfo::CreateTargetInfo(ci.getDiagnostics(), pto->getPtr());
ci.setTarget(pti);
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
ci.createPreprocessor(clang::TU_Complete);
ci.getPreprocessorOpts().UsePredefines = false;
}
示例2: Files
ClangParser()
{
// Usually all examples try to build the CompilerInstance Object from CompilerInvocation object.
// However, CompilterInstance already has an in-built CompilerInvocation object. So we use it.
// Only problem is: target options are not set correctly for the in-built object. We do it manually.
// This below line is just to assert that the object exist.
clang::CompilerInvocation& invocation = m_CompilerInstance.getInvocation();
// Diagnostics is needed - set it up
m_CompilerInstance.createDiagnostics();
// set the include directories path
clang::HeaderSearchOptions & headerSearchOptions = m_CompilerInstance.getHeaderSearchOpts();
headerSearchOptions.AddPath("C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\include", clang::frontend::IncludeDirGroup::Angled, false, false);
// headerSearchOptions.Verbose = true;
// set few options
clang::LangOptions& langOptions = m_CompilerInstance.getLangOpts();
langOptions.CPlusPlus = 1;
langOptions.Bool = 1;
langOptions.RTTI = 0;
#if defined(_MSC_VER)
langOptions.MicrosoftExt = 1;
langOptions.MSVCCompat = 1;
langOptions.MSBitfields = 1;
langOptions.DelayedTemplateParsing = 1; // MSVC parses templates at the time of actual use
m_CompilerInstance.getDiagnosticOpts().setFormat(clang::TextDiagnosticFormat::Msvc);
//clInstance.getTargetOpts().ABI = "microsoft";
#endif
// Need to set the source manager before AST
m_CompilerInstance.createFileManager();
m_CompilerInstance.createSourceManager(m_CompilerInstance.getFileManager());
// Need to set the target before AST. Adjust the default target options and create a target
m_CompilerInstance.getTargetOpts().Triple = llvm::sys::getProcessTriple();
m_CompilerInstance.setTarget(clang::TargetInfo::CreateTargetInfo(m_CompilerInstance.getDiagnostics(), &m_CompilerInstance.getTargetOpts()));
// Create pre-processor and AST Context
m_CompilerInstance.createPreprocessor(clang::TranslationUnitKind::TU_Module);
m_CompilerInstance.createASTContext();
if (m_CompilerInstance.hasPreprocessor())
{
clang::Preprocessor & preprocessor = m_CompilerInstance.getPreprocessor();
preprocessor.getBuiltinInfo().InitializeBuiltins(preprocessor.getIdentifierTable(), preprocessor.getLangOpts());
}
}
示例3: TextDiagnosticPrinter
void c2ffi::init_ci(config &c, clang::CompilerInstance &ci) {
using clang::DiagnosticOptions;
using clang::TextDiagnosticPrinter;
using clang::TargetOptions;
using clang::TargetInfo;
DiagnosticOptions *dopt = new DiagnosticOptions;
TextDiagnosticPrinter *tpd =
new TextDiagnosticPrinter(llvm::errs(), dopt, false);
ci.createDiagnostics(tpd);
std::shared_ptr<TargetOptions> pto =
std::shared_ptr<TargetOptions>(new TargetOptions());
if(c.arch == "")
pto->Triple = llvm::sys::getDefaultTargetTriple();
else
pto->Triple = c.arch;
TargetInfo *pti = TargetInfo::CreateTargetInfo(ci.getDiagnostics(), pto);
clang::LangOptions &lo = ci.getLangOpts();
switch(pti->getTriple().getEnvironment()) {
case llvm::Triple::EnvironmentType::GNU:
lo.GNUMode = 1;
break;
case llvm::Triple::EnvironmentType::MSVC:
lo.MSVCCompat = 1;
lo.MicrosoftExt = 1;
break;
default:
std::cerr << "c2ffi warning: Unhandled environment: '"
<< pti->getTriple().getEnvironmentName().str()
<< "' for triple '" << c.arch
<< "'" << std::endl;
}
ci.getInvocation().setLangDefaults(lo, c.kind, c.std);
ci.setTarget(pti);
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
ci.createPreprocessor(clang::TU_Complete);
ci.getPreprocessorOpts().UsePredefines = false;
ci.getPreprocessorOutputOpts().ShowCPP = c.preprocess_only;
ci.getPreprocessor().setPreprocessedOutput(c.preprocess_only);
}
示例4: getErrorLevel
BlinkGCPluginConsumer::BlinkGCPluginConsumer(
clang::CompilerInstance& instance,
const BlinkGCPluginOptions& options)
: instance_(instance),
diagnostic_(instance.getDiagnostics()),
options_(options),
json_(0) {
// Only check structures in the blink and WebKit namespaces.
options_.checked_namespaces.insert("blink");
// Ignore GC implementation files.
options_.ignored_directories.push_back("/heap/");
// Register warning/error messages.
diag_class_must_left_mostly_derive_gc_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kClassMustLeftMostlyDeriveGC);
diag_class_requires_trace_method_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kClassRequiresTraceMethod);
diag_base_requires_tracing_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kBaseRequiresTracing);
diag_fields_require_tracing_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kFieldsRequireTracing);
diag_class_contains_invalid_fields_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kClassContainsInvalidFields);
diag_class_contains_invalid_fields_warning_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kClassContainsInvalidFields);
diag_class_contains_gc_root_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kClassContainsGCRoot);
diag_class_requires_finalization_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kClassRequiresFinalization);
diag_class_does_not_require_finalization_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Warning, kClassDoesNotRequireFinalization);
diag_finalizer_accesses_finalized_field_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kFinalizerAccessesFinalizedField);
diag_finalizer_eagerly_finalized_field_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kFinalizerAccessesEagerlyFinalizedField);
diag_overridden_non_virtual_trace_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kOverriddenNonVirtualTrace);
diag_missing_trace_dispatch_method_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kMissingTraceDispatchMethod);
diag_missing_finalize_dispatch_method_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kMissingFinalizeDispatchMethod);
diag_virtual_and_manual_dispatch_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kVirtualAndManualDispatch);
diag_missing_trace_dispatch_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kMissingTraceDispatch);
diag_missing_finalize_dispatch_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kMissingFinalizeDispatch);
diag_derives_non_stack_allocated_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kDerivesNonStackAllocated);
diag_class_overrides_new_ =
diagnostic_.getCustomDiagID(getErrorLevel(), kClassOverridesNew);
diag_class_declares_pure_virtual_trace_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kClassDeclaresPureVirtualTrace);
diag_left_most_base_must_be_polymorphic_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kLeftMostBaseMustBePolymorphic);
diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kBaseClassMustDeclareVirtualTrace);
// Register note messages.
diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kBaseRequiresTracingNote);
diag_field_requires_tracing_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kFieldRequiresTracingNote);
diag_raw_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kRawPtrToGCManagedClassNote);
diag_ref_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kRefPtrToGCManagedClassNote);
diag_reference_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kReferencePtrToGCManagedClassNote);
diag_own_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kOwnPtrToGCManagedClassNote);
diag_member_to_gc_unmanaged_class_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kMemberToGCUnmanagedClassNote);
diag_stack_allocated_field_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kStackAllocatedFieldNote);
diag_member_in_unmanaged_class_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kMemberInUnmanagedClassNote);
diag_part_object_to_gc_derived_class_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kPartObjectToGCDerivedClassNote);
diag_part_object_contains_gc_root_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kPartObjectContainsGCRootNote);
diag_field_contains_gc_root_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kFieldContainsGCRootNote);
diag_finalized_field_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kFinalizedFieldNote);
diag_eagerly_finalized_field_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kEagerlyFinalizedFieldNote);
diag_user_declared_destructor_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kUserDeclaredDestructorNote);
diag_user_declared_finalizer_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kUserDeclaredFinalizerNote);
diag_base_requires_finalization_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kBaseRequiresFinalizationNote);
diag_field_requires_finalization_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kFieldRequiresFinalizationNote);
diag_overridden_non_virtual_trace_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kOverriddenNonVirtualTraceNote);
diag_manual_dispatch_method_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kManualDispatchMethodNote);
//.........这里部分代码省略.........
示例5: CreateASTConsumer
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
clang::CompilerInstance &Compiler, llvm::StringRef InFile)
{
return std::unique_ptr<clang::ASTConsumer>(new fxc::Driver(Compiler.getASTContext(), Compiler.getDiagnostics()));
}