Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kconfig: support the macro language #3632

Merged
merged 4 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Units/parser-kconfig.r/macros.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--map-Kconfig=.kconfig
5 changes: 5 additions & 0 deletions Units/parser-kconfig.r/macros.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CC input.kconfig /^CC := gcc$/;" v
CC_HAS_FOO input.kconfig /^config CC_HAS_FOO$/;" c
CONFIG_CC_HAS_FOO input.kconfig /^config CC_HAS_FOO$/;" c
CONFIG_CC_HAS_FOO_MODULE input.kconfig /^config CC_HAS_FOO$/;" c
stringify input.kconfig /^stringify = $(squote)$(quote)$1$(quote)$(squote)$/;" v
10 changes: 10 additions & 0 deletions Units/parser-kconfig.r/macros.d/input.kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Taken from https://www.kernel.org/doc/html/latest/kbuild/kconfig-macro-language.html
CC := gcc

config CC_HAS_FOO
def_bool $(shell, $(srctree)/scripts/gcc-check-foo.sh $(CC))

# Taken from linux/scripts/Kbuild.include
###
# Quote a string to pass it to C files. foo => '"foo"'
stringify = $(squote)$(quote)$1$(quote)$(squote)
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ CONFIG_JFFS2_RTIME_MODULE input-1.kconfig /^config JFFS2_RTIME$/;" c roles:def
JFFS2_RUBIN input-1.kconfig /^config JFFS2_RUBIN$/;" c roles:def
CONFIG_JFFS2_RUBIN input-1.kconfig /^config JFFS2_RUBIN$/;" c roles:def
CONFIG_JFFS2_RUBIN_MODULE input-1.kconfig /^config JFFS2_RUBIN$/;" c roles:def
choice29ffa23a0104 input-1.kconfig /^choice$/;" C roles:def
JFFS2_CMODE_NONE input-1.kconfig /^config JFFS2_CMODE_NONE$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_NONE input-1.kconfig /^config JFFS2_CMODE_NONE$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_NONE_MODULE input-1.kconfig /^config JFFS2_CMODE_NONE$/;" c choice:choice29ffa23a0104 roles:def
JFFS2_CMODE_PRIORITY input-1.kconfig /^config JFFS2_CMODE_PRIORITY$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_PRIORITY input-1.kconfig /^config JFFS2_CMODE_PRIORITY$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_PRIORITY_MODULE input-1.kconfig /^config JFFS2_CMODE_PRIORITY$/;" c choice:choice29ffa23a0104 roles:def
JFFS2_CMODE_SIZE input-1.kconfig /^config JFFS2_CMODE_SIZE$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_SIZE input-1.kconfig /^config JFFS2_CMODE_SIZE$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_SIZE_MODULE input-1.kconfig /^config JFFS2_CMODE_SIZE$/;" c choice:choice29ffa23a0104 roles:def
JFFS2_CMODE_FAVOURLZO input-1.kconfig /^config JFFS2_CMODE_FAVOURLZO$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_FAVOURLZO input-1.kconfig /^config JFFS2_CMODE_FAVOURLZO$/;" c choice:choice29ffa23a0104 roles:def
CONFIG_JFFS2_CMODE_FAVOURLZO_MODULE input-1.kconfig /^config JFFS2_CMODE_FAVOURLZO$/;" c choice:choice29ffa23a0104 roles:def
choicebf6231840104 input-1.kconfig /^choice$/;" C roles:def
JFFS2_CMODE_NONE input-1.kconfig /^config JFFS2_CMODE_NONE$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_NONE input-1.kconfig /^config JFFS2_CMODE_NONE$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_NONE_MODULE input-1.kconfig /^config JFFS2_CMODE_NONE$/;" c choice:choicebf6231840104 roles:def
JFFS2_CMODE_PRIORITY input-1.kconfig /^config JFFS2_CMODE_PRIORITY$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_PRIORITY input-1.kconfig /^config JFFS2_CMODE_PRIORITY$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_PRIORITY_MODULE input-1.kconfig /^config JFFS2_CMODE_PRIORITY$/;" c choice:choicebf6231840104 roles:def
JFFS2_CMODE_SIZE input-1.kconfig /^config JFFS2_CMODE_SIZE$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_SIZE input-1.kconfig /^config JFFS2_CMODE_SIZE$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_SIZE_MODULE input-1.kconfig /^config JFFS2_CMODE_SIZE$/;" c choice:choicebf6231840104 roles:def
JFFS2_CMODE_FAVOURLZO input-1.kconfig /^config JFFS2_CMODE_FAVOURLZO$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_FAVOURLZO input-1.kconfig /^config JFFS2_CMODE_FAVOURLZO$/;" c choice:choicebf6231840104 roles:def
CONFIG_JFFS2_CMODE_FAVOURLZO_MODULE input-1.kconfig /^config JFFS2_CMODE_FAVOURLZO$/;" c choice:choicebf6231840104 roles:def
HAVE_ARCH_KGDB input-2.kconfig /^config HAVE_ARCH_KGDB$/;" c roles:def
CONFIG_HAVE_ARCH_KGDB input-2.kconfig /^config HAVE_ARCH_KGDB$/;" c roles:def
CONFIG_HAVE_ARCH_KGDB_MODULE input-2.kconfig /^config HAVE_ARCH_KGDB$/;" c roles:def
Expand Down
3 changes: 2 additions & 1 deletion docs/man-pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ Man pages
ctags-lang-asm(7) <man/ctags-lang-asm.7.rst>
ctags-lang-elm(7) <man/ctags-lang-elm.7.rst>
ctags-lang-gdscript(7) <man/ctags-lang-gdscript.7.rst>
ctags-lang-inko(7) <man/ctags-lang-inko.7.rst>
ctags-lang-iPythonCell(7) <man/ctags-lang-iPythonCell.7.rst>
ctags-lang-inko(7) <man/ctags-lang-inko.7.rst>
ctags-lang-javascript(7) <man/ctags-lang-javascript.7.rst>
ctags-lang-julia(7) <man/ctags-lang-julia.7.rst>
ctags-lang-kconfig(7) <man/ctags-lang-kconfig.7.rst>
ctags-lang-python(7) <man/ctags-lang-python.7.rst>
ctags-lang-r(7) <man/ctags-lang-r.7.rst>
ctags-lang-rmarkdown(7) <man/ctags-lang-rmarkdown.7.rst>
Expand Down
9 changes: 5 additions & 4 deletions man/GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ GEN_IN_MAN_FILES = \
ctags-faq.7 \
\
ctags-lang-asm.7 \
ctags-lang-elm.7 \
ctags-lang-gdscript.7 \
ctags-lang-iPythonCell.7 \
ctags-lang-inko.7 \
ctags-lang-javascript.7 \
ctags-lang-julia.7 \
ctags-lang-kconfig.7 \
ctags-lang-python.7 \
ctags-lang-tcl.7 \
ctags-lang-verilog.7 \
ctags-lang-inko.7 \
ctags-lang-r.7 \
ctags-lang-rmarkdown.7 \
ctags-lang-sql.7 \
ctags-lang-elm.7 \
ctags-lang-systemtap.7 \
ctags-lang-tcl.7 \
ctags-lang-verilog.7 \
\
readtags.1 \
tags.5 \
Expand Down
35 changes: 35 additions & 0 deletions man/ctags-lang-kconfig.7.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _ctags-lang-kconfig(7):

==============================================================
ctags-lang-kconfig
==============================================================
---------------------------------------------------------------------
Random notes about tagging Kconfig source code with Universal Ctags
---------------------------------------------------------------------
:Version: @VERSION@
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **@CTAGS_NAME_EXECUTABLE@** ... --languages=+Kconfig ...
| **@CTAGS_NAME_EXECUTABLE@** ... --language-force=Kconfig ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Kconfig=+(Kconfig*) ...

DESCRIPTION
-----------
This man page gathers random notes about tagging Kconfig scripts.

VERSIONS
--------

Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New kind ``variable``

SEE ALSO
--------
ctags(1),
`Kconfig Language <https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html>`_ (https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html),
`Kconfig macro language <https://www.kernel.org/doc/html/latest/kbuild/kconfig-macro-language.html>`_ (https://www.kernel.org/doc/html/latest/kbuild/kconfig-macro-language.html),
10 changes: 8 additions & 2 deletions optlib/kconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef enum {
K_MAINMENU,
K_KCONFIG,
K_CHOICE,
K_VARIABLE,
} KconfigKind;


Expand Down Expand Up @@ -56,6 +57,9 @@ extern parserDefinition* KconfigParser (void)
{
true, 'C', "choice", "choices",
},
{
true, 'v', "variable", "macro variables",
},
};
static xtagDefinition KconfigXtagTable [] = {
{
Expand Down Expand Up @@ -87,13 +91,15 @@ extern parserDefinition* KconfigParser (void)
"", "{scope=pop}{placeholder}{exclusive}", NULL, false},
{"^[ \t]*mainmenu[ \t]+\"([^\"]+)\"[ \t]*", "\\1",
"M", "{exclusive}", NULL, false},
{"^([-a-zA-Z0-9_$]+)[ \t]*:?=", "\\1",
"v", "{exclusive}", NULL, false},
};


parserDefinition* const def = parserNew ("Kconfig");

def->versionCurrent= 0;
def->versionAge = 0;
def->versionCurrent= 1;
def->versionAge = 1;
def->enabled = true;
def->extensions = extensions;
def->patterns = patterns;
Expand Down
7 changes: 6 additions & 1 deletion optlib/kconfig.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
#
# Reference
# https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html
# https://www.kernel.org/doc/html/latest/kbuild/kconfig-macro-language.html
#
#
# This parser was originally written in C as proplosed in #2553 by Maxime.
# Masatake converted it to an optlib file.
#
--langdef=Kconfig

--langdef=Kconfig{version=1.1}
--map-Kconfig=+(Kconfig*)

--kinddef-Kconfig=c,config,configs
--kinddef-Kconfig=m,menu,menus
--kinddef-Kconfig=M,mainMenu,the main menu
--kinddef-Kconfig=k,kconfig,kconfig file
--kinddef-Kconfig=C,choice,choices
--kinddef-Kconfig=v,variable,macro variables

--_roledef-Kconfig.{kconfig}=source,kconfig file loaded with source directive

Expand Down Expand Up @@ -65,3 +68,5 @@
--regex-Kconfig=/^[ \t]*endchoice[ \t]*//{scope=pop}{placeholder}{exclusive}

--regex-Kconfig=/^[ \t]*mainmenu[ \t]+"([^"]+)"[ \t]*/\1/M/{exclusive}

--regex-Kconfig=/^([-a-zA-Z0-9_$]+)[ \t]*:?=/\1/v/{exclusive}
2 changes: 2 additions & 0 deletions parsers/perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ static void collectHereDocMarkers (struct hereDocMarkerManager *mgr,
const unsigned char *line)
{
const unsigned char *cp = line;
#ifdef DEBUG
const unsigned char *last = cp;
#endif
while ((cp = collectHereDocMarker(mgr, cp)) != NULL)
Assert(last < cp);
}
Expand Down