Esempio n. 1
0
struct macro_scope *
sal_macro_scope (struct symtab_and_line sal)
{
  struct macro_source_file *main;
  struct macro_scope *ms;

  if (! sal.symtab
      || ! sal.symtab->macro_table)
    return 0;

  ms = (struct macro_scope *) xmalloc (sizeof (*ms));

  main = macro_main (sal.symtab->macro_table);
  ms->file = macro_lookup_inclusion (main, sal.symtab->filename);

  if (! ms->file)
    internal_error
      (__FILE__, __LINE__,
       "\n"
       "the symtab `%s' refers to a preprocessor macro table which doesn't\n"
       "have any record of processing a file by that name.\n",
       sal.symtab->filename);

  ms->line = sal.line;

  return ms;
}
struct macro_scope *
user_macro_scope (void)
{
  struct macro_scope *ms;
  ms = XNEW (struct macro_scope);
  ms->file = macro_main (macro_user_macros);
  ms->line = -1;
  return ms;
}
/* Look up the definition of the macro named NAME in scope at the source
   location given by BATON, which must be a pointer to a `struct
   macro_scope' structure.  */
struct macro_definition *
standard_macro_lookup (const char *name, void *baton)
{
  struct macro_scope *ms = (struct macro_scope *) baton;
  struct macro_definition *result;

  /* Give user-defined macros priority over all others.  */
  result = macro_lookup_definition (macro_main (macro_user_macros), -1, name);
  if (! result)
    result = macro_lookup_definition (ms->file, ms->line, name);
  return result;
}
Esempio n. 4
0
struct macro_scope *
sal_macro_scope (struct symtab_and_line sal)
{
  struct macro_source_file *main_file, *inclusion;
  struct macro_scope *ms;
  struct compunit_symtab *cust;

  if (sal.symtab == NULL)
    return NULL;
  cust = SYMTAB_COMPUNIT (sal.symtab);
  if (COMPUNIT_MACRO_TABLE (cust) == NULL)
    return NULL;

  ms = XNEW (struct macro_scope);

  main_file = macro_main (COMPUNIT_MACRO_TABLE (cust));
  inclusion = macro_lookup_inclusion (main_file, sal.symtab->filename);

  if (inclusion)
    {
      ms->file = inclusion;
      ms->line = sal.line;
    }
  else
    {
      /* There are, unfortunately, cases where a compilation unit can
         have a symtab for a source file that doesn't appear in the
         macro table.  For example, at the moment, Dwarf doesn't have
         any way in the .debug_macinfo section to describe the effect
         of #line directives, so if you debug a YACC parser you'll get
         a macro table which only mentions the .c files generated by
         YACC, but symtabs that mention the .y files consumed by YACC.

         In the long run, we should extend the Dwarf macro info
         representation to handle #line directives, and get GCC to
         emit it.

         For the time being, though, we'll just treat these as
         occurring at the end of the main source file.  */
      ms->file = main_file;
      ms->line = -1;

      complaint (&symfile_complaints,
                 _("symtab found for `%s', but that file\n"
                 "is not covered in the compilation unit's macro information"),
                 symtab_to_filename_for_display (sal.symtab));
    }

  return ms;
}
Esempio n. 5
0
static void
macro_define_command (char *exp, int from_tty)
{
  struct macro_definition new_macro;
  char *name = NULL;
  struct cleanup *cleanup_chain;

  if (!exp)
    error (_("usage: macro define NAME[(ARGUMENT-LIST)] [REPLACEMENT-LIST]"));

  cleanup_chain = make_cleanup (free_macro_definition_ptr, &new_macro);
  make_cleanup (free_current_contents, &name);

  memset (&new_macro, 0, sizeof (struct macro_definition));

  skip_ws (&exp);
  name = extract_identifier (&exp, 0);
  if (! name)
    error (_("Invalid macro name."));
  if (*exp == '(')
    {
      /* Function-like macro.  */
      int alloced = 5;
      char **argv = XNEWVEC (char *, alloced);

      new_macro.kind = macro_function_like;
      new_macro.argc = 0;
      new_macro.argv = (const char * const *) argv;

      /* Skip the '(' and whitespace.  */
      ++exp;
      skip_ws (&exp);

      while (*exp != ')')
	{
	  int i;

	  if (new_macro.argc == alloced)
	    {
	      alloced *= 2;
	      argv = (char **) xrealloc (argv, alloced * sizeof (char *));
	      /* Must update new_macro as well...  */
	      new_macro.argv = (const char * const *) argv;
	    }
	  argv[new_macro.argc] = extract_identifier (&exp, 1);
	  if (! argv[new_macro.argc])
	    error (_("Macro is missing an argument."));
	  ++new_macro.argc;

	  for (i = new_macro.argc - 2; i >= 0; --i)
	    {
	      if (! strcmp (argv[i], argv[new_macro.argc - 1]))
		error (_("Two macro arguments with identical names."));
	    }

	  skip_ws (&exp);
	  if (*exp == ',')
	    {
	      ++exp;
	      skip_ws (&exp);
	    }
	  else if (*exp != ')')
	    error (_("',' or ')' expected at end of macro arguments."));
	}
      /* Skip the closing paren.  */
      ++exp;
      skip_ws (&exp);

      macro_define_function (macro_main (macro_user_macros), -1, name,
			     new_macro.argc, (const char **) new_macro.argv,
			     exp);
    }