"\p*** Pascal String literals ***" are now supported.

This commit is contained in:
Wolfgang Thaller 2014-09-20 02:17:52 +02:00
parent 2c6941895a
commit 4116636965
6 changed files with 58 additions and 4 deletions

View File

@ -174,7 +174,7 @@ int main()
Rect r = bm.bounds;
#endif
SetRect(&r, r.left + 5, r.top + 45, r.right - 5, r.bottom -5);
win = NewWindow(NULL, &r, (ConstStr255Param)"\x09Raytracer", true, 0, (WindowPtr)-1, false, 0);
win = NewWindow(NULL, &r, "\pRaytracer (C Version)", true, 0, (WindowPtr)-1, false, 0);
#if !TARGET_API_MAC_CARBON
SetPort(win);

View File

@ -229,7 +229,7 @@ int main()
Rect r = bm.bounds;
#endif
SetRect(&r, r.left + 5, r.top + 45, r.right - 5, r.bottom -5);
win = NewWindow(NULL, &r, PSTR("Raytracer"), true, 0, (WindowPtr)-1, false, 0);
win = NewWindow(NULL, &r, "\pRaytracer (C++ Version)", true, 0, (WindowPtr)-1, false, 0);
#if !TARGET_API_MAC_CARBON
SetPort(win);

View File

@ -933,6 +933,11 @@ fix_string_type (tree value)
nchars = length;
e_type = char_type_node;
}
else if (TREE_TYPE (value) == uchar_array_type_node)
{
nchars = length;
e_type = unsigned_char_type_node;
}
else if (TREE_TYPE (value) == char16_array_type_node)
{
nchars = length / (TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT);
@ -4906,6 +4911,12 @@ c_common_nodes_and_builtins (void)
char_array_type_node
= build_array_type (char_type_node, array_domain_type);
/* Make a type for arrays of unsigned characters.
Needed for "\ppascal string" support. */
uchar_array_type_node
= build_array_type (unsigned_char_type_node, array_domain_type);
/* Likewise for arrays of ints. */
int_array_type_node
= build_array_type (integer_type_node, array_domain_type);

View File

@ -277,6 +277,7 @@ enum c_tree_index
CTI_UINTPTR_TYPE,
CTI_CHAR_ARRAY_TYPE,
CTI_UCHAR_ARRAY_TYPE,
CTI_CHAR16_ARRAY_TYPE,
CTI_CHAR32_ARRAY_TYPE,
CTI_WCHAR_ARRAY_TYPE,
@ -417,6 +418,7 @@ extern const unsigned int num_c_common_reswords;
#define truthvalue_false_node c_global_trees[CTI_TRUTHVALUE_FALSE]
#define char_array_type_node c_global_trees[CTI_CHAR_ARRAY_TYPE]
#define uchar_array_type_node c_global_trees[CTI_UCHAR_ARRAY_TYPE]
#define char16_array_type_node c_global_trees[CTI_CHAR16_ARRAY_TYPE]
#define char32_array_type_node c_global_trees[CTI_CHAR32_ARRAY_TYPE]
#define wchar_array_type_node c_global_trees[CTI_WCHAR_ARRAY_TYPE]

View File

@ -985,6 +985,8 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
zero '@' before each string. */
bool objc_at_sign_was_seen = false;
bool pascal_string = false;
retry:
tok = cpp_get_token (parse_in);
switch (tok->type)
@ -1044,10 +1046,22 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
warning (OPT_Wtraditional,
"traditional C rejects string constant concatenation");
if (!strncmp((const char*)strs[0].text, "\"\\p", 3))
{
pascal_string = true;
/* replace \p by a valid escape sequence */
((unsigned char*)strs[0].text)[2] = 'n';
}
if ((translate
? cpp_interpret_string : cpp_interpret_string_notranslate)
(parse_in, strs, concats + 1, &istr, type))
{
if (pascal_string)
{
/* put the real string length in */
((unsigned char*)istr.text)[0] = (unsigned char) (istr.len - 1);
}
value = build_string (istr.len, (const char *) istr.text);
free (CONST_CAST (unsigned char *, istr.text));
}
@ -1087,7 +1101,14 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
default:
case CPP_STRING:
case CPP_UTF8STRING:
TREE_TYPE (value) = char_array_type_node;
if (pascal_string)
{
TREE_TYPE (value) = uchar_array_type_node;
}
else
{
TREE_TYPE (value) = char_array_type_node;
}
break;
case CPP_STRING16:
TREE_TYPE (value) = char16_array_type_node;

View File

@ -3393,6 +3393,7 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
tree string_tree;
tree suffix_id = NULL_TREE;
bool curr_tok_is_userdef_p = false;
bool pascal_string = false;
tok = cp_lexer_peek_token (parser->lexer);
if (!cp_parser_is_string_literal (tok))
@ -3506,9 +3507,21 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
type = CPP_STRING;
}
if (!strncmp((const char*)strs[0].text, "\"\\p", 3))
{
pascal_string = true;
/* replace \p by a valid escape sequence */
((unsigned char*)strs[0].text)[2] = 'n';
}
if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate)
(parse_in, strs, count, &istr, type))
{
if (pascal_string)
{
/* put the real string length in */
((unsigned char*)istr.text)[0] = (unsigned char) (istr.len - 1);
}
value = build_string (istr.len, (const char *)istr.text);
free (CONST_CAST (unsigned char *, istr.text));
@ -3517,7 +3530,14 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
default:
case CPP_STRING:
case CPP_UTF8STRING:
TREE_TYPE (value) = char_array_type_node;
if (pascal_string)
{
TREE_TYPE (value) = uchar_array_type_node;
}
else
{
TREE_TYPE (value) = char_array_type_node;
}
break;
case CPP_STRING16:
TREE_TYPE (value) = char16_array_type_node;