Branch: Tag:

2018-01-15

2018-01-15 14:56:05 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Cpp: Use directive_* functions for #error and #warning.

Replace the hard-coded special cases for #error and #warning
with use of the new generic directive_* API. This should make
the code easier to read, and reduces code-duplication somewhat.

736:    *! @seealso    *! @[#warning]    */ +  PIKEFUN string(0..0) directive_error(int flags, string line) +  { +  struct CPP_struct *this = THIS;    -  +  if (OUTP()) { +  cpp_error_sprintf(this, "%O", Pike_sp - 1); +  } +  push_empty_string(); +  } +    /*! @directive #warning    *!    *! Generate a warning during preprocessing.
754:    *! @seealso    *! @[#error]    */ +  PIKEFUN string(0..0) directive_warning(int flags, string line) +  { +  struct CPP_struct *this = THIS;    -  +  if (OUTP()) { +  cpp_warning(this, "%O", Pike_sp - 1); +  } +  push_empty_string(); +  } +    /*! @directive #include    *!    *! @[#include] is used to insert the contents of another file into
2102:   static const char else_[] = { 'e', 'l', 's', 'e' };   static const char elseif_[] = { 'e', 'l', 's', 'e', 'i', 'f' };   static const char elif_[] = { 'e', 'l', 'i', 'f' }; - static const char error_[] = { 'e', 'r', 'r', 'o', 'r' }; +    static const char define_[] = { 'd', 'e', 'f', 'i', 'n', 'e' };   static const char undef_[] = { 'u', 'n', 'd', 'e', 'f' };   static const char undefine_[] = { 'u', 'n', 'd', 'e', 'f', 'i', 'n', 'e' };
2110:   static const char pragma_[] = { 'p', 'r', 'a', 'g', 'm', 'a' };   static const char pike_[] = { 'p', 'i', 'k', 'e' };   static const char require_[] = { 'r', 'e', 'q', 'u', 'i', 'r', 'e' }; - static const char warning_[] = { 'w', 'a', 'r', 'n', 'i', 'n', 'g' }; +    static const char lsh_[] = { '<', '<' };   static const char rsh_[] = { '>', '>' };   
3753:    }    break;    } -  -  if(GOBBLE_WORD(error_)) -  { -  ptrdiff_t foo; -  -  SKIPSPACE(); -  foo=pos; -  FIND_EOL(); -  if(OUTP()) -  { -  push_string(make_shared_binary_pcharp(ADD_PCHARP(data,foo), pos-foo)); -  cpp_error_sprintf(this, "%O", Pike_sp-1); +     } -  break; -  } -  } +     goto unknown_preprocessor_directive;       case 'd': /* define */
4177:    }    goto unknown_preprocessor_directive;    } -  case 'w': /* warning */ -  { -  if(GOBBLE_WORD(warning_)) -  { -  ptrdiff_t foo; -  -  SKIPSPACE(); -  foo=pos; -  FIND_EOL(); -  if(OUTP()) -  { -  push_string(make_shared_binary_pcharp(ADD_PCHARP(data,foo), pos-foo)); -  cpp_warning(this, "%O", Pike_sp-1); -  } -  break; -  } -  goto unknown_preprocessor_directive; -  } +     default:    unknown_preprocessor_directive:    {