[geany/geany] ae8dc5: Add keywordTable to parserDefinition and use a common way to initialize keywords

Jiří Techet git-noreply at xxxxx
Sat Sep 10 07:25:59 UTC 2016


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Fri, 29 Jul 2016 20:50:11 UTC
Commit:      ae8dc545cec1eb7e951d5c36d053615ea548b486
             https://github.com/geany/geany/commit/ae8dc545cec1eb7e951d5c36d053615ea548b486

Log Message:
-----------
Add keywordTable to parserDefinition and use a common way to initialize keywords


Modified Paths:
--------------
    ctags/main/parse.c
    ctags/main/parse.h
    ctags/parsers/asm.c
    ctags/parsers/fortran.c
    ctags/parsers/go.c
    ctags/parsers/jscript.c
    ctags/parsers/objc.c
    ctags/parsers/php.c
    ctags/parsers/sql.c
    ctags/parsers/vhdl.c

Modified: ctags/main/parse.c
39 lines changed, 35 insertions(+), 4 deletions(-)
===================================================================
@@ -19,6 +19,7 @@
 
 #include "mio.h"
 #include "entry.h"
+#include "keyword.h"
 #include "main.h"
 #define OPTION_WRITE
 #include "options.h"
@@ -293,12 +294,24 @@ extern void enableLanguage (const langType language, const boolean state)
 	LanguageTable [language]->enabled = state;
 }
 
+static void initializeParserOne (langType lang)
+{
+	parserDefinition *const parser = LanguageTable [lang];
+
+	installKeywordTable (lang);
+
+	if ((parser->initialize != NULL) && (parser->initialized == FALSE))
+	{
+		parser->initialize (lang);
+		parser->initialized = TRUE;
+	}
+}
+
 static void initializeParsers (void)
 {
-	unsigned int i;
-	for (i = 0  ;  i < LanguageCount  ;  ++i)
-		if (LanguageTable [i]->initialize != NULL)
-			(LanguageTable [i]->initialize) ((langType) i);
+	int i;
+	for (i = 0; i < LanguageCount;  i++)
+		initializeParserOne(i);
 }
 
 extern void initializeParsing (void)
@@ -654,4 +667,22 @@ extern boolean parseFile (const char *const fileName)
 	return tagFileResized;
 }
 
+extern void installKeywordTable (const langType language)
+{
+	parserDefinition* lang;
+	unsigned int i;
+
+	Assert (0 <= language  &&  language < (int) LanguageCount);
+	lang = LanguageTable [language];
+
+	if ((lang->keywordTable != NULL) && (lang->keywordInstalled == FALSE))
+	{
+		for (i = 0; i < lang->keywordCount; ++i)
+			addKeyword (lang->keywordTable [i].name,
+				    language,
+				    lang->keywordTable [i].id);
+		lang->keywordInstalled = TRUE;
+	}
+}
+
 /* vi:set tabstop=4 shiftwidth=4 nowrap: */


Modified: ctags/main/parse.h
7 lines changed, 7 insertions(+), 0 deletions(-)
===================================================================
@@ -65,6 +65,11 @@ typedef struct {
 	boolean enabled;            /* currently enabled? */
 	stringList* currentPatterns;    /* current list of file name patterns */
 	stringList* currentExtensions;  /* current list of extensions */
+	const keywordTable *keywordTable;
+	unsigned int keywordCount;
+
+	unsigned int initialized:1;    /* initialize() is called or not */
+	unsigned int keywordInstalled:1;  /* keywordTable is installed or not. */
 } parserDefinition;
 
 typedef parserDefinition* (parserDefinitionFunc) (void);
@@ -114,6 +119,8 @@ extern boolean processKindOption (const char *const option, const char *const pa
 extern void printKindOptions (void);
 extern boolean parseFile (const char *const fileName);
 
+extern void installKeywordTable (const langType language);
+
 /* Regex interface */
 #ifdef HAVE_REGEX
 extern void findRegexTags (void);


Modified: ctags/parsers/asm.c
14 lines changed, 2 insertions(+), 12 deletions(-)
===================================================================
@@ -110,17 +110,6 @@ static const opKind OpKinds [] = {
 /*
 *   FUNCTION DEFINITIONS
 */
-static void buildAsmKeywordHash (void)
-{
-	const size_t count = sizeof (AsmKeywords) / sizeof (AsmKeywords [0]);
-	size_t i;
-	for (i = 0  ;  i < count  ;  ++i)
-	{
-		const keywordTable* const p = AsmKeywords + i;
-		addKeyword (p->name, Lang_asm, (int) p->id);
-	}
-}
-
 static opKeyword analyzeOperator (const vString *const op)
 {
 	vString *keyword = vStringNew ();
@@ -353,7 +342,6 @@ static void findAsmTags (void)
 static void initialize (const langType language)
 {
 	Lang_asm = language;
-	buildAsmKeywordHash ();
 }
 
 extern parserDefinition* AsmParser (void)
@@ -375,6 +363,8 @@ extern parserDefinition* AsmParser (void)
 	def->patterns   = patterns;
 	def->parser     = findAsmTags;
 	def->initialize = initialize;
+	def->keywordTable = AsmKeywords;
+	def->keywordCount = ARRAY_SIZE (AsmKeywords);
 	return def;
 }
 


Modified: ctags/parsers/fortran.c
18 lines changed, 4 insertions(+), 14 deletions(-)
===================================================================
@@ -416,18 +416,6 @@ static boolean insideInterface (void)
 	return result;
 }
 
-static void buildFortranKeywordHash (const langType language)
-{
-	const size_t count =
-			sizeof (FortranKeywordTable) / sizeof (FortranKeywordTable [0]);
-	size_t i;
-	for (i = 0  ;  i < count  ;  ++i)
-	{
-		const keywordTable* const p = &FortranKeywordTable [i];
-		addKeyword (p->name, language, (int) p->id);
-	}
-}
-
 /*
 *   Tag generation functions
 */
@@ -2331,13 +2319,11 @@ static boolean findFortranTags (const unsigned int passCount)
 static void initializeFortran (const langType language)
 {
 	Lang_fortran = language;
-	buildFortranKeywordHash (language);
 }
 
 static void initializeF77 (const langType language)
 {
 	Lang_f77 = language;
-	buildFortranKeywordHash (language);
 }
 
 extern parserDefinition* FortranParser (void)
@@ -2355,6 +2341,8 @@ extern parserDefinition* FortranParser (void)
 	def->extensions = extensions;
 	def->parser2    = findFortranTags;
 	def->initialize = initializeFortran;
+	def->keywordTable = FortranKeywordTable;
+	def->keywordCount = ARRAY_SIZE (FortranKeywordTable);
 	return def;
 }
 
@@ -2373,6 +2361,8 @@ extern parserDefinition* F77Parser (void)
 	def->extensions = extensions;
 	def->parser2    = findFortranTags;
 	def->initialize = initializeF77;
+	def->keywordTable = FortranKeywordTable;
+	def->keywordCount = ARRAY_SIZE (FortranKeywordTable);
 	return def;
 }
 /* vi:set tabstop=4 shiftwidth=4: */


Modified: ctags/parsers/go.c
10 lines changed, 2 insertions(+), 8 deletions(-)
===================================================================
@@ -133,15 +133,7 @@ static boolean isIdentChar (const int c)
 
 static void initialize (const langType language)
 {
-	size_t i;
-	const size_t count =
-		sizeof (GoKeywordTable) / sizeof (GoKeywordTable[0]);
 	Lang_go = language;
-	for (i = 0; i < count; ++i)
-	{
-		const keywordTable *const p = &GoKeywordTable[i];
-		addKeyword (p->name, language, (int) p->id);
-	}
 }
 
 static tokenInfo *newToken (void)
@@ -837,5 +829,7 @@ extern parserDefinition *GoParser (void)
 	def->extensions = extensions;
 	def->parser = findGoTags;
 	def->initialize = initialize;
+	def->keywordTable = GoKeywordTable;
+	def->keywordCount = ARRAY_SIZE (GoKeywordTable);
 	return def;
 }


Modified: ctags/parsers/jscript.c
17 lines changed, 3 insertions(+), 14 deletions(-)
===================================================================
@@ -180,18 +180,6 @@ static boolean isIdentChar (const int c)
 		 c == '@' || c == '_' || c == '#');
 }
 
-static void buildJsKeywordHash (void)
-{
-	const size_t count = sizeof (JsKeywordTable) /
-		sizeof (JsKeywordTable [0]);
-	size_t i;
-	for (i = 0	;  i < count  ;  ++i)
-	{
-		const keywordTable* const p = &JsKeywordTable [i];
-		addKeyword (p->name, Lang_js, (int) p->id);
-	}
-}
-
 static tokenInfo *newToken (void)
 {
 	tokenInfo *const token = xMalloc (1, tokenInfo);
@@ -1888,9 +1876,8 @@ static void parseJsFile (tokenInfo *const token)
 
 static void initialize (const langType language)
 {
-	Assert (sizeof (JsKinds) / sizeof (JsKinds [0]) == JSTAG_COUNT);
+	Assert (ARRAY_SIZE (JsKinds) == JSTAG_COUNT);
 	Lang_js = language;
-	buildJsKeywordHash ();
 }
 
 static void findJsTags (void)
@@ -1923,6 +1910,8 @@ extern parserDefinition* JavaScriptParser (void)
 	def->kindCount	= ARRAY_SIZE (JsKinds);
 	def->parser		= findJsTags;
 	def->initialize = initialize;
+	def->keywordTable = JsKeywordTable;
+	def->keywordCount = ARRAY_SIZE (JsKeywordTable);
 
 	return def;
 }


Modified: ctags/parsers/objc.c
17 lines changed, 2 insertions(+), 15 deletions(-)
===================================================================
@@ -144,18 +144,6 @@ typedef struct _lexingState {
 	const unsigned char *cp;	/* position in stream */
 } lexingState;
 
-static void initKeywordHash (void)
-{
-	const size_t count = sizeof (objcKeywordTable) / sizeof (keywordTable);
-	size_t i;
-
-	for (i = 0; i < count; ++i)
-	{
-		addKeyword (objcKeywordTable[i].name, Lang_ObjectiveC,
-			(int) objcKeywordTable[i].id);
-	}
-}
-
 /*//////////////////////////////////////////////////////////////////////
 //// Lexing                                     */
 static boolean isNum (char c)
@@ -1133,8 +1121,6 @@ static void findObjcTags (void)
 static void objcInitialize (const langType language)
 {
 	Lang_ObjectiveC = language;
-
-	initKeywordHash ();
 }
 
 extern parserDefinition *ObjcParser (void)
@@ -1146,6 +1132,7 @@ extern parserDefinition *ObjcParser (void)
 	def->extensions = extensions;
 	def->parser = findObjcTags;
 	def->initialize = objcInitialize;
-
+	def->keywordTable = objcKeywordTable;
+	def->keywordCount = ARRAY_SIZE (objcKeywordTable);
 	return def;
 }


Modified: ctags/parsers/php.c
17 lines changed, 4 insertions(+), 13 deletions(-)
===================================================================
@@ -238,17 +238,6 @@ static struct {
 static vString *CurrentNamespace;
 
 
-static void buildPhpKeywordHash (const langType language)
-{
-	const size_t count = sizeof (PhpKeywordTable) / sizeof (PhpKeywordTable[0]);
-	size_t i;
-	for (i = 0; i < count ; i++)
-	{
-		const keywordTable* const p = &PhpKeywordTable[i];
-		addKeyword (p->name, language, (int) p->id);
-	}
-}
-
 static const char *accessToString (const accessType access)
 {
 	static const char *const names[COUNT_ACCESS] = {
@@ -1477,13 +1466,11 @@ static void findZephirTags (void)
 static void initializePhpParser (const langType language)
 {
 	Lang_php = language;
-	buildPhpKeywordHash (language);
 }
 
 static void initializeZephirParser (const langType language)
 {
 	Lang_zephir = language;
-	buildPhpKeywordHash (language);
 }
 
 extern parserDefinition* PhpParser (void)
@@ -1495,6 +1482,8 @@ extern parserDefinition* PhpParser (void)
 	def->extensions = extensions;
 	def->parser     = findPhpTags;
 	def->initialize = initializePhpParser;
+	def->keywordTable = PhpKeywordTable;
+	def->keywordCount = ARRAY_SIZE (PhpKeywordTable);
 	return def;
 }
 
@@ -1507,6 +1496,8 @@ extern parserDefinition* ZephirParser (void)
 	def->extensions = extensions;
 	def->parser     = findZephirTags;
 	def->initialize = initializeZephirParser;
+	def->keywordTable = PhpKeywordTable;
+	def->keywordCount = ARRAY_SIZE (PhpKeywordTable);
 	return def;
 }
 


Modified: ctags/parsers/sql.c
17 lines changed, 3 insertions(+), 14 deletions(-)
===================================================================
@@ -396,18 +396,6 @@ static boolean isMatchedEnd(tokenInfo *const token, int nest_lvl)
 	return terminated;
 }
 
-static void buildSqlKeywordHash (void)
-{
-	const size_t count = sizeof (SqlKeywordTable) /
-		sizeof (SqlKeywordTable [0]);
-	size_t i;
-	for (i = 0	;  i < count  ;  ++i)
-	{
-		const keywordTable* const p = &SqlKeywordTable [i];
-		addKeyword (p->name, Lang_sql, (int) p->id);
-	}
-}
-
 static tokenInfo *newToken (void)
 {
 	tokenInfo *const token = xMalloc (1, tokenInfo);
@@ -2335,9 +2323,8 @@ static void parseSqlFile (tokenInfo *const token)
 
 static void initialize (const langType language)
 {
-	Assert (sizeof (SqlKinds) / sizeof (SqlKinds [0]) == SQLTAG_COUNT);
+	Assert (ARRAY_SIZE (SqlKinds) == SQLTAG_COUNT);
 	Lang_sql = language;
-	buildSqlKeywordHash ();
 }
 
 static void findSqlTags (void)
@@ -2360,6 +2347,8 @@ extern parserDefinition* SqlParser (void)
 	def->extensions = extensions;
 	def->parser		= findSqlTags;
 	def->initialize = initialize;
+	def->keywordTable = SqlKeywordTable;
+	def->keywordCount = ARRAY_SIZE (SqlKeywordTable);
 	return def;
 }
 


Modified: ctags/parsers/vhdl.c
10 lines changed, 2 insertions(+), 8 deletions(-)
===================================================================
@@ -106,15 +106,7 @@ static keywordTable VhdlKeywordTable [] = {
 
 static void initialize (const langType language)
 {
-	size_t i;
-	const size_t count = sizeof (VhdlKeywordTable) /
-						 sizeof (VhdlKeywordTable [0]);
 	Lang_vhdl = language;
-	for (i = 0  ;  i < count  ;  ++i)
-	{
-		const keywordTable* const p = &VhdlKeywordTable [i];
-		addKeyword (p->name, language, (int) p->id);
-	}
 }
 
 static void vUngetc (int c)
@@ -292,6 +284,8 @@ extern parserDefinition* VhdlParser (void)
 	def->extensions = extensions;
 	def->parser     = findVhdlTags;
 	def->initialize = initialize;
+	def->keywordTable = VhdlKeywordTable;
+	def->keywordCount = ARRAY_SIZE (VhdlKeywordTable);
 	return def;
 }
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list