Skip to content

Commit 50065c9

Browse files
idodeclareVladimir Kotal
authored andcommitted
Clone CAnalyzer as AsmAnalyzer, and associate .S and .ASM
CtagsTest.bug19195() was newly failing from explicit registration of .S files for the Ctags C parser versus former implicit use of the Ctags Asm parser. With this change, OpenGrok now explicitly registers the Asm parser for .S and .ASM files.
1 parent 50fd128 commit 50065c9

File tree

7 files changed

+539
-4
lines changed

7 files changed

+539
-4
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.opengrok.indexer.analysis.archive.GZIPAnalyzerFactory;
6464
import org.opengrok.indexer.analysis.archive.TarAnalyzerFactory;
6565
import org.opengrok.indexer.analysis.archive.ZipAnalyzerFactory;
66+
import org.opengrok.indexer.analysis.asm.AsmAnalyzerFactory;
6667
import org.opengrok.indexer.analysis.c.CAnalyzerFactory;
6768
import org.opengrok.indexer.analysis.c.CxxAnalyzerFactory;
6869
import org.opengrok.indexer.analysis.clojure.ClojureAnalyzerFactory;
@@ -298,7 +299,8 @@ public class AnalyzerGuru {
298299
new RubyAnalyzerFactory(),
299300
new EiffelAnalyzerFactory(),
300301
new VerilogAnalyzerFactory(),
301-
new TypeScriptAnalyzerFactory()
302+
new TypeScriptAnalyzerFactory(),
303+
new AsmAnalyzerFactory()
302304
};
303305

304306
for (AnalyzerFactory analyzer : analyzers) {
@@ -332,15 +334,15 @@ public class AnalyzerGuru {
332334
* {@link FileAnalyzerFactory} subclasses are revised to target more or
333335
* different files.
334336
* @return a value whose lower 32-bits are a static value
335-
* 20191006_00
337+
* 20191120_00
336338
* for the current implementation and whose higher-32 bits are non-zero if
337339
* {@link #addExtension(java.lang.String, AnalyzerFactory)}
338340
* or
339341
* {@link #addPrefix(java.lang.String, AnalyzerFactory)}
340342
* has been called.
341343
*/
342344
public static long getVersionNo() {
343-
final int ver32 = 20191006_00; // Edit comment above too!
345+
final int ver32 = 20191120_00; // Edit comment above too!
344346
long ver = ver32;
345347
if (customizationHashCode != 0) {
346348
ver |= (long) customizationHashCode << 32;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opengrok.indexer.analysis.asm;
25+
26+
import org.opengrok.indexer.analysis.AbstractAnalyzer;
27+
import org.opengrok.indexer.analysis.AnalyzerFactory;
28+
import org.opengrok.indexer.analysis.JFlexTokenizer;
29+
import org.opengrok.indexer.analysis.JFlexXref;
30+
import org.opengrok.indexer.analysis.plain.AbstractSourceCodeAnalyzer;
31+
32+
import java.io.Reader;
33+
34+
/**
35+
* Represents an analyzer for assembly language.
36+
*/
37+
public class AsmAnalyzer extends AbstractSourceCodeAnalyzer {
38+
39+
/**
40+
* Creates a new instance of {@link AsmAnalyzer}.
41+
* @param factory instance
42+
*/
43+
protected AsmAnalyzer(AnalyzerFactory factory) {
44+
super(factory, new JFlexTokenizer(new AsmSymbolTokenizer(AbstractAnalyzer.DUMMY_READER)));
45+
}
46+
47+
/**
48+
* @return {@code "Asm"}
49+
*/
50+
@Override
51+
public String getCtagsLang() {
52+
return "Asm";
53+
}
54+
55+
/**
56+
* Gets a version number to be used to tag processed documents so that
57+
* re-analysis can be re-done later if a stored version number is different
58+
* from the current implementation.
59+
* @return 20191120_00
60+
*/
61+
@Override
62+
protected int getSpecializedVersionNo() {
63+
return 20191120_00; // Edit comment above too!
64+
}
65+
66+
/**
67+
* Creates a wrapped {@link AsmXref} instance.
68+
* @return a defined instance
69+
*/
70+
@Override
71+
protected JFlexXref newXref(Reader reader) {
72+
return new JFlexXref(new AsmXref(reader));
73+
}
74+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opengrok.indexer.analysis.asm;
25+
26+
import org.opengrok.indexer.analysis.AbstractAnalyzer;
27+
import org.opengrok.indexer.analysis.FileAnalyzerFactory;
28+
29+
/**
30+
* Represents a factory to create {@link AsmAnalyzer} instances.
31+
*/
32+
public class AsmAnalyzerFactory extends FileAnalyzerFactory {
33+
34+
private static final String NAME = "Asm";
35+
36+
private static final String[] SUFFIXES = {"ASM", "S"};
37+
38+
/**
39+
* Initializes a factory instance to associate file extensions ".asm" and
40+
* ".s" with {@link AsmAnalyzer}.
41+
*/
42+
public AsmAnalyzerFactory() {
43+
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
44+
}
45+
46+
/**
47+
* Creates a new {@link AsmAnalyzer} instance.
48+
* @return a defined instance
49+
*/
50+
@Override
51+
protected AbstractAnalyzer newAnalyzer() {
52+
return new AsmAnalyzer(this);
53+
}
54+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opengrok.indexer.analysis.asm;
24+
25+
import java.util.HashSet;
26+
import java.util.Set;
27+
28+
/**
29+
* Holds static hash set containing the C keywords (copying for use by Asm for
30+
* now).
31+
*/
32+
public class Consts {
33+
34+
public static final Set<String> kwd = new HashSet<>();
35+
36+
static {
37+
// CPP
38+
kwd.add("ident");
39+
kwd.add("ifndef");
40+
kwd.add("defined");
41+
kwd.add("endif");
42+
kwd.add("include");
43+
kwd.add("define");
44+
kwd.add("ifdef");
45+
kwd.add("pragma");
46+
47+
// C keywords
48+
kwd.add("asm");
49+
kwd.add("auto");
50+
kwd.add("break");
51+
kwd.add("case");
52+
kwd.add("char");
53+
kwd.add("const");
54+
kwd.add("continue");
55+
kwd.add("default");
56+
kwd.add("do");
57+
kwd.add("double");
58+
kwd.add("else");
59+
kwd.add("enum");
60+
kwd.add("extern");
61+
kwd.add("float");
62+
kwd.add("for");
63+
kwd.add("goto");
64+
kwd.add("if");
65+
kwd.add("inline");
66+
kwd.add("int");
67+
kwd.add("long");
68+
kwd.add("register");
69+
kwd.add("restrict");
70+
kwd.add("return");
71+
kwd.add("short");
72+
kwd.add("signed");
73+
kwd.add("sizeof");
74+
kwd.add("static");
75+
kwd.add("struct");
76+
kwd.add("switch");
77+
kwd.add("typedef");
78+
kwd.add("union");
79+
kwd.add("unsigned");
80+
kwd.add("void");
81+
kwd.add("volatile");
82+
kwd.add("while");
83+
kwd.add("_Bool");
84+
kwd.add("_Complex");
85+
kwd.add("_Imaginary");
86+
// other keywords
87+
kwd.add("bool");
88+
kwd.add("true");
89+
kwd.add("false");
90+
kwd.add("redeclared");
91+
}
92+
93+
private Consts() {
94+
}
95+
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/c/CAnalyzerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
2223
*/
2324

2425
package org.opengrok.indexer.analysis.c;
@@ -39,7 +40,6 @@ public class CAnalyzerFactory extends FileAnalyzerFactory {
3940
"LEX",
4041
"YACC",
4142
"D",
42-
"S",
4343
"XS", // Mainly found in perl directories
4444
"X", // rpcgen input files
4545
};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
/*
26+
* Gets C symbols - ignores comments, strings, keywords (copying for use by Asm
27+
* for now).
28+
*/
29+
30+
package org.opengrok.indexer.analysis.asm;
31+
32+
import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
33+
%%
34+
%public
35+
%class AsmSymbolTokenizer
36+
%extends JFlexSymbolMatcher
37+
%unicode
38+
%init{
39+
yyline = 1;
40+
%init}
41+
%int
42+
%include CommonLexer.lexh
43+
%char
44+
45+
%state STRING COMMENT SCOMMENT QSTRING
46+
47+
%include Common.lexh
48+
%include C.lexh
49+
%%
50+
51+
<YYINITIAL> {
52+
{Identifier} {String id = yytext();
53+
if(!Consts.kwd.contains(id)) {
54+
onSymbolMatched(id, yychar);
55+
return yystate(); }
56+
}
57+
58+
"#" {WhspChar}* "include" {WhspChar}* ("<"[^>\n\r]+">" | \"[^\"\n\r]+\") {}
59+
60+
{Number} {}
61+
62+
\\\" | \\\' {}
63+
\" { yybegin(STRING); }
64+
\' { yybegin(QSTRING); }
65+
"/*" { yybegin(COMMENT); }
66+
"//" { yybegin(SCOMMENT); }
67+
}
68+
69+
<STRING> {
70+
\\[\"\\] {}
71+
\" { yybegin(YYINITIAL); }
72+
}
73+
74+
<QSTRING> {
75+
\\[\'\\] {}
76+
\' { yybegin(YYINITIAL); }
77+
}
78+
79+
<COMMENT> {
80+
"*/" { yybegin(YYINITIAL);}
81+
}
82+
83+
<SCOMMENT> {
84+
{EOL} { yybegin(YYINITIAL); }
85+
}
86+
87+
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
88+
{WhspChar}+ {}
89+
[^] {}
90+
}

0 commit comments

Comments
 (0)