Skip to content

Commit

Permalink
C,C++: add section field to store __attribute__((section("SECTION")))__
Browse files Browse the repository at this point in the history
input.c:

   extern void f0 (void) __attribute__ ((section ("sec")));

tags output:

   f0	input-1.c	\
	/^extern void f0 (void) __attribute__ ((section ("sec")));$/;"	\
	kind:prototype	line:1	language:C	typeref:typename:void	\
	file:	signature:(void)	roles:def	extras:fileScope	end:1	\
	section:sec	properties:extern

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 17, 2023
1 parent 38ff263 commit ce196a6
Show file tree
Hide file tree
Showing 25 changed files with 466 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tmain/list-fields-with-prefix.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ x UCTAGSxpath no NONE s-- no -- xpath for
- UCTAGSproperties no AutoIt s-- no -- properties (static, volatile, ...)
- UCTAGSmacrodef no C s-- no -- macro definition
- UCTAGSproperties no C s-- no -- properties (static, inline, mutable,...)
- UCTAGSsection no C s-- no -- the place where the object is placed
- UCTAGScaptures no C++ s-- no -- lambda capture list
- UCTAGSmacrodef no C++ s-- no -- macro definition
- UCTAGSname yes C++ s-- no -- aliased names
- UCTAGSproperties no C++ s-- no -- properties (static, inline, mutable,...)
- UCTAGSsection no C++ s-- no -- the place where the object is placed
- UCTAGSspecialization no C++ s-- no -- template specialization parameters
- UCTAGStemplate no C++ s-- no -- template parameters
- UCTAGSmacrodef no CPreProcessor s-- no -- macro definition
- UCTAGSmacrodef no CUDA s-- no -- macro definition
- UCTAGSproperties no CUDA s-- no -- properties (static, inline, mutable,...)
- UCTAGSsection no CUDA s-- no -- the place where the object is placed
- UCTAGSmoduleName yes Elm s-- no -- actual name of renamed module
- UCTAGSannotations yes GDScript s-- no -- annotations on functions and variables
- UCTAGShowImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
Expand Down
3 changes: 3 additions & 0 deletions Tmain/list-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
- properties no AutoIt s-- no -- properties (static, volatile, ...)
- macrodef no C s-- no -- macro definition
- properties no C s-- no -- properties (static, inline, mutable,...)
- section no C s-- no -- the place where the object is placed
- captures no C++ s-- no -- lambda capture list
- macrodef no C++ s-- no -- macro definition
- name yes C++ s-- no -- aliased names
- properties no C++ s-- no -- properties (static, inline, mutable,...)
- section no C++ s-- no -- the place where the object is placed
- specialization no C++ s-- no -- template specialization parameters
- template no C++ s-- no -- template parameters
- macrodef no CPreProcessor s-- no -- macro definition
- macrodef no CUDA s-- no -- macro definition
- properties no CUDA s-- no -- properties (static, inline, mutable,...)
- section no CUDA s-- no -- the place where the object is placed
- moduleName yes Elm s-- no -- actual name of renamed module
- annotations yes GDScript s-- no -- annotations on functions and variables
- howImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
Expand Down
7 changes: 7 additions & 0 deletions Units/parser-cxx.r/attribute-sections.cpp.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--sort=no
--kinds-C=+p
--param-CPreProcessor._expand=1
--fields-C=+{section}{macrodef}
--fields=+S
--fields=+r
--extras=+r
20 changes: 20 additions & 0 deletions Units/parser-cxx.r/attribute-sections.cpp.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
f input.c /^char f [] __attribute__((section("__ksymtab_strings"), used, aligned(1)));$/;" v typeref:typename:char[] roles:def section:__ksymtab_strings
a input.c /^struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };$/;" v typeref:struct:duart roles:def section:DUART_A
b input.c /^struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };$/;" v typeref:struct:duart roles:def section:DUART_B
stack input.c /^char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };$/;" v typeref:typename:char[10000] roles:def section:STACK
init_data input.c /^int init_data __attribute__ ((section ("INITDATA")));$/;" v typeref:typename:int roles:def section:INITDATA
COMMAND_LINE_SIZE input-0.c /^#define COMMAND_LINE_SIZE /;" d file: roles:def macrodef:127
__section input-0.c /^#define __section(section) __attribute__((__section_/;" d file: signature:(section) roles:def macrodef:__attribute__((__section__(section)))
__initdata input-0.c /^#define __initdata /;" d file: roles:def macrodef:__section(".init.data")
b0 input-0.c /^char __initdata b0[COMMAND_LINE_SIZE];$/;" v typeref:typename:char[127] roles:def section:.init.data
b1 input-0.c /^char b1[COMMAND_LINE_SIZE] __initdata;$/;" v typeref:typename:char[127] roles:def section:.init.data
f0 input-1.c /^extern void f0 (void) __attribute__ ((section ("bar0p")));$/;" p typeref:typename:void file: signature:(void) roles:def section:bar0p
f0 input-1.c /^void f0 (void) __attribute__ ((section ("bar0")))$/;" f typeref:typename:void signature:(void) roles:def section:bar0
f1 input-1.c /^extern void __attribute__ ((section ("bar1p"))) f1 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar1p
f1 input-1.c /^void __attribute__ ((section ("bar1"))) f1 (void)$/;" f typeref:typename:void signature:(void) roles:def section:bar1
f2 input-1.c /^extern __attribute__ ((section ("bar2p"))) void f2 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar2p
f2 input-1.c /^__attribute__ ((section ("bar2"))) void f2 (void)$/;" f typeref:typename:void signature:(void) roles:def section:bar2
f3 input-1.c /^__attribute__ ((section ("bar3p"))) extern void f3 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar3p
f3 input-1.c /^__attribute__ ((section ("bar3"))) extern void f3 (void)$/;" f typeref:typename:void signature:(void) roles:def section:bar3
f4 input-1.c /^__attribute__ ((section ("bar4p"))) static void f4 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar4p
f4 input-1.c /^__attribute__ ((section ("bar4"))) static void f4 (void)$/;" f typeref:typename:void file: signature:(void) roles:def section:bar4
6 changes: 6 additions & 0 deletions Units/parser-cxx.r/attribute-sections.cpp.d/input-0.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* --param-CPreProcessor._expand=1 */
#define COMMAND_LINE_SIZE 127
#define __section(section) __attribute__((__section__(section)))
#define __initdata __section(".init.data")
char __initdata b0[COMMAND_LINE_SIZE];
char b1[COMMAND_LINE_SIZE] __initdata;
24 changes: 24 additions & 0 deletions Units/parser-cxx.r/attribute-sections.cpp.d/input-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern void f0 (void) __attribute__ ((section ("bar0p")));
void f0 (void) __attribute__ ((section ("bar0")))
{
}

extern void __attribute__ ((section ("bar1p"))) f1 (void);
void __attribute__ ((section ("bar1"))) f1 (void)
{
}

extern __attribute__ ((section ("bar2p"))) void f2 (void);
__attribute__ ((section ("bar2"))) void f2 (void)
{
}

__attribute__ ((section ("bar3p"))) extern void f3 (void);
__attribute__ ((section ("bar3"))) extern void f3 (void)
{
}

__attribute__ ((section ("bar4p"))) static void f4 (void);
__attribute__ ((section ("bar4"))) static void f4 (void)
{
}
8 changes: 8 additions & 0 deletions Units/parser-cxx.r/attribute-sections.cpp.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Variables */
char f [] __attribute__((section("__ksymtab_strings"), used, aligned(1)));

/* Taken form gcc's info document. */
struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
int init_data __attribute__ ((section ("INITDATA")));
2 changes: 2 additions & 0 deletions docs/man-pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Man pages
ctags-lang-autoit(7) <man/ctags-lang-autoit.7.rst>
ctags-lang-automake(7) <man/ctags-lang-automake.7.rst>
ctags-lang-c(7) <man/ctags-lang-c.7.rst>
ctags-lang-c++(7) <man/ctags-lang-c++.7.rst>
ctags-lang-cuda(7) <man/ctags-lang-cuda.7.rst>
ctags-lang-elm(7) <man/ctags-lang-elm.7.rst>
ctags-lang-fortran(7) <man/ctags-lang-fortran.7.rst>
ctags-lang-gdscript(7) <man/ctags-lang-gdscript.7.rst>
Expand Down
38 changes: 38 additions & 0 deletions docs/man/ctags-lang-c++.7.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. _ctags-lang-c++(7):

==============================================================
ctags-lang-c++
==============================================================

Random notes about tagging C++ source code with Universal Ctags

:Version: 6.0.0
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **ctags** ... --languages=+C++ ...
| **ctags** ... --language-force=C++ ...
| **ctags** ... --map-C++=+.c++ ...
| **ctags** ... --map-C++=+.cc ...
| **ctags** ... --map-C++=+.cpp ...
| **ctags** ... --map-C++=+.h ...
| ...
DESCRIPTION
-----------
This man page gathers random notes about tagging C++ source code.

VERSIONS
--------

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

* New field ``section``

SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`,
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
35 changes: 35 additions & 0 deletions docs/man/ctags-lang-cuda.7.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _ctags-lang-cuda(7):

==============================================================
ctags-lang-cuda
==============================================================

Random notes about tagging CUDA source code with Universal Ctags

:Version: 6.0.0
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **ctags** ... --languages=+CUDA ...
| **ctags** ... --language-force=CUDA ...
| **ctags** ... --map-CUDA=+.cu ...
| **ctags** ... --map-CUDA=+.cuh ...
DESCRIPTION
-----------
This man page gathers random notes about tagging CUDA source code.

VERSIONS
--------

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

* New field ``section``

SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`,
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
10 changes: 10 additions & 0 deletions docs/news/HEAD.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ Changes about parser specific kinds, roles, fields, and extras
+ New role `foreigndecl` for `function` kind
+ New role `foreigndecl` for `struct` kind

+ New filed `section`

* C++

+ New filed `section`

* CUDA

+ New field `section`

* Fortran

+ New extra `linkName`.
Expand Down
2 changes: 2 additions & 0 deletions man/GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ GEN_IN_MAN_FILES = \
ctags-lang-autoit.7 \
ctags-lang-automake.7 \
ctags-lang-c.7 \
ctags-lang-c++.7 \
ctags-lang-cuda.7 \
ctags-lang-elm.7 \
ctags-lang-fortran.7 \
ctags-lang-gdscript.7 \
Expand Down
38 changes: 38 additions & 0 deletions man/ctags-lang-c++.7.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. _ctags-lang-c++(7):

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

SYNOPSIS
--------
| **@CTAGS_NAME_EXECUTABLE@** ... --languages=+C++ ...
| **@CTAGS_NAME_EXECUTABLE@** ... --language-force=C++ ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-C++=+.c++ ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-C++=+.cc ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-C++=+.cpp ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-C++=+.h ...
| ...

DESCRIPTION
-----------
This man page gathers random notes about tagging C++ source code.

VERSIONS
--------

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

* New field ``section``

SEE ALSO
--------
ctags(1),
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
35 changes: 35 additions & 0 deletions man/ctags-lang-cuda.7.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _ctags-lang-cuda(7):

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

SYNOPSIS
--------
| **@CTAGS_NAME_EXECUTABLE@** ... --languages=+CUDA ...
| **@CTAGS_NAME_EXECUTABLE@** ... --language-force=CUDA ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-CUDA=+.cu ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-CUDA=+.cuh ...

DESCRIPTION
-----------
This man page gathers random notes about tagging CUDA source code.

VERSIONS
--------

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

* New field ``section``

SEE ALSO
--------
ctags(1),
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
6 changes: 6 additions & 0 deletions parsers/cxx/cxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ parserDefinition * CppParser (void)
def->selectLanguage = selectors;
def->useCork = CORK_QUEUE|CORK_SYMTAB; // We use corking to block output until the end of file

def->versionCurrent = 1;
def->versionAge = 1;

return def;
}

Expand Down Expand Up @@ -162,5 +165,8 @@ parserDefinition * CUDAParser (void)
def->selectLanguage = NULL;
def->useCork = CORK_QUEUE|CORK_SYMTAB; // We use corking to block output until the end of file

def->versionCurrent = 1;
def->versionAge = 1;

return def;
}
Loading

0 comments on commit ce196a6

Please sign in to comment.