Ejemplo n.º 1
0
static void
def_struct (definition * defp)
{
  token tok;
  declaration dec;
  decl_list *decls;
  decl_list **tailp;

  defp->def_kind = DEF_STRUCT;

  scan (TOK_IDENT, &tok);
  defp->def_name = tok.str;
  scan (TOK_LBRACE, &tok);
  tailp = &defp->def.st.decls;
  do
    {
      get_declaration (&dec, DEF_STRUCT);
      decls = ALLOC (decl_list);
      decls->decl = dec;
      *tailp = decls;
      tailp = &decls->next;
      scan (TOK_SEMICOLON, &tok);
      peek (&tok);
    }
  while (tok.kind != TOK_RBRACE);
  get_token (&tok);
  *tailp = NULL;
}
Ejemplo n.º 2
0
static void
def_union(definition *defp)
{
	token tok;
	declaration dec;
	case_list *cases;
	case_list **tailp;

	defp->def_kind = DEF_UNION;
	scan(TOK_IDENT, &tok);
	defp->def_name = tok.str;
	scan(TOK_SWITCH, &tok);
	scan(TOK_LPAREN, &tok);
	get_declaration(&dec, DEF_UNION);
	defp->def.un.enum_decl = dec;
	tailp = &defp->def.un.cases;
	scan(TOK_RPAREN, &tok);
	scan(TOK_LBRACE, &tok);
	scan(TOK_CASE, &tok);
	while (tok.kind == TOK_CASE) {
		scan(TOK_IDENT, &tok);
		cases = ALLOC(case_list);
		cases->case_name = tok.str;
		scan(TOK_COLON, &tok);
		get_declaration(&dec, DEF_UNION);
		cases->case_decl = dec;
		*tailp = cases;
		tailp = &cases->next;
		scan(TOK_SEMICOLON, &tok);
		scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
	}
	*tailp = NULL;
	if (tok.kind == TOK_DEFAULT) {
		scan(TOK_COLON, &tok);
		get_declaration(&dec, DEF_UNION);
		defp->def.un.default_decl = ALLOC(declaration);
		*defp->def.un.default_decl = dec;
		scan(TOK_SEMICOLON, &tok);
		scan(TOK_RBRACE, &tok);
	} else {
		defp->def.un.default_decl = NULL;
	}
}
Ejemplo n.º 3
0
static void
def_typedef(definition *defp)
{
	declaration dec;

	defp->def_kind = DEF_TYPEDEF;
	get_declaration(&dec, DEF_TYPEDEF);
	defp->def_name = dec.name;
	defp->def.ty.old_prefix = dec.prefix;
	defp->def.ty.old_type = dec.type;
	defp->def.ty.rel = dec.rel;
	defp->def.ty.array_max = dec.array_max;
}
Ejemplo n.º 4
0
static void
def_union (definition *defp)
{
  token tok;
  declaration dec;
  case_list *cases;
/*  case_list *tcase; */
  case_list **tailp;
#if 0
  int flag;
#endif

  defp->def_kind = DEF_UNION;
  scan (TOK_IDENT, &tok);
  defp->def_name = tok.str;
  scan (TOK_SWITCH, &tok);
  scan (TOK_LPAREN, &tok);
  get_declaration (&dec, DEF_UNION);
  defp->def.un.enum_decl = dec;
  tailp = &defp->def.un.cases;
  scan (TOK_RPAREN, &tok);
  scan (TOK_LBRACE, &tok);
  scan (TOK_CASE, &tok);
  while (tok.kind == TOK_CASE)
    {
      scan2 (TOK_IDENT, TOK_CHARCONST, &tok);
      cases = ALLOC (case_list);
      cases->case_name = tok.str;
      scan (TOK_COLON, &tok);
      /* now peek at next token */
#if 0
      flag = 0;
#endif
      if (peekscan (TOK_CASE, &tok))
	{

	  do
	    {
	      scan2 (TOK_IDENT, TOK_CHARCONST, &tok);
	      cases->contflag = 1;	/* continued case statement */
	      *tailp = cases;
	      tailp = &cases->next;
	      cases = ALLOC (case_list);
	      cases->case_name = tok.str;
	      scan (TOK_COLON, &tok);

	    }
	  while (peekscan (TOK_CASE, &tok));
	}
#if 0
      else if (flag)
	{

	  *tailp = cases;
	  tailp = &cases->next;
	  cases = ALLOC (case_list);
	};
#endif

      get_declaration (&dec, DEF_UNION);
      cases->case_decl = dec;
      cases->contflag = 0;	/* no continued case statement */
      *tailp = cases;
      tailp = &cases->next;
      scan (TOK_SEMICOLON, &tok);

      scan3 (TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
    }
  *tailp = NULL;
  if (tok.kind == TOK_DEFAULT)
    {
      scan (TOK_COLON, &tok);
      get_declaration (&dec, DEF_UNION);
      defp->def.un.default_decl = ALLOC (declaration);
      *defp->def.un.default_decl = dec;
      scan (TOK_SEMICOLON, &tok);
      scan (TOK_RBRACE, &tok);
    }
  else
    {
      defp->def.un.default_decl = NULL;
    }
}
Ejemplo n.º 5
0
void 
gather_interface_dies(root_die& root, 
	set<iterator_base>& out, type_set& dedup_types_out, 
	std::function<bool(const iterator_base&)> pred)
{
	/* We want to deduplicate the types that we output, as we go. 
	 * CARE: what about anonymous types? We might want to generate names for them 
	 * based on their offset, in which case deduplication isn't transparent. 
	 * For this reason we output dedup_types_out separately from the DIEs.
	 * However, everything in dedup_types_out is also in out (FIXME: is this a good idea?) */
	auto toplevel_seq = root.grandchildren();
	type_set& types = dedup_types_out;
	/* FIXME: it needn't be just grandchildren. */
	for (auto i_d = std::move(toplevel_seq.first); i_d != toplevel_seq.second; ++i_d)
	{
		if (pred(i_d.base().base()))
		{
			// looks like a goer -- add it to the objs
			out.insert(i_d.base().base());
			
			/* utility that will come in handy */
			auto add_all_types = [&types, &root](iterator_df<type_die> outer_t) {
				walk_type(outer_t, iterator_base::END, 
					[&types, &root](iterator_df<type_die> t, iterator_df<program_element_die> reason) -> bool {
						if (!t) return false; // void case
						auto memb = reason.as_a<member_die>();
						if (memb && memb->get_declaration() && *memb->get_declaration()
							&& memb->get_external() && *memb->get_external())
						{
							// static member vars don't get added nor recursed on
							return false;
						}
						// apart from that, insert all nonvoids....
						auto inserted = types.insert(t);
						if (!inserted.second)
						{
							// cerr << "Type was already present: " << *t 
							// 	<< " (or something equal to it: " << *inserted.first
							// 	<< ")" << endl;
							// cerr << "Attributes: " << t->copy_attrs(root) << endl;
							return false; // was already present
						}
						else
						{
							cerr << "Inserted new type: " << *t << endl;
							// cerr << "Attributes: " << t->copy_attrs(root) << endl;
							return true;
						}
					}
				);
			};
			
			/* Also output everything that this depends on. We have to case-split
			 * for now. */
			if (i_d.base().base().is_a<subprogram_die>())
			{
				// make sure we have all the relevant types in our set
				auto i_subp = i_d.base().base().as_a<subprogram_die>();
				if (i_subp->find_type()) add_all_types(i_subp->find_type());
				auto fps = i_subp->children().subseq_of<formal_parameter_die>();
				for (auto i_fp = std::move(fps.first); i_fp != fps.second; ++i_fp)
				{
					auto outer_t = i_fp->find_type();
					add_all_types(outer_t);
				}
			}
			else if (i_d.base().base().is_a<variable_die>())
			{
				add_all_types(i_d.base().base().as_a<variable_die>()->get_type());
			}
			else if (i_d.base().base().is_a<type_die>())
			{
				/* Just walk it. */
				add_all_types(i_d.base().base().as_a<type_die>());
			}
		} // end if pred
	} // end for
	
	/* Now we've gathered everything. Make sure everything in "types" is in 
	 * "out". */
	for (auto i_d = types.begin(); i_d != types.end(); ++i_d)
	{
		out.insert(*i_d);
	}
	
	/* Check that everything that's in "out", if it is a type, is also in 
	 * types. */
	for (auto i_d = out.begin(); i_d != out.end(); ++i_d)
	{
		if (i_d->is_a<type_die>() && !i_d->is_a<subprogram_die>())
		{
			if (types.find(i_d->as_a<type_die>()) == types.end())
			{
				cerr << "BUG: didn't find " << i_d->summary() << " in types list." << endl;
			}
		}
	}
}