Skip to content

Commit

Permalink
lregex: provide the way to intercept a parser making a tag
Browse files Browse the repository at this point in the history
TBW

Known issue: initForeignRefTagEntry doesn't work well.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed May 16, 2021
1 parent 1b4a608 commit 5831145
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 6 deletions.
13 changes: 9 additions & 4 deletions main/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "debug.h"
#include "dependency.h"
#include "entry.h"
#include "options.h"
#include "parse_p.h"
#include "read.h"
Expand Down Expand Up @@ -184,14 +185,18 @@ extern void notifyMakeTagEntry (const tagEntryInfo *tag, int corkIndex)
{
subparser *s;

/* running optscript code attaching to --makeTagEntryReflection-<LANG> */
langType lang = tag->langType;
notifyLanguageRegexMakeTagEntry (lang, corkIndex);

foreachSubparser(s, false)
{
enterSubparser(s);
if (s->makeTagEntryNotify)
{
enterSubparser(s);
s->makeTagEntryNotify (s, tag, corkIndex);
leaveSubparser();
}
/* propagate the event recursively */
notifyMakeTagEntry (tag, corkIndex);
leaveSubparser();
}
}

Expand Down
5 changes: 5 additions & 0 deletions main/dependency.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ struct sSlaveParser {
slaveParser *next;
};

/* These are for CPreProcessor.
* Don't use in the other parsers. */
extern void notifyInputStart (void);
extern void notifyInputEnd (void);

#endif /* CTAGS_MAIN_DEPENDENCY_H */
8 changes: 8 additions & 0 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,14 @@ extern void notifyRegexInputEnd (struct lregexControlBlock *lcb)
fillEndLineFieldOfUpperScopes (lcb, endline);
}

extern void notifyRegexMakeTagEntry (struct lregexControlBlock *lcb,
int corkIndex)
{
optscriptSetup (optvm, lcb->local_dict, corkIndex);
scriptEvalHook (optvm, lcb, SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION);
optscriptTeardown (optvm, lcb->local_dict);
}

extern void findRegexTagsMainloop (int (* driver)(void))
{
/* merely read all lines of the file */
Expand Down
1 change: 1 addition & 0 deletions main/lregex_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern bool matchMultitableRegex (struct lregexControlBlock *lcb, const vString*

extern void notifyRegexInputStart (struct lregexControlBlock *lcb);
extern void notifyRegexInputEnd (struct lregexControlBlock *lcb);
extern void notifyRegexMakeTagEntry (struct lregexControlBlock *lcb, int corkIndex);

extern void addRegexTable (struct lregexControlBlock *lcb, const char *name);
extern void extendRegexTable (struct lregexControlBlock *lcb, const char *src, const char *dist);
Expand Down
4 changes: 4 additions & 0 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ static optionDescription LongOptionDescription [] = {
{1,1," Define new extra for <LANG>. --extras-<LANG>=+{name} enables it."},
{1,1," --_fielddef-<LANG>=<name>,<description>"},
{1,1," Define new field for <LANG>."},
{1,1," --_makeTagEnryReflection-<LANG>={{ optscript-code }}"},
{1,1," Specify code run when <LANG> parser makes a tag."},
{1,1," --_mtable-extend-<LANG>=disttable+srctable."},
{1,1," Copy patterns of a regex table to another regex table."},
{1,1," --_mtable-regex-<LANG>=<table>/<line_pattern>/<name_pattern>/[<flags>]"},
Expand Down Expand Up @@ -3337,6 +3339,8 @@ static void processLongOption (
;
else if (processSequelOption (option, parameter))
;
else if (processMakeTagEntryReflectionOption (option, parameter))
;
else if (processPretendOption (option, parameter))
;
else if (processRolesOption (option, parameter))
Expand Down
1 change: 1 addition & 0 deletions main/options_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ extern bool processRoledefOption (const char *const option, const char *const pa
extern bool processScopesepOption (const char *const option, const char *const parameter);
extern bool processPreludeOption (const char *const option, const char *const parameter);
extern bool processSequelOption (const char *const option, const char *const parameter);
extern bool processMakeTagEntryReflectionOption (const char *const option, const char *const parameter);
extern bool processPretendOption (const char *const option, const char *const parameter);
extern bool processRolesOption (const char *const option, const char *const parameter);

Expand Down
10 changes: 10 additions & 0 deletions main/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3785,6 +3785,11 @@ extern void notifyLanguageRegexInputEnd (langType language)
notifyRegexInputEnd((LanguageTable + language)->lregexControlBlock);
}

extern void notifyLanguageRegexMakeTagEntry (langType language, int corkIndex)
{
notifyRegexMakeTagEntry((LanguageTable + language)->lregexControlBlock, corkIndex);
}

static unsigned int parserCorkFlags (parserDefinition *parser)
{
subparser *tmp;
Expand Down Expand Up @@ -5096,6 +5101,11 @@ extern bool processSequelOption (const char *const option, const char *const par
return processHookOption (option, parameter, "_sequel-", SCRIPT_HOOK_SEQUEL);
}

extern bool processMakeTagEntryReflectionOption (const char *const option, const char *const parameter)
{
return processHookOption (option, parameter, "_makeTagEntryReflection-", SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION);
}

extern bool processPretendOption (const char *const option, const char *const parameter)
{
langType new_language, old_language;
Expand Down
1 change: 1 addition & 0 deletions main/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef enum {
enum scriptHook {
SCRIPT_HOOK_PRELUDE,
SCRIPT_HOOK_SEQUEL,
SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION,
SCRIPT_HOOK_MAX,
};

Expand Down
1 change: 1 addition & 0 deletions main/parse_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ extern void freeEncodingResources (void);
extern bool processLanguageRegexOption (langType language, enum regexParserType regptype, const char *const parameter);
extern void notifyLanguageRegexInputStart (langType language);
extern void notifyLanguageRegexInputEnd (langType language);
extern void notifyLanguageRegexMakeTagEntry (langType language, int corkIndex);

extern void matchLanguageRegex (const langType language, const vString* const line);
extern void freeRegexResources (void);
Expand Down
2 changes: 0 additions & 2 deletions main/subparser_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ extern langType getSubparserLanguage (subparser *s);

/* A base parser doesn't have to call the following three functions.
The main part calls them internally. */
extern void notifyInputStart (void);
extern void notifyInputEnd (void);
extern void notifyMakeTagEntry (const tagEntryInfo *info, int corkIndex);

extern void setupSubparsersInUse (struct slaveControlBlock *controlBlock);
Expand Down
17 changes: 17 additions & 0 deletions parsers/cpreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string.h>

#include "debug.h"
#include "dependency.h" /* notifyInputStart, notifyInputEnd */
#include "entry.h"
#include "htable.h"
#include "cpreprocessor.h"
Expand Down Expand Up @@ -348,6 +349,14 @@ static void cppInitCommon(langType clientLang,
: clientLang) & CORK_SYMTAB))
? makeMacroTable ()
: NULL;

if (Cpp.lang != Cpp.clientLang
&& Cpp.clientLang != LANG_IGNORE)
{
pushLanguage (Cpp.lang);
notifyInputStart ();
popLanguage ();
}
}

extern void cppInit (const bool state, const bool hasAtLiteralStrings,
Expand Down Expand Up @@ -381,6 +390,14 @@ static void cppClearMacroInUse (cppMacroInfo **pM)

extern void cppTerminate (void)
{
if (Cpp.lang != Cpp.clientLang
&& Cpp.clientLang != LANG_IGNORE)
{
pushLanguage (Cpp.lang);
notifyInputEnd ();
popLanguage ();
}

if (Cpp.directive.name != NULL)
{
vStringDelete (Cpp.directive.name);
Expand Down

0 comments on commit 5831145

Please sign in to comment.