bool cpp_languaget::parse( const std::string &path, message_handlert &message_handler) { // store the path parse_path=path; // preprocessing std::ostringstream o_preprocessed; internal_additions(o_preprocessed); if(preprocess(path, o_preprocessed, message_handler)) return true; std::istringstream i_preprocessed(o_preprocessed.str()); // parsing cpp_parser.clear(); cpp_parser.filename=path; cpp_parser.in=&i_preprocessed; cpp_parser.set_message_handler(&message_handler); cpp_parser.grammar=cpp_parsert::LANGUAGE; if(config.ansi_c.os==configt::ansi_ct::OS_WIN32) cpp_parser.mode=cpp_parsert::MSC; else cpp_parser.mode=cpp_parsert::GCC; cpp_scanner_init(); bool result=cpp_parser.parse(); // save result cpp_parse_tree.swap(cpp_parser.parse_tree); // save some memory cpp_parser.clear(); return result; }
bool cpp_languaget::parse( std::istream &instream, const std::string &path, message_handlert &message_handler) { // store the path parse_path=path; // preprocessing std::ostringstream o_preprocessed; cpp_internal_additions(o_preprocessed); if(preprocess(instream, path, o_preprocessed, message_handler)) return true; std::istringstream i_preprocessed(o_preprocessed.str()); // parsing cpp_parser.clear(); cpp_parser.filename=path; cpp_parser.in=&i_preprocessed; cpp_parser.set_message_handler(message_handler); cpp_parser.grammar=cpp_parsert::LANGUAGE; switch(config.ansi_c.mode) { case configt::ansi_ct::MODE_CODEWARRIOR: cpp_parser.mode=cpp_parsert::CW; break; case configt::ansi_ct::MODE_VISUAL_STUDIO: cpp_parser.mode=cpp_parsert::MSC; break; case configt::ansi_ct::MODE_ANSI: cpp_parser.mode=cpp_parsert::ANSI; break; case configt::ansi_ct::MODE_GCC: cpp_parser.mode=cpp_parsert::GCC; break; case configt::ansi_ct::MODE_ARM: cpp_parser.mode=cpp_parsert::ARM; break; default: assert(false); } cpp_scanner_init(); bool result=cpp_parser.parse(); // save result cpp_parse_tree.swap(cpp_parser.parse_tree); // save some memory cpp_parser.clear(); return result; }