Skip to content

Commit ccac4df

Browse files
authored
Merge pull request #1579 from masatake/cleanup-kind-infra-stage-1
Use kind index instead of kind definition when initializing and making a tag
2 parents 2bc8de8 + 16a2541 commit ccac4df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1359
-1260
lines changed

main/entry.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ static void addCommonPseudoTags (void)
173173
}
174174
}
175175

176+
static kindDefinition *getInputLanguageFileKind (void)
177+
{
178+
return getLanguageKind (getInputLanguage (), KIND_FILE_INDEX);
179+
}
180+
176181
extern void makeFileTag (const char *const fileName)
177182
{
178183
tagEntryInfo tag;
@@ -185,7 +190,7 @@ extern void makeFileTag (const char *const fileName)
185190
Assert (kind);
186191
kind->enabled = true;
187192

188-
initTagEntry (&tag, baseFilename (fileName), kind);
193+
initTagEntry (&tag, baseFilename (fileName), KIND_FILE_INDEX);
189194

190195
tag.isFileEntry = true;
191196
tag.lineNumberEntry = true;
@@ -1304,7 +1309,9 @@ extern int makeTagEntry (const tagEntryInfo *const tag_const)
13041309

13051310
if (getInputLanguageFileKind() != tag->kind)
13061311
{
1307-
if (! isInputLanguageKindEnabled (tag->kind->letter) &&
1312+
/* TODO: don't access the internal of kind directly.
1313+
Use isInputLanguageKindEnabled () instead. */
1314+
if (! tag->kind->enabled &&
13081315
(tag->extensionFields.roleIndex == ROLE_INDEX_DEFINITION))
13091316
return CORK_NIL;
13101317
if ((tag->extensionFields.roleIndex != ROLE_INDEX_DEFINITION)
@@ -1409,29 +1416,29 @@ extern int makeQualifiedTagEntry (const tagEntryInfo *const e)
14091416
}
14101417

14111418
extern void initTagEntry (tagEntryInfo *const e, const char *const name,
1412-
const kindDefinition *kind)
1419+
int kindIndex)
14131420
{
14141421
initTagEntryFull(e, name,
14151422
getInputLineNumber (),
14161423
getInputLanguage (),
14171424
getInputFilePosition (),
14181425
getInputFileTagPath (),
1419-
kind,
1426+
kindIndex,
14201427
ROLE_INDEX_DEFINITION,
14211428
getSourceFileTagPath(),
14221429
getSourceLanguage(),
14231430
getSourceLineNumber() - getInputLineNumber ());
14241431
}
14251432

14261433
extern void initRefTagEntry (tagEntryInfo *const e, const char *const name,
1427-
const kindDefinition *kind, int roleIndex)
1434+
int kindIndex, int roleIndex)
14281435
{
14291436
initTagEntryFull(e, name,
14301437
getInputLineNumber (),
14311438
getInputLanguage (),
14321439
getInputFilePosition (),
14331440
getInputFileTagPath (),
1434-
kind,
1441+
kindIndex,
14351442
roleIndex,
14361443
getSourceFileTagPath(),
14371444
getSourceLanguage(),
@@ -1443,13 +1450,15 @@ extern void initTagEntryFull (tagEntryInfo *const e, const char *const name,
14431450
langType langType_,
14441451
MIOPos filePosition,
14451452
const char *inputFileName,
1446-
const kindDefinition *kind,
1453+
int kindIndex,
14471454
int roleIndex,
14481455
const char *sourceFileName,
14491456
langType sourceLangType,
14501457
long sourceLineNumberDifference)
14511458
{
14521459
int i;
1460+
kindDefinition *kind = getLanguageKind(langType_, kindIndex);
1461+
14531462
Assert (getInputFileName() != NULL);
14541463

14551464
memset (e, 0, sizeof (tagEntryInfo));

main/entry.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ extern void setupWriter (void);
126126
extern bool teardownWriter (const char *inputFilename);
127127
extern int makeTagEntry (const tagEntryInfo *const tag);
128128
extern void initTagEntry (tagEntryInfo *const e, const char *const name,
129-
const kindDefinition *kind);
129+
int kindIndex);
130130
extern void initRefTagEntry (tagEntryInfo *const e, const char *const name,
131-
const kindDefinition *kind, int roleIndex);
131+
int kindIndex, int roleIndex);
132132
extern void initTagEntryFull (tagEntryInfo *const e, const char *const name,
133133
unsigned long lineNumber,
134134
langType langType_,
135135
MIOPos filePosition,
136136
const char *inputFileName,
137-
const kindDefinition *kind,
137+
int kindIndex,
138138
int roleIndex,
139139
const char *sourceFileName,
140140
langType sourceLangType,

main/kind.c

+15
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,26 @@ extern int defineKind (struct kindControlBlock* kcb, kindDefinition *def,
143143
return def->id;
144144
}
145145

146+
extern bool isKindEnabled (struct kindControlBlock* kcb, int kindIndex)
147+
{
148+
return kcb->kind [kindIndex].def->enabled;
149+
}
150+
151+
extern bool isRoleEnabled (struct kindControlBlock* kcb, int kindIndex, int roleIndex)
152+
{
153+
return kcb->kind [kindIndex].def->roles[roleIndex].enabled;
154+
}
155+
146156
extern unsigned int countKinds (struct kindControlBlock* kcb)
147157
{
148158
return kcb->count;
149159
}
150160

161+
extern unsigned int countRoles (struct kindControlBlock* kcb, int kindIndex)
162+
{
163+
return kcb->kind [kindIndex].def->nRoles;
164+
}
165+
151166
extern kindDefinition *getKind (struct kindControlBlock* kcb, int kindIndex)
152167
{
153168
return kcb->kind [kindIndex].def;

main/kind.h

+3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ extern struct kindControlBlock* allocKindControlBlock (parserDefinition *parser)
9090
extern void freeKindControlBlock (struct kindControlBlock* kcb);
9191
extern int defineKind (struct kindControlBlock* kcb, kindDefinition *def,
9292
freeKindDefFunc freeKindDef);
93+
extern bool isKindEnabled (struct kindControlBlock* kcb, int kindIndex);
94+
extern bool isRoleEnabled (struct kindControlBlock* kcb, int kindIndex, int roleIndex);
9395
extern unsigned int countKinds (struct kindControlBlock* kcb);
96+
extern unsigned int countRoles (struct kindControlBlock* kcb, int kindIndex);
9497
extern kindDefinition *getKind (struct kindControlBlock* kcb, int kindIndex);
9598
extern kindDefinition *getKindForLetter (struct kindControlBlock* kcb, int letter);
9699
extern kindDefinition *getKindForName (struct kindControlBlock* kcb, const char* name);

main/lregex.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,13 @@ extern void freeLregexControlBlock (struct lregexControlBlock* lcb)
232232
*/
233233

234234
static bool initRegexTag (tagEntryInfo *e,
235-
const vString* const name, const kindDefinition* const kind, int scopeIndex, int placeholder,
235+
const vString* const name, int kindIndex, int scopeIndex, int placeholder,
236236
unsigned long line, MIOPos *pos, int xtag_type)
237237
{
238-
Assert (kind != NULL);
239-
if (kind->enabled)
238+
if (isInputLanguageKindEnabled (kindIndex))
240239
{
241240
Assert (name != NULL && ((vStringLength (name) > 0) || placeholder));
242-
initTagEntry (e, vStringValue (name), kind);
241+
initTagEntry (e, vStringValue (name), kindIndex);
243242
e->extensionFields.scopeIndex = scopeIndex;
244243
e->placeholder = !!placeholder;
245244
if (line)
@@ -1066,8 +1065,8 @@ static void matchTagPattern (struct lregexControlBlock *lcb,
10661065
{
10671066
unsigned long ln = 0;
10681067
MIOPos pos;
1069-
kindDefinition *kdef;
10701068
tagEntryInfo e;
1069+
int kind;
10711070

10721071
if ((patbuf->regptype == REG_PARSER_MULTI_LINE)
10731072
|| (patbuf->regptype == REG_PARSER_MULTI_TABLE))
@@ -1077,9 +1076,9 @@ static void matchTagPattern (struct lregexControlBlock *lcb,
10771076
}
10781077

10791078
n = CORK_NIL;
1080-
kdef = getLanguageKind (lcb->owner, patbuf->u.tag.kindIndex);
1079+
kind = patbuf->u.tag.kindIndex;
10811080

1082-
if (initRegexTag (&e, name, kdef, scope, placeholder,
1081+
if (initRegexTag (&e, name, kind, scope, placeholder,
10831082
ln, ln == 0? NULL: &pos, patbuf->xtagType))
10841083
{
10851084
static TrashBox* field_trashbox;

main/lxpath.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@ static void simpleXpathMakeTag (xmlNode *node,
2828
{
2929
tagEntryInfo tag;
3030
xmlChar* str;
31-
const kindDefinition *kind;
3231
char *path;
3332

3433
str = xmlNodeGetContent(node);
3534
if (str == NULL)
3635
return;
3736

38-
kind = kinds + spec->kind;
39-
4037
if (spec->role == ROLE_INDEX_DEFINITION)
41-
initTagEntry (&tag, (char *)str, kind);
38+
initTagEntry (&tag, (char *)str, spec->kind);
4239
else if (isXtagEnabled(XTAG_REFERENCE_TAGS))
4340
initRefTagEntry (&tag, (char *)str,
44-
kind,
41+
spec->kind,
4542
spec->role);
4643
else
4744
goto out;

main/parse.c

+29-18
Original file line numberDiff line numberDiff line change
@@ -142,34 +142,34 @@ extern unsigned int countParsers (void)
142142
}
143143

144144
extern int makeSimpleTag (
145-
const vString* const name, kindDefinition* const kinds, const int kind)
145+
const vString* const name, const int kindIndex)
146146
{
147147
int r = CORK_NIL;
148148

149-
if (kinds [kind].enabled && name != NULL && vStringLength (name) > 0)
149+
if (isInputLanguageKindEnabled(kindIndex) && name != NULL && vStringLength (name) > 0)
150150
{
151151
tagEntryInfo e;
152-
initTagEntry (&e, vStringValue (name), & kinds [kind]);
152+
initTagEntry (&e, vStringValue (name), kindIndex);
153153

154154
r = makeTagEntry (&e);
155155
}
156156
return r;
157157
}
158158

159-
extern int makeSimpleRefTag (const vString* const name, kindDefinition* const kinds, const int kind,
159+
extern int makeSimpleRefTag (const vString* const name, const int kindIndex,
160160
int roleIndex)
161161
{
162162
int r = CORK_NIL;
163163

164164
if (! isXtagEnabled (XTAG_REFERENCE_TAGS))
165165
return r;
166166

167-
Assert (roleIndex < kinds[kind].nRoles);
167+
Assert (roleIndex < countInputLanguageRoles(kindIndex));
168168

169-
if (kinds[kind].roles[roleIndex].enabled)
169+
if (isInputLanguageRoleEnabled(kindIndex, roleIndex))
170170
{
171171
tagEntryInfo e;
172-
initRefTagEntry (&e, vStringValue (name), & kinds [kind], roleIndex);
172+
initRefTagEntry (&e, vStringValue (name), kindIndex, roleIndex);
173173

174174
r = makeTagEntry (&e);
175175
}
@@ -249,6 +249,16 @@ extern int defineLanguageKind (const langType language, kindDefinition *def,
249249
return defineKind (LanguageTable [language].kindControlBlock, def, freeKindDef);
250250
}
251251

252+
extern unsigned int countLanguageKinds (const langType language)
253+
{
254+
return countKinds (LanguageTable [language].kindControlBlock);
255+
}
256+
257+
extern unsigned int countLanguageRoles (const langType language, int kindIndex)
258+
{
259+
return countRoles (LanguageTable [language].kindControlBlock, kindIndex);
260+
}
261+
252262
extern kindDefinition* getLanguageKind (const langType language, signed char kindIndex)
253263
{
254264
kindDefinition* kdef;
@@ -1900,16 +1910,17 @@ static kindDefinition *langKindLongOption (const langType language, const char *
19001910
return getKindForName (LanguageTable [language].kindControlBlock, kindLong);
19011911
}
19021912

1903-
extern bool isLanguageKindEnabled (const langType language, char kind)
1913+
extern bool isLanguageKindEnabled (const langType language, int kindIndex)
19041914
{
1905-
const kindDefinition *kindDef;
1906-
1907-
kindDef = langKindDefinition (language, kind);
1908-
Assert (kindDef);
1909-
1910-
return kindDef->enabled;
1915+
return isKindEnabled(LanguageTable [language].kindControlBlock,
1916+
kindIndex);
19111917
}
19121918

1919+
extern bool isLanguageRoleEnabled (const langType language, int kindIndex, int roleIndex)
1920+
{
1921+
return isRoleEnabled(LanguageTable [language].kindControlBlock,
1922+
kindIndex, roleIndex);
1923+
}
19131924

19141925
static void resetLanguageKinds (const langType language, const bool mode)
19151926
{
@@ -3866,23 +3877,23 @@ static void createCTSTTags (void)
38663877
switch (i)
38673878
{
38683879
case K_BROKEN:
3869-
initTagEntry (&e, "one\nof\rbroken\tname", &CTST_Kinds[i]);
3880+
initTagEntry (&e, "one\nof\rbroken\tname", i);
38703881
e.extensionFields.scopeKind = & (CTST_Kinds [K_BROKEN]);
38713882
e.extensionFields.scopeName = "\\Broken\tContext";
38723883
makeTagEntry (&e);
38733884
break;
38743885
case K_NO_LETTER:
3875-
initTagEntry (&e, "abnormal kindDefinition testing (no letter)", &CTST_Kinds[i]);
3886+
initTagEntry (&e, "abnormal kindDefinition testing (no letter)", i);
38763887
makeTagEntry (&e);
38773888
break;
38783889
case K_NO_LONG_NAME:
3879-
initTagEntry (&e, "abnormal kindDefinition testing (no long name)", &CTST_Kinds[i]);
3890+
initTagEntry (&e, "abnormal kindDefinition testing (no long name)", i);
38803891
makeTagEntry (&e);
38813892
break;
38823893
case K_NOTHING_SPECIAL:
38833894
if (!lb)
38843895
{
3885-
initTagEntry (&e, "NOTHING_SPECIAL", &CTST_Kinds[i]);
3896+
initTagEntry (&e, "NOTHING_SPECIAL", i);
38863897
makeTagEntry (&e);
38873898
}
38883899
break;

main/parse.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ extern parserDefinitionFunc YAML_PARSER_LIST;
138138

139139

140140
/* Language processing and parsing */
141-
extern int makeSimpleTag (const vString* const name, kindDefinition* const kinds, const int kind);
142-
extern int makeSimpleRefTag (const vString* const name, kindDefinition* const kinds, const int kind,
141+
extern int makeSimpleTag (const vString* const name, const int kindIndex);
142+
extern int makeSimpleRefTag (const vString* const name, const int kindIndex,
143143
int roleIndex);
144144
extern parserDefinition* parserNew (const char* name);
145145
extern bool doesLanguageAllowNullTag (const langType language);
@@ -150,10 +150,13 @@ extern kindDefinition* getLanguageKindForLetter (const langType language, char k
150150
extern kindDefinition* getLanguageKind(const langType language, signed char kindIndex);
151151
extern int defineLanguageKind (const langType language, kindDefinition *def,
152152
freeKindDefFunc freeKindDef);
153+
extern unsigned int countLanguageKinds (const langType language);
154+
extern unsigned int countLanguageRoles (const langType language, int kindIndex);
153155
extern langType getNamedLanguage (const char *const name, size_t len);
154156
extern langType getFileLanguage (const char *const fileName);
155157
extern bool isLanguageEnabled (const langType language);
156-
extern bool isLanguageKindEnabled (const langType language, char kind);
158+
extern bool isLanguageKindEnabled (const langType language, int kindIndex);
159+
extern bool isLanguageRoleEnabled (const langType language, int kindIndex, int roleIndex);
157160

158161
extern bool isLanguageVisible (const langType language);
159162

main/read.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,30 @@ extern bool isInputHeaderFile (void)
195195
return File.input.isHeader;
196196
}
197197

198-
extern bool isInputLanguageKindEnabled (char c)
198+
extern bool isInputLanguageKindEnabled (int kindIndex)
199199
{
200-
return isLanguageKindEnabled (getInputLanguage (), c);
200+
return isLanguageKindEnabled (getInputLanguage (), kindIndex);
201201
}
202202

203-
extern bool doesInputLanguageAllowNullTag (void)
203+
extern bool isInputLanguageRoleEnabled (int kindIndex, int roleIndex)
204204
{
205-
return doesLanguageAllowNullTag (getInputLanguage ());
205+
return isLanguageRoleEnabled (getInputLanguage (),
206+
kindIndex, roleIndex);
207+
}
208+
209+
extern unsigned int countInputLanguageKinds (void)
210+
{
211+
return countLanguageKinds (getInputLanguage ());
206212
}
207213

208-
extern kindDefinition *getInputLanguageFileKind (void)
214+
extern unsigned int countInputLanguageRoles (int kindIndex)
209215
{
210-
return getLanguageKind (getInputLanguage (), KIND_FILE_INDEX);
216+
return countLanguageRoles (getInputLanguage (), kindIndex);
217+
}
218+
219+
extern bool doesInputLanguageAllowNullTag (void)
220+
{
221+
return doesLanguageAllowNullTag (getInputLanguage ());
211222
}
212223

213224
extern bool doesInputLanguageRequestAutomaticFQTag (void)

main/read.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ extern const char *getInputLanguageName (void);
6464
extern const char *getInputFileTagPath (void);
6565
extern bool isInputLanguage (langType lang);
6666
extern bool isInputHeaderFile (void);
67-
extern bool isInputLanguageKindEnabled (char c);
67+
extern bool isInputLanguageKindEnabled (int kindIndex);
68+
69+
extern bool isInputLanguageRoleEnabled (int kindIndex, int roleIndex);
70+
extern unsigned int countInputLanguageKinds (void);
71+
extern unsigned int countInputLanguageRoles (int kindIndex);
72+
6873
extern bool doesInputLanguageAllowNullTag (void);
69-
extern kindDefinition *getInputLanguageFileKind (void);
7074
extern bool doesInputLanguageRequestAutomaticFQTag (void);
7175
extern bool doesParserRunAsGuest (void);
7276
extern bool doesSubparserRun (void);

0 commit comments

Comments
 (0)