Skip to content

Commit

Permalink
Get rid of the file struct in TMTag, preparation for the union removal
Browse files Browse the repository at this point in the history
The union on TMTag is very confusing and rather dangerous. The fields
file/timestamp and line/lang overlap. Some implicit assumptions are made
in the code - timestamp is never set so when file is NULL, the file
struct should be used to get the lang member. Rather avoid using unions
and move the lang member to the entry struct together with the other
attributes.
  • Loading branch information
techee committed Oct 18, 2014
1 parent a7c6e07 commit 48725e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/symbols.c
Expand Up @@ -266,9 +266,10 @@ GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types, gin
for (j = 0; j < typedefs->len; ++j)
{
tag = TM_TAG(typedefs->pdata[j]);
/* tag->atts.file.lang contains (for some reason) the line of the tag if
* tag->atts.entry.file is not NULL */
tag_lang = (tag->atts.entry.file) ? tag->atts.entry.file->lang : tag->atts.file.lang;
/* tag->atts.file.lang contains the line of the tag if tag->atts.entry.file
* is not NULL (geany document); otherwise it's a global tag with lang
* information in tag->atts.entry.lang */
tag_lang = (tag->atts.entry.file) ? tag->atts.entry.file->lang : tag->atts.entry.lang;

/* the check for tag_lang == lang is necessary to avoid wrong type colouring of
* e.g. PHP classes in C++ files
Expand Down Expand Up @@ -351,7 +352,7 @@ GString *symbols_get_macro_list(gint lang)
{
tag = TM_TAG(tags->pdata[i]);
tag_lang = (tag->atts.entry.file) ?
tag->atts.entry.file->lang : tag->atts.file.lang;
tag->atts.entry.file->lang : tag->atts.entry.lang;

if (tag_lang == lang)
g_ptr_array_add(ftags, (gpointer) tags->pdata[i]);
Expand Down
2 changes: 1 addition & 1 deletion tagmanager/src/tm_tag.c
Expand Up @@ -583,7 +583,7 @@ TMTag *tm_tag_new_from_file(TMSourceFile *file, FILE *fp, gint mode, TMFileForma
TAG_FREE(tag);
return NULL;
}
tag->atts.file.lang = mode;
tag->atts.entry.lang = mode;
return tag;
}

Expand Down
11 changes: 4 additions & 7 deletions tagmanager/src/tm_tag.h
Expand Up @@ -129,7 +129,7 @@ typedef struct _TMTag
/** These are *real* tag attributes */
struct
{
TMSourceFile *file; /**< File in which the tag occurs */
TMSourceFile *file; /**< File in which the tag occurs; NULL for global tags */
gulong line; /**< Line number of the tag */
gboolean local; /**< Is the tag of local scope */
guint pointerOrder;
Expand All @@ -139,13 +139,10 @@ typedef struct _TMTag
char *var_type; /**< Variable type (maps to struct for typedefs) */
char access; /**< Access type (public/protected/private/etc.) */
char impl; /**< Implementation (e.g. virtual) */

langType lang; /**< Programming language of the file - set only for
global tags when the file member is NULL */
} entry;
/** These are pseudo tag attributes representing a file */
struct
{
time_t timestamp; /**< Time of parsing of the file */
langType lang; /**< Programming language of the file */
} file;
} atts;
gint refcount; /**< the reference count of the tag */
} TMTag;
Expand Down
4 changes: 2 additions & 2 deletions tagmanager/src/tm_workspace.c
Expand Up @@ -639,7 +639,7 @@ const GPtrArray *tm_workspace_find(const char *name, int type, TMTagAttrType *at
int tags_lang_alt = 0;
/* tag->atts.file.lang contains the language and
* tags->atts.entry.file is NULL */
tags_lang = (*matches[1])->atts.file.lang;
tags_lang = (*matches[1])->atts.entry.lang;
/* tags_lang_alt is used to load C global tags only once for C and C++
* lang = 1 is C++, lang = 0 is C
* if we have lang 0, than accept also lang 1 for C++ */
Expand Down Expand Up @@ -682,7 +682,7 @@ static gboolean match_langs(gint lang, const TMTag *tag)
}
else
{ /* global tag */
if (lang == tag->atts.file.lang)
if (lang == tag->atts.entry.lang)
return TRUE;
}
return FALSE;
Expand Down

0 comments on commit 48725e4

Please sign in to comment.