Пример #1
0
static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
  using namespace cc1options;
  Opts.Sysroot = getLastArgValue(Args, OPT_isysroot, "/");
  Opts.Verbose = Args.hasArg(OPT_v);
  Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
  Opts.UseStandardIncludes = !Args.hasArg(OPT_nostdinc);
  Opts.ResourceDir = getLastArgValue(Args, OPT_resource_dir);

  // Add -I... and -F... options in order.
  for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F),
         ie = Args.filtered_end(); it != ie; ++it)
    Opts.AddPath(it->getValue(Args), frontend::Angled, true,
                 /*IsFramework=*/ it->getOption().matches(OPT_F));

  // Add -iprefix/-iwith-prefix/-iwithprefixbefore options.
  llvm::StringRef Prefix = ""; // FIXME: This isn't the correct default prefix.
  for (arg_iterator it = Args.filtered_begin(OPT_iprefix, OPT_iwithprefix,
                                             OPT_iwithprefixbefore),
         ie = Args.filtered_end(); it != ie; ++it) {
    if (it->getOption().matches(OPT_iprefix))
      Prefix = it->getValue(Args);
    else if (it->getOption().matches(OPT_iwithprefix))
      Opts.AddPath(Prefix.str() + it->getValue(Args),
                   frontend::System, false, false);
    else
      Opts.AddPath(Prefix.str() + it->getValue(Args),
                   frontend::Angled, false, false);
  }

  for (arg_iterator it = Args.filtered_begin(OPT_idirafter),
         ie = Args.filtered_end(); it != ie; ++it)
    Opts.AddPath(it->getValue(Args), frontend::After, true, false);
  for (arg_iterator it = Args.filtered_begin(OPT_iquote),
         ie = Args.filtered_end(); it != ie; ++it)
    Opts.AddPath(it->getValue(Args), frontend::Quoted, true, false);
  for (arg_iterator it = Args.filtered_begin(OPT_isystem),
         ie = Args.filtered_end(); it != ie; ++it)
    Opts.AddPath(it->getValue(Args), frontend::System, true, false);

  // FIXME: Need options for the various environment variables!
}
Пример #2
0
int main()
{
    //string a;
    //raw_string_ostream ost(a);
    const DiagnosticOptions diagOptions;
    TextDiagnosticPrinter *tdp = 
        new TextDiagnosticPrinter(outs(), diagOptions, true);//, dops);
	LangOptions lang;

    DiagnosticIDs *diagID;
    const llvm::IntrusiveRefCntPtr< DiagnosticIDs > Diags;
	Diagnostic diag(Diags, tdp, false);
    FileSystemOptions fsOptions;
	FileManager fm(fsOptions);
	SourceManager sm(diag, fm);

    //tut3
    HeaderSearchOptions HSOpts;
    HSOpts.AddPath("/usr/include/linux/", frontend::System, false, false, true); // for stddef.h
    HSOpts.AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/", frontend::System, false, false, true); // for stdarg.h
	HeaderSearch headers(fm);

    TargetOptions tarOptions;
    tarOptions.Triple = LLVM_HOSTTRIPLE;
	TargetInfo *ti = TargetInfo::CreateTargetInfo(diag, tarOptions);

    //tut3
    ApplyHeaderSearchOptions( headers, HSOpts, lang, ti->getTriple());

	Preprocessor pp(diag, lang, *ti, sm, headers);



//tut2---------------------------------------------------------------
    const FileEntry *file = fm.getFile("input01.c");
    sm.createMainFileID(file);
    pp.EnterMainSourceFile();

    Token Tok;

    do {
        pp.Lex(Tok);
        if(diag.hasErrorOccurred())
            break;
        pp.DumpToken(Tok);
        std::cerr << std::endl;
    } while(Tok.isNot(tok::eof));
//end of tut2---------------------------------------------------------------

//tut4---------------------------------------------------------------
    IdentifierTable tab(lang);

    SelectorTable sels;
    Builtin::Context builtins(*ti);
    unsigned size = 0;

    ASTContext ctxt(lang, sm, *ti, tab, sels, builtins, size);
    ASTConsumer consumer;
    CodeCompleteConsumer *codeCompleter;
    MySemaAction sema(pp, ctxt, consumer, false, codeCompleter);

    Parser p(pp, sema);
    p.ParseTranslationUnit();
    tab.PrintStats();
//end of tut4---------------------------------------------------------------

    //DeclSpec DS;
    //Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
    //sema.ActOnDeclarator(p.getCurScope(), DeclaratorInfo);

	return 0;
}