@@ -3314,8 +3314,10 @@ static std::string getTimeDefine(const struct tm *timep)
33143314 return std::string (" \" " ).append (buf).append (" \" " );
33153315}
33163316
3317- void simplecpp::preprocess (simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
3317+ static void simplecppPreprocess (simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond, simplecpp::MacroMap& macros )
33183318{
3319+ using namespace simplecpp ;
3320+
33193321#ifdef SIMPLECPP_WINDOWS
33203322 if (dui.clearIncludeCache )
33213323 nonExistingFilesCache.clear ();
@@ -3347,7 +3349,6 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33473349 std::vector<std::string> dummy;
33483350
33493351 const bool hasInclude = isCpp17OrLater (dui);
3350- MacroMap macros;
33513352 for (std::list<std::string>::const_iterator it = dui.defines .begin (); it != dui.defines .end (); ++it) {
33523353 const std::string ¯ostr = *it;
33533354 const std::string::size_type eq = macrostr.find (' =' );
@@ -3792,6 +3793,64 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37923793 }
37933794}
37943795
3796+ void simplecpp::preprocess (simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
3797+ {
3798+ MacroMap macroMap;
3799+ simplecppPreprocess (output,
3800+ rawtokens,
3801+ files,
3802+ filedata,
3803+ dui,
3804+ outputList,
3805+ macroUsage,
3806+ ifCond,
3807+ macroMap);
3808+ }
3809+
3810+
3811+ std::string simplecpp::precompileHeader (const TokenList &rawtokens, std::vector<std::string> &files, const DUI &dui, OutputList *outputList)
3812+ {
3813+ std::map<std::string, TokenList*> filedata;
3814+ simplecpp::TokenList output (files);
3815+ std::list<simplecpp::MacroUsage> macroUsage;
3816+ std::list<simplecpp::IfCond> ifCond;
3817+ simplecpp::MacroMap macroMap;
3818+ simplecppPreprocess (output,
3819+ rawtokens,
3820+ files,
3821+ filedata,
3822+ dui,
3823+ outputList,
3824+ ¯oUsage,
3825+ &ifCond,
3826+ macroMap);
3827+
3828+ std::string ret;
3829+ unsigned int fileIndex = 0 ;
3830+ unsigned int line = 0 ;
3831+ unsigned int col = 0 ;
3832+ for (const simplecpp::Token *tok = output.cfront (); tok; tok = tok->next ) {
3833+ ret += " \n " ;
3834+ if (tok->location .fileIndex != fileIndex) {
3835+ fileIndex = tok->location .fileIndex ;
3836+ ret += " f" + toString (fileIndex);
3837+ }
3838+ if (tok->location .line != line) {
3839+ line = tok->location .line ;
3840+ ret += " l" + toString (line);
3841+ }
3842+ if (tok->location .col != col) {
3843+ col = tok->location .col ;
3844+ ret += " c" + toString (col);
3845+ }
3846+ ret += " :" + tok->str ();
3847+ }
3848+ for (simplecpp::MacroMap::const_iterator it = macroMap.begin (); it != macroMap.end (); ++it) {
3849+ ret += " \n M" + it->second .name ();
3850+ }
3851+ return ret;
3852+ }
3853+
37953854void simplecpp::cleanup (std::map<std::string, TokenList*> &filedata)
37963855{
37973856 for (std::map<std::string, TokenList*>::iterator it = filedata.begin (); it != filedata.end (); ++it)
0 commit comments