Skip to content

Commit c06d333

Browse files
authored
Merge pull request #4263 from masatake/misc-fix
Misc. fixes
2 parents 3f3285c + b1aa722 commit c06d333

File tree

6 files changed

+92
-136
lines changed

6 files changed

+92
-136
lines changed

main/lokeninfo.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

main/options.c

Lines changed: 47 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,64 +2188,45 @@ static void processListLanguagesOption (
21882188
exit (0);
21892189
}
21902190

2191-
static void processListPseudoTagsOptions (
2192-
const char *const option CTAGS_ATTR_UNUSED,
2193-
const char *const parameter CTAGS_ATTR_UNUSED)
2194-
{
2195-
printPtags (localOption.withListHeader, localOption.machinable, stdout);
2196-
exit (0);
2197-
}
2198-
2199-
static void processListRegexFlagsOptions (
2200-
const char *const option CTAGS_ATTR_UNUSED,
2201-
const char *const parameter)
2202-
{
2203-
printRegexFlags (localOption.withListHeader, localOption.machinable, parameter, stdout);
2204-
exit (0);
2205-
}
2206-
2207-
static void processListMultilineRegexFlagsOptions (
2208-
const char *const option CTAGS_ATTR_UNUSED,
2209-
const char *const parameter)
2210-
{
2211-
printMultilineRegexFlags (localOption.withListHeader, localOption.machinable, parameter, stdout);
2212-
exit (0);
2213-
}
2214-
2215-
static void processListMultitableRegexFlagsOptions (
2216-
const char *const option CTAGS_ATTR_UNUSED,
2217-
const char *const parameter)
2218-
{
2219-
printMultitableRegexFlags (localOption.withListHeader, localOption.machinable, parameter, stdout);
2220-
exit (0);
2221-
}
2222-
2223-
static void processListLangdefFlagsOptions (
2224-
const char *const option CTAGS_ATTR_UNUSED,
2225-
const char *const parameter CTAGS_ATTR_UNUSED)
2226-
{
2227-
printLangdefFlags (localOption.withListHeader, localOption.machinable, stdout);
2228-
exit (0);
2229-
}
2230-
2231-
static void processListKinddefFlagsOptions (
2232-
const char *const option CTAGS_ATTR_UNUSED,
2233-
const char *const parameter CTAGS_ATTR_UNUSED)
2234-
{
2235-
printKinddefFlags (localOption.withListHeader, localOption.machinable, stdout);
2236-
exit (0);
2237-
}
2191+
#define defineListFunctionForOption(target,proc) \
2192+
attr__noreturn \
2193+
static void processList##target##Option ( \
2194+
const char *const option CTAGS_ATTR_UNUSED, \
2195+
const char *const parameter CTAGS_ATTR_UNUSED) \
2196+
{ \
2197+
proc (localOption.withListHeader, localOption.machinable, stdout); \
2198+
exit (0); \
2199+
} attr__noreturn static void processList##target##Option ( \
2200+
const char *const option CTAGS_ATTR_UNUSED, \
2201+
const char *const parameter CTAGS_ATTR_UNUSED) /* So we cat put ';' at the end of macro expansion. */
2202+
2203+
#define defineListFunctionForOptionWithParameter(target,proc) \
2204+
attr__noreturn \
2205+
static void processList##target##Option ( \
2206+
const char *const option CTAGS_ATTR_UNUSED, \
2207+
const char *const parameter) \
2208+
{ \
2209+
proc (localOption.withListHeader, localOption.machinable, parameter, stdout); \
2210+
exit (0); \
2211+
} attr__noreturn static void processList##target##Option ( \
2212+
const char *const option CTAGS_ATTR_UNUSED, \
2213+
const char *const parameter) /* So we cat put ';' at the end of macro expansion. */
2214+
2215+
defineListFunctionForOption (PseudoTags, printPtags);
2216+
2217+
defineListFunctionForOptionWithParameter (RegexFlags, printRegexFlags);
2218+
defineListFunctionForOptionWithParameter (MultilineRegexFlags, printMultilineRegexFlags);
2219+
defineListFunctionForOptionWithParameter (MultitableRegexFlags, printMultitableRegexFlags);
2220+
2221+
defineListFunctionForOption (LangdefFlags, printLangdefFlags);
2222+
defineListFunctionForOption (KinddefFlags, printKinddefFlags);
2223+
defineListFunctionForOption (FielddefFlags, printFielddefFlags);
2224+
2225+
defineListFunctionForOption (OutputFormats, printOutputFormats);
22382226

2239-
static void processListFielddefFlagsOptions (
2240-
const char *const option CTAGS_ATTR_UNUSED,
2241-
const char *const parameter CTAGS_ATTR_UNUSED)
2242-
{
2243-
printFielddefFlags (localOption.withListHeader, localOption.machinable, stdout);
2244-
exit (0);
2245-
}
22462227

22472228
attr__noreturn
2248-
static void processListRolesOptions (const char *const option CTAGS_ATTR_UNUSED,
2229+
static void processListRolesOption (const char *const option CTAGS_ATTR_UNUSED,
22492230
const char *const parameter)
22502231
{
22512232
const char* sep;
@@ -2268,7 +2249,7 @@ static void processListRolesOptions (const char *const option CTAGS_ATTR_UNUSED,
22682249
{
22692250
vString* vstr = vStringNewInit (parameter);
22702251
vStringCatS (vstr, (sep? "*": ".*"));
2271-
processListRolesOptions (option, vStringValue (vstr));
2252+
processListRolesOption (option, vStringValue (vstr));
22722253
/* The control should never reached here. */
22732254
}
22742255

@@ -2294,7 +2275,7 @@ static void processListRolesOptions (const char *const option CTAGS_ATTR_UNUSED,
22942275
exit (0);
22952276
}
22962277

2297-
static void processListSubparsersOptions (const char *const option CTAGS_ATTR_UNUSED,
2278+
static void processListSubparsersOption (const char *const option CTAGS_ATTR_UNUSED,
22982279
const char *const parameter)
22992280
{
23002281
langType lang;
@@ -2327,13 +2308,6 @@ static void processListOperators (const char *const option CTAGS_ATTR_UNUSED,
23272308
exit (0);
23282309
}
23292310

2330-
static void processListOutputFormatsOption(const char *const option CTAGS_ATTR_UNUSED,
2331-
const char *const parameter CTAGS_ATTR_UNUSED)
2332-
{
2333-
printOutputFormats (localOption.withListHeader, localOption.machinable, stdout);
2334-
exit (0);
2335-
}
2336-
23372311
static void freeSearchPathList (searchPathList** pathList)
23382312
{
23392313
stringListClear (*pathList);
@@ -2918,13 +2892,13 @@ static parametricOption ParametricOptions [] = {
29182892
{ "list-maps", processListMapsOption, true, STAGE_ANY },
29192893
{ "list-map-extensions", processListMapExtensionsOption, true, STAGE_ANY },
29202894
{ "list-map-patterns", processListMapPatternsOption, true, STAGE_ANY },
2921-
{ "list-mline-regex-flags", processListMultilineRegexFlagsOptions, true, STAGE_ANY },
2895+
{ "list-mline-regex-flags", processListMultilineRegexFlagsOption, true, STAGE_ANY },
29222896
{ "list-output-formats", processListOutputFormatsOption, true, STAGE_ANY },
29232897
{ "list-params", processListParametersOption, true, STAGE_ANY },
2924-
{ "list-pseudo-tags", processListPseudoTagsOptions, true, STAGE_ANY },
2925-
{ "list-regex-flags", processListRegexFlagsOptions, true, STAGE_ANY },
2926-
{ "list-roles", processListRolesOptions, true, STAGE_ANY },
2927-
{ "list-subparsers", processListSubparsersOptions, true, STAGE_ANY },
2898+
{ "list-pseudo-tags", processListPseudoTagsOption, true, STAGE_ANY },
2899+
{ "list-regex-flags", processListRegexFlagsOption, true, STAGE_ANY },
2900+
{ "list-roles", processListRolesOption, true, STAGE_ANY },
2901+
{ "list-subparsers", processListSubparsersOption, true, STAGE_ANY },
29282902
{ "maxdepth", processMaxRecursionDepthOption, true, STAGE_ANY },
29292903
{ "optlib-dir", processOptlibDir, false, STAGE_ANY },
29302904
{ "options", processOptionFile, false, STAGE_ANY },
@@ -2946,10 +2920,10 @@ static parametricOption ParametricOptions [] = {
29462920
#ifdef HAVE_JANSSON
29472921
{ "_interactive", processInteractiveOption, true, STAGE_ANY },
29482922
#endif
2949-
{ "_list-fielddef-flags", processListFielddefFlagsOptions,true, STAGE_ANY },
2950-
{ "_list-kinddef-flags", processListKinddefFlagsOptions, true, STAGE_ANY },
2951-
{ "_list-langdef-flags", processListLangdefFlagsOptions, true, STAGE_ANY },
2952-
{ "_list-mtable-regex-flags", processListMultitableRegexFlagsOptions, true, STAGE_ANY },
2923+
{ "_list-fielddef-flags", processListFielddefFlagsOption, true, STAGE_ANY },
2924+
{ "_list-kinddef-flags", processListKinddefFlagsOption, true, STAGE_ANY },
2925+
{ "_list-langdef-flags", processListLangdefFlagsOption, true, STAGE_ANY },
2926+
{ "_list-mtable-regex-flags", processListMultitableRegexFlagsOption, true, STAGE_ANY },
29532927
{ "_list-operators", processListOperators, true, STAGE_ANY },
29542928
#ifdef DO_TRACING
29552929
{ "_trace", processTraceOption, false, STAGE_ANY },

main/parse.c

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ static flagDefinition PreLangDefFlagDef [] = {
23172317
{ '\0', "_foreignLanguage", NULL, pre_lang_def_flag_foreignLanguage_long,
23182318
"LANG", "initialize another parser" },
23192319
{ '\0', "version", NULL, pre_lang_def_flag_version_long,
2320-
NULL, "set the version of the parser (current.age)"},
2320+
"CURRENT.AGE", "set the version of the parser"},
23212321
};
23222322

23232323
static void optlibFreeDep (langType lang, bool initialized CTAGS_ATTR_UNUSED)
@@ -2809,8 +2809,8 @@ static bool processLangDefineKind(const langType language,
28092809
kdef->letter = letter;
28102810
kdef->name = name;
28112811
kdef->description = description;
2812-
if (flags)
2813-
flagsEval (flags, PreKindDefFlagDef, ARRAY_SIZE (PreKindDefFlagDef), kdef);
2812+
2813+
flagsEval (flags, PreKindDefFlagDef, ARRAY_SIZE (PreKindDefFlagDef), kdef);
28142814

28152815
defineKind (parser->kindControlBlock, kdef, freeKdef);
28162816
return true;
@@ -2919,8 +2919,7 @@ static bool processLangDefineRole(const langType language,
29192919
rdef->name = name;
29202920
rdef->description = description;
29212921

2922-
if (flags)
2923-
flagsEval (flags, NULL, 0, rdef);
2922+
flagsEval (flags, NULL, 0, rdef);
29242923

29252924
defineRole (parser->kindControlBlock, kdef->id, rdef, freeRdef);
29262925

@@ -3589,8 +3588,7 @@ static bool processLangDefineParam (const langType language,
35893588
pdef->name = eStrndup (parameter, name_end - parameter);
35903589
pdef->desc = desc;
35913590

3592-
if (flags)
3593-
flagsEval (flags, NULL, 0, pdef);
3591+
flagsEval (flags, NULL, 0, pdef);
35943592

35953593
parser = LanguageTable + language;
35963594
defineParam (parser->paramControlBlock, pdef, freePdef);
@@ -3997,8 +3995,7 @@ static bool processLangDefineExtra (const langType language,
39973995
xdef->isEnabled = NULL;
39983996
DEFAULT_TRASH_BOX(xdef, xtagDefinitionDestroy);
39993997

4000-
if (flags)
4001-
flagsEval (flags, NULL, 0, xdef);
3998+
flagsEval (flags, NULL, 0, xdef);
40023999

40034000
defineXtag (xdef, language);
40044001

@@ -4092,8 +4089,7 @@ static bool processLangDefineField (const langType language,
40924089
fdef->description = desc;
40934090

40944091
fdef->dataType = 0;
4095-
if (flags)
4096-
flagsEval (flags, FieldDefFlagDef, ARRAY_SIZE (FieldDefFlagDef), fdef);
4092+
flagsEval (flags, FieldDefFlagDef, ARRAY_SIZE (FieldDefFlagDef), fdef);
40974093
if (!fdef->dataType)
40984094
fdef->dataType = FIELDTYPE_STRING;
40994095

@@ -5396,41 +5392,19 @@ extern void printLanguageSubparsers (const langType language,
53965392
colprintTableDelete (table);
53975393
}
53985394

5399-
extern void printLangdefFlags (bool withListHeader, bool machinable, FILE *fp)
5400-
{
5401-
struct colprintTable * table;
5402-
5403-
table = flagsColprintTableNew ();
5404-
5405-
flagsColprintAddDefinitions (table, PreLangDefFlagDef, ARRAY_SIZE (PreLangDefFlagDef));
5406-
5407-
flagsColprintTablePrint (table, withListHeader, machinable, fp);
5408-
colprintTableDelete(table);
5409-
}
5410-
5411-
extern void printKinddefFlags (bool withListHeader, bool machinable, FILE *fp)
5412-
{
5413-
struct colprintTable * table;
5414-
5415-
table = flagsColprintTableNew ();
5416-
5417-
flagsColprintAddDefinitions (table, PreKindDefFlagDef, ARRAY_SIZE (PreKindDefFlagDef));
5418-
5419-
flagsColprintTablePrint (table, withListHeader, machinable, fp);
5420-
colprintTableDelete(table);
5421-
}
5395+
#define defineSimplePrintFLagsFunction(target, flagDef) \
5396+
extern void print##target##Flags (bool withListHeader, bool machinable, FILE *fp) \
5397+
{ \
5398+
struct colprintTable * table = flagsColprintTableNew(); \
5399+
flagsColprintAddDefinitions (table, flagDef, ARRAY_SIZE (flagDef)); \
5400+
flagsColprintTablePrint (table, withListHeader, machinable, fp); \
5401+
colprintTableDelete(table); \
5402+
} extern void print##target##Flags (bool withListHeader, bool machinable, FILE *fp \
5403+
) /* So we can put ';' here. */
54225404

5423-
extern void printFielddefFlags (bool withListHeader, bool machinable, FILE *fp)
5424-
{
5425-
struct colprintTable * table;
5426-
5427-
table = flagsColprintTableNew ();
5428-
5429-
flagsColprintAddDefinitions (table, FieldDefFlagDef, ARRAY_SIZE (FieldDefFlagDef));
5430-
5431-
flagsColprintTablePrint (table, withListHeader, machinable, fp);
5432-
colprintTableDelete(table);
5433-
}
5405+
defineSimplePrintFLagsFunction(Langdef, PreLangDefFlagDef);
5406+
defineSimplePrintFLagsFunction(Kinddef, PreKindDefFlagDef);
5407+
defineSimplePrintFLagsFunction(Fielddef, FieldDefFlagDef);
54345408

54355409
extern void printLanguageMultitableStatistics (langType language)
54365410
{

main/tokeninfo.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ void tokenUnread (tokenInfo *token)
180180
tokenUnreadFull (token, NULL);
181181
}
182182

183+
static int tokenGetRightSideOfPair (tokenInfo *token)
184+
{
185+
int start = token->type;
186+
for (unsigned i = 0; i < token->klass->pairCount; i++)
187+
if (start == token->klass->pairs[i].start)
188+
return token->klass->pairs[i].end;
189+
190+
return token->klass->typeForUndefined;
191+
}
192+
183193
bool tokenSkipOverPair (tokenInfo *token)
184194
{
185195
return tokenSkipOverPairFull(token, NULL);
@@ -189,11 +199,8 @@ bool tokenSkipOverPairFull (tokenInfo *token, void *data)
189199
{
190200
int start = token->type;
191201
int end = token->klass->typeForUndefined;
192-
unsigned int i;
193202

194-
for (i = 0; i < token->klass->pairCount; i++)
195-
if (start == token->klass->pairs[i].start)
196-
end = token->klass->pairs[i].end;
203+
end = tokenGetRightSideOfPair (token);
197204

198205
if (end == token->klass->typeForUndefined)
199206
return false;

misc/ctags-optlib-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
("^[[:space:]]*--\\(langdef\\)=\\([a-zA-Z0-9]+\\)"
3636
(1 font-lock-keyword-face t)
3737
(2 font-lock-type-face t))
38-
("^[[:space:]]*--\\(map\\|alias\\|_?prelude\\|_?scopesep\\)-\\([a-zA-Z0-9]+\\)=.*"
38+
("^[[:space:]]*--\\(map\\|alias\\|_?prelude\\|_?scopesep\\|__selector\\)-\\([a-zA-Z0-9]+\\)=.*"
3939
(1 font-lock-keyword-face t)
4040
(2 font-lock-type-face t))
4141
;;

misc/optlib2c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ my $langdef_flags =
5858
} ],
5959
];
6060

61+
my $kinddef_flags =
62+
[
63+
[ qr/\{_refonly\}/, sub {
64+
$_[0]->{'refonly'} = 1;
65+
} ],
66+
];
67+
6168
my $fielddef_flags =
6269
[
6370
[ qr/\{datatype=([^\}]+)\}/, sub {
@@ -126,7 +133,7 @@ my $options =
126133

127134
return 1;
128135
} ],
129-
[ qr/^--kinddef-(.*)=([^,]),([^,]+),([^\{]+)(\{_refonly\})?/, sub {
136+
[ qr/^--kinddef-(.*)=([^,]),([^,]+),([^\{]+)(.*)/, sub {
130137
die "Don't use --kinddef-<LANG>=+ option before defining the language"
131138
if (! defined $_[0]->{'langdef'});
132139
die "Adding a kind is allowed only to the language specified with --langdef: $1"
@@ -135,8 +142,7 @@ my $options =
135142
my $letter = $2;
136143
my $name = $3;
137144
my $desc = $4;
138-
my $refonly = 0;
139-
$refonly = 1 if defined $5;
145+
my $rest = $5;
140146

141147
die "'F' as a kind letter is reserved for file kind."
142148
if ($letter eq 'F');
@@ -150,8 +156,11 @@ my $options =
150156
die "Letters used in kind name other than initial letter must be alphanumeric characters: $name"
151157
unless (substr ($name, 1) =~ /^[a-zA-Z0-9]+$/);
152158

153-
push @{$_[0]->{'kinddefs'}}, { enabled => 1, letter => $letter, name => $name, desc => $desc,
154-
refonly => $refonly, roles => [], seps => [] };
159+
my $kdef = { enabled => 1, letter => $letter, name => $name, desc => $desc,
160+
refonly => 0, roles => [], seps => [] };
161+
push @{$_[0]->{'kinddefs'}}, $kdef;
162+
parse_flags ($rest, $kdef, $kinddef_flags);
163+
155164
return 1;
156165
} ],
157166
[ qr/^--_extradef-(.*)=([^,]+),([^\{]+)/, sub {

0 commit comments

Comments
 (0)