This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

cpplib: Language defaults


Nathan noticed that cc1plus does not default to -lang-cpp for the
integrated preprocessor (the same would be true for the objc front
end), meaning he had to pass it on the command line.

I've been looking at the best way to solve this.  My approach is:-

o Have a function in cppinit.c called set_lang.  This is called from
  cpp_start_read.  It, and cpp_start_read in turn, take a LANG enum,
  which is from the list below:

  enum c_lang {LANG_GNU89 = 0, LANG_GNU99, LANG_STD89, LANG_STD94,
       LANG_STD99, LANG_CPP, LANG_OBJC, LANG_OBJCPP, LANG_ASM};

o Have each front end, when calling cpp_start_read, pass the default
  language for that front end.  This would seem to solve Nathan's problem.

o Have cppmain.c, the stand-alone preprocessor, and the C front end
  call it with LANG_GNU89.  This seems to be what we default to at
  present (right?).

o Have each command line option, line -std=c89, call set_lang with the
  correct enumeration.  This is nice, as it clears out a lot of crud
  from cpp_parse_option.

I think this is the cleanest and most logical way to fix this.

Below is my first draft the set_lang function.  Can anyone see
anything wrong with it?  I cobbled it together from what is currently
done with command line options.  In creating it, though, I noticed
what seem to be a couple of inconsistencies in existing code:

1) __STRICT_ANSI__ was only being set for C89 and C94.  Surely this
  should be done for C99 too?  Assuming it should, I've fixed this
  below.

2) There is no definition of __STDC_VERSION__ for C89 or GNU89.  There
   is for C94, C99 and GNU99.  I've left this as it is.

3) Whereas it seems we default to GNU89 if not told otherwise, GNU89
   sets the C89 flag to 1.  We were not doing this by default before.
   I've "fixed" this below.

Before I come up with a tested patch for this, does anyone object to
any of the above points or see where I might have things wrong?

Cheers,

Neil.

-----------------

static void
set_lang (pfile, lang)
     cpp_reader *pfile;
     enum c_lang lang;
{
  struct cpp_pending *pend = CPP_OPTION (pfile, pending);

  if (lang == LANG_ASM)
    {
      CPP_OPTION (pfile, lang_asm) = 1;
      CPP_OPTION (pfile, dollars_in_ident) = 0;
      new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
    }
  else
    {
      unsigned char std89 = (lang == LANG_STD89 || lang == LANG_STD94);
      unsigned char std = (std89 || lang == LANG_STD99);

      CPP_OPTION (pfile, dollars_in_ident) = 1;
      CPP_OPTION (pfile, cplusplus_comments) = !std89;
      CPP_OPTION (pfile, digraphs) = lang != LANG_STD89;
      CPP_OPTION (pfile, c89) = (lang == LANG_GNU89 || std89);
      CPP_OPTION (pfile, c99) = (lang == LANG_GNU99 || lang == LANG_STD99);
      CPP_OPTION (pfile, trigraphs) = std;
      CPP_OPTION (pfile, cplusplus) = 0;
      CPP_OPTION (pfile, objc) = 0;

      if (lang == LANG_OBJC || lang == LANG_OBJCPP)
	{
	  CPP_OPTION (pfile, objc) = 1;
	  new_pending_directive (pend, "__OBJC__", cpp_define);
	}

      if (lang == LANG_CPP || lang == LANG_OBJCPP)
	{
	  CPP_OPTION (pfile, cplusplus) = 1;
	  new_pending_directive (pend, "__cplusplus", cpp_define);
	}

      if (std)
	new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);

      if (lang == LANG_GNU99 || lang == LANG_STD99)
	new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
      else if (lang == LANG_STD94)
	new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
    }
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]