Skip to content

Commit 019b38c

Browse files
authored
Merge pull request #1879 from idodeclare/feature/c_cxx_include
Accept any path for #include statement for issue #471
2 parents a57dd0e + 8072901 commit 019b38c

File tree

9 files changed

+60
-28
lines changed

9 files changed

+60
-28
lines changed

src/org/opensolaris/opengrok/analysis/c/CSymbolTokenizer.lex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
4545

4646
%state STRING COMMENT SCOMMENT QSTRING
4747

48+
%include Common.lexh
4849
%%
4950

5051
<YYINITIAL> {
@@ -73,9 +74,10 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
7374
}
7475

7576
<SCOMMENT> {
76-
\n { yybegin(YYINITIAL);}
77+
{EOL} { yybegin(YYINITIAL); }
7778
}
7879

7980
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
81+
{WhiteSpace} {}
8082
[^] {}
8183
}

src/org/opensolaris/opengrok/analysis/c/CXref.lex

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ import org.opensolaris.opengrok.web.Util;
4040
%class CXref
4141
%extends JFlexXref
4242
%unicode
43-
%ignorecase
4443
%int
4544
%include CommonXref.lexh
4645
%{
46+
private static final Pattern MATCH_INCLUDE = Pattern.compile(
47+
"^(#.*)(include)(.*)([<\"])(.*)([>\"])$");
48+
private static final int INCL_HASH_G = 1;
49+
private static final int INCLUDE_G = 2;
50+
private static final int INCL_POST_G = 3;
51+
private static final int INCL_PUNC0_G = 4;
52+
private static final int INCL_PATH_G = 5;
53+
private static final int INCL_PUNCZ_G = 6;
54+
4755
// TODO move this into an include file when bug #16053 is fixed
4856
@Override
4957
protected int getLineNumber() { return yyline; }
@@ -53,7 +61,10 @@ import org.opensolaris.opengrok.web.Util;
5361

5462
Identifier = [a-zA-Z_] [a-zA-Z0-9_]+
5563

56-
File = [a-zA-Z]{FNameChar}* "." ([chts]|"conf"|"java"|"cpp"|"hpp"|"CC"|"txt"|"htm"|"html"|"pl"|"xml"|"cc"|"cxx"|"c++"|"hh"|"hxx"|"h++"|"diff"|"patch")
64+
File = [a-zA-Z]{FNameChar}* "." ([cChHsStT] | [Cc][Oo][Nn][Ff] |
65+
[Jj][Aa][Vv][Aa] | [CcHh][Pp][Pp] | [Cc][Cc] | [Tt][Xx][Tt] |
66+
[Hh][Tt][Mm][Ll]? | [Pp][Ll] | [Xx][Mm][Ll] | [CcHh][\+][\+] | [Hh][Hh] |
67+
[CcHh][Xx][Xx] | [Dd][Ii][Ff][Ff] | [Pp][Aa][Tt][Cc][Hh])
5768

5869
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[1-9][0-9]*)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
5970

@@ -74,16 +85,19 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[1-9][0-9]*)(([eE][+-]?[0-9]+)?[ufdlU
7485
writeSymbol(id, Consts.kwd, yyline);
7586
}
7687

77-
"#" {WhspChar}* "include" {WhspChar}* "<" ({File}|{FPath}|{Identifier}) ">" {
78-
Matcher match = Pattern.compile("(#.*)(include)(.*)<(.*)>").matcher(yytext());
88+
"#" {WhspChar}* "include" {WhspChar}* ("<"[^>\n\r]+">" | \"[^\"\n\r]+\") {
89+
String capture = yytext();
90+
Matcher match = MATCH_INCLUDE.matcher(capture);
7991
if (match.matches()) {
80-
out.write(match.group(1));
81-
writeSymbol(match.group(2), Consts.kwd, yyline);
82-
out.write(match.group(3));
83-
out.write("&lt;");
84-
String path = match.group(4);
92+
out.write(match.group(INCL_HASH_G));
93+
writeSymbol(match.group(INCLUDE_G), Consts.kwd, yyline);
94+
out.write(match.group(INCL_POST_G));
95+
out.write(htmlize(match.group(INCL_PUNC0_G)));
96+
String path = match.group(INCL_PATH_G);
8597
out.write(Util.breadcrumbPath(urlPrefix + "path=", path));
86-
out.write("&gt;");
98+
out.write(htmlize(match.group(INCL_PUNCZ_G)));
99+
} else {
100+
out.write(htmlize(capture));
87101
}
88102
}
89103

src/org/opensolaris/opengrok/analysis/c/CxxSymbolTokenizer.lex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
4242

4343
%state STRING COMMENT SCOMMENT QSTRING
4444

45+
%include Common.lexh
4546
%%
4647

4748
<YYINITIAL> {
@@ -70,9 +71,10 @@ Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
7071
}
7172

7273
<SCOMMENT> {
73-
\n { yybegin(YYINITIAL);}
74+
{EOL} { yybegin(YYINITIAL); }
7475
}
7576

7677
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
78+
{WhiteSpace} {}
7779
[^] {}
7880
}

src/org/opensolaris/opengrok/analysis/c/CxxXref.lex

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ import org.opensolaris.opengrok.web.Util;
4040
%class CxxXref
4141
%extends JFlexXref
4242
%unicode
43-
%ignorecase
4443
%int
4544
%include CommonXref.lexh
4645
%{
46+
private static final Pattern MATCH_INCLUDE = Pattern.compile(
47+
"^(#.*)(include)(.*)([<\"])(.*)([>\"])$");
48+
private static final int INCL_HASH_G = 1;
49+
private static final int INCLUDE_G = 2;
50+
private static final int INCL_POST_G = 3;
51+
private static final int INCL_PUNC0_G = 4;
52+
private static final int INCL_PATH_G = 5;
53+
private static final int INCL_PUNCZ_G = 6;
54+
4755
// TODO move this into an include file when bug #16053 is fixed
4856
@Override
4957
protected int getLineNumber() { return yyline; }
@@ -53,7 +61,10 @@ import org.opensolaris.opengrok.web.Util;
5361

5462
Identifier = [a-zA-Z_] [a-zA-Z0-9_]+
5563

56-
File = [a-zA-Z]{FNameChar}* "." ([chts]|"conf"|"java"|"cpp"|"hpp"|"CC"|"txt"|"htm"|"html"|"pl"|"xml"|"cc"|"cxx"|"c++"|"hh"|"hxx"|"h++"|"diff"|"patch")
64+
File = [a-zA-Z]{FNameChar}* "." ([cChHsStT] | [Cc][Oo][Nn][Ff] |
65+
[Jj][Aa][Vv][Aa] | [CcHh][Pp][Pp] | [Cc][Cc] | [Tt][Xx][Tt] |
66+
[Hh][Tt][Mm][Ll]? | [Pp][Ll] | [Xx][Mm][Ll] | [CcHh][\+][\+] | [Hh][Hh] |
67+
[CcHh][Xx][Xx] | [Dd][Ii][Ff][Ff] | [Pp][Aa][Tt][Cc][Hh])
5768

5869
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[1-9][0-9]*)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
5970

@@ -73,16 +84,19 @@ Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[1-9][0-9]*)(([eE][+-]?[0-9]+)?[ufdlU
7384
writeSymbol(id, CxxConsts.kwd, yyline);
7485
}
7586

76-
"#" {WhspChar}* "include" {WhspChar}* "<" ({File}|{FPath}|{Identifier}) ">" {
77-
Matcher match = Pattern.compile("(#.*)(include)(.*)<(.*)>").matcher(yytext());
87+
"#" {WhspChar}* "include" {WhspChar}* ("<"[^>\n\r]+">" | \"[^\"\n\r]+\") {
88+
String capture = yytext();
89+
Matcher match = MATCH_INCLUDE.matcher(capture);
7890
if (match.matches()) {
79-
out.write(match.group(1));
80-
writeSymbol(match.group(2), CxxConsts.kwd, yyline);
81-
out.write(match.group(3));
82-
out.write("&lt;");
83-
String path = match.group(4);
91+
out.write(match.group(INCL_HASH_G));
92+
writeSymbol(match.group(INCLUDE_G), CxxConsts.kwd, yyline);
93+
out.write(match.group(INCL_POST_G));
94+
out.write(htmlize(match.group(INCL_PUNC0_G)));
95+
String path = match.group(INCL_PATH_G);
8496
out.write(Util.breadcrumbPath(urlPrefix + "path=", path));
85-
out.write("&gt;");
97+
out.write(htmlize(match.group(INCL_PUNCZ_G)));
98+
} else {
99+
out.write(htmlize(capture));
86100
}
87101
}
88102

test/org/opensolaris/opengrok/analysis/JFlexXrefTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ private void testCXrefInclude(Class<? extends JFlexXref> klass) throws Exception
277277
String[][] testData = {
278278
{"#include <abc.h>", "#<b>include</b> &lt;<a href=\"/source/s?path=abc.h\">abc.h</a>&gt;"},
279279
{"#include <abc/def.h>", "#<b>include</b> &lt;<a href=\"/source/s?path=abc/\">abc</a>/<a href=\"/source/s?path=abc/def.h\">def.h</a>&gt;"},
280-
{"#include \"abc.h\"", "#<b>include</b> <span class=\"s\">\"<a href=\"/source/s?path=abc.h\">abc.h</a>\"</span>"},
281-
{"#include \"abc/def.h\"", "#<b>include</b> <span class=\"s\">\"<a href=\"/source/s?path=abc/\">abc</a>/<a href=\"/source/s?path=abc/def.h\">def.h</a>\"</span>"},
280+
{"#include \"abc.h\"", "#<b>include</b> &quot;<a href=\"/source/s?path=abc.h\">abc.h</a>&quot;"},
281+
{"#include \"abc/def.h\"", "#<b>include</b> &quot;<a href=\"/source/s?path=abc/\">abc</a>/<a href=\"/source/s?path=abc/def.h\">def.h</a>&quot;"},
282282
{"#include <vector>", "#<b>include</b> &lt;<a href=\"/source/s?path=vector\">vector</a>&gt;"},
283283
};
284284

test/org/opensolaris/opengrok/analysis/c/c_xrefres.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<a class="l" name="28" href="#28">28</a><span class='fold-space'>&nbsp;</span>
3737
<a class="l" name="29" href="#29">29</a><span class='fold-space'>&nbsp;</span>#<b>include</b> &lt;<a href="/source/s?path=sys/">sys</a>/<a href="/source/s?path=sys/types.h">types.h</a>&gt;
3838
<a class="hl" name="30" href="#30">30</a><span class='fold-space'>&nbsp;</span>#<b>include</b> &lt;<a href="/source/s?path=time.h">time.h</a>&gt;
39-
<a class="l" name="31" href="#31">31</a><span class='fold-space'>&nbsp;</span>#<b>include</b> &lt;<a href="/source/s?path=errno.h">errno.h</a>&gt;
39+
<a class="l" name="31" href="#31">31</a><span class='fold-space'>&nbsp;</span>#<b>include</b> &quot;<a href="/source/s?path=errno.ext1">errno.ext1</a>&quot;
4040
<a class="l" name="32" href="#32">32</a><span class='fold-space'>&nbsp;</span>
4141
<a class="l" name="33" href="#33">33</a><span class='fold-space'>&nbsp;</span><span class="c">/*
4242
<a class="l" name="34" href="#34">34</a><span class='fold-space'>&nbsp;</span> * This function is blatently stolen from the kernel.

test/org/opensolaris/opengrok/analysis/c/cc_xrefres.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<a class="l" name="29" href="#29">29</a><span class='fold-space'>&nbsp;</span>#<b>include</b> &lt;<a href="/source/s?path=stdlib.h">stdlib.h</a>&gt;
3838
<a class="hl" name="30" href="#30">30</a><span class='fold-space'>&nbsp;</span>#<b>include</b> &lt;<a href="/source/s?path=string.h">string.h</a>&gt;
3939
<a class="l" name="31" href="#31">31</a><span class='fold-space'>&nbsp;</span>
40-
<a class="l" name="32" href="#32">32</a><span class='fold-space'>&nbsp;</span>#<b>include</b> <span class="s">"<a href="/source/s?path=Ancestor.h">Ancestor.h</a>"</span>
40+
<a class="l" name="32" href="#32">32</a><span class='fold-space'>&nbsp;</span>#<b>include</b> &quot;<a href="/source/s?path=Ancestor.ext1">Ancestor.ext1</a>&quot;
4141
<a class="l" name="33" href="#33">33</a><span class='fold-space'>&nbsp;</span>
4242
<a class="l" name="34" href="#34">34</a><span class='fold-space'>&nbsp;</span><span class="c">/* ========================================================================= */</span>
4343
<a class="l" name="35" href="#35">35</a><span class='fold-space'>&nbsp;</span><span class="c">/* Ancestor object definitions. */</span>

test/org/opensolaris/opengrok/analysis/c/sample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include <sys/types.h>
3030
#include <time.h>
31-
#include <errno.h>
31+
#include "errno.ext1"
3232

3333
/*
3434
* This function is blatently stolen from the kernel.

test/org/opensolaris/opengrok/analysis/c/sample.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <stdlib.h>
3030
#include <string.h>
3131

32-
#include "Ancestor.h"
32+
#include "Ancestor.ext1"
3333

3434
/* ========================================================================= */
3535
/* Ancestor object definitions. */

0 commit comments

Comments
 (0)