diff --git a/main/dependency.c b/main/dependency.c index 98955d06f3..483ac35694 100644 --- a/main/dependency.c +++ b/main/dependency.c @@ -14,6 +14,7 @@ #include "debug.h" #include "dependency.h" +#include "entry.h" #include "options.h" #include "parse_p.h" #include "read.h" @@ -184,14 +185,18 @@ extern void notifyMakeTagEntry (const tagEntryInfo *tag, int corkIndex) { subparser *s; + /* running optscript code attaching to --makeTagEntryReflection- */ + 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(); } } diff --git a/main/dependency.h b/main/dependency.h index bdeb71ab92..a485fb152a 100644 --- a/main/dependency.h +++ b/main/dependency.h @@ -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 */ diff --git a/main/lregex.c b/main/lregex.c index fad3e6388e..a41b199eb3 100644 --- a/main/lregex.c +++ b/main/lregex.c @@ -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 */ diff --git a/main/lregex_p.h b/main/lregex_p.h index d8b57f6d15..eaa83aabb9 100644 --- a/main/lregex_p.h +++ b/main/lregex_p.h @@ -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); diff --git a/main/options.c b/main/options.c index 7afd119b57..61ae45b654 100644 --- a/main/options.c +++ b/main/options.c @@ -377,6 +377,8 @@ static optionDescription LongOptionDescription [] = { {1,1," Define new extra for . --extras-=+{name} enables it."}, {1,1," --_fielddef-=,"}, {1,1," Define new field for ."}, + {1,1," --_makeTagEnryReflection-={{ optscript-code }}"}, + {1,1," Specify code run when parser makes a tag."}, {1,1," --_mtable-extend-=disttable+srctable."}, {1,1," Copy patterns of a regex table to another regex table."}, {1,1," --_mtable-regex-=///[]"}, @@ -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)) diff --git a/main/options_p.h b/main/options_p.h index 4fe8a77b90..44fe910190 100644 --- a/main/options_p.h +++ b/main/options_p.h @@ -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); diff --git a/main/parse.c b/main/parse.c index 0dd3faa255..9b4d8af900 100644 --- a/main/parse.c +++ b/main/parse.c @@ -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; @@ -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; diff --git a/main/parse.h b/main/parse.h index 853302d0a4..5fe21a875f 100644 --- a/main/parse.h +++ b/main/parse.h @@ -74,6 +74,7 @@ typedef enum { enum scriptHook { SCRIPT_HOOK_PRELUDE, SCRIPT_HOOK_SEQUEL, + SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION, SCRIPT_HOOK_MAX, }; diff --git a/main/parse_p.h b/main/parse_p.h index c482e1295b..9e599bd0f5 100644 --- a/main/parse_p.h +++ b/main/parse_p.h @@ -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); diff --git a/main/subparser_p.h b/main/subparser_p.h index 801e821c9b..3856e368dc 100644 --- a/main/subparser_p.h +++ b/main/subparser_p.h @@ -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); diff --git a/parsers/cpreprocessor.c b/parsers/cpreprocessor.c index 3508f00c29..40e446ba56 100644 --- a/parsers/cpreprocessor.c +++ b/parsers/cpreprocessor.c @@ -16,6 +16,7 @@ #include #include "debug.h" +#include "dependency.h" /* notifyInputStart, notifyInputEnd */ #include "entry.h" #include "htable.h" #include "cpreprocessor.h" @@ -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, @@ -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);