Skip to content

Commit 755ae53

Browse files
committed
[SELF-INCOMPATIBLE]LdScript,Asm: make ref tag entries for sections found in Asm code
In the original code, sections are tagged as "placement" role of "section" kind in Asm language. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 0098b9b commit 755ae53

File tree

7 files changed

+80
-26
lines changed

7 files changed

+80
-26
lines changed

Tmain/list-roles.d/stdout-expected.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#
55
#LANGUAGE KIND(L/N) NAME ENABLED DESCRIPTION
66
Ada p/package subunit on package name referenced in separate()
7-
Asm s/section placement on placement where the assembled code goes
87
AutoIt S/script local on local include
98
AutoIt S/script system on system include
109
Autoconf e/optenable cmdline on specified in a configure command line
@@ -137,7 +136,6 @@ Zsh s/script loaded on loaded
137136
#
138137
#LANGUAGE KIND(L/N) NAME ENABLED DESCRIPTION
139138
Ada p/package subunit on package name referenced in separate()
140-
Asm s/section placement on placement where the assembled code goes
141139
AutoIt S/script local on local include
142140
AutoIt S/script system on system include
143141
Autoconf e/optenable cmdline on specified in a configure command line
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
--sort=no
22
--extras=+r
3-
--fields=+r
3+
--fields=+rlK
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
machine/asm.h input.s /^#include <machine\/asm.h>/;" h roles:system
2-
.rodata.cst8 input.s /^ .section .rodata.cst8,"aM",@progbits,8$/;" s roles:placement
3-
one input.s /^one: .double 1.0$/;" l roles:def
4-
limit input.s /^limit: .double 0.29$/;" l roles:def
5-
.inittext input-0.s /^ .section ".inittext","ax"$/;" s roles:placement
6-
intcall input-0.s /^intcall:$/;" l roles:def
1+
machine/asm.h input.s /^#include <machine\/asm.h>/;" header language:CPreProcessor roles:system
2+
.rodata.cst8 input.s /^ .section .rodata.cst8,"aM",@progbits,8$/;" inputSection language:LdScript roles:destination
3+
one input.s /^one: .double 1.0$/;" label language:Asm roles:def
4+
limit input.s /^limit: .double 0.29$/;" label language:Asm roles:def
5+
.inittext input-0.s /^ .section ".inittext","ax"$/;" inputSection language:LdScript roles:destination
6+
intcall input-0.s /^intcall:$/;" label language:Asm roles:def

docs/man/ctags-lang-asm.7.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ The parser has no ability to expand the macros defined outside of the
166166
current input file. The parser doesn't consider `#undef` when
167167
expanding.
168168

169+
VERSIONS
170+
--------
171+
172+
Change since "0.0"
173+
~~~~~~~~~~~~~~~~~~
174+
175+
* The kind ``section`` is deleted.
176+
The section specified with `.section` directive as tagged as
177+
``placement`` role of ``section`` kind of ``Asm`` language.
178+
These kind and role are deleted.
179+
180+
Instead, it is tagged as ``destination`` role of ``inputSection``
181+
kind of ``LdScript`` language.
182+
169183
SEE ALSO
170184
--------
171185
:ref:`ctags(1) <ctags(1)>`, Info entries for GNU assembler

docs/news/HEAD.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Changes about parser specific kinds, roles, fields, and extras
4646

4747
.. See the output of ./misc/news.bash man [v6.0.0]
4848
49+
* Asm
50+
51+
+ `section` kind is deleted.
52+
4953
* AutoIt
5054

5155
+ Drop `$` from tags for variables names.

man/ctags-lang-asm.7.rst.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ The parser has no ability to expand the macros defined outside of the
166166
current input file. The parser doesn't consider `#undef` when
167167
expanding.
168168

169+
VERSIONS
170+
--------
171+
172+
Change since "0.0"
173+
~~~~~~~~~~~~~~~~~~
174+
175+
* The kind ``section`` is deleted.
176+
The section specified with `.section` directive as tagged as
177+
``placement`` role of ``section`` kind of ``Asm`` language.
178+
These kind and role are deleted.
179+
180+
Instead, it is tagged as ``destination`` role of ``inputSection``
181+
kind of ``LdScript`` language.
182+
169183
SEE ALSO
170184
--------
171185
ctags(1), Info entries for GNU assembler

parsers/asm.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "cpreprocessor.h"
1919
#include "debug.h"
20+
#include "dependency.h"
2021
#include "entry.h"
2122
#include "keyword.h"
2223
#include "param.h"
@@ -31,9 +32,9 @@
3132
* DATA DECLARATIONS
3233
*/
3334
typedef enum {
35+
K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION = -3,
3436
K_PSUEDO_MACRO_END = -2,
3537
K_NONE = -1, K_DEFINE, K_LABEL, K_MACRO, K_TYPE,
36-
K_SECTION,
3738
K_PARAM,
3839
} AsmKind;
3940

@@ -59,10 +60,6 @@ typedef enum {
5960
OP_LAST
6061
} opKeyword;
6162

62-
typedef enum {
63-
ASM_SECTION_PLACEMENT,
64-
} asmSectionRole;
65-
6663
typedef struct {
6764
opKeyword keyword;
6865
AsmKind kind;
@@ -83,17 +80,11 @@ static fieldDefinition AsmFields[] = {
8380
*/
8481
static langType Lang_asm;
8582

86-
static roleDefinition asmSectionRoles [] = {
87-
{ true, "placement", "placement where the assembled code goes" },
88-
};
89-
9083
static kindDefinition AsmKinds [] = {
9184
{ true, 'd', "define", "defines" },
9285
{ true, 'l', "label", "labels" },
9386
{ true, 'm', "macro", "macros" },
9487
{ true, 't', "type", "types (structs and records)" },
95-
{ true, 's', "section", "sections",
96-
.referenceOnly = true, ATTACH_ROLES(asmSectionRoles)},
9788
{ false,'z', "parameter", "parameters for a macro" },
9889
};
9990

@@ -138,7 +129,7 @@ static const opKind OpKinds [] = {
138129
{ OP_PROC, K_LABEL },
139130
{ OP_RECORD, K_TYPE },
140131
{ OP_SECTIONS, K_NONE },
141-
{ OP_SECTION, K_SECTION },
132+
{ OP_SECTION, K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION },
142133
{ OP_SET, K_DEFINE },
143134
{ OP_STRUCT, K_TYPE }
144135
};
@@ -212,6 +203,32 @@ static bool isDefineOperator (const vString *const operator)
212203
return result;
213204
}
214205

206+
static int makeTagForLdScriptSection (const char * section)
207+
{
208+
tagEntryInfo e;
209+
static langType lang = LANG_AUTO;
210+
211+
if(lang == LANG_AUTO)
212+
lang = getNamedLanguage("LdScript", 0);
213+
if(lang == LANG_IGNORE)
214+
return CORK_NIL;
215+
216+
static kindDefinition * kdef = NULL;
217+
if(kdef == NULL)
218+
kdef = getLanguageKindForName (lang, "inputSection");
219+
if(kdef == NULL)
220+
return CORK_NIL;
221+
222+
static roleDefinition *rdef = NULL;
223+
if(rdef == NULL)
224+
rdef = getLanguageRoleForName (lang, kdef->id, "destination");
225+
if (rdef == NULL)
226+
return CORK_NIL;
227+
228+
initForeignRefTagEntry(&e, section, lang, kdef->id, rdef->id);
229+
return makeTagEntry (&e);
230+
}
231+
215232
static int makeAsmTag (
216233
const vString *const name,
217234
const vString *const operator,
@@ -271,10 +288,8 @@ static int makeAsmTag (
271288
*macroScope = macro_tag->extensionFields.scopeIndex;
272289
}
273290
break;
274-
case K_SECTION:
275-
r = makeSimpleRefTag (operator,
276-
kind_for_directive,
277-
ASM_SECTION_PLACEMENT);
291+
case K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION:
292+
r = makeTagForLdScriptSection (vStringValue (operator));
278293
break;
279294
default:
280295
r = makeSimpleTag (operator, kind_for_directive);
@@ -769,7 +784,8 @@ static void findAsmTagsCommon (bool useCpp)
769784
}
770785
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive, &macroScope);
771786
tagEntryInfo *e = getEntryInCorkQueue (r);
772-
if (e && e->kindIndex == K_MACRO && isRoleAssigned(e, ROLE_DEFINITION_INDEX))
787+
if (e && e->langType == Lang_asm
788+
&& e->kindIndex == K_MACRO && isRoleAssigned(e, ROLE_DEFINITION_INDEX))
773789
readMacroParameters (r, e, cp);
774790
}
775791

@@ -869,7 +885,15 @@ extern parserDefinition* AsmParser (void)
869885
};
870886
static selectLanguage selectors[] = { selectByArrowOfR, NULL };
871887

888+
static parserDependency dependencies [] = {
889+
{ DEPTYPE_FOREIGNER, "LdScript", NULL },
890+
};
891+
872892
parserDefinition* def = parserNew ("Asm");
893+
def->versionCurrent = 1;
894+
def->versionAge = 0;
895+
def->dependencies = dependencies;
896+
def->dependencyCount = ARRAY_SIZE (dependencies);
873897
def->kindTable = AsmKinds;
874898
def->kindCount = ARRAY_SIZE (AsmKinds);
875899
def->extensions = extensions;

0 commit comments

Comments
 (0)