From 5030f7f3da945c0caeb42e090991ad362d30a743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sat, 13 Feb 2016 01:43:35 +0100 Subject: [PATCH] Cleanup NONE/AUTO filetype definitions At the moment the Geany code uses arbitrary combination of the following synonyms TM_PARSER_NONE / LANG_IGNORE / -2 TM_PARSER_AUTO / LANG_AUTO / -1 Especially using just the numbers makes things very confusing. In the Geany code this patch replaces all occurrences of -2 and LANG_IGNORE with TM_PARSER_NONE. It also removes LANG_IGNORE from the header which isn't needed any more. In addition, TM_PARSER_AUTO/LANG_AUTO shouldn't be used at all. We want filetype detection based on Geany's definitions and not based on the hard-coded ctags definitions. Remove it completely. Finally, as it's clearer now what the constants mean, the patch fixes the implementation of langs_compatible() (tag or file can never be of type AUTO but we should rather check for NONE filetypes which we should consider incompatible between each other). --- src/filetypes.c | 2 +- src/symbols.c | 4 ++-- tagmanager/src/tm_parser.h | 9 +-------- tagmanager/src/tm_source_file.c | 19 ++++++------------- tagmanager/src/tm_workspace.c | 7 ++++--- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/filetypes.c b/src/filetypes.c index 218d24383b..8a8601a424 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -202,7 +202,7 @@ static GeanyFiletype *filetype_new(void) GeanyFiletype *ft = g_new0(GeanyFiletype, 1); ft->group = GEANY_FILETYPE_GROUP_NONE; - ft->lang = -2; /* assume no tagmanager parser */ + ft->lang = TM_PARSER_NONE; /* assume no tagmanager parser */ /* pattern must not be null */ ft->pattern = g_new0(gchar*, 1); ft->indent_width = -1; diff --git a/src/symbols.c b/src/symbols.c index db37514515..f7217519d3 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -295,8 +295,8 @@ GString *symbols_find_typenames_as_string(gint lang, gboolean global) /* the check for tag_lang == lang is necessary to avoid wrong type colouring of * e.g. PHP classes in C++ files - * lang = -2 disables the check */ - if (tag->name && (tag_lang == lang || lang == -2 || + * lang = TM_PARSER_NONE disables the check */ + if (tag->name && (tag_lang == lang || lang == TM_PARSER_NONE || (lang == TM_PARSER_CPP && tag_lang == TM_PARSER_C))) { if (j != 0) diff --git a/tagmanager/src/tm_parser.h b/tagmanager/src/tm_parser.h index 2e0edaceb8..6d859e0ab9 100644 --- a/tagmanager/src/tm_parser.h +++ b/tagmanager/src/tm_parser.h @@ -10,18 +10,11 @@ #ifndef TM_PARSER_H #define TM_PARSER_H -#ifndef LIBCTAGS_DEFINED -/* from ctags/parse.h */ -# define LANG_AUTO (-1) -# define LANG_IGNORE (-2) -#endif - /* keep in sync with ctags/parsers.h */ typedef enum { - TM_PARSER_NONE = LANG_IGNORE, - TM_PARSER_AUTO = LANG_AUTO, + TM_PARSER_NONE = -2, /* keep in sync with ctags LANG_IGNORE */ TM_PARSER_C = 0, TM_PARSER_CPP, TM_PARSER_JAVA, diff --git a/tagmanager/src/tm_source_file.c b/tagmanager/src/tm_source_file.c index af3d6499c5..9ba2398b85 100644 --- a/tagmanager/src/tm_source_file.c +++ b/tagmanager/src/tm_source_file.c @@ -34,6 +34,7 @@ #define LIBCTAGS_DEFINED #include "tm_source_file.h" #include "tm_tag.h" +#include "tm_parser.h" typedef struct { @@ -193,7 +194,7 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_ } if (name == NULL) - source_file->lang = LANG_AUTO; + source_file->lang = TM_PARSER_NONE; else source_file->lang = getNamedLanguage(name); @@ -203,7 +204,7 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_ /** Initializes a TMSourceFile structure and returns a pointer to it. The * TMSourceFile has to be added to TMWorkspace to start its parsing. * @param file_name The file name. - * @param name Name of the used programming language, NULL for autodetection. + * @param name Name of the used programming language, NULL to disable parsing. * @return The created unparsed TMSourceFile object. * */ GEANY_API_SYMBOL @@ -297,7 +298,7 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize return FALSE; } - if (source_file->lang == LANG_IGNORE) + if (source_file->lang == TM_PARSER_NONE) { tm_tags_array_free(source_file->tags_array, FALSE); return FALSE; @@ -342,15 +343,7 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; } current_source_file = source_file; - if (LANG_AUTO == source_file->lang) - source_file->lang = getFileLanguage (file_name); - if (source_file->lang == LANG_IGNORE) - { -#ifdef TM_DEBUG - g_warning("ignoring %s (unknown language)\n", file_name); -#endif - } - else if (! LanguageTable [source_file->lang]->enabled) + if (! LanguageTable [source_file->lang]->enabled) { #ifdef TM_DEBUG g_warning("ignoring %s (language disabled)\n", file_name); @@ -422,7 +415,7 @@ const gchar *tm_source_file_get_lang_name(gint lang) /* Gets the language index for \a name. @param name The language name. - @return The language index, or -2. + @return The language index, or TM_PARSER_NONE. */ gint tm_source_file_get_named_lang(const gchar *name) { diff --git a/tagmanager/src/tm_workspace.c b/tagmanager/src/tm_workspace.c index b20ed8d79d..fc4b7453a0 100644 --- a/tagmanager/src/tm_workspace.c +++ b/tagmanager/src/tm_workspace.c @@ -193,8 +193,7 @@ void tm_workspace_add_source_file_noupdate(TMSourceFile *source_file) you're editing. It's useful for a "real-time" updating of the tags. The tags array and the tags themselves are destroyed and re-created, hence any other tag arrays pointing to these tags should be rebuilt as well. All sorting - information is also lost. The language parameter is automatically detected - the first time the file is parsed if it is set to LANG_AUTO. + information is also lost. @param source_file The source file to update with a buffer. @param text_buf A text buffer. The user should take care of allocate and free it after the use here. @@ -688,7 +687,9 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i static gboolean langs_compatible(langType lang, langType other) { - if (lang == other || lang == -1 || other == -1) + if (lang == TM_PARSER_NONE || other == TM_PARSER_NONE) + return FALSE; + if (lang == other) return TRUE; /* Accept CPP tags for C lang and vice versa */ else if (lang == TM_PARSER_C && other == TM_PARSER_CPP)