Beispiel #1
0
pascal_type
flatten_type (pascal_type	type,
	      void *		type_ptr,
	      void **		type_ptr_ptr)
{
  pascal_type flattened_type = type;
  if (type == NAMED_TYPE_NODE)
    {
      if (NT->name->s_kind != TYPE_IDENTIFIER)
	{
	  c4p_error ("`%s' is not a type identifier", NT->name->s_repr);
	}
      flattened_type = NT->name->s_type;
      if (type_ptr_ptr != 0)
	{
	  *type_ptr_ptr = NT->name->s_type_ptr;
	}
    }
  else if (type == ARRAY_NODE)
    {
      ARR->component_type =
	flatten_type(ARR->component_type, ARR->component_type_ptr,
		     &ARR->component_type_ptr);
    }
  else if (type == POINTER_NODE)
    {
      PTR->component_type =
	flatten_type(PTR->component_type, PTR->component_type_ptr,
		     &PTR->component_type_ptr);
      PTR->array_node_ptr->component_type = PTR->component_type;
      PTR->array_node_ptr->component_type_ptr = PTR->component_type_ptr;
    }
  else
    {
      if (type == FILE_NODE)
	{
	  FIL->type = flatten_type(FIL->type, FIL->type_ptr, &FIL->type_ptr);
	}
    }
  return (flattened_type);
}
Beispiel #2
0
void
declare_var_list (declarator_node *	vars,
		  unsigned		kind,
		  unsigned		block_level,
		  pascal_type		type,
		  void *		type_ptr)
{
  declarator_node * start = vars;
  const char * translated_type = translate_type(type, type_ptr);
  out_s (" ");
  while (vars != 0)
    {
      if (is_fast_var (vars->name->s_repr))
	{
	  vars->name->s_flags |= S_FAST;
	}
      if (type == POINTER_NODE)
	{
	  out_s ("*");
	}
      if (block_level == 0 && kind == VARIABLE_IDENTIFIER)
	{
	  out_s (var_name_prefix.c_str());
	}
      out_s (vars->name->s_repr);
      if (type == ARRAY_NODE)
	{
	  out_dimensions (reinterpret_cast<array_node*>(type_ptr));
	}
      vars->name->s_translated_type = translated_type;
      vars = vars->next;
      if (vars != 0)
	{
	  out_s (", ");
	}
    }
  type = flatten_type(type, type_ptr, &type_ptr);
  vars = start;
  while (vars != 0)
    {
      vars->name = define_symbol(vars->name, kind, block_level,
				 type, type_ptr, 0);
      vars = vars->next;
    }
}
Beispiel #3
0
static int svgx_all(svgx_opt_t opt, svg_list_t *list)
{
  /* coerce explicit */

  if (svg_list_iterate(list, svg_explicit2, NULL) != 0)
    {
      btrace("failed coerce explicit");
      return 1;
    }

  /* coerce flat */

  if (flatten_type(opt.type))
    {
      if (svg_list_iterate(list, 
			   (int (*)(svg_t*, void*))svg_flatten2, 
			   &(opt.format.alpha)) != 0)
	{
	  btrace("failed coerce explicit");
	  return 1;
	}
    }

  int (*dump)(svg_t*, void*);

  if ((dump = (int (*)(svg_t*, void*))dump_type(opt.type)) == NULL) 
    return 1;

  if (opt.verbose)
    printf("converting all gradients:\n");

  if (svg_list_iterate(list, dump, &opt) != 0)
    {
      btrace("failed writing all gradients");
      return 1;
    }

  return 0;
}
Beispiel #4
0
static int svgx_single(svgx_opt_t opt, svg_t *svg)
{
  const char *file;

  if (svg_explicit(svg) != 0)
    {
      btrace("failed adding explicit stops");
      return 1;
    }

  file = opt.output.file;

  if (flatten_type(opt.type))
    {
      if (svg_flatten(svg, opt.format.alpha) != 0)
	{
	  btrace("failed to flatten transparency");
	  return 1;
	}
    }

  dump_f dump;

  if ((dump = dump_type(opt.type)) == NULL)
    return 1;

  if (dump(svg, &opt) != 0)
    {
      btrace("failed conversion");
      return 1;
    }

  if (opt.verbose)
    printf("wrote %s to %s\n",
	   (opt.name ? opt.name : "gradient"),
	   (file ? file : "<stdout>"));
  
  return 0;
}
Beispiel #5
0
void
generate_routine_head (prototype_node * proto)
{
  out_s ("\n");
  out_form ("%s%s\n%s%s (",
	    ((class_name_scope.length() > 0
	      && proto->result_type != 0
	      && ! (proto->result_type->s_flags & S_PREDEFINED))
	     ? class_name_scope.c_str()
	     : ""),
	    (proto->result_type == 0
	     ? "void"
	     : (proto->result_type->s_translated_type
		? proto->result_type->s_translated_type
		: proto->result_type->s_repr)),
	    class_name_scope.c_str(),
	    proto->name->s_repr);
  redir_file (H_FILE_NUM);
  out_form ("%s %s (",
	    (proto->result_type == 0
	     ? "void"
	     : (proto->result_type->s_translated_type
		? proto->result_type->s_translated_type
		: proto->result_type->s_repr)),
	    proto->name->s_repr);
  redir_file (C_FILE_NUM);
  parameter_node * par = proto->formal_parameter;
  if (par == 0)
    {
      out_s ("void)\n");
      redir_file (H_FILE_NUM);
      out_s ("void);\n");
      redir_file (C_FILE_NUM);
      return;
    }
  symbol_t * type_symbol;
  symbol_t * param_symbol;
  while (par != 0)
    {
      type_symbol = par->type_symbol;
      param_symbol = new_symbol_instance (par->name);
      param_symbol->s_kind = PARAMETER_IDENTIFIER;
      param_symbol->s_block_level = 1;
      param_symbol->s_type = type_symbol->s_type;
      param_symbol->s_type_ptr = type_symbol->s_type_ptr;
      param_symbol->s_type = flatten_type(param_symbol->s_type,
					  param_symbol->s_type_ptr,
					  &param_symbol->s_type_ptr);
      out_form ("%s %s%s",
		(type_symbol->s_translated_type
		 ? type_symbol->s_translated_type
		 : type_symbol->s_repr),
		par->by_reference ? "& " : "",
		par->name);
      redir_file (H_FILE_NUM);
      out_form ("%s %s%s",
		(type_symbol->s_translated_type
		 ? type_symbol->s_translated_type
		 : type_symbol->s_repr),
		par->by_reference ? "& " : "",
		par->name);
      redir_file (C_FILE_NUM);
      if (par->by_reference)
	{
	  param_symbol->s_flags |= S_BY_REFERENCE;
	}
      par = par->next;
      if (par != 0)
	{
	  out_s (",  ");
	  redir_file (H_FILE_NUM);
	  out_s (",  ");
	  redir_file (C_FILE_NUM);
	}
    }

  out_s (")\n");
  redir_file (H_FILE_NUM);
  out_s (");\n");
  redir_file (C_FILE_NUM);
}
Beispiel #6
0
const char *
translate_type (pascal_type	type,
		const void *	type_ptr)
{
  const char * ret = 0;
  switch (type)
    {
    case NAMED_TYPE_NODE:
      ret = (NT->name->s_translated_type
	     ? NT->name->s_translated_type
	     : NT->name->s_repr);
      out_s (ret);
      break;
    case BOOLEAN_TYPE:
      NT->name->s_repr = "C4P_boolean";
      out_s ("C4P_boolean");
      break;
    case CHARACTER_TYPE:
      NT->name->s_repr = "char";
      out_s ("char");
      break;
    case INTEGER_TYPE:
      NT->name->s_repr = "C4P_integer";
      out_s ("C4P_integer");
      break;
    case LONG_INTEGER_TYPE:
      NT->name->s_repr = "C4P_longinteger";
      out_s ("C4P_longinteger");
      break;
    case REAL_TYPE:
      NT->name->s_repr = "float";
      out_s ("float");
      break;
    case LONG_REAL_TYPE:
      NT->name->s_repr = "double";
      out_s ("double");
      break;
    case ARRAY_NODE:
      ret = translate_type (ARR->component_type, ARR->component_type_ptr);
      break;
    case POINTER_NODE:
#if 1
      ret = translate_type (PTR->component_type, PTR->component_type_ptr);
#else
      ret = translate_type (PTR->component_type, PTR->component_type_ptr);
#endif
      break;
    case SUBRANGE_NODE:
      ret = subrange (SUB->lower_bound, SUB->upper_bound);
      out_s (ret);
      break;
    case RECORD_NODE:
      out_s ("struct {\n");
      ++ curly_brace_level;
      translate_type (FIELD_LIST_NODE, REC->field_list);
      -- curly_brace_level;
      out_s ("}");
      break;
    case FIELD_LIST_NODE:
      if (FL->fixed_part != 0)
	{
	  translate_type (RECORD_SECTION_NODE, FL->fixed_part);
	}
      if (FL->variant_part != 0)
	{
	  translate_type (VARIANT_NODE, FL->variant_part);
	}
      break;
    case RECORD_SECTION_NODE:
      declare_var_list (RS->name, FIELD_IDENTIFIER, UINT_MAX,
			RS->type, RS->type_ptr);
      out_s (";\n");
      if (RS->next != 0)
	{
	  translate_type (RECORD_SECTION_NODE, RS->next);
	}
      break;
    case VARIANT_NODE:
      out_s ("union {\n");
      ++ curly_brace_level;
      if (V->variant_field_list != 0)
	{
	  translate_type (VARIANT_FIELD_LIST_NODE, V->variant_field_list);
	}
      -- curly_brace_level;
      out_form ("} %s;\n", V->pseudo_name->s_repr);
      break;
    case VARIANT_FIELD_LIST_NODE:
      if (VFL->pseudo_name != 0)
	{
	  out_s ("struct {\n");
	  ++ curly_brace_level;
	}
      if (VFL->fixed_part != 0)
	{
	  translate_type (RECORD_SECTION_NODE, VFL->fixed_part);
	}
      if (VFL->variant_part != 0)
	{
	  translate_type (VARIANT_NODE, VFL->variant_part);
	}
      if (VFL->pseudo_name != 0)
	{
	  -- curly_brace_level;
	  out_form ("} %s;\n", VFL->pseudo_name->s_repr);
	}
      if (VFL->next != 0)
	{
	  translate_type (VARIANT_FIELD_LIST_NODE, VFL->next);
	}
      break;
    case FILE_NODE:
      if (FIL->type == CHARACTER_TYPE
	  || (FIL->type == NAMED_TYPE_NODE
	      && (((named_type_node *) FIL->type_ptr)->name->s_type
		  == CHARACTER_TYPE)))
	{
	  out_s ("C4P_text");
	}
      else
	{
	  out_s ("C4P_FILE_STRUCT(");
	  translate_type (FIL->type, FIL->type_ptr);
	  out_s (")");
	}
      FIL->type = flatten_type(FIL->type, FIL->type_ptr, &FIL->type_ptr);
      break;
    default:
      c4p_error ("internal error: translate_type: unknown node type: %u", type);
    }
  return (ret);
}