Ejemplo n.º 1
0
Archivo: edit.c Proyecto: albedium/nesc
/* Declare a new temporary that can be assigned a value of type t.
   Place the declaration at the start of block. 
   XXX: See discussion in types.c:tag2ast about the (lack of) correctness of
   this approach.
   Return it's declaration */
data_decl build_declaration(region r, struct environment *e,
			    type t, const char *name, expression init,
			    data_declaration *oddecl)
{
  struct data_declaration tempdecl;
  identifier_declarator id;
  variable_decl vd;
  data_decl dd;
  declarator tdeclarator;
  type_element tmodifiers;

  /* Compute real type, name */
  if (type_array(t))
    t = make_pointer_type(type_array_of(t));
  else if (type_function(t))
    t = make_pointer_type(t);
  /* Qualifiers must not be present on the temp (the qualifiers of t apply
     to the original location we are building a temp) */
  t = make_qualified_type(t, no_qualifiers);

  /* Build AST for the declaration */
  id = new_identifier_declarator(r, dummy_location, str2cstring(r, name));
  type2ast(r, dummy_location, t, CAST(declarator, id), &tdeclarator, &tmodifiers);
  vd = new_variable_decl(r, dummy_location, tdeclarator, NULL, init, NULL, NULL);
  vd->declared_type = t;
  dd = new_data_decl(r, dummy_location, tmodifiers, CAST(declaration, vd));

  if (e) /* Declare the variable */
    {
      init_data_declaration(&tempdecl, CAST(declaration, vd), id->cstring.data, t);
      tempdecl.kind = decl_variable;
      tempdecl.vtype = variable_normal;
      tempdecl.islocal = TRUE;
      *oddecl = vd->ddecl = declare(e, &tempdecl, FALSE);
    }

  return dd;
}
Ejemplo n.º 2
0
// Returns a volatile-qualified type.
//
// FIXME: This is wrong. It should add the qualifier to t, not overwrite
// the existing qualifier.
Type&
Parser::on_volatile_type(Type& t)
{
  return make_qualified_type(cxt, t, volatile_qual);
}
Ejemplo n.º 3
0
// Returns a const-qualified type.
//
// FIXME: This is wrong. It should add the qualifier to t, not overwrite
// the existing qualifier.
Type&
Parser::on_const_type(Type& t)
{
  return make_qualified_type(cxt, t, const_qual);
}