Skip to content

Commit

Permalink
Fortran: generate fake tags for anonymous structures, interfaces and …
Browse files Browse the repository at this point in the history
…enums

This allows both to show those anonymous elements, as well as giving a
parent to their children, fixing display in the symbols tree.
  • Loading branch information
b4n committed Feb 23, 2014
1 parent 9520e7f commit ef4c725
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 65 deletions.
1 change: 1 addition & 0 deletions src/symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ static void add_top_level_items(GeanyDocument *doc)
&(tv_iters.tag_class), _("Types"), "classviewer-class",
&(tv_iters.tag_member), _("Components"), "classviewer-member",
&(tv_iters.tag_macro), _("Blocks"), "classviewer-member",
&(tv_iters.tag_type), _("Enums"), "classviewer-struct",
&(tv_iters.tag_other), _("Other"), "classviewer-other",
NULL);
break;
Expand Down
38 changes: 22 additions & 16 deletions tagmanager/ctags/fortran.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static unsigned int Column = 0;
static boolean FreeSourceForm = FALSE;
static boolean ParsingString;
static tokenInfo *Parent = NULL;
static unsigned int contextual_fake_count = 0;

/* indexed by tagType */
static kindOption FortranKinds [] = {
Expand Down Expand Up @@ -378,8 +379,7 @@ static const tokenInfo* ancestorScope (void)
{
tokenInfo *const token = Ancestors.list + i - 1;
if (token->type == TOKEN_IDENTIFIER &&
token->tag != TAG_UNDEFINED && token->tag != TAG_INTERFACE &&
token->tag != TAG_ENUM)
token->tag != TAG_UNDEFINED)
result = token;
}
return result;
Expand Down Expand Up @@ -456,6 +456,16 @@ static tokenInfo *newTokenFrom (tokenInfo *const token)
return result;
}

static tokenInfo *newAnonTokenFrom (tokenInfo *const token, const char *type)
{
char buffer[64];
tokenInfo *result = newTokenFrom (token);
sprintf (buffer, "%s#%u", type, contextual_fake_count++);
vStringClear (result->string);
vStringCatS (result->string, buffer);
return result;
}

static void deleteToken (tokenInfo *const token)
{
if (token != NULL)
Expand Down Expand Up @@ -1593,25 +1603,24 @@ static void parseUnionStmt (tokenInfo *const token)
*/
static void parseStructureStmt (tokenInfo *const token)
{
tokenInfo *name;
tokenInfo *name = NULL;
Assert (isKeyword (token, KEYWORD_structure));
readToken (token);
if (isType (token, TOKEN_OPERATOR) &&
strcmp (vStringValue (token->string), "/") == 0)
{ /* read structure name */
readToken (token);
if (isType (token, TOKEN_IDENTIFIER))
makeFortranTag (token, TAG_DERIVED_TYPE);
name = newTokenFrom (token);
name = newTokenFrom (token);
skipPast (token, TOKEN_OPERATOR);
}
else
if (name == NULL)
{ /* fake out anonymous structure */
name = newToken ();
name = newAnonTokenFrom (token, "Structure");
name->type = TOKEN_IDENTIFIER;
name->tag = TAG_DERIVED_TYPE;
vStringCopyS (name->string, "anonymous");
}
makeFortranTag (name, TAG_DERIVED_TYPE);
while (isType (token, TOKEN_IDENTIFIER))
{ /* read field names */
makeFortranTag (token, TAG_COMPONENT);
Expand Down Expand Up @@ -1770,7 +1779,6 @@ static void parseInterfaceBlock (tokenInfo *const token)
readToken (token);
if (isType (token, TOKEN_IDENTIFIER))
{
makeFortranTag (token, TAG_INTERFACE);
name = newTokenFrom (token);
}
else if (isKeyword (token, KEYWORD_assignment) ||
Expand All @@ -1780,17 +1788,15 @@ static void parseInterfaceBlock (tokenInfo *const token)
if (isType (token, TOKEN_PAREN_OPEN))
readToken (token);
if (isType (token, TOKEN_OPERATOR))
{
makeFortranTag (token, TAG_INTERFACE);
name = newTokenFrom (token);
}
}
if (name == NULL)
{
name = newToken ();
name = newAnonTokenFrom (token, "Interface");
name->type = TOKEN_IDENTIFIER;
name->tag = TAG_INTERFACE;
}
makeFortranTag (name, TAG_INTERFACE);
ancestorPush (name);
while (! isKeyword (token, KEYWORD_end))
{
Expand Down Expand Up @@ -1842,12 +1848,11 @@ static void parseEnumBlock (tokenInfo *const token)
name = newTokenFrom (token);
if (name == NULL)
{
name = newToken ();
name = newAnonTokenFrom (token, "Enum");
name->type = TOKEN_IDENTIFIER;
name->tag = TAG_ENUM;
}
else
makeFortranTag (name, TAG_ENUM);
makeFortranTag (name, TAG_ENUM);
skipToNextStatement (token);
ancestorPush (name);
while (! isKeyword (token, KEYWORD_end))
Expand Down Expand Up @@ -2282,6 +2287,7 @@ static boolean findFortranTags (const unsigned int passCount)
Parent = newToken ();
token = newToken ();
FreeSourceForm = (boolean) (passCount > 1);
contextual_fake_count = 0;
Column = 0;
exception = (exception_t) setjmp (Exception);
if (exception == ExceptionEOF)
Expand Down
70 changes: 36 additions & 34 deletions tests/ctags/enum.f90.tags
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
# format=tagmanager
Constants�256�0
E_e�16384�Constants�0
Enum#0�2�Constants�0
Enum#1�2�Constants�0
Named1�2�Constants�0
Named2�2�Constants�0
Named3�2�Constants�0
Named4�2�Constants�0
Named5�2�Constants�0
Named6�2�Constants�0
Named7�2�Constants�0
a�4�Constants�0
b�4�Constants�0
black�4�Constants�0
blue�4�Constants�0
bronze�4�Constants�0
c�4�Constants�0
gold�4�Constants�0
a�4�Enum#1�0
b�4�Enum#1�0
black�4�Enum#0�0
blue�4�Enum#0�0
bronze�4�Enum#0�0
c�4�Enum#1�0
gold�4�Enum#0�0
hc�16384�Constants�0
lavender�4�Constants�0
lavender�4�Enum#0�0
pi�16384�Constants�0
pink�4�Constants�0
purple�4�Constants�0
red�4�Constants�0
silver�4�Constants�0
x1�4�Constants�0
x2�4�Constants�0
x3�4�Constants�0
x4�4�Constants�0
x5�4�Constants�0
x6�4�Constants�0
x7�4�Constants�0
y1�4�Constants�0
y2�4�Constants�0
y3�4�Constants�0
y4�4�Constants�0
y5�4�Constants�0
y6�4�Constants�0
y7�4�Constants�0
yellow�4�Constants�0
z1�4�Constants�0
z2�4�Constants�0
z3�4�Constants�0
z4�4�Constants�0
z5�4�Constants�0
z6�4�Constants�0
z7�4�Constants�0
pink�4�Enum#0�0
purple�4�Enum#0�0
red�4�Enum#0�0
silver�4�Enum#0�0
x1�4�Named1�0
x2�4�Named2�0
x3�4�Named3�0
x4�4�Named4�0
x5�4�Named5�0
x6�4�Named6�0
x7�4�Named7�0
y1�4�Named1�0
y2�4�Named2�0
y3�4�Named3�0
y4�4�Named4�0
y5�4�Named5�0
y6�4�Named6�0
y7�4�Named7�0
yellow�4�Enum#0�0
z1�4�Named1�0
z2�4�Named2�0
z3�4�Named3�0
z4�4�Named4�0
z5�4�Named5�0
z6�4�Named6�0
z7�4�Named7�0
31 changes: 17 additions & 14 deletions tests/ctags/enumerators.f90.tags
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ Aster_colon
Aster_kind�2�Enums�0
BodyPart�2�Enums�0
Colons�2�Enums�0
Enum#0�2�Enums�0
Enum#1�2�Enums�0
Enums�256�0
Func�16�Enums�0
Name_colon�2�Enums�0
Paren_colon�2�Enums�0
Paren_kind�2�Enums�0
arm�4�Enums�0
b�4�Enums�0
blue�4�Enums�0
bronze�4�Enums�0
c�4�Enums�0
d�4�Enums�0
e�4�Enums�0
gold�4�Enums�0
leg�4�Enums�0
no_c_binding�4�Enums�0
arm�4�BodyPart�0
b�4�Paren_kind�0
blue�4�Enum#0�0
bronze�4�Enum#0�0
c�4�Aster_kind�0
d�4�Name_colon�0
d�4�Paren_colon�0
e�4�Aster_colon�0
gold�4�Enum#0�0
leg�4�BodyPart�0
no_c_binding�4�Enum#1�0
othervar�16384�Enums�0
purple�4�Enums�0
r�4�Enums�0
red�4�Enums�0
silver�4�Enums�0
purple�4�Enum#0�0
r�4�Colons�0
red�4�Enum#0�0
silver�4�Enum#0�0
somevar�16384�Enums�0
1 change: 1 addition & 0 deletions tests/ctags/numlib.f90.tags
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# format=tagmanager
Interface#0�32�numerical_libraries�0
numerical_libraries�256�0
2 changes: 2 additions & 0 deletions tests/ctags/recursive.f95.tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# format=tagmanager
Interface#0�32�approx�0
Interface#1�32�approx2�0
approx�256�0
approx2�256�0
parts�16384�approx�0
Expand Down
3 changes: 2 additions & 1 deletion tests/ctags/structure.f.tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# format=tagmanager
a�64�anonymous�0
Structure#0�1�nested�0
a�64�Structure#0�0
clouds�64�weather�0
day�64�weather�0
initialized_structure�2048�0
Expand Down

0 comments on commit ef4c725

Please sign in to comment.