67 }
68
69 void get_char_constant(struct token *token, unsigned long long *val)
70 {
71 const char *p = token->embedded, *end;
72 unsigned v;
73 int type = token_type(token);
74 switch (type) {
75 case TOKEN_CHAR:
76 case TOKEN_WIDE_CHAR:
77 p = token->string->data;
78 end = p + token->string->length - 1;
79 break;
80 case TOKEN_CHAR_EMBEDDED_0 ... TOKEN_CHAR_EMBEDDED_3:
81 end = p + type - TOKEN_CHAR;
82 break;
83 default:
84 end = p + type - TOKEN_WIDE_CHAR;
85 }
86 p = parse_escape(p, &v, end,
87 type < TOKEN_WIDE_CHAR ? bits_in_char : bits_in_wchar, token->pos);
88 if (p != end)
89 warning(token->pos,
90 "multi-character character constant");
91 *val = v;
92 }
93
94 struct token *get_string_constant(struct token *token, struct expression *expr)
95 {
96 struct string *string = token->string;
97 struct token *next = token->next, *done = NULL;
98 int stringtype = token_type(token);
99 int is_wide = stringtype == TOKEN_WIDE_STRING;
100 static char buffer[MAX_STRING];
101 int len = 0;
102 int bits;
103 int esc_count = 0;
104
105 while (!done) {
106 switch (token_type(next)) {
107 case TOKEN_WIDE_STRING:
108 is_wide = 1;
109 case TOKEN_STRING:
110 next = next->next;
111 break;
112 default:
113 done = next;
114 }
115 }
116 bits = is_wide ? bits_in_wchar : bits_in_char;
117 while (token != done) {
118 unsigned v;
119 const char *p = token->string->data;
120 const char *end = p + token->string->length - 1;
121 while (p < end) {
122 if (*p == '\\')
123 esc_count++;
124 p = parse_escape(p, &v, end, bits, token->pos);
125 if (len < MAX_STRING)
126 buffer[len] = v;
127 len++;
128 }
129 token = token->next;
130 }
131 if (len > MAX_STRING) {
132 warning(token->pos, "trying to concatenate %d-character string (%d bytes max)", len, MAX_STRING);
133 len = MAX_STRING;
134 }
135
136 if (esc_count || len >= string->length) {
|
67 }
68
69 void get_char_constant(struct token *token, unsigned long long *val)
70 {
71 const char *p = token->embedded, *end;
72 unsigned v;
73 int type = token_type(token);
74 switch (type) {
75 case TOKEN_CHAR:
76 case TOKEN_WIDE_CHAR:
77 p = token->string->data;
78 end = p + token->string->length - 1;
79 break;
80 case TOKEN_CHAR_EMBEDDED_0 ... TOKEN_CHAR_EMBEDDED_3:
81 end = p + type - TOKEN_CHAR;
82 break;
83 default:
84 end = p + type - TOKEN_WIDE_CHAR;
85 }
86 p = parse_escape(p, &v, end,
87 type < TOKEN_WIDE_CHAR ? bits_in_char : wchar_ctype->bit_size, token->pos);
88 if (p != end)
89 warning(token->pos,
90 "multi-character character constant");
91 *val = v;
92 }
93
94 struct token *get_string_constant(struct token *token, struct expression *expr)
95 {
96 struct string *string = token->string;
97 struct token *next = token->next, *done = NULL;
98 int stringtype = token_type(token);
99 int is_wide = stringtype == TOKEN_WIDE_STRING;
100 static char buffer[MAX_STRING];
101 int len = 0;
102 int bits;
103 int esc_count = 0;
104
105 while (!done) {
106 switch (token_type(next)) {
107 case TOKEN_WIDE_STRING:
108 is_wide = 1;
109 case TOKEN_STRING:
110 next = next->next;
111 break;
112 default:
113 done = next;
114 }
115 }
116 bits = is_wide ? wchar_ctype->bit_size: bits_in_char;
117 while (token != done) {
118 unsigned v;
119 const char *p = token->string->data;
120 const char *end = p + token->string->length - 1;
121 while (p < end) {
122 if (*p == '\\')
123 esc_count++;
124 p = parse_escape(p, &v, end, bits, token->pos);
125 if (len < MAX_STRING)
126 buffer[len] = v;
127 len++;
128 }
129 token = token->next;
130 }
131 if (len > MAX_STRING) {
132 warning(token->pos, "trying to concatenate %d-character string (%d bytes max)", len, MAX_STRING);
133 len = MAX_STRING;
134 }
135
136 if (esc_count || len >= string->length) {
|