This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Re: [C++-0x] User-defined literals.
- From: 3dw4rd at verizon dot net
- To: rodrigorivascosta at gmail dot com
- Cc: paolo dot carlini at oracle dot com, gcc at gcc dot gnu dot org
- Date: Tue, 21 Sep 2010 16:24:32 -0500 (CDT)
- Subject: Re: Re: [C++-0x] User-defined literals.
Sep 21, 2010 03:56:25 PM, rodrigorivascosta@gmail.com wrote:
>> 3. The big one: Getting the integer(long long) and float(long double)
>> suffixes that are not used by gcc out of the preprocessor. Then we
>can
>> build the calls.
>
>Just my two cents:
>Add an output parameter to the function "cpp_classify_number()"
>(libcpp/expr.c) to get the user-defined suffix.
>It should be optional, so that it is ignored when not needed.
>
>unsigned int
>-cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
>+cpp_classify_number (cpp_reader *pfile, const cpp_token *token, char
>**suffix) //exposition only!
>
>Then in the function "c_lex_with_flags()" (c-family/c-lex.c) retrieve
>the suffix and pass it on to the function "interpret_integer()" /
>"interpret_float()", that should add an input parameter accordingly.
>
>The function "interpret_{integer,float}()" calls
>"build_int_cst_wide()" / "build_real()" to build the constant.
>Then
>you can build a tree for the identifier (with "get_identifier()",
>perhaps) and attach it somehow to the constant.
>You may consider creating a new TREE type for that...
>
>I'm afraid that you have quite some job here...
>
>Best regards.
>Rodrigo
>
Rodrigo,
Thank you for taking a look at this. These are helpful hints if I need to go this route.
What made the string types and the char types so easy is that the suffix was sent to the parser as a separate token. I was able to look ahead and parse the name and look for a function (which I got working with cp_parser_lookup_name).
I'm holding out for rolling back the lexer in some way that won't break everything and emitting the (unrecognized by cpp ) suffix as a separate identifier token. I'm thinking the cp_lexer_* routines or maybe a new one in parser.c would be worth trying. Then the code I have now would just work (except I would still need enhanced lookup rules as discussed earlier). It would be nice to have all types on the same page too.
Regards,
Ed