Skip to content

Commit afe8aed

Browse files
author
Daniel Kroening
committed
deal with universal character names in identifiers
1 parent 8a33af3 commit afe8aed

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/ansi-c/scanner.l

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
static int isatty(int) { return 0; }
2020
#endif
2121

22+
#include <util/unicode.h>
23+
2224
#include "c_types.h"
2325
#include "preprocessor_line.h"
2426
#include "string_constant.h"
@@ -27,6 +29,7 @@ static int isatty(int) { return 0; }
2729
#include "literals/convert_integer_literal.h"
2830
#include "literals/convert_character_literal.h"
2931
#include "literals/convert_string_literal.h"
32+
#include "literals/unescape_string.h"
3033

3134
#define PARSER ansi_c_parser
3235
#define YYSTYPE unsigned
@@ -45,9 +48,34 @@ extern int yyansi_cdebug;
4548
int make_identifier()
4649
{
4750
loc();
48-
51+
52+
// deal with universal identifiers
53+
std::string final_identifier;
54+
final_identifier.reserve(yyleng);
55+
56+
for(const char *p=yytext; *p!=0; p++)
57+
{
58+
if(p[0]=='\\' && (p[1]=='u' || p[1]=='U'))
59+
{
60+
p++;
61+
unsigned digits=(*p=='u')?4:8;
62+
p++;
63+
unsigned letter=hex_to_unsigned(p, digits);
64+
for(; *p!=0 && digits>0; digits--, p++);
65+
66+
std::basic_string<unsigned> utf32;
67+
utf32+=letter;
68+
69+
// turn into utf-8
70+
std::string utf8_value=utf32_to_utf8(utf32);
71+
final_identifier+=utf8_value;
72+
}
73+
else
74+
final_identifier+=*p;
75+
}
76+
4977
// this hashes the identifier
50-
irep_idt base_name=yytext;
78+
irep_idt base_name=final_identifier;
5179

5280
if(PARSER.cpp98)
5381
{

0 commit comments

Comments
 (0)