Lexilla: const LexerModule

Neil Hodgson <[email protected]>
Newsgroups gmane.comp.lib.scintilla.devel
Message-ID <CACWkrTj=xDJRfMKB86PnJSsa5i5vK=1c3si7mEubBmJs2bZGUw@mail.gmail.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

-- 
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/scintilla-interest/CACWkrTj%3DxDJRfMKB86PnJSsa5i5vK%3D1c3si7mEubBmJs2bZGUw%40mail.gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.