Skip to content

Commit 6cd166f

Browse files
committed
[SELF-INCOMPATIBLE]C++: introduce "using" role to "namespace" kind
WARNING: This change deletes "using" kind from C++ language. "foo" in "using namespace foo;" was captured as using kind. However, "foo" is not defined in the statement. "foo" is referred as a namespace defined somewhere. Therefore, ctags should not capture "foo" as a definition tag. Instead, ctags should capture it as a reference tag. The original code captures "foo" as a definition tag of "using" kind. This change captures "foo" as a reference tag of "using" role of "namespace" kind. $ cat /tmp/foo.hh using namespace std::cout; $ ./ctags -o - /tmp/foo.hh $ ./ctags -o - --extras=+r /tmp/foo.hh std::cout /tmp/foo.hh /^using namespace std::cout;$/;" n $ ./ctags -o - --extras=+r --fields=+K /tmp/foo.hh std::cout /tmp/foo.hh /^using namespace std::cout;$/;" namespace $ ./ctags -o - --extras=+r --fields=+Kr /tmp/foo.hh std::cout /tmp/foo.hh /^using namespace std::cout;$/;" namespace roles:using $ ./ctags --list-roles=C++.namespace #KIND(L/N) NAME ENABLED DESCRIPTION n/namespace using on specified with "using namespace" Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent 24f8524 commit 6cd166f

8 files changed

Lines changed: 36 additions & 13 deletions

File tree

Tmain/list-kinds-full.d/stdout-expected.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ A alias no no 0 NONE namespace aliases
2020
D macroparam no no 0 C parameters inside macro definitions
2121
L label no no 0 C goto labels
2222
N name no no 0 NONE names imported via using scope::symbol
23-
U using no yes 0 NONE using namespace statements
2423
Z tparam no no 0 NONE template parameters
2524
c class yes no 0 NONE classes
2625
d macro yes no 1 C macro definitions
@@ -30,7 +29,7 @@ g enum yes no 0 C enumeration names
3029
h header yes yes 2 C included header files
3130
l local no no 0 C local variables
3231
m member yes no 0 C class, struct, and union members
33-
n namespace yes no 0 NONE namespaces
32+
n namespace yes no 1 NONE namespaces
3433
p prototype no no 0 C function prototypes
3534
s struct yes no 0 C structure names
3635
t typedef yes no 0 C typedefs

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ C h/header system on system header
2121
C++ d/macro undef on undefined
2222
C++ h/header local on local header
2323
C++ h/header system on system header
24+
C++ n/namespace using on specified with "using namespace"
2425
CPreProcessor d/macro undef on undefined
2526
CPreProcessor h/header local on local header
2627
CPreProcessor h/header system on system header
@@ -112,6 +113,7 @@ C h/header system on system header
112113
C++ d/macro undef on undefined
113114
C++ h/header local on local header
114115
C++ h/header system on system header
116+
C++ n/namespace using on specified with "using namespace"
115117
CPreProcessor d/macro undef on undefined
116118
CPreProcessor h/header local on local header
117119
CPreProcessor h/header system on system header
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
main input.cpp /^int main() {$/;" f typeref:typename:int
2-
std input.cpp /^using namespace std;$/;" U function:main
32
m input.cpp /^int m;$/;" l function:main typeref:typename:int file:

Units/parser-cxx.r/bug834.cpp.d/expected.tags

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
std input.cpp /^using namespace std;$/;" U file:
21
C input.cpp /^vector<vector<int>> C;$/;" v typeref:typename:vector<vector<int>>
32
A input.cpp /^struct A {$/;" s file:
43
a input.cpp /^ int a;$/;" m struct:A typeref:typename:int file:

Units/parser-cxx.r/using.cpp.d/expected.tags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
A input.cpp /^class A$/;" class file: roles:def
22
B input.cpp /^class B : public A$/;" class file: roles:def
3-
std input.cpp /^using namespace std;$/;" using file: roles:def
3+
std input.cpp /^using namespace std;$/;" namespace file: roles:using
44
string input.cpp /^#include <string>/;" header roles:system
55
string input.cpp /^using std::string;$/;" name file: roles:def
66
test input.cpp /^ using A::test;$/;" name class:B roles:def

parsers/cxx/cxx_parser_using.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ bool cxxParserParseUsingClause(void)
134134
"Found using clause '%s' which extends scope",
135135
vStringValue(t->pszWord)
136136
);
137-
tag = cxxTagBegin(CXXTagCPPKindUSING,t);
137+
tag = cxxRefTagBegin(CXXTagCPPKindNAMESPACE,
138+
CXXTagCPPNamespaceRoleUSING,t);
139+
138140
} else {
139141

140142
t = cxxTokenChainLast(g_cxx.pTokenChain);

parsers/cxx/cxx_tag.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,17 @@ static kindDefinition g_aCXXCKinds [] = {
6868
CXX_COMMON_KINDS(C,"struct, and union members", LANG_IGNORE)
6969
};
7070

71+
static roleDefinition g_aCXXCPPNamespaceRoles [] = {
72+
{ true, "using", "specified with \"using namespace\"" },
73+
};
74+
7175
static kindDefinition g_aCXXCPPKinds [] = {
7276
CXX_COMMON_KINDS(CXX,"class, struct, and union members", LANG_AUTO),
7377
{ true, 'c', "class", "classes" },
74-
{ true, 'n', "namespace", "namespaces" },
78+
{ true, 'n', "namespace", "namespaces",
79+
.referenceOnly = false, ATTACH_ROLES(g_aCXXCPPNamespaceRoles) },
7580
{ false, 'A', "alias", "namespace aliases" },
7681
{ false, 'N', "name", "names imported via using scope::symbol" },
77-
{ false, 'U', "using", "using namespace statements",
78-
.referenceOnly = true },
7982
{ false, 'Z', "tparam", "template parameters" },
8083
};
8184

@@ -245,7 +248,7 @@ bool cxxTagFieldEnabled(unsigned int uField)
245248
static tagEntryInfo g_oCXXTag;
246249

247250

248-
tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
251+
static tagEntryInfo * cxxTagBeginCommon(unsigned int uKind,unsigned int uRole,CXXToken * pToken)
249252
{
250253
kindDefinition * pKindDefinitions = g_cxx.pKindDefinitions;
251254

@@ -255,10 +258,11 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
255258
return NULL;
256259
}
257260

258-
initTagEntry(
261+
initRefTagEntry(
259262
&g_oCXXTag,
260263
vStringValue(pToken->pszWord),
261-
uKind
264+
uKind,
265+
uRole
262266
);
263267

264268
g_oCXXTag.lineNumber = pToken->iLineNumber;
@@ -277,6 +281,16 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
277281
return &g_oCXXTag;
278282
}
279283

284+
tagEntryInfo * cxxRefTagBegin(unsigned int uKind, unsigned int uRole, CXXToken * pToken)
285+
{
286+
return cxxTagBeginCommon(uKind, uRole, pToken);
287+
}
288+
289+
tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
290+
{
291+
return cxxTagBeginCommon(uKind, ROLE_DEFINITION_INDEX, pToken);
292+
}
293+
280294
vString * cxxTagSetProperties(unsigned int uProperties)
281295
{
282296
if(uProperties == 0)

parsers/cxx/cxx_tag.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ enum CXXTagCPPKind
4646
CXXTagCPPKindNAMESPACE,
4747
CXXTagCPPKindALIAS,
4848
CXXTagCPPKindNAME,
49-
CXXTagCPPKindUSING,
5049
CXXTagCPPKindTEMPLATEPARAM
5150
};
5251

52+
enum CXXTagCPPNamespaceRole
53+
{
54+
CXXTagCPPNamespaceRoleUSING,
55+
};
56+
5357
// The fields common to all (sub)languages this parser supports.
5458
enum CXXTagCommonField
5559
{
@@ -99,6 +103,10 @@ bool cxxTagKindEnabled(unsigned int uTagKind);
99103
// The pToken ownership is NOT transferred.
100104
tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken);
101105

106+
// Do the same as cxxTagBegin but attaching a role for making a
107+
// reference tag.
108+
tagEntryInfo * cxxRefTagBegin(unsigned int uKind,unsigned int uRole,CXXToken * pToken);
109+
102110
// Set the type of the current tag from the specified token sequence
103111
// (which must belong to the same chain!).
104112
// Before setting the type this function will check that the specified

0 commit comments

Comments
 (0)