Beispiel #1
0
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;
}
bool WebCLValidatorAction::initialize(clang::CompilerInstance &instance)
{
    if (!WebCLAction::initialize(instance))
        return false;

    rewriter_ = new clang::Rewriter(
        instance.getSourceManager(), instance.getLangOpts());
    if (!rewriter_) {
        reporter_->fatal("Internal error. Can't create rewriter.\n");
        return false;
    }

    transformer_ = new WebCLTransformer(instance, *rewriter_);
    if (!transformer_) {
        reporter_->fatal("Internal error. Can't create AST transformer.\n");
        return false;
    }

    // Consumer must be allocated dynamically. The framework deletes
    // it.
    consumer_ = new WebCLConsumer(instance, *rewriter_, *transformer_);
    if (!consumer_) {
        reporter_->fatal("Internal error. Can't create AST consumer.\n");
        return false;
    }

    sema_ = new clang::Sema(
        instance.getPreprocessor(), instance.getASTContext(), *consumer_);
    if (!sema_) {
        reporter_->fatal("Internal error. Can't create semantic actions.\n");
        return false;
    }

    return true;
}
bool WebCLMatcherAction::initialize(clang::CompilerInstance &instance)
{
    if (!WebCLAction::initialize(instance))
        return false;

    rewriter_ = new clang::Rewriter(
        instance.getSourceManager(), instance.getLangOpts());
    if (!rewriter_) {
        reporter_->fatal("Internal error. Can't create rewriter.\n");
        return false;
    }

    printer_ = new WebCLPrinter(*rewriter_);
    if (!printer_) {
        reporter_->fatal("Internal error. Can't create printer.\n");
        return false;
    }

    consumer_ = finder_.newASTConsumer();
    if (!consumer_) {
        reporter_->fatal("Internal error. Can't create AST consumer.\n");
        return false;
    }

    return true;
}
std::unique_ptr<clang::ASTConsumer>
FindAllSymbolsAction::CreateASTConsumer(clang::CompilerInstance &Compiler,
                                        StringRef InFile) {
  Compiler.getPreprocessor().addCommentHandler(&Handler);
  Compiler.getPreprocessor().addPPCallbacks(llvm::make_unique<FindAllMacros>(
      Reporter, &Compiler.getSourceManager(), &Collector));
  return MatchFinder.newASTConsumer();
}
Beispiel #5
0
 MkApiASTConsumer2(clang::CompilerInstance &CI, llvm::StringRef InFile)
     : mpVisitor(0)
 {
     CI.setASTConsumer(this);
     //cout << "predefines: " << CI.getPreprocessor().getPredefines() << endl;
     // A Rewriter helps us manage the code rewriting task.
     mRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
     mpVisitor = new MkApiASTVisitor(mRewriter);
 }
Beispiel #6
0
std::string getFileName( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
    clang::FileID fid = ci.getSourceManager().getFileID(sl) ;
    if ( ! fid.isInvalid() ) {
        const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
        if ( fe != NULL ) {
            char * resolved_path = almostRealPath( fe->getName() ) ;
            if ( resolved_path != NULL  and hsd.isPathInUserDir(resolved_path)) {
                return std::string(resolved_path) ;
            }
        }
    }
    return std::string() ;
}
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
    clang::CompilerInstance &Compiler, StringRef File) {
  // FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
  // modify Compiler.
  Context.setSourceManager(&Compiler.getSourceManager());
  Context.setCurrentFile(File);
  Context.setASTContext(&Compiler.getASTContext());

  std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
  CheckFactories->createChecks(&Context, Checks);

  ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
  if (auto *P = Context.getCheckProfileData())
    FinderOptions.CheckProfiling.emplace(P->Records);

  std::unique_ptr<ast_matchers::MatchFinder> Finder(
      new ast_matchers::MatchFinder(std::move(FinderOptions)));

  for (auto &Check : Checks) {
    Check->registerMatchers(&*Finder);
    Check->registerPPCallbacks(Compiler);
  }

  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
  if (!Checks.empty())
    Consumers.push_back(Finder->newASTConsumer());

  AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
  // FIXME: Remove this option once clang's cfg-temporary-dtors option defaults
  // to true.
  AnalyzerOptions->Config["cfg-temporary-dtors"] =
      Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";

  GlobList &Filter = Context.getChecksFilter();
  AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
  if (!AnalyzerOptions->CheckersControlList.empty()) {
    setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
    AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
    AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
    AnalyzerOptions->AnalyzeNestedBlocks = true;
    AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true;
    std::unique_ptr<ento::AnalysisASTConsumer> AnalysisConsumer =
        ento::CreateAnalysisConsumer(Compiler);
    AnalysisConsumer->AddDiagnosticConsumer(
        new AnalyzerDiagnosticConsumer(Context));
    Consumers.push_back(std::move(AnalysisConsumer));
  }
  return llvm::make_unique<ClangTidyASTConsumer>(
      std::move(Consumers), std::move(Finder), std::move(Checks));
}
	bool parseAST(const char* szSourceCodeFilePath, clang::ast_matchers::MatchFinder finder)
	{
		// create the compiler instance setup for this file as main file
		prepareCompilerforFile(szSourceCodeFilePath);

		std::unique_ptr<clang::ASTConsumer> pAstConsumer (finder.newASTConsumer());
		
		clang::DiagnosticConsumer& diagConsumer = m_CompilerInstance.getDiagnosticClient();
		diagConsumer.BeginSourceFile(m_CompilerInstance.getLangOpts(), &m_CompilerInstance.getPreprocessor());
		clang::ParseAST(m_CompilerInstance.getPreprocessor(), pAstConsumer.get(), m_CompilerInstance.getASTContext());
		diagConsumer.EndSourceFile();

		return diagConsumer.getNumErrors() != 0;
	}
Beispiel #9
0
static bool
recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
                     StringRef indexStorePath, bool indexSystemModules,
                     bool isDebugCompilation, StringRef targetTriple,
                     ArrayRef<const clang::FileEntry *> fileDependencies,
                     const clang::CompilerInstance &clangCI,
                     DiagnosticEngine &diags) {
  auto &fileMgr = clangCI.getFileManager();
  auto *module = primarySourceFile->getParentModule();
  bool isSystem = module->isSystemModule();
  auto *mainFile = fileMgr.getFile(primarySourceFile->getFilename());
  // FIXME: Get real values for the following.
  StringRef swiftVersion;
  StringRef sysrootPath = clangCI.getHeaderSearchOpts().Sysroot;

  IndexUnitWriter unitWriter(fileMgr, indexStorePath,
    "swift", swiftVersion, indexUnitToken, module->getNameStr(),
    mainFile, isSystem, /*isModuleUnit=*/false, isDebugCompilation,
    targetTriple, sysrootPath, getModuleInfoFromOpaqueModule);

  // Module dependencies.
  ModuleDecl::ImportFilter importFilter;
  importFilter |= ModuleDecl::ImportFilterKind::Public;
  importFilter |= ModuleDecl::ImportFilterKind::Private;
  importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
  SmallVector<ModuleDecl::ImportedModule, 8> imports;
  primarySourceFile->getImportedModules(imports, importFilter);
  StringScratchSpace moduleNameScratch;
  addModuleDependencies(imports, indexStorePath, indexSystemModules,
                        targetTriple, clangCI, diags, unitWriter, moduleNameScratch);

  // File dependencies.
  for (auto *F : fileDependencies)
    unitWriter.addFileDependency(F, /*FIXME:isSystem=*/false, /*Module=*/nullptr);

  recordSourceFile(primarySourceFile, indexStorePath, diags,
                   [&](StringRef recordFile, StringRef filename) {
    unitWriter.addRecordFile(recordFile, fileMgr.getFile(filename),
                             module->isSystemModule(), /*Module=*/nullptr);
  });

  std::string error;
  if (unitWriter.write(error)) {
    diags.diagnose(SourceLoc(), diag::error_write_index_unit, error);
    return true;
  }

  return false;
}
Beispiel #10
0
    MyASTConsumer(clang::CompilerInstance &ci) : clang::ASTConsumer(), ci(ci),
            annotator (OutputPath, DataPath)

    {
        for(std::string &s : ProjectPaths) {
            auto colonPos = s.find(':');
            if (colonPos >= s.size()) {
                std::cerr << "fail to parse project option : " << s << std::endl;
                continue;
            }
            auto secondColonPos = s.find(':', colonPos+1);
            ProjectInfo info { s.substr(0, colonPos), s.substr(colonPos+1, secondColonPos - colonPos -1),
                                secondColonPos < s.size() ? s.substr(secondColonPos + 1) : std::string() };
            annotator.addProject(std::move(info));
        }
        for(std::string &s : ExternalProjectPaths) {
            auto colonPos = s.find(':');
            if (colonPos >= s.size()) {
                std::cerr << "fail to parse project option : " << s << std::endl;
                continue;
            }
            auto secondColonPos = s.find(':', colonPos+1);
            if (secondColonPos >= s.size()) {
                std::cerr << "fail to parse project option : " << s << std::endl;
                continue;
            }
            ProjectInfo info { s.substr(0, colonPos), s.substr(colonPos+1, secondColonPos - colonPos -1),
                               ProjectInfo::External };
            info.external_root_url = s.substr(secondColonPos + 1);
            annotator.addProject(std::move(info));
        }

        //ci.getLangOpts().DelayedTemplateParsing = (true);
        ci.getPreprocessor().enableIncrementalProcessing();
    }
	void prepareCompilerforFile(const char* szSourceCodeFilePath)
	{
		// To reuse the source manager we have to create these tables.
		m_CompilerInstance.getSourceManager().clearIDTables();
		//m_CompilerInstance.InitializeSourceManager(clang::FrontendInputFile(szSourceCodeFilePath, clang::InputKind::IK_C));// ger(m_CompilerInstance.getFileManager());

		// supply the file to the source manager and set it as main-file 
		const clang::FileEntry * file = m_CompilerInstance.getFileManager().getFile(szSourceCodeFilePath);
		clang::FileID fileID = m_CompilerInstance.getSourceManager().createFileID(file, clang::SourceLocation(), clang::SrcMgr::CharacteristicKind::C_User);
		m_CompilerInstance.getSourceManager().setMainFileID(fileID);

		// CodeGenAction needs this
		clang::FrontendOptions& feOptions = m_CompilerInstance.getFrontendOpts();
		feOptions.Inputs.clear();
		feOptions.Inputs.push_back(clang::FrontendInputFile(szSourceCodeFilePath, clang::FrontendOptions::getInputKindForExtension(clang::StringRef(szSourceCodeFilePath).rsplit('.').second), false));
	}
 std::unique_ptr<clang::ASTConsumer>
 CreateASTConsumer(clang::CompilerInstance &CI, StringRef InFile) override {
   CI.setExternalSemaSource(SemaSource);
   SemaSource->setFilePath(InFile);
   SemaSource->setCompilerInstance(&CI);
   return llvm::make_unique<ASTConsumerManagerWrapper>(SymbolIndexMgr);
 }
bool CollectMacrosSourceFileCallbacks::handleBeginSource(clang::CompilerInstance &compilerInstance)
{
    auto callbacks = std::make_unique<CollectMacrosPreprocessorCallbacks>(
                m_symbolEntries,
                m_sourceLocationEntries,
                m_sourceFiles,
                m_usedMacros,
                m_fileStatuses,
                m_sourceDependencies,
                m_filePathCache,
                compilerInstance.getSourceManager(),
                compilerInstance.getPreprocessorPtr());

    compilerInstance.getPreprocessorPtr()->addPPCallbacks(std::move(callbacks));

    return true;
}
Beispiel #14
0
int TypeUtils::sizeOfPointer(const clang::CompilerInstance &ci, clang::QualType qt)
{
    if (!qt.getTypePtrOrNull())
        return -1;
    // HACK: What's a better way of getting the size of a pointer ?
    auto &astContext = ci.getASTContext();
    return astContext.getTypeSize(astContext.getPointerType(qt));
}
Beispiel #15
0
bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) {
    clang::FileID fid = ci.getSourceManager().getFileID(sl) ;
    bool ret = false ;
    if ( ! fid.isInvalid() ) {
        const clang::FileEntry * fe = ci.getSourceManager().getFileEntryForID(fid) ;
        if ( fe != NULL ) {
            char * resolved_path = almostRealPath( fe->getName() ) ;
            if ( resolved_path != NULL ) {
                if ( hsd.isPathInUserOrTrickDir(resolved_path)) {
                    ret = true ;
                }
                free(resolved_path) ;
            }
        }
    }
    return ret ;
}
Beispiel #16
0
void Decl::set_location(clang::CompilerInstance &ci, const clang::Decl *d) {
    clang::SourceLocation sloc = d->getLocation();

    if(sloc.isValid()) {
        std::string loc = sloc.printToString(ci.getSourceManager());
        set_location(loc);
    }
}
	// Executes CodeGenAction and returns the pointer (caller should own and delete it)
	// Returns NULL on failure (in case of any compiler errors etc.)
	clang::CodeGenAction* emitLLVM(const char* szSourceCodeFilePath)
	{
		// create the compiler instance setup for this file as the main file
		prepareCompilerforFile(szSourceCodeFilePath);

		// Create an action and make the compiler instance carry it out
		clang::CodeGenAction *Act = new clang::EmitLLVMOnlyAction();
		if (!m_CompilerInstance.ExecuteAction(*Act))
			return NULL;

		return Act;
	}
Beispiel #18
0
void c2ffi::process_macros(clang::CompilerInstance &ci, std::ostream &os) {
    using namespace c2ffi;

    clang::SourceManager &sm = ci.getSourceManager();
    clang::Preprocessor &pp = ci.getPreprocessor();

    for(clang::Preprocessor::macro_iterator i = pp.macro_begin();
        i != pp.macro_end(); i++) {
        const clang::MacroInfo *mi = (*i).second->getMacroInfo();
        const clang::SourceLocation sl = mi->getDefinitionLoc();
        std::string loc = sl.printToString(sm);
        const char *name = (*i).first->getNameStart();

        if(mi->isBuiltinMacro() || loc.substr(0,10) == "<built-in>") {
        } else if(mi->isFunctionLike()) {
        } else if(best_guess type = macro_type(pp, name, mi)) {
            os << "/* " << loc << " */" << std::endl;
            os << "#define " << name << " "
                      << macro_to_string(pp, mi)
                      << std::endl << std::endl;
        }
    }


    for(clang::Preprocessor::macro_iterator i = pp.macro_begin();
        i != pp.macro_end(); i++) {
        clang::MacroInfo *mi = (*i).second->getMacroInfo();
        clang::SourceLocation sl = mi->getDefinitionLoc();
        std::string loc = sl.printToString(sm);
        const char *name = (*i).first->getNameStart();

        if(mi->isBuiltinMacro() || loc.substr(0,10) == "<built-in>") {
        } else if(mi->isFunctionLike()) {
        } else if(best_guess type = macro_type(pp, name, mi)) {
            output_redef(pp, name, mi, type, os);
        }
    }
}
bool WebCLAction::initialize(clang::CompilerInstance &instance)
{
    reporter_ = new WebCLReporter(instance);
    if (!reporter_) {
        llvm::errs() << "Internal error. Can't report errors.\n";
        return false;
    }

    preprocessor_ = new WebCLPreprocessor(instance, extensions_, usedExtensions_);
    if (!preprocessor_) {
        reporter_->fatal("Internal error. Can't create preprocessor callbacks.\n");
        return false;
    }
    clang::Preprocessor &preprocessor = instance.getPreprocessor();
    preprocessor.addPPCallbacks(preprocessor_);

    if (output_) {
        // see clang::PrintPreprocessedAction
        instance.getFrontendOpts().OutputFile = output_;
        out_ = instance.createDefaultOutputFile(true, getCurrentFile());
        if (!out_) {
            reporter_->fatal("Internal error. Can't create output stream.");
            return false;
        }
    }

    const clang::FrontendInputFile &file = getCurrentInput();
    if (file.getKind() != clang::IK_OpenCL) {
        static const char *format =
            "Source file '%0' isn't treated as OpenCL code. Make sure that you "
            "give the '-x cl' option or that the file has a '.cl' extension.\n";
        reporter_->fatal(format) << file.getFile();
        return false;
    }

    return true;
}
Beispiel #20
0
void c2ffi::add_include(clang::CompilerInstance &ci, const char *path, bool is_angled,
                        bool show_error) {
    struct stat buf;
    if(stat(path, &buf) < 0 || !S_ISDIR(buf.st_mode)) {
        if(show_error) {
            std::cerr << "Error: Not a directory: ";
            if(is_angled)
                std::cerr << "-i ";
            else
                std::cerr << "-I ";

            std::cerr << path << std::endl;
            exit(1);
        }

        return;
    }

    const clang::DirectoryEntry *dirent = ci.getFileManager().getDirectory(path);
    clang::DirectoryLookup lookup(dirent, clang::SrcMgr::C_System, false);

    ci.getPreprocessor().getHeaderSearchInfo()
        .AddSearchPath(lookup, is_angled);
}
Beispiel #21
0
TriaAction::CreateAstConsumerResultType TriaAction::CreateASTConsumer (clang::CompilerInstance &ci,
                                                                       llvm::StringRef fileName) {
	ci.getFrontendOpts().SkipFunctionBodies = true;
	ci.getPreprocessor().enableIncrementalProcessing (true);
	ci.getLangOpts().DelayedTemplateParsing = true;
	
	// Enable everything for code compatibility
	ci.getLangOpts().MicrosoftExt = true;
	ci.getLangOpts().DollarIdents = true;
	ci.getLangOpts().CPlusPlus11 = true;
	ci.getLangOpts().GNUMode = true;
	
#if CLANG_VERSION_MINOR < 6
	ci.getLangOpts().CPlusPlus1y = true;
#else
	ci.getLangOpts().CPlusPlus14 = true;
#endif
	
	if (argVerboseTimes) {
		UNIQUE_COMPAT(PreprocessorHooks, hook, new PreprocessorHooks (ci));
		hook->timing ()->name = sourceFileName (this->m_definitions->sourceFiles ());
		this->m_definitions->setTimingNode (hook->timing ());
		ci.getPreprocessor ().addPPCallbacks (MOVE_COMPAT(hook));
	}
	
	// 
	QStringList whichInherit;
	for (const std::string &cur : argInspectBases) {
		whichInherit.append (QString::fromStdString (cur));
	}
	
	// 
	TriaASTConsumer *consumer = new TriaASTConsumer (ci, fileName, whichInherit, argInspectAll,
	                                                 argGlobalClass, this->m_definitions);
	
#if CLANG_VERSION_MINOR < 6
	return consumer;
#else
	return std::unique_ptr< clang::ASTConsumer > (consumer);
#endif
}
Beispiel #22
0
  bool
  BeginSourceFileAction(
      clang::CompilerInstance &CI, StringRef Filename) override {
    xmlDoc = xmlNewDoc(BAD_CAST "1.0");
    xmlNodePtr rootnode = xmlNewNode(nullptr, BAD_CAST "clangAST");
    xmlDocSetRootElement(xmlDoc, rootnode);

    char strftimebuf[BUFSIZ];
    time_t t = time(nullptr);

    strftime(strftimebuf, sizeof strftimebuf, "%F %T", localtime(&t));

    xmlNewProp(rootnode, BAD_CAST "source", BAD_CAST Filename.data());
    xmlNewProp(rootnode,
        BAD_CAST "language",
        BAD_CAST getLanguageString(CI.getLangOpts()));
    xmlNewProp(rootnode, BAD_CAST "time", BAD_CAST strftimebuf);

    return true;
  };
Beispiel #23
0
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);
}
IncludeDirectives::IncludeDirectives(clang::CompilerInstance &CI)
    : CI(CI), Sources(CI.getSourceManager()) {
  // addPPCallbacks takes ownership of the callback
  CI.getPreprocessor().addPPCallbacks(new IncludeDirectivesPPCallback(this));
}
Beispiel #25
0
 BrowserASTConsumer(clang::CompilerInstance &ci, ProjectManager &projectManager, bool WasInDatabase)
     : clang::ASTConsumer(), ci(ci), annotator(projectManager), WasInDatabase(WasInDatabase)
 {
     //ci.getLangOpts().DelayedTemplateParsing = (true);
     ci.getPreprocessor().enableIncrementalProcessing();
 }
Beispiel #26
0
bool QtUtils::isTooBigForQList(clang::QualType qt, const clang::CompilerInstance &ci)
{
    return (int)ci.getASTContext().getTypeSize(qt) <= TypeUtils::sizeOfPointer(ci, qt);
}
 std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance & compiler, llvm::StringRef inFile )
 {
   return std::unique_ptr< clang::ASTConsumer >( new MetricsCalculatorASTConsumer( &compiler.getASTContext() ) );
 }
Beispiel #28
0
	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()));
	}
Beispiel #29
0
 virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
     clang::CompilerInstance &Compiler, llvm::StringRef InFile)
 {
    return std::unique_ptr<clang::ASTConsumer>(
        new FindNamedClassConsumer(&Compiler.getASTContext()));
 }
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);
}