Neil Hodgson
unread,Aug 7, 2024, 6:40:10 PMAug 7Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scintilla...@googlegroups.com
Currently, each lexer is defined by a LexerModule object which is
created at startup and doesn't change during execution. These are not
marked 'const' in the source code which makes the code more difficult
to understand and produces warnings from various linters.
For example, from Clang-Tidy:
G:\u\hg\lexilla\lexers\LexA68k.cxx:348:13: warning: variable 'lmA68k'
is non-const and globally accessible, consider making it const
[cppcoreguidelines-avoid-non-const-global-variables]
I am proposing that
1) All LexerModule instances are marked 'const' when they are defined
in their home modules and also when they are referenced inside
Lexilla.cxx. Since 'const' implies 'static' for the main definition,
these must also be 'extern'. This will be achieved by editing all the
lexer modules distributed with Lexilla and changing the script that
generates the references in Lexilla.cxx. Some downstream projects may
hand-edit Lexilla.cxx to include their own lexers or have their own
equivalent of Lexilla.cxx and they will need modifications.
This looks similar to:
diff --git a/lexers/LexAsm.cxx b/lexers/LexAsm.cxx
-LexerModule lmAsm(SCLEX_ASM, LexerAsm::LexerFactoryAsm, "asm",
asmWordListDesc);
+extern const LexerModule lmAsm(SCLEX_ASM, LexerAsm::LexerFactoryAsm,
"asm", asmWordListDesc);
diff --git a/src/Lexilla.cxx b/src/Lexilla.cxx
-extern LexerModule lmAsm;
+extern const LexerModule lmAsm;
2) CatalogueModules replaces LexerModule* with const LexerModule*.
This is simple and will not cause problems.
diff --git a/lexlib/CatalogueModules.h b/lexlib/CatalogueModules.h
class CatalogueModules {
- std::vector<LexerModule *> lexerCatalogue;
+ std::vector<const LexerModule *> lexerCatalogue;
- void AddLexerModule(LexerModule *plm) {
+ void AddLexerModule(const LexerModule *plm) {
- void AddLexerModules(std::initializer_list<LexerModule *> modules) {
+ void AddLexerModules(std::initializer_list<const LexerModule *> modules) {
Lexilla is supposed to remain compatible while retaining the first
version number (currently 5) and, to me, this is a compatible change.
Projects should check their use of Lexilla and see if they have
customized it in a way that this change will be difficult for them.
Neil