InitHeaderSearch replacement ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

InitHeaderSearch replacement ?

Parijat Banerjee
I am having problems parsing programs which include standard header files in my own parser using clang libraries . After v2.6 the InitHeaderSearch and InitPreprocessor header files seem to have been replaced. Can someone tell me how do i initialize the preprocessor and headersearch in the current branch (2.8) so that my parser doesn't segfault out when it runs across a standard header inclusion in a test file ? 

Thanks and Regards, 
Parijat 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: InitHeaderSearch replacement ?

Parijat Banerjee
This is my code which I have used to initialize the parser 

llvm::raw_ostream *os = NULL;
 llvm::raw_ostream *ps = NULL;
 
 const DiagnosticOptions diagop;
 bool OwnsOutputStream=false;
 TextDiagnosticPrinter diagClient(*os,diagop,OwnsOutputStream);
 Diagnostic diags(&diagClient);
 LangOptions opts;
 TargetOptions to;
 const std::string& triple = LLVM_HOSTTRIPLE;
 to.ABI="";
 to.CXXABI="itanium";
 to.CPU="";
 to.Features.clear();
 to.Triple=triple;
 TargetInfo* target = TargetInfo::CreateTargetInfo(diags,to);
 SourceManager sm(diags);
 FileManager fm;
 HeaderSearch headers(fm);

 
 HeaderSearchOptions hso;
 hso.ResourceDir="/u/parijat/llvm2/llvm/Release/lib/clang/2.8";
 hso.AddPath(llvm::StringRef("/usr/local/include"),clang::frontend::Angled,true,false,false);
 hso.AddPath(llvm::StringRef("/usr/include"),clang::frontend::Angled,true,false,false);
 ApplyHeaderSearchOptions(headers,hso,opts,llvm::Triple(llvm::sys::getHostTriple()));
 Preprocessor pp(diags,opts,*target,sm,headers);

 PreprocessorOptions ppo;
 FrontendOptions feo;
 InitializePreprocessor(pp,ppo,hso,feo);
 
const FileEntry* File=fm.getFile(argv_[1]);
 if(!File)
   {printf("File doesn't exist!");
    return 0;
  }

   sm.createMainFileID(File);
   Builtin::Context builtins(*target);
   unsigned size;
   ASTConsumer ac;
   ASTContext acx(opts,sm,*target,pp.getIdentifierTable(),pp.getSelectorTable(),pp.getBuiltinInfo(),10000);
   ParseAST(pp,&ac,acx,false);

The above program segfaults out at ParseAST when it runs across a #include ( with stdio or anything else) in the test file. It works fine when no headers are included . 

Can someone please shed some light on where I might be going wrong . 

Thanks a lot in advance 
Parijat  

On Mon, Sep 20, 2010 at 11:48 AM, Parijat Banerjee <[hidden email]> wrote:
I am having problems parsing programs which include standard header files in my own parser using clang libraries . After v2.6 the InitHeaderSearch and InitPreprocessor header files seem to have been replaced. Can someone tell me how do i initialize the preprocessor and headersearch in the current branch (2.8) so that my parser doesn't segfault out when it runs across a standard header inclusion in a test file ? 

Thanks and Regards, 
Parijat 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev