Beispiel #1
0
static void
emit(stmt_ty *that)
{
    stmt_if_ty      *this;
    size_t          j;

    trace(("if::emit()\n{\n"));
    this = (stmt_if_ty *)that;
    emit_line_number
    (
        this->condition->list[0]->line_number,
        this->condition->list[0]->file_name
    );
    emit_str("#if");
    for (j = 0; j < this->condition->length; ++j)
    {
        emit_char(' ');
        emit_string(this->condition->list[j]->text);
    }
    emit_char('\n');

    stmt_emit(this->then_clause);
    emit_bol();

    if (this->else_clause)
    {
        emit_str("#else\n");
        stmt_emit(this->else_clause);
        emit_bol();
    }
    emit_str("#endif\n");
    trace(("}\n"));
}
Beispiel #2
0
 void Prepreprocess::exact_quote(const std::string &line)  
 {
   int end=line.length();
   state=START;
   for (int pos=0; pos<end; ++pos) emit_char(line[pos]);
   emit_end();
 }
Beispiel #3
0
/* A version of fputs that knows about the __m65x_char_to_file hack.  */
static void
sfputs (const char *str, FILE *f)
{
  const char *iter;
  for (iter = str; *iter; iter++)
    emit_char (*iter, f);
}
Beispiel #4
0
static int print_sdec (FILE *f, long val)
{
  int printed = 0;
  if (val < 0)
    {
      emit_char ('-', f);
      printed += print_udec (f, -val) + 1;
    }
  else
    printed += print_udec (f, val);

  return printed;
}
Beispiel #5
0
  void Prepreprocess::magic_quote(const std::string &line)
  {
    int end=line.length();
    bool use_suffix=true;

    state=START;

    for (int pos=0; pos<end; ++pos) {
      if (line[pos]=='$') {
	if (pos == end-1) {
	  use_suffix=false;
	  break;
	} else {
	  if (id0(line[pos+1])) {
	    ++pos;
	    int begin=pos;
	    while (pos < end && id1(line[pos])) ++pos;
	    emit_expression(line.substr(begin,(pos-begin)));
	    --pos;
	    continue;
	  }
	  if (line[pos+1] == '(') {
	    ++pos;
	    int begin=pos;
	    int parens=0;
	    while (pos < end) {
	      if (line[pos]=='(') ++parens;
	      if (line[pos]==')') {--parens; if (parens==0) { ++pos; break; } }
	      ++pos;
	    }
	    emit_expression(line.substr(begin,(pos-begin)));
	    --pos;
	    continue;
	  }
	  if (line[pos+1]=='$') {
	    ++pos;
	  }
	}
      }
      emit_char(line[pos]);
    }
    emit_end(use_suffix);
  }
Beispiel #6
0
static int print_udec (FILE *f, unsigned long val)
{
  char digits[10];
  int c = 0;
  int printed = 0;
  
  do
    {
      digits[c++] = val % 10;
      val = val / 10;
    }
  while (val > 0);

  for (--c; c >= 0; c--)
    {
      emit_char (digits[c] + '0', f);
      printed++;
    }

  return printed;
}
Beispiel #7
0
static int print_hex (FILE *f, unsigned long val)
{
  unsigned char seen_nonzero = 0;
  int printed = 0;
  int i;
  
  for (i = 7; i >= 0; i--)
    {
      unsigned char nybble = (val >> 28) & 0xf;
      
      if (nybble > 0 || i == 0 || seen_nonzero)
        {
	  emit_char (nybble < 10 ? nybble + '0' : nybble - 10 + 'a', f);
          printed++;
        }
      
      if (nybble != 0)
        seen_nonzero = 1;

      val <<= 4;
    }

  return printed;
}
Beispiel #8
0
int vfprintf (FILE *f, const char *fmt, va_list ap)
{
  int printed = 0;

  while (*fmt)
    {
      if (*fmt == '%')
        {
	retry:
	  switch (*++fmt)
	    {
            case 'c':
              {
                int val = va_arg (ap, int);
                emit_char (val, f);
                printed++;
              }
              break;

	    case 'l':
	      {
	        switch (*++fmt)
		  {
		  case 'd':
		    {
		      long val = va_arg (ap, long);
		      printed += print_sdec (f, val);
		    }
		    break;

		  case 'u':
		    {
		      unsigned long val = va_arg (ap, unsigned long);
		      printed += print_udec (f, val);
		    }
		    break;

		  case 'x':
		    {
		      unsigned long val = va_arg (ap, unsigned long);
		      printed += print_hex (f, val);
		    }
		    break;

		  default:
		    ;
		  }
	      }
	      break;

	    case 'd':
	      {
	        int val = va_arg (ap, int);
		printed += print_sdec (f, val);
	      }
	      break;
	      
	    case 'u':
	      {
	        unsigned int val = va_arg (ap, unsigned int);
		printed += print_udec (f, val);
	      }
	      break;

	    case 's':
	      {
		char *str = va_arg (ap, char *);
		sfputs (str, f);
                printed += strlen (str);
	      }
	      break;

	    case 'p':
	    case 'x':
	      {
	        unsigned int val = va_arg (ap, unsigned int);
		printed += print_hex (f, val);
	      }
	      break;

	    case '%':
	      emit_char ('%', f);
              printed++;
	      break;

#ifdef M65X_FLOAT_PRINT
	    case 'f':
	      {
		float val = va_arg (ap, double);
		printed += print_float (f, val);
	      }
	      break;
#endif
	    default:
	      /* Just skip unknown % formatting codes.  */
	      goto retry;
	    }
	}
      else
        {