Skip to content

Commit

Permalink
c family: Add support for digraphs
Browse files Browse the repository at this point in the history
See http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf 6.4.6§3.

Note: This is not exactly the upstream Universal CTags commit because
it depends on another change for adding the `enter` label, which was
then included here.

X-Universal-CTags-Commit-ID: 3b3b60c7664a321a31ec87de336fc6bda90c405e
  • Loading branch information
b4n committed Jun 14, 2015
1 parent b737f03 commit dbbc042
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tagmanager/ctags/get.c
Expand Up @@ -680,6 +680,42 @@ extern int cppGetc (void)
}
} break;

/* digraphs:
* input: <: :> <% %> %: %:%:
* output: [ ] { } # ##
*/
case '<':
{
int next = fileGetc ();
switch (next)
{
case ':': c = '['; break;
case '%': c = '{'; break;
default: fileUngetc (next);
}
goto enter;
}
case ':':
{
int next = fileGetc ();
if (next == '>')
c = ']';
else
fileUngetc (next);
goto enter;
}
case '%':
{
int next = fileGetc ();
switch (next)
{
case '>': c = '}'; break;
case ':': c = '#'; goto process;
default: fileUngetc (next);
}
goto enter;
}

default:
if (c == '@' && Cpp.hasAtLiteralStrings)
{
Expand All @@ -691,6 +727,7 @@ extern int cppGetc (void)
break;
}
}
enter:
Cpp.directive.accept = FALSE;
if (directive)
ignore = handleDirective (c);
Expand Down
1 change: 1 addition & 0 deletions tests/ctags/Makefile.am
Expand Up @@ -108,6 +108,7 @@ test_sources = \
bug960316.v \
bug961001.v \
byte.f \
c-digraphs.c \
c-trigraphs.c \
case_sensitivity.php \
char-selector.f90 \
Expand Down
35 changes: 35 additions & 0 deletions tests/ctags/c-digraphs.c
@@ -0,0 +1,35 @@

/* simple trigraphs */
%:define A 1
%:define B 2
%:define STRINGIFY_INTERN(x) %:x
%:define STRINGIFY(x) STRINGIFY_INTERN(x)

%:define M3_INIT(a, b, c) <% a, b, c %>
typedef int matrix3<:3:>;

struct str <%
char *buf;
unsigned int len, size;
%>;

int main(void)
<%
const char *hello = STRINGIFY(hello);
matrix3 m = M3_INIT(1, 2, 3);

return m<:2:>;
%>

%:if 0
#define bug4
%:endif


/* test the same with untaken preprocessor paths (as they are then not read by
* the C parser but get.c) */
#if 0
%:define if0d_A 1
%:define if0d_B 2
#endif

12 changes: 12 additions & 0 deletions tests/ctags/c-digraphs.c.tags
@@ -0,0 +1,12 @@
# format=tagmanager
A�65536�0
B�65536�0
M3_INIT�131072�(a, b, c)�0
STRINGIFY�131072�(x)�0
STRINGIFY_INTERN�131072�(x)�0
buf�64�str�0�char
len�64�str�0�int
main�16�(void)�0�int
matrix3�4096�0�int
size�64�str�0�int
str�2048�0

0 comments on commit dbbc042

Please sign in to comment.