Branch: Tag:

2016-09-29

2016-09-29 14:11:23 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler [cpp]: Reduced code duplication somewhat.

Add a flags argument to find_end_of_string() and join it
and find_end_of_string2().

1276:    return pos + 2;   }    - static ptrdiff_t find_end_of_string2( struct cpp *this, const PCHARP data, -  ptrdiff_t len, ptrdiff_t pos) - { -  while(1) -  { -  if(pos>=len) -  { -  cpp_error(this,"End of file in string."); -  break; -  } -  switch(INDEX_PCHARP(data,pos++)) -  { -  case '\n': -  this->current_line++; -  PUTNL(); -  continue; -  case '"': return pos; -  case '\\': -  if(INDEX_PCHARP(data,pos)=='\n') { -  this->current_line++; -  PUTNL(); -  } -  else if ((INDEX_PCHARP(data,pos) == '\r') && (INDEX_PCHARP(data,pos+1) == '\n')) { -  this->current_line++; -  pos++; -  PUTNL(); -  } -  pos++; -  } -  } -  return pos; - } -  -  +    static ptrdiff_t find_end_of_string( struct cpp *this, const PCHARP data, -  ptrdiff_t len, ptrdiff_t pos) +  ptrdiff_t len, ptrdiff_t pos, +  int flags)   {    while(1)    {
1323:    switch(INDEX_PCHARP(data,pos++))    {    case '\n': +  if (flags & CPP_END_AT_NEWLINE) {    cpp_error(this,"Newline in string."); -  +  }    this->current_line++;    PUTNL();    break;
1408:    {    case '\n': PUTNL(); this->current_line++; break;    case '\'': pos=find_end_of_char(this,data,len,pos); break; -  case '"': pos=find_end_of_string(this,data,len,pos); break; +  case '"': pos=find_end_of_string(this,data,len,pos,CPP_END_AT_NEWLINE); break;    case '(': pos=find_end_parenthesis(this, data, len, pos); break;    case '{': pos=find_end_brace(this, data, len, pos); break;    case ')': return pos;
1445:    {    case '\n': PUTNL(); this->current_line++; break;    case '\'': pos=find_end_of_char(this,data,len,pos); break; -  case '"': pos=find_end_of_string(this,data,len,pos); break; +  case '"': pos=find_end_of_string(this,data,len,pos,CPP_END_AT_NEWLINE); break;    case '{': pos=find_end_brace(this, data, len, pos); break;    case '}': return pos;    case '/':
1987:      #define CHECK_WORD(X,LEN) (begins_with(X,ADD_PCHARP(data,pos),(LEN),len-pos,1))   #define GOBBLE_WORD(X) (CHECK_WORD(X,NELEM(X)) ? (pos+=NELEM(X)),1 : 0) - #define FIND_END_OF_STRING() (pos=find_end_of_string(this,data,len,pos)) - #define FIND_END_OF_STRING2() (pos=find_end_of_string2(this,data,len,pos)) + #define FIND_END_OF_STRING() (pos=find_end_of_string(this,data,len,pos,CPP_END_AT_NEWLINE)) + #define FIND_END_OF_STRING2() (pos=find_end_of_string(this,data,len,pos,0))   #define FIND_END_OF_CHAR() (pos=find_end_of_char(this,data,len,pos))   #define FIND_EOL_PRETEND() (pos=find_end_of_line(this,data,len,pos,0))   #define FIND_EOL() (pos=find_end_of_line(this,data,len,pos,1))