1

我正在尝试使用 GCC 3.4.6 和 Boost 1.43 编译以下看似简单的代码,它会产生内部编译器错误:

#include <string>
#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/qi.hpp>

namespace lex    = boost::spirit::lex;
namespace qi     = boost::spirit::qi;

typedef lex::lexertl::token<std::string::iterator> TokenT;
typedef lex::lexertl::actor_lexer<TokenT> LexerT;

template <typename LexerT>
struct Tokens: public lex::lexer<LexerT>
{};

int main()
{
   typedef Tokens<LexerT>::iterator_type IteratorT;
   qi::rule<IteratorT, int> expression;

   expression = (qi::int_ >> qi::int_) [ qi::_val = qi::_1 ];
}

生成的错误:

.../boost/mpl/aux_/preprocessed/gcc/template_arity.hpp:83: internal compiler error: in lookup_member, at cp/search.c:1300

最后一行main()是产生这个错误。通过让expression规则在 astd::string::iterator而不是IteratorT.

非常感谢在仍然使用词法分析器的同时修复错误的任何帮助。

谢谢!

4

1 回答 1

1

你错过了括号:

qi::rule<IteratorT, int()> expression;

这可能会修复编译错误(尽管我无法检查,因为 gcc、clang 和 msvc 都愉快地编译了它)


您可能希望减少编译器压力:

  • 增加可用内存
  • 减少限制(见下文)
  • 禁用调试信息 (-g0)
  • 和优化(-O0;或者,优化大小 -Os)

在那个地区可能更多。

限制

我做了一个简单的

grep -EoRh '\<\w+_LIMIT\>' ~/custom/boost_1_50_0/boost/spirit/home/ -h | sort -u

获取可能定义的列表,并基于它进行以下更改:

#ifdef LEAN
#define PHOENIX_ACTOR_LIMIT      3 // boost 1_50 default: 10
#define PHOENIX_ARG_LIMIT        5 // boost 1_50 default: 10
#define PHOENIX_CATCH_LIMIT      1 // boost 1_50 default:  9
#define PHOENIX_COMPOSITE_LIMIT  5 // boost 1_50 default: 10
#define PHOENIX_DYNAMIC_LIMIT    1 // boost 1_50 default: 10
#define PHOENIX_LIMIT            5 // boost 1_50 default: 10
#define PHOENIX_LOCAL_LIMIT      3 // boost 1_50 default: 10
#define PHOENIX_MEMBER_LIMIT     3 // boost 1_50 default:  8
#define SPIRIT_ARGUMENTS_LIMIT   5 // boost 1_50 default: 10
#define SPIRIT_ATTRIBUTES_LIMIT  5 // boost 1_50 default: 10
#endif

#include <string>
#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/phoenix.hpp>

namespace lex    = boost::spirit::lex;
namespace qi     = boost::spirit::qi;
namespace phx    = boost::phoenix;

struct funcImpl
{
   template <typename T>
   struct result { typedef int type; };

   template <typename T>
   int operator()(T& x) const {
      return 0;
   }
};

typedef lex::lexertl::token<std::string::iterator> TokenT;
typedef lex::lexertl::actor_lexer<TokenT> LexerT;

template <typename LexerT>
struct Tokens: public lex::lexer<LexerT>
{};

int main()
{
   //typedef Tokens<LexerT>::iterator_type IteratorT;
   typedef char* IteratorT;
   qi::rule<IteratorT, int()> expression;

   phx::function<funcImpl> func = funcImpl();
   expression = (qi::int_ >> qi::int_) [ qi::_val = func(qi::_1) ];


   std::cout   << "#define PHOENIX_ACTOR_LIMIT "                       << PHOENIX_ACTOR_LIMIT                       << '\n';
   std::cout   << "#define PHOENIX_ARG_LIMIT "                         << PHOENIX_ARG_LIMIT                         << '\n';
   std::cout   << "#define PHOENIX_CATCH_LIMIT "                       << PHOENIX_CATCH_LIMIT                       << '\n';
   std::cout   << "#define PHOENIX_COMPOSITE_LIMIT "                   << PHOENIX_COMPOSITE_LIMIT                   << '\n';
   std::cout   << "#define PHOENIX_DYNAMIC_LIMIT "                     << PHOENIX_DYNAMIC_LIMIT                     << '\n';
   std::cout   << "#define PHOENIX_LIMIT "                             << PHOENIX_LIMIT                             << '\n';
   std::cout   << "#define PHOENIX_LOCAL_LIMIT "                       << PHOENIX_LOCAL_LIMIT                       << '\n';
   std::cout   << "#define PHOENIX_MEMBER_LIMIT "                      << PHOENIX_MEMBER_LIMIT                      << '\n';
   std::cout   << "#define SPIRIT_ARGUMENTS_LIMIT "                    << SPIRIT_ARGUMENTS_LIMIT                    << '\n';
   std::cout   << "#define SPIRIT_ATTRIBUTES_LIMIT "                   << SPIRIT_ATTRIBUTES_LIMIT                   << '\n';
   //std::cout << "#define BOOST_PHOENIX_LIMIT "                       << BOOST_PHOENIX_LIMIT                       << '\n';
   //std::cout << "#define BOOST_SPIRIT_CLOSURE_LIMIT "                << BOOST_SPIRIT_CLOSURE_LIMIT                << '\n';
   //std::cout << "#define BOOST_SPIRIT_GRAMMAR_STARTRULE_TYPE_LIMIT " << BOOST_SPIRIT_GRAMMAR_STARTRULE_TYPE_LIMIT << '\n';
   //std::cout << "#define BOOST_SPIRIT_RULE_SCANNERTYPE_LIMIT "       << BOOST_SPIRIT_RULE_SCANNERTYPE_LIMIT       << '\n';
   //std::cout << "#define BOOST_SPIRIT_SELECT_LIMIT "                 << BOOST_SPIRIT_SELECT_LIMIT                 << '\n';
   //std::cout << "#define BOOST_SPIRIT_SWITCH_CASE_LIMIT "            << BOOST_SPIRIT_SWITCH_CASE_LIMIT            << '\n';
   //std::cout << "#define PHOENIX_CONSTRUCT_LIMIT "                   << PHOENIX_CONSTRUCT_LIMIT                   << '\n';
   //std::cout << "#define SPIRIT_CLOSURE_LIMIT "                      << SPIRIT_CLOSURE_LIMIT                      << '\n';
}

现在,发生以下大小变化(在 LoC 预处理中):

sehe@mint12:/tmp$ g++ -g0 -O0 -I /home/sehe/custom/boost_1_50_0/ test.cpp -E | wc -l
193011
sehe@mint12:/tmp$ g++ -g0 -O0 -I ./boost_1_43_0/ test.cpp -DLEAN -E | wc -l
168862

基本上,代码行减少了 10% 以上。它可能会有所帮助。

于 2012-07-17T21:39:10.687 回答