diff options
author | Zack Weinberg <zack@gcc.gnu.org> | 2000-08-04 01:30:06 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-08-04 01:30:06 +0000 |
commit | ba89d661ac573f2402fa4f3b4cb117c8c74968e2 (patch) | |
tree | 254d84e8b966d54bb05be43ebe0b47a16be7a4ea /gcc/cpplex.c | |
parent | d31772ca70b9d2a315372456bfdf343c3806a3f8 (diff) | |
download | gcc-ba89d661ac573f2402fa4f3b4cb117c8c74968e2.zip gcc-ba89d661ac573f2402fa4f3b4cb117c8c74968e2.tar.gz gcc-ba89d661ac573f2402fa4f3b4cb117c8c74968e2.tar.bz2 |
cpplex.c (parse_name): Might have to glue a CPP_OTHER token before the name.
* cpplex.c (parse_name): Might have to glue a CPP_OTHER token
before the name.
(lex_line): Glue @ onto the beginning of identifiers and
string constants, in Objective-C mode.
(output_token, spell_token): Handle CPP_OSTRING.
(can_paste, maybe_paste_with_next): Handle pasting @ onto the
beginning of a NAME or a STRING, in objc mode.
* cpplib.c (get_define_node): Do not permit identifiers that
begin with @ to be #defined.
* cppmacro.c (CAN_PASTE_AFTER): Add CPP_OTHER.
* cpplib.h (TTYPE_TABLE): Add CPP_OSTRING.
* c-lang.c, objc/objc-act.c (build_objc_string): Delete.
* c-tree.h (build_objc_string): Delete prototype.
* objc/objc-tree.def: Delete OBJC_STRING_CST.
* c-lex.c (yylex): Use build_string for all three kinds of strings.
* gcc.dg/cpp/20000625-2.c: Don't expect a warning on line 4.
From-SVN: r35470
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r-- | gcc/cpplex.c | 111 |
1 files changed, 75 insertions, 36 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 7485fde..5307edc 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -1008,15 +1008,27 @@ parse_name (pfile, tok, cur, rlimit) } len = cur - name; - if (tok->val.node == 0) + if (tok->type == CPP_NAME && tok->val.node == 0) tok->val.node = _cpp_lookup_with_hash (pfile, name, len, r); else { - unsigned int oldlen = tok->val.node->length; - U_CHAR *newname = alloca (oldlen + len); - memcpy (newname, tok->val.node->name, oldlen); + unsigned int oldlen; + U_CHAR *newname; + + if (tok->type == CPP_NAME) + oldlen = tok->val.node->length; + else + oldlen = 1; + + newname = alloca (oldlen + len); + + if (tok->type == CPP_NAME) + memcpy (newname, tok->val.node->name, oldlen); + else + newname[0] = tok->val.aux; memcpy (newname + oldlen, name, len); tok->val.node = cpp_lookup (pfile, newname, len + oldlen); + tok->type = CPP_NAME; } return cur; @@ -1373,8 +1385,16 @@ lex_line (pfile, list) case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': cur--; /* Backup character. */ - cur_token->val.node = 0; - cur_token->type = CPP_NAME; /* Identifier, macro etc. */ + + /* In Objective C, '@' may begin certain keywords. */ + if (CPP_OPTION (pfile, objc) && cur_token[-1].type == CPP_OTHER + && cur_token[-1].val.aux == '@' && IMMED_TOKEN ()) + cur_token--; + else + { + cur_token->val.node = 0; + cur_token->type = CPP_NAME; /* Identifier, macro etc. */ + } continue_name: cur = parse_name (pfile, cur_token, cur, buffer->rlimit); @@ -1394,12 +1414,21 @@ lex_line (pfile, list) break; case '\'': + cur_token->type = CPP_CHAR; + if (cur_token[-1].type == CPP_NAME && IMMED_TOKEN () + && cur_token[-1].val.node == pfile->spec_nodes->n_L) + BACKUP_TOKEN (CPP_WCHAR); + goto do_parse_string; + case '\"': - cur_token->type = c == '\'' ? CPP_CHAR : CPP_STRING; - /* Do we have a wide string? */ + cur_token->type = CPP_STRING; if (cur_token[-1].type == CPP_NAME && IMMED_TOKEN () && cur_token[-1].val.node == pfile->spec_nodes->n_L) - BACKUP_TOKEN (c == '\'' ? CPP_WCHAR : CPP_WSTRING); + BACKUP_TOKEN (CPP_WSTRING); + else if (CPP_OPTION (pfile, objc) + && cur_token[-1].type == CPP_OTHER && IMMED_TOKEN () + && cur_token[-1].val.aux == '@') + BACKUP_TOKEN (CPP_OSTRING); do_parse_string: /* Here c is one of ' " or >. */ @@ -1883,20 +1912,21 @@ output_token (pfile, fp, token, prev, white) case SPELL_STRING: { - if (token->type == CPP_WSTRING || token->type == CPP_WCHAR) - putc ('L', fp); - - if (token->type == CPP_STRING || token->type == CPP_WSTRING) - putc ('"', fp); - if (token->type == CPP_CHAR || token->type == CPP_WCHAR) - putc ('\'', fp); - + int left, right, tag; + switch (token->type) + { + case CPP_STRING: left = '"'; right = '"'; tag = '\0'; break; + case CPP_WSTRING: left = '"'; right = '"'; tag = 'L'; break; + case CPP_OSTRING: left = '"'; right = '"'; tag = '@'; break; + case CPP_CHAR: left = '\''; right = '\''; tag = '\0'; break; + case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break; + case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break; + default: left = '\0'; right = '\0'; tag = '\0'; break; + } + if (tag) putc (tag, fp); + if (left) putc (left, fp); fwrite (token->val.str.text, 1, token->val.str.len, fp); - - if (token->type == CPP_STRING || token->type == CPP_WSTRING) - putc ('"', fp); - if (token->type == CPP_CHAR || token->type == CPP_WCHAR) - putc ('\'', fp); + if (right) putc (right, fp); } break; @@ -1999,21 +2029,22 @@ spell_token (pfile, token, buffer) case SPELL_STRING: { - if (token->type == CPP_WSTRING || token->type == CPP_WCHAR) - *buffer++ = 'L'; - - if (token->type == CPP_STRING || token->type == CPP_WSTRING) - *buffer++ = '"'; - if (token->type == CPP_CHAR || token->type == CPP_WCHAR) - *buffer++ = '\''; - + int left, right, tag; + switch (token->type) + { + case CPP_STRING: left = '"'; right = '"'; tag = '\0'; break; + case CPP_WSTRING: left = '"'; right = '"'; tag = 'L'; break; + case CPP_OSTRING: left = '"'; right = '"'; tag = '@'; break; + case CPP_CHAR: left = '\''; right = '\''; tag = '\0'; break; + case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break; + case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break; + default: left = '\0'; right = '\0'; tag = '\0'; break; + } + if (tag) *buffer++ = tag; + if (left) *buffer++ = left; memcpy (buffer, token->val.str.text, token->val.str.len); buffer += token->val.str.len; - - if (token->type == CPP_STRING || token->type == CPP_WSTRING) - *buffer++ = '"'; - if (token->type == CPP_CHAR || token->type == CPP_WCHAR) - *buffer++ = '\''; + if (right) *buffer++ = right; } break; @@ -2700,6 +2731,13 @@ can_paste (pfile, token1, token2, digraph) return CPP_NUMBER; break; + case CPP_OTHER: + if (CPP_OPTION (pfile, objc) && token1->val.aux == '@') + { + if (b == CPP_NAME) return CPP_NAME; + if (b == CPP_STRING) return CPP_OSTRING; + } + default: break; } @@ -2789,7 +2827,8 @@ maybe_paste_with_next (pfile, token) pasted->val.str.len = end - buf; } } - else if (type == CPP_WCHAR || type == CPP_WSTRING) + else if (type == CPP_WCHAR || type == CPP_WSTRING + || type == CPP_OSTRING) pasted = duplicate_token (pfile, second); else { |